Skip to content

Use netlink directly instead of iproute2 #1978

@gwenya

Description

@gwenya

We are currently calling the ip command for configuring addresses, routes and neighbour objects.
This is unnecessary additional overhead and requires parsing the output in some cases, like here:

for _, line := range util.SplitNTrimSpace(out, "\n", -1, true) {
// Split fields and early validation.
fields := strings.Fields(line)
if len(fields) != 4 {
continue
}
addr := net.ParseIP(fields[0])
if addr == nil {
continue
}
mac, _ := net.ParseMAC(fields[2])
// Check neighbour matches desired MAC address if specified.
if n.MAC != nil {
if !bytes.Equal(n.MAC, mac) {
continue
}
}
neighbours = append(neighbours, Neigh{
Addr: addr,
MAC: mac,
State: NeighbourIPState(fields[3]),
})
}

By using netlink directly we can avoid that.
We already have a dependency on github.com/vishvananda/netlink, so we could use that without adding any extra dependencies.

If there is interest in this I will make a PR.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions