Skip to content

Commit

Permalink
feature: Add wireguard link type
Browse files Browse the repository at this point in the history
Added type "Wireguard" which implements link type "wireguard".

See also https://www.wireguard.com/

Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
  • Loading branch information
xaionaro committed Jun 3, 2020
1 parent 5a869a7 commit 106ec6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ func (veth *Veth) Type() string {
return "veth"
}

// Wireguard represent links of type "wireguard", see https://www.wireguard.com/
type Wireguard struct {
LinkAttrs
}

func (wg *Wireguard) Attrs() *LinkAttrs {
return &wg.LinkAttrs
}

func (wg *Wireguard) Type() string {
return "wireguard"
}

// GenericLink links represent types that are not currently understood
// by this netlink library.
type GenericLink struct {
Expand Down
2 changes: 2 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
link = &Vlan{}
case "veth":
link = &Veth{}
case "wireguard":
link = &Wireguard{}
case "vxlan":
link = &Vxlan{}
case "bond":
Expand Down
14 changes: 14 additions & 0 deletions link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ func testLinkAddDel(t *testing.T, link Link) {
}
}

if _, ok := link.(*Wireguard); ok {
_, ok := result.(*Wireguard)
if !ok {
t.Fatal("Result of create is not a wireguard")
}
}

if vxlan, ok := link.(*Vxlan); ok {
other, ok := result.(*Vxlan)
if !ok {
Expand Down Expand Up @@ -1063,6 +1070,13 @@ func TestLinkSetNs(t *testing.T) {

}

func TestLinkAddDelWireguard(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()

testLinkAddDel(t, &Wireguard{LinkAttrs: LinkAttrs{Name: "wg0"}})
}

func TestLinkAddDelVxlan(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
Expand Down

0 comments on commit 106ec6e

Please sign in to comment.