From owner-freebsd-net@FreeBSD.ORG Thu Aug 18 21:43:33 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9578716A41F for ; Thu, 18 Aug 2005 21:43:33 +0000 (GMT) (envelope-from david.vos@gmail.com) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2DD8D43D48 for ; Thu, 18 Aug 2005 21:43:32 +0000 (GMT) (envelope-from david.vos@gmail.com) Received: by wproxy.gmail.com with SMTP id i22so416619wra for ; Thu, 18 Aug 2005 14:43:32 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=tBGXBKkxdNdQduAwkDirQBroccLaw/iHFZWP5XCkOZs1+sfIGx5ewSDO5tRJ7v3n6GLYCzzHrVf7v2liegO+/Y2tYQzzrCkYN2mu1bdKUGZNNEjyI4lc/bQAojjfbVYuqf6QEf2b/ypk3jI1h1ofQOZQPLxjgCX/Njiwn60gl1c= Received: by 10.54.36.35 with SMTP id j35mr1449541wrj; Thu, 18 Aug 2005 14:43:32 -0700 (PDT) Received: by 10.54.98.5 with HTTP; Thu, 18 Aug 2005 14:43:32 -0700 (PDT) Message-ID: <16e39c5105081814432e922ec4@mail.gmail.com> Date: Thu, 18 Aug 2005 15:43:32 -0600 From: David Vos To: freebsd-net@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: netgraph memory trouble X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2005 21:43:33 -0000 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