Skip to content

Commit d379b85

Browse files
committed
Implement handling of OSPFv3 packets
1 parent 0b9b901 commit d379b85

17 files changed

+3761
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/bio-routing/tflow2 v0.0.0-20181230153523-2e308a4a3c3a
77
github.com/gogo/protobuf v1.3.0 // indirect
88
github.com/golang/protobuf v1.3.1
9+
github.com/google/gopacket v1.1.17
910
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
1011
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
1112
github.com/pkg/errors v0.8.0
@@ -16,6 +17,7 @@ require (
1617
github.com/urfave/cli v1.21.0
1718
github.com/vishvananda/netlink v1.0.0
1819
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect
20+
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980
1921
google.golang.org/genproto v0.0.0-20181221175505-bd9b4fb69e2f // indirect
2022
google.golang.org/grpc v1.17.0
2123
gopkg.in/yaml.v2 v2.2.2

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
3030
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3131
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
3232
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
33+
github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY=
34+
github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
3335
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
3436
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
3537
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
@@ -86,6 +88,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
8688
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
8789
golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
8890
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
91+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
8992
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
9093
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
9194
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -98,6 +101,8 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
98101
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
99102
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
100103
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
104+
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998=
105+
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
101106
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
102107
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
103108
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

protocols/ospf/packetv3/common.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package packetv3
2+
3+
import (
4+
"bytes"
5+
"encoding/binary"
6+
7+
"github.com/bio-routing/bio-rd/net"
8+
"github.com/bio-routing/tflow2/convert"
9+
"github.com/pkg/errors"
10+
)
11+
12+
// Serializable represents any packet which can be serialized
13+
// to bytes to be on the wire
14+
type Serializable interface {
15+
Serialize(buf *bytes.Buffer)
16+
}
17+
18+
// ID is a common type used for 32-bit IDs in OSPF
19+
type ID uint32
20+
21+
func DeserializeID(buf *bytes.Buffer) (ID, int, error) {
22+
var id uint32
23+
if err := binary.Read(buf, binary.BigEndian, &id); err != nil {
24+
return ID(id), 0, errors.Wrap(err, "unable to read ID from buffer")
25+
}
26+
return ID(id), 4, nil
27+
}
28+
29+
func (i ID) Serialize(buf *bytes.Buffer) {
30+
buf.Write(convert.Uint32Byte(uint32(i)))
31+
}
32+
33+
// bitmasks for flags in RouterOptions
34+
const (
35+
RouterOptV6 uint16 = 1 << iota
36+
RouterOptE
37+
_
38+
RouterOptN
39+
RouterOptR
40+
RouterOptDC
41+
_
42+
_
43+
RouterOptAF
44+
)
45+
46+
type RouterOptions struct {
47+
_ uint8
48+
Flags uint16
49+
}
50+
51+
func (r *RouterOptions) Serialize(buf *bytes.Buffer) {
52+
buf.WriteByte(0)
53+
buf.Write(convert.Uint16Byte(uint16(r.Flags)))
54+
}
55+
56+
type LSType uint16
57+
58+
func (t LSType) Serialize(buf *bytes.Buffer) {
59+
buf.Write(convert.Uint16Byte(uint16(t)))
60+
}
61+
62+
type deserializableIP struct {
63+
Higher uint64
64+
Lower uint64
65+
}
66+
67+
func (ip deserializableIP) ToNetIP() net.IP {
68+
return *(net.IPv6(ip.Higher, ip.Lower))
69+
}
70+
71+
func serializeIPv6(ip net.IP, buf *bytes.Buffer) {
72+
if ip.IsIPv4() {
73+
for i := 0; i < 16; i++ {
74+
buf.WriteByte(0)
75+
}
76+
return
77+
}
78+
79+
buf.Write(ip.Bytes())
80+
}
12.9 KB
Binary file not shown.
5.41 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)