Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/sys Pull up following revision(s) (requested by maxv in t...
details: https://anonhg.NetBSD.org/src/rev/600301014698
branches: netbsd-7
changeset: 800427:600301014698
user: snj <snj%NetBSD.org@localhost>
date: Sat Feb 24 18:29:40 2018 +0000
description:
Pull up following revision(s) (requested by maxv in ticket #1571):
sys/net/if_mpls.c: 1.31-1.33 via patch
sys/netmpls/mpls_ttl.c: 1.9
Style, and fix several bugs:
- ip4_check(), mpls_unlabel_inet() and mpls_unlabel_inet6() perform
pullups, so we need to pass the updated pointers back
- in mpls_lse() the route is not always freed
Looks a little better now.
--
Kick MPLS packets earlier.
--
Several changes:
* Declare TRIM_LABEL as a function.
* In mpls_unlabel_inet, copy the label locally. It's not incorrect to
keep a pointer on the mbuf, but it's bug-friendly.
* In mpls_label_inetX, fix the length check. Meanwhile add an XXX: we
just want to make sure that m_copydata won't fail, but if we were
guaranteed that m has M_PKTHDR set, we could simply check the length
against m->m_pkthdr.len.
diffstat:
sys/net/if_mpls.c | 116 +++++++++++++++++++++++++++++-------------------
sys/netmpls/mpls_ttl.c | 57 +++++++++++------------
2 files changed, 97 insertions(+), 76 deletions(-)
diffs (truncated from 462 to 300 lines):
diff -r ba27237df553 -r 600301014698 sys/net/if_mpls.c
--- a/sys/net/if_mpls.c Mon Feb 19 19:46:26 2018 +0000
+++ b/sys/net/if_mpls.c Sat Feb 24 18:29:40 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_mpls.c,v 1.16 2014/07/17 10:46:57 bouyer Exp $ */
+/* $NetBSD: if_mpls.c,v 1.16.2.1 2018/02/24 18:29:40 snj Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.16 2014/07/17 10:46:57 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.16.2.1 2018/02/24 18:29:40 snj Exp $");
#include "opt_inet.h"
#include "opt_mpls.h"
@@ -92,12 +92,12 @@
static int mpls_lse(struct mbuf *);
#ifdef INET
-static int mpls_unlabel_inet(struct mbuf *);
+static struct mbuf *mpls_unlabel_inet(struct mbuf *, int *error);
static struct mbuf *mpls_label_inet(struct mbuf *, union mpls_shim *, uint);
#endif
#ifdef INET6
-static int mpls_unlabel_inet6(struct mbuf *);
+static struct mbuf *mpls_unlabel_inet6(struct mbuf *, int *error);
static struct mbuf *mpls_label_inet6(struct mbuf *, union mpls_shim *, uint);
#endif
@@ -321,6 +321,12 @@
uint psize = sizeof(struct sockaddr_mpls);
bool push_back_alert = false;
+ /* If we're not accepting MPLS frames, leave now. */
+ if (!mpls_frame_accept) {
+ error = EINVAL;
+ goto done;
+ }
+
if (m->m_len < sizeof(union mpls_shim) &&
(m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
goto done;
@@ -329,21 +335,19 @@
dst.smpls_family = AF_MPLS;
dst.smpls_addr.s_addr = ntohl(mtod(m, union mpls_shim *)->s_addr);
- /* Check if we're accepting MPLS Frames */
error = EINVAL;
- if (!mpls_frame_accept)
- goto done;
/* TTL decrement */
if ((m = mpls_ttl_dec(m)) == NULL)
goto done;
/* RFC 4182 */
- if (mpls_rfc4182 != 0)
- while((dst.smpls_addr.shim.label == MPLS_LABEL_IPV4NULL ||
+ if (mpls_rfc4182 != 0) {
+ while ((dst.smpls_addr.shim.label == MPLS_LABEL_IPV4NULL ||
dst.smpls_addr.shim.label == MPLS_LABEL_IPV6NULL) &&
__predict_false(dst.smpls_addr.shim.bos == 0))
TRIM_LABEL;
+ }
/* RFC 3032 Section 2.1 Page 4 */
if (__predict_false(dst.smpls_addr.shim.label == MPLS_LABEL_RTALERT) &&
@@ -358,15 +362,17 @@
#ifdef INET
case MPLS_LABEL_IPV4NULL:
/* Pop shim and push mbuf to IP stack */
- if (dst.smpls_addr.shim.bos)
- error = mpls_unlabel_inet(m);
+ if (dst.smpls_addr.shim.bos) {
+ m = mpls_unlabel_inet(m, &error);
+ }
break;
#endif
#ifdef INET6
case MPLS_LABEL_IPV6NULL:
/* Pop shim and push mbuf to IPv6 stack */
- if (dst.smpls_addr.shim.bos)
- error = mpls_unlabel_inet6(m);
+ if (dst.smpls_addr.shim.bos) {
+ m = mpls_unlabel_inet6(m, &error);
+ }
break;
#endif
case MPLS_LABEL_RTALERT: /* Yeah, I'm all alerted */
@@ -420,8 +426,10 @@
tshim.shim.bos = tshim.shim.exp = 0;
tshim.shim.ttl = mpls_defttl;
if (tshim.shim.label != MPLS_LABEL_IMPLNULL &&
- ((m = mpls_prepend_shim(m, &tshim)) == NULL))
- return ENOBUFS;
+ ((m = mpls_prepend_shim(m, &tshim)) == NULL)) {
+ error = ENOBUFS;
+ goto done;
+ }
psize += sizeof(tshim);
}
@@ -431,8 +439,10 @@
tshim.s_addr = MPLS_LABEL_RTALERT;
tshim.shim.bos = tshim.shim.exp = 0;
tshim.shim.ttl = mpls_defttl;
- if ((m = mpls_prepend_shim(m, &tshim)) == NULL)
- return ENOBUFS;
+ if ((m = mpls_prepend_shim(m, &tshim)) == NULL) {
+ error = ENOBUFS;
+ goto done;
+ }
}
error = mpls_send_frame(m, rt->rt_ifp, rt);
@@ -480,18 +490,15 @@
return 0;
}
-
-
#ifdef INET
-static int
-mpls_unlabel_inet(struct mbuf *m)
+static struct mbuf *
+mpls_unlabel_inet(struct mbuf *m, int *error)
{
struct ip *iph;
union mpls_shim *ms;
int iphlen;
if (mpls_mapttl_inet || mpls_mapprec_inet) {
-
/* get shim info */
ms = mtod(m, union mpls_shim *);
ms->s_addr = ntohl(ms->s_addr);
@@ -500,23 +507,29 @@
m_adj(m, sizeof(union mpls_shim));
/* get ip header */
- if (m->m_len < sizeof (struct ip) &&
- (m = m_pullup(m, sizeof(struct ip))) == NULL)
- return ENOBUFS;
+ if (m->m_len < sizeof(struct ip) &&
+ (m = m_pullup(m, sizeof(struct ip))) == NULL) {
+ *error = ENOBUFS;
+ return NULL;
+ }
+
iph = mtod(m, struct ip *);
iphlen = iph->ip_hl << 2;
/* get it all */
if (m->m_len < iphlen) {
- if ((m = m_pullup(m, iphlen)) == NULL)
- return ENOBUFS;
+ if ((m = m_pullup(m, iphlen)) == NULL) {
+ *error = ENOBUFS;
+ return NULL;
+ }
iph = mtod(m, struct ip *);
}
/* check ipsum */
if (in_cksum(m, iphlen) != 0) {
m_freem(m);
- return EINVAL;
+ *error = EINVAL;
+ return NULL;
}
/* set IP ttl from MPLS ttl */
@@ -532,15 +545,19 @@
/* reset ipsum because we modified TTL and TOS */
iph->ip_sum = 0;
iph->ip_sum = in_cksum(m, iphlen);
- } else
+ } else {
m_adj(m, sizeof(union mpls_shim));
+ }
/* Put it on IP queue */
if (__predict_false(!pktq_enqueue(ip_pktq, m, 0))) {
m_freem(m);
- return ENOBUFS;
+ *error = ENOBUFS;
+ return NULL;
}
- return 0;
+
+ *error = 0;
+ return m;
}
/*
@@ -552,9 +569,11 @@
struct ip iphdr;
if (mpls_mapttl_inet || mpls_mapprec_inet) {
- if ((m->m_len < sizeof(struct ip)) &&
+ /* XXX Maybe just check m->m_pkthdr.len instead? */
+ if ((m->m_len < offset + sizeof(struct ip)) &&
(m = m_pullup(m, offset + sizeof(struct ip))) == 0)
- return NULL; /* XXX */
+ return NULL;
+
m_copydata(m, offset, sizeof(struct ip), &iphdr);
/* Map TTL */
@@ -571,13 +590,11 @@
return m;
}
-
#endif /* INET */
#ifdef INET6
-
-static int
-mpls_unlabel_inet6(struct mbuf *m)
+static struct mbuf *
+mpls_unlabel_inet6(struct mbuf *m, int *error)
{
struct ip6_hdr *ip6hdr;
union mpls_shim ms;
@@ -588,21 +605,27 @@
m_adj(m, sizeof(union mpls_shim));
if (m->m_len < sizeof (struct ip6_hdr) &&
- (m = m_pullup(m, sizeof(struct ip6_hdr))) == 0)
- return ENOBUFS;
+ (m = m_pullup(m, sizeof(struct ip6_hdr))) == 0) {
+ *error = ENOBUFS;
+ return NULL;
+ }
ip6hdr = mtod(m, struct ip6_hdr *);
/* Because we just decremented this in mpls_lse */
ip6hdr->ip6_hlim = ms.shim.ttl + 1;
- } else
+ } else {
m_adj(m, sizeof(union mpls_shim));
+ }
/* Put it back on IPv6 queue. */
if (__predict_false(!pktq_enqueue(ip6_pktq, m, 0))) {
m_freem(m);
- return ENOBUFS;
+ *error = ENOBUFS;
+ return NULL;
}
- return 0;
+
+ *error = 0;
+ return m;
}
static struct mbuf *
@@ -611,9 +634,11 @@
struct ip6_hdr ip6h;
if (mpls_mapttl_inet6 || mpls_mapclass_inet6) {
- if (m->m_len < sizeof(struct ip6_hdr) &&
+ /* XXX Maybe just check m->m_pkthdr.len instead? */
+ if ((m->m_len < offset + sizeof(struct ip6_hdr)) &&
(m = m_pullup(m, offset + sizeof(struct ip6_hdr))) == 0)
return NULL;
+
m_copydata(m, offset, sizeof(struct ip6_hdr), &ip6h);
if (mpls_mapttl_inet6)
@@ -628,14 +653,13 @@
return m;
}
-
#endif /* INET6 */
static struct mbuf *
-mpls_prepend_shim(struct mbuf *m, union mpls_shim *ms)
+mpls_prepend_shim(struct mbuf *m, union mpls_shim *ms)
{
union mpls_shim *shim;
-
+
M_PREPEND(m, sizeof(*ms), M_DONTWAIT);
if (m == NULL)
return NULL;
diff -r ba27237df553 -r 600301014698 sys/netmpls/mpls_ttl.c
--- a/sys/netmpls/mpls_ttl.c Mon Feb 19 19:46:26 2018 +0000
+++ b/sys/netmpls/mpls_ttl.c Sat Feb 24 18:29:40 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_ttl.c,v 1.4 2013/08/07 06:55:00 kefren Exp $ */
+/* $NetBSD: mpls_ttl.c,v 1.4.4.1 2018/02/24 18:29:41 snj Exp $ */
/*
Home |
Main Index |
Thread Index |
Old Index