-/* $OpenBSD: ip_input.c,v 1.390 2024/02/22 14:25:58 bluhm Exp $ */
+/* $OpenBSD: ip_input.c,v 1.391 2024/02/28 10:57:20 bluhm Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
struct rtentry *rt = NULL;
struct ip *ip;
int hlen;
- in_addr_t pfrdr = 0;
+#if NPF > 0
+ struct in_addr odst;
+#endif
+ int pfrdr = 0;
KASSERT(*offp == 0);
/*
* Packet filter
*/
- pfrdr = ip->ip_dst.s_addr;
+ odst = ip->ip_dst;
if (pf_test(AF_INET, PF_IN, ifp, mp) != PF_PASS)
goto bad;
m = *mp;
goto bad;
ip = mtod(m, struct ip *);
- pfrdr = (pfrdr != ip->ip_dst.s_addr);
+ pfrdr = odst.s_addr != ip->ip_dst.s_addr;
#endif
hlen = ip->ip_hl << 2;
void
ip_forward(struct mbuf *m, struct ifnet *ifp, struct rtentry *rt, int srcrt)
{
- struct mbuf mfake, *mcopy = NULL;
+ struct mbuf mfake, *mcopy;
struct ip *ip = mtod(m, struct ip *);
struct route ro;
int error = 0, type = 0, code = 0, destmtu = 0, fake = 0, len;
if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) {
ipstat_inc(ips_cantforward);
m_freem(m);
- goto freecopy;
+ goto done;
}
if (ip->ip_ttl <= IPTTLDEC) {
icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
- goto freecopy;
+ goto done;
}
ro.ro_rt = NULL;
if (type)
ipstat_inc(ips_redirectsent);
else
- goto freecopy;
+ goto done;
}
if (!fake)
- goto freecopy;
+ goto done;
switch (error) {
case 0: /* forwarded, but need redirect */
}
ipstat_inc(ips_cantfrag);
if (destmtu == 0)
- goto freecopy;
+ goto done;
break;
case EACCES:
* pf(4) blocked the packet. There is no need to send an ICMP
* packet back since pf(4) takes care of it.
*/
- goto freecopy;
+ goto done;
case ENOBUFS:
/*
* source quench could be a big problem under DoS attacks,
* or the underlying interface is rate-limited.
*/
- goto freecopy;
+ goto done;
case ENETUNREACH: /* shouldn't happen, checked above */
case EHOSTUNREACH:
break;
}
mcopy = m_copym(&mfake, 0, len, M_DONTWAIT);
- if (mcopy)
+ if (mcopy != NULL)
icmp_error(mcopy, type, code, dest, destmtu);
-freecopy:
+ done:
if (fake)
m_tag_delete_chain(&mfake);
rtfree(rt);
-/* $OpenBSD: ip6_forward.c,v 1.115 2024/02/22 14:25:58 bluhm Exp $ */
+/* $OpenBSD: ip6_forward.c,v 1.116 2024/02/28 10:57:20 bluhm Exp $ */
/* $KAME: ip6_forward.c,v 1.75 2001/06/29 12:42:13 jinmei Exp $ */
/*
struct route ro;
struct ifnet *ifp = NULL;
int error = 0, type = 0, code = 0, destmtu = 0;
- struct mbuf *mcopy = NULL;
+ struct mbuf *mcopy;
#ifdef IPSEC
struct tdb *tdb = NULL;
#endif /* IPSEC */
m->m_pkthdr.ph_ifidx);
}
m_freem(m);
- goto out;
+ goto done;
}
if (ip6->ip6_hlim <= IPV6_HLIMDEC) {
icmp6_error(m, ICMP6_TIME_EXCEEDED,
ICMP6_TIME_EXCEED_TRANSIT, 0);
- goto out;
+ goto done;
}
ip6->ip6_hlim -= IPV6_HLIMDEC;
m->m_pkthdr.ph_rtableid);
if (rt == NULL) {
ip6stat_inc(ip6s_noroute);
- if (mcopy) {
+ if (mcopy != NULL) {
icmp6_error(mcopy, ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_NOROUTE, 0);
}
m_freem(m);
- goto out;
+ goto done;
}
}
ro.ro_rt = rt;
ip6->ip6_nxt,
m->m_pkthdr.ph_ifidx, rt->rt_ifidx);
}
- if (mcopy)
+ if (mcopy != NULL)
icmp6_error(mcopy, ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_BEYONDSCOPE, 0);
m_freem(m);
- goto out;
+ goto done;
}
#ifdef IPSEC
* type/code is based on suggestion by Rich Draves.
* not sure if it is the best pick.
*/
- if (mcopy)
+ if (mcopy != NULL)
icmp6_error(mcopy, ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_ADDR, 0);
m_freem(m);
- goto out;
+ goto done;
}
type = ND_REDIRECT;
}
if (mcopy != NULL)
icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0, ifp->if_mtu);
m_freem(m);
- goto out;
+ goto done;
senderr:
if (mcopy == NULL)
- goto out;
+ goto done;
switch (error) {
case 0:
if (type == ND_REDIRECT) {
icmp6_redirect_output(mcopy, rt);
ip6stat_inc(ip6s_redirectsent);
- goto out;
+ goto done;
}
goto freecopy;
break;
}
icmp6_error(mcopy, type, code, destmtu);
- goto out;
+ goto done;
-freecopy:
+ freecopy:
m_freem(mcopy);
-out:
+ done:
rtfree(rt);
if_put(ifp);
#ifdef IPSEC
-/* $OpenBSD: ip6_input.c,v 1.258 2024/02/22 14:25:58 bluhm Exp $ */
+/* $OpenBSD: ip6_input.c,v 1.259 2024/02/28 10:57:20 bluhm Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
#if NPF > 0
struct in6_addr odst;
#endif
- int srcrt = 0;
+ int pfrdr = 0;
KASSERT(*offp == 0);
goto bad;
ip6 = mtod(m, struct ip6_hdr *);
- srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
+ pfrdr = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
#endif
/*
}
#endif /* IPSEC */
- ip6_forward(m, rt, srcrt);
+ ip6_forward(m, rt, pfrdr);
*mp = NULL;
return IPPROTO_DONE;
bad:
-/* $OpenBSD: ip6_output.c,v 1.287 2024/02/22 14:25:58 bluhm Exp $ */
+/* $OpenBSD: ip6_output.c,v 1.288 2024/02/28 10:57:20 bluhm Exp $ */
/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
/*
(error = if_output_ml(ifp, &ml, sin6tosa(dst), ro->ro_rt)))
goto done;
ip6stat_inc(ip6s_fragmented);
+ goto done;
-done:
+ freehdrs:
+ m_freem(exthdrs.ip6e_hbh); /* m_freem will check if mbuf is 0 */
+ m_freem(exthdrs.ip6e_dest1);
+ m_freem(exthdrs.ip6e_rthdr);
+ m_freem(exthdrs.ip6e_dest2);
+ bad:
+ m_freem(m);
+ done:
if (ro == &iproute && ro->ro_rt) {
rtfree(ro->ro_rt);
} else if (ro_pmtu == &iproute && ro_pmtu->ro_rt) {
tdb_unref(tdb);
#endif /* IPSEC */
return (error);
-
-freehdrs:
- m_freem(exthdrs.ip6e_hbh); /* m_freem will check if mbuf is 0 */
- m_freem(exthdrs.ip6e_dest1);
- m_freem(exthdrs.ip6e_rthdr);
- m_freem(exthdrs.ip6e_dest2);
- /* FALLTHROUGH */
-bad:
- m_freem(m);
- goto done;
}
int