From 0532d5e5d918c56d6529bc60be62c9c362a8cc86 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 16 Aug 2001 17:16:31 +0000 Subject: Only allocate teh 1540 byte buffer if we need it.. (lazy allocation) MFC after: 13 days --- sys/net/if_sl.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'sys/net/if_sl.c') diff --git a/sys/net/if_sl.c b/sys/net/if_sl.c index 8621880..b681a0b 100644 --- a/sys/net/if_sl.c +++ b/sys/net/if_sl.c @@ -264,13 +264,6 @@ slcreate() struct mbuf *m; MALLOC(sc, struct sl_softc *, sizeof(*sc), M_SL, M_WAITOK | M_ZERO); - if (!sc) - return (NULL); - MALLOC(sc->bpfbuf, u_char *, SLTMAX + SLIP_HDRLEN, M_SL, M_NOWAIT); - if (!sc->bpfbuf) { - FREE(sc, M_SL); - return (NULL); - } m = m_gethdr(M_TRYWAIT, MT_DATA); if (m != NULL) { @@ -283,7 +276,6 @@ slcreate() if (m == NULL) { printf("sl: can't allocate buffer\n"); - FREE(sc->bpfbuf, M_SL); FREE(sc, M_SL); return (NULL); } @@ -394,7 +386,8 @@ sldestroy(struct sl_softc *sc) LIST_REMOVE(sc, sl_next); m_free(sc->sc_mbuf); mtx_destroy(&sc->sc_fastq.ifq_mtx); - FREE(sc->bpfbuf, M_SL); + if (sc->bpfbuf) + FREE(sc->bpfbuf, M_SL); FREE(sc, M_SL); } @@ -661,16 +654,23 @@ slstart(tp) * to the packet transmission time). */ register struct mbuf *m1 = m; - register u_char *cp = sc->bpfbuf + SLIP_HDRLEN; - - len = 0; - do { - register int mlen = m1->m_len; - - bcopy(mtod(m1, caddr_t), cp, mlen); - cp += mlen; - len += mlen; - } while ((m1 = m1->m_next) != NULL); + register u_char *cp; + + if (sc->bpfbuf == NULL) + MALLOC(sc->bpfbuf, u_char *, + SLTMAX + SLIP_HDRLEN, M_SL, M_NOWAIT); + + if (sc->bpfbuf) { + cp = sc->bpfbuf + SLIP_HDRLEN; + len = 0; + do { + register int mlen = m1->m_len; + + bcopy(mtod(m1, caddr_t), cp, mlen); + cp += mlen; + len += mlen; + } while ((m1 = m1->m_next) != NULL); + } } ip = mtod(m, struct ip *); if (ip->ip_v == IPVERSION && ip->ip_p == IPPROTO_TCP) { @@ -678,7 +678,7 @@ slstart(tp) *mtod(m, u_char *) |= sl_compress_tcp(m, ip, &sc->sc_comp, 1); } - if (sc->sc_if.if_bpf) { + if (sc->sc_if.if_bpf && sc->bpfbuf) { /* * Put the SLIP pseudo-"link header" in place. The * compressed header is now at the beginning of the -- cgit v1.1