0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Added protocol debugging flags (protocol.h: D_xxx), parsing of them

in configuration files and commands for manipulating them.

Current debug message policy:

   o  D_STATES, D_ROUTES and D_FILTERS are handled in generic code.
   o  Other debug flags should be handled in the protocols and whenever
      the flag is set, the corresponding messages should be printed
      using calls to log(L_TRACE, ...), each message prefixed with
      the name of the protocol instance. These messages should cover
      the whole normal operation of the protocol and should be useful
      for an administrator trying to understand what does the protocol
      behave on his network or who is attempting to diagnose network
      problems. If your messages don't fit to the categories I've defined,
      feel free to add your own ones (by adding them to protocol.h
      and on two places in nest/config.Y), but please try to keep the
      categories as general as possible (i.e., not tied to your protocol).
   o  Internal debug messages not interesting even to an experienced
      user should be printed by calling DBG() which is either void or
      a call to debug() depending on setting of the LOCAL_DEBUG symbol
      at the top of your source.
   o  Dump functions (proto->dump etc.) should call debug() to print
      their messages.
   o  If you are doing any internal consistency checks, use ASSERT
      or bug().
   o  Nobody shall ever call printf() or any other stdio functions.

Also please try to log any protocol errors you encounter and tag them
with the appropriate message category (usually L_REMOTE or L_AUTH). Always
carefully check contents of any message field you receive and verify all
IP addresses you work with (by calling ipa_classify() or by using the
neighbour cache if you want to check direct connectedness as well).
This commit is contained in:
Martin Mares 2000-03-07 20:49:48 +00:00
parent c801e1fbab
commit 96d8e3bff2
3 changed files with 65 additions and 16 deletions

View File

@ -18,8 +18,8 @@ static struct iface_patt *this_ipatt;
CF_DECLS CF_DECLS
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT) CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE) CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID) CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS)
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT, CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
RIP, RIP_EXT, OSPF, OSPF_EXT, OSPF_IA, OSPF_BOUNDARY, BGP, PIPE) RIP, RIP_EXT, OSPF, OSPF_EXT, OSPF_IA, OSPF_BOUNDARY, BGP, PIPE)
@ -30,7 +30,7 @@ CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIREC
%type <p> password_list password_begin %type <p> password_list password_begin
%type <s> optsym %type <s> optsym
%type <ra> r_args %type <ra> r_args
%type <i> echo_mask echo_size %type <i> echo_mask echo_size debug_mask debug_list debug_flag
%type <t> proto_patt %type <t> proto_patt
CF_GRAMMAR CF_GRAMMAR
@ -91,9 +91,7 @@ proto_item:
this_proto->preference = $2; this_proto->preference = $2;
} }
| DISABLED { this_proto->disabled = 1; } | DISABLED { this_proto->disabled = 1; }
| DEBUG expr { this_proto->debug = $2; } | DEBUG debug_mask { this_proto->debug = $2; }
| DEBUG ALL { this_proto->debug = ~0; }
| DEBUG OFF { this_proto->debug = 0; }
| IMPORT imexport { this_proto->in_filter = $2; } | IMPORT imexport { this_proto->in_filter = $2; }
| EXPORT imexport { this_proto->out_filter = $2; } | EXPORT imexport { this_proto->out_filter = $2; }
| TABLE rtable { this_proto->table = $2; } | TABLE rtable { this_proto->table = $2; }
@ -156,6 +154,27 @@ dev_iface_list:
| dev_iface_list ',' dev_iface_entry | dev_iface_list ',' dev_iface_entry
; ;
/* Debug flags */
debug_mask:
ALL { $$ = ~0; }
| OFF { $$ = 0; }
| '{' debug_list '}' { $$ = $2; }
;
debug_list:
debug_flag
| debug_list ',' debug_flag { $$ = $1 | $3; }
;
debug_flag:
STATES { $$ = D_STATES; }
| ROUTES { $$ = D_ROUTES; }
| FILTERS { $$ = D_FILTERS; }
| EVENTS { $$ = D_EVENTS; }
| PACKETS { $$ = D_PACKETS; }
;
/* Password lists */ /* Password lists */
password_begin: password_begin:
@ -251,20 +270,20 @@ r_args:
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]]) CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
{ cmd_show_symbols($3); } ; { cmd_show_symbols($3); } ;
CF_CLI_HELP(DEBUG, ..., [[Show debugging information]]) CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
CF_CLI(DEBUG RESOURCES,,, [[Show all allocated resource]]) CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
{ rdump(&root_pool); cli_msg(0, ""); } ; { rdump(&root_pool); cli_msg(0, ""); } ;
CF_CLI(DEBUG SOCKETS,,, [[Show open sockets]]) CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
{ sk_dump_all(); cli_msg(0, ""); } ; { sk_dump_all(); cli_msg(0, ""); } ;
CF_CLI(DEBUG INTERFACES,,, [[Show interface information]]) CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
{ if_dump_all(); cli_msg(0, ""); } ; { if_dump_all(); cli_msg(0, ""); } ;
CF_CLI(DEBUG NEIGHBORS,,, [[Show neighbor cache]]) CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
{ neigh_dump_all(); cli_msg(0, ""); } ; { neigh_dump_all(); cli_msg(0, ""); } ;
CF_CLI(DEBUG ATTRIBUTES,,, [[Show attribute cache]]) CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
{ rta_dump_all(); cli_msg(0, ""); } ; { rta_dump_all(); cli_msg(0, ""); } ;
CF_CLI(DEBUG ROUTES,,, [[Show routing table]]) CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
{ rt_dump_all(); cli_msg(0, ""); } ; { rt_dump_all(); cli_msg(0, ""); } ;
CF_CLI(DEBUG PROTOCOLS,,, [[Show protocol information]]) CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
{ protos_dump_all(); cli_msg(0, ""); } ; { protos_dump_all(); cli_msg(0, ""); } ;
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) { CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
@ -293,6 +312,10 @@ CF_CLI(ENABLE, proto_patt, <protocol> | <pattern> | all, [[Enable protocol]])
CF_CLI(RESTART, proto_patt, <protocol> | <pattern> | all, [[Restart protocol]]) CF_CLI(RESTART, proto_patt, <protocol> | <pattern> | all, [[Restart protocol]])
{ proto_xxable($2, 2); } ; { proto_xxable($2, 2); } ;
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
{ proto_debug($2, $3); }
proto_patt: proto_patt:
SYM { $$ = $1->name; } SYM { $$ = $1->name; }
| ALL { $$ = "*"; } | ALL { $$ = "*"; }

View File

@ -139,7 +139,6 @@ proto_config_new(struct protocol *pr, unsigned size)
add_tail(&new_config->protos, &c->n); add_tail(&new_config->protos, &c->n);
c->global = new_config; c->global = new_config;
c->protocol = pr; c->protocol = pr;
c->debug = pr->debug;
c->name = pr->name; c->name = pr->name;
c->out_filter = FILTER_REJECT; c->out_filter = FILTER_REJECT;
c->table = c->global->master_rtc; c->table = c->global->master_rtc;
@ -603,3 +602,20 @@ proto_xxable(char *pattern, int xx)
else else
cli_msg(0, ""); cli_msg(0, "");
} }
void
proto_debug(char *pattern, unsigned int mask)
{
int cnt = 0;
WALK_PROTO_LIST(p)
if (patmatch(pattern, p->name))
{
cnt++;
p->debug = mask;
}
WALK_PROTO_LIST_END;
if (!cnt)
cli_msg(8003, "No protocols match");
else
cli_msg(0, "");
}

View File

@ -34,7 +34,6 @@ struct protocol {
node n; node n;
char *name; char *name;
char *template; /* Template for automatic generation of names */ char *template; /* Template for automatic generation of names */
unsigned debug; /* Default debugging flags */
int name_counter; /* Counter for automatic name generation */ int name_counter; /* Counter for automatic name generation */
void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */ void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
@ -156,6 +155,7 @@ void *proto_config_new(struct protocol *, unsigned size);
void proto_show(struct symbol *, int); void proto_show(struct symbol *, int);
struct proto *proto_get_named(struct symbol *, struct protocol *); struct proto *proto_get_named(struct symbol *, struct protocol *);
void proto_xxable(char *, int); void proto_xxable(char *, int);
void proto_debug(char *, unsigned int);
extern list active_proto_list; extern list active_proto_list;
@ -234,6 +234,16 @@ void proto_notify_state(struct proto *p, unsigned state);
#define FS_HAPPY 2 #define FS_HAPPY 2
#define FS_FLUSHING 3 #define FS_FLUSHING 3
/*
* Debugging flags
*/
#define D_STATES 1 /* [core] State transitions */
#define D_ROUTES 2 /* [core] Routes passed by the filters */
#define D_FILTERS 4 /* [core] Filtering of routes */
#define D_EVENTS 8 /* Protocol events */
#define D_PACKETS 16 /* Packets sent/received */
/* /*
* Known unique protocol instances as referenced by config routines * Known unique protocol instances as referenced by config routines
*/ */