Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wireguard: netlink: generate netlink code

This patch adopts netlink policies and command definitions
generated by ynl-gen, thus completing the conversion to YNL.

Given that the old and new policies are functionally identical
and have just been moved to a new file, it serves to verify
that the policies generated from the spec are identical to the
previous policy code.

The following functions are renamed:
wg_get_device_dump() -> wg_get_device_dumpit()
wg_set_device() -> wg_set_device_doit()

The new files are covered by the existing drivers/net/wireguard/
pattern in MAINTAINERS.

No behavioural changes intended.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

authored by

Asbjørn Sloth Tønnesen and committed by
Jason A. Donenfeld
3fd2f3d2 88cedad4

+109 -56
+1 -1
drivers/net/wireguard/Makefile
··· 13 13 wireguard-y += allowedips.o 14 14 wireguard-y += ratelimiter.o 15 15 wireguard-y += cookie.o 16 - wireguard-y += netlink.o 16 + wireguard-y += netlink.o generated/netlink.o 17 17 obj-$(CONFIG_WIREGUARD) := wireguard.o
+73
drivers/net/wireguard/generated/netlink.c
··· 1 + // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 2 + /* Do not edit directly, auto-generated from: */ 3 + /* Documentation/netlink/specs/wireguard.yaml */ 4 + /* YNL-GEN kernel source */ 5 + /* YNL-ARG --function-prefix wg */ 6 + /* To regenerate run: tools/net/ynl/ynl-regen.sh */ 7 + 8 + #include <net/netlink.h> 9 + #include <net/genetlink.h> 10 + 11 + #include "netlink.h" 12 + 13 + #include <uapi/linux/wireguard.h> 14 + #include <linux/time_types.h> 15 + 16 + /* Common nested types */ 17 + const struct nla_policy wireguard_wgallowedip_nl_policy[WGALLOWEDIP_A_FLAGS + 1] = { 18 + [WGALLOWEDIP_A_FAMILY] = { .type = NLA_U16, }, 19 + [WGALLOWEDIP_A_IPADDR] = NLA_POLICY_MIN_LEN(4), 20 + [WGALLOWEDIP_A_CIDR_MASK] = { .type = NLA_U8, }, 21 + [WGALLOWEDIP_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x1), 22 + }; 23 + 24 + const struct nla_policy wireguard_wgpeer_nl_policy[WGPEER_A_PROTOCOL_VERSION + 1] = { 25 + [WGPEER_A_PUBLIC_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 26 + [WGPEER_A_PRESHARED_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 27 + [WGPEER_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x7), 28 + [WGPEER_A_ENDPOINT] = NLA_POLICY_MIN_LEN(16), 29 + [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NLA_U16, }, 30 + [WGPEER_A_LAST_HANDSHAKE_TIME] = NLA_POLICY_EXACT_LEN(16), 31 + [WGPEER_A_RX_BYTES] = { .type = NLA_U64, }, 32 + [WGPEER_A_TX_BYTES] = { .type = NLA_U64, }, 33 + [WGPEER_A_ALLOWEDIPS] = NLA_POLICY_NESTED_ARRAY(wireguard_wgallowedip_nl_policy), 34 + [WGPEER_A_PROTOCOL_VERSION] = { .type = NLA_U32, }, 35 + }; 36 + 37 + /* WG_CMD_GET_DEVICE - dump */ 38 + static const struct nla_policy wireguard_get_device_nl_policy[WGDEVICE_A_IFNAME + 1] = { 39 + [WGDEVICE_A_IFINDEX] = { .type = NLA_U32, }, 40 + [WGDEVICE_A_IFNAME] = { .type = NLA_NUL_STRING, .len = 15, }, 41 + }; 42 + 43 + /* WG_CMD_SET_DEVICE - do */ 44 + static const struct nla_policy wireguard_set_device_nl_policy[WGDEVICE_A_PEERS + 1] = { 45 + [WGDEVICE_A_IFINDEX] = { .type = NLA_U32, }, 46 + [WGDEVICE_A_IFNAME] = { .type = NLA_NUL_STRING, .len = 15, }, 47 + [WGDEVICE_A_PRIVATE_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 48 + [WGDEVICE_A_PUBLIC_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 49 + [WGDEVICE_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x1), 50 + [WGDEVICE_A_LISTEN_PORT] = { .type = NLA_U16, }, 51 + [WGDEVICE_A_FWMARK] = { .type = NLA_U32, }, 52 + [WGDEVICE_A_PEERS] = NLA_POLICY_NESTED_ARRAY(wireguard_wgpeer_nl_policy), 53 + }; 54 + 55 + /* Ops table for wireguard */ 56 + const struct genl_split_ops wireguard_nl_ops[2] = { 57 + { 58 + .cmd = WG_CMD_GET_DEVICE, 59 + .start = wg_get_device_start, 60 + .dumpit = wg_get_device_dumpit, 61 + .done = wg_get_device_done, 62 + .policy = wireguard_get_device_nl_policy, 63 + .maxattr = WGDEVICE_A_IFNAME, 64 + .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DUMP, 65 + }, 66 + { 67 + .cmd = WG_CMD_SET_DEVICE, 68 + .doit = wg_set_device_doit, 69 + .policy = wireguard_set_device_nl_policy, 70 + .maxattr = WGDEVICE_A_PEERS, 71 + .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DO, 72 + }, 73 + };
+30
drivers/net/wireguard/generated/netlink.h
··· 1 + /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ 2 + /* Do not edit directly, auto-generated from: */ 3 + /* Documentation/netlink/specs/wireguard.yaml */ 4 + /* YNL-GEN kernel header */ 5 + /* YNL-ARG --function-prefix wg */ 6 + /* To regenerate run: tools/net/ynl/ynl-regen.sh */ 7 + 8 + #ifndef _LINUX_WIREGUARD_GEN_H 9 + #define _LINUX_WIREGUARD_GEN_H 10 + 11 + #include <net/netlink.h> 12 + #include <net/genetlink.h> 13 + 14 + #include <uapi/linux/wireguard.h> 15 + #include <linux/time_types.h> 16 + 17 + /* Common nested types */ 18 + extern const struct nla_policy wireguard_wgallowedip_nl_policy[WGALLOWEDIP_A_FLAGS + 1]; 19 + extern const struct nla_policy wireguard_wgpeer_nl_policy[WGPEER_A_PROTOCOL_VERSION + 1]; 20 + 21 + /* Ops table for wireguard */ 22 + extern const struct genl_split_ops wireguard_nl_ops[2]; 23 + 24 + int wg_get_device_start(struct netlink_callback *cb); 25 + int wg_get_device_done(struct netlink_callback *cb); 26 + 27 + int wg_get_device_dumpit(struct sk_buff *skb, struct netlink_callback *cb); 28 + int wg_set_device_doit(struct sk_buff *skb, struct genl_info *info); 29 + 30 + #endif /* _LINUX_WIREGUARD_GEN_H */
+5 -55
drivers/net/wireguard/netlink.c
··· 9 9 #include "socket.h" 10 10 #include "queueing.h" 11 11 #include "messages.h" 12 + #include "generated/netlink.h" 12 13 13 14 #include <uapi/linux/wireguard.h> 14 15 ··· 19 18 #include <crypto/utils.h> 20 19 21 20 static struct genl_family genl_family; 22 - static const struct nla_policy peer_policy[WGPEER_A_MAX + 1]; 23 - static const struct nla_policy allowedip_policy[WGALLOWEDIP_A_MAX + 1]; 24 - 25 - static const struct nla_policy device_policy[WGDEVICE_A_MAX + 1] = { 26 - [WGDEVICE_A_IFINDEX] = { .type = NLA_U32 }, 27 - [WGDEVICE_A_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, 28 - [WGDEVICE_A_PRIVATE_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 29 - [WGDEVICE_A_PUBLIC_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 30 - [WGDEVICE_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x1), 31 - [WGDEVICE_A_LISTEN_PORT] = { .type = NLA_U16 }, 32 - [WGDEVICE_A_FWMARK] = { .type = NLA_U32 }, 33 - [WGDEVICE_A_PEERS] = NLA_POLICY_NESTED_ARRAY(peer_policy), 34 - }; 35 - 36 - static const struct nla_policy peer_policy[WGPEER_A_MAX + 1] = { 37 - [WGPEER_A_PUBLIC_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 38 - [WGPEER_A_PRESHARED_KEY] = NLA_POLICY_EXACT_LEN(WG_KEY_LEN), 39 - [WGPEER_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x7), 40 - [WGPEER_A_ENDPOINT] = NLA_POLICY_MIN_LEN(sizeof(struct sockaddr)), 41 - [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NLA_U16 }, 42 - [WGPEER_A_LAST_HANDSHAKE_TIME] = NLA_POLICY_EXACT_LEN(sizeof(struct __kernel_timespec)), 43 - [WGPEER_A_RX_BYTES] = { .type = NLA_U64 }, 44 - [WGPEER_A_TX_BYTES] = { .type = NLA_U64 }, 45 - [WGPEER_A_ALLOWEDIPS] = NLA_POLICY_NESTED_ARRAY(allowedip_policy), 46 - [WGPEER_A_PROTOCOL_VERSION] = { .type = NLA_U32 } 47 - }; 48 - 49 - static const struct nla_policy allowedip_policy[WGALLOWEDIP_A_MAX + 1] = { 50 - [WGALLOWEDIP_A_FAMILY] = { .type = NLA_U16 }, 51 - [WGALLOWEDIP_A_IPADDR] = NLA_POLICY_MIN_LEN(sizeof(struct in_addr)), 52 - [WGALLOWEDIP_A_CIDR_MASK] = { .type = NLA_U8 }, 53 - [WGALLOWEDIP_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x1), 54 - }; 55 21 56 22 static struct wg_device *lookup_interface(struct nlattr **attrs, 57 23 struct sk_buff *skb) ··· 167 199 return -EMSGSIZE; 168 200 } 169 201 170 - static int wg_get_device_start(struct netlink_callback *cb) 202 + int wg_get_device_start(struct netlink_callback *cb) 171 203 { 172 204 struct wg_device *wg; 173 205 ··· 178 210 return 0; 179 211 } 180 212 181 - static int wg_get_device_dump(struct sk_buff *skb, struct netlink_callback *cb) 213 + int wg_get_device_dumpit(struct sk_buff *skb, struct netlink_callback *cb) 182 214 { 183 215 struct wg_peer *peer, *next_peer_cursor; 184 216 struct dump_ctx *ctx = DUMP_CTX(cb); ··· 272 304 */ 273 305 } 274 306 275 - static int wg_get_device_done(struct netlink_callback *cb) 307 + int wg_get_device_done(struct netlink_callback *cb) 276 308 { 277 309 struct dump_ctx *ctx = DUMP_CTX(cb); 278 310 ··· 470 502 return ret; 471 503 } 472 504 473 - static int wg_set_device(struct sk_buff *skb, struct genl_info *info) 505 + int wg_set_device_doit(struct sk_buff *skb, struct genl_info *info) 474 506 { 475 507 struct wg_device *wg = lookup_interface(info->attrs, skb); 476 508 u32 flags = 0; ··· 583 615 nla_len(info->attrs[WGDEVICE_A_PRIVATE_KEY])); 584 616 return ret; 585 617 } 586 - 587 - static const struct genl_split_ops wireguard_nl_ops[] = { 588 - { 589 - .cmd = WG_CMD_GET_DEVICE, 590 - .start = wg_get_device_start, 591 - .dumpit = wg_get_device_dump, 592 - .done = wg_get_device_done, 593 - .policy = device_policy, 594 - .maxattr = WGDEVICE_A_IFNAME, 595 - .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DUMP, 596 - }, { 597 - .cmd = WG_CMD_SET_DEVICE, 598 - .doit = wg_set_device, 599 - .policy = device_policy, 600 - .maxattr = WGDEVICE_A_PEERS, 601 - .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DO, 602 - } 603 - }; 604 618 605 619 static struct genl_family genl_family __ro_after_init = { 606 620 .split_ops = wireguard_nl_ops,