1a4e21405SAaron LI /*- 2a4e21405SAaron LI * SPDX-License-Identifier: ISC 3a6bca3d2SAaron LI * 4a4e21405SAaron LI * Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. 5a4e21405SAaron LI * Copyright (C) 2019-2020 Matt Dunwoodie <ncon@noconroy.net> 6a6bca3d2SAaron LI * 7a6bca3d2SAaron LI * Permission to use, copy, modify, and distribute this software for any 8a6bca3d2SAaron LI * purpose with or without fee is hereby granted, provided that the above 9a6bca3d2SAaron LI * copyright notice and this permission notice appear in all copies. 10a6bca3d2SAaron LI * 11a6bca3d2SAaron LI * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12a6bca3d2SAaron LI * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13a6bca3d2SAaron LI * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14a6bca3d2SAaron LI * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15a6bca3d2SAaron LI * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16a6bca3d2SAaron LI * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17a6bca3d2SAaron LI * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18a6bca3d2SAaron LI */ 19a4e21405SAaron LI /* 20a4e21405SAaron LI * This is the public interface to the WireGuard network interface. 21a4e21405SAaron LI * 22a4e21405SAaron LI * It is designed to be used by tools such as ifconfig(8) and wg(8). 23a4e21405SAaron LI */ 24a6bca3d2SAaron LI 25a364ee04SAaron LI #ifndef _NET_IF_WG_H_ 26a364ee04SAaron LI #define _NET_IF_WG_H_ 27a6bca3d2SAaron LI 28a4e21405SAaron LI #include <sys/ioccom.h> 29a4e21405SAaron LI #include <sys/time.h> 30a6bca3d2SAaron LI #include <net/if.h> 31a6bca3d2SAaron LI #include <netinet/in.h> 32a6bca3d2SAaron LI 33a6bca3d2SAaron LI #define WG_KEY_SIZE 32 34a6bca3d2SAaron LI 35a4e21405SAaron LI /* Maximum length of the peer description, including the terminating NUL. */ 36a4e21405SAaron LI #define WG_PEER_DESCR_SIZE 64 37a4e21405SAaron LI 38a6bca3d2SAaron LI #define SIOCSWG _IOWR('i', 210, struct wg_data_io) 39a6bca3d2SAaron LI #define SIOCGWG _IOWR('i', 211, struct wg_data_io) 40a6bca3d2SAaron LI 41a4e21405SAaron LI struct wg_aip_io { 42a4e21405SAaron LI sa_family_t a_af; 43a4e21405SAaron LI int a_cidr; 44a4e21405SAaron LI union { 45a4e21405SAaron LI struct in_addr addr_ipv4; 46a4e21405SAaron LI struct in6_addr addr_ipv6; 47a4e21405SAaron LI } a_addr; 48a4e21405SAaron LI }; 49a4e21405SAaron LI 50a4e21405SAaron LI #define a_ipv4 a_addr.addr_ipv4 51a4e21405SAaron LI #define a_ipv6 a_addr.addr_ipv6 52a4e21405SAaron LI 53a4e21405SAaron LI struct wg_peer_io { 54a4e21405SAaron LI int p_flags; /* WG_PEER_* */ 55a4e21405SAaron LI uint8_t p_public[WG_KEY_SIZE]; 56a4e21405SAaron LI uint8_t p_psk[WG_KEY_SIZE]; /* preshared key */ 57a4e21405SAaron LI uint16_t p_pka; /* persistent keepalive */ 58a4e21405SAaron LI union { 59a4e21405SAaron LI struct sockaddr sa_sa; 60a4e21405SAaron LI struct sockaddr_in sa_sin; 61a4e21405SAaron LI struct sockaddr_in6 sa_sin6; 62a4e21405SAaron LI } p_endpoint; 63a4e21405SAaron LI uint64_t p_txbytes; 64a4e21405SAaron LI uint64_t p_rxbytes; 65a4e21405SAaron LI struct timespec p_last_handshake; /* nanotime */ 66*1671e443SAaron LI uint64_t p_id; 67a4e21405SAaron LI char p_description[WG_PEER_DESCR_SIZE]; 68a4e21405SAaron LI size_t p_aips_count; 69a4e21405SAaron LI struct wg_aip_io p_aips[]; 70a4e21405SAaron LI }; 71a4e21405SAaron LI 72a4e21405SAaron LI #define p_sa p_endpoint.sa_sa 73a4e21405SAaron LI #define p_sin p_endpoint.sa_sin 74a4e21405SAaron LI #define p_sin6 p_endpoint.sa_sin6 75a4e21405SAaron LI 76a4e21405SAaron LI #define WG_PEER_HAS_PUBLIC (1 << 0) 77a4e21405SAaron LI #define WG_PEER_HAS_PSK (1 << 1) 78a4e21405SAaron LI #define WG_PEER_HAS_PKA (1 << 2) 79a4e21405SAaron LI #define WG_PEER_HAS_ENDPOINT (1 << 3) 80a4e21405SAaron LI #define WG_PEER_REPLACE_AIPS (1 << 4) 81a4e21405SAaron LI #define WG_PEER_REMOVE (1 << 5) 82a4e21405SAaron LI #define WG_PEER_UPDATE (1 << 6) 83a4e21405SAaron LI #define WG_PEER_SET_DESCRIPTION (1 << 7) 84a4e21405SAaron LI 85a4e21405SAaron LI struct wg_interface_io { 86a4e21405SAaron LI int i_flags; /* WG_INTERFACE_* */ 87a4e21405SAaron LI in_port_t i_port; 88a4e21405SAaron LI uint32_t i_cookie; 89a4e21405SAaron LI uint8_t i_public[WG_KEY_SIZE]; 90a4e21405SAaron LI uint8_t i_private[WG_KEY_SIZE]; 91a4e21405SAaron LI size_t i_peers_count; 92a4e21405SAaron LI struct wg_peer_io i_peers[]; 93a4e21405SAaron LI }; 94a4e21405SAaron LI 95a4e21405SAaron LI #define WG_INTERFACE_HAS_PUBLIC (1 << 0) 96a4e21405SAaron LI #define WG_INTERFACE_HAS_PRIVATE (1 << 1) 97a4e21405SAaron LI #define WG_INTERFACE_HAS_PORT (1 << 2) 98a4e21405SAaron LI #define WG_INTERFACE_HAS_COOKIE (1 << 3) 99a4e21405SAaron LI #define WG_INTERFACE_REPLACE_PEERS (1 << 4) 100a4e21405SAaron LI 101a4e21405SAaron LI struct wg_data_io { 102a4e21405SAaron LI char wgd_name[IFNAMSIZ]; 103a4e21405SAaron LI size_t wgd_size; /* size of wgd_interface */ 104a4e21405SAaron LI struct wg_interface_io *wgd_interface; 105a4e21405SAaron LI }; 106a4e21405SAaron LI 107a364ee04SAaron LI #endif /* _NET_IF_WG_H_ */ 108