From owner-freebsd-net@FreeBSD.ORG Fri May 28 04:09:40 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BDA1516A4CE; Fri, 28 May 2004 04:09:40 -0700 (PDT) Received: from cell.sick.ru (cell.sick.ru [217.72.144.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5FCC643D2F; Fri, 28 May 2004 04:09:39 -0700 (PDT) (envelope-from glebius@cell.sick.ru) Received: from cell.sick.ru (glebius@localhost [127.0.0.1]) by cell.sick.ru (8.12.9/8.12.8) with ESMTP id i4SB8Yvw043712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 May 2004 15:08:34 +0400 (MSD) (envelope-from glebius@cell.sick.ru) Received: (from glebius@localhost) by cell.sick.ru (8.12.9/8.12.6/Submit) id i4SB8WFR043711; Fri, 28 May 2004 15:08:32 +0400 (MSD) Date: Fri, 28 May 2004 15:08:32 +0400 From: Gleb Smirnoff To: Julian Elischer Message-ID: <20040528110832.GA43696@cell.sick.ru> Mail-Followup-To: Gleb Smirnoff , Julian Elischer , Harti Brandt , freebsd-net@freebsd.org References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="CE+1k2dSO48ffgeK" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i cc: freebsd-net@freebsd.org cc: Harti Brandt Subject: Re: shutdown node VS disconnect all hooks X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 May 2004 11:09:40 -0000 --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=koi8-r Content-Disposition: inline On Fri, May 28, 2004 at 01:31:09AM -0700, Julian Elischer wrote: J> It'd be best to make the change to sparse initialisers a separate patch J> that I cold commit separatly, J> so reduce teh size of the functionality change patch. And here is next patch, that must be applied after c99-patch. It introduces a pre-shutdown method - ng_close_t. And it makes ng_tee behave exactly the way it does in STABLE. -- Totus tuus, Glebius. GLEBIUS-RIPN GLEB-RIPE --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename="ng_tee_bypass.diff" diff -ur netgraph.c99/netgraph.h netgraph/netgraph.h --- netgraph.c99/netgraph.h Fri May 28 14:12:30 2004 +++ netgraph/netgraph.h Fri May 28 15:05:48 2004 @@ -83,6 +83,7 @@ /* 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 @@ 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 @@ 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 -ur netgraph.c99/ng_base.c netgraph/ng_base.c --- netgraph.c99/ng_base.c Fri May 28 14:12:30 2004 +++ netgraph/ng_base.c Fri May 28 14:29:28 2004 @@ -199,7 +199,6 @@ 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, @@ -693,6 +692,10 @@ * creation */ 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) diff -ur netgraph.c99/ng_tee.c netgraph/ng_tee.c --- netgraph.c99/ng_tee.c Fri May 28 14:12:30 2004 +++ netgraph/ng_tee.c Fri May 28 14:17:20 2004 @@ -79,6 +79,7 @@ /* 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 @@ .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 @@ } /* - * 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) --CE+1k2dSO48ffgeK--