Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link: add LinkSetIP6AddrGenMode #869

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions handle_unspecified.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func (h *Handle) LinkSetGROMaxSize(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
}
Expand Down
29 changes: 29 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,35 @@ func (h *Handle) LinkSetGROMaxSize(link Link, maxSize 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 boolAttr(val bool) []byte {
var v uint8
if val {
Expand Down
4 changes: 4 additions & 0 deletions netlink_unspecified.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func LinkSetGROMaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}

func LinkSetIP6AddrGenMode(link Link, mode int) error {
return ErrNotImplemented
}

func LinkAdd(link Link) error {
return ErrNotImplemented
}
Expand Down
7 changes: 7 additions & 0 deletions nl/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,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
)