Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net if MGETHDR fails, don't try to copy to single mbuf a...



details:   https://anonhg.NetBSD.org/src/rev/5e94cb1d667c
branches:  trunk
changeset: 352859:5e94cb1d667c
user:      maya <maya%NetBSD.org@localhost>
date:      Thu Apr 13 00:47:33 2017 +0000

description:
if MGETHDR fails, don't try to copy to single mbuf and deref null.

reduce ifdefs.

diffstat:

 sys/net/if_sl.c    |  23 +++++++++--------------
 sys/net/if_strip.c |  23 +++++++++--------------
 2 files changed, 18 insertions(+), 28 deletions(-)

diffs (154 lines):

diff -r dad30a86af15 -r 5e94cb1d667c sys/net/if_sl.c
--- a/sys/net/if_sl.c   Thu Apr 13 00:12:10 2017 +0000
+++ b/sys/net/if_sl.c   Thu Apr 13 00:47:33 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_sl.c,v 1.127 2016/10/02 14:17:07 christos Exp $     */
+/*     $NetBSD: if_sl.c,v 1.128 2017/04/13 00:47:33 maya Exp $ */
 
 /*
  * Copyright (c) 1987, 1989, 1992, 1993
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.127 2016/10/02 14:17:07 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.128 2017/04/13 00:47:33 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -705,12 +705,9 @@
 {
        struct sl_softc *sc = arg;
        struct tty *tp = sc->sc_ttyp;
-       struct mbuf *m;
+       struct mbuf *m, *n;
        int s, len;
        u_char *pktstart;
-#ifdef INET
-       u_char c;
-#endif
        u_char chdr[CHDR_LEN];
 
        KASSERT(tp != NULL);
@@ -720,9 +717,6 @@
         */
        mutex_enter(softnet_lock);
        for (;;) {
-#ifdef INET
-               struct ip *ip;
-#endif
                struct mbuf *m2;
                struct mbuf *bpf_m;
 
@@ -774,6 +768,7 @@
                } else
                        bpf_m = NULL;
 #ifdef INET
+               struct ip *ip;
                if ((ip = mtod(m, struct ip *))->ip_p == IPPROTO_TCP) {
                        if (sc->sc_if.if_flags & SC_COMPRESS)
                                *mtod(m, u_char *) |=
@@ -897,6 +892,7 @@
                        memcpy(chdr, pktstart, CHDR_LEN);
                }
 #ifdef INET
+               u_char c;
                if ((c = (*pktstart & 0xf0)) != (IPVERSION << 4)) {
                        if (c & 0x80)
                                c = TYPE_COMPRESSED_TCP;
@@ -942,14 +938,13 @@
                }
                /*
                 * If the packet will fit into a single
-                * header mbuf, copy it into one, to save
-                * memory.
+                * header mbuf, try to copy it into one,
+                * to save memory.
                 */
-               if (m->m_pkthdr.len < MHLEN) {
-                       struct mbuf *n;
+               if ((m->m_pkthdr.len < MHLEN) &&
+                   (n = m_gethdr(M_DONTWAIT, MT_DATA))) {
                        int pktlen;
 
-                       MGETHDR(n, M_DONTWAIT, MT_DATA);
                        pktlen = m->m_pkthdr.len;
                        M_MOVE_PKTHDR(n, m);
                        memcpy(mtod(n, void *), mtod(m, void *), pktlen);
diff -r dad30a86af15 -r 5e94cb1d667c sys/net/if_strip.c
--- a/sys/net/if_strip.c        Thu Apr 13 00:12:10 2017 +0000
+++ b/sys/net/if_strip.c        Thu Apr 13 00:47:33 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_strip.c,v 1.107 2016/10/02 14:17:07 christos Exp $  */
+/*     $NetBSD: if_strip.c,v 1.108 2017/04/13 00:47:33 maya Exp $      */
 /*     from: NetBSD: if_sl.c,v 1.38 1996/02/13 22:00:23 christos Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.107 2016/10/02 14:17:07 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.108 2017/04/13 00:47:33 maya Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1073,12 +1073,9 @@
 {
        struct strip_softc *sc = arg;
        struct tty *tp = sc->sc_ttyp;
-       struct mbuf *m;
+       struct mbuf *m, *n;
        int s, len;
        u_char *pktstart;
-#ifdef INET
-       u_char c;
-#endif
        u_char chdr[CHDR_LEN];
 
        KASSERT(tp != NULL);
@@ -1088,9 +1085,6 @@
         */
        mutex_enter(softnet_lock);
        for (;;) {
-#ifdef INET
-               struct ip *ip;
-#endif
                struct mbuf *bpf_m;
 
                /*
@@ -1143,6 +1137,7 @@
                } else
                        bpf_m = NULL;
 #ifdef INET
+               struct ip *ip;
                if ((ip = mtod(m, struct ip *))->ip_p == IPPROTO_TCP) {
                        if (sc->sc_if.if_flags & SC_COMPRESS)
                                *mtod(m, u_char *) |=
@@ -1189,6 +1184,7 @@
                        memcpy(chdr, pktstart, CHDR_LEN);
                }
 #ifdef INET
+               u_char c;
                if ((c = (*pktstart & 0xf0)) != (IPVERSION << 4)) {
                        if (c & 0x80)
                                c = TYPE_COMPRESSED_TCP;
@@ -1234,14 +1230,13 @@
                }
                /*
                 * If the packet will fit into a single
-                * header mbuf, copy it into one, to save
-                * memory.
+                * header mbuf, try to copy it into one,
+                * to save memory.
                 */
-               if (m->m_pkthdr.len < MHLEN) {
-                       struct mbuf *n;
+               if ((m->m_pkthdr.len < MHLEN) &&
+                   (n = m_gethdr(M_DONTWAIT, MT_DATA))) {
                        int pktlen;
 
-                       MGETHDR(n, M_DONTWAIT, MT_DATA);
                        pktlen = m->m_pkthdr.len;
                        M_MOVE_PKTHDR(n, m);
                        memcpy(mtod(n, void *), mtod(m, void *), pktlen);



Home | Main Index | Thread Index | Old Index