2014-09-01 03:27:34 +00:00
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"strings"
|
2018-01-19 21:40:24 +00:00
|
|
|
"syscall"
|
2014-09-24 05:21:11 +00:00
|
|
|
|
2014-09-19 02:04:48 +00:00
|
|
|
"github.com/vishvananda/netlink/nl"
|
2016-06-29 16:11:35 +00:00
|
|
|
"github.com/vishvananda/netns"
|
2017-10-20 20:38:07 +00:00
|
|
|
"golang.org/x/sys/unix"
|
2014-09-01 03:27:34 +00:00
|
|
|
)
|
|
|
|
|
2015-11-26 11:47:18 +00:00
|
|
|
// IFA_FLAGS is a u32 attribute.
|
|
|
|
const IFA_FLAGS = 0x8
|
|
|
|
|
2014-09-01 03:27:34 +00:00
|
|
|
// AddrAdd will add an IP address to a link device.
|
2014-12-01 03:31:00 +00:00
|
|
|
// Equivalent to: `ip addr add $addr dev $link`
|
2014-09-24 05:21:11 +00:00
|
|
|
func AddrAdd(link Link, addr *Addr) error {
|
2016-05-09 23:55:00 +00:00
|
|
|
return pkgHandle.AddrAdd(link, addr)
|
2016-05-08 18:35:49 +00:00
|
|
|
}
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2016-05-08 18:35:49 +00:00
|
|
|
// AddrAdd will add an IP address to a link device.
|
|
|
|
// Equivalent to: `ip addr add $addr dev $link`
|
|
|
|
func (h *Handle) AddrAdd(link Link, addr *Addr) error {
|
2017-10-20 20:38:07 +00:00
|
|
|
req := h.newNetlinkRequest(unix.RTM_NEWADDR, unix.NLM_F_CREATE|unix.NLM_F_EXCL|unix.NLM_F_ACK)
|
2016-05-08 18:35:49 +00:00
|
|
|
return h.addrHandle(link, addr, req)
|
2014-09-01 03:27:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 14:52:43 +00:00
|
|
|
// AddrReplace will replace (or, if not present, add) an IP address on a link device.
|
|
|
|
// Equivalent to: `ip addr replace $addr dev $link`
|
|
|
|
func AddrReplace(link Link, addr *Addr) error {
|
|
|
|
return pkgHandle.AddrReplace(link, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddrReplace will replace (or, if not present, add) an IP address on a link device.
|
|
|
|
// Equivalent to: `ip addr replace $addr dev $link`
|
|
|
|
func (h *Handle) AddrReplace(link Link, addr *Addr) error {
|
2017-10-20 20:38:07 +00:00
|
|
|
req := h.newNetlinkRequest(unix.RTM_NEWADDR, unix.NLM_F_CREATE|unix.NLM_F_REPLACE|unix.NLM_F_ACK)
|
2017-03-31 14:52:43 +00:00
|
|
|
return h.addrHandle(link, addr, req)
|
|
|
|
}
|
|
|
|
|
2014-09-01 03:27:34 +00:00
|
|
|
// AddrDel will delete an IP address from a link device.
|
|
|
|
// Equivalent to: `ip addr del $addr dev $link`
|
2014-09-24 05:21:11 +00:00
|
|
|
func AddrDel(link Link, addr *Addr) error {
|
2016-05-09 23:55:00 +00:00
|
|
|
return pkgHandle.AddrDel(link, addr)
|
2014-09-01 03:27:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 18:35:49 +00:00
|
|
|
// AddrDel will delete an IP address from a link device.
|
|
|
|
// Equivalent to: `ip addr del $addr dev $link`
|
|
|
|
func (h *Handle) AddrDel(link Link, addr *Addr) error {
|
2017-10-20 20:38:07 +00:00
|
|
|
req := h.newNetlinkRequest(unix.RTM_DELADDR, unix.NLM_F_ACK)
|
2016-05-08 18:35:49 +00:00
|
|
|
return h.addrHandle(link, addr, req)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error {
|
2014-09-24 05:21:11 +00:00
|
|
|
base := link.Attrs()
|
|
|
|
if addr.Label != "" && !strings.HasPrefix(addr.Label, base.Name) {
|
2014-09-01 03:27:34 +00:00
|
|
|
return fmt.Errorf("label must begin with interface name")
|
|
|
|
}
|
2016-05-08 18:35:49 +00:00
|
|
|
h.ensureIndex(base)
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2014-09-19 02:04:48 +00:00
|
|
|
family := nl.GetIPFamily(addr.IP)
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2014-09-19 02:04:48 +00:00
|
|
|
msg := nl.NewIfAddrmsg(family)
|
2014-09-24 05:21:11 +00:00
|
|
|
msg.Index = uint32(base.Index)
|
2015-11-26 11:47:18 +00:00
|
|
|
msg.Scope = uint8(addr.Scope)
|
2018-06-13 15:13:18 +00:00
|
|
|
mask := addr.Mask
|
|
|
|
if addr.Peer != nil {
|
|
|
|
mask = addr.Peer.Mask
|
|
|
|
}
|
|
|
|
prefixlen, masklen := mask.Size()
|
2014-09-01 03:27:34 +00:00
|
|
|
msg.Prefixlen = uint8(prefixlen)
|
|
|
|
req.AddData(msg)
|
|
|
|
|
2016-10-30 05:46:24 +00:00
|
|
|
var localAddrData []byte
|
2014-09-01 03:27:34 +00:00
|
|
|
if family == FAMILY_V4 {
|
2016-10-30 05:46:24 +00:00
|
|
|
localAddrData = addr.IP.To4()
|
2014-09-01 03:27:34 +00:00
|
|
|
} else {
|
2016-10-30 05:46:24 +00:00
|
|
|
localAddrData = addr.IP.To16()
|
2014-09-01 03:27:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 20:38:07 +00:00
|
|
|
localData := nl.NewRtAttr(unix.IFA_LOCAL, localAddrData)
|
2014-09-01 03:27:34 +00:00
|
|
|
req.AddData(localData)
|
2016-10-30 05:46:24 +00:00
|
|
|
var peerAddrData []byte
|
|
|
|
if addr.Peer != nil {
|
|
|
|
if family == FAMILY_V4 {
|
|
|
|
peerAddrData = addr.Peer.IP.To4()
|
|
|
|
} else {
|
|
|
|
peerAddrData = addr.Peer.IP.To16()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
peerAddrData = localAddrData
|
|
|
|
}
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2017-10-20 20:38:07 +00:00
|
|
|
addressData := nl.NewRtAttr(unix.IFA_ADDRESS, peerAddrData)
|
2014-09-01 03:27:34 +00:00
|
|
|
req.AddData(addressData)
|
|
|
|
|
2015-12-09 10:30:21 +00:00
|
|
|
if addr.Flags != 0 {
|
2016-05-12 17:51:33 +00:00
|
|
|
if addr.Flags <= 0xff {
|
|
|
|
msg.IfAddrmsg.Flags = uint8(addr.Flags)
|
|
|
|
} else {
|
|
|
|
b := make([]byte, 4)
|
|
|
|
native.PutUint32(b, uint32(addr.Flags))
|
|
|
|
flagsData := nl.NewRtAttr(IFA_FLAGS, b)
|
|
|
|
req.AddData(flagsData)
|
|
|
|
}
|
2015-11-26 11:47:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 11:18:57 +00:00
|
|
|
if family == FAMILY_V4 {
|
|
|
|
if addr.Broadcast == nil {
|
|
|
|
calcBroadcast := make(net.IP, masklen/8)
|
|
|
|
for i := range localAddrData {
|
2018-06-13 15:13:18 +00:00
|
|
|
calcBroadcast[i] = localAddrData[i] | ^mask[i]
|
2018-01-17 11:18:57 +00:00
|
|
|
}
|
|
|
|
addr.Broadcast = calcBroadcast
|
2017-07-24 20:03:20 +00:00
|
|
|
}
|
2018-01-17 11:18:57 +00:00
|
|
|
req.AddData(nl.NewRtAttr(unix.IFA_BROADCAST, addr.Broadcast))
|
2017-01-23 08:50:38 +00:00
|
|
|
|
2018-01-17 11:18:57 +00:00
|
|
|
if addr.Label != "" {
|
|
|
|
labelData := nl.NewRtAttr(unix.IFA_LABEL, nl.ZeroTerminated(addr.Label))
|
|
|
|
req.AddData(labelData)
|
|
|
|
}
|
2014-09-01 03:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 12:36:09 +00:00
|
|
|
// 0 is the default value for these attributes. However, 0 means "expired", while the least-surprising default
|
|
|
|
// value should be "forever". To compensate for that, only add the attributes if at least one of the values is
|
|
|
|
// non-zero, which means the caller has explicitly set them
|
|
|
|
if addr.ValidLft > 0 || addr.PreferedLft > 0 {
|
|
|
|
cachedata := nl.IfaCacheInfo{
|
|
|
|
IfaValid: uint32(addr.ValidLft),
|
|
|
|
IfaPrefered: uint32(addr.PreferedLft),
|
|
|
|
}
|
|
|
|
req.AddData(nl.NewRtAttr(unix.IFA_CACHEINFO, cachedata.Serialize()))
|
|
|
|
}
|
|
|
|
|
2017-10-20 20:38:07 +00:00
|
|
|
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
|
2014-09-01 03:27:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddrList gets a list of IP addresses in the system.
|
|
|
|
// Equivalent to: `ip addr show`.
|
|
|
|
// The list can be filtered by link and ip family.
|
2014-09-24 05:21:11 +00:00
|
|
|
func AddrList(link Link, family int) ([]Addr, error) {
|
2016-05-09 23:55:00 +00:00
|
|
|
return pkgHandle.AddrList(link, family)
|
2016-05-08 18:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddrList gets a list of IP addresses in the system.
|
|
|
|
// Equivalent to: `ip addr show`.
|
|
|
|
// The list can be filtered by link and ip family.
|
|
|
|
func (h *Handle) AddrList(link Link, family int) ([]Addr, error) {
|
2017-10-20 20:38:07 +00:00
|
|
|
req := h.newNetlinkRequest(unix.RTM_GETADDR, unix.NLM_F_DUMP)
|
2014-09-19 02:04:48 +00:00
|
|
|
msg := nl.NewIfInfomsg(family)
|
2014-09-01 03:27:34 +00:00
|
|
|
req.AddData(msg)
|
|
|
|
|
2017-10-20 20:38:07 +00:00
|
|
|
msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWADDR)
|
2014-09-01 03:27:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-09-16 00:06:08 +00:00
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
indexFilter := 0
|
2014-09-24 05:21:11 +00:00
|
|
|
if link != nil {
|
|
|
|
base := link.Attrs()
|
2016-05-08 18:35:49 +00:00
|
|
|
h.ensureIndex(base)
|
2016-03-18 20:44:53 +00:00
|
|
|
indexFilter = base.Index
|
2014-09-24 05:21:11 +00:00
|
|
|
}
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2015-06-19 00:41:46 +00:00
|
|
|
var res []Addr
|
2014-09-01 03:27:34 +00:00
|
|
|
for _, m := range msgs {
|
2016-03-23 00:46:16 +00:00
|
|
|
addr, msgFamily, ifindex, err := parseAddr(m)
|
2016-03-18 20:44:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
if link != nil && ifindex != indexFilter {
|
2014-09-01 03:27:34 +00:00
|
|
|
// Ignore messages from other interfaces
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-03-23 00:46:16 +00:00
|
|
|
if family != FAMILY_ALL && msgFamily != family {
|
2016-01-30 15:34:36 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
res = append(res, addr)
|
|
|
|
}
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseAddr(m []byte) (addr Addr, family, index int, err error) {
|
|
|
|
msg := nl.DeserializeIfAddrmsg(m)
|
|
|
|
|
|
|
|
family = -1
|
|
|
|
index = -1
|
|
|
|
|
2016-03-18 21:08:51 +00:00
|
|
|
attrs, err1 := nl.ParseRouteAttr(m[msg.Len():])
|
|
|
|
if err1 != nil {
|
|
|
|
err = err1
|
2016-03-18 20:44:53 +00:00
|
|
|
return
|
|
|
|
}
|
2015-05-10 01:06:42 +00:00
|
|
|
|
2016-03-21 17:14:59 +00:00
|
|
|
family = int(msg.Family)
|
2016-03-18 20:44:53 +00:00
|
|
|
index = int(msg.Index)
|
|
|
|
|
|
|
|
var local, dst *net.IPNet
|
|
|
|
for _, attr := range attrs {
|
|
|
|
switch attr.Attr.Type {
|
2017-10-20 20:38:07 +00:00
|
|
|
case unix.IFA_ADDRESS:
|
2016-03-18 20:44:53 +00:00
|
|
|
dst = &net.IPNet{
|
|
|
|
IP: attr.Value,
|
|
|
|
Mask: net.CIDRMask(int(msg.Prefixlen), 8*len(attr.Value)),
|
|
|
|
}
|
2017-10-20 20:38:07 +00:00
|
|
|
case unix.IFA_LOCAL:
|
2018-06-13 15:13:18 +00:00
|
|
|
// iproute2 manual:
|
|
|
|
// If a peer address is specified, the local address
|
|
|
|
// cannot have a prefix length. The network prefix is
|
|
|
|
// associated with the peer rather than with the local
|
|
|
|
// address.
|
|
|
|
n := 8 * len(attr.Value)
|
2016-03-18 20:44:53 +00:00
|
|
|
local = &net.IPNet{
|
|
|
|
IP: attr.Value,
|
2018-06-13 15:13:18 +00:00
|
|
|
Mask: net.CIDRMask(n, n),
|
2016-03-18 20:44:53 +00:00
|
|
|
}
|
2017-10-20 20:38:07 +00:00
|
|
|
case unix.IFA_BROADCAST:
|
2017-04-29 14:25:32 +00:00
|
|
|
addr.Broadcast = attr.Value
|
2017-10-20 20:38:07 +00:00
|
|
|
case unix.IFA_LABEL:
|
2016-03-18 20:44:53 +00:00
|
|
|
addr.Label = string(attr.Value[:len(attr.Value)-1])
|
|
|
|
case IFA_FLAGS:
|
|
|
|
addr.Flags = int(native.Uint32(attr.Value[0:4]))
|
2017-04-12 16:54:00 +00:00
|
|
|
case nl.IFA_CACHEINFO:
|
|
|
|
ci := nl.DeserializeIfaCacheInfo(attr.Value)
|
|
|
|
addr.PreferedLft = int(ci.IfaPrefered)
|
|
|
|
addr.ValidLft = int(ci.IfaValid)
|
2015-05-10 01:06:42 +00:00
|
|
|
}
|
2016-03-18 20:44:53 +00:00
|
|
|
}
|
2015-05-10 01:06:42 +00:00
|
|
|
|
2018-06-13 15:13:18 +00:00
|
|
|
// libnl addr.c comment:
|
|
|
|
// IPv6 sends the local address as IFA_ADDRESS with no
|
|
|
|
// IFA_LOCAL, IPv4 sends both IFA_LOCAL and IFA_ADDRESS
|
|
|
|
// with IFA_ADDRESS being the peer address if they differ
|
|
|
|
//
|
|
|
|
// But obviously, as there are IPv6 PtP addresses, too,
|
|
|
|
// IFA_LOCAL should also be handled for IPv6.
|
2016-03-18 20:44:53 +00:00
|
|
|
if local != nil {
|
2018-06-13 15:13:18 +00:00
|
|
|
if family == FAMILY_V4 && local.IP.Equal(dst.IP) {
|
|
|
|
addr.IPNet = dst
|
|
|
|
} else {
|
|
|
|
addr.IPNet = local
|
|
|
|
addr.Peer = dst
|
|
|
|
}
|
2016-03-18 20:44:53 +00:00
|
|
|
} else {
|
|
|
|
addr.IPNet = dst
|
2014-09-01 03:27:34 +00:00
|
|
|
}
|
2018-06-13 15:13:18 +00:00
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
addr.Scope = int(msg.Scope)
|
2014-09-01 03:27:34 +00:00
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
return
|
2014-09-01 03:27:34 +00:00
|
|
|
}
|
2016-01-28 19:27:24 +00:00
|
|
|
|
|
|
|
type AddrUpdate struct {
|
|
|
|
LinkAddress net.IPNet
|
|
|
|
LinkIndex int
|
2017-04-12 20:01:17 +00:00
|
|
|
Flags int
|
|
|
|
Scope int
|
|
|
|
PreferedLft int
|
|
|
|
ValidLft int
|
2016-01-28 19:27:24 +00:00
|
|
|
NewAddr bool // true=added false=deleted
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddrSubscribe takes a chan down which notifications will be sent
|
|
|
|
// when addresses change. Close the 'done' chan to stop subscription.
|
|
|
|
func AddrSubscribe(ch chan<- AddrUpdate, done <-chan struct{}) error {
|
2018-01-19 21:40:24 +00:00
|
|
|
return addrSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
|
2016-06-29 16:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddrSubscribeAt works like AddrSubscribe plus it allows the caller
|
|
|
|
// to choose the network namespace in which to subscribe (ns).
|
|
|
|
func AddrSubscribeAt(ns netns.NsHandle, ch chan<- AddrUpdate, done <-chan struct{}) error {
|
2018-01-19 21:40:24 +00:00
|
|
|
return addrSubscribeAt(ns, netns.None(), ch, done, nil, false)
|
2016-06-29 16:11:35 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 11:53:43 +00:00
|
|
|
// AddrSubscribeOptions contains a set of options to use with
|
|
|
|
// AddrSubscribeWithOptions.
|
|
|
|
type AddrSubscribeOptions struct {
|
|
|
|
Namespace *netns.NsHandle
|
|
|
|
ErrorCallback func(error)
|
2018-01-19 21:40:24 +00:00
|
|
|
ListExisting bool
|
2017-09-12 11:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddrSubscribeWithOptions work like AddrSubscribe but enable to
|
|
|
|
// provide additional options to modify the behavior. Currently, the
|
|
|
|
// namespace can be provided as well as an error callback.
|
|
|
|
func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, options AddrSubscribeOptions) error {
|
|
|
|
if options.Namespace == nil {
|
|
|
|
none := netns.None()
|
|
|
|
options.Namespace = &none
|
|
|
|
}
|
2018-01-19 21:40:24 +00:00
|
|
|
return addrSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
|
2017-09-12 11:53:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 21:40:24 +00:00
|
|
|
func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-chan struct{}, cberr func(error), listExisting bool) error {
|
2017-10-20 20:38:07 +00:00
|
|
|
s, err := nl.SubscribeAt(newNs, curNs, unix.NETLINK_ROUTE, unix.RTNLGRP_IPV4_IFADDR, unix.RTNLGRP_IPV6_IFADDR)
|
2016-01-28 19:27:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if done != nil {
|
|
|
|
go func() {
|
|
|
|
<-done
|
|
|
|
s.Close()
|
|
|
|
}()
|
|
|
|
}
|
2018-01-19 21:40:24 +00:00
|
|
|
if listExisting {
|
|
|
|
req := pkgHandle.newNetlinkRequest(unix.RTM_GETADDR,
|
|
|
|
unix.NLM_F_DUMP)
|
|
|
|
infmsg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
|
|
|
req.AddData(infmsg)
|
|
|
|
if err := s.Send(req); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-01-28 19:27:24 +00:00
|
|
|
go func() {
|
|
|
|
defer close(ch)
|
|
|
|
for {
|
|
|
|
msgs, err := s.Receive()
|
|
|
|
if err != nil {
|
2017-09-12 11:24:33 +00:00
|
|
|
if cberr != nil {
|
|
|
|
cberr(err)
|
|
|
|
}
|
2016-01-28 19:27:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, m := range msgs {
|
2018-01-19 21:40:24 +00:00
|
|
|
if m.Header.Type == unix.NLMSG_DONE {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if m.Header.Type == unix.NLMSG_ERROR {
|
|
|
|
native := nl.NativeEndian()
|
|
|
|
error := int32(native.Uint32(m.Data[0:4]))
|
|
|
|
if error == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if cberr != nil {
|
|
|
|
cberr(syscall.Errno(-error))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2016-01-28 19:27:24 +00:00
|
|
|
msgType := m.Header.Type
|
2017-10-20 20:38:07 +00:00
|
|
|
if msgType != unix.RTM_NEWADDR && msgType != unix.RTM_DELADDR {
|
2017-09-12 11:24:33 +00:00
|
|
|
if cberr != nil {
|
|
|
|
cberr(fmt.Errorf("bad message type: %d", msgType))
|
|
|
|
}
|
|
|
|
return
|
2016-01-28 19:27:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 20:44:53 +00:00
|
|
|
addr, _, ifindex, err := parseAddr(m.Data)
|
2016-01-28 19:27:24 +00:00
|
|
|
if err != nil {
|
2017-09-12 11:24:33 +00:00
|
|
|
if cberr != nil {
|
|
|
|
cberr(fmt.Errorf("could not parse address: %v", err))
|
|
|
|
}
|
|
|
|
return
|
2016-01-28 19:27:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 20:01:17 +00:00
|
|
|
ch <- AddrUpdate{LinkAddress: *addr.IPNet,
|
|
|
|
LinkIndex: ifindex,
|
2017-10-20 20:38:07 +00:00
|
|
|
NewAddr: msgType == unix.RTM_NEWADDR,
|
2017-04-12 20:01:17 +00:00
|
|
|
Flags: addr.Flags,
|
|
|
|
Scope: addr.Scope,
|
|
|
|
PreferedLft: addr.PreferedLft,
|
|
|
|
ValidLft: addr.ValidLft}
|
2016-01-28 19:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|