on the status of another interface.
in collaboration with benno@ jca@
OK benno@ jca@
-/* $OpenBSD: ospfd.c,v 1.94 2017/01/24 04:24:25 benno Exp $ */
+/* $OpenBSD: ospfd.c,v 1.95 2018/02/05 12:11:28 remi Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <net/if_types.h>
#include <event.h>
#include <err.h>
int
ospf_redistribute(struct kroute *kr, u_int32_t *metric)
{
+ struct in_addr addr;
+ struct kif *kif;
struct redistribute *r;
- u_int8_t is_default = 0;
+ int is_default = 0, depend_ok = 1;
+
+ bzero(&addr, sizeof(addr));
/* only allow 0.0.0.0/0 via REDIST_DEFAULT */
if (kr->prefix.s_addr == INADDR_ANY && kr->prefixlen == 0)
is_default = 1;
SIMPLEQ_FOREACH(r, &ospfd_conf->redist_list, entry) {
+ if (r->dependon[0] != '\0') {
+ if ((kif = kif_findname(r->dependon, addr, NULL)))
+ depend_ok = ifstate_is_up(kif);
+ else
+ depend_ok = 0;
+ } else
+ depend_ok = 1;
+
switch (r->type & ~REDIST_NO) {
case REDIST_LABEL:
if (kr->rtlabel == r->label) {
- *metric = r->metric;
+ *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_STATIC) {
- *metric = r->metric;
+ *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
if (kr->flags & F_DYNAMIC)
continue;
if (kr->flags & F_CONNECTED) {
- *metric = r->metric;
+ *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
if (r->addr.s_addr == INADDR_ANY &&
r->mask.s_addr == INADDR_ANY) {
if (is_default) {
- *metric = r->metric;
+ *metric = depend_ok ? r->metric :
+ MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
} else
return (0);
if ((kr->prefix.s_addr & r->mask.s_addr) ==
(r->addr.s_addr & r->mask.s_addr) &&
kr->prefixlen >= mask2prefixlen(r->mask.s_addr)) {
- *metric = r->metric;
+ *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
case REDIST_DEFAULT:
if (is_default) {
- *metric = r->metric;
+ *metric = depend_ok ? r->metric : MAX_METRIC;
return (r->type & REDIST_NO ? 0 : 1);
}
break;
if (ospfd_process == PROC_OSPF_ENGINE)
if_fsm(i, IF_EVT_UP);
}
+
+ strlcpy(i->dependon, xi->dependon,
+ sizeof(i->dependon));
+ i->depend_ok = xi->depend_ok;
}
return (dirty);
}
return (i);
return (NULL);
}
+
+int
+ifstate_is_up(struct kif *kif)
+{
+ if (!(kif->flags & IFF_UP))
+ return (0);
+ if (kif->if_type == IFT_CARP &&
+ kif->link_state == LINK_STATE_UNKNOWN)
+ return (0);
+ return LINK_STATE_IS_UP(kif->link_state);
+}
-.\" $OpenBSD: ospfd.conf.5,v 1.49 2017/11/07 06:32:02 remi Exp $
+.\" $OpenBSD: ospfd.conf.5,v 1.50 2018/02/05 12:11:28 remi Exp $
.\"
.\" Copyright (c) 2005 Esben Norby <norby@openbsd.org>
.\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 7 2017 $
+.Dd $Mdocdate: February 5 2018 $
.Dt OSPFD.CONF 5
.Os
.Sh NAME
.Ic default Pc
.Sm on
.Op Ic set ...
+.Op Ic depend on Ar interface
.Xc
.It Xo
.Op Ic no
-.Ic redistribute Ar prefix Op Ic set ...
+.Ic redistribute Ar prefix
+.Op Ic set ...
+.Op Ic depend on Ar interface
.Xc
.It Xo
.Op Ic no
-.Ic redistribute rtlabel Ar label Op Ic set ...
+.Ic redistribute rtlabel Ar label
+.Op Ic set ...
+.Op Ic depend on Ar interface
.Xc
If set to
.Ic connected ,
.Ic no
cannot be used together with it.
.Pp
+With the
+.Ic depend on
+option, redistributed routes will have a metric of 65535 if the specified
+.Ar interface
+is down or in state backup.
+This is especially useful on a carp cluster to ensure all traffic goes to
+the carp master.
+.Pp
It is possible to set the route
.Ic metric
and
when the interface state is going down.
The demotion counter will be decreased when the interface
state is active again.
+.It Ic depend Ic on Ar interface
+A metric of 65535 is used if the specified interface is down or in status
+backup.
.It Ic fast-hello-interval Ic msec Ar milliseconds
If the interface is configured to use
.Ic router-dead-time minimal ,
-/* $OpenBSD: ospfd.h,v 1.97 2017/01/24 04:24:25 benno Exp $ */
+/* $OpenBSD: ospfd.h,v 1.98 2018/02/05 12:11:28 remi Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
u_int32_t metric;
u_int16_t label;
u_int16_t type;
+ char dependon[IFNAMSIZ];
};
SIMPLEQ_HEAD(redist_list, redistribute);
char name[IF_NAMESIZE];
char demote_group[IFNAMSIZ];
+ char dependon[IFNAMSIZ];
char auth_key[MAX_SIMPLE_AUTH_LEN];
struct in_addr addr;
struct in_addr dst;
int fd;
int state;
int mtu;
+ int depend_ok;
u_int16_t flags;
u_int16_t transmit_delay;
u_int16_t hello_interval;
/* parse.y */
struct ospfd_conf *parse_config(char *, int);
int cmdline_symset(char *);
+void conf_clear_redist_list(struct redist_list *);
/* in_cksum.c */
u_int16_t in_cksum(void *, size_t);
void imsg_event_add(struct imsgev *);
int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t,
pid_t, int, void *, u_int16_t);
+int ifstate_is_up(struct kif *kif);
/* printconf.c */
void print_config(struct ospfd_conf *);
-/* $OpenBSD: ospfe.c,v 1.99 2017/01/24 04:24:25 benno Exp $ */
+/* $OpenBSD: ospfe.c,v 1.100 2018/02/05 12:11:28 remi Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
event_add(&oeconf->ev, NULL);
/* remove unneeded config stuff */
- while ((r = SIMPLEQ_FIRST(&oeconf->redist_list)) != NULL) {
- SIMPLEQ_REMOVE_HEAD(&oeconf->redist_list, entry);
- free(r);
- }
+ conf_clear_redist_list(&oeconf->redist_list);
LIST_FOREACH(area, &oeconf->area_list, entry) {
while ((r = SIMPLEQ_FIRST(&area->redist_list)) != NULL) {
SIMPLEQ_REMOVE_HEAD(&area->redist_list, entry);
iface->name);
}
}
+ if (strcmp(kif->ifname,
+ iface->dependon) == 0) {
+ log_warnx("interface %s"
+ " changed state, %s"
+ " depends on it",
+ kif->ifname,
+ iface->name);
+ iface->depend_ok =
+ ifstate_is_up(kif);
+
+ if ((iface->flags &
+ IFF_UP) &&
+ LINK_STATE_IS_UP(iface->linkstate))
+ orig_rtr_lsa(iface->area);
+ }
}
}
break;
if (oeconf->flags & OSPFD_FLAG_STUB_ROUTER ||
oe_nofib)
rtr_link.metric = MAX_METRIC;
+ else if (iface->dependon[0] != '\0' &&
+ iface->depend_ok == 0)
+ rtr_link.metric = MAX_METRIC;
else
rtr_link.metric = htons(iface->metric);
num_links++;
rtr_link.num_tos = 0;
/*
- * backup carp interfaces are anounced with high metric
- * for faster failover.
+ * backup carp interfaces and interfaces that depend
+ * on an interface that is down are announced with
+ * high metric for faster failover.
*/
if (iface->if_type == IFT_CARP &&
iface->linkstate == LINK_STATE_DOWN)
rtr_link.metric = MAX_METRIC;
+ else if (iface->dependon[0] != '\0' &&
+ iface->depend_ok == 0)
+ rtr_link.metric = MAX_METRIC;
else
rtr_link.metric = htons(iface->metric);
num_links++;
if (oe_nofib || oeconf->flags &
OSPFD_FLAG_STUB_ROUTER)
rtr_link.metric = MAX_METRIC;
+ else if (iface->dependon[0] != '\0' &&
+ iface->depend_ok == 0)
+ rtr_link.metric = MAX_METRIC;
else
rtr_link.metric =
htons(iface->metric);
-/* $OpenBSD: parse.y,v 1.83 2017/01/05 13:53:09 krw Exp $ */
+/* $OpenBSD: parse.y,v 1.84 2018/02/05 12:11:28 remi Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
%token DEMOTE
%token INCLUDE
%token ERROR
+%token DEPEND ON
%token <v.string> STRING
%token <v.number> NUMBER
%type <v.number> yesno no optlist optlist_l option demotecount msec
%type <v.number> deadtime
-%type <v.string> string
+%type <v.string> string dependon
%type <v.redist> redistribute
%%
;
-redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist {
+redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
struct redistribute *r;
if ((r = calloc(1, sizeof(*r))) == NULL)
if ($1)
r->type |= REDIST_NO;
r->metric = $6;
+ if ($7) {
+ strlcpy(r->dependon, $7, sizeof(r->dependon));
+ } else
+ r->dependon[0] = '\0';
+ free($7);
$$ = r;
}
- | no REDISTRIBUTE STRING optlist {
+ | no REDISTRIBUTE STRING optlist dependon {
struct redistribute *r;
if ((r = calloc(1, sizeof(*r))) == NULL)
if ($1)
r->type |= REDIST_NO;
r->metric = $4;
+ if ($5) {
+ strlcpy(r->dependon, $5, sizeof(r->dependon));
+ } else
+ r->dependon[0] = '\0';
free($3);
+ free($5);
$$ = r;
}
- | no REDISTRIBUTE RTLABEL STRING optlist {
+ | no REDISTRIBUTE RTLABEL STRING optlist dependon {
struct redistribute *r;
if ((r = calloc(1, sizeof(*r))) == NULL)
if ($1)
r->type |= REDIST_NO;
r->metric = $5;
+ if ($6)
+ strlcpy(r->dependon, $6, sizeof(r->dependon));
+ else
+ r->dependon[0] = '\0';
free($4);
-
+ free($6);
$$ = r;
}
;
optlist : /* empty */ { $$ = DEFAULT_REDIST_METRIC; }
- | SET option {
+ | SET option {
$$ = $2;
if (($$ & LSA_METRIC_MASK) == 0)
$$ |= DEFAULT_REDIST_METRIC;
}
- | SET optnl '{' optnl optlist_l optnl '}' {
+ | SET optnl '{' optnl optlist_l optnl '}' {
$$ = $5;
if (($$ & LSA_METRIC_MASK) == 0)
$$ |= DEFAULT_REDIST_METRIC;
}
;
+dependon : /* empty */ { $$ = NULL; }
+ | DEPEND ON STRING {
+ struct in_addr addr;
+ struct kif *kif;
+
+ if (strlen($3) >= IFNAMSIZ) {
+ yyerror("interface name %s too long", $3);
+ free($3);
+ YYERROR;
+ }
+ bzero(&addr, sizeof(addr));
+ if ((kif = kif_findname($3, addr, NULL)) == NULL) {
+ yyerror("unknown interface %s", $3);
+ free($3);
+ YYERROR;
+ }
+ $$ = $3;
+ }
+ ;
+
authmd : AUTHMD NUMBER STRING {
if ($2 < MIN_MD_ID || $2 > MAX_MD_ID) {
yyerror("auth-md key-id out of range "
YYERROR;
}
}
+ | dependon {
+ struct in_addr addr;
+ struct kif *kif;
+
+ if ($1) {
+ strlcpy(iface->dependon, $1,
+ sizeof(iface->dependon));
+ bzero(&addr, sizeof(addr));
+ kif = kif_findname($1, addr, NULL);
+ iface->depend_ok = ifstate_is_up(kif);
+ } else {
+ iface->dependon[0] = '\0';
+ iface->depend_ok = 1;
+ }
+
+ free($1);
+ }
| defaults
;
{"auth-md-keyid", AUTHMDKEYID},
{"auth-type", AUTHTYPE},
{"demote", DEMOTE},
+ {"depend", DEPEND},
{"external-tag", EXTTAG},
{"fast-hello-interval", FASTHELLOINTERVAL},
{"fib-update", FIBUPDATE},
{"minimal", MINIMAL},
{"msec", MSEC},
{"no", NO},
+ {"on", ON},
{"passive", PASSIVE},
{"rdomain", RDOMAIN},
{"redistribute", REDISTRIBUTE},
return (errs);
}
+void
+conf_clear_redist_list(struct redist_list *rl)
+{
+ struct redistribute *r;
+ while ((r = SIMPLEQ_FIRST(rl)) != NULL) {
+ SIMPLEQ_REMOVE_HEAD(rl, entry);
+ free(r);
+ }
+}
+
void
clear_config(struct ospfd_conf *xconf)
{
area_del(a);
}
+ conf_clear_redist_list(&xconf->redist_list);
+
free(xconf);
}
-/* $OpenBSD: printconf.c,v 1.17 2016/11/19 12:46:46 sthen Exp $ */
+/* $OpenBSD: printconf.c,v 1.18 2018/02/05 12:11:28 remi Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
printf("%sredistribute default ", print_no(r->type));
break;
}
- printf("set { metric %d type %d }\n",
+ printf("set { metric %d type %d }",
(r->metric & LSA_METRIC_MASK),
((r->metric & LSA_ASEXT_E_FLAG) == 0 ? 1 : 2));
+ if (r->dependon[0])
+ printf(" depend on %s", r->dependon);
+ printf("\n");
}
}
printf("\t\tmetric %d\n", iface->metric);
- if (*iface->demote_group)
+ if (iface->demote_group[0] != '\0')
printf("\t\tdemote %s\n", iface->demote_group);
+ if (iface->dependon[0] != '\0')
+ printf("\t\tdepend on %s\n", iface->dependon);
if (iface->passive)
printf("\t\tpassive\n");
else {
-/* $OpenBSD: rde.c,v 1.108 2017/01/24 04:24:25 benno Exp $ */
+/* $OpenBSD: rde.c,v 1.109 2018/02/05 12:11:28 remi Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
struct area *area;
struct iface *iface;
struct passwd *pw;
- struct redistribute *r;
pid_t pid;
switch (pid = fork()) {
LIST_FOREACH(iface, &area->iface_list, entry)
md_list_clr(&iface->auth_md_list);
- while ((r = SIMPLEQ_FIRST(&rdeconf->redist_list)) != NULL) {
- SIMPLEQ_REMOVE_HEAD(&rdeconf->redist_list, entry);
- free(r);
- }
+ conf_clear_redist_list(&rdeconf->redist_list);
gettimeofday(&now, NULL);
rdeconf->uptime = now.tv_sec;