From cfa8497dc94a8056e121f74a39c251a7b334eac9 Mon Sep 17 00:00:00 2001 From: bluhm Date: Sun, 21 Aug 2022 14:15:55 +0000 Subject: [PATCH] Remove ip_local() and ip6_local(). After moving the IPv4 fragment reassembly and IPv6 hob-by-hob header chain processing out of ip_local() and ip6_local(), they are almost empty stubs. The check for local deliver loop in ip_ours() and ip6_ours() is sufficient. Recover mbuf offset and next protocol directly in ipintr() and ip6intr(). OK mvs@ --- sys/netinet/ip_input.c | 38 +++++++------------------- sys/netinet6/ip6_input.c | 59 +++++++++++++++------------------------- 2 files changed, 32 insertions(+), 65 deletions(-) diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 1a4e2d8d90e..affe27038c6 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.379 2022/08/15 16:15:36 bluhm Exp $ */ +/* $OpenBSD: ip_input.c,v 1.380 2022/08/21 14:15:55 bluhm Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -138,7 +138,6 @@ static struct mbuf_queue ipsendraw_mq; extern struct niqueue arpinq; int ip_ours(struct mbuf **, int *, int, int); -int ip_local(struct mbuf **, int *, int, int); int ip_dooptions(struct mbuf *, struct ifnet *); int in_ouraddr(struct mbuf *, struct ifnet *, struct rtentry **); @@ -245,7 +244,7 @@ ip_ours(struct mbuf **mp, int *offp, int nxt, int af) /* We are already in a IPv4/IPv6 local deliver loop. */ if (af != AF_UNSPEC) - return ip_local(mp, offp, nxt, af); + return nxt; niq_enqueue(&ipintrq, *mp); *mp = NULL; @@ -260,15 +259,20 @@ void ipintr(void) { struct mbuf *m; - int off, nxt; while ((m = niq_dequeue(&ipintrq)) != NULL) { + struct ip *ip; + int off, nxt; + #ifdef DIAGNOSTIC if ((m->m_flags & M_PKTHDR) == 0) panic("ipintr no HDR"); #endif - off = 0; - nxt = ip_local(&m, &off, IPPROTO_IPV4, AF_UNSPEC); + ip = mtod(m, struct ip *); + off = ip->ip_hl << 2; + nxt = ip->ip_p; + + nxt = ip_deliver(&m, &off, nxt, AF_INET); KASSERT(nxt == IPPROTO_DONE); } } @@ -552,28 +556,6 @@ ip_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) return nxt; } -/* - * IPv4 local-delivery routine. - * - * If fragmented try to reassemble. Pass to next level. - */ -int -ip_local(struct mbuf **mp, int *offp, int nxt, int af) -{ - if (*offp == 0) { - struct ip *ip; - - ip = mtod(*mp, struct ip *); - *offp = ip->ip_hl << 2; - nxt = ip->ip_p; - } - - /* Check whether we are already in a IPv4/IPv6 local deliver loop. */ - if (af == AF_UNSPEC) - nxt = ip_deliver(mp, offp, nxt, AF_INET); - return nxt; -} - int ip_fragcheck(struct mbuf **mp, int *offp) { diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 6e70de63143..2238a6cb6cd 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.253 2022/08/15 16:15:37 bluhm Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.254 2022/08/21 14:15:55 bluhm Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -120,7 +120,6 @@ struct cpumem *ip6counters; uint8_t ip6_soiikey[IP6_SOIIKEY_LEN]; int ip6_ours(struct mbuf **, int *, int, int); -int ip6_local(struct mbuf **, int *, int, int); int ip6_check_rh0hdr(struct mbuf *, int *); int ip6_hbhchcheck(struct mbuf **, int *, int *); int ip6_hopopts_input(struct mbuf **, int *, u_int32_t *, u_int32_t *); @@ -189,7 +188,7 @@ ip6_ours(struct mbuf **mp, int *offp, int nxt, int af) /* We are already in a IPv4/IPv6 local deliver loop. */ if (af != AF_UNSPEC) - return ip6_local(mp, offp, nxt, af); + return nxt; /* save values for later, use after dequeue */ if (*offp != sizeof(struct ip6_hdr)) { @@ -224,15 +223,32 @@ void ip6intr(void) { struct mbuf *m; - int off, nxt; while ((m = niq_dequeue(&ip6intrq)) != NULL) { + struct m_tag *mtag; + int off, nxt; + #ifdef DIAGNOSTIC if ((m->m_flags & M_PKTHDR) == 0) panic("ip6intr no HDR"); #endif - off = 0; - nxt = ip6_local(&m, &off, IPPROTO_IPV6, AF_UNSPEC); + mtag = m_tag_find(m, PACKET_TAG_IP6_OFFNXT, NULL); + if (mtag != NULL) { + struct ip6_offnxt *ion; + + ion = (struct ip6_offnxt *)(mtag + 1); + off = ion->ion_off; + nxt = ion->ion_nxt; + + m_tag_delete(m, mtag); + } else { + struct ip6_hdr *ip6; + + ip6 = mtod(m, struct ip6_hdr *); + off = sizeof(struct ip6_hdr); + nxt = ip6->ip6_nxt; + } + nxt = ip_deliver(&m, &off, nxt, AF_INET6); KASSERT(nxt == IPPROTO_DONE); } } @@ -613,37 +629,6 @@ ip6_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) return nxt; } -int -ip6_local(struct mbuf **mp, int *offp, int nxt, int af) -{ - if (*offp == 0) { - struct m_tag *mtag; - - mtag = m_tag_find(*mp, PACKET_TAG_IP6_OFFNXT, NULL); - if (mtag != NULL) { - struct ip6_offnxt *ion; - - ion = (struct ip6_offnxt *)(mtag + 1); - *offp = ion->ion_off; - nxt = ion->ion_nxt; - - m_tag_delete(*mp, mtag); - } else { - struct ip6_hdr *ip6; - - ip6 = mtod(*mp, struct ip6_hdr *); - *offp = sizeof(struct ip6_hdr); - nxt = ip6->ip6_nxt; - - } - } - - /* Check whether we are already in a IPv4/IPv6 local deliver loop. */ - if (af == AF_UNSPEC) - nxt = ip_deliver(mp, offp, nxt, AF_INET6); - return nxt; -} - /* On error free mbuf and return IPPROTO_DONE. */ int ip6_hbhchcheck(struct mbuf **mp, int *offp, int *oursp) -- 2.20.1