From 5d393f89df4eea79e7642c10962031cfb716a811 Mon Sep 17 00:00:00 2001 From: remi Date: Thu, 12 Jul 2018 13:45:03 +0000 Subject: [PATCH] Add support for rdomains. small quirk from tb@ ok phessler@ --- usr.sbin/ospf6ctl/ospf6ctl.c | 9 ++++++--- usr.sbin/ospf6d/interface.c | 5 +++-- usr.sbin/ospf6d/kroute.c | 13 ++++++++----- usr.sbin/ospf6d/ospf6d.c | 15 +++++++++++---- usr.sbin/ospf6d/ospf6d.conf.5 | 8 +++++++- usr.sbin/ospf6d/ospf6d.h | 8 +++++--- usr.sbin/ospf6d/ospfe.c | 4 ++-- usr.sbin/ospf6d/parse.y | 35 +++++++++++++++++++++++++++++++++-- usr.sbin/ospf6d/printconf.c | 5 ++++- usr.sbin/ospf6d/rde.c | 4 ++-- 10 files changed, 81 insertions(+), 25 deletions(-) diff --git a/usr.sbin/ospf6ctl/ospf6ctl.c b/usr.sbin/ospf6ctl/ospf6ctl.c index 7410a7c9179..ec2b5c3c2c6 100644 --- a/usr.sbin/ospf6ctl/ospf6ctl.c +++ b/usr.sbin/ospf6ctl/ospf6ctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6ctl.c,v 1.48 2018/06/06 05:51:43 remi Exp $ */ +/* $OpenBSD: ospf6ctl.c,v 1.49 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -90,13 +90,16 @@ main(int argc, char *argv[]) struct parse_result *res; struct imsg imsg; unsigned int ifidx = 0; - int ctl_sock; + int ctl_sock, r; int done = 0, verbose = 0; int n; int ch; char *sockname; - sockname = OSPF6D_SOCKET; + r = getrtable(); + if (asprintf(&sockname, "%s.%d", OSPF6D_SOCKET, r) == -1) + err(1, "asprintf"); + while ((ch = getopt(argc, argv, "s:")) != -1) { switch (ch) { case 's': diff --git a/usr.sbin/ospf6d/interface.c b/usr.sbin/ospf6d/interface.c index 28687558122..d97a1149347 100644 --- a/usr.sbin/ospf6d/interface.c +++ b/usr.sbin/ospf6d/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.23 2018/03/11 13:17:35 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.24 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -235,13 +235,14 @@ if_new(u_short ifindex, char *ifname) void if_update(struct iface *iface, int mtu, int flags, u_int8_t type, - u_int8_t state, u_int64_t rate) + u_int8_t state, u_int64_t rate, u_int32_t rdomain) { iface->mtu = mtu; iface->flags = flags; iface->if_type = type; iface->linkstate = state; iface->baudrate = rate; + iface->rdomain = rdomain; /* set type */ if (flags & IFF_POINTOPOINT) diff --git a/usr.sbin/ospf6d/kroute.c b/usr.sbin/ospf6d/kroute.c index 7d798cd038a..9bec21a00d3 100644 --- a/usr.sbin/ospf6d/kroute.c +++ b/usr.sbin/ospf6d/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.57 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: kroute.c,v 1.58 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -47,6 +47,7 @@ struct { int fib_sync; int fd; struct event ev; + u_int rdomain; } kr_state; struct kroute_node { @@ -94,12 +95,13 @@ RB_PROTOTYPE(kroute_tree, kroute_node, entry, kroute_compare) RB_GENERATE(kroute_tree, kroute_node, entry, kroute_compare) int -kr_init(int fs) +kr_init(int fs, u_int rdomain) { int opt = 0, rcvbuf, default_rcvbuf; socklen_t optlen; kr_state.fib_sync = fs; + kr_state.rdomain = rdomain; if ((kr_state.fd = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, AF_INET6)) == -1) { @@ -718,7 +720,7 @@ kif_update(u_short ifindex, int flags, struct if_data *ifd, } if_update(iface, ifd->ifi_mtu, flags, ifd->ifi_type, - ifd->ifi_link_state, ifd->ifi_baudrate); + ifd->ifi_link_state, ifd->ifi_baudrate, ifd->ifi_rdomain); return (iface); } @@ -1012,6 +1014,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute) hdr.rtm_version = RTM_VERSION; hdr.rtm_type = action; hdr.rtm_priority = RTP_OSPF; + hdr.rtm_tableid = kr_state.rdomain; /* rtableid */ if (action == RTM_CHANGE) hdr.rtm_fmask = RTF_REJECT|RTF_BLACKHOLE; else @@ -1143,7 +1146,7 @@ fetchtable(void) mib[3] = AF_INET6; mib[4] = NET_RT_DUMP; mib[5] = 0; - mib[6] = 0; /* rtableid */ + mib[6] = kr_state.rdomain; /* rtableid */ if (sysctl(mib, 7, NULL, &len, NULL, 0) == -1) { log_warn("sysctl"); @@ -1377,7 +1380,7 @@ dispatch_rtmsg(void) sa = (struct sockaddr *)(next + rtm->rtm_hdrlen); get_rtaddrs(rtm->rtm_addrs, sa, rti_info); - if (rtm->rtm_tableid != 0) + if (rtm->rtm_tableid != kr_state.rdomain) continue; if (rtm->rtm_pid == kr_state.pid) /* caused by us */ diff --git a/usr.sbin/ospf6d/ospf6d.c b/usr.sbin/ospf6d/ospf6d.c index dcea8c7a86b..e8ef83f575b 100644 --- a/usr.sbin/ospf6d/ospf6d.c +++ b/usr.sbin/ospf6d/ospf6d.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6d.c,v 1.37 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: ospf6d.c,v 1.38 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -114,11 +114,10 @@ main(int argc, char *argv[]) int ipforwarding; int mib[4]; size_t len; - char *sockname; + char *sockname = NULL; conffile = CONF_FILE; ospfd_process = PROC_MAIN; - sockname = OSPF6D_SOCKET; log_init(1, LOG_DAEMON); /* log to stderr until daemonized */ log_procinit(log_procnames[ospfd_process]); @@ -182,6 +181,13 @@ main(int argc, char *argv[]) /* parse config file */ if ((ospfd_conf = parse_config(conffile, opts)) == NULL ) exit(1); + + if (sockname == NULL) { + if (asprintf(&sockname, "%s.%d", OSPF6D_SOCKET, + ospfd_conf->rdomain) == -1) + err(1, "asprintf"); + } + ospfd_conf->csock = sockname; if (ospfd_conf->opts & OSPFD_OPT_NOACTION) { @@ -260,7 +266,8 @@ main(int argc, char *argv[]) iev_rde->handler, iev_rde); event_add(&iev_rde->ev, NULL); - if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE)) == -1) + if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE), + ospfd_conf->rdomain) == -1) fatalx("kr_init failed"); event_dispatch(); diff --git a/usr.sbin/ospf6d/ospf6d.conf.5 b/usr.sbin/ospf6d/ospf6d.conf.5 index ac0c51a6535..c57b6faa945 100644 --- a/usr.sbin/ospf6d/ospf6d.conf.5 +++ b/usr.sbin/ospf6d/ospf6d.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ospf6d.conf.5,v 1.15 2018/07/12 12:19:05 remi Exp $ +.\" $OpenBSD: ospf6d.conf.5,v 1.16 2018/07/12 13:45:03 remi Exp $ .\" .\" Copyright (c) 2005 Esben Norby .\" Copyright (c) 2004 Claudio Jeker @@ -101,6 +101,12 @@ will implicitly set the .Ic stub Ic router option to ensure that no traffic tries to transit via this router. .Pp +.It Ic rdomain Ar tableid +Specifies the routing table +.Xr ospfd 8 +should modify. +Table 0 is the default table. +.Pp .It Xo .Op Ic no .Ic redistribute diff --git a/usr.sbin/ospf6d/ospf6d.h b/usr.sbin/ospf6d/ospf6d.h index 38314e2992c..25972892395 100644 --- a/usr.sbin/ospf6d/ospf6d.h +++ b/usr.sbin/ospf6d/ospf6d.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6d.h,v 1.36 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: ospf6d.h,v 1.37 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2004, 2007 Esben Norby @@ -312,6 +312,7 @@ struct iface { u_int32_t ls_ack_cnt; time_t uptime; unsigned int ifindex; + u_int rdomain; int fd; int state; int mtu; @@ -384,6 +385,7 @@ struct ospfd_conf { int flags; u_int8_t border; u_int8_t redistribute; + u_int rdomain; char *csock; }; @@ -525,7 +527,7 @@ struct iface *if_find(unsigned int); struct iface *if_findname(char *); struct iface *if_new(u_short, char *); void if_update(struct iface *, int, int, u_int8_t, u_int8_t, - u_int64_t); + u_int64_t, u_int32_t); /* in_cksum.c */ u_int16_t in_cksum(void *, size_t); @@ -534,7 +536,7 @@ u_int16_t in_cksum(void *, size_t); u_int16_t iso_cksum(void *, u_int16_t, u_int16_t); /* kroute.c */ -int kr_init(int); +int kr_init(int, u_int); int kr_change(struct kroute *, int); int kr_delete(struct kroute *); void kr_shutdown(void); diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c index 7ce0392aec5..3f03589ab49 100644 --- a/usr.sbin/ospf6d/ospfe.c +++ b/usr.sbin/ospf6d/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.53 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: ospfe.c,v 1.54 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -324,7 +324,7 @@ ospfe_dispatch_main(int fd, short event, void *bula) LINK_STATE_IS_UP(iface->linkstate); if_update(iface, ifp->mtu, ifp->flags, ifp->if_type, - ifp->linkstate, ifp->baudrate); + ifp->linkstate, ifp->baudrate, ifp->rdomain); isvalid = (iface->flags & IFF_UP) && LINK_STATE_IS_UP(iface->linkstate); diff --git a/usr.sbin/ospf6d/parse.y b/usr.sbin/ospf6d/parse.y index 75ffb782d7b..2b2476d0606 100644 --- a/usr.sbin/ospf6d/parse.y +++ b/usr.sbin/ospf6d/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.37 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: parse.y,v 1.38 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby @@ -109,6 +109,7 @@ struct config_defaults ifacedefs; struct config_defaults *defs; struct area *conf_get_area(struct in_addr); +int conf_check_rdomain(u_int); typedef struct { union { @@ -121,7 +122,7 @@ typedef struct { %} -%token AREA INTERFACE ROUTERID FIBUPDATE REDISTRIBUTE RTLABEL +%token AREA INTERFACE ROUTERID FIBUPDATE REDISTRIBUTE RTLABEL RDOMAIN %token STUB ROUTER SPFDELAY SPFHOLDTIME EXTTAG %token METRIC PASSIVE %token HELLOINTERVAL TRANSMITDELAY @@ -232,6 +233,13 @@ conf_main : ROUTERID STRING { rtlabel_tag(rtlabel_name2id($2), $4); free($2); } + | RDOMAIN NUMBER { + if ($2 < 0 || $2 > RT_TABLEID_MAX) { + yyerror("invalid rdomain"); + YYERROR; + } + conf->rdomain = $2; + } | SPFDELAY NUMBER { if ($2 < MIN_SPF_DELAY || $2 > MAX_SPF_DELAY) { yyerror("spf-delay out of range " @@ -613,6 +621,7 @@ lookup(char *s) {"no", NO}, {"on", ON}, {"passive", PASSIVE}, + {"rdomain", RDOMAIN}, {"redistribute", REDISTRIBUTE}, {"retransmit-interval", RETRANSMITINTERVAL}, {"router", ROUTER}, @@ -1027,6 +1036,9 @@ parse_config(char *filename, int opts) } } + /* check that all interfaces belong to the configured rdomain */ + errors += conf_check_rdomain(conf->rdomain); + if (errors) { clear_config(conf); return (NULL); @@ -1130,6 +1142,25 @@ conf_get_area(struct in_addr id) return (a); } +int +conf_check_rdomain(u_int rdomain) +{ + struct area *a; + struct iface *i; + int errs = 0; + + LIST_FOREACH(a, &conf->area_list, entry) + LIST_FOREACH(i, &a->iface_list, entry) + if (i->rdomain != rdomain) { + logit(LOG_CRIT, + "interface %s not in rdomain %u", + i->name, rdomain); + errs++; + } + + return (errs); +} + void clear_config(struct ospfd_conf *xconf) { diff --git a/usr.sbin/ospf6d/printconf.c b/usr.sbin/ospf6d/printconf.c index a8e77ac962d..a67a072d484 100644 --- a/usr.sbin/ospf6d/printconf.c +++ b/usr.sbin/ospf6d/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.6 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: printconf.c,v 1.7 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby @@ -45,6 +45,9 @@ print_mainconf(struct ospfd_conf *conf) else printf("fib-update yes\n"); + if (conf->rdomain) + printf("rdomain %d\n", conf->rdomain); + if (conf->flags & OSPFD_FLAG_STUB_ROUTER) printf("stub router yes\n"); diff --git a/usr.sbin/ospf6d/rde.c b/usr.sbin/ospf6d/rde.c index eaeccace4f0..a057d32c957 100644 --- a/usr.sbin/ospf6d/rde.c +++ b/usr.sbin/ospf6d/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.78 2018/07/12 12:19:05 remi Exp $ */ +/* $OpenBSD: rde.c,v 1.79 2018/07/12 13:45:03 remi Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker @@ -735,7 +735,7 @@ rde_dispatch_parent(int fd, short event, void *bula) LINK_STATE_IS_UP(iface->linkstate); if_update(iface, ifp->mtu, ifp->flags, ifp->if_type, - ifp->linkstate, ifp->baudrate); + ifp->linkstate, ifp->baudrate, ifp->rdomain); /* Resend LSAs if interface state changes. */ link_ok = (iface->flags & IFF_UP) && -- 2.20.1