summaryrefslogtreecommitdiff
path: root/conf
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-07-25 22:33:57 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2013-07-25 22:33:57 +0200
commit1103b32e830fbf98d9b3e32c0425b9a589773bf8 (patch)
tree9d3577cf205e74002ea43e7754f3391cc1e4992d /conf
parentac5745134847c044b21c311e5ab11d92d05bacc1 (diff)
Allows to define constants of all filter types.
Diffstat (limited to 'conf')
-rw-r--r--conf/cf-lex.l19
-rw-r--r--conf/conf.h10
-rw-r--r--conf/confbase.Y31
3 files changed, 31 insertions, 29 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index e0430485..50f390e0 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -15,10 +15,10 @@
* symbols and keywords.
*
* Each symbol is represented by a &symbol structure containing name
- * of the symbol, its lexical scope, symbol class (%SYM_PROTO for a name of a protocol,
- * %SYM_NUMBER for a numeric constant etc.) and class dependent data.
- * When an unknown symbol is encountered, it's automatically added to the
- * symbol table with class %SYM_VOID.
+ * of the symbol, its lexical scope, symbol class (%SYM_PROTO for a
+ * name of a protocol, %SYM_CONSTANT for a constant etc.) and class
+ * dependent data. When an unknown symbol is encountered, it's
+ * automatically added to the symbol table with class %SYM_VOID.
*
* The keyword tables are generated from the grammar templates
* using the |gen_keywords.m4| script.
@@ -623,24 +623,23 @@ cf_walk_symbols(struct config *cf, struct symbol *sym, int *pos)
char *
cf_symbol_class_name(struct symbol *sym)
{
+ if ((sym->class & 0xff00) == SYM_CONSTANT)
+ return "constant";
+
switch (sym->class)
{
case SYM_VOID:
return "undefined";
case SYM_PROTO:
return "protocol";
- case SYM_NUMBER:
- return "numeric constant";
+ case SYM_TEMPLATE:
+ return "protocol template";
case SYM_FUNCTION:
return "function";
case SYM_FILTER:
return "filter";
case SYM_TABLE:
return "routing table";
- case SYM_IPA:
- return "network address";
- case SYM_TEMPLATE:
- return "protocol template";
case SYM_ROA:
return "ROA table";
default:
diff --git a/conf/conf.h b/conf/conf.h
index 683374e0..28624294 100644
--- a/conf/conf.h
+++ b/conf/conf.h
@@ -110,15 +110,17 @@ struct symbol {
/* Remember to update cf_symbol_class_name() */
#define SYM_VOID 0
#define SYM_PROTO 1
-#define SYM_NUMBER 2
+#define SYM_TEMPLATE 2
#define SYM_FUNCTION 3
#define SYM_FILTER 4
#define SYM_TABLE 5
-#define SYM_IPA 6
-#define SYM_TEMPLATE 7
-#define SYM_ROA 8
+#define SYM_ROA 6
#define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */
+#define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */
+
+#define SYM_TYPE(s) (((struct f_val *) (s)->def)->type)
+#define SYM_VAL(s) (((struct f_val *) (s)->def)->val)
struct include_file_stack {
void *buffer; /* Internal lexer state */
diff --git a/conf/confbase.Y b/conf/confbase.Y
index dcb0719f..c6678e77 100644
--- a/conf/confbase.Y
+++ b/conf/confbase.Y
@@ -103,28 +103,29 @@ conf_entries:
CF_ADDTO(conf, ';')
+
/* Constant expressions */
+CF_ADDTO(conf, definition)
+definition:
+ DEFINE SYM '=' term ';' {
+ struct f_val *val = cfg_alloc(sizeof(struct f_val));
+ *val = f_eval($4, cfg_mem);
+ if (val->type == T_RETURN) cf_error("Runtime error");
+ cf_define_symbol($2, SYM_CONSTANT | val->type, val);
+ }
+ ;
+
expr:
NUM
| '(' term ')' { $$ = f_eval_int($2); }
- | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
+ | SYM {
+ if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
+ $$ = SYM_VAL($1).i; }
;
/* expr_u16: expr { check_u16($1); $$ = $1; }; */
-CF_ADDTO(conf, definition)
-definition:
- DEFINE SYM '=' expr ';' {
- cf_define_symbol($2, SYM_NUMBER, NULL);
- $2->aux = $4;
- }
- | DEFINE SYM '=' IPA ';' {
- cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
- *(ip_addr *)$2->def = $4;
- }
- ;
-
/* Switches */
bool:
@@ -141,8 +142,8 @@ bool:
ipa:
IPA
| SYM {
- if ($1->class != SYM_IPA) cf_error("IP address expected");
- $$ = *(ip_addr *)$1->def;
+ if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
+ $$ = SYM_VAL($1).px.ip;
}
;