diff options
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); |