kern/63863: [patch] implement NGM_ELECTROCUTE
Gleb Smirnoff
glebius at cell.sick.ru
Sat Mar 6 17:40:17 PST 2004
>Number: 63863
>Category: kern
>Synopsis: [patch] implement NGM_ELECTROCUTE
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat Mar 06 17:40:16 PST 2004
>Closed-Date:
>Last-Modified:
>Originator: Gleb Smirnoff
>Release: FreeBSD 5.2-CURRENT i386
>Organization:
>Environment:
System: FreeBSD morannon.bestcom.ru 5.2-CURRENT FreeBSD 5.2-CURRENT #3: Mon Mar 1 21:49:20 MSK 2004 glebius at morannon.bestcom.ru:/usr/obj/usr/src/sys/MORANNON i386
>Description:
Implement a new generic netgraph message - "electrocute", which shuts down the
node it was sent to, and all connected nodes recursively.
This idea was suggested by Archie Cobbs in his article:
http://www.daemonnews.org/200003/netgraph.html
One problem is that the word "electrocute" itself is too long. For my point of view
it'll be better to call it "flush" or "destroy".
>How-To-Repeat:
Create a complicated graph. Shutdown it using shutdown message multiple times.
Think about electrocution :)
>Fix:
Here are two diffs: to netgraph base and to ngctl utility.
--- netgraph.h.orig Mon Mar 1 21:36:58 2004
+++ netgraph.h Sun Mar 7 03:06:34 2004
@@ -349,6 +349,7 @@
#define NG_FORCE_WRITER 0x00000004 /* Never multithread this node */
#define NG_CLOSING 0x00000008 /* ng_rmnode() at work */
#define NG_REALLY_DIE 0x00000010 /* "persistant" node is unloading */
+#define NG_ELECTROCUTING 0x00000020 /* node is already touched by electrocution */
#define NGF_TYPE1 0x10000000 /* reserved for type specific storage */
#define NGF_TYPE2 0x20000000 /* reserved for type specific storage */
#define NGF_TYPE3 0x40000000 /* reserved for type specific storage */
--- ng_message.h.orig Sun Mar 7 03:07:39 2004
+++ ng_message.h Sun Mar 7 03:07:53 2004
@@ -131,6 +131,7 @@
#define NGM_BINARY2ASCII (12|NGM_READONLY)/* convert ng_mesg to ascii */
#define NGM_ASCII2BINARY (13|NGM_READONLY)/* convert ascii to ng_mesg */
#define NGM_TEXT_CONFIG 14 /* (optional) get/set text config */
+#define NGM_ELECTROCUTE 15 /* shut down node and attached graph */
/*
* Flow control and intra node control messages.
--- ng_base.c.orig Mon Mar 1 20:51:10 2004
+++ ng_base.c Sun Mar 7 03:59:18 2004
@@ -525,6 +525,13 @@
&ng_parse_ng_mesg_type,
&ng_parse_ng_mesg_type
},
+ {
+ NGM_GENERIC_COOKIE,
+ NGM_ELECTROCUTE,
+ "electrocute",
+ NULL,
+ NULL
+ },
{ 0 }
};
@@ -2475,6 +2482,39 @@
case NGM_SHUTDOWN:
ng_rmnode(here, NULL, NULL, 0);
break;
+ case NGM_ELECTROCUTE:
+ {
+ hook_p hook;
+
+ /* Check if it's already shutting down */
+ if ((here->nd_flags & NG_ELECTROCUTING) != 0)
+ break;
+
+ here->nd_flags |= NG_ELECTROCUTING;
+
+ LIST_FOREACH(hook, &here->nd_hooks, hk_hooks) {
+ struct ng_mesg *msg;
+
+ /* In case of closed graph we can encounter a node
+ * which has already received message */
+ if (NG_NODE_NOT_VALID(NG_PEER_NODE(hook)))
+ continue;
+
+ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_ELECTROCUTE, 0, M_NOWAIT);
+ if (msg == NULL) {
+ error = ENOBUFS;
+ break;
+ }
+
+ NG_SEND_MSG_HOOK(error, here, msg, hook, 0);
+ if (error)
+ break;
+
+ }
+
+ ng_rmnode(here, NULL, NULL, 0);
+ break;
+ }
case NGM_MKPEER:
{
struct ngm_mkpeer *const mkp = (struct ngm_mkpeer *) msg->data;
diff -Nu ngctl.orig/Makefile ngctl/Makefile
--- ngctl.orig/Makefile Sun Mar 7 04:07:52 2004
+++ ngctl/Makefile Sun Mar 7 03:13:01 2004
@@ -4,7 +4,8 @@
PROG= ngctl
MAN= ngctl.8
SRCS= main.c mkpeer.c config.c connect.c dot.c name.c show.c list.c \
- msg.c debug.c shutdown.c rmhook.c status.c types.c write.c
+ msg.c debug.c shutdown.c rmhook.c status.c types.c write.c \
+ electrocute.c
WARNS?= 3
DPADD= ${LIBNETGRAPH}
LDADD= -lnetgraph
diff -Nu ngctl.orig/electrocute.c ngctl/electrocute.c
--- ngctl.orig/electrocute.c Thu Jan 1 03:00:00 1970
+++ ngctl/electrocute.c Mon Mar 1 23:27:59 2004
@@ -0,0 +1,73 @@
+
+/*
+ * electrocute.c
+ *
+ * Copyright (c) 1996-1999 Whistle Communications, Inc.
+ * All rights reserved.
+ *
+ * Subject to the following obligations and disclaimer of warranty, use and
+ * redistribution of this software, in source or object code forms, with or
+ * without modifications are expressly permitted by Whistle Communications;
+ * provided, however, that:
+ * 1. Any and all reproductions of the source or object code must include the
+ * copyright notice above and the following disclaimer of warranties; and
+ * 2. No rights are granted, in any manner or form, to use Whistle
+ * Communications, Inc. trademarks, including the mark "WHISTLE
+ * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
+ * such appears in the above copyright notice or in the software.
+ *
+ * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
+ * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
+ * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
+ * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
+ * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
+ * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
+ * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
+ * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
+ * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $FreeBSD: src/usr.sbin/ngctl/shutdown.c,v 1.2 1999/11/30 02:45:32 archie Exp $
+ */
+
+#include "ngctl.h"
+
+static int ElectrocuteCmd(int ac, char **av);
+
+const struct ngcmd electrocute_cmd = {
+ ElectrocuteCmd,
+ "electrocute <path>",
+ "Shutdown the node and attached graph at <path>",
+ NULL,
+ { "destroy", "rmgraph" }
+};
+
+static int
+ElectrocuteCmd(int ac, char **av)
+{
+ char *path;
+
+ /* Get arguments */
+ switch (ac) {
+ case 2:
+ path = av[1];
+ break;
+ default:
+ return(CMDRTN_USAGE);
+ }
+
+ /* Shutdown node */
+ if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
+ NGM_ELECTROCUTE, NULL, 0) < 0) {
+ warn("electrocute");
+ return(CMDRTN_ERROR);
+ }
+ return(CMDRTN_OK);
+}
diff -Nu ngctl.orig/main.c ngctl/main.c
--- ngctl.orig/main.c Sun Mar 7 04:07:52 2004
+++ ngctl/main.c Sun Mar 7 03:14:04 2004
@@ -72,6 +72,7 @@
&rmhook_cmd,
&show_cmd,
&shutdown_cmd,
+ &electrocute_cmd,
&status_cmd,
&types_cmd,
&write_cmd,
diff -Nu ngctl.orig/ngctl.h ngctl/ngctl.h
--- ngctl.orig/ngctl.h Sun Mar 7 04:07:52 2004
+++ ngctl/ngctl.h Sun Mar 7 03:13:27 2004
@@ -88,6 +88,7 @@
extern const struct ngcmd rmhook_cmd;
extern const struct ngcmd show_cmd;
extern const struct ngcmd shutdown_cmd;
+extern const struct ngcmd electrocute_cmd;
extern const struct ngcmd status_cmd;
extern const struct ngcmd types_cmd;
extern const struct ngcmd write_cmd;
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list