vishvananda/netlink

AddrAdd, AddReplace and AddrDel should not require a Link

Closed this issue · 1 comments

I propose the three methods:

AddrAdd(link Link, addr *Addr) error
AddrReplace(link Link, addr *Addr) error
AddrDel(link Link, addr *Addr) error

Have their signatures changed to:

AddrAdd(addr *Addr) error
AddrReplace(addr *Addr) error
AddrDel(addr *Addr) error

The link arguments are not needed because the interface index is already in the Addr struct.

This would make it similar to how it works for Neighbor and Routes. It would also give the nice property that the information you get about an address in AddrList is exactly the same as you need to give to the functions here.

The implementation does also use Name of the link in order to test if the label has it as prefix:

base := link.Attrs()
if addr.Label != "" && !strings.HasPrefix(addr.Label, base.Name) {
  return fmt.Errorf("label must begin with interface name")
}

But presumably this check is not really needed? It seems like it is the kernel that should make this check if it is needed.

I would be happy to make a PR with this change.

Please go ahead.
We cannot break current contract though, and golang does not support function overloading.