Skip to content

Commit 106ec6e

Browse files
committed
feature: Add wireguard link type
Added type "Wireguard" which implements link type "wireguard". See also https://www.wireguard.com/ Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
1 parent 5a869a7 commit 106ec6e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

link.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ func (veth *Veth) Type() string {
349349
return "veth"
350350
}
351351

352+
// Wireguard represent links of type "wireguard", see https://www.wireguard.com/
353+
type Wireguard struct {
354+
LinkAttrs
355+
}
356+
357+
func (wg *Wireguard) Attrs() *LinkAttrs {
358+
return &wg.LinkAttrs
359+
}
360+
361+
func (wg *Wireguard) Type() string {
362+
return "wireguard"
363+
}
364+
352365
// GenericLink links represent types that are not currently understood
353366
// by this netlink library.
354367
type GenericLink struct {

link_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,8 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
16001600
link = &Vlan{}
16011601
case "veth":
16021602
link = &Veth{}
1603+
case "wireguard":
1604+
link = &Wireguard{}
16031605
case "vxlan":
16041606
link = &Vxlan{}
16051607
case "bond":

link_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ func testLinkAddDel(t *testing.T, link Link) {
117117
}
118118
}
119119

120+
if _, ok := link.(*Wireguard); ok {
121+
_, ok := result.(*Wireguard)
122+
if !ok {
123+
t.Fatal("Result of create is not a wireguard")
124+
}
125+
}
126+
120127
if vxlan, ok := link.(*Vxlan); ok {
121128
other, ok := result.(*Vxlan)
122129
if !ok {
@@ -1063,6 +1070,13 @@ func TestLinkSetNs(t *testing.T) {
10631070

10641071
}
10651072

1073+
func TestLinkAddDelWireguard(t *testing.T) {
1074+
tearDown := setUpNetlinkTest(t)
1075+
defer tearDown()
1076+
1077+
testLinkAddDel(t, &Wireguard{LinkAttrs: LinkAttrs{Name: "wg0"}})
1078+
}
1079+
10661080
func TestLinkAddDelVxlan(t *testing.T) {
10671081
tearDown := setUpNetlinkTest(t)
10681082
defer tearDown()

0 commit comments

Comments
 (0)