diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2002-06-08 08:04:03 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2002-06-08 08:04:03 +0000 |
commit | f89c39e4bbdd38c9f9903adc6156420f7a64e6a4 (patch) | |
tree | 7a556e4db2daa3760baaad508eba33b7f54e0d58 | |
parent | eea5018d0d7c1bb9effc7d83ffcdb7b8c644bb40 (diff) |
allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@
-rw-r--r-- | sbin/pfctl/parse.y | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index e6f88352269..c2de13b1d23 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.81 2002/06/08 07:58:07 dhartmei Exp $ */ +/* $OpenBSD: parse.y,v 1.82 2002/06/08 08:04:02 henning Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. @@ -143,6 +143,7 @@ struct sym { struct sym *symhead = NULL; int symset(char *name, char *val); +int symextend(char *name, char *val); char * symget(char *name); struct ifaddrs *ifa0_lookup(char *ifa_name); @@ -198,9 +199,9 @@ typedef struct { %token PASS BLOCK SCRUB RETURN IN OUT LOG LOGALL QUICK ON FROM TO FLAGS %token RETURNRST RETURNICMP RETURNICMP6 PROTO INET INET6 ALL ANY ICMPTYPE -%token ICMP6TYPE CODE KEEP MODULATE STATE PORT RDR NAT BINAT ARROW NODF +%token ICMP6TYPE CODE KEEP MODULATE STATE PORT RDR NAT BINAT ARROW NODF %token MINTTL IPV6ADDR ERROR ALLOWOPTS FASTROUTE ROUTETO DUPTO NO LABEL -%token NOROUTE FRAGMENT USER GROUP MAXMSS MAXIMUM TTL +%token NOROUTE FRAGMENT USER GROUP MAXMSS MAXIMUM TTL PLUSEQUAL %token <v.string> STRING %token <v.number> NUMBER %token <v.i> PORTUNARY PORTBINARY @@ -231,6 +232,7 @@ ruleset : /* empty */ | ruleset binatrule '\n' | ruleset rdrrule '\n' | ruleset varset '\n' + | ruleset varextend '\n' | ruleset error '\n' { errors++; } ; @@ -245,6 +247,17 @@ varset : STRING PORTUNARY STRING } ; +varextend : STRING PLUSEQUAL STRING + { + if (pf->opts & PF_OPT_VERBOSE) + printf("%s += %s\n", $1, $3); + if (symextend($1, $3) == -1) { + yyerror("cannot extend variable %s", $1); + YYERROR; + } + } + ; + pfrule : action dir log quick interface route af proto fromto uids gids flags icmpspec keep fragment nodf minttl maxmss allowopts label @@ -2209,6 +2222,12 @@ top: return (ARROW); lungetc(next, fin); break; + case '+': + next = lgetc(fin); + if (next == '=') + return (PLUSEQUAL); + lungetc(next, fin); + break; } /* Need to parse v6 addresses before tokenizing numbers. ick */ @@ -2399,6 +2418,24 @@ symset(char *nam, char *val) return (0); } +int +symextend(char *nam, char *val) +{ + struct sym *sym; + char *p; + + for (sym = symhead; sym && strcmp(nam, sym->nam); sym = sym->next) + ; /* nothing */ + if (sym == NULL) + return -1; + p = realloc(sym->val, strlen(sym->val) + strlen(val) + 1); + if (p == NULL) + return -1; + sym->val = p; + strlcat(sym->val, val, strlen(sym->val) + strlen(val) + 1); + return 0; +} + char * symget(char *nam) { |