Date: Thu, 18 Aug 2005 15:43:32 -0600 From: David Vos <david.vos@gmail.com> To: freebsd-net@freebsd.org Subject: netgraph memory trouble Message-ID: <16e39c5105081814432e922ec4@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
I have been playing with the netgraph ng_split node. I discovered that if I sent packets to it, after a period of time, I could no longer use netgraph. If I tried to use ngctl, I got an error back saying that it could not allocate memory to send a message. This also meant that I could not shutdown my nodes (because that required sending a message) and had to reboot my machine to start using netgraph again. vmstat -m would show netgraph_item having 128 items in use. I am sending data to the split node using the macro "NG_FWD_ITEM_HOOK". Since this macro nulls out the item pointer, I assume it takes full responsibility to free the item if something fails. The item then gets sent on to the function: static int ng_split_rcvdata(hook_p hook, item_p item) { =09const priv_p=09priv =3D NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); =09int=09=09error =3D 0; =09if (hook =3D=3D priv->out) { =09=09printf("ng_split: got packet from out hook!\n"); =09=09NG_FREE_ITEM(item); =09=09error =3D EINVAL; =09} else if ((hook =3D=3D priv->in) && (priv->mixed !=3D NULL)) { =09=09NG_FWD_ITEM_HOOK(error, item, priv->mixed); =09} else if ((hook =3D=3D priv->mixed) && (priv->out !=3D NULL)) { =09=09NG_FWD_ITEM_HOOK(error, item, priv->out); =09} =09return (error); } Unfortunately, if priv->mixed or priv->out are NULL, then there is no error generated, and the item is not freed. I modified the function to be: printf("ng_split: got packet hook=3D%x, priv->in=3D%x, priv->out=3D= %x priv->mixed=3D%x\n", hook, priv->in, priv->out, priv->mi= xed); if (hook =3D=3D priv->out) { printf("ng_split: got packet from out hook!\n"); NG_FREE_ITEM(item); error =3D EINVAL; } else if ((hook =3D=3D priv->in) && (priv->mixed !=3D NULL)) { NG_FWD_ITEM_HOOK(error, item, priv->mixed); } else if ((hook =3D=3D priv->mixed) && (priv->out !=3D NULL)) { NG_FWD_ITEM_HOOK(error, item, priv->out); } else { printf("ng_split: got packet from unknown hook, or output hook is null\n"); NG_FREE_ITEM(item); error =3D EINVAL; } In /var/log/messages, I get: Aug 18 15:31:50 foo kernel: ng_split: got packet hook=3Dc53f6800, priv->in=3Dc53f6800, priv->out=3Dc53f8c80 priv->mixed=3D0 Aug 18 15:31:50 foo kernel: ng_split: got packet from unknown hook, or output hook is null After making this modification to the code, I have not experienced any of the memory problems mentioned above. My conclusion is that an else clause needs to be added to the branches in the ng_split_rcfdata() function. I am using FreeBSD 5.4-RELEASE #1. David
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?16e39c5105081814432e922ec4>