I agree with this.
ok benno@
Claudio Jeker(cje...@diehard.n-r-g.com) on 2020.12.23 15:37:02 +0100:
> In bgpd statements like
> network inet static
> or
> network rtlabel "exportme"
> will skip routes that use 127.0.0.1 as nexthop. This makes sense for
> network connected and network static but for rtlabel and even priority
> based selection this makes less sense.
>
> Especially using rtlabel to export routes should give the admin also the
> option to export reject or blackhole routes (which have their nexthop set
> to 127.0.0.1).
>
> This diff does this change but still skips networks like 224/4 for network
> inet static. I think this is a decent compromise.
> --
> :wq Claudio
>
> Index: kroute.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/kroute.c,v
> retrieving revision 1.239
> diff -u -p -r1.239 kroute.c
> --- kroute.c 1 Oct 2019 08:57:48 - 1.239
> +++ kroute.c 4 Dec 2020 11:31:09 -
> @@ -110,7 +110,7 @@ int kr6_delete(struct ktable *, struct k
> int krVPN4_delete(struct ktable *, struct kroute_full *, u_int8_t);
> int krVPN6_delete(struct ktable *, struct kroute_full *, u_int8_t);
> void kr_net_delete(struct network *);
> -int kr_net_match(struct ktable *, struct network_config *, u_int16_t);
> +int kr_net_match(struct ktable *, struct network_config *, u_int16_t, int);
> struct network *kr_net_find(struct ktable *, struct network *);
> void kr_net_clear(struct ktable *);
> void kr_redistribute(int, struct ktable *, struct kroute *);
> @@ -1318,7 +1318,8 @@ kr_net_redist_del(struct ktable *kt, str
> }
>
> int
> -kr_net_match(struct ktable *kt, struct network_config *net, u_int16_t flags)
> +kr_net_match(struct ktable *kt, struct network_config *net, u_int16_t flags,
> +int loopback)
> {
> struct network *xn;
>
> @@ -1330,10 +1331,16 @@ kr_net_match(struct ktable *kt, struct n
> /* static match already redistributed */
> continue;
> case NETWORK_STATIC:
> + /* Skip networks with nexthop on loopback. */
> + if (loopback)
> + continue;
> if (flags & F_STATIC)
> break;
> continue;
> case NETWORK_CONNECTED:
> + /* Skip networks with nexthop on loopback. */
> + if (loopback)
> + continue;
> if (flags & F_CONNECTED)
> break;
> continue;
> @@ -1419,6 +1426,7 @@ kr_redistribute(int type, struct ktable
> {
> struct network_confignet;
> u_int32_ta;
> + int loflag = 0;
>
> bzero(, sizeof(net));
> net.prefix.aid = AID_INET;
> @@ -1449,9 +1457,9 @@ kr_redistribute(int type, struct ktable
> (a >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
> return;
>
> - /* Consider networks with nexthop loopback as not redistributable. */
> + /* Check if the nexthop is the loopback addr. */
> if (kr->nexthop.s_addr == htonl(INADDR_LOOPBACK))
> - return;
> + loflag = 1;
>
> /*
>* never allow 0.0.0.0/0 the default route can only be redistributed
> @@ -1460,7 +1468,7 @@ kr_redistribute(int type, struct ktable
> if (kr->prefix.s_addr == INADDR_ANY && kr->prefixlen == 0)
> return;
>
> - if (kr_net_match(kt, , kr->flags) == 0)
> + if (kr_net_match(kt, , kr->flags, loflag) == 0)
> /* no longer matches, if still present remove it */
> kr_net_redist_del(kt, , 1);
> }
> @@ -1468,7 +1476,8 @@ kr_redistribute(int type, struct ktable
> void
> kr_redistribute6(int type, struct ktable *kt, struct kroute6 *kr6)
> {
> - struct network_confignet;
> + struct network_config net;
> + int loflag = 0;
>
> bzero(, sizeof(net));
> net.prefix.aid = AID_INET6;
> @@ -1503,11 +1512,9 @@ kr_redistribute6(int type, struct ktable
> IN6_IS_ADDR_V4COMPAT(>prefix))
> return;
>
> - /*
> - * Consider networks with nexthop loopback as not redistributable.
> - */
> + /* Check if the nexthop is the loopback addr. */
> if (IN6_IS_ADDR_LOOPBACK(>nexthop))
> - return;
> + loflag = 1;
>
> /*
>* never allow ::/0 the default route can only be redistributed
> @@ -1517,7 +1524,7 @@ kr_redistribute6(int type, struct ktable
> memcmp(>prefix, _any, sizeof(struct in6_addr)) == 0)
> return;
>
> - if (kr_net_match(kt, , kr6->flags) == 0)
> + if (kr_net_match(kt, , kr6->flags, loflag) == 0)
> /* no longer matches, if still present remove it */
> kr_net_redist_del(kt, , 1);
> }
>