if_pfsync.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  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. * Copyright (c) 2008 David Gwynne <dlg@openbsd.org>
  30. *
  31. * Permission to use, copy, modify, and distribute this software for any
  32. * purpose with or without fee is hereby granted, provided that the above
  33. * copyright notice and this permission notice appear in all copies.
  34. *
  35. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  36. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  37. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  38. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  39. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  40. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  41. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  42. */
  43. /*
  44. * $OpenBSD: if_pfsync.h,v 1.35 2008/06/29 08:42:15 mcbride Exp $
  45. * $FreeBSD$
  46. */
  47. #ifndef _NET_IF_PFSYNC_H_
  48. #define _NET_IF_PFSYNC_H_
  49. #define PFSYNC_VERSION 5
  50. #define PFSYNC_DFLTTL 255
  51. #define PFSYNC_ACT_CLR 0 /* clear all states */
  52. #define PFSYNC_ACT_INS 1 /* insert state */
  53. #define PFSYNC_ACT_INS_ACK 2 /* ack of insterted state */
  54. #define PFSYNC_ACT_UPD 3 /* 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 */
  64. #define PFSYNC_ACT_MAX 13
  65. /*
  66. * A pfsync frame is built from a header followed by several sections which
  67. * are all prefixed with their own subheaders. Frames must be terminated with
  68. * an EOF subheader.
  69. *
  70. * | ... |
  71. * | IP header |
  72. * +============================+
  73. * | pfsync_header |
  74. * +----------------------------+
  75. * | pfsync_subheader |
  76. * +----------------------------+
  77. * | first action fields |
  78. * | ... |
  79. * +----------------------------+
  80. * | pfsync_subheader |
  81. * +----------------------------+
  82. * | second action fields |
  83. * | ... |
  84. * +----------------------------+
  85. * | EOF pfsync_subheader |
  86. * +----------------------------+
  87. * | HMAC |
  88. * +============================+
  89. */
  90. /*
  91. * Frame header
  92. */
  93. struct pfsync_header {
  94. u_int8_t version;
  95. u_int8_t _pad;
  96. u_int16_t len;
  97. u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH];
  98. } __packed;
  99. /*
  100. * Frame region subheader
  101. */
  102. struct pfsync_subheader {
  103. u_int8_t action;
  104. u_int8_t _pad;
  105. u_int16_t count;
  106. } __packed;
  107. /*
  108. * CLR
  109. */
  110. struct pfsync_clr {
  111. char ifname[IFNAMSIZ];
  112. u_int32_t creatorid;
  113. } __packed;
  114. /*
  115. * INS, UPD, DEL
  116. */
  117. /* these use struct pfsync_state in pfvar.h */
  118. /*
  119. * INS_ACK
  120. */
  121. struct pfsync_ins_ack {
  122. u_int64_t id;
  123. u_int32_t creatorid;
  124. } __packed;
  125. /*
  126. * UPD_C
  127. */
  128. struct pfsync_upd_c {
  129. u_int64_t id;
  130. struct pfsync_state_peer src;
  131. struct pfsync_state_peer dst;
  132. u_int32_t creatorid;
  133. u_int32_t expire;
  134. u_int8_t timeout;
  135. u_int8_t _pad[3];
  136. } __packed;
  137. /*
  138. * UPD_REQ
  139. */
  140. struct pfsync_upd_req {
  141. u_int64_t id;
  142. u_int32_t creatorid;
  143. } __packed;
  144. /*
  145. * DEL_C
  146. */
  147. struct pfsync_del_c {
  148. u_int64_t id;
  149. u_int32_t creatorid;
  150. } __packed;
  151. /*
  152. * INS_F, DEL_F
  153. */
  154. /* not implemented (yet) */
  155. /*
  156. * BUS
  157. */
  158. struct pfsync_bus {
  159. u_int32_t creatorid;
  160. u_int32_t endtime;
  161. u_int8_t status;
  162. #define PFSYNC_BUS_START 1
  163. #define PFSYNC_BUS_END 2
  164. u_int8_t _pad[3];
  165. } __packed;
  166. /*
  167. * TDB
  168. */
  169. struct pfsync_tdb {
  170. u_int32_t spi;
  171. union sockaddr_union dst;
  172. u_int32_t rpl;
  173. u_int64_t cur_bytes;
  174. u_int8_t sproto;
  175. u_int8_t updates;
  176. u_int8_t _pad[2];
  177. } __packed;
  178. #define PFSYNC_HDRLEN sizeof(struct pfsync_header)
  179. struct pfsyncstats {
  180. u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */
  181. u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */
  182. u_int64_t pfsyncs_badif; /* not the right interface */
  183. u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */
  184. u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */
  185. u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */
  186. u_int64_t pfsyncs_badact; /* bad action */
  187. u_int64_t pfsyncs_badlen; /* data length does not match */
  188. u_int64_t pfsyncs_badauth; /* bad authentication */
  189. u_int64_t pfsyncs_stale; /* stale state */
  190. u_int64_t pfsyncs_badval; /* bad values */
  191. u_int64_t pfsyncs_badstate; /* insert/lookup failed */
  192. u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */
  193. u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */
  194. u_int64_t pfsyncs_onomem; /* no memory for an mbuf */
  195. u_int64_t pfsyncs_oerrors; /* ip output error */
  196. u_int64_t pfsyncs_iacts[PFSYNC_ACT_MAX];
  197. u_int64_t pfsyncs_oacts[PFSYNC_ACT_MAX];
  198. };
  199. /*
  200. * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC
  201. */
  202. struct pfsyncreq {
  203. char pfsyncr_syncdev[IFNAMSIZ];
  204. struct in_addr pfsyncr_syncpeer;
  205. int pfsyncr_maxupdates;
  206. int pfsyncr_defer;
  207. };
  208. #define SIOCSETPFSYNC _IOW('i', 247, struct ifreq)
  209. #define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq)
  210. #ifdef _KERNEL
  211. /*
  212. * this shows where a pf state is with respect to the syncing.
  213. */
  214. #define PFSYNC_S_INS 0x00
  215. #define PFSYNC_S_IACK 0x01
  216. #define PFSYNC_S_UPD 0x02
  217. #define PFSYNC_S_UPD_C 0x03
  218. #define PFSYNC_S_DEL 0x04
  219. #define PFSYNC_S_COUNT 0x05
  220. #define PFSYNC_S_DEFER 0xfe
  221. #define PFSYNC_S_NONE 0xff
  222. #define PFSYNC_SI_IOCTL 0x01
  223. #define PFSYNC_SI_CKSUM 0x02
  224. #define PFSYNC_SI_ACK 0x04
  225. #endif /* _KERNEL */
  226. #endif /* _NET_IF_PFSYNC_H_ */