mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 12:21:22 -05:00
This patch adds a near[1] complete YNL specification for WireGuard, documenting the protocol in a machine-readable format, rather than comments in wireguard.h, and eases usage from C and non-C programming languages alike. The generated C library will be featured in a later patch, so in this patch I will use the in-kernel python client for examples. This makes the documentation in the UAPI header redundant, it is therefore removed. The in-line documentation in the spec is based on the existing comment in wireguard.h, and once released it will be available in the kernel documentation at: https://docs.kernel.org/netlink/specs/wireguard.html (until then run: make htmldocs) Generate wireguard.rst from this spec: $ make -C tools/net/ynl/generated/ wireguard.rst Query wireguard interface through pyynl: $ sudo ./tools/net/ynl/pyynl/cli.py --family wireguard \ --dump get-device \ --json '{"ifindex":3}' [{'fwmark': 0, 'ifindex': 3, 'ifname': 'wg-test', 'listen-port': 54318, 'peers': [{0: {'allowedips': [{0: {'cidr-mask': 0, 'family': 2, 'ipaddr': '0.0.0.0'}}, {0: {'cidr-mask': 0, 'family': 10, 'ipaddr': '::'}}], 'endpoint': b'[...]', 'last-handshake-time': {'nsec': 42, 'sec': 42}, 'persistent-keepalive-interval': 42, 'preshared-key': '[...]', 'protocol-version': 1, 'public-key': '[...]', 'rx-bytes': 42, 'tx-bytes': 42}}], 'private-key': '[...]', 'public-key': '[...]'}] Add another allowed IP prefix: $ sudo ./tools/net/ynl/pyynl/cli.py --family wireguard \ --do set-device --json '{"ifindex":3,"peers":[ {"public-key":"6a df b1 83 a4 ..","allowedips":[ {"cidr-mask":0,"family":10,"ipaddr":"::"}]}]}' [1] As can be seen above, the "endpoint" is only dumped as binary data, as it can't be fully described in YNL. It's either a struct sockaddr_in or struct sockaddr_in6 depending on the attribute length. Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
77 lines
1.7 KiB
C
77 lines
1.7 KiB
C
/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
|
|
/*
|
|
* Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef _WG_UAPI_WIREGUARD_H
|
|
#define _WG_UAPI_WIREGUARD_H
|
|
|
|
#define WG_GENL_NAME "wireguard"
|
|
#define WG_GENL_VERSION 1
|
|
|
|
#define WG_KEY_LEN 32
|
|
|
|
enum wg_cmd {
|
|
WG_CMD_GET_DEVICE,
|
|
WG_CMD_SET_DEVICE,
|
|
__WG_CMD_MAX
|
|
};
|
|
#define WG_CMD_MAX (__WG_CMD_MAX - 1)
|
|
|
|
enum wgdevice_flag {
|
|
WGDEVICE_F_REPLACE_PEERS = 1U << 0,
|
|
__WGDEVICE_F_ALL = WGDEVICE_F_REPLACE_PEERS
|
|
};
|
|
enum wgdevice_attribute {
|
|
WGDEVICE_A_UNSPEC,
|
|
WGDEVICE_A_IFINDEX,
|
|
WGDEVICE_A_IFNAME,
|
|
WGDEVICE_A_PRIVATE_KEY,
|
|
WGDEVICE_A_PUBLIC_KEY,
|
|
WGDEVICE_A_FLAGS,
|
|
WGDEVICE_A_LISTEN_PORT,
|
|
WGDEVICE_A_FWMARK,
|
|
WGDEVICE_A_PEERS,
|
|
__WGDEVICE_A_LAST
|
|
};
|
|
#define WGDEVICE_A_MAX (__WGDEVICE_A_LAST - 1)
|
|
|
|
enum wgpeer_flag {
|
|
WGPEER_F_REMOVE_ME = 1U << 0,
|
|
WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,
|
|
WGPEER_F_UPDATE_ONLY = 1U << 2,
|
|
__WGPEER_F_ALL = WGPEER_F_REMOVE_ME | WGPEER_F_REPLACE_ALLOWEDIPS |
|
|
WGPEER_F_UPDATE_ONLY
|
|
};
|
|
enum wgpeer_attribute {
|
|
WGPEER_A_UNSPEC,
|
|
WGPEER_A_PUBLIC_KEY,
|
|
WGPEER_A_PRESHARED_KEY,
|
|
WGPEER_A_FLAGS,
|
|
WGPEER_A_ENDPOINT,
|
|
WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
|
|
WGPEER_A_LAST_HANDSHAKE_TIME,
|
|
WGPEER_A_RX_BYTES,
|
|
WGPEER_A_TX_BYTES,
|
|
WGPEER_A_ALLOWEDIPS,
|
|
WGPEER_A_PROTOCOL_VERSION,
|
|
__WGPEER_A_LAST
|
|
};
|
|
#define WGPEER_A_MAX (__WGPEER_A_LAST - 1)
|
|
|
|
enum wgallowedip_flag {
|
|
WGALLOWEDIP_F_REMOVE_ME = 1U << 0,
|
|
__WGALLOWEDIP_F_ALL = WGALLOWEDIP_F_REMOVE_ME
|
|
};
|
|
enum wgallowedip_attribute {
|
|
WGALLOWEDIP_A_UNSPEC,
|
|
WGALLOWEDIP_A_FAMILY,
|
|
WGALLOWEDIP_A_IPADDR,
|
|
WGALLOWEDIP_A_CIDR_MASK,
|
|
WGALLOWEDIP_A_FLAGS,
|
|
__WGALLOWEDIP_A_LAST
|
|
};
|
|
#define WGALLOWEDIP_A_MAX (__WGALLOWEDIP_A_LAST - 1)
|
|
|
|
#endif /* _WG_UAPI_WIREGUARD_H */
|