-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement handling of OSPFv3 packets
- Loading branch information
Showing
17 changed files
with
3,761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
960 changes: 960 additions & 0 deletions
960
protocols/ospf/packetv3/fixtures/packets/OSPFv3_NBMA_adjacencies.cap.go
Large diffs are not rendered by default.
Oops, something went wrong.
398 changes: 398 additions & 0 deletions
398
protocols/ospf/packetv3/fixtures/packets/OSPFv3_broadcast_adjacency.cap.go
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.