14cf49a43SJulian Elischer
24cf49a43SJulian Elischer /*
34cf49a43SJulian Elischer * debug.c
44cf49a43SJulian Elischer *
54cf49a43SJulian Elischer * Copyright (c) 1996-1999 Whistle Communications, Inc.
64cf49a43SJulian Elischer * All rights reserved.
74cf49a43SJulian Elischer *
84cf49a43SJulian Elischer * Subject to the following obligations and disclaimer of warranty, use and
94cf49a43SJulian Elischer * redistribution of this software, in source or object code forms, with or
104cf49a43SJulian Elischer * without modifications are expressly permitted by Whistle Communications;
114cf49a43SJulian Elischer * provided, however, that:
124cf49a43SJulian Elischer * 1. Any and all reproductions of the source or object code must include the
134cf49a43SJulian Elischer * copyright notice above and the following disclaimer of warranties; and
144cf49a43SJulian Elischer * 2. No rights are granted, in any manner or form, to use Whistle
154cf49a43SJulian Elischer * Communications, Inc. trademarks, including the mark "WHISTLE
164cf49a43SJulian Elischer * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
174cf49a43SJulian Elischer * such appears in the above copyright notice or in the software.
184cf49a43SJulian Elischer *
194cf49a43SJulian Elischer * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
204cf49a43SJulian Elischer * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
214cf49a43SJulian Elischer * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
224cf49a43SJulian Elischer * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
234cf49a43SJulian Elischer * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
244cf49a43SJulian Elischer * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
254cf49a43SJulian Elischer * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
264cf49a43SJulian Elischer * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
274cf49a43SJulian Elischer * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
284cf49a43SJulian Elischer * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
294cf49a43SJulian Elischer * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
304cf49a43SJulian Elischer * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
314cf49a43SJulian Elischer * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
324cf49a43SJulian Elischer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
334cf49a43SJulian Elischer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
344cf49a43SJulian Elischer * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
354cf49a43SJulian Elischer * OF SUCH DAMAGE.
364cf49a43SJulian Elischer */
374cf49a43SJulian Elischer
3878cdd8edSGleb Smirnoff #include <netgraph.h>
3978cdd8edSGleb Smirnoff #include <stdio.h>
4078cdd8edSGleb Smirnoff #include <stdlib.h>
4178cdd8edSGleb Smirnoff #include <string.h>
4278cdd8edSGleb Smirnoff
434cf49a43SJulian Elischer #include "ngctl.h"
444cf49a43SJulian Elischer
454cf49a43SJulian Elischer static int DebugCmd(int ac, char **av);
464cf49a43SJulian Elischer
474cf49a43SJulian Elischer const struct ngcmd debug_cmd = {
484cf49a43SJulian Elischer DebugCmd,
494cf49a43SJulian Elischer "debug [level]",
504cf49a43SJulian Elischer "Get/set debugging verbosity level",
514cf49a43SJulian Elischer "Without any argument, this command displays the current"
524cf49a43SJulian Elischer " debugging verbosity level. If the argument is ``+'' or ``-''"
534cf49a43SJulian Elischer " the debug level is incremented or decremented; otherwise,"
54723c1c2eSRuslan Ermilov " it must be an absolute numerical level.",
55c3759b3aSStefan Farfeleder { NULL }
564cf49a43SJulian Elischer };
574cf49a43SJulian Elischer
584cf49a43SJulian Elischer static int
DebugCmd(int ac,char ** av)594cf49a43SJulian Elischer DebugCmd(int ac, char **av)
604cf49a43SJulian Elischer {
614cf49a43SJulian Elischer int level;
624cf49a43SJulian Elischer
634cf49a43SJulian Elischer /* Get arguments */
644cf49a43SJulian Elischer switch (ac) {
654cf49a43SJulian Elischer case 2:
664cf49a43SJulian Elischer if (!strcmp(av[1], "+"))
674cf49a43SJulian Elischer level = NgSetDebug(-1) + 1;
684cf49a43SJulian Elischer else if (!strcmp(av[1], "-"))
694cf49a43SJulian Elischer level = NgSetDebug(-1) - 1;
704cf49a43SJulian Elischer else if ((level = atoi(av[1])) < 0)
714cf49a43SJulian Elischer return (CMDRTN_USAGE);
724cf49a43SJulian Elischer NgSetDebug(level);
734cf49a43SJulian Elischer break;
744cf49a43SJulian Elischer case 1:
754cf49a43SJulian Elischer printf("Current debug level is %d\n", NgSetDebug(-1));
764cf49a43SJulian Elischer break;
774cf49a43SJulian Elischer default:
784cf49a43SJulian Elischer return (CMDRTN_USAGE);
794cf49a43SJulian Elischer }
804cf49a43SJulian Elischer return (CMDRTN_OK);
814cf49a43SJulian Elischer }
824cf49a43SJulian Elischer
83