Subject: kern/1227: DIRECTED_BROADCAST to sysctl
To: None <gnats-admin@sun-lamp.pc.cs.cmu.edu>
From: Darren Reed <darrenr@vitruvius.arbld.unimelb.edu.au>
List: netbsd-bugs
Date: 07/14/1995 09:50:11
>Number:         1227
>Category:       kern
>Synopsis:       remove need for #ifdef of DIRECTED_BROADCAST
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 14 09:50:06 1995
>Originator:     Darren Reed
>Organization:
University of Melbourne
>Release:        NetBSD-sparc-current
>Environment:
Sun IPC, NetBSD-current
System: NetBSD candella.arbld.unimelb.edu.au 1.0A NetBSD 1.0A (1.0A) #4: Mon Feb 20 18:33:28 EST 1995 root@:/usr/src/sys/arch/sparc/compile/1.0A sparc


>Description:
Changing broadcast behaviour of the kernel currently
requires it to be recompiled, changing the compile time option
DIRECTED_BROADCAST.  These patches support it moving under sysctl control
in the kernel (these should support sysctl(8) automatically).  You may wish
to change the names - I'm not sure if NetBSD should use "ip_" or just "ip"
as the prefix for variables of this nature, nor if sysctl is limited to
one word/name for a variable (thus the "-").  Might I suggest we go one way
or the other (we have "ip_defttl" vs everything else) ?

>How-To-Repeat:
>Fix:
Patches for /sys/netinet/in.h and /sys/netinet/ip_input.c included
below.

*** /sys/netinet/in.h.org	Sat Jul 15 23:04:09 1995
--- /sys/netinet/in.h	Sat Jul 15 23:06:44 1995
***************
*** 243,249 ****
  #ifdef notyet
  #define	IPCTL_DEFMTU		4	/* default MTU */
  #endif
! #define	IPCTL_MAXID		5
  
  #define	IPCTL_NAMES { \
  	{ 0, 0 }, \
--- 243,250 ----
  #ifdef notyet
  #define	IPCTL_DEFMTU		4	/* default MTU */
  #endif
! #define	IPCTL_DIRECTEDBROADCAST	5
! #define	IPCTL_MAXID		6
  
  #define	IPCTL_NAMES { \
  	{ 0, 0 }, \
***************
*** 251,256 ****
--- 252,258 ----
  	{ "redirect", CTLTYPE_INT }, \
  	{ "ttl", CTLTYPE_INT }, \
  	{ "mtu", CTLTYPE_INT }, \
+ 	{ "directed-broadcast", CTLTYPE_INT }, \
  }
  
  
*** /sys/netinet/ip_input.c.org	Sat Jul 15 22:54:55 1995
--- /sys/netinet/ip_input.c	Sat Jul 15 23:03:47 1995
***************
*** 67,74 ****
--- 67,78 ----
  #ifndef	IPSENDREDIRECTS
  #define	IPSENDREDIRECTS	1
  #endif
+ #ifndef	DIRECTED_BROADCAST
+ #define	DIRECTED_BROADCAST	0
+ #endif
  int	ipforwarding = IPFORWARDING;
  int	ipsendredirects = IPSENDREDIRECTS;
+ int	ipdirbroadcast = DIRECTED_BROADCAST;
  int	ip_defttl = IPDEFTTL;
  #ifdef DIAGNOSTIC
  int	ipprintfs = 0;
***************
*** 232,241 ****
  	for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) {
  		if (ip->ip_dst.s_addr == ia->ia_addr.sin_addr.s_addr)
  			goto ours;
! 		if (
! #ifdef	DIRECTED_BROADCAST
! 		    ia->ia_ifp == m->m_pkthdr.rcvif &&
! #endif
  		    (ia->ia_ifp->if_flags & IFF_BROADCAST)) {
  			if (ip->ip_dst.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
  			    ip->ip_dst.s_addr == ia->ia_netbroadcast.s_addr ||
--- 236,243 ----
  	for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) {
  		if (ip->ip_dst.s_addr == ia->ia_addr.sin_addr.s_addr)
  			goto ours;
! 		if ((!ipdirbroadcast || (ipdirbroadcast &&
! 		      ia->ia_ifp == m->m_pkthdr.rcvif)) &&
  		    (ia->ia_ifp->if_flags & IFF_BROADCAST)) {
  			if (ip->ip_dst.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
  			    ip->ip_dst.s_addr == ia->ia_netbroadcast.s_addr ||
***************
*** 1145,1150 ****
--- 1147,1155 ----
  	case IPCTL_SENDREDIRECTS:
  		return (sysctl_int(oldp, oldlenp, newp, newlen,
  			&ipsendredirects));
+ 	case IPCTL_DIRECTEDBROADCAST:
+ 		return (sysctl_int(oldp, oldlenp, newp, newlen,
+ 			&ipdirbroadcast));
  	case IPCTL_DEFTTL:
  		return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_defttl));
  #ifdef notyet
>Audit-Trail:
>Unformatted: