1/* 2 * SPDX-License-Identifier: BSD-2-Clause 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 31#ifndef _NETGRAPH_MACFILTER_H_ 32#define _NETGRAPH_MACFILTER_H_ 33 34#define NG_MACFILTER_NODE_TYPE "macfilter" 35#define NGM_MACFILTER_COOKIE 1042445461 36 37/* Hook names */ 38#define NG_MACFILTER_HOOK_ETHER "ether" /* connected to ether:lower */ 39#define NG_MACFILTER_HOOK_DEFAULT "default" /* connected to ether:upper; upper[0] */ 40/* Other hooks may be named freely connected to ether:upper; upper[1..n]*/ 41#define NG_MACFILTER_HOOK_DEFAULT_ID 0 42 43#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0)) 44 45/* Netgraph commands understood/sent by this node type */ 46enum { 47 NGM_MACFILTER_RESET = 1, 48 NGM_MACFILTER_DIRECT = 2, 49 NGM_MACFILTER_DIRECT_HOOKID = 3, 50 NGM_MACFILTER_GET_MACS = 4, 51 NGM_MACFILTER_GETCLR_MACS = 5, 52 NGM_MACFILTER_CLR_MACS = 6, 53 NGM_MACFILTER_GET_HOOKS = 7 54}; 55 56/* This structure is supplied with the NGM_MACFILTER_DIRECT command */ 57struct ngm_macfilter_direct { 58 u_char ether[ETHER_ADDR_LEN]; /* MAC address */ 59 u_char hookname[NG_HOOKSIZ]; /* Upper hook name*/ 60}; 61#define NGM_MACFILTER_DIRECT_FIELDS { \ 62 { "ether", &ng_parse_enaddr_type }, \ 63 { "hookname", &ng_parse_hookbuf_type }, \ 64 { NULL } \ 65} 66 67/* This structure is supplied with the NGM_MACFILTER_DIRECT_HOOKID command */ 68struct ngm_macfilter_direct_hookid { 69 u_char ether[ETHER_ADDR_LEN]; /* MAC address */ 70 u_int16_t hookid; /* Upper hook hookid */ 71}; 72#define NGM_MACFILTER_DIRECT_NDX_FIELDS { \ 73 { "ether", &ng_parse_enaddr_type }, \ 74 { "hookid", &ng_parse_uint16_type }, \ 75 { NULL } \ 76} 77 78/* This structure is returned in the array by the NGM_MACFILTER_GET(CLR)_MACS commands */ 79struct ngm_macfilter_mac { 80 u_char ether[ETHER_ADDR_LEN]; /* MAC address */ 81 u_int16_t hookid; /* Upper hook hookid */ 82 u_int64_t packets_in; /* packets in from downstream */ 83 u_int64_t bytes_in; /* bytes in from upstream */ 84 u_int64_t packets_out; /* packets out towards downstream */ 85 u_int64_t bytes_out; /* bytes out towards downstream */ 86}; 87#define NGM_MACFILTER_MAC_FIELDS { \ 88 { "ether", &ng_parse_enaddr_type }, \ 89 { "hookid", &ng_parse_uint16_type }, \ 90 { "packets_in", &ng_parse_uint64_type }, \ 91 { "bytes_in", &ng_parse_uint64_type }, \ 92 { "packets_out", &ng_parse_uint64_type }, \ 93 { "bytes_out", &ng_parse_uint64_type }, \ 94 { NULL } \ 95} 96/* This structure is returned by the NGM_MACFILTER_GET(CLR)_MACS commands */ 97struct ngm_macfilter_macs { 98 u_int32_t n; /* Number of entries in macs */ 99 struct ngm_macfilter_mac macs[]; /* Macs table */ 100}; 101#define NGM_MACFILTER_MACS_FIELDS { \ 102 { "n", &ng_parse_uint32_type }, \ 103 { "macs", &ng_macfilter_macs_array_type },\ 104 { NULL } \ 105} 106 107/* This structure is returned in an array by the NGM_MACFILTER_GET_HOOKS command */ 108struct ngm_macfilter_hook { 109 u_char hookname[NG_HOOKSIZ]; /* Upper hook name*/ 110 u_int16_t hookid; /* Upper hook hookid */ 111 u_int32_t maccnt; /* Number of mac addresses associated with hook */ 112}; 113#define NGM_MACFILTER_HOOK_FIELDS { \ 114 { "hookname", &ng_parse_hookbuf_type }, \ 115 { "hookid", &ng_parse_uint16_type }, \ 116 { "maccnt", &ng_parse_uint32_type }, \ 117 { NULL } \ 118} 119/* This structure is returned by the NGM_MACFILTER_GET_HOOKS command */ 120struct ngm_macfilter_hooks { 121 u_int32_t n; /* Number of entries in hooks */ 122 struct ngm_macfilter_hook hooks[]; /* Hooks table */ 123}; 124#define NGM_MACFILTER_HOOKS_FIELDS { \ 125 { "n", &ng_parse_uint32_type }, \ 126 { "hooks", &ng_macfilter_hooks_array_type },\ 127 { NULL } \ 128} 129 130#endif /* _NETGRAPH_MACFILTER_H_ */ 131