1f6eef2c2SGleb Smirnoff /*- 2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 48f6eef2c2SGleb Smirnoff */ 49f6eef2c2SGleb Smirnoff 503b3a8eb9SGleb Smirnoff #ifndef _NET_IF_PFSYNC_H_ 513b3a8eb9SGleb Smirnoff #define _NET_IF_PFSYNC_H_ 523b3a8eb9SGleb Smirnoff 533b3a8eb9SGleb Smirnoff #define PFSYNC_VERSION 5 543b3a8eb9SGleb Smirnoff #define PFSYNC_DFLTTL 255 553b3a8eb9SGleb Smirnoff 563b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_CLR 0 /* clear all states */ 573b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_INS 1 /* insert state */ 585666643aSGordon Bergling #define PFSYNC_ACT_INS_ACK 2 /* ack of inserted state */ 593b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_UPD 3 /* update state */ 603b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */ 613b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */ 623b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_DEL 6 /* delete state */ 633b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */ 643b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_INS_F 8 /* insert fragment */ 653b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_DEL_F 9 /* delete fragments */ 663b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_BUS 10 /* bulk update status */ 673b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_TDB 11 /* TDB replay counter update */ 683b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_EOF 12 /* end of frame */ 693b3a8eb9SGleb Smirnoff #define PFSYNC_ACT_MAX 13 703b3a8eb9SGleb Smirnoff 713b3a8eb9SGleb Smirnoff /* 723b3a8eb9SGleb Smirnoff * A pfsync frame is built from a header followed by several sections which 733b3a8eb9SGleb Smirnoff * are all prefixed with their own subheaders. Frames must be terminated with 743b3a8eb9SGleb Smirnoff * an EOF subheader. 753b3a8eb9SGleb Smirnoff * 763b3a8eb9SGleb Smirnoff * | ... | 773b3a8eb9SGleb Smirnoff * | IP header | 783b3a8eb9SGleb Smirnoff * +============================+ 793b3a8eb9SGleb Smirnoff * | pfsync_header | 803b3a8eb9SGleb Smirnoff * +----------------------------+ 813b3a8eb9SGleb Smirnoff * | pfsync_subheader | 823b3a8eb9SGleb Smirnoff * +----------------------------+ 833b3a8eb9SGleb Smirnoff * | first action fields | 843b3a8eb9SGleb Smirnoff * | ... | 853b3a8eb9SGleb Smirnoff * +----------------------------+ 863b3a8eb9SGleb Smirnoff * | pfsync_subheader | 873b3a8eb9SGleb Smirnoff * +----------------------------+ 883b3a8eb9SGleb Smirnoff * | second action fields | 893b3a8eb9SGleb Smirnoff * | ... | 903b3a8eb9SGleb Smirnoff * +----------------------------+ 913b3a8eb9SGleb Smirnoff * | EOF pfsync_subheader | 923b3a8eb9SGleb Smirnoff * +----------------------------+ 933b3a8eb9SGleb Smirnoff * | HMAC | 943b3a8eb9SGleb Smirnoff * +============================+ 953b3a8eb9SGleb Smirnoff */ 963b3a8eb9SGleb Smirnoff 973b3a8eb9SGleb Smirnoff /* 983b3a8eb9SGleb Smirnoff * Frame header 993b3a8eb9SGleb Smirnoff */ 1003b3a8eb9SGleb Smirnoff 1013b3a8eb9SGleb Smirnoff struct pfsync_header { 1023b3a8eb9SGleb Smirnoff u_int8_t version; 1033b3a8eb9SGleb Smirnoff u_int8_t _pad; 1043b3a8eb9SGleb Smirnoff u_int16_t len; 1053b3a8eb9SGleb Smirnoff u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH]; 1063b3a8eb9SGleb Smirnoff } __packed; 1073b3a8eb9SGleb Smirnoff 1083b3a8eb9SGleb Smirnoff /* 1093b3a8eb9SGleb Smirnoff * Frame region subheader 1103b3a8eb9SGleb Smirnoff */ 1113b3a8eb9SGleb Smirnoff 1123b3a8eb9SGleb Smirnoff struct pfsync_subheader { 1133b3a8eb9SGleb Smirnoff u_int8_t action; 1143b3a8eb9SGleb Smirnoff u_int8_t _pad; 1153b3a8eb9SGleb Smirnoff u_int16_t count; 1163b3a8eb9SGleb Smirnoff } __packed; 1173b3a8eb9SGleb Smirnoff 1183b3a8eb9SGleb Smirnoff /* 1193b3a8eb9SGleb Smirnoff * CLR 1203b3a8eb9SGleb Smirnoff */ 1213b3a8eb9SGleb Smirnoff 1223b3a8eb9SGleb Smirnoff struct pfsync_clr { 1233b3a8eb9SGleb Smirnoff char ifname[IFNAMSIZ]; 1243b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1253b3a8eb9SGleb Smirnoff } __packed; 1263b3a8eb9SGleb Smirnoff 1273b3a8eb9SGleb Smirnoff /* 1283b3a8eb9SGleb Smirnoff * INS, UPD, DEL 1293b3a8eb9SGleb Smirnoff */ 1303b3a8eb9SGleb Smirnoff 1313b3a8eb9SGleb Smirnoff /* these use struct pfsync_state in pfvar.h */ 1323b3a8eb9SGleb Smirnoff 1333b3a8eb9SGleb Smirnoff /* 1343b3a8eb9SGleb Smirnoff * INS_ACK 1353b3a8eb9SGleb Smirnoff */ 1363b3a8eb9SGleb Smirnoff 1373b3a8eb9SGleb Smirnoff struct pfsync_ins_ack { 1383b3a8eb9SGleb Smirnoff u_int64_t id; 1393b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1403b3a8eb9SGleb Smirnoff } __packed; 1413b3a8eb9SGleb Smirnoff 1423b3a8eb9SGleb Smirnoff /* 1433b3a8eb9SGleb Smirnoff * UPD_C 1443b3a8eb9SGleb Smirnoff */ 1453b3a8eb9SGleb Smirnoff 1463b3a8eb9SGleb Smirnoff struct pfsync_upd_c { 1473b3a8eb9SGleb Smirnoff u_int64_t id; 1483b3a8eb9SGleb Smirnoff struct pfsync_state_peer src; 1493b3a8eb9SGleb Smirnoff struct pfsync_state_peer dst; 1503b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1513b3a8eb9SGleb Smirnoff u_int32_t expire; 1523b3a8eb9SGleb Smirnoff u_int8_t timeout; 1533b3a8eb9SGleb Smirnoff u_int8_t _pad[3]; 1543b3a8eb9SGleb Smirnoff } __packed; 1553b3a8eb9SGleb Smirnoff 1563b3a8eb9SGleb Smirnoff /* 1573b3a8eb9SGleb Smirnoff * UPD_REQ 1583b3a8eb9SGleb Smirnoff */ 1593b3a8eb9SGleb Smirnoff 1603b3a8eb9SGleb Smirnoff struct pfsync_upd_req { 1613b3a8eb9SGleb Smirnoff u_int64_t id; 1623b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1633b3a8eb9SGleb Smirnoff } __packed; 1643b3a8eb9SGleb Smirnoff 1653b3a8eb9SGleb Smirnoff /* 1663b3a8eb9SGleb Smirnoff * DEL_C 1673b3a8eb9SGleb Smirnoff */ 1683b3a8eb9SGleb Smirnoff 1693b3a8eb9SGleb Smirnoff struct pfsync_del_c { 1703b3a8eb9SGleb Smirnoff u_int64_t id; 1713b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1723b3a8eb9SGleb Smirnoff } __packed; 1733b3a8eb9SGleb Smirnoff 1743b3a8eb9SGleb Smirnoff /* 1753b3a8eb9SGleb Smirnoff * INS_F, DEL_F 1763b3a8eb9SGleb Smirnoff */ 1773b3a8eb9SGleb Smirnoff 1783b3a8eb9SGleb Smirnoff /* not implemented (yet) */ 1793b3a8eb9SGleb Smirnoff 1803b3a8eb9SGleb Smirnoff /* 1813b3a8eb9SGleb Smirnoff * BUS 1823b3a8eb9SGleb Smirnoff */ 1833b3a8eb9SGleb Smirnoff 1843b3a8eb9SGleb Smirnoff struct pfsync_bus { 1853b3a8eb9SGleb Smirnoff u_int32_t creatorid; 1863b3a8eb9SGleb Smirnoff u_int32_t endtime; 1873b3a8eb9SGleb Smirnoff u_int8_t status; 1883b3a8eb9SGleb Smirnoff #define PFSYNC_BUS_START 1 1893b3a8eb9SGleb Smirnoff #define PFSYNC_BUS_END 2 1903b3a8eb9SGleb Smirnoff u_int8_t _pad[3]; 1913b3a8eb9SGleb Smirnoff } __packed; 1923b3a8eb9SGleb Smirnoff 1933b3a8eb9SGleb Smirnoff /* 1943b3a8eb9SGleb Smirnoff * TDB 1953b3a8eb9SGleb Smirnoff */ 1963b3a8eb9SGleb Smirnoff 1973b3a8eb9SGleb Smirnoff struct pfsync_tdb { 1983b3a8eb9SGleb Smirnoff u_int32_t spi; 1993b3a8eb9SGleb Smirnoff union sockaddr_union dst; 2003b3a8eb9SGleb Smirnoff u_int32_t rpl; 2013b3a8eb9SGleb Smirnoff u_int64_t cur_bytes; 2023b3a8eb9SGleb Smirnoff u_int8_t sproto; 2033b3a8eb9SGleb Smirnoff u_int8_t updates; 2043b3a8eb9SGleb Smirnoff u_int8_t _pad[2]; 2053b3a8eb9SGleb Smirnoff } __packed; 2063b3a8eb9SGleb Smirnoff 2073b3a8eb9SGleb Smirnoff #define PFSYNC_HDRLEN sizeof(struct pfsync_header) 2083b3a8eb9SGleb Smirnoff 2093b3a8eb9SGleb Smirnoff struct pfsyncstats { 2103b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */ 2113b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */ 2123b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badif; /* not the right interface */ 2133b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */ 2143b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */ 2153b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */ 2163b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badact; /* bad action */ 2173b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badlen; /* data length does not match */ 2183b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badauth; /* bad authentication */ 2193b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_stale; /* stale state */ 2203b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badval; /* bad values */ 2213b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_badstate; /* insert/lookup failed */ 2223b3a8eb9SGleb Smirnoff 2233b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */ 2243b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */ 2253b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_onomem; /* no memory for an mbuf */ 2263b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_oerrors; /* ip output error */ 2273b3a8eb9SGleb Smirnoff 2283b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_iacts[PFSYNC_ACT_MAX]; 2293b3a8eb9SGleb Smirnoff u_int64_t pfsyncs_oacts[PFSYNC_ACT_MAX]; 2303b3a8eb9SGleb Smirnoff }; 2313b3a8eb9SGleb Smirnoff 2323b3a8eb9SGleb Smirnoff /* 2333b3a8eb9SGleb Smirnoff * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC 2343b3a8eb9SGleb Smirnoff */ 2353b3a8eb9SGleb Smirnoff struct pfsyncreq { 2363b3a8eb9SGleb Smirnoff char pfsyncr_syncdev[IFNAMSIZ]; 2373b3a8eb9SGleb Smirnoff struct in_addr pfsyncr_syncpeer; 2383b3a8eb9SGleb Smirnoff int pfsyncr_maxupdates; 239*5f5bf889SKristof Provost #define PFSYNCF_OK 0x00000001 240*5f5bf889SKristof Provost #define PFSYNCF_DEFER 0x00000002 2413b3a8eb9SGleb Smirnoff int pfsyncr_defer; 2423b3a8eb9SGleb Smirnoff }; 2433b3a8eb9SGleb Smirnoff 2443b3a8eb9SGleb Smirnoff #define SIOCSETPFSYNC _IOW('i', 247, struct ifreq) 2453b3a8eb9SGleb Smirnoff #define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq) 2463b3a8eb9SGleb Smirnoff 2473b3a8eb9SGleb Smirnoff #ifdef _KERNEL 2483b3a8eb9SGleb Smirnoff 2493b3a8eb9SGleb Smirnoff /* 2503b3a8eb9SGleb Smirnoff * this shows where a pf state is with respect to the syncing. 2513b3a8eb9SGleb Smirnoff */ 2523b3a8eb9SGleb Smirnoff #define PFSYNC_S_INS 0x00 2533b3a8eb9SGleb Smirnoff #define PFSYNC_S_IACK 0x01 2543b3a8eb9SGleb Smirnoff #define PFSYNC_S_UPD 0x02 2553b3a8eb9SGleb Smirnoff #define PFSYNC_S_UPD_C 0x03 2563b3a8eb9SGleb Smirnoff #define PFSYNC_S_DEL 0x04 2573b3a8eb9SGleb Smirnoff #define PFSYNC_S_COUNT 0x05 2583b3a8eb9SGleb Smirnoff 2593b3a8eb9SGleb Smirnoff #define PFSYNC_S_DEFER 0xfe 2603b3a8eb9SGleb Smirnoff #define PFSYNC_S_NONE 0xff 2613b3a8eb9SGleb Smirnoff 2623b3a8eb9SGleb Smirnoff #define PFSYNC_SI_IOCTL 0x01 2633b3a8eb9SGleb Smirnoff #define PFSYNC_SI_CKSUM 0x02 2643b3a8eb9SGleb Smirnoff #define PFSYNC_SI_ACK 0x04 2653b3a8eb9SGleb Smirnoff 2663b3a8eb9SGleb Smirnoff #endif /* _KERNEL */ 2673b3a8eb9SGleb Smirnoff 2683b3a8eb9SGleb Smirnoff #endif /* _NET_IF_PFSYNC_H_ */ 269