Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wireguard link type #464

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 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,15 @@ func TestLinkSetNs(t *testing.T) {

}

func TestLinkAddDelWireguard(t *testing.T) {
minKernelRequired(t, 5, 6)

tearDown := setUpNetlinkTest(t)
defer tearDown()

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

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