1208946Sae/*-
2208946Sae * Copyright (C) 2010 by Maxim Ignatenko <gelraen.ua@gmail.com>
3208946Sae * All rights reserved.
4208946Sae *
5208946Sae * Redistribution and use in source and binary forms, with or without
6208946Sae * modification, are permitted provided that the following conditions
7208946Sae * are met:
8208946Sae * 1. Redistributions of source code must retain the above copyright
9208946Sae *    notice, this list of conditions and the following disclaimer.
10208946Sae * 2. Redistributions in binary form must reproduce the above copyright
11208946Sae *    notice, this list of conditions and the following disclaimer in the
12208946Sae *    documentation and/or other materials provided with the distribution.
13208946Sae *
14208946Sae * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15208946Sae * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16208946Sae * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17208946Sae * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18208946Sae * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19208946Sae * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20208946Sae * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21208946Sae * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22208946Sae * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23208946Sae * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24208946Sae * SUCH DAMAGE.
25208946Sae *
26208946Sae * $FreeBSD$
27208946Sae */
28208946Sae
29208946Sae#ifndef _NETGRAPH_NG_PATCH_H_
30208946Sae#define _NETGRAPH_NG_PATCH_H_
31208946Sae
32208946Sae/* Node type name. */
33208989Sae#define	NG_PATCH_NODE_TYPE	"patch"
34208946Sae
35208946Sae/* Node type cookie. */
36208989Sae#define	NGM_PATCH_COOKIE	1262445509
37208946Sae
38208946Sae/* Hook names */
39208989Sae#define	NG_PATCH_HOOK_IN	"in"
40208989Sae#define	NG_PATCH_HOOK_OUT	"out"
41208946Sae
42208946Sae/* Netgraph commands understood by this node type */
43208946Saeenum {
44208946Sae	NGM_PATCH_SETCONFIG = 1,
45208946Sae	NGM_PATCH_GETCONFIG,
46208946Sae	NGM_PATCH_GET_STATS,
47208946Sae	NGM_PATCH_CLR_STATS,
48208946Sae	NGM_PATCH_GETCLR_STATS
49208946Sae};
50208946Sae
51208946Sae/* Patching modes */
52208946Saeenum {
53208946Sae	NG_PATCH_MODE_SET = 1,
54208946Sae	NG_PATCH_MODE_ADD = 2,
55208946Sae	NG_PATCH_MODE_SUB = 3,
56208946Sae	NG_PATCH_MODE_MUL = 4,
57208946Sae	NG_PATCH_MODE_DIV = 5,
58208946Sae	NG_PATCH_MODE_NEG = 6,
59208946Sae	NG_PATCH_MODE_AND = 7,
60208946Sae	NG_PATCH_MODE_OR = 8,
61208946Sae	NG_PATCH_MODE_XOR = 9,
62208946Sae	NG_PATCH_MODE_SHL = 10,
63208946Sae	NG_PATCH_MODE_SHR = 11
64208946Sae};
65208946Sae
66208946Saestruct ng_patch_op {
67208946Sae	uint64_t	value;
68208946Sae	uint32_t	offset;
69208946Sae	uint16_t	length;	/* 1,2,4 or 8 (bytes) */
70208946Sae	uint16_t	mode;
71208946Sae};
72208946Sae
73208989Sae#define	NG_PATCH_OP_TYPE_INFO	{	\
74208946Sae		{ "value",	&ng_parse_uint64_type	},	\
75208946Sae		{ "offset",	&ng_parse_uint32_type	},	\
76208946Sae		{ "length",	&ng_parse_uint16_type	},	\
77208946Sae		{ "mode",	&ng_parse_uint16_type	},	\
78208946Sae		{ NULL } \
79208946Sae}
80208946Sae
81208946Saestruct ng_patch_config {
82208946Sae	uint32_t	count;
83208946Sae	uint32_t	csum_flags;
84208946Sae	struct ng_patch_op ops[];
85208946Sae};
86208946Sae
87208989Sae#define	NG_PATCH_CONFIG_TYPE_INFO	{	\
88208946Sae		{ "count",	&ng_parse_uint32_type	},	\
89208946Sae		{ "csum_flags",	&ng_parse_uint32_type	},	\
90208946Sae		{ "ops",	&ng_patch_confarr_type	},	\
91208946Sae		{ NULL } \
92208946Sae}
93208946Sae
94208946Saestruct ng_patch_stats {
95208946Sae	uint64_t	received;
96208946Sae	uint64_t	patched;
97208946Sae	uint64_t	dropped;
98208946Sae};
99208946Sae
100208989Sae#define	NG_PATCH_STATS_TYPE_INFO {	\
101208946Sae		{ "received",	&ng_parse_uint64_type	},	\
102208946Sae		{ "patched",	&ng_parse_uint64_type	},	\
103208946Sae		{ "dropped",	&ng_parse_uint64_type	},	\
104208946Sae		{ NULL } \
105208946Sae}
106208946Sae
107208946Sae#endif /* _NETGRAPH_NG_PATCH_H_ */
108