fix: Use correct message type for Set (#64)

In looking through the documentation and iproute2 code, `RTM_SETLINK`
seems to only be used in a handful of special cases, whereas `RTM_NEWLINK`
is used across the board for both new link creation as well as modification.

Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
This commit is contained in:
Brad Beam 2019-12-11 11:11:48 -06:00 committed by Jeroen Simonetti
parent 228b24473a
commit 87f74a6e05

10
link.go
View File

@ -157,9 +157,17 @@ func (l *LinkService) Get(index uint32) (LinkMessage, error) {
}
// Set sets interface attributes according to the LinkMessage information.
//
// ref: https://lwn.net/Articles/236919/
// We explicitly use RTM_NEWLINK to set link attributes instead of
// RTM_SETLINK because:
// - using RTM_SETLINK is actually an old rtnetlink API, not supporting most
// attributes common today
// - using RTM_NEWLINK is the prefered way to create AND update links
// - RTM_NEWLINK is backward compatible to RTM_SETLINK
func (l *LinkService) Set(req *LinkMessage) error {
flags := netlink.Request | netlink.Acknowledge
_, err := l.c.Execute(req, unix.RTM_SETLINK, flags)
_, err := l.c.Execute(req, unix.RTM_NEWLINK, flags)
if err != nil {
return err
}