-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from WireGuard/mdl-openbsd
internal/openbsd: initial stub commit and CI build
- Loading branch information
Showing
8 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
image: openbsd/6.5 | ||
packages: | ||
- bash | ||
- go | ||
sources: | ||
- https://github.com/WireGuard/wgctrl-go | ||
environment: | ||
GO111MODULE: "on" | ||
tasks: | ||
- setup-wireguard: | | ||
./wgctrl-go/.cibuild.sh | ||
- build: | | ||
go version | ||
go get golang.org/x/lint/golint | ||
go get honnef.co/go/tools/cmd/staticcheck | ||
cd wgctrl-go/ | ||
diff -u <(echo -n) <(/usr/local/go/bin/gofmt -d -s .) | ||
go vet ./... | ||
/home/build/go/bin/staticcheck ./... | ||
/home/build/go/bin/golint -set_exit_status ./... | ||
# The race detector is not supported on OpenBSD. | ||
go test -v ./... | ||
go test -c -tags=integration . | ||
# Use wireguard-go for additional testing. | ||
doas /home/build/go/bin/wireguard-go tun0 | ||
doas ./wgctrl.test -test.v -test.run TestClientIntegration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package wgopenbsd | ||
|
||
import "golang.zx2c4.com/wireguard/wgctrl/internal/wginternal" | ||
|
||
var _ wginternal.Client = &client{} | ||
|
||
// A Client provides access to OpenBSD WireGuard ioctl information. | ||
type Client struct { | ||
wginternal.Client | ||
} | ||
|
||
// New creates a new Client. | ||
func New() (*Client, error) { | ||
c, err := newClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Client{ | ||
Client: c, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//+build openbsd | ||
|
||
package wgopenbsd | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" | ||
) | ||
|
||
// A client is an OpenBSD-specific WireGuard client. | ||
type client struct { | ||
fd int | ||
} | ||
|
||
// newClient creates a client using a BSD socket. | ||
func newClient() (*client, error) { | ||
// The OpenBSD ioctl interface operates on a generic AF_INET socket. | ||
fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &client{ | ||
fd: fd, | ||
}, nil | ||
} | ||
|
||
// Close implements wginternal.Client. | ||
func (c *client) Close() error { | ||
return unix.Close(c.fd) | ||
} | ||
|
||
// Devices implements wginternal.Client. | ||
func (c *client) Devices() ([]*wgtypes.Device, error) { | ||
// Unimplemented: no devices means this code can be built but is effectively | ||
// a no-op. | ||
return nil, nil | ||
} | ||
|
||
// Device implements wginternal.Client. | ||
func (c *client) Device(name string) (*wgtypes.Device, error) { | ||
// Unimplemented: "not exist" error means this code can be built but is | ||
// effectively a no-op. | ||
return nil, os.ErrNotExist | ||
} | ||
|
||
// ConfigureDevice implements wginternal.Client. | ||
func (c *client) ConfigureDevice(name string, cfg wgtypes.Config) error { | ||
// Unimplemented: "not exist" error means this code can be built but is | ||
// effectively a no-op. | ||
return os.ErrNotExist | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//+build !openbsd | ||
|
||
package wgopenbsd | ||
|
||
import "golang.zx2c4.com/wireguard/wgctrl/internal/wginternal" | ||
|
||
// A client is an unimplemented wgopenbsd client. | ||
type client struct { | ||
wginternal.Client | ||
} | ||
|
||
func newClient() (*client, error) { | ||
return &client{ | ||
Client: wginternal.Unimplemented( | ||
"wgopenbsd", | ||
"the WireGuard ioctl interface is only available on OpenBSD", | ||
), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Package wgopenbsd provides internal access to OpenBSD's WireGuard | ||
// ioctl interface. | ||
// | ||
// This package is internal-only and not meant for end users to consume. | ||
// Please use package wgctrl (an abstraction over this package) instead. | ||
package wgopenbsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//+build openbsd | ||
|
||
package wgctrl | ||
|
||
import ( | ||
"golang.zx2c4.com/wireguard/wgctrl/internal/wginternal" | ||
"golang.zx2c4.com/wireguard/wgctrl/internal/wgopenbsd" | ||
"golang.zx2c4.com/wireguard/wgctrl/internal/wguser" | ||
) | ||
|
||
// newClients configures wginternal.Clients for OpenBSD systems. | ||
func newClients() ([]wginternal.Client, error) { | ||
// OpenBSD has an in-kernel WireGuard implementation. | ||
kc, err := wgopenbsd.New() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uc, err := wguser.New() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return []wginternal.Client{kc, uc}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//+build !linux | ||
//+build !linux,!openbsd | ||
|
||
package wgctrl | ||
|
||
|