xref: /freebsd/sys/netgraph/ng_source.h (revision 67d187beb1d5628b7ecd8652ea9ff7d732b9ee41)
1585ff168SJulian Elischer /*
2585ff168SJulian Elischer  * ng_source.h
3c398230bSWarner Losh  */
4c398230bSWarner Losh 
5c398230bSWarner Losh /*-
6585ff168SJulian Elischer  * Copyright 2002 Sandvine Inc.
7585ff168SJulian Elischer  * All rights reserved.
8585ff168SJulian Elischer  *
9585ff168SJulian Elischer  * Subject to the following obligations and disclaimer of warranty, use and
10585ff168SJulian Elischer  * redistribution of this software, in source or object code forms, with or
112b0ffc02SBosko Milekic  * without modifications are expressly permitted by Sandvine Inc.; provided,
12585ff168SJulian Elischer  * however, that:
132b0ffc02SBosko Milekic  * 1. Any and all reproductions of the source or object code must include the
142b0ffc02SBosko Milekic  *    copyright notice above and the following disclaimer of warranties; and
15585ff168SJulian Elischer  * 2. No rights are granted, in any manner or form, to use Sandvine Inc.
162b0ffc02SBosko Milekic  *    trademarks, including the mark "SANDVINE" on advertising, endorsements,
172b0ffc02SBosko Milekic  *    or otherwise except as such appears in the above copyright notice or in
18585ff168SJulian Elischer  *    the software.
19585ff168SJulian Elischer  *
20585ff168SJulian Elischer  * THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM
212b0ffc02SBosko Milekic  * EXTENT PERMITTED BY LAW, SANDVINE MAKES NO REPRESENTATIONS OR WARRANTIES,
222b0ffc02SBosko Milekic  * EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
232b0ffc02SBosko Milekic  * ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24585ff168SJulian Elischer  * PURPOSE, OR NON-INFRINGEMENT.  SANDVINE DOES NOT WARRANT, GUARANTEE, OR
25585ff168SJulian Elischer  * MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE
26585ff168SJulian Elischer  * USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY
27585ff168SJulian Elischer  * OR OTHERWISE.  IN NO EVENT SHALL SANDVINE BE LIABLE FOR ANY DAMAGES
28585ff168SJulian Elischer  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
292b0ffc02SBosko Milekic  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30585ff168SJulian Elischer  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31585ff168SJulian Elischer  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32585ff168SJulian Elischer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33585ff168SJulian Elischer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34585ff168SJulian Elischer  * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
35585ff168SJulian Elischer  * DAMAGE.
36585ff168SJulian Elischer  *
37*67d187beSEd Maste  * Author: Dave Chapeskie
38585ff168SJulian Elischer  *
39585ff168SJulian Elischer  * $FreeBSD$
40585ff168SJulian Elischer  */
41585ff168SJulian Elischer 
42e20480bfSRuslan Ermilov #ifndef _NETGRAPH_NG_SOURCE_H_
43e20480bfSRuslan Ermilov #define _NETGRAPH_NG_SOURCE_H_
44585ff168SJulian Elischer 
45585ff168SJulian Elischer /* Node type name and magic cookie */
46585ff168SJulian Elischer #define NG_SOURCE_NODE_TYPE	"source"
47d8f5d037SGleb Smirnoff #define NGM_SOURCE_COOKIE	1110646684
48585ff168SJulian Elischer 
49585ff168SJulian Elischer /* Hook names */
50585ff168SJulian Elischer #define NG_SOURCE_HOOK_INPUT	"input"
51585ff168SJulian Elischer #define NG_SOURCE_HOOK_OUTPUT	"output"
52585ff168SJulian Elischer 
53585ff168SJulian Elischer /* Statistics structure returned by NGM_SOURCE_GET_STATS */
54585ff168SJulian Elischer struct ng_source_stats {
5572235857SGleb Smirnoff 	uint64_t	outOctets;
5672235857SGleb Smirnoff 	uint64_t	outFrames;
5772235857SGleb Smirnoff 	uint32_t	queueOctets;
5872235857SGleb Smirnoff 	uint32_t	queueFrames;
5972235857SGleb Smirnoff 	uint32_t	maxPps;
60585ff168SJulian Elischer 	struct timeval	startTime;
61585ff168SJulian Elischer 	struct timeval	endTime;
62585ff168SJulian Elischer 	struct timeval	elapsedTime;
6372235857SGleb Smirnoff 	struct timeval	lastTime;
64585ff168SJulian Elischer };
65585ff168SJulian Elischer 
66585ff168SJulian Elischer extern const struct ng_parse_type ng_source_timeval_type;
67585ff168SJulian Elischer /* Keep this in sync with the above structure definition */
68585ff168SJulian Elischer #define NG_SOURCE_STATS_TYPE_INFO	{			\
69585ff168SJulian Elischer 	  { "outOctets",	&ng_parse_uint64_type	},	\
70585ff168SJulian Elischer 	  { "outFrames",	&ng_parse_uint64_type	},	\
71585ff168SJulian Elischer 	  { "queueOctets",	&ng_parse_uint32_type	},	\
72585ff168SJulian Elischer 	  { "queueFrames",	&ng_parse_uint32_type	},	\
7372235857SGleb Smirnoff 	  { "maxPps",		&ng_parse_uint32_type	},	\
74585ff168SJulian Elischer 	  { "startTime",	&ng_source_timeval_type },	\
75585ff168SJulian Elischer 	  { "endTime",		&ng_source_timeval_type },	\
76585ff168SJulian Elischer 	  { "elapsedTime",	&ng_source_timeval_type },	\
7772235857SGleb Smirnoff 	  { "lastTime",		&ng_source_timeval_type },	\
78585ff168SJulian Elischer 	  { NULL }						\
79585ff168SJulian Elischer }
80585ff168SJulian Elischer 
815f87dd69SEd Maste /* Packet embedding info for NGM_SOURCE_GET/SET_TIMESTAMP */
825f87dd69SEd Maste struct ng_source_embed_info {
835f87dd69SEd Maste 	uint16_t	offset;		/* offset from ethernet header */
845f87dd69SEd Maste 	uint8_t		flags;
855f87dd69SEd Maste 	uint8_t		spare;
865f87dd69SEd Maste };
875f87dd69SEd Maste #define NGM_SOURCE_EMBED_ENABLE		0x01	/* enable embedding */
88577421ebSEd Maste #define	NGM_SOURCE_INC_CNT_PER_LIST	0x02	/* increment once per list */
895f87dd69SEd Maste 
905f87dd69SEd Maste /* Keep this in sync with the above structure definition. */
915f87dd69SEd Maste #define NG_SOURCE_EMBED_TYPE_INFO {				\
925f87dd69SEd Maste 	{ "offset",		&ng_parse_hint16_type	},	\
935f87dd69SEd Maste 	{ "flags",		&ng_parse_hint8_type	},	\
945f87dd69SEd Maste 	{ NULL }						\
955f87dd69SEd Maste }
965f87dd69SEd Maste 
97577421ebSEd Maste /* Packet embedding info for NGM_SOURCE_GET/SET_COUNTER */
98577421ebSEd Maste #define	NG_SOURCE_COUNTERS	4
99577421ebSEd Maste struct ng_source_embed_cnt_info {
100577421ebSEd Maste 	uint16_t	offset;		/* offset from ethernet header */
101577421ebSEd Maste 	uint8_t		flags;		/* as above */
102577421ebSEd Maste 	uint8_t		width;		/* in bytes (1, 2, 4) */
103577421ebSEd Maste 	uint32_t	next_val;
104577421ebSEd Maste 	uint32_t	min_val;
105577421ebSEd Maste 	uint32_t	max_val;
106577421ebSEd Maste 	int32_t		increment;
107577421ebSEd Maste 	uint8_t		index;		/* which counter (0..3) */
108577421ebSEd Maste };
109577421ebSEd Maste 
110577421ebSEd Maste /* Keep this in sync with the above structure definition. */
111577421ebSEd Maste #define NG_SOURCE_EMBED_CNT_TYPE_INFO {				\
112577421ebSEd Maste 	{ "offset",		&ng_parse_hint16_type	}, 	\
113577421ebSEd Maste 	{ "flags",		&ng_parse_hint8_type	},	\
114577421ebSEd Maste 	{ "width",		&ng_parse_uint8_type	},	\
115577421ebSEd Maste 	{ "next_val",		&ng_parse_uint32_type	},	\
116577421ebSEd Maste 	{ "min_val",		&ng_parse_uint32_type	},	\
117577421ebSEd Maste 	{ "max_val",		&ng_parse_uint32_type	},	\
118577421ebSEd Maste 	{ "increment",		&ng_parse_int32_type	},	\
119577421ebSEd Maste 	{ "index",		&ng_parse_uint8_type	},	\
120577421ebSEd Maste 	{ NULL }						\
121577421ebSEd Maste }
122577421ebSEd Maste 
123585ff168SJulian Elischer /* Netgraph commands */
124585ff168SJulian Elischer enum {
125585ff168SJulian Elischer 	NGM_SOURCE_GET_STATS = 1,	/* get stats */
126585ff168SJulian Elischer 	NGM_SOURCE_CLR_STATS,		/* clear stats */
127585ff168SJulian Elischer 	NGM_SOURCE_GETCLR_STATS,	/* atomically get and clear stats */
128585ff168SJulian Elischer 	NGM_SOURCE_START,		/* start sending queued data */
129585ff168SJulian Elischer 	NGM_SOURCE_STOP,		/* stop sending queued data */
130585ff168SJulian Elischer 	NGM_SOURCE_CLR_DATA,		/* clear the queued data */
131d8f5d037SGleb Smirnoff 	NGM_SOURCE_SETIFACE,		/* configure downstream iface */
13272235857SGleb Smirnoff 	NGM_SOURCE_SETPPS,		/* rate-limiting packets per second */
1335f87dd69SEd Maste 	NGM_SOURCE_SET_TIMESTAMP,	/* embed xmit timestamp */
1345f87dd69SEd Maste 	NGM_SOURCE_GET_TIMESTAMP,
135577421ebSEd Maste 	NGM_SOURCE_SET_COUNTER,		/* embed counter */
136577421ebSEd Maste 	NGM_SOURCE_GET_COUNTER,
137585ff168SJulian Elischer };
138585ff168SJulian Elischer 
139e20480bfSRuslan Ermilov #endif /* _NETGRAPH_NG_SOURCE_H_ */
140