99#include "socket.h"
1010#include "queueing.h"
1111#include "messages.h"
12+ #include "generated/netlink.h"
1213
1314#include <uapi/linux/wireguard.h>
1415
1819#include <crypto/utils.h>
1920
2021static struct genl_family genl_family ;
21- static const struct nla_policy peer_policy [WGPEER_A_MAX + 1 ];
22- static const struct nla_policy allowedip_policy [WGALLOWEDIP_A_MAX + 1 ];
23-
24- static const struct nla_policy device_policy [WGDEVICE_A_MAX + 1 ] = {
25- [WGDEVICE_A_IFINDEX ] = { .type = NLA_U32 },
26- [WGDEVICE_A_IFNAME ] = { .type = NLA_NUL_STRING , .len = IFNAMSIZ - 1 },
27- [WGDEVICE_A_PRIVATE_KEY ] = NLA_POLICY_EXACT_LEN (WG_KEY_LEN ),
28- [WGDEVICE_A_PUBLIC_KEY ] = NLA_POLICY_EXACT_LEN (WG_KEY_LEN ),
29- [WGDEVICE_A_FLAGS ] = NLA_POLICY_MASK (NLA_U32 , 0x1 ),
30- [WGDEVICE_A_LISTEN_PORT ] = { .type = NLA_U16 },
31- [WGDEVICE_A_FWMARK ] = { .type = NLA_U32 },
32- [WGDEVICE_A_PEERS ] = NLA_POLICY_NESTED_ARRAY (peer_policy ),
33- };
34-
35- static const struct nla_policy peer_policy [WGPEER_A_MAX + 1 ] = {
36- [WGPEER_A_PUBLIC_KEY ] = NLA_POLICY_EXACT_LEN (WG_KEY_LEN ),
37- [WGPEER_A_PRESHARED_KEY ] = NLA_POLICY_EXACT_LEN (WG_KEY_LEN ),
38- [WGPEER_A_FLAGS ] = NLA_POLICY_MASK (NLA_U32 , 0x7 ),
39- [WGPEER_A_ENDPOINT ] = NLA_POLICY_MIN_LEN (sizeof (struct sockaddr )),
40- [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL ] = { .type = NLA_U16 },
41- [WGPEER_A_LAST_HANDSHAKE_TIME ] = NLA_POLICY_EXACT_LEN (sizeof (struct __kernel_timespec )),
42- [WGPEER_A_RX_BYTES ] = { .type = NLA_U64 },
43- [WGPEER_A_TX_BYTES ] = { .type = NLA_U64 },
44- [WGPEER_A_ALLOWEDIPS ] = NLA_POLICY_NESTED_ARRAY (allowedip_policy ),
45- [WGPEER_A_PROTOCOL_VERSION ] = { .type = NLA_U32 }
46- };
47-
48- static const struct nla_policy allowedip_policy [WGALLOWEDIP_A_MAX + 1 ] = {
49- [WGALLOWEDIP_A_FAMILY ] = { .type = NLA_U16 },
50- [WGALLOWEDIP_A_IPADDR ] = NLA_POLICY_MIN_LEN (sizeof (struct in_addr )),
51- [WGALLOWEDIP_A_CIDR_MASK ] = { .type = NLA_U8 },
52- [WGALLOWEDIP_A_FLAGS ] = NLA_POLICY_MASK (NLA_U32 , 0x1 ),
53- };
5422
5523static struct wg_device * lookup_interface (struct nlattr * * attrs ,
5624 struct sk_buff * skb )
@@ -199,7 +167,7 @@ get_peer(struct wg_peer *peer, struct sk_buff *skb, struct dump_ctx *ctx)
199167 return - EMSGSIZE ;
200168}
201169
202- static int wg_get_device_start (struct netlink_callback * cb )
170+ int wg_get_device_start (struct netlink_callback * cb )
203171{
204172 struct wg_device * wg ;
205173
@@ -210,7 +178,7 @@ static int wg_get_device_start(struct netlink_callback *cb)
210178 return 0 ;
211179}
212180
213- static int wg_get_device_dump (struct sk_buff * skb , struct netlink_callback * cb )
181+ int wg_get_device_dumpit (struct sk_buff * skb , struct netlink_callback * cb )
214182{
215183 struct wg_peer * peer , * next_peer_cursor ;
216184 struct dump_ctx * ctx = DUMP_CTX (cb );
@@ -304,7 +272,7 @@ static int wg_get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
304272 */
305273}
306274
307- static int wg_get_device_done (struct netlink_callback * cb )
275+ int wg_get_device_done (struct netlink_callback * cb )
308276{
309277 struct dump_ctx * ctx = DUMP_CTX (cb );
310278
@@ -502,7 +470,7 @@ static int set_peer(struct wg_device *wg, struct nlattr **attrs)
502470 return ret ;
503471}
504472
505- static int wg_set_device (struct sk_buff * skb , struct genl_info * info )
473+ int wg_set_device_doit (struct sk_buff * skb , struct genl_info * info )
506474{
507475 struct wg_device * wg = lookup_interface (info -> attrs , skb );
508476 u32 flags = 0 ;
@@ -616,24 +584,6 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info)
616584 return ret ;
617585}
618586
619- static const struct genl_split_ops wireguard_nl_ops [] = {
620- {
621- .cmd = WG_CMD_GET_DEVICE ,
622- .start = wg_get_device_start ,
623- .dumpit = wg_get_device_dump ,
624- .done = wg_get_device_done ,
625- .policy = device_policy ,
626- .maxattr = WGDEVICE_A_IFNAME ,
627- .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DUMP ,
628- }, {
629- .cmd = WG_CMD_SET_DEVICE ,
630- .doit = wg_set_device ,
631- .policy = device_policy ,
632- .maxattr = WGDEVICE_A_PEERS ,
633- .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DO ,
634- }
635- };
636-
637587static struct genl_family genl_family __ro_after_init = {
638588 .split_ops = wireguard_nl_ops ,
639589 .n_split_ops = ARRAY_SIZE (wireguard_nl_ops ),
0 commit comments