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