Skip to content

Commit d85a66b

Browse files
zlavaaboch
authored andcommitted
feat: add IFLA_INET6_ADDR_GEN_MODE support
1 parent 5a4ec4b commit d85a66b

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

handle_unspecified.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !linux
12
// +build !linux
23

34
package netlink
@@ -183,6 +184,10 @@ func (h *Handle) LinkSetGROIPv4MaxSize(link Link, maxSize int) error {
183184
return ErrNotImplemented
184185
}
185186

187+
func (h *Handle) LinkSetIP6AddrGenMode(link Link, mode int) error {
188+
return ErrNotImplemented
189+
}
190+
186191
func (h *Handle) setProtinfoAttr(link Link, mode bool, attr int) error {
187192
return ErrNotImplemented
188193
}

link_linux.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,35 @@ func (h *Handle) LinkSetGroup(link Link, group int) error {
26702670
return err
26712671
}
26722672

2673+
// LinkSetIP6AddrGenMode sets the IPv6 address generation mode of the link device.
2674+
// Equivalent to: `ip link set $link addrgenmode $mode`
2675+
func LinkSetIP6AddrGenMode(link Link, mode int) error {
2676+
return pkgHandle.LinkSetIP6AddrGenMode(link, mode)
2677+
}
2678+
2679+
// LinkSetIP6AddrGenMode sets the IPv6 address generation mode of the link device.
2680+
// Equivalent to: `ip link set $link addrgenmode $mode`
2681+
func (h *Handle) LinkSetIP6AddrGenMode(link Link, mode int) error {
2682+
base := link.Attrs()
2683+
h.ensureIndex(base)
2684+
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)
2685+
2686+
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
2687+
msg.Index = int32(base.Index)
2688+
req.AddData(msg)
2689+
2690+
b := make([]byte, 1)
2691+
b[0] = uint8(mode)
2692+
2693+
data := nl.NewRtAttr(unix.IFLA_INET6_ADDR_GEN_MODE, b)
2694+
af := nl.NewRtAttr(unix.AF_INET6, data.Serialize())
2695+
spec := nl.NewRtAttr(unix.IFLA_AF_SPEC, af.Serialize())
2696+
req.AddData(spec)
2697+
2698+
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
2699+
return err
2700+
}
2701+
26732702
func addNetkitAttrs(nk *Netkit, linkInfo *nl.RtAttr, flag int) error {
26742703
if nk.Mode != NETKIT_MODE_L2 && (nk.LinkAttrs.HardwareAddr != nil || nk.peerLinkAttrs.HardwareAddr != nil) {
26752704
return fmt.Errorf("netkit only allows setting Ethernet in L2 mode")

netlink_unspecified.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !linux
12
// +build !linux
23

34
package netlink
@@ -144,6 +145,10 @@ func LinkSetGROIPv4MaxSize(link Link, maxSize int) error {
144145
return ErrNotImplemented
145146
}
146147

148+
func LinkSetIP6AddrGenMode(link Link, mode int) error {
149+
return ErrNotImplemented
150+
}
151+
147152
func LinkAdd(link Link) error {
148153
return ErrNotImplemented
149154
}

nl/link_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,10 @@ const (
818818
IFLA_BAREUDP_MULTIPROTO_MODE
819819
IFLA_BAREUDP_MAX = IFLA_BAREUDP_MULTIPROTO_MODE
820820
)
821+
822+
const (
823+
IN6_ADDR_GEN_MODE_EUI64 = iota
824+
IN6_ADDR_GEN_MODE_NONE
825+
IN6_ADDR_GEN_MODE_STABLE_PRIVACY
826+
IN6_ADDR_GEN_MODE_RANDOM
827+
)

0 commit comments

Comments
 (0)