1/*
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2002 Ericsson Research & Pekka Nikander
5 * Copyright (c) 2020 Nick Hibma <n_hibma@FreeBSD.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice unmodified, this list of conditions, and the following
13 *    disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD$
31 */
32
33#ifndef _NETGRAPH_MACFILTER_H_
34#define _NETGRAPH_MACFILTER_H_
35
36#define NG_MACFILTER_NODE_TYPE		"macfilter"
37#define NGM_MACFILTER_COOKIE 		1042445461
38
39/* Hook names */
40#define NG_MACFILTER_HOOK_ETHER		"ether"         /* connected to ether:lower */
41#define NG_MACFILTER_HOOK_DEFAULT 	"default"       /* connected to ether:upper; upper[0] */
42/* Other hooks may be named freely                         connected to ether:upper; upper[1..n]*/
43#define NG_MACFILTER_HOOK_DEFAULT_ID    0
44
45#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
46
47/* Netgraph commands understood/sent by this node type */
48enum {
49    NGM_MACFILTER_RESET = 1,
50    NGM_MACFILTER_DIRECT = 2,
51    NGM_MACFILTER_DIRECT_HOOKID = 3,
52    NGM_MACFILTER_GET_MACS = 4,
53    NGM_MACFILTER_GETCLR_MACS = 5,
54    NGM_MACFILTER_CLR_MACS = 6,
55    NGM_MACFILTER_GET_HOOKS = 7
56};
57
58/* This structure is supplied with the NGM_MACFILTER_DIRECT command */
59struct ngm_macfilter_direct {
60    u_char	ether[ETHER_ADDR_LEN];  	/* MAC address */
61    u_char	hookname[NG_HOOKSIZ];   	/* Upper hook name*/
62};
63#define NGM_MACFILTER_DIRECT_FIELDS {                   \
64    { "ether",          &ng_parse_enaddr_type },        \
65    { "hookname",       &ng_parse_hookbuf_type },       \
66    { NULL }                                            \
67}
68
69/* This structure is supplied with the NGM_MACFILTER_DIRECT_HOOKID command */
70struct ngm_macfilter_direct_hookid {
71    u_char	ether[ETHER_ADDR_LEN];  	/* MAC address */
72    u_int16_t	hookid;		        	/* Upper hook hookid */
73};
74#define NGM_MACFILTER_DIRECT_NDX_FIELDS {               \
75    { "ether",          &ng_parse_enaddr_type },        \
76    { "hookid",         &ng_parse_uint16_type },        \
77    { NULL }                                            \
78}
79
80/* This structure is returned in the array by the NGM_MACFILTER_GET(CLR)_MACS commands */
81struct ngm_macfilter_mac {
82    u_char	ether[ETHER_ADDR_LEN];  	/* MAC address */
83    u_int16_t	hookid;		        	/* Upper hook hookid */
84    u_int64_t	packets_in;			/* packets in from downstream */
85    u_int64_t	bytes_in;			/* bytes in from upstream */
86    u_int64_t	packets_out;			/* packets out towards downstream */
87    u_int64_t	bytes_out;			/* bytes out towards downstream */
88};
89#define NGM_MACFILTER_MAC_FIELDS {                      \
90    { "ether",          &ng_parse_enaddr_type },        \
91    { "hookid",         &ng_parse_uint16_type },        \
92    { "packets_in",	&ng_parse_uint64_type },        \
93    { "bytes_in",  	&ng_parse_uint64_type },        \
94    { "packets_out",    &ng_parse_uint64_type },        \
95    { "bytes_out",      &ng_parse_uint64_type },        \
96    { NULL }                                            \
97}
98/* This structure is returned by the NGM_MACFILTER_GET(CLR)_MACS commands */
99struct ngm_macfilter_macs {
100    u_int32_t   n;                              /* Number of entries in macs */
101    struct ngm_macfilter_mac macs[];            /* Macs table */
102};
103#define NGM_MACFILTER_MACS_FIELDS {                     \
104    { "n",              &ng_parse_uint32_type },        \
105    { "macs",           &ng_macfilter_macs_array_type },\
106    { NULL }                                            \
107}
108
109/* This structure is returned in an array by the NGM_MACFILTER_GET_HOOKS command */
110struct ngm_macfilter_hook {
111    u_char	hookname[NG_HOOKSIZ];   	/* Upper hook name*/
112    u_int16_t	hookid;		        	/* Upper hook hookid */
113    u_int32_t   maccnt;                         /* Number of mac addresses associated with hook */
114};
115#define NGM_MACFILTER_HOOK_FIELDS {                     \
116    { "hookname",       &ng_parse_hookbuf_type },       \
117    { "hookid",         &ng_parse_uint16_type },        \
118    { "maccnt",         &ng_parse_uint32_type },        \
119    { NULL }                                            \
120}
121/* This structure is returned by the NGM_MACFILTER_GET_HOOKS command */
122struct ngm_macfilter_hooks {
123    u_int32_t   n;                              /* Number of entries in hooks */
124    struct ngm_macfilter_hook hooks[];          /* Hooks table */
125};
126#define NGM_MACFILTER_HOOKS_FIELDS {                     \
127    { "n",              &ng_parse_uint32_type },         \
128    { "hooks",          &ng_macfilter_hooks_array_type },\
129    { NULL }                                             \
130}
131
132#endif /* _NETGRAPH_MACFILTER_H_ */
133