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

Fixed wireguard MTU and added windows iface func #1567

Merged
merged 1 commit into from
May 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/wireguard/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type wgDeviceAttrs struct {
psk *wgtypes.Key
keepalive *time.Duration
name string
MTU int
}

type wgDevice struct {
Expand Down Expand Up @@ -127,6 +128,7 @@ func newWGDevice(devAttrs *wgDeviceAttrs, ctx context.Context, wg *sync.WaitGrou
// Create network device
la := netlink.LinkAttrs{
Name: devAttrs.name,
MTU: devAttrs.MTU,
}
link := &netlink.GenericLink{LinkAttrs: la, LinkType: "wireguard"}

Expand Down
9 changes: 5 additions & 4 deletions backend/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ func newSubnetAttrs(publicIP net.IP, publicIPv6 net.IP, enableIPv4, enableIPv6 b
return leaseAttrs, nil
}

func createWGDev(ctx context.Context, wg *sync.WaitGroup, name string, psk string, keepalive *time.Duration, listenPort int) (*wgDevice, error) {
func createWGDev(ctx context.Context, wg *sync.WaitGroup, name string, psk string, keepalive *time.Duration, listenPort int, mtu int) (*wgDevice, error) {
devAttrs := wgDeviceAttrs{
keepalive: keepalive,
listenPort: listenPort,
name: name,
MTU: mtu,
}
err := devAttrs.setupKeys(psk)
if err != nil {
Expand Down Expand Up @@ -128,21 +129,21 @@ func (be *WireguardBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGr
var publicKey string
if cfg.Mode == Separate {
if config.EnableIPv4 {
dev, err = createWGDev(ctx, wg, "flannel-wg", cfg.PSK, &keepalive, cfg.ListenPort)
dev, err = createWGDev(ctx, wg, "flannel-wg", cfg.PSK, &keepalive, cfg.ListenPort, be.extIface.Iface.MTU)
if err != nil {
return nil, err
}
publicKey = dev.attrs.publicKey.String()
}
if config.EnableIPv6 {
v6Dev, err = createWGDev(ctx, wg, "flannel-wg-v6", cfg.PSK, &keepalive, cfg.ListenPortV6)
v6Dev, err = createWGDev(ctx, wg, "flannel-wg-v6", cfg.PSK, &keepalive, cfg.ListenPortV6, be.extIface.Iface.MTU)
if err != nil {
return nil, err
}
publicKey = dev.attrs.publicKey.String()
}
} else if cfg.Mode == Auto || cfg.Mode == Ipv4 || cfg.Mode == Ipv6 {
dev, err = createWGDev(ctx, wg, "flannel-wg", cfg.PSK, &keepalive, cfg.ListenPort)
dev, err = createWGDev(ctx, wg, "flannel-wg", cfg.PSK, &keepalive, cfg.ListenPort, be.extIface.Iface.MTU)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/ip/iface_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func IsForwardingEnabledForInterface(iface *net.Interface) (bool, error) {
return powerShellJsonData.Forwarding == 1, nil
}

func GetInterfaceByIP6(ip net.IP) (*net.Interface, error) { return nil, nil }
func GetInterfaceIP6Addrs(iface *net.Interface) ([]net.IP, error) { return nil, nil }
func GetDefaultV6GatewayInterface() (*net.Interface, error) { return nil, nil }
func GetInterfaceByIP6(ip net.IP) (*net.Interface, error) { return nil, nil }
func GetInterfaceIP6Addrs(iface *net.Interface) ([]net.IP, error) { return nil, nil }
func GetInterfaceBySpecificIPRouting(ip net.IP) (*net.Interface, net.IP, error) { return nil, nil, nil }
func GetDefaultV6GatewayInterface() (*net.Interface, error) { return nil, nil }