Hi,
This adds rdomain support to ospf6d. It works the same as in ospfd.
OK?
Remi
Index: ospf6ctl/ospf6ctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
retrieving revision 1.48
diff -u -p -r1.48 ospf6ctl.c
--- ospf6ctl/ospf6ctl.c 6 Jun 2018 05:51:43 -0000 1.48
+++ ospf6ctl/ospf6ctl.c 11 Jul 2018 14:29:49 -0000
@@ -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':
Index: ospf6d/interface.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/interface.c,v
retrieving revision 1.23
diff -u -p -r1.23 interface.c
--- ospf6d/interface.c 11 Mar 2018 13:17:35 -0000 1.23
+++ ospf6d/interface.c 11 Jul 2018 18:02:42 -0000
@@ -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)
Index: ospf6d/kroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.56
diff -u -p -r1.56 kroute.c
--- ospf6d/kroute.c 10 Jul 2018 12:17:38 -0000 1.56
+++ ospf6d/kroute.c 11 Jul 2018 14:10:26 -0000
@@ -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, e
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, s
}
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);
}
@@ -1016,6 +1018,7 @@ send_rtmsg(int fd, int action, struct kr
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
@@ -1147,7 +1150,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");
@@ -1381,7 +1384,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 */
Index: ospf6d/ospf6d.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.36
diff -u -p -r1.36 ospf6d.c
--- ospf6d/ospf6d.c 9 Jul 2018 13:19:46 -0000 1.36
+++ ospf6d/ospf6d.c 11 Jul 2018 14:24:49 -0000
@@ -113,11 +113,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]);
@@ -181,6 +180,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) {
@@ -259,7 +265,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();
Index: ospf6d/ospf6d.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.conf.5,v
retrieving revision 1.14
diff -u -p -r1.14 ospf6d.conf.5
--- ospf6d/ospf6d.conf.5 18 Jun 2018 06:04:25 -0000 1.14
+++ ospf6d/ospf6d.conf.5 11 Jul 2018 13:50:38 -0000
@@ -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
Index: ospf6d/ospf6d.h
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.35
diff -u -p -r1.35 ospf6d.h
--- ospf6d/ospf6d.h 8 Feb 2018 00:18:20 -0000 1.35
+++ ospf6d/ospf6d.h 11 Jul 2018 14:04:10 -0000
@@ -311,6 +311,7 @@ struct iface {
u_int32_t ls_ack_cnt;
time_t uptime;
unsigned int ifindex;
+ u_int rdomain;
int fd;
int state;
int mtu;
@@ -381,6 +382,7 @@ struct ospfd_conf {
int flags;
u_int8_t border;
u_int8_t redistribute;
+ int rdomain;
char *csock;
};
@@ -522,7 +524,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);
@@ -531,7 +533,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);
Index: ospf6d/ospfe.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.52
diff -u -p -r1.52 ospfe.c
--- ospf6d/ospfe.c 10 Jul 2018 21:21:56 -0000 1.52
+++ ospf6d/ospfe.c 11 Jul 2018 13:45:12 -0000
@@ -306,7 +306,7 @@ ospfe_dispatch_main(int fd, short event,
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);
Index: ospf6d/parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
retrieving revision 1.34
diff -u -p -r1.34 parse.y
--- ospf6d/parse.y 9 Jul 2018 12:05:11 -0000 1.34
+++ ospf6d/parse.y 11 Jul 2018 18:30:46 -0000
@@ -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
@@ -231,6 +232,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 "
@@ -571,6 +579,7 @@ lookup(char *s)
{"metric", METRIC},
{"no", NO},
{"passive", PASSIVE},
+ {"rdomain", RDOMAIN},
{"redistribute", REDISTRIBUTE},
{"retransmit-interval", RETRANSMITINTERVAL},
{"router", ROUTER},
@@ -985,6 +994,9 @@ parse_config(char *filename, int opts)
}
}
+ /* check that all interfaces belong to the configured rdomain */
+ errors += conf_check_rdomain(conf->rdomain);
+
/* free global config defaults */
if (errors) {
clear_config(conf);
@@ -1087,6 +1099,25 @@ conf_get_area(struct in_addr id)
a->id.s_addr = id.s_addr;
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
Index: ospf6d/printconf.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/printconf.c,v
retrieving revision 1.5
diff -u -p -r1.5 printconf.c
--- ospf6d/printconf.c 24 Dec 2016 14:58:55 -0000 1.5
+++ ospf6d/printconf.c 11 Jul 2018 12:33:32 -0000
@@ -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");
Index: ospf6d/rde.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/rde.c,v
retrieving revision 1.77
diff -u -p -r1.77 rde.c
--- ospf6d/rde.c 10 Jul 2018 21:21:56 -0000 1.77
+++ ospf6d/rde.c 11 Jul 2018 13:45:46 -0000
@@ -717,7 +717,7 @@ rde_dispatch_parent(int fd, short event,
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) &&