2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2001 Michael Shalayeff
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c) 2008 David Gwynne <dlg@openbsd.org>
32 * Permission to use, copy, modify, and distribute this software for any
33 * purpose with or without fee is hereby granted, provided that the above
34 * copyright notice and this permission notice appear in all copies.
36 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
46 * $OpenBSD: if_pfsync.h,v 1.35 2008/06/29 08:42:15 mcbride Exp $
49 #ifndef _NET_IF_PFSYNC_H_
50 #define _NET_IF_PFSYNC_H_
52 #include <sys/types.h>
55 #include <net/pfvar.h>
56 #include <netpfil/pf/pf.h>
58 #define PFSYNC_VERSION 5
59 #define PFSYNC_DFLTTL 255
61 enum pfsync_msg_versions {
62 PFSYNC_MSG_VERSION_UNSPECIFIED = 0,
63 PFSYNC_MSG_VERSION_1301 = 1301,
64 PFSYNC_MSG_VERSION_1400 = 1400,
67 #define PFSYNC_MSG_VERSION_DEFAULT PFSYNC_MSG_VERSION_1400
69 #define PFSYNC_ACT_CLR 0 /* clear all states */
70 #define PFSYNC_ACT_INS_1301 1 /* insert state */
71 #define PFSYNC_ACT_INS_ACK 2 /* ack of inserted state */
72 #define PFSYNC_ACT_UPD_1301 3 /* update state */
73 #define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */
74 #define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */
75 #define PFSYNC_ACT_DEL 6 /* delete state */
76 #define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */
77 #define PFSYNC_ACT_INS_F 8 /* insert fragment */
78 #define PFSYNC_ACT_DEL_F 9 /* delete fragments */
79 #define PFSYNC_ACT_BUS 10 /* bulk update status */
80 #define PFSYNC_ACT_TDB 11 /* TDB replay counter update */
81 #define PFSYNC_ACT_EOF 12 /* end of frame */
82 #define PFSYNC_ACT_INS_1400 13 /* insert state */
83 #define PFSYNC_ACT_UPD_1400 14 /* update state */
84 #define PFSYNC_ACT_MAX 15
87 * A pfsync frame is built from a header followed by several sections which
88 * are all prefixed with their own subheaders. Frames must be terminated with
93 * +============================+
95 * +----------------------------+
96 * | pfsync_subheader |
97 * +----------------------------+
98 * | first action fields |
100 * +----------------------------+
101 * | pfsync_subheader |
102 * +----------------------------+
103 * | second action fields |
105 * +----------------------------+
106 * | EOF pfsync_subheader |
107 * +----------------------------+
109 * +============================+
116 struct pfsync_header {
120 u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH];
124 * Frame region subheader
127 struct pfsync_subheader {
138 char ifname[IFNAMSIZ];
146 /* these use struct pfsync_state in pfvar.h */
152 struct pfsync_ins_ack {
161 struct pfsync_upd_c {
163 struct pfsync_state_peer src;
164 struct pfsync_state_peer dst;
175 struct pfsync_upd_req {
184 struct pfsync_del_c {
193 /* not implemented (yet) */
203 #define PFSYNC_BUS_START 1
204 #define PFSYNC_BUS_END 2
214 union sockaddr_union dst;
222 #define PFSYNC_HDRLEN sizeof(struct pfsync_header)
225 u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */
226 u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */
227 u_int64_t pfsyncs_badif; /* not the right interface */
228 u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */
229 u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */
230 u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */
231 u_int64_t pfsyncs_badact; /* bad action */
232 u_int64_t pfsyncs_badlen; /* data length does not match */
233 u_int64_t pfsyncs_badauth; /* bad authentication */
234 u_int64_t pfsyncs_stale; /* stale state */
235 u_int64_t pfsyncs_badval; /* bad values */
236 u_int64_t pfsyncs_badstate; /* insert/lookup failed */
238 u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */
239 u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */
240 u_int64_t pfsyncs_onomem; /* no memory for an mbuf */
241 u_int64_t pfsyncs_oerrors; /* ip output error */
243 u_int64_t pfsyncs_iacts[PFSYNC_ACT_MAX];
244 u_int64_t pfsyncs_oacts[PFSYNC_ACT_MAX];
248 * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC
251 char pfsyncr_syncdev[IFNAMSIZ];
252 struct in_addr pfsyncr_syncpeer;
253 int pfsyncr_maxupdates;
254 #define PFSYNCF_OK 0x00000001
255 #define PFSYNCF_DEFER 0x00000002
259 struct pfsync_kstatus {
260 char syncdev[IFNAMSIZ];
261 struct sockaddr_storage syncpeer;
267 struct pfsyncioc_nv {
269 size_t len; /* The length of the nvlist data. */
270 size_t size; /* The total size of the data buffer. */
273 #define SIOCSETPFSYNC _IOW('i', 247, struct ifreq)
274 #define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq)
275 #define SIOCSETPFSYNCNV _IOW('i', 249, struct ifreq)
276 #define SIOCGETPFSYNCNV _IOWR('i', 250, struct ifreq)
281 * this shows where a pf state is with respect to the syncing.
282 * pf_kstate->sync_state
284 #define PFSYNC_S_INS 0x00
285 #define PFSYNC_S_IACK 0x01
286 #define PFSYNC_S_UPD 0x02
287 #define PFSYNC_S_UPD_C 0x03
288 #define PFSYNC_S_DEL_C 0x04
290 #define PFSYNC_S_DEFER 0xfe
291 #define PFSYNC_S_NONE 0xff
293 #define PFSYNC_SI_IOCTL 0x01
294 #define PFSYNC_SI_CKSUM 0x02
295 #define PFSYNC_SI_ACK 0x04
299 #endif /* _NET_IF_PFSYNC_H_ */