diff options
author | glebius <glebius@FreeBSD.org> | 2007-11-14 11:25:58 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2007-11-14 11:25:58 +0000 |
commit | 6cd20c281d1cc43413205876ff4d8bcc02027d78 (patch) | |
tree | 0b7639598b1545ad93ce6c00f8882c93b416d551 /sys/netgraph | |
parent | a65c7c8bdbe5475c886ee962c0af991019ef35e5 (diff) | |
download | FreeBSD-src-6cd20c281d1cc43413205876ff4d8bcc02027d78.zip FreeBSD-src-6cd20c281d1cc43413205876ff4d8bcc02027d78.tar.gz |
- Merge all the ng_send_fn2* functions into one - ng_send_fn2(),
removing some copy&pasted code.
- Reduce copy and paste in ng_apply_item().
- Resurrect ng_send_fn() as a valid symbol, not a define.
Reviewed by: mav, julian
Diffstat (limited to 'sys/netgraph')
-rw-r--r-- | sys/netgraph/netgraph.h | 22 | ||||
-rw-r--r-- | sys/netgraph/ng_base.c | 113 |
2 files changed, 43 insertions, 92 deletions
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h index 51eebbf..792814c 100644 --- a/sys/netgraph/netgraph.h +++ b/sys/netgraph/netgraph.h @@ -1110,22 +1110,12 @@ int ng_rmhook_self(hook_p hook); /* if a node wants to kill a hook */ int ng_rmnode_self(node_p here); /* if a node wants to suicide */ int ng_rmtype(struct ng_type *tp); int ng_snd_item(item_p item, int queue); -int ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, +int ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void *arg1, + int arg2); +int ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void *arg1, + int arg2, int flags); +int ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, void *arg1, int arg2, int flags); -#define ng_send_fn(node, hook, fn, arg1, arg2) \ - ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS) -int ng_send_fn21(node_p node, hook_p hook, ng_item_fn2 *fn, - void *arg1, int arg2, int flags); -#define ng_send_fn2(node, hook, fn, arg1, arg2) \ - ng_send_fn21(node, hook, fn, arg1, arg2, NG_NOFLAGS) -int ng_send_fn21_cont(item_p item, node_p node, hook_p hook, ng_item_fn2 *fn, - void *arg1, int arg2, int flags); -#define ng_send_fn2_cont(item, node, hook, fn, arg1, arg2) \ - ng_send_fn21_cont(item, node, hook, fn, arg1, arg2, NG_NOFLAGS) -int ng_send_fn21_fwd(item_p item, node_p node, hook_p hook, ng_item_fn2 *fn, - void *arg1, int arg2, int flags); -#define ng_send_fn2_fwd(item, node, hook, fn, arg1, arg2) \ - ng_send_fn21_fwd(item, node, hook, fn, arg1, arg2, NG_NOFLAGS) int ng_uncallout(struct callout *c, node_p node); int ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, ng_item_fn *fn, void * arg1, int arg2); @@ -1135,7 +1125,9 @@ int ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, #define NG_NOFLAGS 0x00000000 /* no special options */ #define NG_QUEUE 0x00000001 /* enqueue item, don't dispatch */ #define NG_WAITOK 0x00000002 /* use M_WAITOK, etc. */ +/* XXXGL: NG_PROGRESS unused since ng_base.c rev. 1.136. Should be deleted? */ #define NG_PROGRESS 0x00000004 /* return EINPROGRESS if queued */ +#define NG_REUSE_ITEM 0x00000008 /* supplied item should be reused */ /* * prototypes the user should DEFINITELY not use directly diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 1ee1108..ad0bec6 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -1351,8 +1351,8 @@ ng_con_part2(node_p node, item_p item, hook_p hook) } mtx_unlock(&ng_topo_mtx); - if ((error = ng_send_fn2_fwd(item, peer->hk_node, peer, - &ng_con_part3, NULL, 0))) { + if ((error = ng_send_fn2(peer->hk_node, peer, item, &ng_con_part3, + NULL, 0, NG_REUSE_ITEM))) { printf("failed in ng_con_part2(C)\n"); ng_destroy_hook(hook); /* also zaps peer */ return (error); /* item was consumed. */ @@ -1403,8 +1403,8 @@ ng_con_nodes(item_p item, node_p node, const char *name, * Procesing continues in that function in the lock context of * the other node. */ - if ((error = ng_send_fn2_cont(item, node2, hook2, - &ng_con_part2, NULL, 0))) { + if ((error = ng_send_fn2(node2, hook2, item, &ng_con_part2, NULL, 0, + NG_NOFLAGS))) { printf("failed in ng_con_nodes(): %d\n", error); ng_destroy_hook(hook); /* also zaps peer */ } @@ -2540,23 +2540,6 @@ ng_apply_item(node_p node, item_p item, int rw) } break; case NGQF_FN: - /* - * We have to implicitly trust the hook, - * as some of these are used for system purposes - * where the hook is invalid. In the case of - * the shutdown message we allow it to hit - * even if the node is invalid. - */ - if ((NG_NODE_NOT_VALID(node)) - && (NGI_FN(item) != &ng_rmnode)) { - TRAP_ERROR(); - error = EINVAL; - NG_FREE_ITEM(item); - break; - } - (*NGI_FN(item))(node, hook, NGI_ARG1(item), NGI_ARG2(item)); - NG_FREE_ITEM(item); - break; case NGQF_FN2: /* * We have to implicitly trust the hook, @@ -2572,7 +2555,12 @@ ng_apply_item(node_p node, item_p item, int rw) NG_FREE_ITEM(item); break; } - error = (*NGI_FN2(item))(node, item, hook); + if ((item->el_flags & NGQF_TYPE) == NGQF_FN) { + (*NGI_FN(item))(node, hook, NGI_ARG1(item), + NGI_ARG2(item)); + NG_FREE_ITEM(item); + } else /* it is NGQF_FN2 */ + error = (*NGI_FN2(item))(node, item, hook); break; } /* @@ -3693,33 +3681,14 @@ ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg) */ int -ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2, - int flags) +ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2) { - item_p item; - if ((item = ng_getqblk(flags)) == NULL) { - return (ENOMEM); - } - item->el_flags = NGQF_FN | NGQF_WRITER; - NG_NODE_REF(node); /* and one for the item */ - NGI_SET_NODE(item, node); - if (hook) { - NG_HOOK_REF(hook); - NGI_SET_HOOK(item, hook); - } - NGI_FN(item) = fn; - NGI_ARG1(item) = arg1; - NGI_ARG2(item) = arg2; - return(ng_snd_item(item, flags)); + return ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS); } -/* - * Send ng_item_fn2 function call to the specified. - */ - int -ng_send_fn21(node_p node, hook_p hook, ng_item_fn2 *fn, void * arg1, int arg2, +ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2, int flags) { item_p item; @@ -3727,58 +3696,46 @@ ng_send_fn21(node_p node, hook_p hook, ng_item_fn2 *fn, void * arg1, int arg2, if ((item = ng_getqblk(flags)) == NULL) { return (ENOMEM); } - item->el_flags = NGQF_FN2 | NGQF_WRITER; + item->el_flags = NGQF_FN | NGQF_WRITER; NG_NODE_REF(node); /* and one for the item */ NGI_SET_NODE(item, node); if (hook) { NG_HOOK_REF(hook); NGI_SET_HOOK(item, hook); } - NGI_FN2(item) = fn; + NGI_FN(item) = fn; NGI_ARG1(item) = arg1; NGI_ARG2(item) = arg2; return(ng_snd_item(item, flags)); } /* - * Send ng_item_fn2 function call to the specified node - * with copying apply pointer from specified item. - * Passed item left untouched. + * Send ng_item_fn2 function call to the specified node. + * + * If an optional pitem parameter is supplied, its apply + * callback will be copied to the new item. If also NG_REUSE_ITEM + * flag is set, no new item will be allocated, but pitem will + * be used. */ - int -ng_send_fn21_cont(item_p pitem, node_p node, hook_p hook, - ng_item_fn2 *fn, void * arg1, int arg2, int flags) +ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, void *arg1, + int arg2, int flags) { item_p item; - if ((item = ng_getqblk(flags)) == NULL) { - return (ENOMEM); - } - item->el_flags = NGQF_FN2 | NGQF_WRITER; - NG_NODE_REF(node); /* and one for the item */ - NGI_SET_NODE(item, node); - if (hook) { - NG_HOOK_REF(hook); - NGI_SET_HOOK(item, hook); - } - NGI_FN2(item) = fn; - NGI_ARG1(item) = arg1; - NGI_ARG2(item) = arg2; - item->apply = pitem->apply; - return(ng_snd_item(item, flags)); -} + KASSERT((pitem != NULL || (flags & NG_REUSE_ITEM) == 0), + ("%s: NG_REUSE_ITEM but no pitem", __func__)); -/* - * Send ng_item_fn2 function call to the specified node - * reusing item including apply pointer. - * Passed item is consumed. - */ + /* + * Allocate a new item if no supplied or + * if we can't use supplied one. + */ + if (pitem == NULL || (flags & NG_REUSE_ITEM) == 0) { + if ((item = ng_getqblk(flags)) == NULL) + return (ENOMEM); + } else + item = pitem; -int -ng_send_fn21_fwd(item_p item, node_p node, hook_p hook, - ng_item_fn2 *fn, void * arg1, int arg2, int flags) -{ item->el_flags = NGQF_FN2 | NGQF_WRITER; NG_NODE_REF(node); /* and one for the item */ NGI_SET_NODE(item, node); @@ -3789,6 +3746,8 @@ ng_send_fn21_fwd(item_p item, node_p node, hook_p hook, NGI_FN2(item) = fn; NGI_ARG1(item) = arg1; NGI_ARG2(item) = arg2; + if (pitem != NULL && (flags & NG_REUSE_ITEM) == 0) + item->apply = pitem->apply; return(ng_snd_item(item, flags)); } |