1 /*- 2 * Copyright (c) 2001 Michael Shalayeff 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 * THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 /*- 28 * Copyright (c) 2008 David Gwynne <dlg@openbsd.org> 29 * 30 * Permission to use, copy, modify, and distribute this software for any 31 * purpose with or without fee is hereby granted, provided that the above 32 * copyright notice and this permission notice appear in all copies. 33 * 34 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 35 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 36 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 37 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 39 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 40 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 41 */ 42 43 /* 44 * $OpenBSD: if_pfsync.h,v 1.35 2008/06/29 08:42:15 mcbride Exp $ 45 * $FreeBSD$ 46 */ 47 48 49 #ifndef _NET_IF_PFSYNC_H_ 50 #define _NET_IF_PFSYNC_H_ 51 52 #define PFSYNC_VERSION 5 53 #define PFSYNC_DFLTTL 255 54 55 #define PFSYNC_ACT_CLR 0 /* clear all states */ 56 #define PFSYNC_ACT_INS 1 /* insert state */ 57 #define PFSYNC_ACT_INS_ACK 2 /* ack of insterted state */ 58 #define PFSYNC_ACT_UPD 3 /* update state */ 59 #define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */ 60 #define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */ 61 #define PFSYNC_ACT_DEL 6 /* delete state */ 62 #define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */ 63 #define PFSYNC_ACT_INS_F 8 /* insert fragment */ 64 #define PFSYNC_ACT_DEL_F 9 /* delete fragments */ 65 #define PFSYNC_ACT_BUS 10 /* bulk update status */ 66 #define PFSYNC_ACT_TDB 11 /* TDB replay counter update */ 67 #define PFSYNC_ACT_EOF 12 /* end of frame */ 68 #define PFSYNC_ACT_MAX 13 69 70 #define PFSYNC_HMAC_LEN 20 71 72 /* 73 * A pfsync frame is built from a header followed by several sections which 74 * are all prefixed with their own subheaders. Frames must be terminated with 75 * an EOF subheader. 76 * 77 * | ... | 78 * | IP header | 79 * +============================+ 80 * | pfsync_header | 81 * +----------------------------+ 82 * | pfsync_subheader | 83 * +----------------------------+ 84 * | first action fields | 85 * | ... | 86 * +----------------------------+ 87 * | pfsync_subheader | 88 * +----------------------------+ 89 * | second action fields | 90 * | ... | 91 * +----------------------------+ 92 * | EOF pfsync_subheader | 93 * +----------------------------+ 94 * | HMAC | 95 * +============================+ 96 */ 97 98 /* 99 * Frame header 100 */ 101 102 struct pfsync_header { 103 u_int8_t version; 104 u_int8_t _pad; 105 u_int16_t len; 106 u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH]; 107 } __packed; 108 109 /* 110 * Frame region subheader 111 */ 112 113 struct pfsync_subheader { 114 u_int8_t action; 115 u_int8_t _pad; 116 u_int16_t count; 117 } __packed; 118 119 /* 120 * CLR 121 */ 122 123 struct pfsync_clr { 124 char ifname[IFNAMSIZ]; 125 u_int32_t creatorid; 126 } __packed; 127 128 /* 129 * INS, UPD, DEL 130 */ 131 132 /* these use struct pfsync_state in pfvar.h */ 133 134 /* 135 * INS_ACK 136 */ 137 138 struct pfsync_ins_ack { 139 u_int64_t id; 140 u_int32_t creatorid; 141 } __packed; 142 143 /* 144 * UPD_C 145 */ 146 147 struct pfsync_upd_c { 148 u_int64_t id; 149 struct pfsync_state_peer src; 150 struct pfsync_state_peer dst; 151 u_int32_t creatorid; 152 u_int32_t expire; 153 u_int8_t timeout; 154 u_int8_t _pad[3]; 155 } __packed; 156 157 /* 158 * UPD_REQ 159 */ 160 161 struct pfsync_upd_req { 162 u_int64_t id; 163 u_int32_t creatorid; 164 } __packed; 165 166 /* 167 * DEL_C 168 */ 169 170 struct pfsync_del_c { 171 u_int64_t id; 172 u_int32_t creatorid; 173 } __packed; 174 175 /* 176 * INS_F, DEL_F 177 */ 178 179 /* not implemented (yet) */ 180 181 /* 182 * BUS 183 */ 184 185 struct pfsync_bus { 186 u_int32_t creatorid; 187 u_int32_t endtime; 188 u_int8_t status; 189 #define PFSYNC_BUS_START 1 190 #define PFSYNC_BUS_END 2 191 u_int8_t _pad[3]; 192 } __packed; 193 194 /* 195 * TDB 196 */ 197 198 struct pfsync_tdb { 199 u_int32_t spi; 200 union sockaddr_union dst; 201 u_int32_t rpl; 202 u_int64_t cur_bytes; 203 u_int8_t sproto; 204 u_int8_t updates; 205 u_int8_t _pad[2]; 206 } __packed; 207 208 /* 209 * EOF 210 */ 211 212 struct pfsync_eof { 213 u_int8_t hmac[PFSYNC_HMAC_LEN]; 214 } __packed; 215 216 #define PFSYNC_HDRLEN sizeof(struct pfsync_header) 217 218 219 220 /* 221 * Names for PFSYNC sysctl objects 222 */ 223 #define PFSYNCCTL_STATS 1 /* PFSYNC stats */ 224 #define PFSYNCCTL_MAXID 2 225 226 #define PFSYNCCTL_NAMES { \ 227 { 0, 0 }, \ 228 { "stats", CTLTYPE_STRUCT }, \ 229 } 230 231 struct pfsyncstats { 232 u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */ 233 u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */ 234 u_int64_t pfsyncs_badif; /* not the right interface */ 235 u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */ 236 u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */ 237 u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */ 238 u_int64_t pfsyncs_badact; /* bad action */ 239 u_int64_t pfsyncs_badlen; /* data length does not match */ 240 u_int64_t pfsyncs_badauth; /* bad authentication */ 241 u_int64_t pfsyncs_stale; /* stale state */ 242 u_int64_t pfsyncs_badval; /* bad values */ 243 u_int64_t pfsyncs_badstate; /* insert/lookup failed */ 244 245 u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */ 246 u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */ 247 u_int64_t pfsyncs_onomem; /* no memory for an mbuf */ 248 u_int64_t pfsyncs_oerrors; /* ip output error */ 249 250 u_int64_t pfsyncs_iacts[PFSYNC_ACT_MAX]; 251 u_int64_t pfsyncs_oacts[PFSYNC_ACT_MAX]; 252 }; 253 254 /* 255 * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC 256 */ 257 struct pfsyncreq { 258 char pfsyncr_syncdev[IFNAMSIZ]; 259 struct in_addr pfsyncr_syncpeer; 260 int pfsyncr_maxupdates; 261 int pfsyncr_defer; 262 }; 263 264 #define SIOCSETPFSYNC _IOW('i', 247, struct ifreq) 265 #define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq) 266 267 #ifdef _KERNEL 268 269 /* 270 * this shows where a pf state is with respect to the syncing. 271 */ 272 #define PFSYNC_S_INS 0x00 273 #define PFSYNC_S_IACK 0x01 274 #define PFSYNC_S_UPD 0x02 275 #define PFSYNC_S_UPD_C 0x03 276 #define PFSYNC_S_DEL 0x04 277 #define PFSYNC_S_COUNT 0x05 278 279 #define PFSYNC_S_DEFER 0xfe 280 #define PFSYNC_S_NONE 0xff 281 282 #define PFSYNC_SI_IOCTL 0x01 283 #define PFSYNC_SI_CKSUM 0x02 284 #define PFSYNC_SI_ACK 0x04 285 286 #endif /* _KERNEL */ 287 288 #endif /* _NET_IF_PFSYNC_H_ */ 289