Skip to content

Commit b6671a7

Browse files
committed
BSD: Reject routes are not cloned/connected routes
Likewise, if we change from a reject to a non reject route we need to remove it rather than changing it as some BSD kernels preserve the RTF_GATEWAY flag.
1 parent 49d2181 commit b6671a7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/if-bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ if_route(unsigned char cmd, const struct rt *rt)
761761
rtm->rtm_flags |= RTF_HOST;
762762
/* Network routes are cloning or connected if supported.
763763
* All other routes are static. */
764-
if (gateway_unspec) {
764+
if (gateway_unspec && !(rtm->rtm_flags & RTF_REJECT)) {
765765
#ifdef RTF_CLONING
766766
rtm->rtm_flags |= RTF_CLONING;
767767
#endif

src/route.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ rt_add(rb_tree_t *kroutes, struct rt *nrt, struct rt *ort)
597597
sa_cmp(&krt->rt_dest, &nrt->rt_dest) == 0 &&
598598
rt_cmp_netmask(krt, nrt) == 0 &&
599599
sa_cmp(&krt->rt_gateway, &nrt->rt_gateway) == 0 &&
600-
rt_cmp_mtu(krt, nrt) == 0)
600+
(nrt->rt_ifp->flags & IFF_LOOPBACK || rt_cmp_mtu(krt, nrt) == 0))
601601
{
602602
#ifdef HAVE_ROUTE_LIFETIME
603603
if (rt_cmp_lifetime(krt, nrt) == 0) {
@@ -622,6 +622,10 @@ rt_add(rb_tree_t *kroutes, struct rt *nrt, struct rt *ort)
622622
if (change && krt != NULL && krt->rt_flags & RTF_CLONING)
623623
change = false;
624624
#endif
625+
/* Reject routes have a gateway, non reject routes don't.
626+
* BSD kernels at least preserve RTF_GATEWAY so we need to punt it. */
627+
if (change && krt->rt_flags & RTF_REJECT && !(nrt->rt_flags & RTF_REJECT))
628+
change = false;
625629

626630
if (change) {
627631
if (if_route(RTM_CHANGE, nrt) != -1) {

0 commit comments

Comments
 (0)