From fcbdfd0eb4f509af7f2a382daaf2c52ce49704c8 Mon Sep 17 00:00:00 2001 From: glebius Date: Tue, 5 Jul 2005 17:35:20 +0000 Subject: In the splnet times, netgraph was functional and synchronous. Nowadays, an item may be queued and processed later. While this is OK for mbufs, this is a problem for control messages. In the framework: - Add optional callback function pointer to an item. When item gets applied the callback is executed from ng_apply_item(). - Add new flag NG_PROGRESS. If this flag is supplied, then return EINPROGRESS instead of 0 in case if item failed to deliver synchronously and was queued. - Honor NG_PROGRESS in ng_snd_item(). In ng_socket: - When userland sends control message add callback to the item. - If ng_snd_item() returns EINPROGRESS, then sleep. This change fixes possible races in ngctl(8) scripts. Reviewed by: julian Approved by: re (scottl) --- sys/netgraph/netgraph.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sys/netgraph/netgraph.h') diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h index a963fc8..4304ced 100644 --- a/sys/netgraph/netgraph.h +++ b/sys/netgraph/netgraph.h @@ -580,6 +580,7 @@ _ng_node_foreach_hook(node_p node, ng_fn_eachhook *fn, void *arg, * */ typedef void ng_item_fn(node_p node, hook_p hook, void *arg1, int arg2); +typedef void ng_apply_t(void *context, int error); struct ng_item { u_long el_flags; item_p el_next; @@ -597,6 +598,12 @@ struct ng_item { int fn_arg2; } fn; } body; + /* + * Optional callback called when item is being applied, + * and its context. + */ + ng_apply_t *apply; + void *context; #ifdef NETGRAPH_DEBUG /*----------------------------------------------*/ char *lastfile; int lastline; @@ -1084,6 +1091,7 @@ 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. */ +#define NG_PROGRESS 0x00000004 /* return EINPROGRESS if queued */ /* * prototypes the user should DEFINITELY not use directly -- cgit v1.1