TLV Update: handle update RouterID (R Flag)
This commit is contained in:
parent
ff695a5956
commit
7283f52d41
20
tlv/tlv.go
20
tlv/tlv.go
|
@ -508,6 +508,7 @@ type Update struct {
|
|||
Interval uint16
|
||||
Seqno uint16
|
||||
Metric uint16
|
||||
RouterID RouterID
|
||||
Prefix netaddr.IPPrefix
|
||||
NextHop netaddr.IP
|
||||
}
|
||||
|
@ -521,8 +522,8 @@ func (u Update) L() uint8 {
|
|||
}
|
||||
|
||||
func (u Update) FormatHeader() string {
|
||||
return fmt.Sprintf("Flags 0x%02x Omitted %2d Interval %4d Seqno %5d Metric %5d NextHop %s",
|
||||
u.Flags, u.Omitted, u.Interval, u.Seqno, u.Metric, u.NextHop,
|
||||
return fmt.Sprintf("Flags 0x%02x Omitted %2d Interval %4d Seqno %5d Metric %5d RouterID %s",
|
||||
u.Flags, u.Omitted, u.Interval, u.Seqno, u.Metric, u.RouterID,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -561,6 +562,21 @@ func (s *PacketDecoder) UpdateFromBytes(b []byte) (Update, []byte, error) {
|
|||
u.NextHop = s.nexthopv6
|
||||
}
|
||||
|
||||
if u.Flags&0x40 > 0 {
|
||||
addr := u.Prefix.IP()
|
||||
switch {
|
||||
case addr.Is6():
|
||||
v6 := addr.As16()
|
||||
copy(s.routerID[:], v6[8:])
|
||||
case addr.Is4():
|
||||
s.routerID = RouterID{}
|
||||
v4 := addr.As4()
|
||||
copy(s.routerID[4:], v4[:])
|
||||
}
|
||||
}
|
||||
|
||||
u.RouterID = s.routerID
|
||||
|
||||
return u, b, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue