Skip to content

Commit

Permalink
Implement handling of OSPFv3 packets
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed Dec 27, 2019
1 parent 4da0c14 commit 137a8a1
Show file tree
Hide file tree
Showing 17 changed files with 3,761 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -7,6 +7,7 @@ require (
github.com/gogo/protobuf v1.3.0 // indirect
github.com/golang/protobuf v1.3.1
github.com/google/btree v1.0.0
github.com/google/gopacket v1.1.17
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/pkg/errors v0.8.0
Expand All @@ -17,6 +18,7 @@ require (
github.com/urfave/cli v1.21.0
github.com/vishvananda/netlink v1.0.0
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980
google.golang.org/genproto v0.0.0-20181221175505-bd9b4fb69e2f // indirect
google.golang.org/grpc v1.17.0
gopkg.in/yaml.v2 v2.2.2
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Expand Up @@ -32,6 +32,8 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY=
github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
Expand Down Expand Up @@ -88,6 +90,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -100,6 +103,8 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
80 changes: 80 additions & 0 deletions protocols/ospf/packetv3/common.go
@@ -0,0 +1,80 @@
package packetv3

import (
"bytes"
"encoding/binary"

"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/tflow2/convert"
"github.com/pkg/errors"
)

// Serializable represents any packet which can be serialized
// to bytes to be on the wire
type Serializable interface {
Serialize(buf *bytes.Buffer)
}

// ID is a common type used for 32-bit IDs in OSPF
type ID uint32

func DeserializeID(buf *bytes.Buffer) (ID, int, error) {
var id uint32
if err := binary.Read(buf, binary.BigEndian, &id); err != nil {
return ID(id), 0, errors.Wrap(err, "unable to read ID from buffer")
}
return ID(id), 4, nil
}

func (i ID) Serialize(buf *bytes.Buffer) {
buf.Write(convert.Uint32Byte(uint32(i)))
}

// bitmasks for flags in RouterOptions
const (
RouterOptV6 uint16 = 1 << iota
RouterOptE
_
RouterOptN
RouterOptR
RouterOptDC
_
_
RouterOptAF
)

type RouterOptions struct {
_ uint8
Flags uint16
}

func (r *RouterOptions) Serialize(buf *bytes.Buffer) {
buf.WriteByte(0)
buf.Write(convert.Uint16Byte(uint16(r.Flags)))
}

type LSType uint16

func (t LSType) Serialize(buf *bytes.Buffer) {
buf.Write(convert.Uint16Byte(uint16(t)))
}

type deserializableIP struct {
Higher uint64
Lower uint64
}

func (ip deserializableIP) ToNetIP() net.IP {
return *(net.IPv6(ip.Higher, ip.Lower))
}

func serializeIPv6(ip net.IP, buf *bytes.Buffer) {
if ip.IsIPv4() {
for i := 0; i < 16; i++ {
buf.WriteByte(0)
}
return
}

buf.Write(ip.Bytes())
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 137a8a1

Please sign in to comment.