aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-05 22:59:40 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-10-05 22:59:40 +0200
commitc211f7d1e2c27e22e11581bef5a847582b26c08b (patch)
tree0b4be584f3dffab7baf153e51c09f161742fdc8c
parentMakefile: clang now builds the kernel, so use scan-build (diff)
downloadwireguard-monolithic-historical-c211f7d1e2c27e22e11581bef5a847582b26c08b.tar.xz
wireguard-monolithic-historical-c211f7d1e2c27e22e11581bef5a847582b26c08b.zip
compat: macro rewrite netlink instead of cluttering
-rw-r--r--src/compat/compat.h13
-rw-r--r--src/netlink.c29
2 files changed, 23 insertions, 19 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index b422c6d..c75bfe3 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -440,6 +440,19 @@ static inline struct nlattr **genl_family_attrbuf(const struct genl_family *fami
#endif
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
+#define get_device_dump(a, b) get_device_dump_real(a, b); \
+static int get_device_dump(a, b) { \
+ struct wireguard_device *wg = (struct wireguard_device *)cb->args[0]; \
+ if (!wg) { \
+ int ret = get_device_start(cb); \
+ if (ret) \
+ return ret; \
+ } \
+ return get_device_dump_real(skb, cb); \
+} \
+static int get_device_dump_real(a, b)
+#endif
/* https://lkml.org/lkml/2017/6/23/790 */
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
diff --git a/src/netlink.c b/src/netlink.c
index 8734ddd..b813508 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -141,7 +141,7 @@ err:
return -EMSGSIZE;
}
-static int get_start(struct netlink_callback *cb)
+static int get_device_start(struct netlink_callback *cb)
{
struct wireguard_device *wg;
struct nlattr **attrs = genl_family_attrbuf(&genl_family);
@@ -156,7 +156,7 @@ static int get_start(struct netlink_callback *cb)
return 0;
}
-static int get(struct sk_buff *skb, struct netlink_callback *cb)
+static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
{
struct wireguard_device *wg = (struct wireguard_device *)cb->args[0];
struct wireguard_peer *peer, *next_peer_cursor = NULL, *last_peer_cursor = (struct wireguard_peer *)cb->args[1];
@@ -166,15 +166,6 @@ static int get(struct sk_buff *skb, struct netlink_callback *cb)
void *hdr;
int ret = -EMSGSIZE;
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
- if (!wg) {
- ret = get_start(cb);
- if (ret)
- return ret;
- return get(skb, cb);
- }
-#endif
-
rtnl_lock();
mutex_lock(&wg->device_update_lock);
cb->seq = wg->device_update_gen;
@@ -245,7 +236,7 @@ out:
* in the kernel for marking skbs as zero_on_free. */
}
-static int get_done(struct netlink_callback *cb)
+static int get_device_done(struct netlink_callback *cb)
{
struct wireguard_device *wg = (struct wireguard_device *)cb->args[0];
struct wireguard_peer *peer = (struct wireguard_peer *)cb->args[1];
@@ -256,7 +247,7 @@ static int get_done(struct netlink_callback *cb)
return 0;
}
-static int set_device_port(struct wireguard_device *wg, u16 port)
+static int set_port(struct wireguard_device *wg, u16 port)
{
struct wireguard_peer *peer, *temp;
@@ -385,7 +376,7 @@ out:
return ret;
}
-static int set(struct sk_buff *skb, struct genl_info *info)
+static int set_device(struct sk_buff *skb, struct genl_info *info)
{
int ret;
struct wireguard_device *wg = lookup_interface(info->attrs, skb);
@@ -407,7 +398,7 @@ static int set(struct sk_buff *skb, struct genl_info *info)
}
if (info->attrs[WGDEVICE_A_LISTEN_PORT]) {
- ret = set_device_port(wg, nla_get_u16(info->attrs[WGDEVICE_A_LISTEN_PORT]));
+ ret = set_port(wg, nla_get_u16(info->attrs[WGDEVICE_A_LISTEN_PORT]));
if (ret)
goto out;
}
@@ -461,15 +452,15 @@ static const struct genl_ops genl_ops[] = {
{
.cmd = WG_CMD_GET_DEVICE,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
- .start = get_start,
+ .start = get_device_start,
#endif
- .dumpit = get,
- .done = get_done,
+ .dumpit = get_device_dump,
+ .done = get_device_done,
.policy = device_policy,
.flags = GENL_UNS_ADMIN_PERM
}, {
.cmd = WG_CMD_SET_DEVICE,
- .doit = set,
+ .doit = set_device,
.policy = device_policy,
.flags = GENL_UNS_ADMIN_PERM
}