1106266Sjulian/*
2106266Sjulian * ng_source.h
3139823Simp */
4139823Simp
5139823Simp/*-
6106266Sjulian * Copyright 2002 Sandvine Inc.
7106266Sjulian * All rights reserved.
8106266Sjulian *
9106266Sjulian * Subject to the following obligations and disclaimer of warranty, use and
10106266Sjulian * redistribution of this software, in source or object code forms, with or
11143387Sbmilekic * without modifications are expressly permitted by Sandvine Inc.; provided,
12106266Sjulian * however, that:
13143387Sbmilekic * 1. Any and all reproductions of the source or object code must include the
14143387Sbmilekic *    copyright notice above and the following disclaimer of warranties; and
15106266Sjulian * 2. No rights are granted, in any manner or form, to use Sandvine Inc.
16143387Sbmilekic *    trademarks, including the mark "SANDVINE" on advertising, endorsements,
17143387Sbmilekic *    or otherwise except as such appears in the above copyright notice or in
18106266Sjulian *    the software.
19106266Sjulian *
20106266Sjulian * THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM
21143387Sbmilekic * EXTENT PERMITTED BY LAW, SANDVINE MAKES NO REPRESENTATIONS OR WARRANTIES,
22143387Sbmilekic * EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
23143387Sbmilekic * ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24106266Sjulian * PURPOSE, OR NON-INFRINGEMENT.  SANDVINE DOES NOT WARRANT, GUARANTEE, OR
25106266Sjulian * MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE
26106266Sjulian * USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY
27106266Sjulian * OR OTHERWISE.  IN NO EVENT SHALL SANDVINE BE LIABLE FOR ANY DAMAGES
28106266Sjulian * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29143387Sbmilekic * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30106266Sjulian * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31106266Sjulian * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32106266Sjulian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33106266Sjulian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34106266Sjulian * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
35106266Sjulian * DAMAGE.
36106266Sjulian *
37209730Semaste * Author: Dave Chapeskie
38106266Sjulian *
39106266Sjulian * $FreeBSD$
40106266Sjulian */
41106266Sjulian
42122481Sru#ifndef _NETGRAPH_NG_SOURCE_H_
43122481Sru#define _NETGRAPH_NG_SOURCE_H_
44106266Sjulian
45106266Sjulian/* Node type name and magic cookie */
46106266Sjulian#define NG_SOURCE_NODE_TYPE	"source"
47144674Sglebius#define NGM_SOURCE_COOKIE	1110646684
48106266Sjulian
49106266Sjulian/* Hook names */
50106266Sjulian#define NG_SOURCE_HOOK_INPUT	"input"
51106266Sjulian#define NG_SOURCE_HOOK_OUTPUT	"output"
52106266Sjulian
53106266Sjulian/* Statistics structure returned by NGM_SOURCE_GET_STATS */
54106266Sjulianstruct ng_source_stats {
55153690Sglebius	uint64_t	outOctets;
56153690Sglebius	uint64_t	outFrames;
57153690Sglebius	uint32_t	queueOctets;
58153690Sglebius	uint32_t	queueFrames;
59153690Sglebius	uint32_t	maxPps;
60106266Sjulian	struct timeval	startTime;
61106266Sjulian	struct timeval	endTime;
62106266Sjulian	struct timeval	elapsedTime;
63153690Sglebius	struct timeval	lastTime;
64106266Sjulian};
65106266Sjulian
66106266Sjulianextern const struct ng_parse_type ng_source_timeval_type;
67106266Sjulian/* Keep this in sync with the above structure definition */
68106266Sjulian#define NG_SOURCE_STATS_TYPE_INFO	{			\
69106266Sjulian	  { "outOctets",	&ng_parse_uint64_type	},	\
70106266Sjulian	  { "outFrames",	&ng_parse_uint64_type	},	\
71106266Sjulian	  { "queueOctets",	&ng_parse_uint32_type	},	\
72106266Sjulian	  { "queueFrames",	&ng_parse_uint32_type	},	\
73153690Sglebius	  { "maxPps",		&ng_parse_uint32_type	},	\
74106266Sjulian	  { "startTime",	&ng_source_timeval_type },	\
75106266Sjulian	  { "endTime",		&ng_source_timeval_type },	\
76106266Sjulian	  { "elapsedTime",	&ng_source_timeval_type },	\
77153690Sglebius	  { "lastTime",		&ng_source_timeval_type },	\
78106266Sjulian	  { NULL }						\
79106266Sjulian}
80106266Sjulian
81167156Semaste/* Packet embedding info for NGM_SOURCE_GET/SET_TIMESTAMP */
82167156Semastestruct ng_source_embed_info {
83167156Semaste	uint16_t	offset;		/* offset from ethernet header */
84167156Semaste	uint8_t		flags;
85167156Semaste	uint8_t		spare;
86167156Semaste};
87167156Semaste#define NGM_SOURCE_EMBED_ENABLE		0x01	/* enable embedding */
88167160Semaste#define	NGM_SOURCE_INC_CNT_PER_LIST	0x02	/* increment once per list */
89167156Semaste
90167156Semaste/* Keep this in sync with the above structure definition. */
91167156Semaste#define NG_SOURCE_EMBED_TYPE_INFO {				\
92167156Semaste	{ "offset",		&ng_parse_hint16_type	},	\
93167156Semaste	{ "flags",		&ng_parse_hint8_type	},	\
94167156Semaste	{ NULL }						\
95167156Semaste}
96167156Semaste
97167160Semaste/* Packet embedding info for NGM_SOURCE_GET/SET_COUNTER */
98167160Semaste#define	NG_SOURCE_COUNTERS	4
99167160Semastestruct ng_source_embed_cnt_info {
100167160Semaste	uint16_t	offset;		/* offset from ethernet header */
101167160Semaste	uint8_t		flags;		/* as above */
102167160Semaste	uint8_t		width;		/* in bytes (1, 2, 4) */
103167160Semaste	uint32_t	next_val;
104167160Semaste	uint32_t	min_val;
105167160Semaste	uint32_t	max_val;
106167160Semaste	int32_t		increment;
107167160Semaste	uint8_t		index;		/* which counter (0..3) */
108167160Semaste};
109167160Semaste
110167160Semaste/* Keep this in sync with the above structure definition. */
111167160Semaste#define NG_SOURCE_EMBED_CNT_TYPE_INFO {				\
112167160Semaste	{ "offset",		&ng_parse_hint16_type	}, 	\
113167160Semaste	{ "flags",		&ng_parse_hint8_type	},	\
114167160Semaste	{ "width",		&ng_parse_uint8_type	},	\
115167160Semaste	{ "next_val",		&ng_parse_uint32_type	},	\
116167160Semaste	{ "min_val",		&ng_parse_uint32_type	},	\
117167160Semaste	{ "max_val",		&ng_parse_uint32_type	},	\
118167160Semaste	{ "increment",		&ng_parse_int32_type	},	\
119167160Semaste	{ "index",		&ng_parse_uint8_type	},	\
120167160Semaste	{ NULL }						\
121167160Semaste}
122167160Semaste
123106266Sjulian/* Netgraph commands */
124106266Sjulianenum {
125106266Sjulian	NGM_SOURCE_GET_STATS = 1,	/* get stats */
126106266Sjulian	NGM_SOURCE_CLR_STATS,		/* clear stats */
127106266Sjulian	NGM_SOURCE_GETCLR_STATS,	/* atomically get and clear stats */
128106266Sjulian	NGM_SOURCE_START,		/* start sending queued data */
129106266Sjulian	NGM_SOURCE_STOP,		/* stop sending queued data */
130106266Sjulian	NGM_SOURCE_CLR_DATA,		/* clear the queued data */
131144674Sglebius	NGM_SOURCE_SETIFACE,		/* configure downstream iface */
132153690Sglebius	NGM_SOURCE_SETPPS,		/* rate-limiting packets per second */
133167156Semaste	NGM_SOURCE_SET_TIMESTAMP,	/* embed xmit timestamp */
134167156Semaste	NGM_SOURCE_GET_TIMESTAMP,
135167160Semaste	NGM_SOURCE_SET_COUNTER,		/* embed counter */
136167160Semaste	NGM_SOURCE_GET_COUNTER,
137106266Sjulian};
138106266Sjulian
139122481Sru#endif /* _NETGRAPH_NG_SOURCE_H_ */
140