Skip to content
Snippets Groups Projects
Unverified Commit 47db7589 authored by Daniel Czerwonk's avatar Daniel Czerwonk Committed by GitHub
Browse files

Merge pull request #78 from bio-routing/feature/unknown_attr_pass_extended_length

added support for extended legth on unknown attributes
parents b9c33e27 5f6c6ff1
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
# IDE specific files
.idea/
*.iml
.vscode
# 'go build' binary
bio-rd
......
......@@ -373,28 +373,28 @@ func dumpNBytes(buf *bytes.Buffer, n uint16) error {
}
// Serialize serializes a path attribute
func (pa *PathAttribute) Serialize(buf *bytes.Buffer, opt *types.Options) uint8 {
pathAttrLen := uint8(0)
func (pa *PathAttribute) Serialize(buf *bytes.Buffer, opt *types.Options) uint16 {
pathAttrLen := uint16(0)
switch pa.TypeCode {
case OriginAttr:
pathAttrLen = pa.serializeOrigin(buf)
pathAttrLen = uint16(pa.serializeOrigin(buf))
case ASPathAttr:
pathAttrLen = pa.serializeASPath(buf, opt)
pathAttrLen = uint16(pa.serializeASPath(buf, opt))
case NextHopAttr:
pathAttrLen = pa.serializeNextHop(buf)
pathAttrLen = uint16(pa.serializeNextHop(buf))
case MEDAttr:
pathAttrLen = pa.serializeMED(buf)
pathAttrLen = uint16(pa.serializeMED(buf))
case LocalPrefAttr:
pathAttrLen = pa.serializeLocalpref(buf)
pathAttrLen = uint16(pa.serializeLocalpref(buf))
case AtomicAggrAttr:
pathAttrLen = pa.serializeAtomicAggregate(buf)
pathAttrLen = uint16(pa.serializeAtomicAggregate(buf))
case AggregatorAttr:
pathAttrLen = pa.serializeAggregator(buf)
pathAttrLen = uint16(pa.serializeAggregator(buf))
case CommunitiesAttr:
pathAttrLen = pa.serializeCommunities(buf)
pathAttrLen = uint16(pa.serializeCommunities(buf))
case LargeCommunitiesAttr:
pathAttrLen = pa.serializeLargeCommunities(buf)
pathAttrLen = uint16(pa.serializeLargeCommunities(buf))
default:
pathAttrLen = pa.serializeUnknownAttribute(buf)
}
......@@ -552,21 +552,30 @@ func (pa *PathAttribute) serializeLargeCommunities(buf *bytes.Buffer) uint8 {
return length
}
func (pa *PathAttribute) serializeUnknownAttribute(buf *bytes.Buffer) uint8 {
func (pa *PathAttribute) serializeUnknownAttribute(buf *bytes.Buffer) uint16 {
attrFlags := uint8(0)
if pa.Optional {
attrFlags = setOptional(attrFlags)
}
if pa.ExtendedLength {
attrFlags = setExtendedLength(attrFlags)
}
attrFlags = setTransitive(attrFlags)
buf.WriteByte(attrFlags)
buf.WriteByte(pa.TypeCode)
b := pa.Value.([]byte)
buf.WriteByte(uint8(len(b)))
if pa.ExtendedLength {
l := len(b)
buf.WriteByte(uint8(l >> 8))
buf.WriteByte(uint8(l & 0x0000FFFF))
} else {
buf.WriteByte(uint8(len(b)))
}
buf.Write(b)
return uint8(len(b) + 2)
return uint16(len(b) + 2)
}
func fourBytesToUint32(address [4]byte) uint32 {
......
......@@ -1348,7 +1348,7 @@ func TestSerializeUnknownAttribute(t *testing.T) {
name string
input *PathAttribute
expected []byte
expectedLen uint8
expectedLen uint16
}{
{
name: "Arbritary attribute",
......@@ -1365,6 +1365,36 @@ func TestSerializeUnknownAttribute(t *testing.T) {
},
expectedLen: 6,
},
{
name: "Extended length",
input: &PathAttribute{
TypeCode: 200,
Value: make([]byte, 256),
Transitive: true,
ExtendedLength: true,
},
expected: []byte{
80, // Attribute flags
200, // Type
1, 0, // Length
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Payload
},
expectedLen: 258,
},
}
for _, test := range tests {
......
......@@ -255,8 +255,8 @@ func (b *BGPPath) insertNewASSequence() {
pa := make(types.ASPath, len(b.ASPath)+1)
copy(pa[1:], b.ASPath)
pa[0] = types.ASPathSegment{
ASNs: make([]uint32, 0),
Type: packet.ASSequence,
ASNs: make([]uint32, 0),
Type: types.ASSequence,
}
b.ASPath = pa
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment