diff options
Diffstat (limited to 'packet/bgp/bgp.go')
-rw-r--r-- | packet/bgp/bgp.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index a911c411..3afb7a9e 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -5189,20 +5189,20 @@ func (p *PathAttributeMpReachNLRI) DecodeFromBytes(data []byte) error { } nexthopbin := value[4 : 4+nexthoplen] if nexthoplen > 0 { - addrlen := 4 - if afi == AFI_IP6 { - addrlen = 16 - } + v4addrlen := 4 + v6addrlen := 16 offset := 0 if safi == SAFI_MPLS_VPN { offset = 8 } switch nexthoplen { - case 2 * (offset + addrlen): - p.LinkLocalNexthop = nexthopbin[offset+addrlen+offset : 2*(offset+addrlen)] + case 2 * (offset + v6addrlen): + p.LinkLocalNexthop = nexthopbin[offset+v6addrlen+offset : 2*(offset+v6addrlen)] fallthrough - case offset + addrlen: - p.Nexthop = nexthopbin[offset : offset+addrlen] + case offset + v6addrlen: + p.Nexthop = nexthopbin[offset : offset+v6addrlen] + case offset + v4addrlen: + p.Nexthop = nexthopbin[offset : offset+v4addrlen] default: return NewMessageError(eCode, eSubCode, value, "mpreach nexthop length is incorrect") } @@ -5235,7 +5235,7 @@ func (p *PathAttributeMpReachNLRI) Serialize() ([]byte, error) { afi := p.AFI safi := p.SAFI nexthoplen := 4 - if afi == AFI_IP6 { + if afi == AFI_IP6 || p.Nexthop.To4() == nil { nexthoplen = 16 } offset := 0 @@ -5254,7 +5254,7 @@ func (p *PathAttributeMpReachNLRI) Serialize() ([]byte, error) { buf[2] = safi buf[3] = uint8(nexthoplen) if nexthoplen != 0 { - if afi == AFI_IP6 { + if p.Nexthop.To4() == nil { copy(buf[4+offset:], p.Nexthop.To16()) if p.LinkLocalNexthop != nil { copy(buf[4+offset+16:], p.LinkLocalNexthop.To16()) |