Skip to content

Commit

Permalink
Filter + Config: Fix bugs, tests and split symbols by type
Browse files Browse the repository at this point in the history
  • Loading branch information
marenamat committed Feb 20, 2019
1 parent 7136587 commit c0e958e
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 152 deletions.
22 changes: 18 additions & 4 deletions conf/cf-lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,18 @@ else: {
}
cf_lval.s = cf_get_symbol(yytext);
return SYM;
switch (cf_lval.s->class) {
case SYM_VOID: return CF_SYM_VOID;
case SYM_PROTO: return CF_SYM_PROTO;
case SYM_TEMPLATE: return CF_SYM_TEMPLATE;
case SYM_FUNCTION: return CF_SYM_FUNCTION;
case SYM_FILTER: return CF_SYM_FILTER;
case SYM_TABLE: return CF_SYM_TABLE;
case SYM_ATTRIBUTE: return CF_SYM_ATTRIBUTE;
case SYM_VARIABLE_RANGE: return CF_SYM_VARIABLE;
case SYM_CONSTANT_RANGE: return CF_SYM_CONSTANT;
default: bug("Unknown symbol class %d", cf_lval.s->class);
}
}
<CLI>(.|\n) {
Expand Down Expand Up @@ -723,9 +734,6 @@ cf_pop_scope(void)
char *
cf_symbol_class_name(struct symbol *sym)
{
if (cf_symbol_is_constant(sym))
return "constant";

switch (sym->class)
{
case SYM_VOID:
Expand All @@ -740,6 +748,12 @@ cf_symbol_class_name(struct symbol *sym)
return "filter";
case SYM_TABLE:
return "routing table";
case SYM_ATTRIBUTE:
return "custom attribute";
case SYM_CONSTANT_RANGE:
return "constant";
case SYM_VARIABLE_RANGE:
return "variable";
default:
return "unknown type";
}
Expand Down
4 changes: 0 additions & 4 deletions conf/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ void cf_push_scope(struct symbol *);
void cf_pop_scope(void);
char *cf_symbol_class_name(struct symbol *sym);

static inline int cf_symbol_is_constant(struct symbol *sym)
{ return (sym->class & 0xff00) == SYM_CONSTANT; }


/* Parser */

extern char *cf_text;
Expand Down
35 changes: 24 additions & 11 deletions conf/confbase.Y
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CF_DECLS
enum ec_subtype ecs;
struct f_dynamic_attr fda;
struct f_static_attr fsa;
struct f_lval flv;
struct filter *f;
struct f_tree *e;
struct f_trie *trie;
Expand All @@ -81,7 +82,7 @@ CF_DECLS
%token <ip4> IP4
%token <ip6> IP6
%token <i64> VPN_RD
%token <s> SYM
%token <s> CF_SYM_VOID CF_SYM_PROTO CF_SYM_TEMPLATE CF_SYM_FUNCTION CF_SYM_FILTER CF_SYM_TABLE CF_SYM_ATTRIBUTE CF_SYM_VARIABLE CF_SYM_CONSTANT
%token <t> TEXT
%type <iface> ipa_scope

Expand All @@ -93,6 +94,7 @@ CF_DECLS
%type <mls> label_stack_start label_stack

%type <t> text opttext
%type <s> symbol

%nonassoc PREFIX_DUMMY
%left AND OR
Expand Down Expand Up @@ -125,7 +127,7 @@ conf: ';' ;
conf: definition ;

definition:
DEFINE SYM '=' term ';' {
DEFINE CF_SYM_VOID '=' term ';' {
struct f_val *val = cfg_alloc(sizeof(struct f_val));
if (f_eval(f_postfixify($4), cfg_mem, val) > F_RETURN) cf_error("Runtime error");
cf_define_symbol($2, SYM_CONSTANT | val->type, val);
Expand All @@ -135,18 +137,29 @@ definition:
expr:
NUM
| '(' term ')' { $$ = f_eval_int(f_postfixify($2)); }
| SYM {
| CF_SYM_CONSTANT {
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
$$ = SYM_VAL($1).i; }
;


expr_us:
expr S { $$ = $1 S_; }
| expr MS { $$ = $1 MS_; }
| expr US { $$ = $1 US_; }
;

symbol:
CF_SYM_VOID
| CF_SYM_PROTO
| CF_SYM_TEMPLATE
| CF_SYM_FUNCTION
| CF_SYM_FILTER
| CF_SYM_TABLE
| CF_SYM_ATTRIBUTE
| CF_SYM_VARIABLE
| CF_SYM_CONSTANT
;

/* Switches */

bool:
Expand All @@ -164,15 +177,15 @@ bool:
ipa:
IP4 { $$ = ipa_from_ip4($1); }
| IP6 { $$ = ipa_from_ip6($1); }
| SYM {
| CF_SYM_CONSTANT {
if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
$$ = SYM_VAL($1).ip;
}
;

ipa_scope:
/* empty */ { $$ = NULL; }
| '%' SYM { $$ = if_get_by_name($2->name); }
| '%' symbol { $$ = if_get_by_name($2->name); }
;


Expand Down Expand Up @@ -279,7 +292,7 @@ net_:

net_ip6:
net_ip6_
| SYM {
| CF_SYM_CONSTANT {
if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
cf_error("IPv6 network expected");
$$ = * SYM_VAL($1).net;
Expand All @@ -288,7 +301,7 @@ net_ip6:

net_ip:
net_ip_
| SYM {
| CF_SYM_CONSTANT {
if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
cf_error("IP network expected");
$$ = * SYM_VAL($1).net;
Expand All @@ -297,7 +310,7 @@ net_ip:

net_any:
net_
| SYM {
| CF_SYM_CONSTANT {
if ($1->class != (SYM_CONSTANT | T_NET))
cf_error("Network expected");
$$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
Expand All @@ -309,7 +322,7 @@ net_or_ipa:
| net_ip6_
| IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
| IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
| SYM {
| CF_SYM_CONSTANT {
if ($1->class == (SYM_CONSTANT | T_IP))
net_fill_ip_host(&($$), SYM_VAL($1).ip);
else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
Expand Down Expand Up @@ -346,7 +359,7 @@ time:

text:
TEXT
| SYM {
| CF_SYM_CONSTANT {
if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
$$ = SYM_VAL($1).s;
}
Expand Down
Loading

0 comments on commit c0e958e

Please sign in to comment.