The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=25a11d9805fc94ec6b01525b3902c89be87c735c
commit 25a11d9805fc94ec6b01525b3902c89be87c735c Author: Gleb Smirnoff <[email protected]> AuthorDate: 2026-01-23 22:17:16 +0000 Commit: Gleb Smirnoff <[email protected]> CommitDate: 2026-01-23 22:17:16 +0000 netinet6: use in6_ifmtu() instead of IN6_LINKMTU() macro There should be no functional change. If there are any performance concerns with a function call, with the future changes, that would move ND6 bits into in6_ifextra, this function would be easily inline-able. Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D54724 --- sys/netinet6/in6.c | 9 +++++++-- sys/netinet6/in6_rmx.c | 6 ++---- sys/netinet6/in6_var.h | 2 +- sys/netinet6/ip6_forward.c | 4 ++-- sys/netinet6/ip6_mroute.c | 2 +- sys/netinet6/ip6_output.c | 4 ++-- sys/netinet6/nd6.c | 2 +- sys/netinet6/nd6.h | 5 ----- sys/netpfil/pf/pf.c | 4 ++-- 9 files changed, 18 insertions(+), 20 deletions(-) diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 40bc286f3ab2..07f1198cd283 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -2627,9 +2627,14 @@ EVENTHANDLER_DEFINE(ifnet_arrival_event, in6_ifarrival, NULL, EVENTHANDLER_PRI_ANY); uint32_t -in6_ifmtu(struct ifnet *ifp) +in6_ifmtu(const struct ifnet *ifp) { - return (IN6_LINKMTU(ifp)); + struct nd_ifinfo *ndi = ND_IFINFO(ifp); + + return ( + (ndi->linkmtu > 0 && ndi->linkmtu < ifp->if_mtu) ? ndi->linkmtu : + ((ndi->maxmtu > 0 && ndi->maxmtu < ifp->if_mtu) ? ndi->maxmtu : + ifp->if_mtu)); } /* diff --git a/sys/netinet6/in6_rmx.c b/sys/netinet6/in6_rmx.c index d1c121115b60..35c6cd5ba5f1 100644 --- a/sys/netinet6/in6_rmx.c +++ b/sys/netinet6/in6_rmx.c @@ -114,10 +114,8 @@ rib6_augment_nh(u_int fibnum, struct nhop_object *nh) * inherit interface MTU if not set or * check if MTU is too large. */ - if (nh->nh_mtu == 0) { - nh->nh_mtu = IN6_LINKMTU(nh->nh_ifp); - } else if (nh->nh_mtu > IN6_LINKMTU(nh->nh_ifp)) - nh->nh_mtu = IN6_LINKMTU(nh->nh_ifp); + if (nh->nh_mtu == 0 || nh->nh_mtu > in6_ifmtu(nh->nh_ifp)) + nh->nh_mtu = in6_ifmtu(nh->nh_ifp); /* Set nexthop type */ if (nhop_get_type(nh) == 0) { diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h index 1e0b6c0ed29e..f22b75ce71db 100644 --- a/sys/netinet6/in6_var.h +++ b/sys/netinet6/in6_var.h @@ -861,7 +861,7 @@ void in6_purgeaddr(struct ifaddr *); void in6_purgeifaddr(struct in6_ifaddr *); int in6if_do_dad(struct ifnet *); void in6_savemkludge(struct in6_ifaddr *); -uint32_t in6_ifmtu(struct ifnet *); +uint32_t in6_ifmtu(const struct ifnet *); struct rib_head *in6_inithead(uint32_t fibnum); void in6_detachhead(struct rib_head *rh); int in6_if2idlen(struct ifnet *); diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index 9823366b0156..0ebb51fd80f0 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -384,11 +384,11 @@ again: pass: /* See if the size was changed by the packet filter. */ /* TODO: change to nh->nh_mtu */ - if (m->m_pkthdr.len > IN6_LINKMTU(nh->nh_ifp)) { + if (m->m_pkthdr.len > in6_ifmtu(nh->nh_ifp)) { in6_ifstat_inc(nh->nh_ifp, ifs6_in_toobig); if (mcopy) icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0, - IN6_LINKMTU(nh->nh_ifp)); + in6_ifmtu(nh->nh_ifp)); goto bad; } diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 4473d3931af8..46981aff1025 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1582,7 +1582,7 @@ phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m) * Put the packet into the sending queue of the outgoing interface * if it would fit in the MTU of the interface. */ - linkmtu = IN6_LINKMTU(ifp); + linkmtu = in6_ifmtu(ifp); if (mb_copy->m_pkthdr.len <= linkmtu || linkmtu < IPV6_MMTU) { struct sockaddr_in6 dst6; diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index d61bc983cc12..25fe8f347e35 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1147,7 +1147,7 @@ passout: dontfrag = 1; else dontfrag = 0; - if (dontfrag && tlen > IN6_LINKMTU(ifp) && !tso) { /* Case 2-b. */ + if (dontfrag && tlen > in6_ifmtu(ifp) && !tso) { /* Case 2-b. */ /* * If the DONTFRAG option is specified, we cannot send the * packet when the data length is larger than the MTU of the @@ -1561,7 +1561,7 @@ ip6_calcmtu(struct ifnet *ifp, const struct in6_addr *dst, u_long rt_mtu, } if (mtu == 0) - mtu = IN6_LINKMTU(ifp); + mtu = in6_ifmtu(ifp); *mtup = mtu; } diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 04ce9bf6dd55..2e59f96a95c3 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1662,7 +1662,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp) /* 0 means 'unspecified' */ if (ND.linkmtu != 0) { if (ND.linkmtu < IPV6_MMTU || - ND.linkmtu > IN6_LINKMTU(ifp)) { + ND.linkmtu > in6_ifmtu(ifp)) { error = EINVAL; break; } diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index 28de6e2ae153..c500f236d6ff 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -83,11 +83,6 @@ struct llentry; #ifdef _KERNEL #define ND_IFINFO(ifp) ((if_getinet6(ifp))->nd_ifinfo) -#define IN6_LINKMTU(ifp) \ - ((ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) \ - ? ND_IFINFO(ifp)->linkmtu \ - : ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) \ - ? ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)) #endif struct in6_nbrinfo { diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 13e2f5bb77f2..bec6911795bd 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -11708,9 +11708,9 @@ pf_test(sa_family_t af, int dir, int pflags, struct ifnet *ifp, struct mbuf **m0 * it here, before we do any NAT. */ if (af == AF_INET6 && dir == PF_OUT && pflags & PFIL_FWD && - IN6_LINKMTU(ifp) < pf_max_frag_size(*m0)) { + in6_ifmtu(ifp) < pf_max_frag_size(*m0)) { PF_RULES_RUNLOCK(); - icmp6_error(*m0, ICMP6_PACKET_TOO_BIG, 0, IN6_LINKMTU(ifp)); + icmp6_error(*m0, ICMP6_PACKET_TOO_BIG, 0, in6_ifmtu(ifp)); *m0 = NULL; return (PF_DROP); }
