mirror of https://github.com/vishvananda/netlink
prefer IFA_LOCAL address when dumping addresses
IFA_LOCAL and IFA_ADDRESS are the same for bcast interfaces, however for point-to-point links, IFA_ADDRESS is the remote address while IFA_LOCAL is the interface address.
This commit is contained in:
parent
ae3e7dba57
commit
efb2ec546f
|
@ -95,11 +95,17 @@ func AddrList(link Link, family int) ([]Addr, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var local, dst *net.IPNet
|
||||||
var addr Addr
|
var addr Addr
|
||||||
for _, attr := range attrs {
|
for _, attr := range attrs {
|
||||||
switch attr.Attr.Type {
|
switch attr.Attr.Type {
|
||||||
case syscall.IFA_ADDRESS:
|
case syscall.IFA_ADDRESS:
|
||||||
addr.IPNet = &net.IPNet{
|
dst = &net.IPNet{
|
||||||
|
IP: attr.Value,
|
||||||
|
Mask: net.CIDRMask(int(msg.Prefixlen), 8*len(attr.Value)),
|
||||||
|
}
|
||||||
|
case syscall.IFA_LOCAL:
|
||||||
|
local = &net.IPNet{
|
||||||
IP: attr.Value,
|
IP: attr.Value,
|
||||||
Mask: net.CIDRMask(int(msg.Prefixlen), 8*len(attr.Value)),
|
Mask: net.CIDRMask(int(msg.Prefixlen), 8*len(attr.Value)),
|
||||||
}
|
}
|
||||||
|
@ -107,6 +113,14 @@ func AddrList(link Link, family int) ([]Addr, error) {
|
||||||
addr.Label = string(attr.Value[:len(attr.Value)-1])
|
addr.Label = string(attr.Value[:len(attr.Value)-1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IFA_LOCAL should be there but if not, fall back to IFA_ADDRESS
|
||||||
|
if local != nil {
|
||||||
|
addr.IPNet = local
|
||||||
|
} else {
|
||||||
|
addr.IPNet = dst
|
||||||
|
}
|
||||||
|
|
||||||
res = append(res, addr)
|
res = append(res, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue