NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/53974: arp(8): Attempting to set many ARP entries with -f option, it can cause "socket: Too many open files" error.



The following reply was made to PR bin/53974; it has been noted by GNATS.

From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/53974: arp(8): Attempting to set many ARP entries with -f
 option, it can cause "socket: Too many open files" error.
Date: Tue, 26 Feb 2019 07:26:28 +0000

 On Sun, Feb 17, 2019 at 02:20:01AM +0000, David Holland wrote:
  >  I'm not really in a position to test the following right now so please
  >  let me know if it works and doesn't blow things up.
 
 It blows rumpity things up.
 
 current candidate:
 
 Index: arp.c
 ===================================================================
 RCS file: /cvsroot/src/usr.sbin/arp/arp.c,v
 retrieving revision 1.63
 diff -u -p -r1.63 arp.c
 --- arp.c	31 Jul 2018 09:45:52 -0000	1.63
 +++ arp.c	26 Feb 2019 07:19:19 -0000
 @@ -276,8 +276,10 @@ set(int argc, char **argv)
  	argc -= 2;
  	argv += 2;
  
 -	if (getinetaddr(host, &sin_m.sin_addr) == -1)
 +	if (getinetaddr(host, &sin_m.sin_addr) == -1) {
 +		prog_close(s);
  		return (1);
 +	}
  	if (strcmp(eaddr, "auto") != 0 && atosdl(eaddr, &sdl_m))
  		warnx("invalid link-level address '%s'", eaddr);
  	doing_proxy = flags = export_only = expire_time = 0;
 @@ -310,13 +312,16 @@ set(int argc, char **argv)
  
  	}
  	if (doing_proxy && strcmp(eaddr, "auto") == 0) {
 -		if (getetheraddr(sin_m.sin_addr, &sdl_m) == -1)
 +		if (getetheraddr(sin_m.sin_addr, &sdl_m) == -1) {
 +			prog_close(s);
  			return 1;
 +		}
  	}
  tryagain:
  	rtm = rtmsg(s, RTM_GET, NULL, &sin_m, &sdl_m);
  	if (rtm == NULL) {
  		warn("%s", host);
 +		prog_close(s);
  		return (1);
  	}
  	sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
 @@ -327,10 +332,12 @@ tryagain:
  			goto overwrite;
  		if (doing_proxy == 0) {
  			warnx("set: can only proxy for %s", host);
 +			prog_close(s);
  			return (1);
  		}
  		if (sin_m.sin_other & SIN_PROXY) {
  			warnx("set: proxy entry exists for non 802 device");
 +			prog_close(s);
  			return (1);
  		}
  		sin_m.sin_other = SIN_PROXY;
 @@ -341,6 +348,7 @@ overwrite:
  	if (sdl->sdl_family != AF_LINK) {
  		warnx("cannot intuit interface index and type for %s",
  		    host);
 +		prog_close(s);
  		return (1);
  	}
  	sdl_m.sdl_type = sdl->sdl_type;
 @@ -351,6 +359,7 @@ overwrite:
  	rtm = rtmsg(s, RTM_ADD, NULL, &sin_m, &sdl_m);
  	if (vflag)
  		(void)printf("%s (%s) added\n", host, eaddr);
 +	prog_close(s);
  	return (rtm == NULL) ? 1 : 0;
  }
  
 @@ -407,6 +416,7 @@ delete_one(struct rt_msghdr *rtm)
  	if (sdl->sdl_family != AF_LINK)
  		return (1);
  	rtm = rtmsg(s, RTM_DELETE, rtm, sina, sdl);
 +	prog_close(s);
  	if (rtm == NULL)
  		return (1);
  	return (0);
 Index: arp_hostops.c
 ===================================================================
 RCS file: /cvsroot/src/usr.sbin/arp/arp_hostops.c,v
 retrieving revision 1.1
 diff -u -p -r1.1 arp_hostops.c
 --- arp_hostops.c	29 Jul 2015 06:07:35 -0000	1.1
 +++ arp_hostops.c	26 Feb 2019 07:19:19 -0000
 @@ -47,6 +47,7 @@ const struct prog_ops prog_ops = {
  
  	.op_read = read,
  	.op_write = write,
 +	.op_close = close,
  
  	.op_sysctl = sysctl,
  };
 Index: arp_rumpops.c
 ===================================================================
 RCS file: /cvsroot/src/usr.sbin/arp/arp_rumpops.c,v
 retrieving revision 1.1
 diff -u -p -r1.1 arp_rumpops.c
 --- arp_rumpops.c	29 Jul 2015 06:07:35 -0000	1.1
 +++ arp_rumpops.c	26 Feb 2019 07:19:19 -0000
 @@ -51,6 +51,7 @@ const struct prog_ops prog_ops = {
  
  	.op_read =	rump_sys_read,
  	.op_write =	rump_sys_write,
 +	.op_close =	rump_sys_close,
  
  	.op_sysctl =	rump_sys___sysctl,
  };
 Index: prog_ops.h
 ===================================================================
 RCS file: /cvsroot/src/usr.sbin/arp/prog_ops.h,v
 retrieving revision 1.1
 diff -u -p -r1.1 prog_ops.h
 --- prog_ops.h	29 Jul 2015 06:07:35 -0000	1.1
 +++ prog_ops.h	26 Feb 2019 07:19:19 -0000
 @@ -45,6 +45,8 @@ struct prog_ops {
  
  	ssize_t (*op_read)(int, void *, size_t);
  	ssize_t (*op_write)(int, const void *, size_t);
 +
 +	int (*op_close)(int);
  };
  extern const struct prog_ops prog_ops;
  
 @@ -54,6 +56,7 @@ extern const struct prog_ops prog_ops;
  #define prog_getpid prog_ops.op_getpid
  #define prog_read prog_ops.op_read
  #define prog_write prog_ops.op_write
 +#define prog_close prog_ops.op_close
  #define prog_sysctl prog_ops.op_sysctl
  #else
  #define prog_init ((int (*)(void))NULL)
 @@ -62,6 +65,7 @@ extern const struct prog_ops prog_ops;
  #define prog_getpid getpid
  #define prog_read read
  #define prog_write write
 +#define prog_close close
  #define prog_sysctl sysctl
  #endif
  
 
 
 -- 
 David A. Holland
 dholland%netbsd.org@localhost
 


Home | Main Index | Thread Index | Old Index