xref: /freebsd/sys/netgraph/ng_source.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
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 
40e20480bfSRuslan Ermilov #ifndef _NETGRAPH_NG_SOURCE_H_
41e20480bfSRuslan Ermilov #define _NETGRAPH_NG_SOURCE_H_
42585ff168SJulian Elischer 
43585ff168SJulian Elischer /* Node type name and magic cookie */
44585ff168SJulian Elischer #define NG_SOURCE_NODE_TYPE	"source"
45d8f5d037SGleb Smirnoff #define NGM_SOURCE_COOKIE	1110646684
46585ff168SJulian Elischer 
47585ff168SJulian Elischer /* Hook names */
48585ff168SJulian Elischer #define NG_SOURCE_HOOK_INPUT	"input"
49585ff168SJulian Elischer #define NG_SOURCE_HOOK_OUTPUT	"output"
50585ff168SJulian Elischer 
51585ff168SJulian Elischer /* Statistics structure returned by NGM_SOURCE_GET_STATS */
52585ff168SJulian Elischer struct ng_source_stats {
5372235857SGleb Smirnoff 	uint64_t	outOctets;
5472235857SGleb Smirnoff 	uint64_t	outFrames;
5572235857SGleb Smirnoff 	uint32_t	queueOctets;
5672235857SGleb Smirnoff 	uint32_t	queueFrames;
5772235857SGleb Smirnoff 	uint32_t	maxPps;
58585ff168SJulian Elischer 	struct timeval	startTime;
59585ff168SJulian Elischer 	struct timeval	endTime;
60585ff168SJulian Elischer 	struct timeval	elapsedTime;
6172235857SGleb Smirnoff 	struct timeval	lastTime;
62585ff168SJulian Elischer };
63585ff168SJulian Elischer 
64585ff168SJulian Elischer extern const struct ng_parse_type ng_source_timeval_type;
65585ff168SJulian Elischer /* Keep this in sync with the above structure definition */
66585ff168SJulian Elischer #define NG_SOURCE_STATS_TYPE_INFO	{			\
67585ff168SJulian Elischer 	  { "outOctets",	&ng_parse_uint64_type	},	\
68585ff168SJulian Elischer 	  { "outFrames",	&ng_parse_uint64_type	},	\
69585ff168SJulian Elischer 	  { "queueOctets",	&ng_parse_uint32_type	},	\
70585ff168SJulian Elischer 	  { "queueFrames",	&ng_parse_uint32_type	},	\
7172235857SGleb Smirnoff 	  { "maxPps",		&ng_parse_uint32_type	},	\
72585ff168SJulian Elischer 	  { "startTime",	&ng_source_timeval_type },	\
73585ff168SJulian Elischer 	  { "endTime",		&ng_source_timeval_type },	\
74585ff168SJulian Elischer 	  { "elapsedTime",	&ng_source_timeval_type },	\
7572235857SGleb Smirnoff 	  { "lastTime",		&ng_source_timeval_type },	\
76585ff168SJulian Elischer 	  { NULL }						\
77585ff168SJulian Elischer }
78585ff168SJulian Elischer 
795f87dd69SEd Maste /* Packet embedding info for NGM_SOURCE_GET/SET_TIMESTAMP */
805f87dd69SEd Maste struct ng_source_embed_info {
815f87dd69SEd Maste 	uint16_t	offset;		/* offset from ethernet header */
825f87dd69SEd Maste 	uint8_t		flags;
835f87dd69SEd Maste 	uint8_t		spare;
845f87dd69SEd Maste };
855f87dd69SEd Maste #define NGM_SOURCE_EMBED_ENABLE		0x01	/* enable embedding */
86577421ebSEd Maste #define	NGM_SOURCE_INC_CNT_PER_LIST	0x02	/* increment once per list */
875f87dd69SEd Maste 
885f87dd69SEd Maste /* Keep this in sync with the above structure definition. */
895f87dd69SEd Maste #define NG_SOURCE_EMBED_TYPE_INFO {				\
905f87dd69SEd Maste 	{ "offset",		&ng_parse_hint16_type	},	\
915f87dd69SEd Maste 	{ "flags",		&ng_parse_hint8_type	},	\
925f87dd69SEd Maste 	{ NULL }						\
935f87dd69SEd Maste }
945f87dd69SEd Maste 
95577421ebSEd Maste /* Packet embedding info for NGM_SOURCE_GET/SET_COUNTER */
96577421ebSEd Maste #define	NG_SOURCE_COUNTERS	4
97577421ebSEd Maste struct ng_source_embed_cnt_info {
98577421ebSEd Maste 	uint16_t	offset;		/* offset from ethernet header */
99577421ebSEd Maste 	uint8_t		flags;		/* as above */
100577421ebSEd Maste 	uint8_t		width;		/* in bytes (1, 2, 4) */
101577421ebSEd Maste 	uint32_t	next_val;
102577421ebSEd Maste 	uint32_t	min_val;
103577421ebSEd Maste 	uint32_t	max_val;
104577421ebSEd Maste 	int32_t		increment;
105577421ebSEd Maste 	uint8_t		index;		/* which counter (0..3) */
106577421ebSEd Maste };
107577421ebSEd Maste 
108577421ebSEd Maste /* Keep this in sync with the above structure definition. */
109577421ebSEd Maste #define NG_SOURCE_EMBED_CNT_TYPE_INFO {				\
110577421ebSEd Maste 	{ "offset",		&ng_parse_hint16_type	}, 	\
111577421ebSEd Maste 	{ "flags",		&ng_parse_hint8_type	},	\
112577421ebSEd Maste 	{ "width",		&ng_parse_uint8_type	},	\
113577421ebSEd Maste 	{ "next_val",		&ng_parse_uint32_type	},	\
114577421ebSEd Maste 	{ "min_val",		&ng_parse_uint32_type	},	\
115577421ebSEd Maste 	{ "max_val",		&ng_parse_uint32_type	},	\
116577421ebSEd Maste 	{ "increment",		&ng_parse_int32_type	},	\
117577421ebSEd Maste 	{ "index",		&ng_parse_uint8_type	},	\
118577421ebSEd Maste 	{ NULL }						\
119577421ebSEd Maste }
120577421ebSEd Maste 
121585ff168SJulian Elischer /* Netgraph commands */
122585ff168SJulian Elischer enum {
123585ff168SJulian Elischer 	NGM_SOURCE_GET_STATS = 1,	/* get stats */
124585ff168SJulian Elischer 	NGM_SOURCE_CLR_STATS,		/* clear stats */
125585ff168SJulian Elischer 	NGM_SOURCE_GETCLR_STATS,	/* atomically get and clear stats */
126585ff168SJulian Elischer 	NGM_SOURCE_START,		/* start sending queued data */
127585ff168SJulian Elischer 	NGM_SOURCE_STOP,		/* stop sending queued data */
128585ff168SJulian Elischer 	NGM_SOURCE_CLR_DATA,		/* clear the queued data */
129d8f5d037SGleb Smirnoff 	NGM_SOURCE_SETIFACE,		/* configure downstream iface */
13072235857SGleb Smirnoff 	NGM_SOURCE_SETPPS,		/* rate-limiting packets per second */
1315f87dd69SEd Maste 	NGM_SOURCE_SET_TIMESTAMP,	/* embed xmit timestamp */
1325f87dd69SEd Maste 	NGM_SOURCE_GET_TIMESTAMP,
133577421ebSEd Maste 	NGM_SOURCE_SET_COUNTER,		/* embed counter */
134577421ebSEd Maste 	NGM_SOURCE_GET_COUNTER,
135585ff168SJulian Elischer };
136585ff168SJulian Elischer 
137e20480bfSRuslan Ermilov #endif /* _NETGRAPH_NG_SOURCE_H_ */
138