xref: /dflybsd-src/sys/netgraph7/ng_source.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  * ng_source.h
3*86d7f5d3SJohn Marino  */
4*86d7f5d3SJohn Marino 
5*86d7f5d3SJohn Marino /*-
6*86d7f5d3SJohn Marino  * Copyright 2002 Sandvine Inc.
7*86d7f5d3SJohn Marino  * All rights reserved.
8*86d7f5d3SJohn Marino  *
9*86d7f5d3SJohn Marino  * Subject to the following obligations and disclaimer of warranty, use and
10*86d7f5d3SJohn Marino  * redistribution of this software, in source or object code forms, with or
11*86d7f5d3SJohn Marino  * without modifications are expressly permitted by Sandvine Inc.; provided,
12*86d7f5d3SJohn Marino  * however, that:
13*86d7f5d3SJohn Marino  * 1. Any and all reproductions of the source or object code must include the
14*86d7f5d3SJohn Marino  *    copyright notice above and the following disclaimer of warranties; and
15*86d7f5d3SJohn Marino  * 2. No rights are granted, in any manner or form, to use Sandvine Inc.
16*86d7f5d3SJohn Marino  *    trademarks, including the mark "SANDVINE" on advertising, endorsements,
17*86d7f5d3SJohn Marino  *    or otherwise except as such appears in the above copyright notice or in
18*86d7f5d3SJohn Marino  *    the software.
19*86d7f5d3SJohn Marino  *
20*86d7f5d3SJohn Marino  * THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM
21*86d7f5d3SJohn Marino  * EXTENT PERMITTED BY LAW, SANDVINE MAKES NO REPRESENTATIONS OR WARRANTIES,
22*86d7f5d3SJohn Marino  * EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
23*86d7f5d3SJohn Marino  * ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24*86d7f5d3SJohn Marino  * PURPOSE, OR NON-INFRINGEMENT.  SANDVINE DOES NOT WARRANT, GUARANTEE, OR
25*86d7f5d3SJohn Marino  * MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE
26*86d7f5d3SJohn Marino  * USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY
27*86d7f5d3SJohn Marino  * OR OTHERWISE.  IN NO EVENT SHALL SANDVINE BE LIABLE FOR ANY DAMAGES
28*86d7f5d3SJohn Marino  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29*86d7f5d3SJohn Marino  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30*86d7f5d3SJohn Marino  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31*86d7f5d3SJohn Marino  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32*86d7f5d3SJohn Marino  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33*86d7f5d3SJohn Marino  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34*86d7f5d3SJohn Marino  * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
35*86d7f5d3SJohn Marino  * DAMAGE.
36*86d7f5d3SJohn Marino  *
37*86d7f5d3SJohn Marino  * Author: Dave Chapeskie <dchapeskie@sandvine.com>
38*86d7f5d3SJohn Marino  *
39*86d7f5d3SJohn Marino  * $FreeBSD: src/sys/netgraph/ng_source.h,v 1.9 2007/03/02 01:44:04 emaste Exp $
40*86d7f5d3SJohn Marino  * $DragonFly: src/sys/netgraph7/ng_source.h,v 1.2 2008/06/26 23:05:35 dillon Exp $
41*86d7f5d3SJohn Marino  */
42*86d7f5d3SJohn Marino 
43*86d7f5d3SJohn Marino #ifndef _NETGRAPH_NG_SOURCE_H_
44*86d7f5d3SJohn Marino #define _NETGRAPH_NG_SOURCE_H_
45*86d7f5d3SJohn Marino 
46*86d7f5d3SJohn Marino /* Node type name and magic cookie */
47*86d7f5d3SJohn Marino #define NG_SOURCE_NODE_TYPE	"source"
48*86d7f5d3SJohn Marino #define NGM_SOURCE_COOKIE	1110646684
49*86d7f5d3SJohn Marino 
50*86d7f5d3SJohn Marino /* Hook names */
51*86d7f5d3SJohn Marino #define NG_SOURCE_HOOK_INPUT	"input"
52*86d7f5d3SJohn Marino #define NG_SOURCE_HOOK_OUTPUT	"output"
53*86d7f5d3SJohn Marino 
54*86d7f5d3SJohn Marino /* Statistics structure returned by NGM_SOURCE_GET_STATS */
55*86d7f5d3SJohn Marino struct ng_source_stats {
56*86d7f5d3SJohn Marino 	uint64_t	outOctets;
57*86d7f5d3SJohn Marino 	uint64_t	outFrames;
58*86d7f5d3SJohn Marino 	uint32_t	queueOctets;
59*86d7f5d3SJohn Marino 	uint32_t	queueFrames;
60*86d7f5d3SJohn Marino 	uint32_t	maxPps;
61*86d7f5d3SJohn Marino 	struct timeval	startTime;
62*86d7f5d3SJohn Marino 	struct timeval	endTime;
63*86d7f5d3SJohn Marino 	struct timeval	elapsedTime;
64*86d7f5d3SJohn Marino 	struct timeval	lastTime;
65*86d7f5d3SJohn Marino };
66*86d7f5d3SJohn Marino 
67*86d7f5d3SJohn Marino extern const struct ng_parse_type ng_source_timeval_type;
68*86d7f5d3SJohn Marino /* Keep this in sync with the above structure definition */
69*86d7f5d3SJohn Marino #define NG_SOURCE_STATS_TYPE_INFO	{			\
70*86d7f5d3SJohn Marino 	  { "outOctets",	&ng_parse_uint64_type	},	\
71*86d7f5d3SJohn Marino 	  { "outFrames",	&ng_parse_uint64_type	},	\
72*86d7f5d3SJohn Marino 	  { "queueOctets",	&ng_parse_uint32_type	},	\
73*86d7f5d3SJohn Marino 	  { "queueFrames",	&ng_parse_uint32_type	},	\
74*86d7f5d3SJohn Marino 	  { "maxPps",		&ng_parse_uint32_type	},	\
75*86d7f5d3SJohn Marino 	  { "startTime",	&ng_source_timeval_type },	\
76*86d7f5d3SJohn Marino 	  { "endTime",		&ng_source_timeval_type },	\
77*86d7f5d3SJohn Marino 	  { "elapsedTime",	&ng_source_timeval_type },	\
78*86d7f5d3SJohn Marino 	  { "lastTime",		&ng_source_timeval_type },	\
79*86d7f5d3SJohn Marino 	  { NULL }						\
80*86d7f5d3SJohn Marino }
81*86d7f5d3SJohn Marino 
82*86d7f5d3SJohn Marino /* Packet embedding info for NGM_SOURCE_GET/SET_TIMESTAMP */
83*86d7f5d3SJohn Marino struct ng_source_embed_info {
84*86d7f5d3SJohn Marino 	uint16_t	offset;		/* offset from ethernet header */
85*86d7f5d3SJohn Marino 	uint8_t		flags;
86*86d7f5d3SJohn Marino 	uint8_t		spare;
87*86d7f5d3SJohn Marino };
88*86d7f5d3SJohn Marino #define NGM_SOURCE_EMBED_ENABLE		0x01	/* enable embedding */
89*86d7f5d3SJohn Marino #define	NGM_SOURCE_INC_CNT_PER_LIST	0x02	/* increment once per list */
90*86d7f5d3SJohn Marino 
91*86d7f5d3SJohn Marino /* Keep this in sync with the above structure definition. */
92*86d7f5d3SJohn Marino #define NG_SOURCE_EMBED_TYPE_INFO {				\
93*86d7f5d3SJohn Marino 	{ "offset",		&ng_parse_hint16_type	},	\
94*86d7f5d3SJohn Marino 	{ "flags",		&ng_parse_hint8_type	},	\
95*86d7f5d3SJohn Marino 	{ NULL }						\
96*86d7f5d3SJohn Marino }
97*86d7f5d3SJohn Marino 
98*86d7f5d3SJohn Marino /* Packet embedding info for NGM_SOURCE_GET/SET_COUNTER */
99*86d7f5d3SJohn Marino #define	NG_SOURCE_COUNTERS	4
100*86d7f5d3SJohn Marino struct ng_source_embed_cnt_info {
101*86d7f5d3SJohn Marino 	uint16_t	offset;		/* offset from ethernet header */
102*86d7f5d3SJohn Marino 	uint8_t		flags;		/* as above */
103*86d7f5d3SJohn Marino 	uint8_t		width;		/* in bytes (1, 2, 4) */
104*86d7f5d3SJohn Marino 	uint32_t	next_val;
105*86d7f5d3SJohn Marino 	uint32_t	min_val;
106*86d7f5d3SJohn Marino 	uint32_t	max_val;
107*86d7f5d3SJohn Marino 	int32_t		increment;
108*86d7f5d3SJohn Marino 	uint8_t		index;		/* which counter (0..3) */
109*86d7f5d3SJohn Marino };
110*86d7f5d3SJohn Marino 
111*86d7f5d3SJohn Marino /* Keep this in sync with the above structure definition. */
112*86d7f5d3SJohn Marino #define NG_SOURCE_EMBED_CNT_TYPE_INFO {				\
113*86d7f5d3SJohn Marino 	{ "offset",		&ng_parse_hint16_type	}, 	\
114*86d7f5d3SJohn Marino 	{ "flags",		&ng_parse_hint8_type	},	\
115*86d7f5d3SJohn Marino 	{ "width",		&ng_parse_uint8_type	},	\
116*86d7f5d3SJohn Marino 	{ "next_val",		&ng_parse_uint32_type	},	\
117*86d7f5d3SJohn Marino 	{ "min_val",		&ng_parse_uint32_type	},	\
118*86d7f5d3SJohn Marino 	{ "max_val",		&ng_parse_uint32_type	},	\
119*86d7f5d3SJohn Marino 	{ "increment",		&ng_parse_int32_type	},	\
120*86d7f5d3SJohn Marino 	{ "index",		&ng_parse_uint8_type	},	\
121*86d7f5d3SJohn Marino 	{ NULL }						\
122*86d7f5d3SJohn Marino }
123*86d7f5d3SJohn Marino 
124*86d7f5d3SJohn Marino /* Netgraph commands */
125*86d7f5d3SJohn Marino enum {
126*86d7f5d3SJohn Marino 	NGM_SOURCE_GET_STATS = 1,	/* get stats */
127*86d7f5d3SJohn Marino 	NGM_SOURCE_CLR_STATS,		/* clear stats */
128*86d7f5d3SJohn Marino 	NGM_SOURCE_GETCLR_STATS,	/* atomically get and clear stats */
129*86d7f5d3SJohn Marino 	NGM_SOURCE_START,		/* start sending queued data */
130*86d7f5d3SJohn Marino 	NGM_SOURCE_STOP,		/* stop sending queued data */
131*86d7f5d3SJohn Marino 	NGM_SOURCE_CLR_DATA,		/* clear the queued data */
132*86d7f5d3SJohn Marino 	NGM_SOURCE_SETIFACE,		/* configure downstream iface */
133*86d7f5d3SJohn Marino 	NGM_SOURCE_SETPPS,		/* rate-limiting packets per second */
134*86d7f5d3SJohn Marino 	NGM_SOURCE_SET_TIMESTAMP,	/* embed xmit timestamp */
135*86d7f5d3SJohn Marino 	NGM_SOURCE_GET_TIMESTAMP,
136*86d7f5d3SJohn Marino 	NGM_SOURCE_SET_COUNTER,		/* embed counter */
137*86d7f5d3SJohn Marino 	NGM_SOURCE_GET_COUNTER,
138*86d7f5d3SJohn Marino };
139*86d7f5d3SJohn Marino 
140*86d7f5d3SJohn Marino #endif /* _NETGRAPH_NG_SOURCE_H_ */
141