File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / quagga / zebra / debug.c
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 10:09:10 2016 UTC (7 years, 8 months ago) by misho
Branches: quagga, MAIN
CVS tags: v1_0_20160315, HEAD
quagga 1.0.20160315

    1: /*
    2:  * Zebra debug related function
    3:  * Copyright (C) 1999 Kunihiro Ishiguro
    4:  *
    5:  * This file is part of GNU Zebra.
    6:  *
    7:  * GNU Zebra is free software; you can redistribute it and/or modify it
    8:  * under the terms of the GNU General Public License as published by the
    9:  * Free Software Foundation; either version 2, or (at your option) any
   10:  * later version.
   11:  *
   12:  * GNU Zebra is distributed in the hope that it will be useful, but
   13:  * WITHOUT ANY WARRANTY; without even the implied warranty of
   14:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15:  * General Public License for more details.
   16:  *
   17:  * You should have received a copy of the GNU General Public License
   18:  * along with GNU Zebra; see the file COPYING.  If not, write to the 
   19:  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
   20:  * Boston, MA 02111-1307, USA.  
   21:  */
   22: 
   23: #include <zebra.h>
   24: #include "command.h"
   25: #include "debug.h"
   26: 
   27: /* For debug statement. */
   28: unsigned long zebra_debug_event;
   29: unsigned long zebra_debug_packet;
   30: unsigned long zebra_debug_kernel;
   31: unsigned long zebra_debug_rib;
   32: unsigned long zebra_debug_fpm;
   33: 
   34: DEFUN (show_debugging_zebra,
   35:        show_debugging_zebra_cmd,
   36:        "show debugging zebra",
   37:        SHOW_STR
   38:        "Debugging information\n"
   39:        "Zebra configuration\n")
   40: {
   41:   vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE);
   42: 
   43:   if (IS_ZEBRA_DEBUG_EVENT)
   44:     vty_out (vty, "  Zebra event debugging is on%s", VTY_NEWLINE);
   45: 
   46:   if (IS_ZEBRA_DEBUG_PACKET)
   47:     {
   48:       if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
   49: 	{
   50: 	  vty_out (vty, "  Zebra packet%s debugging is on%s",
   51: 		   IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
   52: 		   VTY_NEWLINE);
   53: 	}
   54:       else
   55: 	{
   56: 	  if (IS_ZEBRA_DEBUG_SEND)
   57: 	    vty_out (vty, "  Zebra packet send%s debugging is on%s",
   58: 		     IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
   59: 		     VTY_NEWLINE);
   60: 	  else
   61: 	    vty_out (vty, "  Zebra packet receive%s debugging is on%s",
   62: 		     IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
   63: 		     VTY_NEWLINE);
   64: 	}
   65:     }
   66: 
   67:   if (IS_ZEBRA_DEBUG_KERNEL)
   68:     vty_out (vty, "  Zebra kernel debugging is on%s", VTY_NEWLINE);
   69: 
   70:   if (IS_ZEBRA_DEBUG_RIB)
   71:     vty_out (vty, "  Zebra RIB debugging is on%s", VTY_NEWLINE);
   72:   if (IS_ZEBRA_DEBUG_RIB_Q)
   73:     vty_out (vty, "  Zebra RIB queue debugging is on%s", VTY_NEWLINE);
   74: 
   75:   if (IS_ZEBRA_DEBUG_FPM)
   76:     vty_out (vty, "  Zebra FPM debugging is on%s", VTY_NEWLINE);
   77: 
   78:   return CMD_SUCCESS;
   79: }
   80: 
   81: DEFUN (debug_zebra_events,
   82:        debug_zebra_events_cmd,
   83:        "debug zebra events",
   84:        DEBUG_STR
   85:        "Zebra configuration\n"
   86:        "Debug option set for zebra events\n")
   87: {
   88:   zebra_debug_event = ZEBRA_DEBUG_EVENT;
   89:   return CMD_WARNING;
   90: }
   91: 
   92: DEFUN (debug_zebra_packet,
   93:        debug_zebra_packet_cmd,
   94:        "debug zebra packet",
   95:        DEBUG_STR
   96:        "Zebra configuration\n"
   97:        "Debug option set for zebra packet\n")
   98: {
   99:   zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  100:   zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  101:   zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  102:   return CMD_SUCCESS;
  103: }
  104: 
  105: DEFUN (debug_zebra_packet_direct,
  106:        debug_zebra_packet_direct_cmd,
  107:        "debug zebra packet (recv|send|detail)",
  108:        DEBUG_STR
  109:        "Zebra configuration\n"
  110:        "Debug option set for zebra packet\n"
  111:        "Debug option set for receive packet\n"
  112:        "Debug option set for send packet\n")
  113: {
  114:   zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  115:   if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  116:     zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  117:   if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  118:     zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  119:   if (strncmp ("detail", argv[0], strlen (argv[0])) == 0)
  120:     zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
  121:   return CMD_SUCCESS;
  122: }
  123: 
  124: DEFUN (debug_zebra_packet_detail,
  125:        debug_zebra_packet_detail_cmd,
  126:        "debug zebra packet (recv|send) detail",
  127:        DEBUG_STR
  128:        "Zebra configuration\n"
  129:        "Debug option set for zebra packet\n"
  130:        "Debug option set for receive packet\n"
  131:        "Debug option set for send packet\n"
  132:        "Debug option set detailed information\n")
  133: {
  134:   zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  135:   if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  136:     zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  137:   if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  138:     zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  139:   zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
  140:   return CMD_SUCCESS;
  141: }
  142: 
  143: DEFUN (debug_zebra_kernel,
  144:        debug_zebra_kernel_cmd,
  145:        "debug zebra kernel",
  146:        DEBUG_STR
  147:        "Zebra configuration\n"
  148:        "Debug option set for zebra between kernel interface\n")
  149: {
  150:   zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
  151:   return CMD_SUCCESS;
  152: }
  153: 
  154: DEFUN (debug_zebra_rib,
  155:        debug_zebra_rib_cmd,
  156:        "debug zebra rib",
  157:        DEBUG_STR
  158:        "Zebra configuration\n"
  159:        "Debug RIB events\n")
  160: {
  161:   SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
  162:   return CMD_SUCCESS;
  163: }
  164: 
  165: DEFUN (debug_zebra_rib_q,
  166:        debug_zebra_rib_q_cmd,
  167:        "debug zebra rib queue",
  168:        DEBUG_STR
  169:        "Zebra configuration\n"
  170:        "Debug RIB events\n"
  171:        "Debug RIB queueing\n")
  172: {
  173:   SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
  174:   return CMD_SUCCESS;
  175: }
  176: 
  177: DEFUN (debug_zebra_fpm,
  178:        debug_zebra_fpm_cmd,
  179:        "debug zebra fpm",
  180:        DEBUG_STR
  181:        "Zebra configuration\n"
  182:        "Debug zebra FPM events\n")
  183: {
  184:   SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
  185:   return CMD_SUCCESS;
  186: }
  187: 
  188: DEFUN (no_debug_zebra_events,
  189:        no_debug_zebra_events_cmd,
  190:        "no debug zebra events",
  191:        NO_STR
  192:        DEBUG_STR
  193:        "Zebra configuration\n"
  194:        "Debug option set for zebra events\n")
  195: {
  196:   zebra_debug_event = 0;
  197:   return CMD_SUCCESS;
  198: }
  199: 
  200: DEFUN (no_debug_zebra_packet,
  201:        no_debug_zebra_packet_cmd,
  202:        "no debug zebra packet",
  203:        NO_STR
  204:        DEBUG_STR
  205:        "Zebra configuration\n"
  206:        "Debug option set for zebra packet\n")
  207: {
  208:   zebra_debug_packet = 0;
  209:   return CMD_SUCCESS;
  210: }
  211: 
  212: DEFUN (no_debug_zebra_packet_direct,
  213:        no_debug_zebra_packet_direct_cmd,
  214:        "no debug zebra packet (recv|send)",
  215:        NO_STR
  216:        DEBUG_STR
  217:        "Zebra configuration\n"
  218:        "Debug option set for zebra packet\n"
  219:        "Debug option set for receive packet\n"
  220:        "Debug option set for send packet\n")
  221: {
  222:   if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  223:     zebra_debug_packet &= ~ZEBRA_DEBUG_SEND;
  224:   if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  225:     zebra_debug_packet &= ~ZEBRA_DEBUG_RECV;
  226:   return CMD_SUCCESS;
  227: }
  228: 
  229: DEFUN (no_debug_zebra_kernel,
  230:        no_debug_zebra_kernel_cmd,
  231:        "no debug zebra kernel",
  232:        NO_STR
  233:        DEBUG_STR
  234:        "Zebra configuration\n"
  235:        "Debug option set for zebra between kernel interface\n")
  236: {
  237:   zebra_debug_kernel = 0;
  238:   return CMD_SUCCESS;
  239: }
  240: 
  241: DEFUN (no_debug_zebra_rib,
  242:        no_debug_zebra_rib_cmd,
  243:        "no debug zebra rib",
  244:        NO_STR
  245:        DEBUG_STR
  246:        "Zebra configuration\n"
  247:        "Debug zebra RIB\n")
  248: {
  249:   zebra_debug_rib = 0;
  250:   return CMD_SUCCESS;
  251: }
  252: 
  253: DEFUN (no_debug_zebra_rib_q,
  254:        no_debug_zebra_rib_q_cmd,
  255:        "no debug zebra rib queue",
  256:        NO_STR
  257:        DEBUG_STR
  258:        "Zebra configuration\n"
  259:        "Debug zebra RIB\n"
  260:        "Debug RIB queueing\n")
  261: {
  262:   UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
  263:   return CMD_SUCCESS;
  264: }
  265: 
  266: DEFUN (no_debug_zebra_fpm,
  267:        no_debug_zebra_fpm_cmd,
  268:        "no debug zebra fpm",
  269:        NO_STR
  270:        DEBUG_STR
  271:        "Zebra configuration\n"
  272:        "Debug zebra FPM events\n")
  273: {
  274:   zebra_debug_fpm = 0;
  275:   return CMD_SUCCESS;
  276: }
  277: 
  278: /* Debug node. */
  279: struct cmd_node debug_node =
  280: {
  281:   DEBUG_NODE,
  282:   "",				/* Debug node has no interface. */
  283:   1
  284: };
  285: 
  286: static int
  287: config_write_debug (struct vty *vty)
  288: {
  289:   int write = 0;
  290: 
  291:   if (IS_ZEBRA_DEBUG_EVENT)
  292:     {
  293:       vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
  294:       write++;
  295:     }
  296:   if (IS_ZEBRA_DEBUG_PACKET)
  297:     {
  298:       if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
  299: 	{
  300: 	  vty_out (vty, "debug zebra packet%s%s",
  301: 		   IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  302: 		   VTY_NEWLINE);
  303: 	  write++;
  304: 	}
  305:       else
  306: 	{
  307: 	  if (IS_ZEBRA_DEBUG_SEND)
  308: 	    vty_out (vty, "debug zebra packet send%s%s",
  309: 		     IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  310: 		     VTY_NEWLINE);
  311: 	  else
  312: 	    vty_out (vty, "debug zebra packet recv%s%s",
  313: 		     IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  314: 		     VTY_NEWLINE);
  315: 	  write++;
  316: 	}
  317:     }
  318:   if (IS_ZEBRA_DEBUG_KERNEL)
  319:     {
  320:       vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
  321:       write++;
  322:     }
  323:   if (IS_ZEBRA_DEBUG_RIB)
  324:     {
  325:       vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
  326:       write++;
  327:     }
  328:   if (IS_ZEBRA_DEBUG_RIB_Q)
  329:     {
  330:       vty_out (vty, "debug zebra rib queue%s", VTY_NEWLINE);
  331:       write++;
  332:     }
  333:   if (IS_ZEBRA_DEBUG_FPM)
  334:     {
  335:       vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
  336:       write++;
  337:     }
  338:   return write;
  339: }
  340: 
  341: void
  342: zebra_debug_init (void)
  343: {
  344:   zebra_debug_event = 0;
  345:   zebra_debug_packet = 0;
  346:   zebra_debug_kernel = 0;
  347:   zebra_debug_rib = 0;
  348:   zebra_debug_fpm = 0;
  349: 
  350:   install_node (&debug_node, config_write_debug);
  351: 
  352:   install_element (VIEW_NODE, &show_debugging_zebra_cmd);
  353: 
  354:   install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
  355:   install_element (ENABLE_NODE, &debug_zebra_events_cmd);
  356:   install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
  357:   install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
  358:   install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
  359:   install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
  360:   install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
  361:   install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd);
  362:   install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
  363:   install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
  364:   install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
  365:   install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
  366:   install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
  367:   install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd);
  368:   install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
  369: 
  370:   install_element (CONFIG_NODE, &debug_zebra_events_cmd);
  371:   install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
  372:   install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
  373:   install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
  374:   install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
  375:   install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
  376:   install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd);
  377:   install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
  378:   install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
  379:   install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
  380:   install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
  381:   install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
  382:   install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd);
  383:   install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
  384: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>