Page MenuHomeFreeBSD

D61385.1796209343.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D61385.1796209343.diff

diff --git a/sys/net/route.h b/sys/net/route.h
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -72,6 +72,7 @@
#define RT_MAY_LOOP (1 << RT_MAY_LOOP_BIT) /* 0x0008 */
#define RT_HAS_HEADER (1 << RT_HAS_HEADER_BIT) /* 0x0010 */
+#define RT_NH_NOREF 0x0002 /* Do not reference ro_nh */
#define RT_REJECT 0x0020 /* Destination is reject */
#define RT_BLACKHOLE 0x0040 /* Destination is blackhole */
#define RT_HAS_GW 0x0080 /* Destination has GW */
@@ -370,9 +371,19 @@
#ifdef _KERNEL
+/*
+ * RT_NH_NOREF is set by the owner of a route, before the route is first
+ * used, and is never cleared. The nexthop of such a route is not
+ * referenced: it is looked up without NHR_REF and is dropped without being
+ * released. This is for a route on the stack that is only used in one
+ * network epoch section, never for a route that is cached, such as the
+ * route of a PCB. Only ip_output() honors the flag when it stores a
+ * nexthop; ip6_output() does not.
+ */
#define RO_NHFREE(_ro) do { \
if ((_ro)->ro_nh) { \
- NH_FREE((_ro)->ro_nh); \
+ if (((_ro)->ro_flags & RT_NH_NOREF) == 0) \
+ NH_FREE((_ro)->ro_nh); \
(_ro)->ro_nh = NULL; \
} \
} while (0)
@@ -382,10 +393,7 @@
LLE_FREE((ro)->ro_lle); \
(ro)->ro_lle = NULL; \
} \
- if ((ro)->ro_nh != NULL) { \
- NH_FREE((ro)->ro_nh); \
- (ro)->ro_nh = NULL; \
- } \
+ RO_NHFREE(ro); \
} while (0)
#define RO_GET_FAMILY(ro, dst) ((ro) != NULL && \
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -964,17 +964,23 @@
sin->sin_len = sizeof(*sin);
sin->sin_addr = ip->ip_dst;
flowid = m->m_pkthdr.flowid;
- ro.ro_nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_REF, flowid);
+ /*
+ * The nexthop is not referenced: nexthops are destroyed through
+ * NET_EPOCH_CALL(), so this one stays valid until we return, and
+ * the route does not outlive this function. With RT_NH_NOREF
+ * ip_output() does not reference or release a nexthop of this
+ * route either.
+ */
+ ro.ro_flags = RT_NH_NOREF;
+ ro.ro_nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_NONE, flowid);
if (ro.ro_nh != NULL) {
if (ro.ro_nh->nh_flags & (NHF_BLACKHOLE | NHF_BROADCAST)) {
IPSTAT_INC(ips_cantforward);
m_freem(m);
- NH_FREE(ro.ro_nh);
return;
}
if (ro.ro_nh->nh_flags & NHF_REJECT) {
IPSTAT_INC(ips_cantforward);
- NH_FREE(ro.ro_nh);
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
return;
}
@@ -1021,7 +1027,6 @@
if (IPSEC_ENABLED(ipv4)) {
if ((error = IPSEC_FORWARD(ipv4, m)) != 0) {
/* mbuf consumed by IPsec */
- RO_NHFREE(&ro);
m_freem(mcopy);
if (error != EINPROGRESS)
IPSTAT_INC(ips_cantforward);
@@ -1069,7 +1074,6 @@
if (error == EMSGSIZE && ro.ro_nh)
mtu = ro.ro_nh->nh_mtu;
- RO_NHFREE(&ro);
if (error)
IPSTAT_INC(ips_cantforward);
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -476,6 +476,7 @@
uint32_t flowid;
flowid = m->m_pkthdr.flowid;
ro->ro_nh = fib4_lookup(fibnum, dst->sin_addr, 0,
+ (ro->ro_flags & RT_NH_NOREF) != 0 ? NHR_NONE :
NHR_REF, flowid);
if (ro->ro_nh == NULL || (!NH_IS_VALID(ro->ro_nh))) {

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 2, 11:02 AM (12 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42141214
Default Alt Text
D61385.1796209343.diff (3 KB)

Event Timeline