From c5c63975d538cf48ceb99ba48c341293676d15c0 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 21 Oct 1999 09:06:11 +0000 Subject: Whistle's Netgraph link-layer (sometimes more) networking infrastructure. Been in production for 3 years now. Gives Instant Frame relay to if_sr and if_ar drivers, and PPPOE support soon. See: ftp://ftp.whistle.com/pub/archie/netgraph/index.html for on-line manual pages. Reviewed by: Doug Rabson (dfr@freebsd.org) Obtained from: Whistle CVS tree --- usr.sbin/Makefile | 2 + usr.sbin/ngctl/Makefile | 15 ++ usr.sbin/ngctl/connect.c | 85 +++++++++++ usr.sbin/ngctl/debug.c | 78 ++++++++++ usr.sbin/ngctl/list.c | 113 ++++++++++++++ usr.sbin/ngctl/main.c | 373 ++++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/ngctl/mkpeer.c | 85 +++++++++++ usr.sbin/ngctl/name.c | 75 ++++++++++ usr.sbin/ngctl/ngctl.8 | 115 ++++++++++++++ usr.sbin/ngctl/ngctl.h | 89 +++++++++++ usr.sbin/ngctl/rmhook.c | 81 ++++++++++ usr.sbin/ngctl/show.c | 130 ++++++++++++++++ usr.sbin/ngctl/shutdown.c | 74 +++++++++ usr.sbin/ngctl/status.c | 95 ++++++++++++ usr.sbin/ngctl/types.c | 92 ++++++++++++ usr.sbin/nghook/Makefile | 11 ++ usr.sbin/nghook/main.c | 220 +++++++++++++++++++++++++++ usr.sbin/nghook/nghook.8 | 87 +++++++++++ 18 files changed, 1820 insertions(+) create mode 100644 usr.sbin/ngctl/Makefile create mode 100644 usr.sbin/ngctl/connect.c create mode 100644 usr.sbin/ngctl/debug.c create mode 100644 usr.sbin/ngctl/list.c create mode 100644 usr.sbin/ngctl/main.c create mode 100644 usr.sbin/ngctl/mkpeer.c create mode 100644 usr.sbin/ngctl/name.c create mode 100644 usr.sbin/ngctl/ngctl.8 create mode 100644 usr.sbin/ngctl/ngctl.h create mode 100644 usr.sbin/ngctl/rmhook.c create mode 100644 usr.sbin/ngctl/show.c create mode 100644 usr.sbin/ngctl/shutdown.c create mode 100644 usr.sbin/ngctl/status.c create mode 100644 usr.sbin/ngctl/types.c create mode 100644 usr.sbin/nghook/Makefile create mode 100644 usr.sbin/nghook/main.c create mode 100644 usr.sbin/nghook/nghook.8 (limited to 'usr.sbin') diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile index b56da8f..356e36c 100644 --- a/usr.sbin/Makefile +++ b/usr.sbin/Makefile @@ -47,6 +47,8 @@ SUBDIR= IPXrouted \ named.restart \ ndc \ newsyslog \ + ngctl \ + nghook \ nslookup \ nsupdate \ pccard \ diff --git a/usr.sbin/ngctl/Makefile b/usr.sbin/ngctl/Makefile new file mode 100644 index 0000000..a4e02ad --- /dev/null +++ b/usr.sbin/ngctl/Makefile @@ -0,0 +1,15 @@ +# $FreeBSD$ +# $Whistle: Makefile,v 1.3 1999/01/16 00:10:11 archie Exp $ + +PROG= ngctl +SRCS= main.c mkpeer.c connect.c name.c show.c list.c \ + debug.c shutdown.c rmhook.c status.c types.c +MAN8= ngctl.8 + +LDADD+= -lnetgraph +DPADD+= /usr/lib/libnetgraph.a + +COPTS+= -O2 -g -Wall -Werror +COPTS+= -I/usr/src.freefall/sys + +.include diff --git a/usr.sbin/ngctl/connect.c b/usr.sbin/ngctl/connect.c new file mode 100644 index 0000000..8b15ca0 --- /dev/null +++ b/usr.sbin/ngctl/connect.c @@ -0,0 +1,85 @@ + +/* + * connect.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$ + */ + +#include "ngctl.h" + +static int ConnectCmd(int ac, char **av); + +const struct ngcmd connect_cmd = { + ConnectCmd, + "connect [path] ", + "Connects hook of the node at to ", + "The connect command creates a link between the two nodes at" + " \"path\" and \"relpath\" using hooks \"hook\" and \"peerhook\"," + " respectively. The \"relpath\", if not absolute, is specified" + " relative to the node at \"path\"." + " If \"path\" is omitted then \".\" is assumed." +}; + +static int +ConnectCmd(int ac, char **av) +{ + struct ngm_connect con; + char *path = "."; + + /* Get arguments */ + switch (ac) { + case 5: + path = av[1]; + ac--; + av++; + /* FALLTHROUGH */ + case 4: + snprintf(con.path, sizeof(con.path), "%s", av[1]); + snprintf(con.ourhook, sizeof(con.ourhook), "%s", av[2]); + snprintf(con.peerhook, sizeof(con.peerhook), "%s", av[3]); + break; + default: + return(CMDRTN_USAGE); + } + + /* Send message */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_CONNECT, &con, sizeof(con)) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + return(CMDRTN_OK); +} + diff --git a/usr.sbin/ngctl/debug.c b/usr.sbin/ngctl/debug.c new file mode 100644 index 0000000..7b355e5 --- /dev/null +++ b/usr.sbin/ngctl/debug.c @@ -0,0 +1,78 @@ + +/* + * debug.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$ + */ + +#include "ngctl.h" + +static int DebugCmd(int ac, char **av); + +const struct ngcmd debug_cmd = { + DebugCmd, + "debug [level]", + "Get/set debugging verbosity level", + "Without any argument, this command displays the current" + " debugging verbosity level. If the argument is ``+'' or ``-''" + " the debug level is incremented or decremented; otherwise," + " it must be an absolute numerical level." +}; + +static int +DebugCmd(int ac, char **av) +{ + int level; + + /* Get arguments */ + switch (ac) { + case 2: + if (!strcmp(av[1], "+")) + level = NgSetDebug(-1) + 1; + else if (!strcmp(av[1], "-")) + level = NgSetDebug(-1) - 1; + else if ((level = atoi(av[1])) < 0) + return(CMDRTN_USAGE); + NgSetDebug(level); + break; + case 1: + printf("Current debug level is %d\n", NgSetDebug(-1)); + break; + default: + return(CMDRTN_USAGE); + } + return(CMDRTN_OK); +} + diff --git a/usr.sbin/ngctl/list.c b/usr.sbin/ngctl/list.c new file mode 100644 index 0000000..d763061 --- /dev/null +++ b/usr.sbin/ngctl/list.c @@ -0,0 +1,113 @@ + +/* + * list.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$ + */ + +#include "ngctl.h" + +static int ListCmd(int ac, char **av); + +const struct ngcmd list_cmd = { + ListCmd, + "list [-n]", + "Show information about all nodes", + "The list command shows information every node that currently" + " exists in the netgraph system. The optional -n argument limits" + " this list to only those nodes with a global name assignment." +}; + +static int +ListCmd(int ac, char **av) +{ + u_char rbuf[16 * 1024]; + struct ng_mesg *const resp = (struct ng_mesg *) rbuf; + struct namelist *const nlist = (struct namelist *) resp->data; + int named_only = 0; + int k, ch, rtn = CMDRTN_OK; + + /* Get options */ + optind = 1; + while ((ch = getopt(ac, av, "n")) != EOF) { + switch (ch) { + case 'n': + named_only = 1; + break; + case '?': + default: + return(CMDRTN_USAGE); + break; + } + } + ac -= optind; + av += optind; + + /* Get arguments */ + switch (ac) { + case 0: + break; + default: + return(CMDRTN_USAGE); + } + + /* Get list of nodes */ + if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, + named_only ? NGM_LISTNAMES : NGM_LISTNODES, NULL, 0) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0) { + warn("recv msg"); + return(CMDRTN_ERROR); + } + + /* Show each node */ + printf("There are %d total %snodes:\n", + nlist->numnames, named_only ? "named " : ""); + for (k = 0; k < nlist->numnames; k++) { + char path[NG_PATHLEN+1]; + char *av[3] = { "list", "-n", path }; + + snprintf(path, sizeof(path), + "[%lx]:", (u_long) nlist->nodeinfo[k].id); + if ((rtn = (*show_cmd.func)(3, av)) != CMDRTN_OK) + break; + } + + /* Done */ + return (rtn); +} + diff --git a/usr.sbin/ngctl/main.c b/usr.sbin/ngctl/main.c new file mode 100644 index 0000000..9a54cc7 --- /dev/null +++ b/usr.sbin/ngctl/main.c @@ -0,0 +1,373 @@ + +/* + * main.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$ + */ + +#include "ngctl.h" + +#define PROMPT "+ " +#define MAX_ARGS 512 +#define WHITESPACE " \t\r\n\v\f" + +/* Internal functions */ +static int ReadFile(FILE *fp); +static int DoParseCommand(char *line); +static int DoCommand(int ac, char **av); +static int DoInteractive(void); +static const struct ngcmd *FindCommand(const char *string); +static void Usage(const char *msg); +static int ReadCmd(int ac, char **av); +static int HelpCmd(int ac, char **av); +static int QuitCmd(int ac, char **av); + +/* List of commands */ +static const struct ngcmd *const cmds[] = { + &connect_cmd, + &debug_cmd, + &help_cmd, + &list_cmd, + &mkpeer_cmd, + &name_cmd, + &read_cmd, + &rmhook_cmd, + &show_cmd, + &shutdown_cmd, + &status_cmd, + &types_cmd, + &quit_cmd, + NULL +}; + +/* Commands defined in this file */ +const struct ngcmd read_cmd = { + ReadCmd, + "read ", + "Read and execute commands from a file", + NULL +}; +const struct ngcmd help_cmd = { + HelpCmd, + "help [command]", + "Show command summary or get more help on a specific command", + NULL +}; +const struct ngcmd quit_cmd = { + QuitCmd, + "quit", + "Exit program", + NULL +}; + +/* Our control and data sockets */ +int csock, dsock; + +/* + * main() + */ +int +main(int ac, char *av[]) +{ + char name[NG_NODELEN + 1]; + int interactive = isatty(0) && isatty(1); + FILE *fp = NULL; + int ch, rtn = 0; + + /* Set default node name */ + snprintf(name, sizeof(name), "ngctl%d", getpid()); + + /* Parse command line */ + while ((ch = getopt(ac, av, "df:n:")) != EOF) { + switch (ch) { + case 'd': + NgSetDebug(NgSetDebug(-1) + 1); + break; + case 'f': + if (strcmp(optarg, "-") == 0) + fp = stdin; + else if ((fp = fopen(optarg, "r")) == NULL) + err(EX_NOINPUT, "%s", optarg); + break; + case 'n': + snprintf(name, sizeof(name), "%s", optarg); + break; + case '?': + default: + Usage((char *)NULL); + break; + } + } + ac -= optind; + av += optind; + + /* Create a new socket node */ + if (NgMkSockNode(name, &csock, &dsock) < 0) + err(EX_OSERR, "can't create node"); + + /* Do commands as requested */ + if (ac == 0) { + if (fp != NULL) { + rtn = ReadFile(fp); + } else if (interactive) { + rtn = DoInteractive(); + } else + Usage("no command specified"); + } else { + rtn = DoCommand(ac, av); + } + + /* Convert command return code into system exit code */ + switch (rtn) { + case CMDRTN_OK: + case CMDRTN_QUIT: + rtn = 0; + break; + case CMDRTN_USAGE: + rtn = EX_USAGE; + break; + case CMDRTN_ERROR: + rtn = EX_OSERR; + break; + } + return(rtn); +} + +/* + * Process commands from a file + */ +static int +ReadFile(FILE *fp) +{ + char line[LINE_MAX]; + int num, rtn; + + for (num = 1; fgets(line, sizeof(line), fp) != NULL; num++) { + if (*line == '#') + continue; + if ((rtn = DoParseCommand(line)) != 0) { + warnx("line %d: error in file", num); + return(rtn); + } + } + return(CMDRTN_OK); +} + +/* + * Interactive mode + */ +static int +DoInteractive(void) +{ + char buf[LINE_MAX]; + + /* Read commands from stdin */ + (*help_cmd.func)(0, NULL); + do { + printf("%s", PROMPT); + if (fgets(buf, sizeof(buf), stdin) == NULL) + break; + fflush(stdout); + } while (DoParseCommand(buf) != CMDRTN_QUIT); + return(CMDRTN_QUIT); +} + +/* + * Parse a command line and execute the command + */ +static int +DoParseCommand(char *line) +{ + char *av[MAX_ARGS]; + int ac; + + /* Parse line */ + for (ac = 0, av[0] = strtok(line, WHITESPACE); + ac < MAX_ARGS - 1 && av[ac]; + av[++ac] = strtok(NULL, WHITESPACE)); + + /* Do command */ + return(DoCommand(ac, av)); +} + +/* + * Execute the command + */ +static int +DoCommand(int ac, char **av) +{ + const struct ngcmd *cmd; + int rtn; + + if (ac == 0 || *av[0] == 0) + return(CMDRTN_OK); + if ((cmd = FindCommand(av[0])) == NULL) + return(CMDRTN_ERROR); + if ((rtn = (*cmd->func)(ac, av)) == CMDRTN_USAGE) + warnx("usage: %s", cmd->cmd); + return(rtn); +} + +/* + * Find a command + */ +static const struct ngcmd * +FindCommand(const char *string) +{ + const struct ngcmd *cmd; + int k, len, found; + + if (strcmp(string, "?") == 0) + string = "help"; + for (k = 0, found = -1; cmds[k]; k++) { + cmd = cmds[k]; + len = strcspn(cmd->cmd, WHITESPACE); + if (len > strlen(string)) + len = strlen(string); + if (!strncasecmp(string, cmd->cmd, len)) { + if (found != -1) { + warnx("\"%s\": ambiguous command", string); + return(NULL); + } + found = k; + } + } + if (found == -1) { + warnx("\"%s\": unknown command", string); + return(NULL); + } + return(cmds[found]); +} + +/* + * ReadCmd() + */ +static int +ReadCmd(int ac, char **av) +{ + FILE *fp; + int rtn; + + /* Open file */ + switch (ac) { + case 2: + if ((fp = fopen(av[1], "r")) == NULL) + warn("%s", av[1]); + return(CMDRTN_ERROR); + default: + return(CMDRTN_USAGE); + } + + /* Process it */ + rtn = ReadFile(fp); + fclose(fp); + return(rtn); +} + +/* + * HelpCmd() + */ +static int +HelpCmd(int ac, char **av) +{ + const struct ngcmd *cmd; + int k; + + switch (ac) { + case 0: + case 1: + /* Show all commands */ + printf("Available commands:\n"); + for (k = 0; cmds[k] != NULL; k++) { + char *s, buf[100]; + + cmd = cmds[k]; + snprintf(buf, sizeof(buf), "%s", cmd->cmd); + for (s = buf; *s != '\0' && !isspace(*s); s++); + *s = '\0'; + printf(" %-10s %s\n", buf, cmd->desc); + } + return(CMDRTN_OK); + default: + /* Show help on a specific command */ + if ((cmd = FindCommand(av[1])) != NULL) { + printf("Usage: %s\n", cmd->cmd); + printf("Summary: %s\n", cmd->desc); + if (cmd->help != NULL) { + const char *s; + char buf[65]; + int tot, len, done; + + printf("Description:\n"); + for (s = cmd->help; *s != '\0'; s += len) { + while (isspace(*s)) + s++; + tot = snprintf(buf, + sizeof(buf), "%s", s); + len = strlen(buf); + done = len == tot; + if (!done) { + while (len > 0 + && !isspace(buf[len-1])) + buf[--len] = '\0'; + } + printf(" %s\n", buf); + } + } + } + } + return(CMDRTN_OK); +} + +/* + * QuitCmd() + */ +static int +QuitCmd(int ac, char **av) +{ + return(CMDRTN_QUIT); +} + +/* + * Usage() + */ +static void +Usage(const char *msg) +{ + if (msg) + warnx("%s", msg); + errx(EX_USAGE, "usage: ngctl [-d] [-f file] [-n name] [command ...]"); +} + diff --git a/usr.sbin/ngctl/mkpeer.c b/usr.sbin/ngctl/mkpeer.c new file mode 100644 index 0000000..c5735e1 --- /dev/null +++ b/usr.sbin/ngctl/mkpeer.c @@ -0,0 +1,85 @@ + +/* + * mkpeer.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$ + */ + +#include "ngctl.h" + +static int MkPeerCmd(int ac, char **av); + +const struct ngcmd mkpeer_cmd = { + MkPeerCmd, + "mkpeer [path] ", + "Create and connect a new node to the node at \"path\"", + "The mkpeer command atomically creates a new node of type \"type\"" + " and connects it to the node at \"path\". The hooks used for the" + " connection are \"hook\" on the original node and \"peerhook\"" + " on the new node." + " If \"path\" is omitted then \".\" is assumed." +}; + +static int +MkPeerCmd(int ac, char **av) +{ + struct ngm_mkpeer mkp; + char *path = "."; + + /* Get arguments */ + switch (ac) { + case 5: + path = av[1]; + ac--; + av++; + /* FALLTHROUGH */ + case 4: + snprintf(mkp.type, sizeof(mkp.type), "%s", av[1]); + snprintf(mkp.ourhook, sizeof(mkp.ourhook), "%s", av[2]); + snprintf(mkp.peerhook, sizeof(mkp.peerhook), "%s", av[3]); + break; + default: + return(CMDRTN_USAGE); + } + + /* Send message */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_MKPEER, &mkp, sizeof(mkp)) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + return(CMDRTN_OK); +} + diff --git a/usr.sbin/ngctl/name.c b/usr.sbin/ngctl/name.c new file mode 100644 index 0000000..85c6eff --- /dev/null +++ b/usr.sbin/ngctl/name.c @@ -0,0 +1,75 @@ + +/* + * name.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$ + */ + +#include "ngctl.h" + +static int NameCmd(int ac, char **av); + +const struct ngcmd name_cmd = { + NameCmd, + "name ", + "Assign name to the node at ", + NULL +}; + +static int +NameCmd(int ac, char **av) +{ + struct ngm_name name; + char *path; + + /* Get arguments */ + switch (ac) { + case 3: + path = av[1]; + snprintf(name.name, sizeof(name.name), "%s", av[2]); + break; + default: + return(CMDRTN_USAGE); + } + + /* Send message */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_NAME, &name, sizeof(name)) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + return(CMDRTN_OK); +} + diff --git a/usr.sbin/ngctl/ngctl.8 b/usr.sbin/ngctl/ngctl.8 new file mode 100644 index 0000000..ee4f3be --- /dev/null +++ b/usr.sbin/ngctl/ngctl.8 @@ -0,0 +1,115 @@ +.\" 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$ +.\" $Whistle: ngctl.8,v 1.6 1999/01/20 03:19:44 archie Exp $ +.\" +.Dd January 19, 1999 +.Dt NGCTL 8 +.Os FreeBSD 3 +.Sh NAME +.Nm ngctl +.Nd netgraph control utility +.Sh SYNOPSIS +.Nm ngctl +.Op Fl d +.Op Fl f Ar filename +.Op Fl n Ar nodename +.Op Ar command ... +.Sh DESCRIPTION +The +.Nm +utility creates a new netgraph node of type +.Em socket +which can be used to issue netgraph commands. +If no +.Fl f +flag is given, no +command is supplied on the command line, and standard input is a tty, +.Nm ngctl +will enter interactive mode. Otherwise +.Nm ngctl +will execute the supplied command(s) and exit immediately. +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl f Ar nodeinfo +Read commands from the named file. +A single dash represents the standard input. +Blank lines and lines starting with a ``#'' are ignored. +.It Fl n Ar nodename +Assign +.Em nodename +to the newly created netgraph node. The default name is +.Em ngctlXXX +where XXX is the process ID number. +.It Fl d +Increase the debugging verbosity level. +.El +.Sh COMMANDS +The currently supported commands in +.Nm ngctl +are: +.Pp +.Bd -literal -offset indent -compact +connect Connects two nodes +debug Get/set debugging verbosity level +help Show command summary or get help on a command +list Show information about all nodes +mkpeer Create and connect a new node to an existing node +name Assign a name to a node +read Read and execute commands from a file +rmhook Disconnect a node's hook +show Show information about a node +shutdown Shutdown a node +status Get human readable status from a node +types Show all installed node types +quit Exit program +.Ed +.Pp +The ``help'' command displays the available +commands, their usage, and a brief description. +.Sh EXIT VALUE +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr netgraph 3 , +.Xr netgraph 4 . +.Xr nghook 8 . +.Sh AUTHOR +Archie Cobbs +.Sh HISTORY +The +.Em netgraph +system was designed and first implemented at Whistle Communications, Inc. +in a version FreeBSD 2.2 customized for the Whistle InterJet. diff --git a/usr.sbin/ngctl/ngctl.h b/usr.sbin/ngctl/ngctl.h new file mode 100644 index 0000000..b0fce23 --- /dev/null +++ b/usr.sbin/ngctl/ngctl.h @@ -0,0 +1,89 @@ + +/* + * ngctl.h + * + * 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$ + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* Command descriptors */ +struct ngcmd { + int (*func)(int ac, char **av); + const char *cmd; + const char *desc; + const char *help; +}; + +/* Command return values */ +#define CMDRTN_OK 0 +#define CMDRTN_USAGE 1 +#define CMDRTN_ERROR 2 +#define CMDRTN_QUIT 3 + +/* Available commands */ +extern const struct ngcmd connect_cmd; +extern const struct ngcmd debug_cmd; +extern const struct ngcmd help_cmd; +extern const struct ngcmd list_cmd; +extern const struct ngcmd mkpeer_cmd; +extern const struct ngcmd name_cmd; +extern const struct ngcmd read_cmd; +extern const struct ngcmd rmhook_cmd; +extern const struct ngcmd show_cmd; +extern const struct ngcmd shutdown_cmd; +extern const struct ngcmd status_cmd; +extern const struct ngcmd types_cmd; +extern const struct ngcmd quit_cmd; + +/* Data and control sockets */ +extern int csock, dsock; + diff --git a/usr.sbin/ngctl/rmhook.c b/usr.sbin/ngctl/rmhook.c new file mode 100644 index 0000000..551c06f --- /dev/null +++ b/usr.sbin/ngctl/rmhook.c @@ -0,0 +1,81 @@ + +/* + * rmhook.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$ + */ + +#include "ngctl.h" + +static int RmHookCmd(int ac, char **av); + +const struct ngcmd rmhook_cmd = { + RmHookCmd, + "rmhook [path] ", + "Disconnect hook \"hook\" of the node at \"path\"", + "The rmhook command forces the node at \"path\" to break the link" + " formed by its hook \"hook\", if connected." + " If \"path\" is omitted then \".\" is assumed." +}; + +static int +RmHookCmd(int ac, char **av) +{ + struct ngm_rmhook rmh; + char *path = "."; + + /* Get arguments */ + switch (ac) { + case 3: + path = av[1]; + ac--; + av++; + /* FALLTHROUGH */ + case 2: + snprintf(rmh.ourhook, sizeof(rmh.ourhook), "%s", av[1]); + break; + default: + return(CMDRTN_USAGE); + } + + /* Send message */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_RMHOOK, &rmh, sizeof(rmh)) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + return(CMDRTN_OK); +} + diff --git a/usr.sbin/ngctl/show.c b/usr.sbin/ngctl/show.c new file mode 100644 index 0000000..7cfdd48 --- /dev/null +++ b/usr.sbin/ngctl/show.c @@ -0,0 +1,130 @@ + +/* + * show.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$ + */ + +#include "ngctl.h" + +#define FMT " %-15s %-15s %-12s %-15s %-15s\n" +#define UNNAMED "" +#define NOSTATUS "" + +static int ShowCmd(int ac, char **av); + +const struct ngcmd show_cmd = { + ShowCmd, + "show [-n] ", + "Show information about the node at ", + "If the -n flag is given, hooks are not listed." +}; + +static int +ShowCmd(int ac, char **av) +{ + char *path; + u_char rbuf[16 * 1024]; + struct ng_mesg *const resp = (struct ng_mesg *) rbuf; + struct hooklist *const hlist = (struct hooklist *) resp->data; + struct nodeinfo *const ninfo = &hlist->nodeinfo; + int ch, no_hooks = 0; + + /* Get options */ + optind = 1; + while ((ch = getopt(ac, av, "n")) != EOF) { + switch (ch) { + case 'n': + no_hooks = 1; + break; + case '?': + default: + return(CMDRTN_USAGE); + break; + } + } + ac -= optind; + av += optind; + + /* Get arguments */ + switch (ac) { + case 1: + path = av[0]; + break; + default: + return(CMDRTN_USAGE); + } + + /* Get node info and hook list */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_LISTHOOKS, NULL, 0) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0) { + warn("recv msg"); + return(CMDRTN_ERROR); + } + + /* Show node information */ + if (!*ninfo->name) + snprintf(ninfo->name, sizeof(ninfo->name), "%s", UNNAMED); + printf(" Name: %-15s Type: %-15s ID: %08x Num hooks: %d\n", + ninfo->name, ninfo->type, ninfo->id, ninfo->hooks); + if (!no_hooks && ninfo->hooks > 0) { + int k; + + printf(FMT, "Local hook", "Peer name", + "Peer type", "Peer ID", "Peer hook"); + printf(FMT, "----------", "---------", + "---------", "-------", "---------"); + for (k = 0; k < ninfo->hooks; k++) { + struct linkinfo *const link = &hlist->link[k]; + struct nodeinfo *const peer = &hlist->link[k].nodeinfo; + char idbuf[20]; + + if (!*peer->name) { + snprintf(peer->name, sizeof(peer->name), + "%s", UNNAMED); + } + snprintf(idbuf, sizeof(idbuf), "%08x", peer->id); + printf(FMT, link->ourhook, peer->name, + peer->type, idbuf, link->peerhook); + } + } + return(CMDRTN_OK); +} + + diff --git a/usr.sbin/ngctl/shutdown.c b/usr.sbin/ngctl/shutdown.c new file mode 100644 index 0000000..769f122 --- /dev/null +++ b/usr.sbin/ngctl/shutdown.c @@ -0,0 +1,74 @@ + +/* + * shutdown.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$ + */ + +#include "ngctl.h" + +static int ShutdownCmd(int ac, char **av); + +const struct ngcmd shutdown_cmd = { + ShutdownCmd, + "shutdown ", + "Shutdown the node at ", + NULL +}; + +static int +ShutdownCmd(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_SHUTDOWN, NULL, 0) < 0) { + warn("shutdown"); + return(CMDRTN_ERROR); + } + return(CMDRTN_OK); +} + + diff --git a/usr.sbin/ngctl/status.c b/usr.sbin/ngctl/status.c new file mode 100644 index 0000000..75706b3 --- /dev/null +++ b/usr.sbin/ngctl/status.c @@ -0,0 +1,95 @@ + +/* + * status.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$ + */ + +#include "ngctl.h" + +#define NOSTATUS "" + +static int StatusCmd(int ac, char **av); + +const struct ngcmd status_cmd = { + StatusCmd, + "status ", + "Get human readable status information from the node at ", + NULL +}; + +static int +StatusCmd(int ac, char **av) +{ + u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE]; + struct ng_mesg *const resp = (struct ng_mesg *) sbuf; + char *const status = (char *) resp->data; + char *path; + int nostat = 0; + + /* Get arguments */ + switch (ac) { + case 2: + path = av[1]; + break; + default: + return(CMDRTN_USAGE); + } + + /* Get node status summary */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_TEXT_STATUS, NULL, 0) < 0) { + switch (errno) { + case EINVAL: + nostat = 1; + break; + default: + warn("send msg"); + return(CMDRTN_ERROR); + } + } else { + if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0 + || (resp->header.flags & NGF_RESP) == 0) + nostat = 1; + } + + /* Show it */ + if (nostat) + printf("No status available for \"%s\"\n", path); + else + printf("Status for \"%s\":\n%s\n", path, status); + return(CMDRTN_OK); +} + diff --git a/usr.sbin/ngctl/types.c b/usr.sbin/ngctl/types.c new file mode 100644 index 0000000..b7be6aa --- /dev/null +++ b/usr.sbin/ngctl/types.c @@ -0,0 +1,92 @@ + +/* + * types.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$ + */ + +#include "ngctl.h" + +static int TypesCmd(int ac, char **av); + +const struct ngcmd types_cmd = { + TypesCmd, + "types", + "Show information about all installed node types", + NULL +}; + +static int +TypesCmd(int ac, char **av) +{ + u_char rbuf[16 * 1024]; + struct ng_mesg *const resp = (struct ng_mesg *) rbuf; + struct typelist *const tlist = (struct typelist *) resp->data; + int k, rtn = CMDRTN_OK; + + /* Get arguments */ + switch (ac) { + case 1: + break; + default: + return(CMDRTN_USAGE); + } + + /* Get list of types */ + if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, + NGM_LISTTYPES, NULL, 0) < 0) { + warn("send msg"); + return(CMDRTN_ERROR); + } + if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0) { + warn("recv msg"); + return(CMDRTN_ERROR); + } + + /* Show each type */ + printf("There are %d total types:\n", tlist->numtypes); + if (tlist->numtypes > 0) { + printf("%15s Number of living nodes\n", "Type name"); + printf("%15s ----------------------\n", "---------"); + } + for (k = 0; k < tlist->numtypes; k++) { + struct typeinfo *const ti = &tlist->typeinfo[k]; + printf("%15s %5d\n", ti->typename, ti->numnodes); + } + + /* Done */ + return (rtn); +} + diff --git a/usr.sbin/nghook/Makefile b/usr.sbin/nghook/Makefile new file mode 100644 index 0000000..1130ec9 --- /dev/null +++ b/usr.sbin/nghook/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ +# $Whistle: Makefile,v 1.4 1999/01/16 04:44:33 archie Exp $ + +PROG= nghook +SRCS= main.c +MAN8= nghook.8 +DPADD= ${LIBNETGRAPH} +LDADD= -lnetgraph +COPTS+= -g -Wall -O2 -Werror + +.include diff --git a/usr.sbin/nghook/main.c b/usr.sbin/nghook/main.c new file mode 100644 index 0000000..ce29d9d --- /dev/null +++ b/usr.sbin/nghook/main.c @@ -0,0 +1,220 @@ + +/* + * main.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$ + * $Whistle: main.c,v 1.9 1999/01/20 00:26:26 archie Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#define DEFAULT_HOOKNAME "debug" +#define NG_SOCK_HOOK_NAME "hook" + +#define BUF_SIZE (64 * 1024) + +static void WriteAscii(u_char * buf, int len); +static void Usage(void); + +/* + * main() + */ +int +main(int ac, char *av[]) +{ + struct ngm_connect ngc; + char *path = NULL, *hook = DEFAULT_HOOKNAME; + int csock, dsock; + int asciiFlag = 0; + int ch; + + /* Parse flags */ + while ((ch = getopt(ac, av, "da")) != EOF) { + switch (ch) { + case 'd': + NgSetDebug(NgSetDebug(-1) + 1); + break; + case 'a': + asciiFlag = 1; + break; + case '?': + default: + Usage(); + } + } + ac -= optind; + av += optind; + + /* Get params */ + switch (ac) { + case 2: + hook = av[1]; + /* FALLTHROUGH */ + case 1: + path = av[0]; + break; + default: + Usage(); + } + + /* Get sockets */ + if (NgMkSockNode(NULL, &csock, &dsock) < 0) + errx(EX_OSERR, "can't get sockets"); + + /* Connect socket node to specified node */ + snprintf(ngc.path, sizeof(ngc.path), "%s", path); + snprintf(ngc.ourhook, sizeof(ngc.ourhook), NG_SOCK_HOOK_NAME); + snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", hook); + + if (NgSendMsg(csock, ".", + NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, sizeof(ngc)) < 0) + errx(EX_OSERR, "can't connect to node"); + + /* Relay data */ + while (1) { + fd_set rfds; + + /* Setup bits */ + FD_ZERO(&rfds); + FD_SET(0, &rfds); + FD_SET(dsock, &rfds); + + /* Wait for something to happen */ + if (select(FD_SETSIZE, &rfds, NULL, NULL, NULL) < 0) + err(EX_OSERR, "select"); + + /* Check data from socket */ + if (FD_ISSET(dsock, &rfds)) { + char buf[BUF_SIZE]; + int rl, wl; + + /* Read packet from socket */ + if ((rl = NgRecvData(dsock, + buf, sizeof(buf), NULL)) < 0) + err(EX_OSERR, "read(hook)"); + if (rl == 0) + errx(EX_OSERR, "read EOF from hook?!"); + + /* Write packet to stdout */ + if (asciiFlag) + WriteAscii((u_char *) buf, rl); + else if ((wl = write(1, buf, rl)) != rl) { + if (wl < 0) { + err(EX_OSERR, "write(stdout)"); + } else { + errx(EX_OSERR, + "stdout: read %d, wrote %d", + rl, wl); + } + } + } + + /* Check data from stdin */ + if (FD_ISSET(0, &rfds)) { + char buf[BUF_SIZE]; + int rl; + + /* Read packet from stdin */ + if ((rl = read(0, buf, sizeof(buf))) < 0) + err(EX_OSERR, "read(stdin)"); + if (rl == 0) + errx(EX_OSERR, "EOF(stdin)"); + + /* Write packet to socket */ + if (NgSendData(dsock, NG_SOCK_HOOK_NAME, buf, rl) < 0) + err(EX_OSERR, "write(hook)"); + } + } +} + +/* + * Dump data in hex and ASCII form + */ +static void +WriteAscii(u_char *buf, int len) +{ + char ch, sbuf[100]; + int k, count; + + for (count = 0; count < len; count += 16) { + snprintf(sbuf, sizeof(sbuf), "%04x: ", count); + for (k = 0; k < 16; k++) + if (count + k < len) + snprintf(sbuf + strlen(sbuf), + sizeof(sbuf) - strlen(sbuf), + "%02x ", buf[count + k]); + else + snprintf(sbuf + strlen(sbuf), + sizeof(sbuf) - strlen(sbuf), " "); + snprintf(sbuf + strlen(sbuf), sizeof(sbuf) - strlen(sbuf), " "); + for (k = 0; k < 16; k++) + if (count + k < len) { + ch = isprint(buf[count + k]) ? + buf[count + k] : '.'; + snprintf(sbuf + strlen(sbuf), + sizeof(sbuf) - strlen(sbuf), "%c", ch); + } else + snprintf(sbuf + strlen(sbuf), + sizeof(sbuf) - strlen(sbuf), " "); + snprintf(sbuf + strlen(sbuf), + sizeof(sbuf) - strlen(sbuf), "\n"); + (void) write(1, sbuf, strlen(sbuf)); + } + ch = '\n'; + write(1, &ch, 1); +} + +/* + * Display usage and exit + */ +static void +Usage(void) +{ + errx(EX_USAGE, "usage: nghook [-da] path [hookname]"); +} + diff --git a/usr.sbin/nghook/nghook.8 b/usr.sbin/nghook/nghook.8 new file mode 100644 index 0000000..33016b0 --- /dev/null +++ b/usr.sbin/nghook/nghook.8 @@ -0,0 +1,87 @@ +.\" 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$ +.\" $Whistle: nghook.8,v 1.4 1999/01/20 03:19:45 archie Exp $ +.\" +.Dd January 19, 1999 +.Dt NGHOOK 8 +.Os FreeBSD 3 +.Sh NAME +.Nm nghook +.Nd connect to a +.Xr netgraph 8 +node +.Sh SYNOPSIS +.Nm +.Op Fl a +.Op Fl d +.Ar path +.Op Ar hookname +.Sh DESCRIPTION +.Nm +creates a +.Xr netgraph 8 +socket type node and connects it to hook +.Ar hookname +of the node found at +.Ar path . +If +.Ar hookname +is omitted, ``debug'' is assumed. +.Pp +At this point all data written to standard input is sent +to the node and all data received from the node is relayed +to standard output. +.Pp +The options are as follows: +.Pp +.Bl -tag -width indent +.It Fl a +Output each read packet in ASCII. +.It Fl d +Increase the debugging verbosity level. +.El +.Sh BUGS +Although all input is read in unbuffered mode, +there's no way to control the packetization of the input. +.Sh SEE ALSO +.Xr netgraph 4 , +.Xr netgraph 3 , +.Xr ngctl 8 . +.Sh AUTHOR +Archie Cobbs +.Sh HISTORY +The +.Em netgraph +system was designed and first implemented at Whistle Communications, Inc. +in a version FreeBSD 2.2 customized for the Whistle InterJet. -- cgit v1.1