diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-09-15 23:15:20 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-09-15 23:15:32 +0200 |
commit | 1bf89e0aedbd05b24579e7cdc326182d55ac10d2 (patch) | |
tree | 23d63c5db5d144c3892eac72f7d096dace3d7e43 /src/netlink.c | |
parent | 6e73af25c5008b4330ad14b5e22b94fff8771eb9 (diff) |
global: support changing transport socketfeature/socketdev
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/netlink.c b/src/netlink.c index 573df1a..3021424 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -311,19 +311,20 @@ static int wg_get_device_done(struct netlink_callback *cb) return 0; } -static int set_port(struct wg_device *wg, u16 port) +static int set_port(struct wg_device *wg, u16 port, u32 dev) { struct wg_peer *peer; - if (wg->incoming_port == port) + if (wg->incoming_port == port && wg->socketdev_index == dev) return 0; list_for_each_entry(peer, &wg->peer_list, peer_list) wg_socket_clear_peer_endpoint_src(peer); if (!netif_running(wg->dev)) { wg->incoming_port = port; + wg->socketdev_index = dev; return 0; } - return wg_socket_init(wg, port); + return wg_socket_init(wg, port, dev); } static int set_allowedip(struct wg_peer *peer, struct nlattr **attrs) @@ -531,16 +532,21 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info) wg_socket_clear_peer_endpoint_src(peer); } - if (info->attrs[WGDEVICE_A_LISTEN_PORT]) { - ret = set_port(wg, - nla_get_u16(info->attrs[WGDEVICE_A_LISTEN_PORT])); + if (info->attrs[WGDEVICE_A_LISTEN_PORT] || info->attrs[WGDEVICE_A_SOCKETDEV_INDEX]) { + u16 port = wg->incoming_port; + u32 dev = wg->socketdev_index; + + if (info->attrs[WGDEVICE_A_LISTEN_PORT]) + port = nla_get_u16(info->attrs[WGDEVICE_A_LISTEN_PORT]); + + if (info->attrs[WGDEVICE_A_SOCKETDEV_INDEX]) + dev = nla_get_u32(info->attrs[WGDEVICE_A_SOCKETDEV_INDEX]); + + ret = set_port(wg, port, dev); if (ret) 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); |