xref: /openbsd/sys/net/if_pflow.h (revision 17df1aa7)
1 /*	$OpenBSD: if_pflow.h,v 1.5 2009/02/27 11:09:36 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 struct pflow_softc {
60 	struct ifnet		 sc_if;
61 	struct ifnet		*sc_pflow_ifp;
62 
63 	unsigned int		 sc_count;
64 	unsigned int		 sc_maxcount;
65 	u_int64_t		 sc_gcounter;
66 	struct ip_moptions	 sc_imo;
67 	struct timeout		 sc_tmo;
68 	struct in_addr		 sc_sender_ip;
69 	u_int16_t		 sc_sender_port;
70 	struct in_addr		 sc_receiver_ip;
71 	u_int16_t		 sc_receiver_port;
72 	struct mbuf		*sc_mbuf;	/* current cumulative mbuf */
73 	SLIST_ENTRY(pflow_softc) sc_next;
74 };
75 
76 extern struct pflow_softc	*pflowif;
77 
78 #endif /* _KERNEL */
79 
80 struct pflow_header {
81 	u_int16_t	version;
82 	u_int16_t	count;
83 	u_int32_t	uptime_ms;
84 	u_int32_t	time_sec;
85 	u_int32_t	time_nanosec;
86 	u_int32_t	flow_sequence;
87 	u_int8_t	engine_type;
88 	u_int8_t	engine_id;
89 	u_int8_t	reserved1;
90 	u_int8_t	reserved2;
91 } __packed;
92 
93 #define PFLOW_HDRLEN sizeof(struct pflow_header)
94 
95 struct pflowstats {
96 	u_int64_t	pflow_flows;
97 	u_int64_t	pflow_packets;
98 	u_int64_t	pflow_onomem;
99 	u_int64_t	pflow_oerrors;
100 };
101 
102 /*
103  * Configuration structure for SIOCSETPFLOW SIOCGETPFLOW
104  */
105 struct pflowreq {
106 	struct in_addr		sender_ip;
107 	struct in_addr		receiver_ip;
108 	u_int16_t		receiver_port;
109 	u_int16_t		addrmask;
110 #define PFLOW_MASK_SRCIP	0x01
111 #define PFLOW_MASK_DSTIP	0x02
112 #define PFLOW_MASK_DSTPRT	0x04
113 };
114 
115 #ifdef _KERNEL
116 int export_pflow(struct pf_state *);
117 int pflow_sysctl(int *, u_int,  void *, size_t *, void *, size_t);
118 #endif /* _KERNEL */
119 
120 #endif /* _NET_IF_PFLOW_H_ */
121