if_pfsync.h 7.9 KB

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