netgraph.h (67506) | netgraph.h (69922) |
---|---|
1 2/* 3 * netgraph.h 4 * 5 * Copyright (c) 1996-1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 22 unchanged lines hidden (view full) --- 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 WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Julian Elischer <julian@freebsd.org> 38 * | 1 2/* 3 * netgraph.h 4 * 5 * Copyright (c) 1996-1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 22 unchanged lines hidden (view full) --- 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 WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Julian Elischer <julian@freebsd.org> 38 * |
39 * $FreeBSD: head/sys/netgraph/netgraph.h 67506 2000-10-24 17:32:45Z julian $ | 39 * $FreeBSD: head/sys/netgraph/netgraph.h 69922 2000-12-12 18:52:14Z julian $ |
40 * $Whistle: netgraph.h,v 1.29 1999/11/01 07:56:13 julian Exp $ 41 */ 42 43#ifndef _NETGRAPH_NETGRAPH_H_ 44#define _NETGRAPH_NETGRAPH_H_ 1 45 46#include <sys/queue.h> 47#include <sys/malloc.h> --- 14 unchanged lines hidden (view full) --- 62 struct ng_hook *peer; /* the other end of this link */ 63 struct ng_node *node; /* The node this hook is attached to */ 64 LIST_ENTRY(ng_hook) hooks; /* linked list of all hooks on node */ 65}; 66typedef struct ng_hook *hook_p; 67 68/* Flags for a hook */ 69#define HK_INVALID 0x0001 /* don't trust it! */ | 40 * $Whistle: netgraph.h,v 1.29 1999/11/01 07:56:13 julian Exp $ 41 */ 42 43#ifndef _NETGRAPH_NETGRAPH_H_ 44#define _NETGRAPH_NETGRAPH_H_ 1 45 46#include <sys/queue.h> 47#include <sys/malloc.h> --- 14 unchanged lines hidden (view full) --- 62 struct ng_hook *peer; /* the other end of this link */ 63 struct ng_node *node; /* The node this hook is attached to */ 64 LIST_ENTRY(ng_hook) hooks; /* linked list of all hooks on node */ 65}; 66typedef struct ng_hook *hook_p; 67 68/* Flags for a hook */ 69#define HK_INVALID 0x0001 /* don't trust it! */ |
70#define HK_QUEUE 0x0002 /* queue for later delivery */ |
|
70 71/* 72 * Structure of a node 73 */ 74struct ng_node { 75 char *name; /* optional globally unique name */ 76 struct ng_type *type; /* the installed 'type' */ 77 int flags; /* see below for bit definitions */ --- 56 unchanged lines hidden (view full) --- 134typedef int ng_rcvmsg_t(node_p node, struct ng_mesg *msg, 135 const char *retaddr, struct ng_mesg **resp, 136 hook_p lasthook); 137typedef int ng_shutdown_t(node_p node); 138typedef int ng_newhook_t(node_p node, hook_p hook, const char *name); 139typedef hook_p ng_findhook_t(node_p node, const char *name); 140typedef int ng_connect_t(hook_p hook); 141typedef int ng_rcvdata_t(hook_p hook, struct mbuf *m, meta_p meta, | 71 72/* 73 * Structure of a node 74 */ 75struct ng_node { 76 char *name; /* optional globally unique name */ 77 struct ng_type *type; /* the installed 'type' */ 78 int flags; /* see below for bit definitions */ --- 56 unchanged lines hidden (view full) --- 135typedef int ng_rcvmsg_t(node_p node, struct ng_mesg *msg, 136 const char *retaddr, struct ng_mesg **resp, 137 hook_p lasthook); 138typedef int ng_shutdown_t(node_p node); 139typedef int ng_newhook_t(node_p node, hook_p hook, const char *name); 140typedef hook_p ng_findhook_t(node_p node, const char *name); 141typedef int ng_connect_t(hook_p hook); 142typedef int ng_rcvdata_t(hook_p hook, struct mbuf *m, meta_p meta, |
142 struct mbuf **ret_m, meta_p *ret_meta); | 143 struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp); |
143typedef int ng_disconnect_t(hook_p hook); 144 145/* 146 * Command list -- each node type specifies the command that it knows 147 * how to convert between ASCII and binary using an array of these. 148 * The last element in the array must be a terminator with cookie=0. 149 */ 150 151struct ng_cmdlist { 152 u_int32_t cookie; /* command typecookie */ 153 int cmd; /* command number */ 154 const char *name; /* command name */ 155 const struct ng_parse_type *mesgType; /* args if !NGF_RESP */ 156 const struct ng_parse_type *respType; /* args if NGF_RESP */ 157}; 158 159/* 160 * Structure of a node type | 144typedef int ng_disconnect_t(hook_p hook); 145 146/* 147 * Command list -- each node type specifies the command that it knows 148 * how to convert between ASCII and binary using an array of these. 149 * The last element in the array must be a terminator with cookie=0. 150 */ 151 152struct ng_cmdlist { 153 u_int32_t cookie; /* command typecookie */ 154 int cmd; /* command number */ 155 const char *name; /* command name */ 156 const struct ng_parse_type *mesgType; /* args if !NGF_RESP */ 157 const struct ng_parse_type *respType; /* args if NGF_RESP */ 158}; 159 160/* 161 * Structure of a node type |
162 * If data is sent to the "rcvdata()" entrypoint then the system 163 * may decide to defer it until later by queing it with the normal netgraph 164 * input queuing system. This is decidde by the HK_QUEUE flag being set in 165 * the flags word of the peer (receiving) hook. The dequeuing mechanism will 166 * ensure it is not requeued again. 167 * Note the input queueing system is to allow modules 168 * to 'release the stack' or to pass data across spl layers. 169 * The data will be redelivered as soon as the NETISR code runs 170 * which may be almost immediatly. A node may also do it's own queueing 171 * for other reasons (e.g. device output queuing). |
|
161 */ 162struct ng_type { 163 164 u_int32_t version; /* must equal NG_VERSION */ 165 const char *name; /* Unique type name */ 166 modeventhand_t mod_event; /* Module event handler (optional) */ 167 ng_constructor_t *constructor; /* Node constructor */ 168 ng_rcvmsg_t *rcvmsg; /* control messages come here */ 169 ng_shutdown_t *shutdown; /* reset, and free resources */ 170 ng_newhook_t *newhook; /* first notification of new hook */ 171 ng_findhook_t *findhook; /* only if you have lots of hooks */ 172 ng_connect_t *connect; /* final notification of new hook */ | 172 */ 173struct ng_type { 174 175 u_int32_t version; /* must equal NG_VERSION */ 176 const char *name; /* Unique type name */ 177 modeventhand_t mod_event; /* Module event handler (optional) */ 178 ng_constructor_t *constructor; /* Node constructor */ 179 ng_rcvmsg_t *rcvmsg; /* control messages come here */ 180 ng_shutdown_t *shutdown; /* reset, and free resources */ 181 ng_newhook_t *newhook; /* first notification of new hook */ 182 ng_findhook_t *findhook; /* only if you have lots of hooks */ 183 ng_connect_t *connect; /* final notification of new hook */ |
173 ng_rcvdata_t *rcvdata; /* date comes here */ 174 ng_rcvdata_t *rcvdataq; /* or here if being queued */ | 184 ng_rcvdata_t *rcvdata; /* data comes here */ |
175 ng_disconnect_t *disconnect; /* notify on disconnect */ 176 177 const struct ng_cmdlist *cmdlist; /* commands we can convert */ 178 179 /* R/W data private to the base netgraph code DON'T TOUCH! */ 180 LIST_ENTRY(ng_type) types; /* linked list of all types */ 181 int refs; /* number of instances */ 182}; 183 184/* Send data packet with meta-data */ | 185 ng_disconnect_t *disconnect; /* notify on disconnect */ 186 187 const struct ng_cmdlist *cmdlist; /* commands we can convert */ 188 189 /* R/W data private to the base netgraph code DON'T TOUCH! */ 190 LIST_ENTRY(ng_type) types; /* linked list of all types */ 191 int refs; /* number of instances */ 192}; 193 194/* Send data packet with meta-data */ |
185#define NG_SEND_DATA(error, hook, m, a) \ | 195#define NG_SEND_DATA(err, hook, m, meta) \ |
186 do { \ | 196 do { \ |
187 (error) = ng_send_data((hook), (m), (a), NULL, NULL); \ | 197 (err) = ng_send_data((hook), (m), (meta), \ 198 NULL, NULL, NULL); \ |
188 (m) = NULL; \ | 199 (m) = NULL; \ |
189 (a) = NULL; \ | 200 (meta) = NULL; \ |
190 } while (0) 191 | 201 } while (0) 202 |
192/* Send queued data packet with meta-data */ 193#define NG_SEND_DATAQ(error, hook, m, a) \ | 203/* Send data packet with no meta-data */ 204#define NG_SEND_DATA_ONLY(err, hook, m) \ |
194 do { \ | 205 do { \ |
195 (error) = ng_send_dataq((hook), (m), (a), NULL, NULL); \ | 206 (err) = ng_send_data((hook), (m), NULL, \ 207 NULL, NULL, NULL); \ |
196 (m) = NULL; \ | 208 (m) = NULL; \ |
197 (a) = NULL; \ | |
198 } while (0) 199 | 209 } while (0) 210 |
200#define NG_SEND_DATA_RET(error, hook, m, a) \ | 211/* Send data packet including a possible sync response pointer */ 212#define NG_SEND_DATA_RESP(err, hook, m, meta, rmsg) \ |
201 do { \ | 213 do { \ |
214 (err) = ng_send_data((hook), (m), (meta), \ 215 NULL, NULL, rmsg); \ 216 (m) = NULL; \ 217 (meta) = NULL; \ 218 } while (0) 219 220/* 221 * Send data packet including a possible sync response pointer 222 * Allow the callee to replace the data and pass it back 223 * or to simply 'reject it' or 'keep it' 224 */ 225#define NG_SEND_DATA_RET(err, hook, m, meta, rmsg) \ 226 do { \ |
|
202 struct mbuf *rm = NULL; \ | 227 struct mbuf *rm = NULL; \ |
203 meta_p ra = NULL; \ 204 (error) = ng_send_data((hook), (m), (a), &rm, &ra); \ | 228 meta_p rmeta = NULL; \ 229 (err) = ng_send_data((hook), (m), (meta), \ 230 &rm, &rmeta, (rmsg)); \ |
205 (m) = rm; \ | 231 (m) = rm; \ |
206 (a) = ra; \ | 232 (meta) = rmeta; \ |
207 } while (0) 208 | 233 } while (0) 234 |
235 |
|
209/* Free metadata */ | 236/* Free metadata */ |
210#define NG_FREE_META(a) \ | 237#define NG_FREE_META(meta) \ |
211 do { \ | 238 do { \ |
212 if ((a)) { \ 213 FREE((a), M_NETGRAPH); \ 214 a = NULL; \ | 239 if ((meta)) { \ 240 FREE((meta), M_NETGRAPH); \ 241 meta = NULL; \ |
215 } \ 216 } while (0) 217 218/* Free any data packet and/or meta-data */ | 242 } \ 243 } while (0) 244 245/* Free any data packet and/or meta-data */ |
219#define NG_FREE_DATA(m, a) \ | 246#define NG_FREE_DATA(m, meta) \ |
220 do { \ 221 if ((m)) { \ 222 m_freem((m)); \ 223 m = NULL; \ 224 } \ | 247 do { \ 248 if ((m)) { \ 249 m_freem((m)); \ 250 m = NULL; \ 251 } \ |
225 NG_FREE_META((a)); \ | 252 NG_FREE_META((meta)); \ |
226 } while (0) 227 228/* 229 * Use the NETGRAPH_INIT() macro to link a node type into the 230 * netgraph system. This works for types compiled into the kernel 231 * as well as KLD modules. The first argument should be the type 232 * name (eg, echo) and the second a pointer to the type struct. 233 * --- 29 unchanged lines hidden (view full) --- 263struct ng_type *ng_findtype(const char *type); 264int ng_make_node(const char *type, node_p *nodepp); 265int ng_make_node_common(struct ng_type *typep, node_p *nodep); 266int ng_mkpeer(node_p node, const char *name, const char *name2, char *type); 267int ng_mod_event(module_t mod, int what, void *arg); 268int ng_name_node(node_p node, const char *name); 269int ng_newtype(struct ng_type *tp); 270ng_ID_t ng_node2ID(node_p node); | 253 } while (0) 254 255/* 256 * Use the NETGRAPH_INIT() macro to link a node type into the 257 * netgraph system. This works for types compiled into the kernel 258 * as well as KLD modules. The first argument should be the type 259 * name (eg, echo) and the second a pointer to the type struct. 260 * --- 29 unchanged lines hidden (view full) --- 290struct ng_type *ng_findtype(const char *type); 291int ng_make_node(const char *type, node_p *nodepp); 292int ng_make_node_common(struct ng_type *typep, node_p *nodep); 293int ng_mkpeer(node_p node, const char *name, const char *name2, char *type); 294int ng_mod_event(module_t mod, int what, void *arg); 295int ng_name_node(node_p node, const char *name); 296int ng_newtype(struct ng_type *tp); 297ng_ID_t ng_node2ID(node_p node); |
271int ng_path2node(node_p here, const char *path, node_p *dest, char **rtnp, 272 hook_p *lasthook); | 298int ng_path2node(node_p here, const char *path, 299 node_p *dest, hook_p *lasthook); |
273int ng_path_parse(char *addr, char **node, char **path, char **hook); 274int ng_queue_data(hook_p hook, struct mbuf *m, meta_p meta); | 300int ng_path_parse(char *addr, char **node, char **path, char **hook); 301int ng_queue_data(hook_p hook, struct mbuf *m, meta_p meta); |
275int ng_queue_msg(node_p here, struct ng_mesg *msg, const char *address); | 302int ng_queue_msg(node_p here, struct ng_mesg *msg, const char *address, 303 hook_p hook, char *retaddr); |
276void ng_release_node(node_p node); 277void ng_rmnode(node_p node); 278int ng_send_data(hook_p hook, struct mbuf *m, meta_p meta, | 304void ng_release_node(node_p node); 305void ng_rmnode(node_p node); 306int ng_send_data(hook_p hook, struct mbuf *m, meta_p meta, |
279 struct mbuf **ret_m, meta_p *ret_meta); 280int ng_send_dataq(hook_p hook, struct mbuf *m, meta_p meta, 281 struct mbuf **ret_m, meta_p *ret_meta); 282int ng_send_msg(node_p here, struct ng_mesg *msg, 283 const char *address, struct ng_mesg **resp); | 307 struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp); 308int ng_send_msg(node_p here, struct ng_mesg *msg, const char *address, 309 hook_p hook, char *retaddr, struct ng_mesg **resp); |
284void ng_unname(node_p node); 285void ng_unref(node_p node); 286int ng_wait_node(node_p node, char *msg); 287 288#endif /* _NETGRAPH_NETGRAPH_H_ */ 289 | 310void ng_unname(node_p node); 311void ng_unref(node_p node); 312int ng_wait_node(node_p node, char *msg); 313 314#endif /* _NETGRAPH_NETGRAPH_H_ */ 315 |