1159979Sglebius/*- 2159979Sglebius * Copyright (c) 2006 Vadim Goncharov <vadimnuclight@tpu.ru> 3159979Sglebius * All rights reserved. 4159979Sglebius * 5159979Sglebius * Redistribution and use in source and binary forms, with or without 6159979Sglebius * modification, are permitted provided that the following conditions 7159979Sglebius * are met: 8159979Sglebius * 1. Redistributions of source code must retain the above copyright 9159979Sglebius * notice unmodified, this list of conditions, and the following 10159979Sglebius * disclaimer. 11159979Sglebius * 2. Redistributions in binary form must reproduce the above copyright 12159979Sglebius * notice, this list of conditions and the following disclaimer in the 13159979Sglebius * documentation and/or other materials provided with the distribution. 14159979Sglebius * 15159979Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16159979Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17159979Sglebius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18159979Sglebius * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19159979Sglebius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20159979Sglebius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21159979Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22159979Sglebius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23159979Sglebius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24159979Sglebius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25159979Sglebius * SUCH DAMAGE. 26159979Sglebius * 27159979Sglebius * $FreeBSD$ 28159979Sglebius */ 29159979Sglebius 30159979Sglebius#ifndef _NETGRAPH_NG_TAG_H_ 31159979Sglebius#define _NETGRAPH_NG_TAG_H_ 32159979Sglebius 33159979Sglebius/* Node type name and magic cookie. */ 34159979Sglebius#define NG_TAG_NODE_TYPE "tag" 35159979Sglebius#define NGM_TAG_COOKIE 1149771193 36159979Sglebius 37159979Sglebius/* 38159979Sglebius * The types of tag_cookie, tag_len and tag_id in structures below 39159979Sglebius * must be the same as corresponding members m_tag_cookie, m_tag_len 40159979Sglebius * and m_tag_id in struct m_tag (defined in <sys/mbuf.h>). 41159979Sglebius */ 42159979Sglebius 43159979Sglebius/* Tag match structure for every (input) hook. */ 44159979Sglebiusstruct ng_tag_hookin { 45159979Sglebius char thisHook[NG_HOOKSIZ]; /* name of hook */ 46159979Sglebius char ifMatch[NG_HOOKSIZ]; /* match dest hook */ 47159979Sglebius char ifNotMatch[NG_HOOKSIZ]; /* !match dest hook */ 48159979Sglebius uint8_t strip; /* strip tag if found */ 49159979Sglebius uint32_t tag_cookie; /* ABI/Module ID */ 50159979Sglebius uint16_t tag_id; /* tag ID */ 51159979Sglebius uint16_t tag_len; /* length of data */ 52159979Sglebius uint8_t tag_data[0]; /* tag data */ 53159979Sglebius}; 54159979Sglebius 55159979Sglebius/* Tag set structure for every (output) hook. */ 56159979Sglebiusstruct ng_tag_hookout { 57159979Sglebius char thisHook[NG_HOOKSIZ]; /* name of hook */ 58159979Sglebius uint32_t tag_cookie; /* ABI/Module ID */ 59159979Sglebius uint16_t tag_id; /* tag ID */ 60159979Sglebius uint16_t tag_len; /* length of data */ 61159979Sglebius uint8_t tag_data[0]; /* tag data */ 62159979Sglebius}; 63159979Sglebius 64159979Sglebius#define NG_TAG_HOOKIN_SIZE(taglen) \ 65159979Sglebius (sizeof(struct ng_tag_hookin) + (taglen)) 66159979Sglebius 67159979Sglebius#define NG_TAG_HOOKOUT_SIZE(taglen) \ 68159979Sglebius (sizeof(struct ng_tag_hookout) + (taglen)) 69159979Sglebius 70159979Sglebius/* Keep this in sync with the above structures definitions. */ 71159979Sglebius#define NG_TAG_HOOKIN_TYPE_INFO(tdtype) { \ 72159979Sglebius { "thisHook", &ng_parse_hookbuf_type }, \ 73159979Sglebius { "ifMatch", &ng_parse_hookbuf_type }, \ 74159979Sglebius { "ifNotMatch", &ng_parse_hookbuf_type }, \ 75159979Sglebius { "strip", &ng_parse_uint8_type }, \ 76159979Sglebius { "tag_cookie", &ng_parse_uint32_type }, \ 77159979Sglebius { "tag_id", &ng_parse_uint16_type }, \ 78159979Sglebius { "tag_len", &ng_parse_uint16_type }, \ 79159979Sglebius { "tag_data", (tdtype) }, \ 80159979Sglebius { NULL } \ 81159979Sglebius} 82159979Sglebius 83159979Sglebius#define NG_TAG_HOOKOUT_TYPE_INFO(tdtype) { \ 84159979Sglebius { "thisHook", &ng_parse_hookbuf_type }, \ 85159979Sglebius { "tag_cookie", &ng_parse_uint32_type }, \ 86159979Sglebius { "tag_id", &ng_parse_uint16_type }, \ 87159979Sglebius { "tag_len", &ng_parse_uint16_type }, \ 88159979Sglebius { "tag_data", (tdtype) }, \ 89159979Sglebius { NULL } \ 90159979Sglebius} 91159979Sglebius 92159979Sglebius#ifdef NG_TAG_DEBUG 93159979Sglebius 94159979Sglebius/* Statistics structure for one hook. */ 95159979Sglebiusstruct ng_tag_hookstat { 96159979Sglebius uint64_t recvFrames; 97159979Sglebius uint64_t recvOctets; 98159979Sglebius uint64_t recvMatchFrames; 99159979Sglebius uint64_t recvMatchOctets; 100159979Sglebius uint64_t xmitFrames; 101159979Sglebius uint64_t xmitOctets; 102159979Sglebius}; 103159979Sglebius 104159979Sglebius/* Keep this in sync with the above structure definition. */ 105159979Sglebius#define NG_TAG_HOOKSTAT_TYPE_INFO { \ 106159979Sglebius { "recvFrames", &ng_parse_uint64_type }, \ 107159979Sglebius { "recvOctets", &ng_parse_uint64_type }, \ 108159979Sglebius { "recvMatchFrames", &ng_parse_uint64_type }, \ 109159979Sglebius { "recvMatchOctets", &ng_parse_uint64_type }, \ 110159979Sglebius { "xmitFrames", &ng_parse_uint64_type }, \ 111159979Sglebius { "xmitOctets", &ng_parse_uint64_type }, \ 112159979Sglebius { NULL } \ 113159979Sglebius} 114159979Sglebius 115159979Sglebius#endif /* NG_TAG_DEBUG */ 116159979Sglebius 117159979Sglebius/* Netgraph commands. */ 118159979Sglebiusenum { 119159979Sglebius NGM_TAG_SET_HOOKIN = 1, /* supply a struct ng_tag_hookin */ 120159979Sglebius NGM_TAG_GET_HOOKIN, /* returns a struct ng_tag_hookin */ 121159979Sglebius NGM_TAG_SET_HOOKOUT, /* supply a struct ng_tag_hookout */ 122159979Sglebius NGM_TAG_GET_HOOKOUT, /* returns a struct ng_tag_hookout */ 123159979Sglebius#ifdef NG_TAG_DEBUG 124159979Sglebius NGM_TAG_GET_STATS, /* supply name as char[NG_HOOKSIZ] */ 125159979Sglebius NGM_TAG_CLR_STATS, /* supply name as char[NG_HOOKSIZ] */ 126159979Sglebius NGM_TAG_GETCLR_STATS, /* supply name as char[NG_HOOKSIZ] */ 127159979Sglebius#endif 128159979Sglebius}; 129159979Sglebius 130159979Sglebius#endif /* _NETGRAPH_NG_TAG_H_ */ 131