Fix some memory leaks
Add memory leak detection assitance.
This commit is contained in:
parent
cb4e03f2d8
commit
bb6dbcf3b2
@ -50,8 +50,9 @@
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
/* debugging options */
|
||||
#define NETGRAPH_DEBUG
|
||||
#define NG_SEPARATE_MALLOC /* make modules use their own malloc types */
|
||||
|
||||
/*
|
||||
* This defines the in-kernel binary interface version.
|
||||
|
@ -59,6 +59,13 @@
|
||||
|
||||
#include <net/ppp_defs.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_ASYNC, "netgraph_async", "netgraph async node ");
|
||||
#else
|
||||
#define M_NETGRAPH_ASYNC M_NETGRAPH
|
||||
#endif
|
||||
|
||||
|
||||
/* Async decode state */
|
||||
#define MODE_HUNT 0
|
||||
#define MODE_NORMAL 1
|
||||
@ -178,7 +185,7 @@ nga_constructor(node_p node)
|
||||
{
|
||||
sc_p sc;
|
||||
|
||||
MALLOC(sc, sc_p, sizeof(*sc), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(sc, sc_p, sizeof(*sc), M_NETGRAPH_ASYNC, M_NOWAIT | M_ZERO);
|
||||
if (sc == NULL)
|
||||
return (ENOMEM);
|
||||
sc->amode = MODE_HUNT;
|
||||
@ -186,15 +193,15 @@ nga_constructor(node_p node)
|
||||
sc->cfg.amru = NG_ASYNC_DEFAULT_MRU;
|
||||
sc->cfg.smru = NG_ASYNC_DEFAULT_MRU;
|
||||
MALLOC(sc->abuf, u_char *,
|
||||
ASYNC_BUF_SIZE(sc->cfg.smru), M_NETGRAPH, M_NOWAIT);
|
||||
ASYNC_BUF_SIZE(sc->cfg.smru), M_NETGRAPH_ASYNC, M_NOWAIT);
|
||||
if (sc->abuf == NULL)
|
||||
goto fail;
|
||||
MALLOC(sc->sbuf, u_char *,
|
||||
SYNC_BUF_SIZE(sc->cfg.amru), M_NETGRAPH, M_NOWAIT);
|
||||
SYNC_BUF_SIZE(sc->cfg.amru), M_NETGRAPH_ASYNC, M_NOWAIT);
|
||||
if (sc->sbuf == NULL) {
|
||||
FREE(sc->abuf, M_NETGRAPH);
|
||||
FREE(sc->abuf, M_NETGRAPH_ASYNC);
|
||||
fail:
|
||||
FREE(sc, M_NETGRAPH);
|
||||
FREE(sc, M_NETGRAPH_ASYNC);
|
||||
return (ENOMEM);
|
||||
}
|
||||
NG_NODE_SET_PRIVATE(node, sc);
|
||||
@ -294,18 +301,18 @@ nga_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
||||
cfg->enabled = !!cfg->enabled; /* normalize */
|
||||
if (cfg->smru > sc->cfg.smru) { /* reallocate buffer */
|
||||
MALLOC(buf, u_char *, ASYNC_BUF_SIZE(cfg->smru),
|
||||
M_NETGRAPH, M_NOWAIT);
|
||||
M_NETGRAPH_ASYNC, M_NOWAIT);
|
||||
if (!buf)
|
||||
ERROUT(ENOMEM);
|
||||
FREE(sc->abuf, M_NETGRAPH);
|
||||
FREE(sc->abuf, M_NETGRAPH_ASYNC);
|
||||
sc->abuf = buf;
|
||||
}
|
||||
if (cfg->amru > sc->cfg.amru) { /* reallocate buffer */
|
||||
MALLOC(buf, u_char *, SYNC_BUF_SIZE(cfg->amru),
|
||||
M_NETGRAPH, M_NOWAIT);
|
||||
M_NETGRAPH_ASYNC, M_NOWAIT);
|
||||
if (!buf)
|
||||
ERROUT(ENOMEM);
|
||||
FREE(sc->sbuf, M_NETGRAPH);
|
||||
FREE(sc->sbuf, M_NETGRAPH_ASYNC);
|
||||
sc->sbuf = buf;
|
||||
sc->amode = MODE_HUNT;
|
||||
sc->slen = 0;
|
||||
@ -344,10 +351,10 @@ nga_shutdown(node_p node)
|
||||
{
|
||||
const sc_p sc = NG_NODE_PRIVATE(node);
|
||||
|
||||
FREE(sc->abuf, M_NETGRAPH);
|
||||
FREE(sc->sbuf, M_NETGRAPH);
|
||||
FREE(sc->abuf, M_NETGRAPH_ASYNC);
|
||||
FREE(sc->sbuf, M_NETGRAPH_ASYNC);
|
||||
bzero(sc, sizeof(*sc));
|
||||
FREE(sc, M_NETGRAPH);
|
||||
FREE(sc, M_NETGRAPH_ASYNC);
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node);
|
||||
return (0);
|
||||
|
@ -67,6 +67,12 @@
|
||||
#include <netgraph/ng_parse.h>
|
||||
#include <netgraph/ng_bpf.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_BPF, "netgraph_bpf", "netgraph bpf node ");
|
||||
#else
|
||||
#define M_NETGRAPH_BPF M_NETGRAPH
|
||||
#endif
|
||||
|
||||
#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
|
||||
|
||||
#define ERROUT(x) do { error = (x); goto done; } while (0)
|
||||
@ -233,7 +239,7 @@ ng_bpf_newhook(node_p node, hook_p hook, const char *name)
|
||||
int error;
|
||||
|
||||
/* Create hook private structure */
|
||||
MALLOC(hip, hinfo_p, sizeof(*hip), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(hip, hinfo_p, sizeof(*hip), M_NETGRAPH_BPF, M_NOWAIT | M_ZERO);
|
||||
if (hip == NULL)
|
||||
return (ENOMEM);
|
||||
hip->hook = hook;
|
||||
@ -242,7 +248,7 @@ ng_bpf_newhook(node_p node, hook_p hook, const char *name)
|
||||
|
||||
/* Attach the default BPF program */
|
||||
if ((error = ng_bpf_setprog(hook, &ng_bpf_default_prog)) != 0) {
|
||||
FREE(hip, M_NETGRAPH);
|
||||
FREE(hip, M_NETGRAPH_BPF);
|
||||
NG_HOOK_SET_PRIVATE(hook, NULL);
|
||||
return (error);
|
||||
}
|
||||
@ -391,7 +397,7 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
|
||||
/* Need to put packet in contiguous memory for bpf */
|
||||
if (m->m_next != NULL) {
|
||||
if (totlen > sizeof(buf)) {
|
||||
MALLOC(data, u_char *, totlen, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(data, u_char *, totlen, M_NETGRAPH_BPF, M_NOWAIT);
|
||||
if (data == NULL) {
|
||||
NG_FREE_ITEM(item);
|
||||
return (ENOMEM);
|
||||
@ -406,7 +412,7 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
|
||||
/* Run packet through filter */
|
||||
len = bpf_filter(hip->prog->bpf_prog, data, totlen, totlen);
|
||||
if (needfree)
|
||||
FREE(data, M_NETGRAPH);
|
||||
FREE(data, M_NETGRAPH_BPF);
|
||||
|
||||
/* See if we got a match and find destination hook */
|
||||
if (len > 0) {
|
||||
@ -457,9 +463,9 @@ ng_bpf_disconnect(hook_p hook)
|
||||
const hinfo_p hip = NG_HOOK_PRIVATE(hook);
|
||||
|
||||
KASSERT(hip != NULL, ("%s: null info", __FUNCTION__));
|
||||
FREE(hip->prog, M_NETGRAPH);
|
||||
FREE(hip->prog, M_NETGRAPH_BPF);
|
||||
bzero(hip, sizeof(*hip));
|
||||
FREE(hip, M_NETGRAPH);
|
||||
FREE(hip, M_NETGRAPH_BPF);
|
||||
NG_HOOK_SET_PRIVATE(hook, NULL); /* for good measure */
|
||||
if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
|
||||
&& (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
|
||||
@ -488,14 +494,14 @@ ng_bpf_setprog(hook_p hook, const struct ng_bpf_hookprog *hp0)
|
||||
|
||||
/* Make a copy of the program */
|
||||
size = NG_BPF_HOOKPROG_SIZE(hp0->bpf_prog_len);
|
||||
MALLOC(hp, struct ng_bpf_hookprog *, size, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(hp, struct ng_bpf_hookprog *, size, M_NETGRAPH_BPF, M_NOWAIT);
|
||||
if (hp == NULL)
|
||||
return (ENOMEM);
|
||||
bcopy(hp0, hp, size);
|
||||
|
||||
/* Free previous program, if any, and assign new one */
|
||||
if (hip->prog != NULL)
|
||||
FREE(hip->prog, M_NETGRAPH);
|
||||
FREE(hip->prog, M_NETGRAPH_BPF);
|
||||
hip->prog = hp;
|
||||
return (0);
|
||||
}
|
||||
|
@ -79,6 +79,12 @@
|
||||
#include <netgraph/ng_bridge.h>
|
||||
#include <netgraph/ng_ether.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_BRIDGE, "netgraph_bridge", "netgraph bridge node ");
|
||||
#else
|
||||
#define M_NETGRAPH_BRIDGE M_NETGRAPH
|
||||
#endif
|
||||
|
||||
/* Per-link private data */
|
||||
struct ng_bridge_link {
|
||||
hook_p hook; /* netgraph hook */
|
||||
@ -297,16 +303,16 @@ ng_bridge_constructor(node_p node)
|
||||
priv_p priv;
|
||||
|
||||
/* Allocate and initialize private info */
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO);
|
||||
if (priv == NULL)
|
||||
return (ENOMEM);
|
||||
callout_init(&priv->timer, 0);
|
||||
|
||||
/* Allocate and initialize hash table, etc. */
|
||||
MALLOC(priv->tab, struct ng_bridge_bucket *,
|
||||
MIN_BUCKETS * sizeof(*priv->tab), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MIN_BUCKETS * sizeof(*priv->tab), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO);
|
||||
if (priv->tab == NULL) {
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH_BRIDGE);
|
||||
return (ENOMEM);
|
||||
}
|
||||
priv->numBuckets = MIN_BUCKETS;
|
||||
@ -358,7 +364,7 @@ ng_bridge_newhook(node_p node, hook_p hook, const char *name)
|
||||
if (priv->links[linkNum] != NULL)
|
||||
return (EISCONN);
|
||||
MALLOC(priv->links[linkNum], struct ng_bridge_link *,
|
||||
sizeof(*priv->links[linkNum]), M_NETGRAPH, M_NOWAIT|M_ZERO);
|
||||
sizeof(*priv->links[linkNum]), M_NETGRAPH_BRIDGE, M_NOWAIT|M_ZERO);
|
||||
if (priv->links[linkNum] == NULL)
|
||||
return (ENOMEM);
|
||||
priv->links[linkNum]->hook = hook;
|
||||
@ -763,8 +769,8 @@ ng_bridge_shutdown(node_p node)
|
||||
KASSERT(priv->numLinks == 0 && priv->numHosts == 0,
|
||||
("%s: numLinks=%d numHosts=%d",
|
||||
__FUNCTION__, priv->numLinks, priv->numHosts));
|
||||
FREE(priv->tab, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv->tab, M_NETGRAPH_BRIDGE);
|
||||
FREE(priv, M_NETGRAPH_BRIDGE);
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node);
|
||||
return (0);
|
||||
@ -789,7 +795,7 @@ ng_bridge_disconnect(hook_p hook)
|
||||
|
||||
/* Free associated link information */
|
||||
KASSERT(priv->links[linkNum] != NULL, ("%s: no link", __FUNCTION__));
|
||||
FREE(priv->links[linkNum], M_NETGRAPH);
|
||||
FREE(priv->links[linkNum], M_NETGRAPH_BRIDGE);
|
||||
priv->links[linkNum] = NULL;
|
||||
priv->numLinks--;
|
||||
|
||||
@ -851,7 +857,7 @@ ng_bridge_put(priv_p priv, const u_char *addr, int linkNum)
|
||||
|
||||
/* Allocate and initialize new hashtable entry */
|
||||
MALLOC(hent, struct ng_bridge_hent *,
|
||||
sizeof(*hent), M_NETGRAPH, M_NOWAIT);
|
||||
sizeof(*hent), M_NETGRAPH_BRIDGE, M_NOWAIT);
|
||||
if (hent == NULL)
|
||||
return (0);
|
||||
bcopy(addr, hent->host.addr, ETHER_ADDR_LEN);
|
||||
@ -896,7 +902,7 @@ ng_bridge_rehash(priv_p priv)
|
||||
|
||||
/* Allocate and initialize new table */
|
||||
MALLOC(newTab, struct ng_bridge_bucket *,
|
||||
newNumBuckets * sizeof(*newTab), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
newNumBuckets * sizeof(*newTab), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO);
|
||||
if (newTab == NULL)
|
||||
return;
|
||||
|
||||
@ -920,7 +926,7 @@ ng_bridge_rehash(priv_p priv)
|
||||
ng_bridge_nodename(priv->node),
|
||||
priv->numBuckets, newNumBuckets);
|
||||
}
|
||||
FREE(priv->tab, M_NETGRAPH);
|
||||
FREE(priv->tab, M_NETGRAPH_BRIDGE);
|
||||
priv->numBuckets = newNumBuckets;
|
||||
priv->hashMask = newMask;
|
||||
priv->tab = newTab;
|
||||
@ -948,7 +954,7 @@ ng_bridge_remove_hosts(priv_p priv, int linkNum)
|
||||
|
||||
if (linkNum == -1 || hent->host.linkNum == linkNum) {
|
||||
*hptr = SLIST_NEXT(hent, next);
|
||||
FREE(hent, M_NETGRAPH);
|
||||
FREE(hent, M_NETGRAPH_BRIDGE);
|
||||
priv->numHosts--;
|
||||
} else
|
||||
hptr = &SLIST_NEXT(hent, next);
|
||||
@ -998,7 +1004,7 @@ ng_bridge_timeout(void *arg)
|
||||
/* Remove hosts we haven't heard from in a while */
|
||||
if (++hent->host.staleness >= priv->conf.maxStaleness) {
|
||||
*hptr = SLIST_NEXT(hent, next);
|
||||
FREE(hent, M_NETGRAPH);
|
||||
FREE(hent, M_NETGRAPH_BRIDGE);
|
||||
priv->numHosts--;
|
||||
} else {
|
||||
if (hent->host.age < 0xffff)
|
||||
|
@ -76,6 +76,12 @@
|
||||
#include <netgraph/ng_iface.h>
|
||||
#include <netgraph/ng_cisco.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_IFACE, "netgraph_iface", "netgraph iface node ");
|
||||
#else
|
||||
#define M_NETGRAPH_IFACE M_NETGRAPH
|
||||
#endif
|
||||
|
||||
/* This struct describes one address family */
|
||||
struct iffam {
|
||||
sa_family_t family; /* Address family */
|
||||
@ -200,6 +206,7 @@ NETGRAPH_INIT(iface, &typestruct);
|
||||
One means the unit number is free, zero means it's taken. */
|
||||
static int *ng_iface_units = NULL;
|
||||
static int ng_iface_units_len = 0;
|
||||
static int ng_units_in_use = 0;
|
||||
|
||||
#define UNITS_BITSPERWORD (sizeof(*ng_iface_units) * NBBY)
|
||||
|
||||
@ -281,7 +288,7 @@ ng_iface_get_unit(int *unit)
|
||||
|
||||
newlen = (2 * ng_iface_units_len) + 4;
|
||||
MALLOC(newarray, int *, newlen * sizeof(*ng_iface_units),
|
||||
M_NETGRAPH, M_NOWAIT);
|
||||
M_NETGRAPH_IFACE, M_NOWAIT);
|
||||
if (newarray == NULL)
|
||||
return (ENOMEM);
|
||||
bcopy(ng_iface_units, newarray,
|
||||
@ -289,7 +296,7 @@ ng_iface_get_unit(int *unit)
|
||||
for (i = ng_iface_units_len; i < newlen; i++)
|
||||
newarray[i] = ~0;
|
||||
if (ng_iface_units != NULL)
|
||||
FREE(ng_iface_units, M_NETGRAPH);
|
||||
FREE(ng_iface_units, M_NETGRAPH_IFACE);
|
||||
ng_iface_units = newarray;
|
||||
ng_iface_units_len = newlen;
|
||||
}
|
||||
@ -298,6 +305,7 @@ ng_iface_get_unit(int *unit)
|
||||
("%s: word=%d bit=%d", __FUNCTION__, ng_iface_units[index], bit));
|
||||
ng_iface_units[index] &= ~(1 << bit);
|
||||
*unit = (index * UNITS_BITSPERWORD) + bit;
|
||||
ng_units_in_use++;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -319,7 +327,15 @@ ng_iface_free_unit(int unit)
|
||||
/*
|
||||
* XXX We could think about reducing the size of ng_iface_units[]
|
||||
* XXX here if the last portion is all ones
|
||||
* XXX At least free it if no more units.
|
||||
* Needed if we are to eventually be able to unload.
|
||||
*/
|
||||
ng_units_in_use--;
|
||||
if (ng_units_in_use == 0) { /* XXX make SMP safe */
|
||||
FREE(ng_iface_units, M_NETGRAPH_IFACE);
|
||||
ng_iface_units_len = 0;
|
||||
ng_iface_units = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
@ -529,12 +545,12 @@ ng_iface_constructor(node_p node)
|
||||
int error = 0;
|
||||
|
||||
/* Allocate node and interface private structures */
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT|M_ZERO);
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH_IFACE, M_NOWAIT|M_ZERO);
|
||||
if (priv == NULL)
|
||||
return (ENOMEM);
|
||||
MALLOC(ifp, struct ifnet *, sizeof(*ifp), M_NETGRAPH, M_NOWAIT|M_ZERO);
|
||||
MALLOC(ifp, struct ifnet *, sizeof(*ifp), M_NETGRAPH_IFACE, M_NOWAIT|M_ZERO);
|
||||
if (ifp == NULL) {
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH_IFACE);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
@ -544,8 +560,8 @@ ng_iface_constructor(node_p node)
|
||||
|
||||
/* Get an interface unit number */
|
||||
if ((error = ng_iface_get_unit(&priv->unit)) != 0) {
|
||||
FREE(ifp, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(ifp, M_NETGRAPH_IFACE);
|
||||
FREE(priv, M_NETGRAPH_IFACE);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -750,9 +766,10 @@ ng_iface_shutdown(node_p node)
|
||||
|
||||
bpfdetach(priv->ifp);
|
||||
if_detach(priv->ifp);
|
||||
FREE(priv->ifp, M_NETGRAPH_IFACE);
|
||||
priv->ifp = NULL;
|
||||
ng_iface_free_unit(priv->unit);
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH_IFACE);
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node);
|
||||
return (0);
|
||||
|
@ -67,6 +67,12 @@
|
||||
#include <netinet/in.h>
|
||||
#include <netatalk/at.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_KSOCKET, "netgraph_ksock", "netgraph ksock node ");
|
||||
#else
|
||||
#define M_NETGRAPH_KSOCKET M_NETGRAPH
|
||||
#endif
|
||||
|
||||
#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
|
||||
#define SADATA_OFFSET (OFFSETOF(struct sockaddr, sa_data))
|
||||
|
||||
@ -224,17 +230,17 @@ ng_ksocket_sockaddr_parse(const struct ng_parse_type *type,
|
||||
return (EINVAL);
|
||||
pathlen = strlen(path);
|
||||
if (pathlen > SOCK_MAXADDRLEN) {
|
||||
FREE(path, M_NETGRAPH);
|
||||
FREE(path, M_NETGRAPH_KSOCKET);
|
||||
return (E2BIG);
|
||||
}
|
||||
if (*buflen < pathoff + pathlen) {
|
||||
FREE(path, M_NETGRAPH);
|
||||
FREE(path, M_NETGRAPH_KSOCKET);
|
||||
return (ERANGE);
|
||||
}
|
||||
*off += toklen;
|
||||
bcopy(path, sun->sun_path, pathlen);
|
||||
sun->sun_len = pathoff + pathlen;
|
||||
FREE(path, M_NETGRAPH);
|
||||
FREE(path, M_NETGRAPH_KSOCKET);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -309,7 +315,7 @@ ng_ksocket_sockaddr_unparse(const struct ng_parse_type *type,
|
||||
if ((pathtoken = ng_encode_string(pathbuf, pathlen)) == NULL)
|
||||
return (ENOMEM);
|
||||
slen += snprintf(cbuf, cbuflen, "local/%s", pathtoken);
|
||||
FREE(pathtoken, M_NETGRAPH);
|
||||
FREE(pathtoken, M_NETGRAPH_KSOCKET);
|
||||
if (slen >= cbuflen)
|
||||
return (ERANGE);
|
||||
*off += sun->sun_len;
|
||||
@ -489,7 +495,7 @@ ng_ksocket_constructor(node_p node)
|
||||
priv_p priv;
|
||||
|
||||
/* Allocate private structure */
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH_KSOCKET, M_NOWAIT | M_ZERO);
|
||||
if (priv == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
@ -805,7 +811,7 @@ ng_ksocket_shutdown(node_p node)
|
||||
|
||||
/* Take down netgraph node */
|
||||
bzero(priv, sizeof(*priv));
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH_KSOCKET);
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node); /* let the node escape */
|
||||
return (0);
|
||||
|
@ -329,9 +329,7 @@ nglmi_inquire(sc_p sc, int full)
|
||||
m->m_pkthdr.rcvif = NULL;
|
||||
/* Allocate a meta struct (and leave some slop for options to be
|
||||
* added by other modules). */
|
||||
/* MALLOC(meta, meta_p, sizeof( struct ng_meta) + META_PAD,
|
||||
* M_NETGRAPH, M_NOWAIT); */
|
||||
MALLOC(meta, meta_p, sizeof(*meta) + META_PAD, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(meta, meta_p, sizeof(*meta) + META_PAD, M_NETGRAPH_META, M_NOWAIT);
|
||||
if (meta != NULL) { /* if it failed, well, it was optional anyhow */
|
||||
meta->used_len = (u_short) sizeof(struct ng_meta);
|
||||
meta->allocated_len
|
||||
|
@ -65,6 +65,12 @@
|
||||
#error Need either NETGRAPH_MPPC_COMPRESSION or NETGRAPH_MPPC_ENCRYPTION
|
||||
#endif
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_MPPC, "netgraph_mppc", "netgraph mppc node ");
|
||||
#else
|
||||
#define M_NETGRAPH_MPPC M_NETGRAPH
|
||||
#endif
|
||||
|
||||
#ifdef NETGRAPH_MPPC_COMPRESSION
|
||||
/* XXX this file doesn't exist yet, but hopefully someday it will... */
|
||||
#include <net/mppc.h>
|
||||
@ -176,7 +182,7 @@ ng_mppc_constructor(node_p node)
|
||||
priv_p priv;
|
||||
|
||||
/* Allocate private structure */
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH_MPPC, M_NOWAIT | M_ZERO);
|
||||
if (priv == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
@ -263,14 +269,14 @@ ng_mppc_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
||||
#ifdef NETGRAPH_MPPC_COMPRESSION
|
||||
/* Initialize state buffers for compression */
|
||||
if (d->history != NULL) {
|
||||
FREE(d->history, M_NETGRAPH);
|
||||
FREE(d->history, M_NETGRAPH_MPPC);
|
||||
d->history = NULL;
|
||||
}
|
||||
if ((cfg->bits & MPPC_BIT) != 0) {
|
||||
MALLOC(d->history, u_char *,
|
||||
isComp ? MPPC_SizeOfCompressionHistory() :
|
||||
MPPC_SizeOfDecompressionHistory(),
|
||||
M_NETGRAPH, M_NOWAIT);
|
||||
M_NETGRAPH_MPPC, M_NOWAIT);
|
||||
if (d->history == NULL)
|
||||
ERROUT(ENOMEM);
|
||||
if (isComp)
|
||||
@ -395,12 +401,12 @@ ng_mppc_shutdown(node_p node)
|
||||
/* Take down netgraph node */
|
||||
#ifdef NETGRAPH_MPPC_COMPRESSION
|
||||
if (priv->xmit.history != NULL)
|
||||
FREE(priv->xmit.history, M_NETGRAPH);
|
||||
FREE(priv->xmit.history, M_NETGRAPH_MPPC);
|
||||
if (priv->recv.history != NULL)
|
||||
FREE(priv->recv.history, M_NETGRAPH);
|
||||
FREE(priv->recv.history, M_NETGRAPH_MPPC);
|
||||
#endif
|
||||
bzero(priv, sizeof(*priv));
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH_MPPC);
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node); /* let the node escape */
|
||||
return (0);
|
||||
@ -455,7 +461,7 @@ ng_mppc_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
|
||||
|
||||
/* Work with contiguous regions of memory */
|
||||
inlen = m->m_pkthdr.len;
|
||||
MALLOC(inbuf, u_char *, inlen, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(inbuf, u_char *, inlen, M_NETGRAPH_MPPC, M_NOWAIT);
|
||||
if (inbuf == NULL)
|
||||
return (ENOMEM);
|
||||
m_copydata(m, 0, inlen, (caddr_t)inbuf);
|
||||
@ -463,9 +469,9 @@ ng_mppc_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
|
||||
outlen = MPPC_MAX_BLOWUP(inlen);
|
||||
else
|
||||
outlen = MPPC_HDRLEN + inlen;
|
||||
MALLOC(outbuf, u_char *, outlen, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(outbuf, u_char *, outlen, M_NETGRAPH_MPPC, M_NOWAIT);
|
||||
if (outbuf == NULL) {
|
||||
FREE(inbuf, M_NETGRAPH);
|
||||
FREE(inbuf, M_NETGRAPH_MPPC);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
@ -508,7 +514,7 @@ ng_mppc_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
|
||||
bcopy(inbuf, outbuf + MPPC_HDRLEN, inlen);
|
||||
outlen = MPPC_HDRLEN + inlen;
|
||||
}
|
||||
FREE(inbuf, M_NETGRAPH);
|
||||
FREE(inbuf, M_NETGRAPH_MPPC);
|
||||
|
||||
/* Always set the flushed bit in stateless mode */
|
||||
if ((d->cfg.bits & MPPE_STATELESS) != 0)
|
||||
@ -544,7 +550,7 @@ ng_mppc_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
|
||||
|
||||
/* Return packet in an mbuf */
|
||||
*resultp = m_devget((caddr_t)outbuf, outlen, 0, NULL, NULL);
|
||||
FREE(outbuf, M_NETGRAPH);
|
||||
FREE(outbuf, M_NETGRAPH_MPPC);
|
||||
return (*resultp == NULL ? ENOBUFS : 0);
|
||||
}
|
||||
|
||||
@ -570,7 +576,7 @@ ng_mppc_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
|
||||
|
||||
/* Copy payload into a contiguous region of memory */
|
||||
len = m->m_pkthdr.len - MPPC_HDRLEN;
|
||||
MALLOC(buf, u_char *, len, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(buf, u_char *, len, M_NETGRAPH_MPPC, M_NOWAIT);
|
||||
if (buf == NULL)
|
||||
return (ENOMEM);
|
||||
m_copydata(m, MPPC_HDRLEN, len, (caddr_t)buf);
|
||||
@ -656,7 +662,7 @@ ng_mppc_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
|
||||
log(LOG_ERR, "%s: rec'd unexpectedly %s packet",
|
||||
__FUNCTION__, "compressed");
|
||||
failed:
|
||||
FREE(buf, M_NETGRAPH);
|
||||
FREE(buf, M_NETGRAPH_MPPC);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
@ -670,9 +676,9 @@ failed:
|
||||
|
||||
/* Allocate a buffer for decompressed data */
|
||||
MALLOC(decompbuf, u_char *, MPPC_DECOMP_BUFSIZE
|
||||
+ MPPC_DECOMP_SAFETY, M_NETGRAPH, M_NOWAIT);
|
||||
+ MPPC_DECOMP_SAFETY, M_NETGRAPH_MPPC, M_NOWAIT);
|
||||
if (decompbuf == NULL) {
|
||||
FREE(buf, M_NETGRAPH);
|
||||
FREE(buf, M_NETGRAPH_MPPC);
|
||||
return (ENOMEM);
|
||||
}
|
||||
decomplen = MPPC_DECOMP_BUFSIZE;
|
||||
@ -695,12 +701,12 @@ failed:
|
||||
|| (rtn & MPPC_DECOMP_OK) != MPPC_DECOMP_OK) {
|
||||
log(LOG_ERR, "%s: decomp returned 0x%x",
|
||||
__FUNCTION__, rtn);
|
||||
FREE(decompbuf, M_NETGRAPH);
|
||||
FREE(decompbuf, M_NETGRAPH_MPPC);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
/* Replace compressed data with decompressed data */
|
||||
FREE(buf, M_NETGRAPH);
|
||||
FREE(buf, M_NETGRAPH_MPPC);
|
||||
buf = decompbuf;
|
||||
len = decomplen - destCnt;
|
||||
}
|
||||
@ -708,7 +714,7 @@ failed:
|
||||
|
||||
/* Return result in an mbuf */
|
||||
*resultp = m_devget((caddr_t)buf, len, 0, NULL, NULL);
|
||||
FREE(buf, M_NETGRAPH);
|
||||
FREE(buf, M_NETGRAPH_MPPC);
|
||||
return (*resultp == NULL ? ENOBUFS : 0);
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/ctype.h>
|
||||
@ -53,6 +54,12 @@
|
||||
#include <netgraph/netgraph.h>
|
||||
#include <netgraph/ng_parse.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_PARSE, "netgraph_parse", "netgraph parse info");
|
||||
#else
|
||||
#define M_NETGRAPH_PARSE M_NETGRAPH
|
||||
#endif
|
||||
|
||||
/* Compute alignment for primitive integral types */
|
||||
struct int16_temp {
|
||||
char x;
|
||||
@ -714,7 +721,7 @@ ng_string_parse(const struct ng_parse_type *type,
|
||||
return (EINVAL);
|
||||
*off += len;
|
||||
bcopy(sval, buf, slen + 1);
|
||||
FREE(sval, M_NETGRAPH);
|
||||
FREE(sval, M_NETGRAPH_PARSE);
|
||||
*buflen = slen + 1;
|
||||
return (0);
|
||||
}
|
||||
@ -730,7 +737,7 @@ ng_string_unparse(const struct ng_parse_type *type,
|
||||
return (ENOMEM);
|
||||
NG_PARSE_APPEND("%s", s);
|
||||
*off += strlen(raw) + 1;
|
||||
FREE(s, M_NETGRAPH);
|
||||
FREE(s, M_NETGRAPH_PARSE);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -776,7 +783,7 @@ ng_fixedstring_parse(const struct ng_parse_type *type,
|
||||
return (E2BIG);
|
||||
*off += len;
|
||||
bcopy(sval, buf, slen);
|
||||
FREE(sval, M_NETGRAPH);
|
||||
FREE(sval, M_NETGRAPH_PARSE);
|
||||
bzero(buf + slen, fi->bufSize - slen);
|
||||
*buflen = fi->bufSize;
|
||||
return (0);
|
||||
@ -878,7 +885,7 @@ ng_sizedstring_parse(const struct ng_parse_type *type,
|
||||
*off += len;
|
||||
*((u_int16_t *)buf) = (u_int16_t)slen;
|
||||
bcopy(sval, buf + 2, slen);
|
||||
FREE(sval, M_NETGRAPH);
|
||||
FREE(sval, M_NETGRAPH_PARSE);
|
||||
*buflen = 2 + slen;
|
||||
return (0);
|
||||
}
|
||||
@ -894,7 +901,7 @@ ng_sizedstring_unparse(const struct ng_parse_type *type,
|
||||
if (s == NULL)
|
||||
return (ENOMEM);
|
||||
NG_PARSE_APPEND("%s", s);
|
||||
FREE(s, M_NETGRAPH);
|
||||
FREE(s, M_NETGRAPH_PARSE);
|
||||
*off += slen + 2;
|
||||
return (0);
|
||||
}
|
||||
@ -1020,16 +1027,16 @@ ng_bytearray_parse(const struct ng_parse_type *type,
|
||||
|
||||
arraylen = (*getLength)(type, start, buf);
|
||||
if (arraylen > *buflen) {
|
||||
FREE(str, M_NETGRAPH);
|
||||
FREE(str, M_NETGRAPH_PARSE);
|
||||
return (ERANGE);
|
||||
}
|
||||
if (slen > arraylen) {
|
||||
FREE(str, M_NETGRAPH);
|
||||
FREE(str, M_NETGRAPH_PARSE);
|
||||
return (E2BIG);
|
||||
}
|
||||
bcopy(str, buf, slen);
|
||||
bzero(buf + slen, arraylen - slen);
|
||||
FREE(str, M_NETGRAPH);
|
||||
FREE(str, M_NETGRAPH_PARSE);
|
||||
*off += toklen;
|
||||
*buflen = arraylen;
|
||||
return (0);
|
||||
@ -1122,7 +1129,7 @@ ng_parse_composite(const struct ng_parse_type *type, const char *s,
|
||||
int align, len, blen, error = 0;
|
||||
|
||||
/* Initialize */
|
||||
MALLOC(foff, int *, num * sizeof(*foff), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(foff, int *, num * sizeof(*foff), M_NETGRAPH_PARSE, M_NOWAIT | M_ZERO);
|
||||
if (foff == NULL) {
|
||||
error = ENOMEM;
|
||||
goto done;
|
||||
@ -1276,7 +1283,7 @@ gotIndex:
|
||||
*buflen = blen;
|
||||
done:
|
||||
if (foff != NULL)
|
||||
FREE(foff, M_NETGRAPH);
|
||||
FREE(foff, M_NETGRAPH_PARSE);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -1294,7 +1301,7 @@ ng_unparse_composite(const struct ng_parse_type *type, const u_char *data,
|
||||
u_char *workBuf;
|
||||
|
||||
/* Get workspace for checking default values */
|
||||
MALLOC(workBuf, u_char *, workSize, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(workBuf, u_char *, workSize, M_NETGRAPH_PARSE, M_NOWAIT);
|
||||
if (workBuf == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
@ -1340,14 +1347,14 @@ ng_unparse_composite(const struct ng_parse_type *type, const u_char *data,
|
||||
/* Print value */
|
||||
if ((error = INVOKE(etype, unparse)
|
||||
(etype, data, off, cbuf, cbuflen)) != 0) {
|
||||
FREE(workBuf, M_NETGRAPH);
|
||||
FREE(workBuf, M_NETGRAPH_PARSE);
|
||||
return (error);
|
||||
}
|
||||
cbuflen -= strlen(cbuf);
|
||||
cbuf += strlen(cbuf);
|
||||
didOne = 1;
|
||||
}
|
||||
FREE(workBuf, M_NETGRAPH);
|
||||
FREE(workBuf, M_NETGRAPH_PARSE);
|
||||
|
||||
/* Closing brace/bracket */
|
||||
NG_PARSE_APPEND("%s%c",
|
||||
@ -1581,7 +1588,7 @@ ng_parse_get_token(const char *s, int *startp, int *lenp)
|
||||
case '"':
|
||||
if ((t = ng_get_string_token(s, startp, lenp, NULL)) == NULL)
|
||||
return T_ERROR;
|
||||
FREE(t, M_NETGRAPH);
|
||||
FREE(t, M_NETGRAPH_PARSE);
|
||||
return T_STRING;
|
||||
default:
|
||||
for (i = *startp + 1; s[i] != '\0' && !isspace(s[i])
|
||||
@ -1609,7 +1616,7 @@ ng_get_string_token(const char *s, int *startp, int *lenp, int *slenp)
|
||||
start = *startp;
|
||||
if (s[*startp] != '"')
|
||||
return (NULL);
|
||||
MALLOC(cbuf, char *, strlen(s + start), M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(cbuf, char *, strlen(s + start), M_NETGRAPH_PARSE, M_NOWAIT);
|
||||
if (cbuf == NULL)
|
||||
return (NULL);
|
||||
strcpy(cbuf, s + start + 1);
|
||||
@ -1691,7 +1698,7 @@ ng_encode_string(const char *raw, int slen)
|
||||
int off = 0;
|
||||
int i;
|
||||
|
||||
MALLOC(cbuf, char *, strlen(raw) * 4 + 3, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(cbuf, char *, strlen(raw) * 4 + 3, M_NETGRAPH_PARSE, M_NOWAIT);
|
||||
if (cbuf == NULL)
|
||||
return (NULL);
|
||||
cbuf[off++] = '"';
|
||||
|
@ -61,6 +61,12 @@
|
||||
#include <netgraph/ng_ppp.h>
|
||||
#include <netgraph/ng_vjc.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_PPP, "netgraph_ppp", "netgraph ppp node");
|
||||
#else
|
||||
#define M_NETGRAPH_PPP M_NETGRAPH
|
||||
#endif
|
||||
|
||||
#define PROT_VALID(p) (((p) & 0x0101) == 0x0001)
|
||||
#define PROT_COMPRESSABLE(p) (((p) & 0xff00) == 0x0000)
|
||||
|
||||
@ -382,7 +388,7 @@ ng_ppp_constructor(node_p node)
|
||||
int i;
|
||||
|
||||
/* Allocate private structure */
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH_PPP, M_NOWAIT | M_ZERO);
|
||||
if (priv == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
@ -805,7 +811,7 @@ ng_ppp_shutdown(node_p node)
|
||||
/* Take down netgraph node */
|
||||
ng_ppp_frag_reset(node);
|
||||
bzero(priv, sizeof(*priv));
|
||||
FREE(priv, M_NETGRAPH);
|
||||
FREE(priv, M_NETGRAPH_PPP);
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node); /* let the node escape */
|
||||
return (0);
|
||||
@ -1149,7 +1155,7 @@ ng_ppp_mp_input(node_p node, int linkNum, item_p item)
|
||||
}
|
||||
|
||||
/* Allocate a new frag struct for the queue */
|
||||
MALLOC(frag, struct ng_ppp_frag *, sizeof(*frag), M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(frag, struct ng_ppp_frag *, sizeof(*frag), M_NETGRAPH_PPP, M_NOWAIT);
|
||||
if (frag == NULL) {
|
||||
NG_FREE_M(m);
|
||||
NG_FREE_META(meta);
|
||||
@ -1170,7 +1176,7 @@ ng_ppp_mp_input(node_p node, int linkNum, item_p item)
|
||||
link->stats.dupFragments++;
|
||||
NG_FREE_M(frag->data);
|
||||
NG_FREE_META(frag->meta);
|
||||
FREE(frag, M_NETGRAPH);
|
||||
FREE(frag, M_NETGRAPH_PPP);
|
||||
return (EINVAL);
|
||||
}
|
||||
}
|
||||
@ -1247,7 +1253,7 @@ ng_ppp_get_packet(node_p node, struct mbuf **mp, meta_p *metap)
|
||||
tail = tail->m_next;
|
||||
if (qent->last)
|
||||
qnext = NULL;
|
||||
FREE(qent, M_NETGRAPH);
|
||||
FREE(qent, M_NETGRAPH_PPP);
|
||||
priv->qlen--;
|
||||
}
|
||||
*mp = m;
|
||||
@ -1297,7 +1303,7 @@ ng_ppp_frag_trim(node_p node)
|
||||
TAILQ_REMOVE(&priv->frags, qent, f_qent);
|
||||
NG_FREE_M(qent->data);
|
||||
NG_FREE_META(qent->meta);
|
||||
FREE(qent, M_NETGRAPH);
|
||||
FREE(qent, M_NETGRAPH_PPP);
|
||||
priv->qlen--;
|
||||
removed = 1;
|
||||
}
|
||||
@ -1363,7 +1369,7 @@ ng_ppp_frag_process(node_p node)
|
||||
TAILQ_REMOVE(&priv->frags, qent, f_qent);
|
||||
NG_FREE_M(qent->data);
|
||||
NG_FREE_META(qent->meta);
|
||||
FREE(qent, M_NETGRAPH);
|
||||
FREE(qent, M_NETGRAPH_PPP);
|
||||
priv->qlen--;
|
||||
|
||||
/* Process queue again */
|
||||
@ -1441,7 +1447,7 @@ ng_ppp_frag_checkstale(node_p node)
|
||||
TAILQ_REMOVE(&priv->frags, qent, f_qent);
|
||||
NG_FREE_M(qent->data);
|
||||
NG_FREE_META(qent->meta);
|
||||
FREE(qent, M_NETGRAPH);
|
||||
FREE(qent, M_NETGRAPH_PPP);
|
||||
priv->qlen--;
|
||||
}
|
||||
|
||||
@ -2036,7 +2042,7 @@ ng_ppp_frag_reset(node_p node)
|
||||
qnext = TAILQ_NEXT(qent, f_qent);
|
||||
NG_FREE_M(qent->data);
|
||||
NG_FREE_META(qent->meta);
|
||||
FREE(qent, M_NETGRAPH);
|
||||
FREE(qent, M_NETGRAPH_PPP);
|
||||
}
|
||||
TAILQ_INIT(&priv->frags);
|
||||
priv->qlen = 0;
|
||||
|
@ -60,6 +60,12 @@
|
||||
#include <netgraph/ng_parse.h>
|
||||
#include <netgraph/ng_pppoe.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_PPPOE, "netgraph_pppoe", "netgraph pppoe node");
|
||||
#else
|
||||
#define M_NETGRAPH_PPPOE M_NETGRAPH
|
||||
#endif
|
||||
|
||||
#define SIGNOFF "session closed"
|
||||
#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
|
||||
|
||||
@ -538,7 +544,7 @@ ng_pppoe_constructor(node_p node)
|
||||
|
||||
AAA
|
||||
/* Initialize private descriptor */
|
||||
MALLOC(privdata, priv_p, sizeof(*privdata), M_NETGRAPH,
|
||||
MALLOC(privdata, priv_p, sizeof(*privdata), M_NETGRAPH_PPPOE,
|
||||
M_NOWAIT | M_ZERO);
|
||||
if (privdata == NULL)
|
||||
return (ENOMEM);
|
||||
@ -577,7 +583,7 @@ AAA
|
||||
* The infrastructure has already checked that it's unique,
|
||||
* so just allocate it and hook it in.
|
||||
*/
|
||||
MALLOC(sp, sessp, sizeof(*sp), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||
MALLOC(sp, sessp, sizeof(*sp), M_NETGRAPH_PPPOE, M_NOWAIT | M_ZERO);
|
||||
if (sp == NULL) {
|
||||
return (ENOMEM);
|
||||
}
|
||||
@ -667,7 +673,7 @@ AAA
|
||||
/*
|
||||
* set up prototype header
|
||||
*/
|
||||
MALLOC(neg, negp, sizeof(*neg), M_NETGRAPH,
|
||||
MALLOC(neg, negp, sizeof(*neg), M_NETGRAPH_PPPOE,
|
||||
M_NOWAIT | M_ZERO);
|
||||
|
||||
if (neg == NULL) {
|
||||
@ -677,7 +683,7 @@ AAA
|
||||
MGETHDR(neg->m, M_DONTWAIT, MT_DATA);
|
||||
if(neg->m == NULL) {
|
||||
printf("pppoe: Session out of mbufs\n");
|
||||
FREE(neg, M_NETGRAPH);
|
||||
FREE(neg, M_NETGRAPH_PPPOE);
|
||||
LEAVE(ENOBUFS);
|
||||
}
|
||||
neg->m->m_pkthdr.rcvif = NULL;
|
||||
@ -685,7 +691,7 @@ AAA
|
||||
if ((neg->m->m_flags & M_EXT) == 0) {
|
||||
printf("pppoe: Session out of mcls\n");
|
||||
m_freem(neg->m);
|
||||
FREE(neg, M_NETGRAPH);
|
||||
FREE(neg, M_NETGRAPH_PPPOE);
|
||||
LEAVE(ENOBUFS);
|
||||
}
|
||||
sp->neg = neg;
|
||||
@ -1141,7 +1147,7 @@ AAA
|
||||
= ETHERTYPE_PPPOE_SESS;
|
||||
sp->pkt_hdr.ph.code = 0;
|
||||
m_freem(neg->m);
|
||||
FREE(sp->neg, M_NETGRAPH);
|
||||
FREE(sp->neg, M_NETGRAPH_PPPOE);
|
||||
sp->neg = NULL;
|
||||
pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
|
||||
break;
|
||||
@ -1199,7 +1205,7 @@ AAA
|
||||
m_freem(sp->neg->m);
|
||||
untimeout(pppoe_ticker, sendhook,
|
||||
sp->neg->timeout_handle);
|
||||
FREE(sp->neg, M_NETGRAPH);
|
||||
FREE(sp->neg, M_NETGRAPH_PPPOE);
|
||||
sp->neg = NULL;
|
||||
} else {
|
||||
LEAVE (ENETUNREACH);
|
||||
@ -1354,7 +1360,7 @@ ng_pppoe_shutdown(node_p node)
|
||||
AAA
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(privdata->node);
|
||||
FREE(privdata, M_NETGRAPH);
|
||||
FREE(privdata, M_NETGRAPH_PPPOE);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -1448,9 +1454,9 @@ AAA
|
||||
untimeout(pppoe_ticker, hook, sp->neg->timeout_handle);
|
||||
if (sp->neg->m)
|
||||
m_freem(sp->neg->m);
|
||||
FREE(sp->neg, M_NETGRAPH);
|
||||
FREE(sp->neg, M_NETGRAPH_PPPOE);
|
||||
}
|
||||
FREE(sp, M_NETGRAPH);
|
||||
FREE(sp, M_NETGRAPH_PPPOE);
|
||||
NG_HOOK_SET_PRIVATE(hook, NULL);
|
||||
/* work out how many session hooks there are */
|
||||
/* Node goes away on last session hook removal */
|
||||
|
@ -54,6 +54,14 @@
|
||||
#include <netgraph/ng_sample.h>
|
||||
#include <netgraph/netgraph.h>
|
||||
|
||||
/* If you do complicated mallocs you may want to do this */
|
||||
/* and use it for your mallocs */
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_XXX, "netgraph_xxx", "netgraph xxx node ");
|
||||
#else
|
||||
#define M_NETGRAPH_XXX M_NETGRAPH
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This section contains the netgraph method declarations for the
|
||||
* sample node. These methods define the netgraph 'type'.
|
||||
|
@ -69,6 +69,14 @@
|
||||
#include <netgraph/ng_socketvar.h>
|
||||
#include <netgraph/ng_socket.h>
|
||||
|
||||
#ifdef NG_SEPARATE_MALLOC
|
||||
MALLOC_DEFINE(M_NETGRAPH_PATH, "netgraph_path", "netgraph path info ");
|
||||
MALLOC_DEFINE(M_NETGRAPH_SOCK, "netgraph_sock", "netgraph socket info ");
|
||||
#else
|
||||
#define M_NETGRAPH_PATH M_NETGRAPH
|
||||
#define M_NETGRAPH_SOCK M_NETGRAPH
|
||||
#endif
|
||||
|
||||
/*
|
||||
* It's Ascii-art time!
|
||||
* +-------------+ +-------------+
|
||||
@ -213,7 +221,7 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
||||
/* Allocate an expendable buffer for the path, chop off
|
||||
* the sockaddr header, and make sure it's NUL terminated */
|
||||
len = sap->sg_len - 2;
|
||||
MALLOC(path, char *, len + 1, M_NETGRAPH, M_WAITOK);
|
||||
MALLOC(path, char *, len + 1, M_NETGRAPH_PATH, M_WAITOK);
|
||||
if (path == NULL) {
|
||||
error = ENOMEM;
|
||||
goto release;
|
||||
@ -269,7 +277,7 @@ printf("errx=%d\n",error);
|
||||
#endif
|
||||
release:
|
||||
if (path != NULL)
|
||||
FREE(path, M_NETGRAPH);
|
||||
FREE(path, M_NETGRAPH_PATH);
|
||||
if (control != NULL)
|
||||
m_freem(control);
|
||||
if (m != NULL)
|
||||
@ -457,7 +465,7 @@ ng_attach_cntl(struct socket *so)
|
||||
|
||||
/* Allocate node private info */
|
||||
MALLOC(privdata, struct ngsock *,
|
||||
sizeof(*privdata), M_NETGRAPH, M_WAITOK | M_ZERO);
|
||||
sizeof(*privdata), M_NETGRAPH_SOCK, M_WAITOK | M_ZERO);
|
||||
if (privdata == NULL) {
|
||||
ng_detach_common(pcbp, NG_CONTROL);
|
||||
return (ENOMEM);
|
||||
@ -465,7 +473,7 @@ ng_attach_cntl(struct socket *so)
|
||||
|
||||
/* Make the generic node components */
|
||||
if ((error = ng_make_node_common(&typestruct, &privdata->node)) != 0) {
|
||||
FREE(privdata, M_NETGRAPH);
|
||||
FREE(privdata, M_NETGRAPH_SOCK);
|
||||
ng_detach_common(pcbp, NG_CONTROL);
|
||||
return (error);
|
||||
}
|
||||
@ -800,7 +808,7 @@ msg->header.token);
|
||||
/* Get the return address into a sockaddr */
|
||||
sprintf(retabuf,"[%x]:", retaddr);
|
||||
addrlen = strlen(retabuf);
|
||||
MALLOC(addr, struct sockaddr_ng *, addrlen + 4, M_NETGRAPH, M_NOWAIT);
|
||||
MALLOC(addr, struct sockaddr_ng *, addrlen + 4, M_NETGRAPH_PATH, M_NOWAIT);
|
||||
if (addr == NULL) {
|
||||
TRAP_ERROR;
|
||||
return (ENOMEM);
|
||||
@ -812,7 +820,7 @@ msg->header.token);
|
||||
|
||||
/* Send it up */
|
||||
error = ship_msg(pcbp, msg, addr);
|
||||
FREE(addr, M_NETGRAPH);
|
||||
FREE(addr, M_NETGRAPH_PATH);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -902,7 +910,7 @@ ngs_shutdown(node_p node)
|
||||
}
|
||||
NG_NODE_SET_PRIVATE(node, NULL);
|
||||
NG_NODE_UNREF(node);
|
||||
FREE(sockdata, M_NETGRAPH);
|
||||
FREE(sockdata, M_NETGRAPH_SOCK);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user