summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-24 00:06:05 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-24 00:06:05 +0900
commit4656ce8419083536d36f16e4b0dc0203e642efa0 (patch)
treed2a606b298f1c1cb75c979fc5b8a18e1c340903c /packet
parent3aced1df03476d01939b7739152728b18825f56d (diff)
packet: fix PathAttributeMpReachNLRI's Serialize()
len(p.Valu) could be zero. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index a3bee84d..34eb3939 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -1860,6 +1860,8 @@ func NewPathAttributeClusterList(value []string) *PathAttributeClusterList {
type PathAttributeMpReachNLRI struct {
PathAttribute
Nexthop net.IP
+ AFI uint16
+ SAFI uint8
Value []AddrPrefixInterface
}
@@ -1877,6 +1879,8 @@ func (p *PathAttributeMpReachNLRI) DecodeFromBytes(data []byte) error {
}
afi := binary.BigEndian.Uint16(value[0:2])
safi := value[2]
+ p.AFI = afi
+ p.SAFI = safi
nexthopLen := value[3]
if len(value) < 4+int(nexthopLen) {
return NewMessageError(eCode, eSubCode, value, "mpreach nexthop length is short")
@@ -1921,8 +1925,12 @@ func (p *PathAttributeMpReachNLRI) DecodeFromBytes(data []byte) error {
}
func (p *PathAttributeMpReachNLRI) Serialize() ([]byte, error) {
- afi := p.Value[0].AFI()
- safi := p.Value[0].SAFI()
+ afi := p.AFI
+ safi := p.SAFI
+ if len(p.Value) > 0 && afi == 0 {
+ afi = p.Value[0].AFI()
+ safi = p.Value[0].SAFI()
+ }
nexthoplen := 4
if afi == AFI_IP6 {
nexthoplen = 16