o Untangle the confusion with the malloc flags {M_WAITOK, M_NOWAIT} and
the mbuf allocator flags {M_TRYWAIT, M_DONTWAIT}. o Fix a bpf_compat issue where malloc() was defined to just call bpf_alloc() and pass the 'canwait' flag(s) along. It's been changed to call bpf_alloc() but pass the corresponding M_TRYWAIT or M_DONTWAIT flag (and only one of those two). Submitted by: Hiten Pandya <hiten@unixdaemons.com> (hiten->commit_count++)
This commit is contained in:
parent
9dbbb2829e
commit
86fea6be59
@ -40,14 +40,14 @@
|
||||
/*
|
||||
* Some hacks for compatibility across SunOS and 4.4BSD. We emulate malloc
|
||||
* and free with mbuf clusters. We store a pointer to the mbuf in the first
|
||||
* word of the mbuf and return 8 bytes passed the start of data (for double
|
||||
* word of the mbuf and return 8 bytes past the start of data (for double
|
||||
* word alignment). We cannot just use offsets because clusters are not at
|
||||
* a fixed offset from the associated mbuf. Sorry for this kludge.
|
||||
*/
|
||||
#define malloc(size, type, canwait) bpf_alloc(size, canwait)
|
||||
#define malloc(size, type, canwait) \
|
||||
bpf_alloc(size, (canwait & M_NOWAIT) ? M_DONTWAIT : M_TRYWAIT)
|
||||
|
||||
#define free(cp, type) m_free(*(struct mbuf **)(cp - 8))
|
||||
#define M_WAITOK M_TRYWAIT
|
||||
#define M_NOWAIT M_DONTWAIT
|
||||
|
||||
/* This mapping works for our purposes. */
|
||||
#define ERESTART EINTR
|
||||
|
@ -239,7 +239,7 @@ add_cluster(u_int16_t cluster_id, struct arpcom *ac)
|
||||
goto found;
|
||||
|
||||
/* Not found, need to reallocate */
|
||||
c = malloc((1+n_clusters) * sizeof (*c), M_IFADDR, M_DONTWAIT | M_ZERO);
|
||||
c = malloc((1+n_clusters) * sizeof (*c), M_IFADDR, M_NOWAIT | M_ZERO);
|
||||
if (c == NULL) {/* malloc failure */
|
||||
printf("-- bridge: cannot add new cluster\n");
|
||||
return NULL;
|
||||
@ -793,7 +793,7 @@ static struct mbuf *
|
||||
bdg_forward(struct mbuf *m0, struct ifnet *dst)
|
||||
{
|
||||
#define EH_RESTORE(_m) do { \
|
||||
M_PREPEND((_m), ETHER_HDR_LEN, M_NOWAIT); \
|
||||
M_PREPEND((_m), ETHER_HDR_LEN, M_DONTWAIT); \
|
||||
if ((_m) == NULL) { \
|
||||
bdg_dropped++; \
|
||||
return NULL; \
|
||||
|
@ -470,7 +470,7 @@ ether_ipfw_chk(struct mbuf **m0, struct ifnet *dst,
|
||||
* Restore Ethernet header, as needed, in case the
|
||||
* mbuf chain was replaced by ipfw.
|
||||
*/
|
||||
M_PREPEND(m, ETHER_HDR_LEN, M_NOWAIT);
|
||||
M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
|
||||
if (m == NULL) {
|
||||
*m0 = m;
|
||||
return 0;
|
||||
@ -894,7 +894,7 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
|
||||
* Put back the ethernet header so netgraph has a
|
||||
* consistent view of inbound packets.
|
||||
*/
|
||||
M_PREPEND(m, sizeof (struct ether_header), M_NOWAIT);
|
||||
M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
|
||||
(*ng_ether_input_orphan_p)(ifp, m);
|
||||
return;
|
||||
}
|
||||
|
@ -42,7 +42,6 @@
|
||||
#ifdef _KERNEL
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#define M_DONTWAIT M_NOWAIT
|
||||
#include <sys/domain.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
|
@ -150,7 +150,7 @@ struct radix_node_head {
|
||||
#define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
|
||||
#define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
|
||||
#define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n));
|
||||
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_DONTWAIT))
|
||||
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_NOWAIT))
|
||||
#define Free(p) free((caddr_t)p, M_RTABLE);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
|
@ -139,7 +139,7 @@ raw_bind(so, nam)
|
||||
if (ifnet == 0)
|
||||
return (EADDRNOTAVAIL);
|
||||
rp = sotorawcb(so);
|
||||
nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
|
||||
nam = m_copym(nam, 0, M_COPYALL, M_TRYWAIT);
|
||||
rp->rcb_laddr = mtod(nam, struct sockaddr *);
|
||||
return (0);
|
||||
}
|
||||
|
@ -1271,7 +1271,7 @@ ng_btsocket_hci_raw_send(struct socket *so, int flags, struct mbuf *m,
|
||||
sa = (struct sockaddr *) &pcb->addr;
|
||||
}
|
||||
|
||||
MGET(nam, M_WAITOK, MT_SONAME);
|
||||
MGET(nam, M_TRYWAIT, MT_SONAME);
|
||||
if (nam == NULL) {
|
||||
error = ENOBUFS;
|
||||
goto drop;
|
||||
|
@ -1464,7 +1464,7 @@ ng_btsocket_l2cap_data_input(struct mbuf *m, hook_p hook)
|
||||
* it is a broadcast traffic after all
|
||||
*/
|
||||
|
||||
copy = m_dup(m, M_NOWAIT);
|
||||
copy = m_dup(m, M_DONTWAIT);
|
||||
if (copy != NULL) {
|
||||
sbappendrecord(&pcb->so->so_rcv, copy);
|
||||
sorwakeup(pcb->so);
|
||||
@ -2384,7 +2384,7 @@ ng_btsocket_l2cap_send2(ng_btsocket_l2cap_pcb_p pcb)
|
||||
if (pcb->so->so_snd.sb_cc == 0)
|
||||
return (EINVAL); /* XXX */
|
||||
|
||||
m = m_dup(pcb->so->so_snd.sb_mb, M_NOWAIT);
|
||||
m = m_dup(pcb->so->so_snd.sb_mb, M_DONTWAIT);
|
||||
if (m == NULL)
|
||||
return (ENOBUFS);
|
||||
|
||||
|
@ -713,7 +713,7 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
|
||||
* It's usable link but not the reserved (first) one.
|
||||
* Copy mbuf and meta info for sending.
|
||||
*/
|
||||
m2 = m_dup(m, M_NOWAIT); /* XXX m_copypacket() */
|
||||
m2 = m_dup(m, M_DONTWAIT); /* XXX m_copypacket() */
|
||||
if (m2 == NULL) {
|
||||
link->stats.memoryFailures++;
|
||||
NG_FREE_ITEM(item);
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/libkern.h>
|
||||
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/netgraph.h>
|
||||
@ -295,9 +296,8 @@ NETGRAPH_INIT(l2tp, &ng_l2tp_typestruct);
|
||||
#define L2TP_SEQ_CHECK(x) do { } while (0)
|
||||
#endif
|
||||
|
||||
/* mem*() macros */
|
||||
/* memmove macro */
|
||||
#define memmove(d, s, l) ovbcopy(s, d, l)
|
||||
#define memset(d, z, l) bzero(d, l) /* XXX */
|
||||
|
||||
/* Whether to use m_copypacket() or m_dup() */
|
||||
#define L2TP_COPY_MBUF m_copypacket
|
||||
@ -955,7 +955,7 @@ ng_l2tp_recv_ctrl(node_p node, item_p item)
|
||||
}
|
||||
|
||||
/* Copy packet */
|
||||
if ((m = L2TP_COPY_MBUF(seq->xwin[i], M_NOWAIT)) == NULL) {
|
||||
if ((m = L2TP_COPY_MBUF(seq->xwin[i], M_DONTWAIT)) == NULL) {
|
||||
priv->stats.memoryFailures++;
|
||||
return (ENOBUFS);
|
||||
}
|
||||
@ -1219,7 +1219,7 @@ ng_l2tp_seq_recv_nr(priv_p priv, u_int16_t nr)
|
||||
*/
|
||||
while ((i = L2TP_SEQ_DIFF(seq->ns, seq->rack)) < seq->cwnd
|
||||
&& seq->xwin[i] != NULL) {
|
||||
if ((m = L2TP_COPY_MBUF(seq->xwin[i], M_NOWAIT)) == NULL)
|
||||
if ((m = L2TP_COPY_MBUF(seq->xwin[i], M_DONTWAIT)) == NULL)
|
||||
priv->stats.memoryFailures++;
|
||||
else
|
||||
ng_l2tp_xmit_ctrl(priv, m, seq->ns);
|
||||
@ -1361,7 +1361,7 @@ ng_l2tp_seq_rack_timeout(void *arg)
|
||||
seq->acks = 0;
|
||||
|
||||
/* Retransmit oldest unack'd packet */
|
||||
if ((m = L2TP_COPY_MBUF(seq->xwin[0], M_NOWAIT)) == NULL)
|
||||
if ((m = L2TP_COPY_MBUF(seq->xwin[0], M_DONTWAIT)) == NULL)
|
||||
priv->stats.memoryFailures++;
|
||||
else
|
||||
ng_l2tp_xmit_ctrl(priv, m, seq->rack);
|
||||
|
@ -427,7 +427,7 @@ ng_one2many_rcvdata(hook_p hook, item_p item)
|
||||
struct ng_one2many_link *mdst;
|
||||
|
||||
mdst = &priv->many[priv->activeMany[i]];
|
||||
m2 = m_dup(m, M_NOWAIT); /* XXX m_copypacket() */
|
||||
m2 = m_dup(m, M_DONTWAIT); /* XXX m_copypacket() */
|
||||
if (m2 == NULL) {
|
||||
mdst->stats.memoryFailures++;
|
||||
NG_FREE_ITEM(item);
|
||||
|
@ -1595,7 +1595,7 @@ ng_ppp_mp_output(node_p node, struct mbuf *m, meta_p meta)
|
||||
/* Split off next fragment as "m2" */
|
||||
m2 = m;
|
||||
if (!lastFragment) {
|
||||
struct mbuf *n = m_split(m, len, M_NOWAIT);
|
||||
struct mbuf *n = m_split(m, len, M_DONTWAIT);
|
||||
|
||||
if (n == NULL) {
|
||||
NG_FREE_M(m);
|
||||
@ -1916,7 +1916,7 @@ ng_ppp_addproto(struct mbuf *m, int proto, int compOK)
|
||||
static struct mbuf *
|
||||
ng_ppp_prepend(struct mbuf *m, const void *buf, int len)
|
||||
{
|
||||
M_PREPEND(m, len, M_NOWAIT);
|
||||
M_PREPEND(m, len, M_DONTWAIT);
|
||||
if (m == NULL || (m->m_len < len && (m = m_pullup(m, len)) == NULL))
|
||||
return (NULL);
|
||||
bcopy(buf, mtod(m, u_char *), len);
|
||||
|
@ -532,7 +532,7 @@ ng_pptpgre_xmit(node_p node, item_p item)
|
||||
m->m_len = m->m_pkthdr.len = grelen;
|
||||
m->m_pkthdr.rcvif = NULL;
|
||||
} else {
|
||||
M_PREPEND(m, grelen, M_NOWAIT);
|
||||
M_PREPEND(m, grelen, M_DONTWAIT);
|
||||
if (m == NULL || (m->m_len < grelen
|
||||
&& (m = m_pullup(m, grelen)) == NULL)) {
|
||||
priv->stats.memoryFailures++;
|
||||
|
@ -638,7 +638,7 @@ ng_source_send (sc_p sc, int tosend, int *sent_p)
|
||||
break;
|
||||
|
||||
/* duplicate the packet */
|
||||
m2 = m_copypacket(m, M_NOWAIT);
|
||||
m2 = m_copypacket(m, M_DONTWAIT);
|
||||
if (m2 == NULL) {
|
||||
s = splnet();
|
||||
IF_PREPEND(&sc->snd_queue, m);
|
||||
|
@ -334,7 +334,7 @@ ngt_rcvdata(hook_p hook, item_p item)
|
||||
meta_p meta2;
|
||||
|
||||
/* Copy packet (failure will not stop the original)*/
|
||||
m2 = m_dup(m, M_NOWAIT);
|
||||
m2 = m_dup(m, M_DONTWAIT);
|
||||
if (m2) {
|
||||
|
||||
/* Copy meta info */
|
||||
|
@ -487,7 +487,7 @@ encap_fillarg(m, ep)
|
||||
{
|
||||
struct m_tag *tag;
|
||||
|
||||
tag = m_tag_get(PACKET_TAG_ENCAP, sizeof (void*), M_NOWAIT);
|
||||
tag = m_tag_get(PACKET_TAG_ENCAP, sizeof (void*), M_DONTWAIT);
|
||||
if (tag) {
|
||||
*(void**)(tag+1) = ep->arg;
|
||||
m_tag_prepend(m, tag);
|
||||
|
@ -882,7 +882,7 @@ add_dyn_rule(struct ipfw_flow_id *id, u_int8_t dyn_type, struct ip_fw *rule)
|
||||
}
|
||||
i = hash_packet(id);
|
||||
|
||||
r = malloc(sizeof *r, M_IPFW, M_DONTWAIT | M_ZERO);
|
||||
r = malloc(sizeof *r, M_IPFW, M_NOWAIT | M_ZERO);
|
||||
if (r == NULL) {
|
||||
printf ("sorry cannot allocate state\n");
|
||||
return NULL ;
|
||||
@ -1695,7 +1695,7 @@ add_entry(struct ip_fw_head *head, struct ip_fw *rule)
|
||||
u_short nbr = 0;
|
||||
int s;
|
||||
|
||||
ftmp = malloc(sizeof *ftmp, M_IPFW, M_DONTWAIT | M_ZERO);
|
||||
ftmp = malloc(sizeof *ftmp, M_IPFW, M_NOWAIT | M_ZERO);
|
||||
if (!ftmp)
|
||||
return (ENOSPC);
|
||||
bcopy(rule, ftmp, sizeof(*ftmp));
|
||||
|
@ -219,7 +219,7 @@ esp_schedule(algo, sav)
|
||||
sav->schedlen = (*algo->schedlen)(algo);
|
||||
if (sav->schedlen < 0)
|
||||
return EINVAL;
|
||||
sav->sched = malloc(sav->schedlen, M_SECA, M_DONTWAIT);
|
||||
sav->sched = malloc(sav->schedlen, M_SECA, M_NOWAIT);
|
||||
if (!sav->sched) {
|
||||
sav->schedlen = 0;
|
||||
return ENOBUFS;
|
||||
|
@ -845,8 +845,8 @@ add_entry6(struct ip6_fw_head *chainptr, struct ip6_fw *frwl)
|
||||
u_short nbr = 0;
|
||||
int s;
|
||||
|
||||
fwc = malloc(sizeof *fwc, M_IP6FW, M_DONTWAIT);
|
||||
ftmp = malloc(sizeof *ftmp, M_IP6FW, M_DONTWAIT);
|
||||
fwc = malloc(sizeof *fwc, M_IP6FW, M_NOWAIT);
|
||||
ftmp = malloc(sizeof *ftmp, M_IP6FW, M_NOWAIT);
|
||||
if (!fwc || !ftmp) {
|
||||
dprintf(("%s malloc said no\n", err_prefix));
|
||||
if (fwc) free(fwc, M_IP6FW);
|
||||
|
@ -1623,7 +1623,7 @@ ip6_addaux(m)
|
||||
if (!tag) {
|
||||
tag = m_tag_get(PACKET_TAG_IPV6_INPUT,
|
||||
sizeof (struct ip6aux),
|
||||
M_NOWAIT);
|
||||
M_DONTWAIT);
|
||||
if (tag)
|
||||
m_tag_prepend(m, tag);
|
||||
}
|
||||
|
@ -171,12 +171,12 @@ ipcomp_output(m, nexthdrp, md, isr, af)
|
||||
* compromise two m_copym(). we will be going through every byte of
|
||||
* the payload during compression process anyways.
|
||||
*/
|
||||
mcopy = m_copym(m, 0, M_COPYALL, M_NOWAIT);
|
||||
mcopy = m_copym(m, 0, M_COPYALL, M_DONTWAIT);
|
||||
if (mcopy == NULL) {
|
||||
error = ENOBUFS;
|
||||
return 0;
|
||||
}
|
||||
md0 = m_copym(md, 0, M_COPYALL, M_NOWAIT);
|
||||
md0 = m_copym(md, 0, M_COPYALL, M_DONTWAIT);
|
||||
if (md0 == NULL) {
|
||||
m_freem(mcopy);
|
||||
error = ENOBUFS;
|
||||
|
@ -152,7 +152,7 @@ key_sendup0(rp, m, promisc)
|
||||
if (promisc) {
|
||||
struct sadb_msg *pmsg;
|
||||
|
||||
M_PREPEND(m, sizeof(struct sadb_msg), M_NOWAIT);
|
||||
M_PREPEND(m, sizeof(struct sadb_msg), M_DONTWAIT);
|
||||
if (m && m->m_len < sizeof(struct sadb_msg))
|
||||
m = m_pullup(m, sizeof(struct sadb_msg));
|
||||
if (!m) {
|
||||
|
@ -147,7 +147,7 @@ key_sendup0(rp, m, promisc)
|
||||
if (promisc) {
|
||||
struct sadb_msg *pmsg;
|
||||
|
||||
M_PREPEND(m, sizeof(struct sadb_msg), M_NOWAIT);
|
||||
M_PREPEND(m, sizeof(struct sadb_msg), M_DONTWAIT);
|
||||
if (m && m->m_len < sizeof(struct sadb_msg))
|
||||
m = m_pullup(m, sizeof(struct sadb_msg));
|
||||
if (!m) {
|
||||
|
@ -648,7 +648,7 @@ smb_nbst_send(struct smb_vc *vcp, struct mbuf *m0, struct thread *td)
|
||||
error = ENOTCONN;
|
||||
goto abort;
|
||||
}
|
||||
M_PREPEND(m0, 4, M_WAITOK);
|
||||
M_PREPEND(m0, 4, M_TRYWAIT);
|
||||
if (m0 == NULL)
|
||||
return ENOBUFS;
|
||||
nb_sethdr(m0, NB_SSN_MESSAGE, m_fixhdr(m0) - 4);
|
||||
|
Loading…
Reference in New Issue
Block a user