1 /* $OpenBSD: if_pfsync.h,v 1.44 2010/11/29 05:31:38 dlg Exp $ */ 2 3 /* 4 * Copyright (c) 2001 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 15 * 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. 27 */ 28 29 /* 30 * Copyright (c) 2008 David Gwynne <dlg@openbsd.org> 31 * 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. 35 * 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. 43 */ 44 45 #ifndef _NET_IF_PFSYNC_H_ 46 #define _NET_IF_PFSYNC_H_ 47 48 #define PFSYNC_VERSION 6 49 #define PFSYNC_DFLTTL 255 50 51 #define PFSYNC_ACT_CLR 0 /* clear all states */ 52 #define PFSYNC_ACT_OINS 1 /* old insert state */ 53 #define PFSYNC_ACT_INS_ACK 2 /* ack of insterted state */ 54 #define PFSYNC_ACT_OUPD 3 /* old update state */ 55 #define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */ 56 #define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */ 57 #define PFSYNC_ACT_DEL 6 /* delete state */ 58 #define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */ 59 #define PFSYNC_ACT_INS_F 8 /* insert fragment */ 60 #define PFSYNC_ACT_DEL_F 9 /* delete fragments */ 61 #define PFSYNC_ACT_BUS 10 /* bulk update status */ 62 #define PFSYNC_ACT_TDB 11 /* TDB replay counter update */ 63 #define PFSYNC_ACT_EOF 12 /* end of frame - DEPRECATED */ 64 #define PFSYNC_ACT_INS 13 /* insert state */ 65 #define PFSYNC_ACT_UPD 14 /* update state */ 66 #define PFSYNC_ACT_MAX 15 67 68 #define PFSYNC_ACTIONS "CLR ST", \ 69 "INS ST OLD", \ 70 "INS ST ACK", \ 71 "UPD ST OLD", \ 72 "UPD ST COMP", \ 73 "UPD ST REQ", \ 74 "DEL ST", \ 75 "DEL ST COMP", \ 76 "INS FR", \ 77 "DEL FR", \ 78 "BULK UPD STAT", \ 79 "TDB UPD", \ 80 "EOF", \ 81 "INS ST", \ 82 "UPD ST" 83 84 /* 85 * A pfsync frame is built from a header followed by several sections which 86 * are all prefixed with their own subheaders. 87 * 88 * | ... | 89 * | IP header | 90 * +============================+ 91 * | pfsync_header | 92 * +----------------------------+ 93 * | pfsync_subheader | 94 * +----------------------------+ 95 * | first action fields | 96 * | ... | 97 * +----------------------------+ 98 * | pfsync_subheader | 99 * +----------------------------+ 100 * | second action fields | 101 * | ... | 102 * +============================+ 103 */ 104 105 /* 106 * Frame header 107 */ 108 109 struct pfsync_header { 110 u_int8_t version; 111 u_int8_t _pad; 112 u_int16_t len; /* in bytes */ 113 u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH]; 114 } __packed; 115 116 /* 117 * Frame region subheader 118 */ 119 120 struct pfsync_subheader { 121 u_int8_t action; 122 u_int8_t len; /* in dwords */ 123 u_int16_t count; 124 } __packed; 125 126 /* 127 * CLR 128 */ 129 130 struct pfsync_clr { 131 char ifname[IFNAMSIZ]; 132 u_int32_t creatorid; 133 } __packed; 134 135 /* 136 * OINS, OUPD 137 */ 138 139 /* these messages are deprecated */ 140 141 /* 142 * INS, UPD, DEL 143 */ 144 145 /* these use struct pfsync_state in pfvar.h */ 146 147 /* 148 * INS_ACK 149 */ 150 151 struct pfsync_ins_ack { 152 u_int64_t id; 153 u_int32_t creatorid; 154 } __packed; 155 156 /* 157 * UPD_C 158 */ 159 160 struct pfsync_upd_c { 161 u_int64_t id; 162 struct pfsync_state_peer src; 163 struct pfsync_state_peer dst; 164 u_int32_t creatorid; 165 u_int32_t expire; 166 u_int8_t timeout; 167 u_int8_t state_flags; 168 u_int8_t _pad[2]; 169 } __packed; 170 171 /* 172 * UPD_REQ 173 */ 174 175 struct pfsync_upd_req { 176 u_int64_t id; 177 u_int32_t creatorid; 178 } __packed; 179 180 /* 181 * DEL_C 182 */ 183 184 struct pfsync_del_c { 185 u_int64_t id; 186 u_int32_t creatorid; 187 } __packed; 188 189 /* 190 * INS_F, DEL_F 191 */ 192 193 /* not implemented (yet) */ 194 195 /* 196 * BUS 197 */ 198 199 struct pfsync_bus { 200 u_int32_t creatorid; 201 u_int32_t endtime; 202 u_int8_t status; 203 #define PFSYNC_BUS_START 1 204 #define PFSYNC_BUS_END 2 205 u_int8_t _pad[3]; 206 } __packed; 207 208 /* 209 * TDB 210 */ 211 212 struct pfsync_tdb { 213 u_int32_t spi; 214 union sockaddr_union dst; 215 u_int32_t rpl; 216 u_int64_t cur_bytes; 217 u_int8_t sproto; 218 u_int8_t updates; 219 u_int16_t rdomain; 220 } __packed; 221 222 /* 223 * EOF 224 */ 225 226 /* this message is deprecated */ 227 228 229 #define PFSYNC_HDRLEN sizeof(struct pfsync_header) 230 231 232 /* 233 * Names for PFSYNC sysctl objects 234 */ 235 #define PFSYNCCTL_STATS 1 /* PFSYNC stats */ 236 #define PFSYNCCTL_MAXID 2 237 238 #define PFSYNCCTL_NAMES { \ 239 { 0, 0 }, \ 240 { "stats", CTLTYPE_STRUCT }, \ 241 } 242 243 struct pfsyncstats { 244 u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */ 245 u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */ 246 u_int64_t pfsyncs_badif; /* not the right interface */ 247 u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */ 248 u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */ 249 u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */ 250 u_int64_t pfsyncs_badact; /* bad action */ 251 u_int64_t pfsyncs_badlen; /* data length does not match */ 252 u_int64_t pfsyncs_badauth; /* bad authentication */ 253 u_int64_t pfsyncs_stale; /* stale state */ 254 u_int64_t pfsyncs_badval; /* bad values */ 255 u_int64_t pfsyncs_badstate; /* insert/lookup failed */ 256 257 u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */ 258 u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */ 259 u_int64_t pfsyncs_onomem; /* no memory for an mbuf */ 260 u_int64_t pfsyncs_oerrors; /* ip output error */ 261 }; 262 263 /* 264 * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC 265 */ 266 struct pfsyncreq { 267 char pfsyncr_syncdev[IFNAMSIZ]; 268 struct in_addr pfsyncr_syncpeer; 269 int pfsyncr_maxupdates; 270 int pfsyncr_defer; 271 }; 272 273 #ifdef _KERNEL 274 275 /* 276 * this shows where a pf state is with respect to the syncing. 277 */ 278 #define PFSYNC_S_IACK 0x00 279 #define PFSYNC_S_UPD_C 0x01 280 #define PFSYNC_S_DEL 0x02 281 #define PFSYNC_S_INS 0x03 282 #define PFSYNC_S_UPD 0x04 283 #define PFSYNC_S_COUNT 0x05 284 285 #define PFSYNC_S_DEFER 0xfe 286 #define PFSYNC_S_NONE 0xff 287 288 void pfsync_input(struct mbuf *, ...); 289 int pfsync_sysctl(int *, u_int, void *, size_t *, 290 void *, size_t); 291 292 #define PFSYNC_SI_IOCTL 0x01 293 #define PFSYNC_SI_CKSUM 0x02 294 #define PFSYNC_SI_ACK 0x04 295 int pfsync_state_import(struct pfsync_state *, int); 296 void pfsync_state_export(struct pfsync_state *, 297 struct pf_state *); 298 299 void pfsync_insert_state(struct pf_state *); 300 void pfsync_update_state(struct pf_state *); 301 void pfsync_delete_state(struct pf_state *); 302 void pfsync_clear_states(u_int32_t, const char *); 303 304 void pfsync_update_tdb(struct tdb *, int); 305 void pfsync_delete_tdb(struct tdb *); 306 307 int pfsync_defer(struct pf_state *, struct mbuf *); 308 309 int pfsync_up(void); 310 int pfsync_state_in_use(struct pf_state *); 311 #endif 312 313 #endif /* _NET_IF_PFSYNC_H_ */ 314