// Address specific func handleAddr(update netlink.AddrUpdate, callback func(supervisor.NetlinkUpdate)) { if update.NewAddr { fmt.Printf("[Add a address]") } else { fmt.Printf("[Delete a address]") } if update.LinkAddress.IP.To4() != nil { fmt.Printf("[IPv4]\t%+v\n", update) } else { // We would not like to handle IPv6 at present. fmt.Printf("[IPv6]\t%+v\n", update) return } netlinkUpdate := supervisor.NetlinkUpdate{} netlinkUpdate.Addr = update netlinkUpdate.UpdateType = supervisor.UpdateTypeAddr links, err := netlink.LinkList() if err != nil { glog.Error(err) } for _, link := range links { if link.Attrs().Index == update.LinkIndex && link.Type() == "veth" { netlinkUpdate.Veth = link.(*netlink.Veth) break } } callback(netlinkUpdate) }
// Link specific func handleLink(update netlink.LinkUpdate, callback func(supervisor.NetlinkUpdate)) { if update.IfInfomsg.Flags&syscall.IFF_UP == 1 { fmt.Printf("[Link device up]\tupdateLink is:%+v, flag is:0x%x\n", update.Link.Attrs(), update.IfInfomsg.Flags) } else { if update.Link.Attrs().ParentIndex == 0 { fmt.Printf("[Link device !up][Deleted]\tupdateLink is:%+v, flag is:0x%x\n", update.Link.Attrs(), update.IfInfomsg.Flags) } else { fmt.Printf("[Link device !up]\tupdateLink is:%+v, flag is:0x%x\n", update.Link.Attrs(), update.IfInfomsg.Flags) } } netlinkUpdate := supervisor.NetlinkUpdate{} netlinkUpdate.UpdateType = supervisor.UpdateTypeLink // We would like to only handle the veth pair link at present. if veth, ok := (update.Link).(*netlink.Veth); ok { netlinkUpdate.Veth = veth callback(netlinkUpdate) } }