From D.Rock@t-online.de  Thu Dec 18 07:17:47 2003
Return-Path: <D.Rock@t-online.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id BD12116A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 18 Dec 2003 07:17:47 -0800 (PST)
Received: from mailout05.sul.t-online.com (mailout05.sul.t-online.com [194.25.134.82])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 26CB643D1F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 18 Dec 2003 07:17:45 -0800 (PST)
	(envelope-from D.Rock@t-online.de)
Received: from fwd09.aul.t-online.de 
	by mailout05.aul.t-online.de with smtp 
	id 1AW1xK-0005SR-00; Tue, 16 Dec 2003 00:16:50 +0100
Received: from dialin.t-online.de (VyF24+Z1Ye3sztsHrD06I0KGyoYwu3oEp5L+BVnCjJ5sf9ZaB3EJU+@[217.234.85.129]) by fwd09.sul.t-online.com
	with esmtp id 1AW1x6-1MMiJc0; Tue, 16 Dec 2003 00:16:36 +0100
Received: from gate.rock.net (gate [172.23.7.126])
	by dialin.t-online.de (8.12.10+Sun/8.12.10/Rock) with ESMTP id hBFNGG8f000849
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Dec 2003 00:16:16 +0100 (CET)
Received: from gate.rock.net (localhost [127.0.0.1])
	by gate.rock.net (8.12.10/8.12.9) with ESMTP id hBFNGFgg022703
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Dec 2003 00:16:15 +0100 (CET)
	(envelope-from rock@gate.rock.net)
Received: (from rock@localhost)
	by gate.rock.net (8.12.10/8.12.9/Submit) id hBFNGF75022702;
	Tue, 16 Dec 2003 00:16:15 +0100 (CET)
	(envelope-from rock)
Message-Id: <200312152316.hBFNGF75022702@gate.rock.net>
Date: Tue, 16 Dec 2003 00:16:15 +0100 (CET)
From: D.Rock@t-online.de (D. Rock)
Reply-To: "D. Rock" <D.Rock@t-online.de>
To: FreeBSD-gnats-submit@freebsd.org
Subject: performance problem /usr/sbin/ppp
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         60368
>Category:       bin
>Synopsis:       performance problem /usr/sbin/ppp
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jmg
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 18 07:20:15 PST 2003
>Closed-Date:    Wed Jun 16 16:59:45 GMT 2004
>Last-Modified:  Wed Jun 16 16:59:45 GMT 2004
>Originator:     D. Rock
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
>Environment:
System: FreeBSD gate.rock.net 5.2-CURRENT FreeBSD 5.2-CURRENT #832: Mon Dec 8 10:46:30 CET 2003 root@gate.rock.net:/export/common/src/sys/i386/compile/ROCK i386
>Description:
With filtering rules active user-PPP (/usr/sbin/ppp) consumes high CPU load
while filtering packets.
Caused by calling getprotobynumber() for each packet filtered, regardless
if there will be any logging output or not.
>How-To-Repeat:
Define filtering rules in your /etc/ppp/ppp.conf
do some performance tests on the PPP link
>Fix:
see patch below

--- ppp.diff begins here ---
Index: usr.sbin/ppp/ip.c
===================================================================
RCS file: /export/cvs/src/usr.sbin/ppp/ip.c,v
retrieving revision 1.100
diff -u -r1.100 ip.c
--- usr.sbin/ppp/ip.c	26 Mar 2003 02:27:32 -0000	1.100
+++ usr.sbin/ppp/ip.c	11 Dec 2003 22:20:27 -0000
@@ -161,6 +161,18 @@
   }
 }
 
+static char *toprototxt(int cproto)
+{
+  static char prototxt[16];
+  struct protoent *pe;
+
+  if ((pe = getprotobynumber(cproto)) == NULL)
+    snprintf(prototxt, sizeof prototxt, "%d", cproto);
+  else
+    snprintf(prototxt, sizeof prototxt, "%s", pe->p_name);
+  return prototxt;
+}
+
 /*
  * Check a packet against the given filter
  * Returns 0 to accept the packet, non-zero to drop the packet.
@@ -187,8 +199,7 @@
   int match;			/* true if condition matched */
   int mindata;			/* minimum data size or zero */
   const struct filterent *fp = filter->rule;
-  char dbuff[100], dstip[16], prototxt[16];
-  struct protoent *pe;
+  char dbuff[100], dstip[16];
   struct ncpaddr srcaddr, dstaddr;
   const char *payload;		/* IP payload */
   int datalen;			/* IP datagram length */
@@ -239,10 +250,6 @@
     cproto = pip->ip_p;
   }
 
-  if ((pe = getprotobynumber(cproto)) == NULL)
-    snprintf(prototxt, sizeof prototxt, "%d", cproto);
-  else
-    snprintf(prototxt, sizeof prototxt, "%s", pe->p_name);
   gotinfo = estab = syn = finrst = didname = 0;
   sport = dport = 0;
 
@@ -356,7 +363,7 @@
 
           if (datalen < mindata) {
             log_Printf(LogFILTER, " error: proto %s must be at least"
-                       " %d octets\n", prototxt, mindata);
+                       " %d octets\n", toprototxt(cproto), mindata);
             return 1;
           }
 
@@ -367,7 +374,8 @@
                        ", estab = %d, syn = %d, finrst = %d",
                        estab, syn, finrst);
             }
-            log_Printf(LogDEBUG, " Filter: proto = %s, %s\n", prototxt, dbuff);
+            log_Printf(LogDEBUG, " Filter: proto = %s, %s\n",
+                       toprototxt(cproto), dbuff);
           }
           gotinfo = 1;
         }
@@ -424,7 +432,8 @@
             if (log_IsKept(LogFILTER)) {
               snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr));
               log_Printf(LogFILTER, "%sbound rule = %d accept %s "
-                         "src = %s:%d dst = %s:%d\n", filter->name, n, prototxt,
+                         "src = %s:%d dst = %s:%d\n", filter->name, n,
+                         toprototxt(cproto),
                          ncpaddr_ntoa(&srcaddr), sport, dstip, dport);
             }
           }
@@ -434,7 +443,7 @@
             snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr));
             log_Printf(LogFILTER,
                        "%sbound rule = %d deny %s src = %s/%d dst = %s/%d\n",
-                       filter->name, n, prototxt,
+                       filter->name, n, toprototxt(cproto),
                        ncpaddr_ntoa(&srcaddr), sport, dstip, dport);
           }
           return 1;
@@ -450,7 +459,7 @@
     snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr));
     log_Printf(LogFILTER,
                "%sbound rule = implicit deny %s src = %s/%d dst = %s/%d\n",
-               filter->name, prototxt, ncpaddr_ntoa(&srcaddr), sport,
+               filter->name, toprototxt(cproto), ncpaddr_ntoa(&srcaddr), sport,
                dstip, dport);
   }
 
--- ppp.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jmg 
Responsible-Changed-By: jmg 
Responsible-Changed-When: Tue Dec 23 10:49:07 PST 2003 
Responsible-Changed-Why:  
I'm going to take a look at this.. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60368 
State-Changed-From-To: open->closed 
State-Changed-By: jmg 
State-Changed-When: Wed Jun 16 16:58:53 GMT 2004 
State-Changed-Why:  
dds committed a similar patch in v1.101, and MFC'd it in v1.78.2.12 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60368 
>Unformatted:
