feat: add IFLA_INET6_ADDR_GEN_MODE support

This commit is contained in:
zlava
2025-04-11 20:22:56 +02:00
committed by Alessandro Boch
parent 5a4ec4bea5
commit d85a66b0d8
4 changed files with 46 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux
package netlink
@@ -183,6 +184,10 @@ func (h *Handle) LinkSetGROIPv4MaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}
func (h *Handle) LinkSetIP6AddrGenMode(link Link, mode int) error {
return ErrNotImplemented
}
func (h *Handle) setProtinfoAttr(link Link, mode bool, attr int) error {
return ErrNotImplemented
}

View File

@@ -2670,6 +2670,35 @@ func (h *Handle) LinkSetGroup(link Link, group int) error {
return err
}
// LinkSetIP6AddrGenMode sets the IPv6 address generation mode of the link device.
// Equivalent to: `ip link set $link addrgenmode $mode`
func LinkSetIP6AddrGenMode(link Link, mode int) error {
return pkgHandle.LinkSetIP6AddrGenMode(link, mode)
}
// LinkSetIP6AddrGenMode sets the IPv6 address generation mode of the link device.
// Equivalent to: `ip link set $link addrgenmode $mode`
func (h *Handle) LinkSetIP6AddrGenMode(link Link, mode int) error {
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)
b := make([]byte, 1)
b[0] = uint8(mode)
data := nl.NewRtAttr(unix.IFLA_INET6_ADDR_GEN_MODE, b)
af := nl.NewRtAttr(unix.AF_INET6, data.Serialize())
spec := nl.NewRtAttr(unix.IFLA_AF_SPEC, af.Serialize())
req.AddData(spec)
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
}
func addNetkitAttrs(nk *Netkit, linkInfo *nl.RtAttr, flag int) error {
if nk.Mode != NETKIT_MODE_L2 && (nk.LinkAttrs.HardwareAddr != nil || nk.peerLinkAttrs.HardwareAddr != nil) {
return fmt.Errorf("netkit only allows setting Ethernet in L2 mode")

View File

@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux
package netlink
@@ -144,6 +145,10 @@ func LinkSetGROIPv4MaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}
func LinkSetIP6AddrGenMode(link Link, mode int) error {
return ErrNotImplemented
}
func LinkAdd(link Link) error {
return ErrNotImplemented
}

View File

@@ -818,3 +818,10 @@ const (
IFLA_BAREUDP_MULTIPROTO_MODE
IFLA_BAREUDP_MAX = IFLA_BAREUDP_MULTIPROTO_MODE
)
const (
IN6_ADDR_GEN_MODE_EUI64 = iota
IN6_ADDR_GEN_MODE_NONE
IN6_ADDR_GEN_MODE_STABLE_PRIVACY
IN6_ADDR_GEN_MODE_RANDOM
)