diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-05-31 03:24:07 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-05-31 03:24:07 +0000 |
commit | 096d22c2a59ca8fd190428607badf44481bcb88e (patch) | |
tree | 37d9e8b77bbe608b52e203e5937e6677f8341847 /usr.sbin | |
parent | 4efb916c2227091b9bdd87d8d5abc6720e52da33 (diff) |
More redistribute fun. Add a possibility to deny redistribution of specified
routes via "no redistribute rtlabel admin". Redistribute rules are parsed
in order and the first match is used. Only exception is "redistribute default"
Which is independent of the other rules and can't be negated.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ospfd/ospfd.c | 17 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 15 | ||||
-rw-r--r-- | usr.sbin/ospfd/parse.y | 56 | ||||
-rw-r--r-- | usr.sbin/ospfd/printconf.c | 22 |
4 files changed, 66 insertions, 44 deletions
diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c index fd07d6bb078..472fbc79e08 100644 --- a/usr.sbin/ospfd/ospfd.c +++ b/usr.sbin/ospfd/ospfd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.c,v 1.32 2006/05/30 22:06:14 claudio Exp $ */ +/* $OpenBSD: ospfd.c,v 1.33 2006/05/31 03:24:06 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -500,10 +500,10 @@ ospf_redistribute(struct kroute *kr) return (0); SIMPLEQ_FOREACH(r, &conf->redist_list, entry) { - switch (r->type) { + switch (r->type & ~REDIST_NO) { case REDIST_LABEL: if (kr->rtlabel == r->label) - return (1); + return (r->type & REDIST_NO ? 0 : 1); break; case REDIST_STATIC: /* @@ -514,14 +514,19 @@ ospf_redistribute(struct kroute *kr) if (kr->flags & F_DYNAMIC) continue; if (kr->flags & F_STATIC) - return (1); + return (r->type & REDIST_NO ? 0 : 1); case REDIST_CONNECTED: if (kr->flags & F_DYNAMIC) continue; if (kr->flags & F_CONNECTED) - return (1); + return (r->type & REDIST_NO ? 0 : 1); case REDIST_ADDR: - /* ignore */ + if (kr->flags & F_DYNAMIC) + continue; + if ((kr->prefix.s_addr & r->mask.s_addr) == + (r->addr.s_addr & r->mask.s_addr) && + kr->prefixlen >= mask2prefixlen(r->mask.s_addr)) + return (r->type & REDIST_NO? 0 : 1); break; } } diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index e513c0d7af9..408d842ecdd 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.58 2006/05/30 22:06:14 claudio Exp $ */ +/* $OpenBSD: ospfd.h,v 1.59 2006/05/31 03:24:06 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -361,19 +361,18 @@ enum { PROC_RDE_ENGINE } ospfd_process; -enum redist_types { - REDIST_CONNECTED, - REDIST_STATIC, - REDIST_LABEL, - REDIST_ADDR -}; +#define REDIST_CONNECTED 0x01 +#define REDIST_STATIC 0x02 +#define REDIST_LABEL 0x04 +#define REDIST_ADDR 0x08 +#define REDIST_NO 0x10 struct redistribute { SIMPLEQ_ENTRY(redistribute) entry; struct in_addr addr; struct in_addr mask; u_int16_t label; - enum redist_types type; + u_int16_t type; }; struct ospfd_conf { diff --git a/usr.sbin/ospfd/parse.y b/usr.sbin/ospfd/parse.y index 8297690d3de..c45a30eb9e2 100644 --- a/usr.sbin/ospfd/parse.y +++ b/usr.sbin/ospfd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.32 2006/05/31 02:18:23 pat Exp $ */ +/* $OpenBSD: parse.y,v 1.33 2006/05/31 03:24:06 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -112,9 +112,10 @@ typedef struct { %token METRIC PASSIVE %token HELLOINTERVAL TRANSMITDELAY %token RETRANSMITINTERVAL ROUTERDEADTIME ROUTERPRIORITY +%token YES NO %token ERROR %token <v.string> STRING -%type <v.number> number yesno +%type <v.number> number yesno no %type <v.string> string %% @@ -153,19 +154,13 @@ string : string STRING { | STRING ; -yesno : STRING { - if (!strcmp($1, "yes")) - $$ = 1; - else if (!strcmp($1, "no")) - $$ = 0; - else { - free($1); - YYERROR; - } - free($1); - } +yesno : YES { $$ = 1; } + | NO { $$ = 0; } ; +no : /* empty */ { $$ = 0; } + | NO { $$ = 1; } + varset : STRING '=' string { if (conf->opts & OSPFD_OPT_VERBOSE) printf("%s = \"%s\"\n", $1, $3); @@ -190,40 +185,51 @@ conf_main : ROUTERID STRING { else conf->flags &= ~OSPFD_FLAG_NO_FIB_UPDATE; } - | REDISTRIBUTE STRING { + | no REDISTRIBUTE STRING { struct redistribute *r; - if (!strcmp($2, "default")) + if (!strcmp($3, "default")) { conf->redistribute |= REDISTRIBUTE_DEFAULT; - else { + if ($1) { + yyerror("cannot use 'no' with " + "redistribute default"); + free($3); + YYERROR; + } + } else { if ((r = calloc(1, sizeof(*r))) == NULL) fatal(NULL); - if (!strcmp($2, "static")) + if (!strcmp($3, "static")) r->type = REDIST_STATIC; - else if (!strcmp($2, "connected")) + else if (!strcmp($3, "connected")) r->type = REDIST_CONNECTED; else { yyerror("unknown redistribute type"); - free($2); + free($3); free(r); YYERROR; } + if ($1) + r->type |= REDIST_NO; + SIMPLEQ_INSERT_TAIL(&conf->redist_list, r, entry); } conf->redistribute |= REDISTRIBUTE_ON; - free($2); + free($3); } - | REDISTRIBUTE RTLABEL STRING { + | no REDISTRIBUTE RTLABEL STRING { struct redistribute *r; if ((r = calloc(1, sizeof(*r))) == NULL) fatal(NULL); r->type = REDIST_LABEL; - r->label = rtlabel_name2id($3); - free($3); + r->label = rtlabel_name2id($4); + if ($1) + r->type |= REDIST_NO; + free($4); SIMPLEQ_INSERT_TAIL(&conf->redist_list, r, entry); conf->redistribute |= REDISTRIBUTE_ON; @@ -496,6 +502,7 @@ lookup(char *s) {"hello-interval", HELLOINTERVAL}, {"interface", INTERFACE}, {"metric", METRIC}, + {"no", NO}, {"passive", PASSIVE}, {"redistribute", REDISTRIBUTE}, {"retransmit-interval", RETRANSMITINTERVAL}, @@ -506,7 +513,8 @@ lookup(char *s) {"rtlabel", RTLABEL}, {"spf-delay", SPFDELAY}, {"spf-holdtime", SPFHOLDTIME}, - {"transmit-delay", TRANSMITDELAY} + {"transmit-delay", TRANSMITDELAY}, + {"yes", YES} }; const struct keywords *p; diff --git a/usr.sbin/ospfd/printconf.c b/usr.sbin/ospfd/printconf.c index 2960f9fc38c..537760f02ec 100644 --- a/usr.sbin/ospfd/printconf.c +++ b/usr.sbin/ospfd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.3 2006/05/30 22:06:14 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.4 2006/05/31 03:24:06 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -29,6 +29,7 @@ #include "ospfe.h" void print_mainconf(struct ospfd_conf *); +const char *print_no(u_int16_t); void print_redistribute(struct ospfd_conf *); void print_iface(struct iface *); @@ -53,6 +54,15 @@ print_mainconf(struct ospfd_conf *conf) printf("spf-holdtime %u\n", conf->spf_hold_time); } +const char * +print_no(u_int16_t type) +{ + if (type & REDIST_NO) + return ("no "); + else + return (""); +} + void print_redistribute(struct ospfd_conf *conf) { @@ -62,16 +72,16 @@ print_redistribute(struct ospfd_conf *conf) printf("redistribute default\n"); SIMPLEQ_FOREACH(r, &conf->redist_list, entry) { - switch (r->type) { + switch (r->type & ~REDIST_NO) { case REDIST_STATIC: - printf("redistribute static\n"); + printf("%sredistribute static\n", print_no(r->type)); break; case REDIST_CONNECTED: - printf("redistribute connected\n"); + printf("%sredistribute connected\n", print_no(r->type)); break; case REDIST_LABEL: - printf("redistribute rtlabel %s\n", - rtlabel_id2name(r->label)); + printf("%sredistribute rtlabel %s\n", + print_no(r->type), rtlabel_id2name(r->label)); break; case REDIST_ADDR: /* ignore for now */ |