Hi tech,

this allows to adjust the priority of the routes that ospf6d inserts
into the kernel routing table.

It's basically the same change that I commited to ospfd today (without
reload support).

OK?

Remi



Index: kroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/kroute.c,v
retrieving revision 1.58
diff -u -p -r1.58 kroute.c
--- kroute.c    12 Jul 2018 13:45:03 -0000      1.58
+++ kroute.c    28 Dec 2018 19:58:05 -0000
@@ -45,6 +45,7 @@ struct {
        u_int32_t               rtseq;
        pid_t                   pid;
        int                     fib_sync;
+       u_int8_t                fib_prio;
        int                     fd;
        struct event            ev;
        u_int                   rdomain;
@@ -95,13 +96,14 @@ RB_PROTOTYPE(kroute_tree, kroute_node, e
 RB_GENERATE(kroute_tree, kroute_node, entry, kroute_compare)
 
 int
-kr_init(int fs, u_int rdomain)
+kr_init(int fs, u_int rdomain, u_int8_t fib_prio)
 {
        int             opt = 0, rcvbuf, default_rcvbuf;
        socklen_t       optlen;
 
        kr_state.fib_sync = fs;
        kr_state.rdomain = rdomain;
+       kr_state.fib_prio = fib_prio;
 
        if ((kr_state.fd = socket(AF_ROUTE,
            SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, AF_INET6)) == -1) {
@@ -218,7 +220,7 @@ kr_change_fib(struct kroute_node *kr, st
                kn->r.nexthop = kroute[i].nexthop;
                kn->r.scope = kroute[i].scope;
                kn->r.flags = kroute[i].flags | F_OSPFD_INSERTED;
-               kn->r.priority = RTP_OSPF;
+               kn->r.priority = kr_state.fib_prio;
                kn->r.ext_tag = kroute[i].ext_tag;
                rtlabel_unref(kn->r.rtlabel);   /* for RTM_CHANGE */
                kn->r.rtlabel = kroute[i].rtlabel;
@@ -242,7 +244,7 @@ kr_change(struct kroute *kroute, int krc
 
        kroute->rtlabel = rtlabel_tag2id(kroute->ext_tag);
 
-       kr = kroute_find(&kroute->prefix, kroute->prefixlen, RTP_OSPF);
+       kr = kroute_find(&kroute->prefix, kroute->prefixlen, kr_state.fib_prio);
        if (kr != NULL && kr->next == NULL && krcount == 1) {
                /*
                 * single path OSPF route.
@@ -272,7 +274,7 @@ kr_change(struct kroute *kroute, int krc
 int
 kr_delete_fib(struct kroute_node *kr)
 {
-       if (kr->r.priority != RTP_OSPF)
+       if (kr->r.priority != kr_state.fib_prio)
                log_warn("kr_delete_fib: %s/%d has wrong priority %d",
                    log_in6addr(&kr->r.prefix), kr->r.prefixlen,
                    kr->r.priority);
@@ -292,7 +294,7 @@ kr_delete(struct kroute *kroute)
        struct kroute_node      *kr, *nkr;
 
        if ((kr = kroute_find(&kroute->prefix, kroute->prefixlen,
-           RTP_OSPF)) == NULL)
+           kr_state.fib_prio)) == NULL)
                return (0);
 
        while (kr != NULL) {
@@ -324,7 +326,7 @@ kr_fib_couple(void)
        kr_state.fib_sync = 1;
 
        RB_FOREACH(kr, kroute_tree, &krt)
-               if (kr->r.priority == RTP_OSPF)
+               if (kr->r.priority == kr_state.fib_prio)
                        for (kn = kr; kn != NULL; kn = kn->next)
                                send_rtmsg(kr_state.fd, RTM_ADD, &kn->r);
 
@@ -341,7 +343,7 @@ kr_fib_decouple(void)
                return;
 
        RB_FOREACH(kr, kroute_tree, &krt)
-               if (kr->r.priority == RTP_OSPF)
+               if (kr->r.priority == kr_state.fib_prio)
                        for (kn = kr; kn != NULL; kn = kn->next)
                                send_rtmsg(kr_state.fd, RTM_DELETE, &kn->r);
 
@@ -1013,7 +1015,7 @@ send_rtmsg(int fd, int action, struct kr
        bzero(&hdr, sizeof(hdr));
        hdr.rtm_version = RTM_VERSION;
        hdr.rtm_type = action;
-       hdr.rtm_priority = RTP_OSPF;
+       hdr.rtm_priority = kr_state.fib_prio;
        hdr.rtm_tableid = kr_state.rdomain;     /* rtableid */
        if (action == RTM_CHANGE)
                hdr.rtm_fmask = RTF_REJECT|RTF_BLACKHOLE;
@@ -1241,7 +1243,7 @@ fetchtable(void)
                                break;
                        }
 
-               if (rtm->rtm_priority == RTP_OSPF)  {
+               if (rtm->rtm_priority == kr_state.fib_prio)  {
                        send_rtmsg(kr_state.fd, RTM_DELETE, &kr->r);
                        free(kr);
                } else {
Index: ospf6d.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.c,v
retrieving revision 1.40
diff -u -p -r1.40 ospf6d.c
--- ospf6d.c    30 Oct 2018 16:52:19 -0000      1.40
+++ ospf6d.c    28 Dec 2018 19:50:29 -0000
@@ -280,7 +280,7 @@ main(int argc, char *argv[])
                fatal("unveil");
 
        if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE),
-           ospfd_conf->rdomain) == -1)
+           ospfd_conf->rdomain, ospfd_conf->fib_priority) == -1)
                fatalx("kr_init failed");
 
        event_dispatch();
Index: ospf6d.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.conf.5,v
retrieving revision 1.17
diff -u -p -r1.17 ospf6d.conf.5
--- ospf6d.conf.5       12 Jul 2018 18:45:13 -0000      1.17
+++ ospf6d.conf.5       28 Dec 2018 19:30:06 -0000
@@ -83,6 +83,11 @@ interface.
 The only settings that can be set globally and not overruled are listed below.
 .Pp
 .Bl -tag -width Ds -compact
+.It Ic fib-priority Ar prio
+Set the routing priority to
+.Ar prio .
+The default is 32.
+.Pp
 .It Xo
 .Ic fib-update
 .Pq Ic yes Ns | Ns Ic no
Index: ospf6d.h
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.h,v
retrieving revision 1.38
diff -u -p -r1.38 ospf6d.h
--- ospf6d.h    1 Sep 2018 19:21:10 -0000       1.38
+++ ospf6d.h    28 Dec 2018 19:51:09 -0000
@@ -386,6 +386,7 @@ struct ospfd_conf {
        int                     flags;
        u_int8_t                border;
        u_int8_t                redistribute;
+       u_int8_t                fib_priority;
        u_int                   rdomain;
        char                    *csock;
 };
@@ -537,7 +538,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, u_int);
+int             kr_init(int, u_int, u_int8_t);
 int             kr_change(struct kroute *, int);
 int             kr_delete(struct kroute *);
 void            kr_shutdown(void);
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
retrieving revision 1.40
diff -u -p -r1.40 parse.y
--- parse.y     1 Nov 2018 00:18:44 -0000       1.40
+++ parse.y     28 Dec 2018 19:37:34 -0000
@@ -25,6 +25,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
+#include <net/route.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
@@ -122,8 +123,8 @@ typedef struct {
 
 %}
 
-%token AREA INTERFACE ROUTERID FIBUPDATE REDISTRIBUTE RTLABEL RDOMAIN
-%token STUB ROUTER SPFDELAY SPFHOLDTIME EXTTAG
+%token AREA INTERFACE ROUTERID FIBPRIORITY FIBUPDATE REDISTRIBUTE RTLABEL
+%token RDOMAIN STUB ROUTER SPFDELAY SPFHOLDTIME EXTTAG
 %token METRIC PASSIVE
 %token HELLOINTERVAL TRANSMITDELAY
 %token RETRANSMITINTERVAL ROUTERDEADTIME ROUTERPRIORITY
@@ -214,6 +215,13 @@ conf_main  : ROUTERID STRING {
                        }
                        free($2);
                }
+               | FIBPRIORITY NUMBER {
+                       if ($2 <= RTP_NONE || $2 > RTP_MAX) {
+                               yyerror("invalid fib-priority");
+                               YYERROR;
+                       }
+                       conf->fib_priority = $2;
+               }
                | FIBUPDATE yesno {
                        if ($2 == 0)
                                conf->flags |= OSPFD_FLAG_NO_FIB_UPDATE;
@@ -613,6 +621,7 @@ lookup(char *s)
                {"demote",              DEMOTE},
                {"depend",              DEPEND},
                {"external-tag",        EXTTAG},
+               {"fib-priority",        FIBPRIORITY},
                {"fib-update",          FIBUPDATE},
                {"hello-interval",      HELLOINTERVAL},
                {"include",             INCLUDE},
@@ -1008,6 +1017,7 @@ parse_config(char *filename, int opts)
        conf->spf_delay = DEFAULT_SPF_DELAY;
        conf->spf_hold_time = DEFAULT_SPF_HOLDTIME;
        conf->spf_state = SPF_IDLE;
+       conf->fib_priority = RTP_OSPF;
 
        if ((file = pushfile(filename,
            !(conf->opts & OSPFD_OPT_NOACTION))) == NULL) {
Index: printconf.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/printconf.c,v
retrieving revision 1.7
diff -u -p -r1.7 printconf.c
--- printconf.c 12 Jul 2018 13:45:03 -0000      1.7
+++ printconf.c 28 Dec 2018 19:40:46 -0000
@@ -45,6 +45,8 @@ print_mainconf(struct ospfd_conf *conf)
        else
                printf("fib-update yes\n");
 
+       printf("fib-priority %hhu\n", conf->fib_priority);
+
        if (conf->rdomain)
                printf("rdomain %d\n", conf->rdomain);
 

Reply via email to