diff options
author | Marvin Gaube <dev@marvingaube.de> | 2021-09-15 22:53:33 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-09-15 23:15:29 +0200 |
commit | 6e73af25c5008b4330ad14b5e22b94fff8771eb9 (patch) | |
tree | 5280c88dba6bd81be96db8d052759653515d4bf3 /src/netlink.c | |
parent | 8118c247a75ae95169f0a9a539dfc661ffda8bc5 (diff) |
global: support binding the transport socket to a device
This patch depends on da5095d052860baa7fe2932fb1209628dd3e3813
from udp_tunnel module, and allows to bind the transport socket
to a specific interface.
With this patch, it is possible to use wireguard with VRFs:
The transport uses a separate "WAN" VRF, cleanly isolating
Local/VPN and WAN Routing.
The userspace API is designed to transmit the device index of
the device to listen on. Listening on a device does only work if
the socketdev_index is set/changed before the socket is brought up.
Signed-off-by: Marvin Gaube <dev@marvingaube.de>
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/netlink.c b/src/netlink.c index ef239ab..573df1a 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -25,7 +25,8 @@ static const struct nla_policy device_policy[WGDEVICE_A_MAX + 1] = { [WGDEVICE_A_FLAGS] = { .type = NLA_U32 }, [WGDEVICE_A_LISTEN_PORT] = { .type = NLA_U16 }, [WGDEVICE_A_FWMARK] = { .type = NLA_U32 }, - [WGDEVICE_A_PEERS] = { .type = NLA_NESTED } + [WGDEVICE_A_PEERS] = { .type = NLA_NESTED }, + [WGDEVICE_A_SOCKETDEV_INDEX] = { .type = NLA_U32 } }; static const struct nla_policy peer_policy[WGPEER_A_MAX + 1] = { @@ -230,6 +231,7 @@ static int wg_get_device_dump(struct sk_buff *skb, struct netlink_callback *cb) if (nla_put_u16(skb, WGDEVICE_A_LISTEN_PORT, wg->incoming_port) || nla_put_u32(skb, WGDEVICE_A_FWMARK, wg->fwmark) || + nla_put_u32(skb, WGDEVICE_A_SOCKETDEV_INDEX, wg->socketdev_index) || nla_put_u32(skb, WGDEVICE_A_IFINDEX, wg->dev->ifindex) || nla_put_string(skb, WGDEVICE_A_IFNAME, wg->dev->name)) goto out; @@ -536,6 +538,10 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info) goto out; } + if (info->attrs[WGDEVICE_A_SOCKETDEV_INDEX]) { + wg->socketdev_index = nla_get_u32(info->attrs[WGDEVICE_A_SOCKETDEV_INDEX]); + } + if (flags & WGDEVICE_F_REPLACE_PEERS) wg_peer_remove_all(wg); |