1 /* $OpenBSD: if_pflow.h,v 1.2 2008/09/16 15:48:12 gollo Exp $ */ 2 3 /* 4 * Copyright (c) 2008 Henning Brauer <henning@openbsd.org> 5 * Copyright (c) 2008 Joerg Goltermann <jg@osn.de> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN 16 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _NET_IF_PFLOW_H_ 21 #define _NET_IF_PFLOW_H_ 22 23 #define PFLOW_ID_LEN sizeof(u_int64_t) 24 25 #define PFLOW_MAXFLOWS 30 26 #define PFLOW_VERSION 5 27 #define PFLOW_ENGINE_TYPE 42 28 #define PFLOW_ENGINE_ID 42 29 #define PFLOW_MAXBYTES 0xffffffff 30 #define PFLOW_TIMEOUT 30 31 32 struct pflow_flow { 33 u_int32_t src_ip; 34 u_int32_t dest_ip; 35 u_int32_t nexthop_ip; 36 u_int16_t if_index_in; 37 u_int16_t if_index_out; 38 u_int32_t flow_packets; 39 u_int32_t flow_octets; 40 u_int32_t flow_start; 41 u_int32_t flow_finish; 42 u_int16_t src_port; 43 u_int16_t dest_port; 44 u_int8_t pad1; 45 u_int8_t tcp_flags; 46 u_int8_t protocol; 47 u_int8_t tos; 48 u_int16_t src_as; 49 u_int16_t dest_as; 50 u_int8_t src_mask; 51 u_int8_t dest_mask; 52 u_int16_t pad2; 53 } __packed; 54 55 #ifdef _KERNEL 56 57 extern int pflow_ok; 58 59 union sc_flowp { 60 struct pflow_flow *s; 61 }; 62 63 struct pflow_softc { 64 struct ifnet sc_if; 65 struct ifnet *sc_pflow_ifp; 66 67 unsigned int sc_count; 68 unsigned int sc_maxcount; 69 u_int32_t sc_gcounter; 70 struct ip_moptions sc_imo; 71 struct timeout sc_tmo; 72 struct in_addr sc_sender_ip; 73 u_int16_t sc_sender_port; 74 struct in_addr sc_receiver_ip; 75 u_int16_t sc_receiver_port; 76 union sc_flowp sc_flowp; 77 struct mbuf *sc_mbuf; /* current cumulative mbuf */ 78 }; 79 80 extern struct pflow_softc *pflowif; 81 82 #endif /* _KERNEL */ 83 84 struct pflow_header { 85 u_int16_t version; 86 u_int16_t count; 87 u_int32_t uptime_ms; 88 u_int32_t time_sec; 89 u_int32_t time_nanosec; 90 u_int32_t flow_sequence; 91 u_int8_t engine_type; 92 u_int8_t engine_id; 93 u_int8_t reserved1; 94 u_int8_t reserved2; 95 } __packed; 96 97 #define PFLOW_HDRLEN sizeof(struct pflow_header) 98 99 struct pflowstats { 100 u_int64_t pflow_flows; 101 u_int64_t pflow_packets; 102 u_int64_t pflow_onomem; 103 u_int64_t pflow_oerrors; 104 }; 105 106 /* 107 * Configuration structure for SIOCSETPFLOW SIOCGETPFLOW 108 */ 109 struct pflowreq { 110 struct in_addr sender_ip; 111 struct in_addr receiver_ip; 112 u_int16_t receiver_port; 113 u_int16_t addrmask; 114 #define PFLOW_MASK_SRCIP 0x01 115 #define PFLOW_MASK_DSTIP 0x02 116 #define PFLOW_MASK_DSTPRT 0x04 117 }; 118 119 #ifdef _KERNEL 120 int export_pflow(struct pf_state *); 121 int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t); 122 #endif /* _KERNEL */ 123 124 #endif /* _NET_IF_PFLOW_H_ */ 125