1 /* 2 * ng_source.h 3 */ 4 5 /*- 6 * Copyright 2002 Sandvine Inc. 7 * All rights reserved. 8 * 9 * Subject to the following obligations and disclaimer of warranty, use and 10 * redistribution of this software, in source or object code forms, with or 11 * without modifications are expressly permitted by Sandvine Inc.; provided, 12 * however, that: 13 * 1. Any and all reproductions of the source or object code must include the 14 * copyright notice above and the following disclaimer of warranties; and 15 * 2. No rights are granted, in any manner or form, to use Sandvine Inc. 16 * trademarks, including the mark "SANDVINE" on advertising, endorsements, 17 * or otherwise except as such appears in the above copyright notice or in 18 * the software. 19 * 20 * THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM 21 * EXTENT PERMITTED BY LAW, SANDVINE MAKES NO REPRESENTATIONS OR WARRANTIES, 22 * EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, 23 * ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 24 * PURPOSE, OR NON-INFRINGEMENT. SANDVINE DOES NOT WARRANT, GUARANTEE, OR 25 * MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE 26 * USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY 27 * OR OTHERWISE. IN NO EVENT SHALL SANDVINE BE LIABLE FOR ANY DAMAGES 28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH 35 * DAMAGE. 36 * 37 * Author: Dave Chapeskie 38 */ 39 40 #ifndef _NETGRAPH_NG_SOURCE_H_ 41 #define _NETGRAPH_NG_SOURCE_H_ 42 43 /* Node type name and magic cookie */ 44 #define NG_SOURCE_NODE_TYPE "source" 45 #define NGM_SOURCE_COOKIE 1110646684 46 47 /* Hook names */ 48 #define NG_SOURCE_HOOK_INPUT "input" 49 #define NG_SOURCE_HOOK_OUTPUT "output" 50 51 /* Statistics structure returned by NGM_SOURCE_GET_STATS */ 52 struct ng_source_stats { 53 uint64_t outOctets; 54 uint64_t outFrames; 55 uint32_t queueOctets; 56 uint32_t queueFrames; 57 uint32_t maxPps; 58 struct timeval startTime; 59 struct timeval endTime; 60 struct timeval elapsedTime; 61 struct timeval lastTime; 62 }; 63 64 extern const struct ng_parse_type ng_source_timeval_type; 65 /* Keep this in sync with the above structure definition */ 66 #define NG_SOURCE_STATS_TYPE_INFO { \ 67 { "outOctets", &ng_parse_uint64_type }, \ 68 { "outFrames", &ng_parse_uint64_type }, \ 69 { "queueOctets", &ng_parse_uint32_type }, \ 70 { "queueFrames", &ng_parse_uint32_type }, \ 71 { "maxPps", &ng_parse_uint32_type }, \ 72 { "startTime", &ng_source_timeval_type }, \ 73 { "endTime", &ng_source_timeval_type }, \ 74 { "elapsedTime", &ng_source_timeval_type }, \ 75 { "lastTime", &ng_source_timeval_type }, \ 76 { NULL } \ 77 } 78 79 /* Packet embedding info for NGM_SOURCE_GET/SET_TIMESTAMP */ 80 struct ng_source_embed_info { 81 uint16_t offset; /* offset from ethernet header */ 82 uint8_t flags; 83 uint8_t spare; 84 }; 85 #define NGM_SOURCE_EMBED_ENABLE 0x01 /* enable embedding */ 86 #define NGM_SOURCE_INC_CNT_PER_LIST 0x02 /* increment once per list */ 87 88 /* Keep this in sync with the above structure definition. */ 89 #define NG_SOURCE_EMBED_TYPE_INFO { \ 90 { "offset", &ng_parse_hint16_type }, \ 91 { "flags", &ng_parse_hint8_type }, \ 92 { NULL } \ 93 } 94 95 /* Packet embedding info for NGM_SOURCE_GET/SET_COUNTER */ 96 #define NG_SOURCE_COUNTERS 4 97 struct ng_source_embed_cnt_info { 98 uint16_t offset; /* offset from ethernet header */ 99 uint8_t flags; /* as above */ 100 uint8_t width; /* in bytes (1, 2, 4) */ 101 uint32_t next_val; 102 uint32_t min_val; 103 uint32_t max_val; 104 int32_t increment; 105 uint8_t index; /* which counter (0..3) */ 106 }; 107 108 /* Keep this in sync with the above structure definition. */ 109 #define NG_SOURCE_EMBED_CNT_TYPE_INFO { \ 110 { "offset", &ng_parse_hint16_type }, \ 111 { "flags", &ng_parse_hint8_type }, \ 112 { "width", &ng_parse_uint8_type }, \ 113 { "next_val", &ng_parse_uint32_type }, \ 114 { "min_val", &ng_parse_uint32_type }, \ 115 { "max_val", &ng_parse_uint32_type }, \ 116 { "increment", &ng_parse_int32_type }, \ 117 { "index", &ng_parse_uint8_type }, \ 118 { NULL } \ 119 } 120 121 /* Netgraph commands */ 122 enum { 123 NGM_SOURCE_GET_STATS = 1, /* get stats */ 124 NGM_SOURCE_CLR_STATS, /* clear stats */ 125 NGM_SOURCE_GETCLR_STATS, /* atomically get and clear stats */ 126 NGM_SOURCE_START, /* start sending queued data */ 127 NGM_SOURCE_STOP, /* stop sending queued data */ 128 NGM_SOURCE_CLR_DATA, /* clear the queued data */ 129 NGM_SOURCE_SETIFACE, /* configure downstream iface */ 130 NGM_SOURCE_SETPPS, /* rate-limiting packets per second */ 131 NGM_SOURCE_SET_TIMESTAMP, /* embed xmit timestamp */ 132 NGM_SOURCE_GET_TIMESTAMP, 133 NGM_SOURCE_SET_COUNTER, /* embed counter */ 134 NGM_SOURCE_GET_COUNTER, 135 }; 136 137 #endif /* _NETGRAPH_NG_SOURCE_H_ */ 138