Revision 508d9360

View differences:

doc/bird.sgml
282 282
	<tag>include "<m/filename/"</tag> 
283 283
	This statement causes inclusion of a new file. The maximal depth is set to 5.
284 284

  
285
	<tag>log "<m/filename/"|syslog [name <m/name/]|stderr all|{ <m/list of classes/ }</tag> 
285
	<tag><label id="dsc-log">log "<m/filename/"|syslog [name <m/name/]|stderr all|{ <m/list of classes/ }</tag> 
286 286
	Set logging of messages having the given class (either <cf/all/ or <cf/{
287 287
	error, trace }/ etc.) into selected destination (a file specified as a filename string,
288 288
	syslog with optional name argument, or the stderr output). Classes are:
......
651 651
<p>Here is a brief list of supported functions:
652 652

  
653 653
<descrip>
654
	<tag>dump resources|sockets|interfaces|neighbors|attributes|routes|protocols</tag>
655
	Dump contents of internal data structures to the debugging output.
656

  
657 654
	<tag>show status</tag>
658 655
	Show router status, that is BIRD version, uptime and time from last reconfiguration.
659 656

  
......
812 809

  
813 810
	<tag>debug <m/protocol/|<m/pattern/|all all|off|{ states | routes | filters | events | packets }</tag>
814 811
	Control protocol debugging.
812

  
813
	<tag>dump resources|sockets|interfaces|neighbors|attributes|routes|protocols</tag>
814
	Dump contents of internal data structures to the debugging output.
815

  
816
	<tag>echo all|off|{ <m/list of log classes/ } [ <m/buffer-size/ ]</tag>
817
	Control echoing of log messages to the command-line output.
818
	See <ref id="dsc-log" name="log option"> for a list of log classes.
819

  
820
	<tag>eval <m/expr/</tag>
821
	Evaluate given expression.
822

  
815 823
</descrip>
816 824

  
817 825
<chapt>Filters
doc/reply_codes
31 31
0020	Configuration OK
32 32
0021	Undo requested
33 33
0022	Undo scheduled
34
0023	Evaluation of expression
34 35

  
35 36
1000	BIRD version
36 37
1001	Interface list
......
61 62
8005	Protocol is down => cannot dump
62 63
8006	Reload failed
63 64
8007	Access denied
65
8008	Evaluation runtime error
64 66

  
65 67
9000	Command too long
66 68
9001	Parse error
filter/filter.c
440 440
  return CMP_ERROR;
441 441
}
442 442

  
443
static void val_print(struct f_val v);
444

  
445 443
static void
446 444
tree_node_print(struct f_tree *t, char **sep)
447 445
{
......
474 472
/*
475 473
 * val_print - format filter value
476 474
 */
477
static void
475
void
478 476
val_print(struct f_val v)
479 477
{
480 478
  char buf2[1024];
......
558 556
#define TWOARGS_C TWOARGS \
559 557
                  if (v1.type != v2.type) \
560 558
		    runtime( "Can't operate with values of incompatible types" );
559
#define ACCESS_RTE \
560
  do { if (!f_rte) runtime("No route to access"); } while (0)
561 561

  
562 562
/**
563 563
 * interpret
......
821 821
    break;
822 822
  case 'a':	/* rta access */
823 823
    {
824
      ACCESS_RTE;
824 825
      struct rta *rta = (*f_rte)->attrs;
825 826
      res.type = what->aux;
826 827
      switch(res.type) {
......
845 846
    }
846 847
    break;
847 848
  case P('a','S'):
849
    ACCESS_RTE;
848 850
    ONEARG;
849 851
    if (what->aux != v1.type)
850 852
      runtime( "Attempt to set static attribute to incompatible type" );
......
877 879
    }
878 880
    break;
879 881
  case P('e','a'):	/* Access to extended attributes */
882
    ACCESS_RTE;
880 883
    {
881 884
      eattr *e = NULL;
882 885
      if (!(f_flags & FF_FORCE_TMPATTR))
......
944 947
    }
945 948
    break;
946 949
  case P('e','S'):
950
    ACCESS_RTE;
947 951
    ONEARG;
948 952
    {
949 953
      struct ea_list *l = lp_alloc(f_pool, sizeof(struct ea_list) + sizeof(eattr));
......
1021 1025
    }
1022 1026
    break;
1023 1027
  case 'P':
1028
    ACCESS_RTE;
1024 1029
    res.type = T_INT;
1025 1030
    res.val.i = (*f_rte)->pref;
1026 1031
    break;
1027 1032
  case P('P','S'):
1033
    ACCESS_RTE;
1028 1034
    ONEARG;
1029 1035
    if (v1.type != T_INT)
1030 1036
      runtime( "Can't set preference to non-integer" );
......
1246 1252
    }
1247 1253
    else
1248 1254
    {
1255
      ACCESS_RTE;
1249 1256
      v1.val.px.ip = (*f_rte)->net->n.prefix;
1250 1257
      v1.val.px.len = (*f_rte)->net->n.pxlen;
1251 1258

  
......
1478 1485
  return res.val.i;
1479 1486
}
1480 1487

  
1481
int
1482
f_eval_int(struct f_inst *expr)
1488
struct f_val
1489
f_eval(struct f_inst *expr, struct linpool *tmp_pool)
1483 1490
{
1484
  /* Called independently in parse-time to eval expressions */
1485
  struct f_val res;
1486

  
1487 1491
  f_flags = 0;
1488 1492
  f_tmp_attrs = NULL;
1489 1493
  f_rte = NULL;
1490
  f_pool = cfg_mem;
1494
  f_pool = tmp_pool;
1491 1495

  
1492 1496
  log_reset();
1493
  res = interpret(expr);
1497
  return interpret(expr);
1498
}
1499

  
1500
int
1501
f_eval_int(struct f_inst *expr)
1502
{
1503
  /* Called independently in parse-time to eval expressions */
1504
  struct f_val res = f_eval(expr, cfg_mem);
1494 1505

  
1495 1506
  if (res.type != T_INT)
1496 1507
    cf_error("Integer expression expected");
1508

  
1497 1509
  return res.val.i;
1498 1510
}
1499 1511

  
filter/filter.h
106 106
struct rte;
107 107

  
108 108
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
109
struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool);
109 110
int f_eval_int(struct f_inst *expr);
110 111
u32 f_eval_asn(struct f_inst *expr);
111 112

  
......
117 118
int val_compare(struct f_val v1, struct f_val v2);
118 119
int tree_compare(const void *p1, const void *p2);
119 120

  
121
void val_print(struct f_val v);
122

  
120 123
#define F_NOP 0
121 124
#define F_NONL 1
122 125
#define F_ACCEPT 2	/* Need to preserve ordering: accepts < rejects! */
nest/cmds.c
13 13
#include "nest/cmds.h"
14 14
#include "lib/string.h"
15 15
#include "lib/resource.h"
16
#include "filter/filter.h"
16 17

  
17 18
extern int shutting_down;
18 19
extern int configuring;
......
90 91
  print_size("Total:", rmemsize(&root_pool));
91 92
  cli_msg(0, "");
92 93
}
94

  
95
extern const char *log_buffer_ptr;
96

  
97
void
98
cmd_eval(struct f_inst *expr)
99
{
100
  struct f_val v = f_eval(expr, this_cli->parser_pool);
101
  log_reset();
102

  
103
  if (v.type == T_RETURN)
104
    {
105
      cli_msg(8008, "runtime error");
106
      return;
107
    }
108

  
109
  val_print(v);
110
  cli_msg(23, "%s", log_buffer_ptr);
111
  log_reset();
112
}
nest/cmds.h
11 11
	struct symbol	*sym;
12 12
};
13 13

  
14
struct f_inst;
15

  
14 16
void cmd_show_status(void);
15 17
void cmd_show_symbols(struct sym_show_data *sym);
16 18
void cmd_show_memory(void);
19
void cmd_eval(struct f_inst *expr);
nest/config.Y
612 612
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
613 613
{ protos_dump_all(); cli_msg(0, ""); } ;
614 614

  
615
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
615
CF_CLI(EVAL, term, <expr>, [[Evaluate an expression]])
616
{ cmd_eval($2); } ;
617

  
618
CF_CLI_HELP(ECHO, ..., [[Control echoing of log messages]])
619
CF_CLI(ECHO, echo_mask echo_size, (all | off | { debug | trace | info | remote | warning | error | auth }) [<buffer-size>], [[Control echoing of log messages]]) {
616 620
  cli_set_log_echo(this_cli, $2, $3);
617 621
  cli_msg(0, "");
618 622
} ;
......
620 624
echo_mask:
621 625
   ALL { $$ = ~0; }
622 626
 | OFF { $$ = 0; }
623
 | NUM
627
 | '{' log_mask_list '}' { $$ = $2; }
624 628
 ;
625 629

  
626 630
echo_size:
sysdep/unix/log.c
70 70
static char *log_buffer_pos;
71 71
static int log_buffer_remains;
72 72

  
73
const char *log_buffer_ptr = log_buffer;
74

  
73 75

  
74 76
/**
75 77
 * log_reset - reset the log buffer

Also available in: Unified diff