From: benno Date: Sun, 11 Feb 2018 02:27:33 +0000 (+0000) Subject: Use the new route filter ROUTE_PRIOFILTER in ospfd. Usually we only X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ad4152efb0e24a256768384735c285b5c1843907;p=openbsd Use the new route filter ROUTE_PRIOFILTER in ospfd. Usually we only need to see routes with a higher priority (lower value) than ospfds own routes. ok claudio, ok henning previous version, feedback from sthen --- diff --git a/usr.sbin/ospfd/kroute.c b/usr.sbin/ospfd/kroute.c index 17febefbdcb..dd078776b1b 100644 --- a/usr.sbin/ospfd/kroute.c +++ b/usr.sbin/ospfd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.108 2017/07/24 11:00:01 friehm Exp $ */ +/* $OpenBSD: kroute.c,v 1.109 2018/02/11 02:27:33 benno Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -127,10 +127,11 @@ kif_init(void) } int -kr_init(int fs, u_int rdomain) +kr_init(int fs, u_int rdomain, int redis_label_or_prefix) { int opt = 0, rcvbuf, default_rcvbuf; socklen_t optlen; + int filter_prio = RTP_OSPF; kr_state.fib_sync = fs; kr_state.rdomain = rdomain; @@ -146,6 +147,18 @@ kr_init(int fs, u_int rdomain) &opt, sizeof(opt)) == -1) log_warn("kr_init: setsockopt"); /* not fatal */ + if (redis_label_or_prefix) { + filter_prio = 0; + log_info("%s: priority filter disabled", __func__); + } else + log_debug("%s: priority filter enabled", __func__); + + if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, &filter_prio, + sizeof(filter_prio)) == -1) { + log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__); + /* not fatal */ + } + /* grow receive buffer, don't wanna miss messages */ optlen = sizeof(default_rcvbuf); if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF, @@ -600,12 +613,27 @@ kr_redistribute(struct kroute_node *kh) } void -kr_reload(void) +kr_reload(int redis_label_or_prefix) { struct kroute_node *kr, *kn; u_int32_t dummy; int r; + int filter_prio = RTP_OSPF; + + /* update the priority filter */ + if (redis_label_or_prefix) { + filter_prio = 0; + log_info("%s: priority filter disabled", __func__); + } else + log_debug("%s: priority filter enabled", __func__); + + if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, &filter_prio, + sizeof(filter_prio)) == -1) { + log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__); + /* not fatal */ + } + /* update redistribute lists */ RB_FOREACH(kr, kroute_tree, &krt) { for (kn = kr; kn; kn = kn->next) { r = ospf_redistribute(&kn->r, &dummy); diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c index 3c5057ae04e..3c738b10557 100644 --- a/usr.sbin/ospfd/ospfd.c +++ b/usr.sbin/ospfd/ospfd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.c,v 1.96 2018/02/09 22:52:54 jca Exp $ */ +/* $OpenBSD: ospfd.c,v 1.97 2018/02/11 02:27:33 benno Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -265,7 +265,7 @@ main(int argc, char *argv[]) event_add(&iev_rde->ev, NULL); if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE), - ospfd_conf->rdomain) == -1) + ospfd_conf->rdomain, ospfd_conf->redist_label_or_prefix) == -1) fatalx("kr_init failed"); /* remove unneeded stuff from config */ @@ -637,7 +637,7 @@ ospf_reload(void) merge_config(ospfd_conf, xconf); /* update redistribute lists */ - kr_reload(); + kr_reload(ospfd_conf->redist_label_or_prefix); return (0); } @@ -667,6 +667,7 @@ merge_config(struct ospfd_conf *conf, struct ospfd_conf *xconf) SIMPLEQ_EMPTY(&xconf->redist_list)) rchange = 1; conf->rfc1583compat = xconf->rfc1583compat; + conf->redist_label_or_prefix = xconf->redist_label_or_prefix; if (ospfd_process == PROC_MAIN) { /* main process does neither use areas nor interfaces */ diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index af082b1079c..dd397d27cd5 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.99 2018/02/08 00:18:57 claudio Exp $ */ +/* $OpenBSD: ospfd.h,v 1.100 2018/02/11 02:27:33 benno Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -394,6 +394,7 @@ struct ospfd_conf { int spf_state; int ospf_socket; int flags; + int redist_label_or_prefix; u_int8_t rfc1583compat; u_int8_t border; u_int8_t redistribute; @@ -567,7 +568,7 @@ u_int16_t iso_cksum(void *, u_int16_t, u_int16_t); /* kroute.c */ int kif_init(void); void kif_clear(void); -int kr_init(int, u_int); +int kr_init(int, u_int, int); int kr_change(struct kroute *, int); int kr_delete(struct kroute *); void kr_shutdown(void); @@ -578,7 +579,7 @@ void kr_dispatch_msg(int, short, void *); void kr_show_route(struct imsg *); void kr_ifinfo(char *, pid_t); struct kif *kif_findname(char *, struct in_addr, struct kif_addr **); -void kr_reload(void); +void kr_reload(int); u_int8_t mask2prefixlen(in_addr_t); in_addr_t prefixlen2mask(u_int8_t); diff --git a/usr.sbin/ospfd/parse.y b/usr.sbin/ospfd/parse.y index 4bf64d5d7e3..859918537cc 100644 --- a/usr.sbin/ospfd/parse.y +++ b/usr.sbin/ospfd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.85 2018/02/09 22:52:54 jca Exp $ */ +/* $OpenBSD: parse.y,v 1.86 2018/02/11 02:27:33 benno Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby @@ -295,6 +295,8 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon { if ($1) r->type |= REDIST_NO; + else + conf->redist_label_or_prefix = 1; r->metric = $6; if ($7) strlcpy(r->dependon, $7, sizeof(r->dependon)); @@ -314,9 +316,10 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon { r->type = REDIST_STATIC; else if (!strcmp($3, "connected")) r->type = REDIST_CONNECTED; - else if (host($3, &r->addr, &r->mask)) + else if (host($3, &r->addr, &r->mask)) { r->type = REDIST_ADDR; - else { + conf->redist_label_or_prefix = !$1; + } else { yyerror("unknown redistribute type"); free($3); free(r); @@ -343,6 +346,8 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon { r->label = rtlabel_name2id($4); if ($1) r->type |= REDIST_NO; + else + conf->redist_label_or_prefix = 1; r->metric = $5; if ($6) strlcpy(r->dependon, $6, sizeof(r->dependon));