aboutsummaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2020-10-04 13:24:58 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2020-10-04 13:24:58 +0000
commit1b95005e950b8f683aca88056a15a7252ca919d5 (patch)
treefb0de2f6973a1b76bdd5e6f17194ab106c55d1b6 /sys/net
parentdf01340989f4fc2b1d6cded4729a6c1b4d9ff40b (diff)
downloadsrc-1b95005e950b8f683aca88056a15a7252ca919d5.tar.gz
src-1b95005e950b8f683aca88056a15a7252ca919d5.zip
Fix route flags update during RTM_CHANGE.
Nexthop lookup was not consireding rt_flags when doing structure comparison, which lead to an original nexthop selection when changing flags. Fix the case by adding rt_flags field into comparison and rearranging nhop_priv fields to allow for efficient matching. Fix `route change X/Y flags` case - recent changes disallowed specifying RTF_GATEWAY flag without actual gateway. It turns out, route(8) fills in RTF_GATEWAY by default, unless -interface flag is specified. Fix regression by clearing RTF_GATEWAY flag instead of failing. Fix route flag reporting in RTM_CHANGE messages by explicitly updating rtm_flags after operation competion. Add IPv4/IPv6 tests for flag-only route changes.
Notes
Notes: svn path=/head/; revision=366424
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/route/nhop_ctl.c3
-rw-r--r--sys/net/route/nhop_var.h9
-rw-r--r--sys/net/route/route_ctl.c11
-rw-r--r--sys/net/rtsock.c1
4 files changed, 18 insertions, 6 deletions
diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c
index 150ae5c4be58..fe30b0289ff1 100644
--- a/sys/net/route/nhop_ctl.c
+++ b/sys/net/route/nhop_ctl.c
@@ -164,8 +164,7 @@ cmp_priv(const struct nhop_priv *_one, const struct nhop_priv *_two)
if (memcmp(_one->nh, _two->nh, NHOP_END_CMP) != 0)
return (0);
- if ((_one->nh_type != _two->nh_type) ||
- (_one->nh_family != _two->nh_family))
+ if (memcmp(_one, _two, NH_PRIV_END_CMP) != 0)
return (0);
return (1);
diff --git a/sys/net/route/nhop_var.h b/sys/net/route/nhop_var.h
index 6e1aba670e3c..4ce82dd4a968 100644
--- a/sys/net/route/nhop_var.h
+++ b/sys/net/route/nhop_var.h
@@ -74,13 +74,16 @@ struct nh_control {
/* Control plane-only nhop data */
struct nhop_object;
struct nhop_priv {
- uint32_t nh_idx; /* nexthop index */
+ /* nhop lookup comparison start */
uint8_t nh_family; /* address family of the lookup */
+ uint8_t spare;
uint16_t nh_type; /* nexthop type */
+ uint32_t rt_flags; /* routing flags for the control plane */
+ /* nhop lookup comparison end */
+ uint32_t nh_idx; /* nexthop index */
void *cb_func; /* function handling additional rewrite caps */
u_int nh_refcnt; /* number of references, refcount(9) */
u_int nh_linked; /* refcount(9), == 2 if linked to the list */
- int rt_flags; /* routing flags for the control plane */
struct nhop_object *nh; /* backreference to the dataplane nhop */
struct nh_control *nh_control; /* backreference to the rnh */
struct nhop_priv *nh_next; /* hash table membership */
@@ -88,6 +91,8 @@ struct nhop_priv {
struct epoch_context nh_epoch_ctx; /* epoch data for nhop */
};
+#define NH_PRIV_END_CMP (__offsetof(struct nhop_priv, nh_idx))
+
#define NH_IS_PINNED(_nh) ((!NH_IS_NHGRP(_nh)) && \
((_nh)->nh_priv->rt_flags & RTF_PINNED))
diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index 6ee4931680f2..7a4d5003efb6 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -733,8 +733,15 @@ rib_change_route(uint32_t fibnum, struct rt_addrinfo *info,
/* Check if updated gateway exists */
if ((info->rti_flags & RTF_GATEWAY) &&
- (info->rti_info[RTAX_GATEWAY] == NULL))
- return (EINVAL);
+ (info->rti_info[RTAX_GATEWAY] == NULL)) {
+
+ /*
+ * route(8) adds RTF_GATEWAY flag if -interface is not set.
+ * Remove RTF_GATEWAY to enforce consistency and maintain
+ * compatibility..
+ */
+ info->rti_flags &= ~RTF_GATEWAY;
+ }
/*
* route change is done in multiple steps, with dropping and
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index cdbe0d5b2118..83539de55b58 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -965,6 +965,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
#endif
nh = rc.rc_nh_new;
rtm->rtm_index = nh->nh_ifp->if_index;
+ rtm->rtm_flags = rc.rc_rt->rte_flags | nhop_get_rtflags(nh);
}
break;