summaryrefslogtreecommitdiffstats
path: root/sys/netinet6/ip6_input.c
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2017-02-06 16:01:25 +0000
committerbluhm <bluhm@openbsd.org>2017-02-06 16:01:25 +0000
commitd88f5bbfd294797dafae3a2d93804ad577342e1a (patch)
tree11040b647e148c7ca2e7b24c082bf814dc176ca5 /sys/netinet6/ip6_input.c
parentMark ehci_intr() as MP-safe on octeon. (diff)
downloadwireguard-openbsd-d88f5bbfd294797dafae3a2d93804ad577342e1a.tar.xz
wireguard-openbsd-d88f5bbfd294797dafae3a2d93804ad577342e1a.zip
Make ip6_input() more like ipv4_input() and introduce ip6_ours().
OK mpi@
Diffstat (limited to 'sys/netinet6/ip6_input.c')
-rw-r--r--sys/netinet6/ip6_input.c69
1 files changed, 31 insertions, 38 deletions
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index d306e043c31..8cc803a431d 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_input.c,v 1.177 2017/02/05 16:23:38 jca Exp $ */
+/* $OpenBSD: ip6_input.c,v 1.178 2017/02/06 16:01:25 bluhm Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@@ -120,9 +120,9 @@ struct niqueue ip6intrq = NIQUEUE_INITIALIZER(IFQ_MAXLEN, NETISR_IPV6);
struct cpumem *ip6counters;
int ip6_check_rh0hdr(struct mbuf *, int *);
-
int ip6_hbhchcheck(struct mbuf *, int *, int *, int *);
int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *);
+void ip6_ours(struct mbuf *, int, int);
struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
static struct mbuf_queue ip6send_mq;
@@ -181,9 +181,8 @@ ip6_input(struct mbuf *m)
struct ip6_hdr *ip6;
struct sockaddr_in6 sin6;
struct rtentry *rt = NULL;
- int off, nest;
+ int off, nxt, ours = 0;
u_int16_t src_scope, dst_scope;
- int nxt, ours = 0;
#if NPF > 0
struct in6_addr odst;
#endif
@@ -198,8 +197,7 @@ ip6_input(struct mbuf *m)
if (m->m_len < sizeof(struct ip6_hdr)) {
if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
ip6stat_inc(ip6s_toosmall);
- if_put(ifp);
- return;
+ goto out;
}
}
@@ -337,9 +335,7 @@ ip6_input(struct mbuf *m)
ip6_check_rh0hdr(m, &off)) {
ip6stat_inc(ip6s_badoptions);
icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, off);
- /* m is already freed */
- if_put(ifp);
- return;
+ goto out;
}
if (IN6_IS_ADDR_LOOPBACK(&ip6->ip6_src) ||
@@ -375,11 +371,8 @@ ip6_input(struct mbuf *m)
#ifdef MROUTING
if (ip6_mforwarding && ip6_mrouter) {
- if (ip6_hbhchcheck(m, &off, &nxt, &ours)) {
- rtfree(rt);
- if_put(ifp);
- return; /* m have already been freed */
- }
+ if (ip6_hbhchcheck(m, &off, &nxt, &ours))
+ goto out;
ip6 = mtod(m, struct ip6_hdr *);
@@ -391,14 +384,15 @@ ip6_input(struct mbuf *m)
* ip6_mforward() returns a non-zero value, the packet
* must be discarded, else it may be accepted below.
*/
- if (ip6_mforward(ip6, ifp, m)) {
+ if (ip6_mforward(ip6, ifp, m)) {
ip6stat_inc(ip6s_cantforward);
goto bad;
}
if (!ours)
goto bad;
- goto ours;
+ ip6_ours(m, off, nxt);
+ goto out;
}
#endif
if (!ours) {
@@ -468,36 +462,39 @@ ip6_input(struct mbuf *m)
hbhcheck:
- if (ip6_hbhchcheck(m, &off, &nxt, &ours)) {
- rtfree(rt);
- if_put(ifp);
- return; /* m have already been freed */
- }
+ if (ip6_hbhchcheck(m, &off, &nxt, &ours))
+ goto out;
- /* adjust pointer */
- ip6 = mtod(m, struct ip6_hdr *);
+ if (ours) {
+ ip6_ours(m, off, nxt);
+ goto out;
+ }
/*
* Forward if desirable.
*/
- if (!ours) {
- ip6_forward(m, rt, srcrt);
- if_put(ifp);
- return;
- }
-#ifdef MROUTING
- ours:
-#endif
+ ip6_forward(m, rt, srcrt);
+ if_put(ifp);
+ return;
+ bad:
+ m_freem(m);
+ out:
+ rtfree(rt);
+ if_put(ifp);
+}
+
+void
+ip6_ours(struct mbuf *m, int off, int nxt)
+{
+ int nest = 0;
+
/* pf might have changed things */
in6_proto_cksum_out(m, NULL);
- ip6 = mtod(m, struct ip6_hdr *);
-
/*
* Tell launch routine the next header
*/
ip6stat_inc(ip6s_delivered);
- nest = 0;
while (nxt != IPPROTO_DONE) {
if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
@@ -527,12 +524,8 @@ ip6_input(struct mbuf *m)
nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
}
- rtfree(rt);
- if_put(ifp);
return;
bad:
- rtfree(rt);
- if_put(ifp);
m_freem(m);
}