summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichele <michele@openbsd.org>2009-03-24 19:26:13 +0000
committermichele <michele@openbsd.org>2009-03-24 19:26:13 +0000
commit39c227bca9a4003fc2ff80ecdea035ada6f8d152 (patch)
tree4135188d56a4b3ed0bacdb9d8a9a169b43f3d73a
parent+otus(4) (diff)
downloadwireguard-openbsd-39c227bca9a4003fc2ff80ecdea035ada6f8d152.tar.xz
wireguard-openbsd-39c227bca9a4003fc2ff80ecdea035ada6f8d152.zip
Change the behaviour of redistribute default.
Now a default route have to be present in the fib to be correctly advertised. Spotted and tested by Steven Surdok on ripd. ok claudio@
-rw-r--r--usr.sbin/ospfd/ospfd.c42
-rw-r--r--usr.sbin/ripd/parse.y52
-rw-r--r--usr.sbin/ripd/printconf.c8
-rw-r--r--usr.sbin/ripd/ripd.c36
-rw-r--r--usr.sbin/ripd/ripd.h6
5 files changed, 60 insertions, 84 deletions
diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c
index 613d3db4001..18aae6370f3 100644
--- a/usr.sbin/ospfd/ospfd.c
+++ b/usr.sbin/ospfd/ospfd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfd.c,v 1.61 2009/03/01 16:03:12 michele Exp $ */
+/* $OpenBSD: ospfd.c,v 1.62 2009/03/24 19:26:13 michele Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -55,8 +55,6 @@ int check_child(pid_t, const char *);
void main_dispatch_ospfe(int, short, void *);
void main_dispatch_rde(int, short, void *);
-void ospf_redistribute_default(int);
-
int ospf_reload(void);
int ospf_sendboth(enum imsg_type, void *, u_int16_t);
int merge_interfaces(struct area *, struct area *);
@@ -291,9 +289,6 @@ main(int argc, char *argv[])
area_del(a);
}
- /* redistribute default */
- ospf_redistribute_default(IMSG_NETWORK_ADD);
-
event_dispatch();
ospfd_shutdown();
@@ -523,14 +518,17 @@ int
ospf_redistribute(struct kroute *kr, u_int32_t *metric)
{
struct redistribute *r;
+ u_int8_t is_default = 0;
- /* only allow 0.0.0.0/0 via REDISTRIBUTE_DEFAULT */
+ /* only allow 0.0.0.0/0 via REDIST_DEFAULT */
if (kr->prefix.s_addr == INADDR_ANY && kr->prefixlen == 0)
- return (0);
+ is_default = 1;
SIMPLEQ_FOREACH(r, &ospfd_conf->redist_list, entry) {
switch (r->type & ~REDIST_NO) {
case REDIST_LABEL:
+ if (is_default)
+ continue;
if (kr->rtlabel == r->label) {
*metric = r->metric;
return (r->type & REDIST_NO ? 0 : 1);
@@ -542,6 +540,8 @@ ospf_redistribute(struct kroute *kr, u_int32_t *metric)
* so that link local addresses can be redistributed
* via a rtlabel.
*/
+ if (is_default)
+ continue;
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_STATIC) {
@@ -550,6 +550,8 @@ ospf_redistribute(struct kroute *kr, u_int32_t *metric)
}
break;
case REDIST_CONNECTED:
+ if (is_default)
+ continue;
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_CONNECTED) {
@@ -558,6 +560,8 @@ ospf_redistribute(struct kroute *kr, u_int32_t *metric)
}
break;
case REDIST_ADDR:
+ if (is_default)
+ continue;
if (kr->flags & F_DYNAMIC)
continue;
if ((kr->prefix.s_addr & r->mask.s_addr) ==
@@ -568,7 +572,8 @@ ospf_redistribute(struct kroute *kr, u_int32_t *metric)
}
break;
case REDIST_DEFAULT:
- /* nothing to be done here */
+ if (is_default)
+ return (1);
break;
}
}
@@ -576,25 +581,6 @@ ospf_redistribute(struct kroute *kr, u_int32_t *metric)
return (0);
}
-void
-ospf_redistribute_default(int type)
-{
- struct rroute rr;
- struct redistribute *r;
-
- SIMPLEQ_FOREACH(r, &ospfd_conf->redist_list, entry) {
- if (r->type != REDIST_DEFAULT)
- continue;
- if (r->type == (REDIST_DEFAULT | REDIST_NO))
- return;
-
- bzero(&rr, sizeof(rr));
- rr.metric = r->metric;
- main_imsg_compose_rde(type, 0, &rr, sizeof(struct rroute));
- return;
- }
-}
-
int
ospf_reload(void)
{
diff --git a/usr.sbin/ripd/parse.y b/usr.sbin/ripd/parse.y
index 678a2649da5..5f7d1d748cc 100644
--- a/usr.sbin/ripd/parse.y
+++ b/usr.sbin/ripd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.22 2009/03/04 22:59:28 michele Exp $ */
+/* $OpenBSD: parse.y,v 1.23 2009/03/24 19:26:13 michele Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -185,35 +185,29 @@ conf_main : SPLIT_HORIZON STRING {
| no REDISTRIBUTE STRING {
struct redistribute *r;
- if (!strcmp($3, "default")) {
- if (!$1)
- conf->redistribute |=
- REDISTRIBUTE_DEFAULT;
- else
- conf->redistribute &=
- ~REDISTRIBUTE_DEFAULT;
- } else {
- if ((r = calloc(1, sizeof(*r))) == NULL)
- fatal(NULL);
- if (!strcmp($3, "static"))
- r->type = REDIST_STATIC;
- else if (!strcmp($3, "connected"))
- r->type = REDIST_CONNECTED;
- else if (host($3, &r->addr, &r->mask))
- r->type = REDIST_ADDR;
- else {
- yyerror("unknown redistribute type");
- free($3);
- free(r);
- YYERROR;
- }
-
- if ($1)
- r->type |= REDIST_NO;
-
- SIMPLEQ_INSERT_TAIL(&conf->redist_list, r,
- entry);
+ if ((r = calloc(1, sizeof(*r))) == NULL)
+ fatal(NULL);
+ if (!strcmp($3, "static"))
+ r->type = REDIST_STATIC;
+ else if (!strcmp($3, "connected"))
+ r->type = REDIST_CONNECTED;
+ else if (!strcmp($3, "default"))
+ r->type = REDIST_DEFAULT;
+ else if (host($3, &r->addr, &r->mask))
+ r->type = REDIST_ADDR;
+ else {
+ yyerror("unknown redistribute type");
+ free($3);
+ free(r);
+ YYERROR;
}
+
+ if ($1)
+ r->type |= REDIST_NO;
+
+ SIMPLEQ_INSERT_TAIL(&conf->redist_list, r,
+ entry);
+
conf->redistribute |= REDISTRIBUTE_ON;
free($3);
}
diff --git a/usr.sbin/ripd/printconf.c b/usr.sbin/ripd/printconf.c
index bc0d0603c97..4564540f0de 100644
--- a/usr.sbin/ripd/printconf.c
+++ b/usr.sbin/ripd/printconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printconf.c,v 1.4 2007/10/18 09:42:47 claudio Exp $ */
+/* $OpenBSD: printconf.c,v 1.5 2009/03/24 19:26:13 michele Exp $ */
/*
* Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -70,9 +70,6 @@ print_redistribute(struct ripd_conf *conf)
{
struct redistribute *r;
- if (conf->redistribute & REDISTRIBUTE_DEFAULT)
- printf("redistribute default\n");
-
SIMPLEQ_FOREACH(r, &conf->redist_list, entry) {
switch (r->type & ~REDIST_NO) {
case REDIST_STATIC:
@@ -85,6 +82,9 @@ print_redistribute(struct ripd_conf *conf)
printf("%sredistribute rtlabel %s\n",
print_no(r->type), rtlabel_id2name(r->label));
break;
+ case REDIST_DEFAULT:
+ printf("redistribute default\n");
+ break;
case REDIST_ADDR:
printf("%ssredistribute %s/%d\n",
print_no(r->type), inet_ntoa(r->addr),
diff --git a/usr.sbin/ripd/ripd.c b/usr.sbin/ripd/ripd.c
index 57f5b5c8f34..462d43a64a6 100644
--- a/usr.sbin/ripd/ripd.c
+++ b/usr.sbin/ripd/ripd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripd.c,v 1.11 2008/12/17 14:19:39 michele Exp $ */
+/* $OpenBSD: ripd.c,v 1.12 2009/03/24 19:26:13 michele Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -54,7 +54,6 @@ void main_sig_handler(int, short, void *);
void ripd_shutdown(void);
void main_dispatch_ripe(int, short, void *);
void main_dispatch_rde(int, short, void *);
-void ripd_redistribute_default(int);
int pipe_parent2ripe[2];
int pipe_parent2rde[2];
@@ -267,9 +266,6 @@ main(int argc, char *argv[])
if (kr_init(!(conf->flags & RIPD_FLAG_NO_FIB_UPDATE)) == -1)
fatalx("kr_init failed");
- /* redistribute default */
- ripd_redistribute_default(IMSG_NETWORK_ADD);
-
event_dispatch();
ripd_shutdown();
@@ -486,17 +482,20 @@ int
rip_redistribute(struct kroute *kr)
{
struct redistribute *r;
+ u_int8_t is_default = 0;
if (kr->flags & F_RIPD_INSERTED)
return (1);
- /* only allow 0.0.0.0/0 via REDISTRIBUTE_DEFAULT */
+ /* only allow 0.0.0.0/0 via REDIST_DEFAULT */
if (kr->prefix.s_addr == INADDR_ANY && kr->netmask.s_addr == INADDR_ANY)
- return (0);
+ is_default = 1;
SIMPLEQ_FOREACH(r, &conf->redist_list, entry) {
switch (r->type & ~REDIST_NO) {
case REDIST_LABEL:
+ if (is_default)
+ continue;
if (kr->rtlabel == r->label)
return (r->type & REDIST_NO ? 0 : 1);
break;
@@ -506,18 +505,24 @@ rip_redistribute(struct kroute *kr)
* so that link local addresses can be redistributed
* via a rtlabel.
*/
+ if (is_default)
+ continue;
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_STATIC)
return (r->type & REDIST_NO ? 0 : 1);
break;
case REDIST_CONNECTED:
+ if (is_default)
+ continue;
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_CONNECTED)
return (r->type & REDIST_NO ? 0 : 1);
break;
case REDIST_ADDR:
+ if (is_default)
+ continue;
if (kr->flags & F_DYNAMIC)
continue;
if ((kr->prefix.s_addr & r->mask.s_addr) ==
@@ -526,25 +531,16 @@ rip_redistribute(struct kroute *kr)
r->mask.s_addr)
return (r->type & REDIST_NO? 0 : 1);
break;
+ case REDIST_DEFAULT:
+ if (is_default)
+ return (1);
+ break;
}
}
return (0);
}
-void
-ripd_redistribute_default(int type)
-{
- struct kroute kr;
-
- if (!(conf->redistribute & REDISTRIBUTE_DEFAULT))
- return;
-
- bzero(&kr, sizeof(kr));
- kr.metric = 1; /* default metric */
- main_imsg_compose_rde(type, 0, &kr, sizeof(struct kroute));
-}
-
/* this needs to be added here so that ripctl can be used without libevent */
void
imsg_event_add(struct imsgbuf *ibuf)
diff --git a/usr.sbin/ripd/ripd.h b/usr.sbin/ripd/ripd.h
index f14fe7d8b31..7c400bdc9a0 100644
--- a/usr.sbin/ripd/ripd.h
+++ b/usr.sbin/ripd/ripd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripd.h,v 1.11 2008/12/17 14:19:39 michele Exp $ */
+/* $OpenBSD: ripd.h,v 1.12 2009/03/24 19:26:13 michele Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -58,7 +58,6 @@
#define F_REDISTRIBUTED 0x0100
#define REDISTRIBUTE_ON 0x01
-#define REDISTRIBUTE_DEFAULT 0x02
#define OPT_SPLIT_HORIZON 0x01
#define OPT_SPLIT_POISONED 0x02
@@ -256,7 +255,8 @@ enum {
#define REDIST_STATIC 0x02
#define REDIST_LABEL 0x04
#define REDIST_ADDR 0x08
-#define REDIST_NO 0x10
+#define REDIST_DEFAULT 0x10
+#define REDIST_NO 0x20
struct redistribute {
SIMPLEQ_ENTRY(redistribute) entry;