From nobody@FreeBSD.org  Sat Jul 11 13:22:57 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 672DD1065672
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 11 Jul 2009 13:22:57 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 556748FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 11 Jul 2009 13:22:57 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n6BDMtQu075867
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 11 Jul 2009 13:22:55 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n6BDMt7P075858;
	Sat, 11 Jul 2009 13:22:55 GMT
	(envelope-from nobody)
Message-Id: <200907111322.n6BDMt7P075858@www.freebsd.org>
Date: Sat, 11 Jul 2009 13:22:55 GMT
From: "Alexander V. Chernikov" <melifaro@ipfw.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ndp ignores -f option
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         136661
>Category:       bin
>Synopsis:       [patch] ndp(8) ignores -f option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    melifaro
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 11 13:30:01 UTC 2009
>Closed-Date:    
>Last-Modified:  Fri May  9 14:30:00 UTC 2014
>Originator:     Alexander V. Chernikov
>Release:        8.0-CURRENT
>Organization:
>Environment:
FreeBSD ws.ipfw.ru 8.0-CURRENT FreeBSD 8.0-CURRENT #6: Sat Jun 20 20:59:45 MSD 2009     root@ws.ipfw.ru:/usr/obj/usr/src/sys/WS  amd64

>Description:
According to ndp(8) manpage and ndp usage() -f flags can be used to make ndp parse file with ndp entries.

There is getopt "f:" option and file() function in ndp.c,
but there is no dispatcher of 'f' mode in second switch {}
>How-To-Repeat:
ktrace -tn ndp -f /dev/null ; kdump | grep /dev/null
>Fix:
Apply attached patch

Patch attached with submission follows:

--- usr.sbin/ndp/ndp.c.orig	2009-07-11 17:12:43.000000000 +0400
+++ usr.sbin/ndp/ndp.c	2009-07-11 17:14:35.000000000 +0400
@@ -246,6 +246,8 @@
 		}
 		delete(arg);
 		break;
+	case 'f':
+		exit(file(arg) ? 1 : 0);
 	case 'I':
 #ifdef SIOCSDEFIFACE_IN6	/* XXX: check SIOCGDEFIFACE_IN6 as well? */
 		if (argc > 1) {


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Mon Jan 4 20:00:59 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer(s).  Patch looks good (and fits the style of the rest of 
the file), but I'm not in any position to test it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=136661 

From: Sergey Kandaurov <pluknet@gmail.com>
To: bug-followup@FreeBSD.org, melifaro@ipfw.ru
Cc:  
Subject: Re: bin/136661: [patch] ndp(8) ignores -f option
Date: Fri, 29 Jul 2011 14:47:28 +0400

 The '-f' argument parsing was (accidentally?) removed with KAME sync in 2003.
 
 "make command line argument parsing POSIX compliant."
 http://svn.freebsd.org/changeset/base/122615
 
 http://www.kame.net/dev/cvsweb2.cgi/kame/kame/kame/ndp/ndp.c#rev1.92
Responsible-Changed-From-To: freebsd-net->melifaro 
Responsible-Changed-By: melifaro 
Responsible-Changed-When: Thu Nov 3 09:49:06 UTC 2011 
Responsible-Changed-Why:  
Take my own PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=136661 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/136661: commit references a PR
Date: Fri,  9 May 2014 14:24:06 +0000 (UTC)

 Author: melifaro
 Date: Fri May  9 14:24:02 2014
 New Revision: 265778
 URL: http://svnweb.freebsd.org/changeset/base/265778
 
 Log:
   Fix ndp(8) -f flag parsing
   
   PR:		bin/136661
   Reminded by:	Vinicius Zavam
   MFC after:	2 weeks
 
 Modified:
   head/usr.sbin/ndp/ndp.8
   head/usr.sbin/ndp/ndp.c
 
 Modified: head/usr.sbin/ndp/ndp.8
 ==============================================================================
 --- head/usr.sbin/ndp/ndp.8	Fri May  9 14:23:06 2014	(r265777)
 +++ head/usr.sbin/ndp/ndp.8	Fri May  9 14:24:02 2014	(r265778)
 @@ -29,7 +29,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd Jan 10, 2013
 +.Dd May 9, 2014
  .Dt NDP 8
  .Os
  .\"
 @@ -136,9 +136,26 @@ seconds.
  Erase all the NDP entries.
  .It Fl d
  Delete specified NDP entry.
 -.It Fl f
 -Parse the file specified by
 -.Ar filename .
 +.It Fl f Ar filename
 +Cause the file
 +.Ar filename
 +to be read and multiple entries to be set in the
 +.Tn NDP
 +table.
 +Entries
 +in the file should be of the form
 +.Pp
 +.Bd -ragged -offset indent -compact
 +.Ar hostname ether_addr
 +.Op Cm temp
 +.Op Cm proxy
 +.Ed
 +.Pp
 +with argument meanings as given above.
 +Leading whitespace and empty lines are ignored.
 +A
 +.Ql #
 +character will mark the rest of the line as a comment.
  .It Fl H
  Harmonize consistency between the routing table and the default router
  list; install the top entry of the list into the kernel routing table.
 
 Modified: head/usr.sbin/ndp/ndp.c
 ==============================================================================
 --- head/usr.sbin/ndp/ndp.c	Fri May  9 14:23:06 2014	(r265777)
 +++ head/usr.sbin/ndp/ndp.c	Fri May  9 14:24:02 2014	(r265778)
 @@ -97,6 +97,7 @@
  
  #include <arpa/inet.h>
  
 +#include <ctype.h>
  #include <netdb.h>
  #include <errno.h>
  #include <nlist.h>
 @@ -126,7 +127,7 @@ char host_buf[NI_MAXHOST];		/* getnamein
  char ifix_buf[IFNAMSIZ];		/* if_indextoname() */
  
  int main(int, char **);
 -int file(char *);
 +static int file(char *);
  void getsocket(void);
  int set(int, char **);
  void get(char *);
 @@ -189,7 +190,8 @@ main(int argc, char **argv)
  			break;
  		case 'd':
  		case 'f':
 -		case 'i' :
 +			exit(file(optarg) ? 1 : 0);
 +		case 'i':
  			if (mode) {
  				usage();
  				/*NOTREACHED*/
 @@ -312,17 +314,15 @@ main(int argc, char **argv)
  /*
   * Process a file to set standard ndp entries
   */
 -int
 +static int
  file(char *name)
  {
  	FILE *fp;
  	int i, retval;
 -	char line[100], arg[5][50], *args[5];
 +	char line[100], arg[5][50], *args[5], *p;
  
 -	if ((fp = fopen(name, "r")) == NULL) {
 -		fprintf(stderr, "ndp: cannot open %s\n", name);
 -		exit(1);
 -	}
 +	if ((fp = fopen(name, "r")) == NULL)
 +		err(1, "cannot open %s", name);
  	args[0] = &arg[0][0];
  	args[1] = &arg[1][0];
  	args[2] = &arg[2][0];
 @@ -330,10 +330,15 @@ file(char *name)
  	args[4] = &arg[4][0];
  	retval = 0;
  	while (fgets(line, sizeof(line), fp) != NULL) {
 +		if ((p = strchr(line, '#')) != NULL)
 +			*p = '\0';
 +		for (p = line; isblank(*p); p++);
 +		if (*p == '\n' || *p == '\0')
 +			continue;
  		i = sscanf(line, "%49s %49s %49s %49s %49s",
  		    arg[0], arg[1], arg[2], arg[3], arg[4]);
  		if (i < 2) {
 -			fprintf(stderr, "ndp: bad line: %s\n", line);
 +			warnx("bad line: %s", line);
  			retval = 1;
  			continue;
  		}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
