Skip to content

Commit

Permalink
Add LinkList() method to netlink library wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: amaslennikov <[email protected]>
  • Loading branch information
almaslennikov committed Jul 23, 2024
1 parent 588abb4 commit b51ba3b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/host/internal/lib/netlink/mock/mock_netlink.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/host/internal/lib/netlink/netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type NetlinkLib interface {
LinkByName(name string) (Link, error)
// LinkByIndex finds a link by index and returns a pointer to the object.
LinkByIndex(index int) (Link, error)
// LinkList gets a list of link devices.
// Equivalent to: `ip link show`
LinkList() ([]Link, error)
// LinkSetVfHardwareAddr sets the hardware address of a vf for the link.
// Equivalent to: `ip link set $link vf $vf mac $hwaddr`
LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error
Expand Down Expand Up @@ -91,6 +94,23 @@ func (w *libWrapper) LinkByIndex(index int) (Link, error) {
return netlink.LinkByIndex(index)
}

// LinkList gets a list of link devices.
// Equivalent to: `ip link show`
func (w *libWrapper) LinkList() ([]Link, error) {
links, err := netlink.LinkList()
if err != nil {
return nil, err
}

// Convert each netlink.Link to the custom Link interface
customLinks := make([]Link, len(links))
for i, link := range links {
customLinks[i] = link
}

return customLinks, nil
}

// LinkSetVfHardwareAddr sets the hardware address of a vf for the link.
// Equivalent to: `ip link set $link vf $vf mac $hwaddr`
func (w *libWrapper) LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAddr) error {
Expand Down

0 comments on commit b51ba3b

Please sign in to comment.