197 lines · c
1/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */2/*3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.4 *5 * Documentation6 * =============7 *8 * The below enums and macros are for interfacing with WireGuard, using generic9 * netlink, with family WG_GENL_NAME and version WG_GENL_VERSION. It defines two10 * methods: get and set. Note that while they share many common attributes,11 * these two functions actually accept a slightly different set of inputs and12 * outputs.13 *14 * WG_CMD_GET_DEVICE15 * -----------------16 *17 * May only be called via NLM_F_REQUEST | NLM_F_DUMP. The command should contain18 * one but not both of:19 *20 * WGDEVICE_A_IFINDEX: NLA_U3221 * WGDEVICE_A_IFNAME: NLA_NUL_STRING, maxlen IFNAMSIZ - 122 *23 * The kernel will then return several messages (NLM_F_MULTI) containing the24 * following tree of nested items:25 *26 * WGDEVICE_A_IFINDEX: NLA_U3227 * WGDEVICE_A_IFNAME: NLA_NUL_STRING, maxlen IFNAMSIZ - 128 * WGDEVICE_A_PRIVATE_KEY: NLA_EXACT_LEN, len WG_KEY_LEN29 * WGDEVICE_A_PUBLIC_KEY: NLA_EXACT_LEN, len WG_KEY_LEN30 * WGDEVICE_A_LISTEN_PORT: NLA_U1631 * WGDEVICE_A_FWMARK: NLA_U3232 * WGDEVICE_A_PEERS: NLA_NESTED33 * 0: NLA_NESTED34 * WGPEER_A_PUBLIC_KEY: NLA_EXACT_LEN, len WG_KEY_LEN35 * WGPEER_A_PRESHARED_KEY: NLA_EXACT_LEN, len WG_KEY_LEN36 * WGPEER_A_ENDPOINT: NLA_MIN_LEN(struct sockaddr), struct sockaddr_in or struct sockaddr_in637 * WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL: NLA_U1638 * WGPEER_A_LAST_HANDSHAKE_TIME: NLA_EXACT_LEN, struct __kernel_timespec39 * WGPEER_A_RX_BYTES: NLA_U6440 * WGPEER_A_TX_BYTES: NLA_U6441 * WGPEER_A_ALLOWEDIPS: NLA_NESTED42 * 0: NLA_NESTED43 * WGALLOWEDIP_A_FAMILY: NLA_U1644 * WGALLOWEDIP_A_IPADDR: NLA_MIN_LEN(struct in_addr), struct in_addr or struct in6_addr45 * WGALLOWEDIP_A_CIDR_MASK: NLA_U846 * 0: NLA_NESTED47 * ...48 * 0: NLA_NESTED49 * ...50 * ...51 * WGPEER_A_PROTOCOL_VERSION: NLA_U3252 * 0: NLA_NESTED53 * ...54 * ...55 *56 * It is possible that all of the allowed IPs of a single peer will not57 * fit within a single netlink message. In that case, the same peer will58 * be written in the following message, except it will only contain59 * WGPEER_A_PUBLIC_KEY and WGPEER_A_ALLOWEDIPS. This may occur several60 * times in a row for the same peer. It is then up to the receiver to61 * coalesce adjacent peers. Likewise, it is possible that all peers will62 * not fit within a single message. So, subsequent peers will be sent63 * in following messages, except those will only contain WGDEVICE_A_IFNAME64 * and WGDEVICE_A_PEERS. It is then up to the receiver to coalesce these65 * messages to form the complete list of peers.66 *67 * Since this is an NLA_F_DUMP command, the final message will always be68 * NLMSG_DONE, even if an error occurs. However, this NLMSG_DONE message69 * contains an integer error code. It is either zero or a negative error70 * code corresponding to the errno.71 *72 * WG_CMD_SET_DEVICE73 * -----------------74 *75 * May only be called via NLM_F_REQUEST. The command should contain the76 * following tree of nested items, containing one but not both of77 * WGDEVICE_A_IFINDEX and WGDEVICE_A_IFNAME:78 *79 * WGDEVICE_A_IFINDEX: NLA_U3280 * WGDEVICE_A_IFNAME: NLA_NUL_STRING, maxlen IFNAMSIZ - 181 * WGDEVICE_A_FLAGS: NLA_U32, 0 or WGDEVICE_F_REPLACE_PEERS if all current82 * peers should be removed prior to adding the list below.83 * WGDEVICE_A_PRIVATE_KEY: len WG_KEY_LEN, all zeros to remove84 * WGDEVICE_A_LISTEN_PORT: NLA_U16, 0 to choose randomly85 * WGDEVICE_A_FWMARK: NLA_U32, 0 to disable86 * WGDEVICE_A_PEERS: NLA_NESTED87 * 0: NLA_NESTED88 * WGPEER_A_PUBLIC_KEY: len WG_KEY_LEN89 * WGPEER_A_FLAGS: NLA_U32, 0 and/or WGPEER_F_REMOVE_ME if the90 * specified peer should not exist at the end of the91 * operation, rather than added/updated and/or92 * WGPEER_F_REPLACE_ALLOWEDIPS if all current allowed93 * IPs of this peer should be removed prior to adding94 * the list below and/or WGPEER_F_UPDATE_ONLY if the95 * peer should only be set if it already exists.96 * WGPEER_A_PRESHARED_KEY: len WG_KEY_LEN, all zeros to remove97 * WGPEER_A_ENDPOINT: struct sockaddr_in or struct sockaddr_in698 * WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL: NLA_U16, 0 to disable99 * WGPEER_A_ALLOWEDIPS: NLA_NESTED100 * 0: NLA_NESTED101 * WGALLOWEDIP_A_FAMILY: NLA_U16102 * WGALLOWEDIP_A_IPADDR: struct in_addr or struct in6_addr103 * WGALLOWEDIP_A_CIDR_MASK: NLA_U8104 * 0: NLA_NESTED105 * ...106 * 0: NLA_NESTED107 * ...108 * ...109 * WGPEER_A_PROTOCOL_VERSION: NLA_U32, should not be set or used at110 * all by most users of this API, as the111 * most recent protocol will be used when112 * this is unset. Otherwise, must be set113 * to 1.114 * 0: NLA_NESTED115 * ...116 * ...117 *118 * It is possible that the amount of configuration data exceeds that of119 * the maximum message length accepted by the kernel. In that case, several120 * messages should be sent one after another, with each successive one121 * filling in information not contained in the prior. Note that if122 * WGDEVICE_F_REPLACE_PEERS is specified in the first message, it probably123 * should not be specified in fragments that come after, so that the list124 * of peers is only cleared the first time but appended after. Likewise for125 * peers, if WGPEER_F_REPLACE_ALLOWEDIPS is specified in the first message126 * of a peer, it likely should not be specified in subsequent fragments.127 *128 * If an error occurs, NLMSG_ERROR will reply containing an errno.129 */130 131#ifndef _WG_UAPI_WIREGUARD_H132#define _WG_UAPI_WIREGUARD_H133 134#define WG_GENL_NAME "wireguard"135#define WG_GENL_VERSION 1136 137#define WG_KEY_LEN 32138 139enum wg_cmd {140 WG_CMD_GET_DEVICE,141 WG_CMD_SET_DEVICE,142 __WG_CMD_MAX143};144#define WG_CMD_MAX (__WG_CMD_MAX - 1)145 146enum wgdevice_flag {147 WGDEVICE_F_REPLACE_PEERS = 1U << 0,148 __WGDEVICE_F_ALL = WGDEVICE_F_REPLACE_PEERS149};150enum wgdevice_attribute {151 WGDEVICE_A_UNSPEC,152 WGDEVICE_A_IFINDEX,153 WGDEVICE_A_IFNAME,154 WGDEVICE_A_PRIVATE_KEY,155 WGDEVICE_A_PUBLIC_KEY,156 WGDEVICE_A_FLAGS,157 WGDEVICE_A_LISTEN_PORT,158 WGDEVICE_A_FWMARK,159 WGDEVICE_A_PEERS,160 __WGDEVICE_A_LAST161};162#define WGDEVICE_A_MAX (__WGDEVICE_A_LAST - 1)163 164enum wgpeer_flag {165 WGPEER_F_REMOVE_ME = 1U << 0,166 WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,167 WGPEER_F_UPDATE_ONLY = 1U << 2,168 __WGPEER_F_ALL = WGPEER_F_REMOVE_ME | WGPEER_F_REPLACE_ALLOWEDIPS |169 WGPEER_F_UPDATE_ONLY170};171enum wgpeer_attribute {172 WGPEER_A_UNSPEC,173 WGPEER_A_PUBLIC_KEY,174 WGPEER_A_PRESHARED_KEY,175 WGPEER_A_FLAGS,176 WGPEER_A_ENDPOINT,177 WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,178 WGPEER_A_LAST_HANDSHAKE_TIME,179 WGPEER_A_RX_BYTES,180 WGPEER_A_TX_BYTES,181 WGPEER_A_ALLOWEDIPS,182 WGPEER_A_PROTOCOL_VERSION,183 __WGPEER_A_LAST184};185#define WGPEER_A_MAX (__WGPEER_A_LAST - 1)186 187enum wgallowedip_attribute {188 WGALLOWEDIP_A_UNSPEC,189 WGALLOWEDIP_A_FAMILY,190 WGALLOWEDIP_A_IPADDR,191 WGALLOWEDIP_A_CIDR_MASK,192 __WGALLOWEDIP_A_LAST193};194#define WGALLOWEDIP_A_MAX (__WGALLOWEDIP_A_LAST - 1)195 196#endif /* _WG_UAPI_WIREGUARD_H */197