diff options
author | julian <julian@FreeBSD.org> | 2004-05-29 07:21:46 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2004-05-29 07:21:46 +0000 |
commit | 14e22ae790f0931cfc80145d29b654521b3a3a10 (patch) | |
tree | 67609d746180f3ac3b3714e8dcaba00a354b8f02 /sys/netgraph | |
parent | 9fc4e00a1cc5858d10a3b68a9861213b649ccb04 (diff) | |
download | FreeBSD-src-14e22ae790f0931cfc80145d29b654521b3a3a10.zip FreeBSD-src-14e22ae790f0931cfc80145d29b654521b3a3a10.tar.gz |
Add a new netgraph method to allow restoration of some
behaviour lost in the change from 4.x style netgraph tee nodes.
Alter the tee node to use the new method. Document the behaviour.
Step the ABI version number... old netgraph klds will refuse to load.
Better than just crashing.
Submitted by: Gleb Smirnoff <glebius@cell.sick.ru>
Diffstat (limited to 'sys/netgraph')
-rw-r--r-- | sys/netgraph/netgraph.h | 5 | ||||
-rw-r--r-- | sys/netgraph/ng_base.c | 5 | ||||
-rw-r--r-- | sys/netgraph/ng_tee.c | 28 |
3 files changed, 28 insertions, 10 deletions
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h index 8981836..99adc60 100644 --- a/sys/netgraph/netgraph.h +++ b/sys/netgraph/netgraph.h @@ -62,7 +62,7 @@ * Change it for NETGRAPH_DEBUG version so we cannot mix debug and non debug * modules. */ -#define _NG_ABI_VERSION 7 +#define _NG_ABI_VERSION 8 #ifdef NETGRAPH_DEBUG /*----------------------------------------------*/ #define NG_ABI_VERSION (_NG_ABI_VERSION + 0x10000) #else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/ @@ -83,6 +83,7 @@ typedef struct ng_hook *hook_p; /* node method definitions */ typedef int ng_constructor_t(node_p node); +typedef int ng_close_t(node_p node); typedef int ng_shutdown_t(node_p node); typedef int ng_newhook_t(node_p node, hook_p hook, const char *name); typedef hook_p ng_findhook_t(node_p node, const char *name); @@ -1052,6 +1053,7 @@ struct ng_type { modeventhand_t mod_event; /* Module event handler (optional) */ ng_constructor_t *constructor; /* Node constructor */ ng_rcvmsg_t *rcvmsg; /* control messages come here */ + ng_close_t *close; /* warn about forthcoming shutdown */ ng_shutdown_t *shutdown; /* reset, and free resources */ ng_newhook_t *newhook; /* first notification of new hook */ ng_findhook_t *findhook; /* only if you have lots of hooks */ @@ -1112,6 +1114,7 @@ SYSCTL_DECL(_net_graph); int ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr); int ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr); int ng_address_path(node_p here, item_p item, char *address, ng_ID_t raddr); +int ng_bypass(hook_p hook1, hook_p hook2); meta_p ng_copy_meta(meta_p meta); hook_p ng_findhook(node_p node, const char *name); int ng_make_node_common(struct ng_type *typep, node_p *nodep); diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 878ec88..d3acc01 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -199,7 +199,6 @@ static int ng_mkpeer(node_p node, const char *name, const char *name2, char *type); /* imported , these used to be externally visible, some may go back */ -int ng_bypass(hook_p hook1, hook_p hook2); void ng_destroy_hook(hook_p hook); node_p ng_name2noderef(node_p node, const char *name); int ng_path2noderef(node_p here, const char *path, @@ -694,6 +693,10 @@ ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3) */ node->nd_flags |= NG_INVALID|NG_CLOSING; + /* If node has its pre-shutdown method, then call it first*/ + if (node->nd_type && node->nd_type->close) + (*node->nd_type->close)(node); + /* Notify all remaining connected nodes to disconnect */ while ((hook = LIST_FIRST(&node->nd_hooks)) != NULL) ng_destroy_hook(hook); diff --git a/sys/netgraph/ng_tee.c b/sys/netgraph/ng_tee.c index 1f6fb9a..d7d19d5 100644 --- a/sys/netgraph/ng_tee.c +++ b/sys/netgraph/ng_tee.c @@ -79,6 +79,7 @@ typedef struct privdata *sc_p; /* Netgraph methods */ static ng_constructor_t ngt_constructor; static ng_rcvmsg_t ngt_rcvmsg; +static ng_close_t ngt_close; static ng_shutdown_t ngt_shutdown; static ng_newhook_t ngt_newhook; static ng_rcvdata_t ngt_rcvdata; @@ -132,6 +133,7 @@ static struct ng_type ng_tee_typestruct = { .name = NG_TEE_NODE_TYPE, .constructor = ngt_constructor, .rcvmsg = ngt_rcvmsg, + .close = ngt_close, .shutdown = ngt_shutdown, .newhook = ngt_newhook, .rcvdata = ngt_rcvdata, @@ -358,15 +360,25 @@ ngt_rcvdata(hook_p hook, item_p item) } /* - * Shutdown processing - * - * This is tricky. If we have both a left and right hook, then we - * probably want to extricate ourselves and leave the two peers - * still linked to each other. Otherwise we should just shut down as - * a normal node would. + * We are going to be shut down soon * - * To keep the scope of info correct the routine to "extract" a node - * from two links is in ng_base.c. + * If we have both a left and right hook, then we probably want to extricate + * ourselves and leave the two peers still linked to each other. Otherwise we + * should just shut down as a normal node would. + */ +static int +ngt_close(node_p node) +{ + const sc_p privdata = NG_NODE_PRIVATE(node); + + if (privdata->left.hook && privdata->right.hook) + ng_bypass(privdata->left.hook, privdata->right.hook); + + return (0); +} + +/* + * Shutdown processing */ static int ngt_shutdown(node_p node) |