xref: /freebsd/sys/netgraph/ng_patch.h (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
1 /*-
2  * Copyright (C) 2010 by Maxim Ignatenko <gelraen.ua@gmail.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _NETGRAPH_NG_PATCH_H_
30 #define _NETGRAPH_NG_PATCH_H_
31 
32 /* Node type name. */
33 #define	NG_PATCH_NODE_TYPE	"patch"
34 
35 /* Node type cookie. */
36 #define	NGM_PATCH_COOKIE	1262445509
37 
38 /* Hook names */
39 #define	NG_PATCH_HOOK_IN	"in"
40 #define	NG_PATCH_HOOK_OUT	"out"
41 
42 /* Netgraph commands understood by this node type */
43 enum {
44 	NGM_PATCH_SETCONFIG = 1,
45 	NGM_PATCH_GETCONFIG,
46 	NGM_PATCH_GET_STATS,
47 	NGM_PATCH_CLR_STATS,
48 	NGM_PATCH_GETCLR_STATS
49 };
50 
51 /* Patching modes */
52 enum {
53 	NG_PATCH_MODE_SET = 1,
54 	NG_PATCH_MODE_ADD = 2,
55 	NG_PATCH_MODE_SUB = 3,
56 	NG_PATCH_MODE_MUL = 4,
57 	NG_PATCH_MODE_DIV = 5,
58 	NG_PATCH_MODE_NEG = 6,
59 	NG_PATCH_MODE_AND = 7,
60 	NG_PATCH_MODE_OR  = 8,
61 	NG_PATCH_MODE_XOR = 9,
62 	NG_PATCH_MODE_SHL = 10,
63 	NG_PATCH_MODE_SHR = 11
64 };
65 
66 struct ng_patch_op {
67 	uint64_t	value;
68 	uint32_t	offset;
69 	uint16_t	length;	/* 1, 2, 4 or 8 (bytes) */
70 	uint16_t	mode;
71 };
72 
73 #define	NG_PATCH_OP_TYPE_INFO {				\
74 	{ "value",	&ng_parse_uint64_type	},	\
75 	{ "offset",	&ng_parse_uint32_type	},	\
76 	{ "length",	&ng_parse_uint16_type	},	\
77 	{ "mode",	&ng_parse_uint16_type	},	\
78 	{ NULL }					\
79 }
80 
81 struct ng_patch_config {
82 	uint32_t	count;
83 	uint32_t	csum_flags;
84 	struct ng_patch_op ops[];
85 };
86 
87 #define	NG_PATCH_CONFIG_TYPE_INFO {					\
88 	{ "count",		&ng_parse_uint32_type		},	\
89 	{ "csum_flags",		&ng_parse_uint64_type		},	\
90 	{ "ops",		&ng_patch_ops_array_type		},	\
91 	{ NULL }							\
92 }
93 
94 struct ng_patch_stats {
95 	uint64_t	received;
96 	uint64_t	patched;
97 	uint64_t	dropped;
98 };
99 
100 #define	NG_PATCH_STATS_TYPE_INFO {			\
101 	{ "Received",	&ng_parse_uint64_type	},	\
102 	{ "Patched",	&ng_parse_uint64_type	},	\
103 	{ "Dropped",	&ng_parse_uint64_type	},	\
104 	{ NULL }					\
105 }
106 
107 #endif /* _NETGRAPH_NG_PATCH_H_ */
108