Skip to content

Commit

Permalink
Merge pull request #46 from WireGuard/mdl-openbsd
Browse files Browse the repository at this point in the history
 internal/openbsd: initial stub commit and CI build
  • Loading branch information
mdlayher authored May 15, 2019
2 parents a652194 + 8b77f1d commit ea566ea
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .builds/openbsd.yml
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
11 changes: 9 additions & 2 deletions .cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ set -x
BINDIR=/home/build/go/bin

KERNEL=$(uname -s)

# Use doas in place of sudo for OpenBSD.
SUDO="sudo"
if [ "${KERNEL}" == "OpenBSD" ]; then
SUDO="doas"
fi

if [ "${KERNEL}" == "Linux" ]; then
# Set up the WireGuard kernel module on Linux.
sudo apt-get -y install software-properties-common
Expand All @@ -32,6 +39,6 @@ else
fi

mkdir -p ${BINDIR}
sudo mv ./wireguard-go ${BINDIR}/wireguard-go
${SUDO} mv ./wireguard-go ${BINDIR}/wireguard-go
cd ..
sudo rm -rf ./wireguard-go
${SUDO} rm -rf ./wireguard-go
22 changes: 22 additions & 0 deletions internal/wgopenbsd/client.go
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
}
54 changes: 54 additions & 0 deletions internal/wgopenbsd/client_openbsd.go
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
}
19 changes: 19 additions & 0 deletions internal/wgopenbsd/client_others.go
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
}
6 changes: 6 additions & 0 deletions internal/wgopenbsd/doc.go
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
25 changes: 25 additions & 0 deletions os_openbsd.go
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
}
2 changes: 1 addition & 1 deletion os_userspace.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !linux
//+build !linux,!openbsd

package wgctrl

Expand Down

0 comments on commit ea566ea

Please sign in to comment.