1f6eef2c2SGleb Smirnoff /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 43b3a8eb9SGleb Smirnoff * Copyright (c) 2001 Michael Shalayeff 53b3a8eb9SGleb Smirnoff * All rights reserved. 63b3a8eb9SGleb Smirnoff * 73b3a8eb9SGleb Smirnoff * Redistribution and use in source and binary forms, with or without 83b3a8eb9SGleb Smirnoff * modification, are permitted provided that the following conditions 93b3a8eb9SGleb Smirnoff * are met: 103b3a8eb9SGleb Smirnoff * 1. Redistributions of source code must retain the above copyright 113b3a8eb9SGleb Smirnoff * notice, this list of conditions and the following disclaimer. 123b3a8eb9SGleb Smirnoff * 2. Redistributions in binary form must reproduce the above copyright 133b3a8eb9SGleb Smirnoff * notice, this list of conditions and the following disclaimer in the 143b3a8eb9SGleb Smirnoff * documentation and/or other materials provided with the distribution. 153b3a8eb9SGleb Smirnoff * 163b3a8eb9SGleb Smirnoff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 173b3a8eb9SGleb Smirnoff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 183b3a8eb9SGleb Smirnoff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 193b3a8eb9SGleb Smirnoff * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 203b3a8eb9SGleb Smirnoff * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 213b3a8eb9SGleb Smirnoff * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 223b3a8eb9SGleb Smirnoff * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 233b3a8eb9SGleb Smirnoff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 243b3a8eb9SGleb Smirnoff * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 253b3a8eb9SGleb Smirnoff * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 263b3a8eb9SGleb Smirnoff * THE POSSIBILITY OF SUCH DAMAGE. 273b3a8eb9SGleb Smirnoff */ 283b3a8eb9SGleb Smirnoff 29f6eef2c2SGleb Smirnoff /*- 303b3a8eb9SGleb Smirnoff * Copyright (c) 2008 David Gwynne <dlg@openbsd.org> 313b3a8eb9SGleb Smirnoff * 323b3a8eb9SGleb Smirnoff * Permission to use, copy, modify, and distribute this software for any 333b3a8eb9SGleb Smirnoff * purpose with or without fee is hereby granted, provided that the above 343b3a8eb9SGleb Smirnoff * copyright notice and this permission notice appear in all copies. 353b3a8eb9SGleb Smirnoff * 363b3a8eb9SGleb Smirnoff * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 373b3a8eb9SGleb Smirnoff * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 383b3a8eb9SGleb Smirnoff * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 393b3a8eb9SGleb Smirnoff * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 403b3a8eb9SGleb Smirnoff * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 413b3a8eb9SGleb Smirnoff * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 423b3a8eb9SGleb Smirnoff * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 433b3a8eb9SGleb Smirnoff */ 443b3a8eb9SGleb Smirnoff 45f6eef2c2SGleb Smirnoff /* 46f6eef2c2SGleb Smirnoff * $OpenBSD: if_pfsync.h,v 1.35 2008/06/29 08:42:15 mcbride Exp $ 47f6eef2c2SGleb Smirnoff */ 48f6eef2c2SGleb Smirnoff 493b3a8eb9SGleb Smirnoff #ifndef _NET_IF_PFSYNC_H_ 503b3a8eb9SGleb Smirnoff #define _NET_IF_PFSYNC_H_ 513b3a8eb9SGleb Smirnoff 52e7809dceSKristof Provost #include <sys/types.h> 53e7809dceSKristof Provost 54e7809dceSKristof Provost #include <net/if.h> 55e7809dceSKristof Provost #include <net/pfvar.h> 56e7809dceSKristof Provost #include <netpfil/pf/pf.h> 57e7809dceSKristof Provost 583b3a8eb9SGleb Smirnoff #define PFSYNC_VERSION 5 593b3a8eb9SGleb Smirnoff #define PFSYNC_DFLTTL 255 603b3a8eb9SGleb Smirnoff 61*4bf98559SKajetan Staszkiewicz enum pfsync_msg_versions { 62*4bf98559SKajetan Staszkiewicz PFSYNC_MSG_VERSION_UNSPECIFIED = 0, 63*4bf98559SKajetan Staszkiewicz PFSYNC_MSG_VERSION_1301 = 1301, 64*4bf98559SKajetan Staszkiewicz PFSYNC_MSG_VERSION_1400 = 1400, 65*4bf98559SKajetan Staszkiewicz }; 66*4bf98559SKajetan Staszkiewicz 67*4bf98559SKajetan Staszkiewicz #define PFSYNC_MSG_VERSION_DEFAULT PFSYNC_MSG_VERSION_1400 68*4bf98559SKajetan Staszkiewicz 693b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_CLR 0 /* clear all states */ 70*4bf98559SKajetan Staszkiewicz #define PFSYNC_ACT_INS_1301 1 /* insert state */ 715666643aSGordon Bergling #define PFSYNC_ACT_INS_ACK 2 /* ack of inserted state */ 72*4bf98559SKajetan Staszkiewicz #define PFSYNC_ACT_UPD_1301 3 /* update state */ 733b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */ 743b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */ 753b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_DEL 6 /* delete state */ 763b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */ 773b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_INS_F 8 /* insert fragment */ 783b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_DEL_F 9 /* delete fragments */ 793b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_BUS 10 /* bulk update status */ 803b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_TDB 11 /* TDB replay counter update */ 813b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_EOF 12 /* end of frame */ 82*4bf98559SKajetan Staszkiewicz #define PFSYNC_ACT_INS_1400 13 /* insert state */ 83*4bf98559SKajetan Staszkiewicz #define PFSYNC_ACT_UPD_1400 14 /* update state */ 84*4bf98559SKajetan Staszkiewicz #define PFSYNC_ACT_MAX 15 853b3a8eb9SGleb Smirnoff 863b3a8eb9SGleb Smirnoff /* 873b3a8eb9SGleb Smirnoff * A pfsync frame is built from a header followed by several sections which 883b3a8eb9SGleb Smirnoff * are all prefixed with their own subheaders. Frames must be terminated with 893b3a8eb9SGleb Smirnoff * an EOF subheader. 903b3a8eb9SGleb Smirnoff * 913b3a8eb9SGleb Smirnoff * | ... | 923b3a8eb9SGleb Smirnoff * | IP header | 933b3a8eb9SGleb Smirnoff * +============================+ 943b3a8eb9SGleb Smirnoff * | pfsync_header | 953b3a8eb9SGleb Smirnoff * +----------------------------+ 963b3a8eb9SGleb Smirnoff * | pfsync_subheader | 973b3a8eb9SGleb Smirnoff * +----------------------------+ 983b3a8eb9SGleb Smirnoff * | first action fields | 993b3a8eb9SGleb Smirnoff * | ... | 1003b3a8eb9SGleb Smirnoff * +----------------------------+ 1013b3a8eb9SGleb Smirnoff * | pfsync_subheader | 1023b3a8eb9SGleb Smirnoff * +----------------------------+ 1033b3a8eb9SGleb Smirnoff * | second action fields | 1043b3a8eb9SGleb Smirnoff * | ... | 1053b3a8eb9SGleb Smirnoff * +----------------------------+ 1063b3a8eb9SGleb Smirnoff * | EOF pfsync_subheader | 1073b3a8eb9SGleb Smirnoff * +----------------------------+ 1083b3a8eb9SGleb Smirnoff * | HMAC | 1093b3a8eb9SGleb Smirnoff * +============================+ 1103b3a8eb9SGleb Smirnoff */ 1113b3a8eb9SGleb Smirnoff 1123b3a8eb9SGleb Smirnoff /* 1133b3a8eb9SGleb Smirnoff * Frame header 1143b3a8eb9SGleb Smirnoff */ 1153b3a8eb9SGleb Smirnoff 1163b3a8eb9SGleb Smirnoff struct pfsync_header { 1173b3a8eb9SGleb Smirnoff u_int8_t version; 1183b3a8eb9SGleb Smirnoff u_int8_t _pad; 1193b3a8eb9SGleb Smirnoff u_int16_t len; 1203b3a8eb9SGleb Smirnoff u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH]; 1213b3a8eb9SGleb Smirnoff } __packed; 1223b3a8eb9SGleb Smirnoff 1233b3a8eb9SGleb Smirnoff /* 1243b3a8eb9SGleb Smirnoff * Frame region subheader 1253b3a8eb9SGleb Smirnoff */ 1263b3a8eb9SGleb Smirnoff 1273b3a8eb9SGleb Smirnoff struct pfsync_subheader { 1283b3a8eb9SGleb Smirnoff u_int8_t action; 1293b3a8eb9SGleb Smirnoff u_int8_t _pad; 1303b3a8eb9SGleb Smirnoff u_int16_t count; 1313b3a8eb9SGleb Smirnoff } __packed; 1323b3a8eb9SGleb Smirnoff 1333b3a8eb9SGleb Smirnoff /* 1343b3a8eb9SGleb Smirnoff * CLR 1353b3a8eb9SGleb Smirnoff */ 1363b3a8eb9SGleb Smirnoff 1373b3a8eb9SGleb Smirnoff struct pfsync_clr { 1383b3a8eb9SGleb Smirnoff char ifname[IFNAMSIZ]; 1393b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1403b3a8eb9SGleb Smirnoff } __packed; 1413b3a8eb9SGleb Smirnoff 1423b3a8eb9SGleb Smirnoff /* 1433b3a8eb9SGleb Smirnoff * INS, UPD, DEL 1443b3a8eb9SGleb Smirnoff */ 1453b3a8eb9SGleb Smirnoff 1463b3a8eb9SGleb Smirnoff /* these use struct pfsync_state in pfvar.h */ 1473b3a8eb9SGleb Smirnoff 1483b3a8eb9SGleb Smirnoff /* 1493b3a8eb9SGleb Smirnoff * INS_ACK 1503b3a8eb9SGleb Smirnoff */ 1513b3a8eb9SGleb Smirnoff 1523b3a8eb9SGleb Smirnoff struct pfsync_ins_ack { 1533b3a8eb9SGleb Smirnoff u_int64_t id; 1543b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1553b3a8eb9SGleb Smirnoff } __packed; 1563b3a8eb9SGleb Smirnoff 1573b3a8eb9SGleb Smirnoff /* 1583b3a8eb9SGleb Smirnoff * UPD_C 1593b3a8eb9SGleb Smirnoff */ 1603b3a8eb9SGleb Smirnoff 1613b3a8eb9SGleb Smirnoff struct pfsync_upd_c { 1623b3a8eb9SGleb Smirnoff u_int64_t id; 1633b3a8eb9SGleb Smirnoff struct pfsync_state_peer src; 1643b3a8eb9SGleb Smirnoff struct pfsync_state_peer dst; 1653b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1663b3a8eb9SGleb Smirnoff u_int32_t expire; 1673b3a8eb9SGleb Smirnoff u_int8_t timeout; 1683b3a8eb9SGleb Smirnoff u_int8_t _pad[3]; 1693b3a8eb9SGleb Smirnoff } __packed; 1703b3a8eb9SGleb Smirnoff 1713b3a8eb9SGleb Smirnoff /* 1723b3a8eb9SGleb Smirnoff * UPD_REQ 1733b3a8eb9SGleb Smirnoff */ 1743b3a8eb9SGleb Smirnoff 1753b3a8eb9SGleb Smirnoff struct pfsync_upd_req { 1763b3a8eb9SGleb Smirnoff u_int64_t id; 1773b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1783b3a8eb9SGleb Smirnoff } __packed; 1793b3a8eb9SGleb Smirnoff 1803b3a8eb9SGleb Smirnoff /* 1813b3a8eb9SGleb Smirnoff * DEL_C 1823b3a8eb9SGleb Smirnoff */ 1833b3a8eb9SGleb Smirnoff 1843b3a8eb9SGleb Smirnoff struct pfsync_del_c { 1853b3a8eb9SGleb Smirnoff u_int64_t id; 1863b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1873b3a8eb9SGleb Smirnoff } __packed; 1883b3a8eb9SGleb Smirnoff 1893b3a8eb9SGleb Smirnoff /* 1903b3a8eb9SGleb Smirnoff * INS_F, DEL_F 1913b3a8eb9SGleb Smirnoff */ 1923b3a8eb9SGleb Smirnoff 1933b3a8eb9SGleb Smirnoff /* not implemented (yet) */ 1943b3a8eb9SGleb Smirnoff 1953b3a8eb9SGleb Smirnoff /* 1963b3a8eb9SGleb Smirnoff * BUS 1973b3a8eb9SGleb Smirnoff */ 1983b3a8eb9SGleb Smirnoff 1993b3a8eb9SGleb Smirnoff struct pfsync_bus { 2003b3a8eb9SGleb Smirnoff u_int32_t creatorid; 2013b3a8eb9SGleb Smirnoff u_int32_t endtime; 2023b3a8eb9SGleb Smirnoff u_int8_t status; 2033b3a8eb9SGleb Smirnoff #define PFSYNC_BUS_START 1 2043b3a8eb9SGleb Smirnoff #define PFSYNC_BUS_END 2 2053b3a8eb9SGleb Smirnoff u_int8_t _pad[3]; 2063b3a8eb9SGleb Smirnoff } __packed; 2073b3a8eb9SGleb Smirnoff 2083b3a8eb9SGleb Smirnoff /* 2093b3a8eb9SGleb Smirnoff * TDB 2103b3a8eb9SGleb Smirnoff */ 2113b3a8eb9SGleb Smirnoff 2123b3a8eb9SGleb Smirnoff struct pfsync_tdb { 2133b3a8eb9SGleb Smirnoff u_int32_t spi; 2143b3a8eb9SGleb Smirnoff union sockaddr_union dst; 2153b3a8eb9SGleb Smirnoff u_int32_t rpl; 2163b3a8eb9SGleb Smirnoff u_int64_t cur_bytes; 2173b3a8eb9SGleb Smirnoff u_int8_t sproto; 2183b3a8eb9SGleb Smirnoff u_int8_t updates; 2193b3a8eb9SGleb Smirnoff u_int8_t _pad[2]; 2203b3a8eb9SGleb Smirnoff } __packed; 2213b3a8eb9SGleb Smirnoff 2223b3a8eb9SGleb Smirnoff #define PFSYNC_HDRLEN sizeof(struct pfsync_header) 2233b3a8eb9SGleb Smirnoff 2243b3a8eb9SGleb Smirnoff struct pfsyncstats { 2253b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */ 2263b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */ 2273b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badif; /* not the right interface */ 2283b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */ 2293b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */ 2303b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */ 2313b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badact; /* bad action */ 2323b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badlen; /* data length does not match */ 2333b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badauth; /* bad authentication */ 2343b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_stale; /* stale state */ 2353b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badval; /* bad values */ 2363b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badstate; /* insert/lookup failed */ 2373b3a8eb9SGleb Smirnoff 2383b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */ 2393b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */ 2403b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_onomem; /* no memory for an mbuf */ 2413b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_oerrors; /* ip output error */ 2423b3a8eb9SGleb Smirnoff 2433b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_iacts[PFSYNC_ACT_MAX]; 2443b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_oacts[PFSYNC_ACT_MAX]; 2453b3a8eb9SGleb Smirnoff }; 2463b3a8eb9SGleb Smirnoff 2473b3a8eb9SGleb Smirnoff /* 2483b3a8eb9SGleb Smirnoff * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC 2493b3a8eb9SGleb Smirnoff */ 2503b3a8eb9SGleb Smirnoff struct pfsyncreq { 2513b3a8eb9SGleb Smirnoff char pfsyncr_syncdev[IFNAMSIZ]; 2523b3a8eb9SGleb Smirnoff struct in_addr pfsyncr_syncpeer; 2533b3a8eb9SGleb Smirnoff int pfsyncr_maxupdates; 2545f5bf889SKristof Provost #define PFSYNCF_OK 0x00000001 2555f5bf889SKristof Provost #define PFSYNCF_DEFER 0x00000002 2563b3a8eb9SGleb Smirnoff int pfsyncr_defer; 2573b3a8eb9SGleb Smirnoff }; 2583b3a8eb9SGleb Smirnoff 259813c5b75SLuiz Amaral struct pfsync_kstatus { 260813c5b75SLuiz Amaral char syncdev[IFNAMSIZ]; 261813c5b75SLuiz Amaral struct sockaddr_storage syncpeer; 262813c5b75SLuiz Amaral int maxupdates; 263*4bf98559SKajetan Staszkiewicz int version; 264813c5b75SLuiz Amaral int flags; 265813c5b75SLuiz Amaral }; 266813c5b75SLuiz Amaral 267813c5b75SLuiz Amaral struct pfsyncioc_nv { 268813c5b75SLuiz Amaral void *data; 269813c5b75SLuiz Amaral size_t len; /* The length of the nvlist data. */ 270813c5b75SLuiz Amaral size_t size; /* The total size of the data buffer. */ 271813c5b75SLuiz Amaral }; 272813c5b75SLuiz Amaral 2733b3a8eb9SGleb Smirnoff #define SIOCSETPFSYNC _IOW('i', 247, struct ifreq) 2743b3a8eb9SGleb Smirnoff #define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq) 275813c5b75SLuiz Amaral #define SIOCSETPFSYNCNV _IOW('i', 249, struct ifreq) 276813c5b75SLuiz Amaral #define SIOCGETPFSYNCNV _IOWR('i', 250, struct ifreq) 2773b3a8eb9SGleb Smirnoff 2783b3a8eb9SGleb Smirnoff #ifdef _KERNEL 2793b3a8eb9SGleb Smirnoff 2803b3a8eb9SGleb Smirnoff /* 2813b3a8eb9SGleb Smirnoff * this shows where a pf state is with respect to the syncing. 282*4bf98559SKajetan Staszkiewicz * pf_kstate->sync_state 2833b3a8eb9SGleb Smirnoff */ 2843b3a8eb9SGleb Smirnoff #define PFSYNC_S_INS 0x00 2853b3a8eb9SGleb Smirnoff #define PFSYNC_S_IACK 0x01 2863b3a8eb9SGleb Smirnoff #define PFSYNC_S_UPD 0x02 2873b3a8eb9SGleb Smirnoff #define PFSYNC_S_UPD_C 0x03 288cdc231bdSKajetan Staszkiewicz #define PFSYNC_S_DEL_C 0x04 2893b3a8eb9SGleb Smirnoff 2903b3a8eb9SGleb Smirnoff #define PFSYNC_S_DEFER 0xfe 2913b3a8eb9SGleb Smirnoff #define PFSYNC_S_NONE 0xff 2923b3a8eb9SGleb Smirnoff 2933b3a8eb9SGleb Smirnoff #define PFSYNC_SI_IOCTL 0x01 2943b3a8eb9SGleb Smirnoff #define PFSYNC_SI_CKSUM 0x02 2953b3a8eb9SGleb Smirnoff #define PFSYNC_SI_ACK 0x04 2963b3a8eb9SGleb Smirnoff 2973b3a8eb9SGleb Smirnoff #endif /* _KERNEL */ 2983b3a8eb9SGleb Smirnoff 2993b3a8eb9SGleb Smirnoff #endif /* _NET_IF_PFSYNC_H_ */ 300