From 87f74a6e057aee4902bdddc954f194a3eb2423e6 Mon Sep 17 00:00:00 2001 From: Brad Beam Date: Wed, 11 Dec 2019 11:11:48 -0600 Subject: [PATCH] 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 --- link.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/link.go b/link.go index 0869ab3..24f480d 100644 --- a/link.go +++ b/link.go @@ -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 }