link: Create some exported constants for each link type
I think that having the link type such as "tap", "macvlan", "ipvlan", ... being hardcoded directly into each implementation of the function Type() from the Link interface is not a great idea since it prevents those from being reused as standards.
What I'm suggesting is that we could define some constants like:
const NetlinkLinkTypeMacvtap = "macvtap"
so that each implementation would be along those lines:
func (macvtap Macvtap) Type() string {
return NetlinkLinkTypeMacvtap
}
and at the same time could be reused by any code importing this library.
/cc @amshinde @mcastelino
Any news on this? I would like to use this library to create Wireguard interfaces (www.wireguard.com), but atm it is a bit limiting. Having something like this would make it much more comfortable to use.
As alternative for now, if someone else has this use-case, you can simply do this:
package main
import (
"fmt"
"github.com/vishvananda/netlink"
"log"
)
// WG links are virtual wireguard ethernet devices
type WG struct {
netlink.LinkAttrs
}
func (wglink *WG) Attrs() *netlink.LinkAttrs {
return &wglink.LinkAttrs
}
func (wglink *WG) Type() string {
return "wireguard"
}
func main() {
wa := netlink.NewLinkAttrs()
wa.Name = "wg0"
wgdev := &WG{LinkAttrs: wa}
err := netlink.LinkAdd(wgdev)
if err != nil {
log.Fatal(err)
}
w, _ := netlink.LinkByName("wg0")
fmt.Printf("%+v\n", w)
}
But it would still be nice to have a generic way of doing it instead.
Worked for me, thanks @aroundthfur