Subject: routed patch
To: None <current-users@NetBSD.ORG>
From: Christos Zoulas <christos@deshaw.com>
List: current-users
Date: 11/06/1996 09:13:26
People who reported problems with routed and ppp, please try this patch...

1. Looks like we suffer from the MCAST_PPP_BUG.
2. ...and there is another place in the code we need it.
3. Make /etc/gateways errors better, and match the documentation, by adding
   the active keyword (we could never get to the qual[0] == '\0' portion of
   the code before.
4. inet_aton() returns addresses in network byte order, so the HTONL() is
   superfluous. Is the fact that inet_aton() returns addresses in network
   byte order documented anywhere? Maybe it should...
5. ifp->int_dstaddr is in host byte order and ifp->int_net is in network
   byte order; fix the code to reflect that.

Another useful thing to do is to add in /etc/gateways:

if=ppp0 no_rip

to avoid sending routing updates through your ppp link (if you don't need to).

christos

diff -rc /usr/src.remote/sbin/routed/defs.h ./defs.h
*** /usr/src.remote/sbin/routed/defs.h	Mon Oct 14 11:45:21 1996
--- ./defs.h	Tue Nov  5 13:11:39 1996
***************
*** 112,118 ****
  /* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
   * the dstaddr of point-to-point interfaces.
   */
! /* #define MCAST_PPP_BUG */
  
  #define NEVER (24*60*60)		/* a long time */
  #define EPOCH NEVER			/* bias time by this to avoid <0 */
--- 112,118 ----
  /* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
   * the dstaddr of point-to-point interfaces.
   */
! #define MCAST_PPP_BUG
  
  #define NEVER (24*60*60)		/* a long time */
  #define EPOCH NEVER			/* bias time by this to avoid <0 */
diff -rc /usr/src.remote/sbin/routed/if.c ./if.c
*** /usr/src.remote/sbin/routed/if.c	Mon Oct 14 11:45:23 1996
--- ./if.c	Tue Nov  5 13:39:26 1996
***************
*** 127,138 ****
  
  	maybe = 0;
  	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
  		if (ifp->int_if_flags & IFF_POINTOPOINT) {
  			if (ifp->int_dstaddr == addr)
  				/* finished with a match */
  				return ifp;
  
! 		} else {
  			/* finished with an exact match */
  			if (ifp->int_addr == addr)
  				return ifp;
--- 127,141 ----
  
  	maybe = 0;
  	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+ #ifndef MCAST_PPP_BUG
  		if (ifp->int_if_flags & IFF_POINTOPOINT) {
  			if (ifp->int_dstaddr == addr)
  				/* finished with a match */
  				return ifp;
  
! 		} else
! #endif
! 		{
  			/* finished with an exact match */
  			if (ifp->int_addr == addr)
  				return ifp;
diff -rc /usr/src.remote/sbin/routed/parms.c ./parms.c
*** /usr/src.remote/sbin/routed/parms.c	Mon Oct 14 11:45:37 1996
--- ./parms.c	Tue Nov  5 14:47:31 1996
***************
*** 187,222 ****
  			   " %64[^ / \t] metric %d %8s\n",
  			   net_host, dname, gname, &metric, qual);
  		if (n != 5) {
! 			msglog("bad "_PATH_GATEWAYS" entry \"%s\"", lptr);
  			continue;
  		}
  		if (metric < 0 || metric >= HOPCNT_INFINITY) {
! 			msglog("bad metric in "_PATH_GATEWAYS" entry \"%s\"",
! 			       lptr);
  			continue;
  		}
  		if (!strcmp(net_host, "host")) {
  			if (!gethost(dname, &dst)) {
! 				msglog("bad host \"%s\" in "_PATH_GATEWAYS
! 				       " entry \"%s\"", dname, lptr);
  				continue;
  			}
  			netmask = HOST_MASK;
  		} else if (!strcmp(net_host, "net")) {
  			if (!getnet(dname, &dst, &netmask)) {
! 				msglog("bad net \"%s\" in "_PATH_GATEWAYS
! 				       " entry \"%s\"", dname, lptr);
  				continue;
  			}
  		} else {
! 			msglog("bad \"%s\" in "_PATH_GATEWAYS
! 			       " entry \"%s\"", lptr);
  			continue;
  		}
  
  		if (!gethost(gname, &gate)) {
! 			msglog("bad gateway \"%s\" in "_PATH_GATEWAYS
! 			       " entry \"%s\"", gname, lptr);
  			continue;
  		}
  
--- 187,223 ----
  			   " %64[^ / \t] metric %d %8s\n",
  			   net_host, dname, gname, &metric, qual);
  		if (n != 5) {
! 			msglog("missing fields in %s entry \"%s\"",
! 			    _PATH_GATEWAYS, lptr);
  			continue;
  		}
  		if (metric < 0 || metric >= HOPCNT_INFINITY) {
! 			msglog("bad metric in %s entry \"%s\"",
! 			    _PATH_GATEWAYS, lptr);
  			continue;
  		}
  		if (!strcmp(net_host, "host")) {
  			if (!gethost(dname, &dst)) {
! 				msglog("bad host \"%s\" in %s entry \"%s\"",
! 				    dname, _PATH_GATEWAYS, lptr);
  				continue;
  			}
  			netmask = HOST_MASK;
  		} else if (!strcmp(net_host, "net")) {
  			if (!getnet(dname, &dst, &netmask)) {
! 				msglog("bad net \"%s\" in %s entry \"%s\"",
! 				    dname, _PATH_GATEWAYS, lptr);
  				continue;
  			}
  		} else {
! 			msglog("bad \"%s\" in %s entry \"%s\"",
! 			    _PATH_GATEWAYS, lptr);
  			continue;
  		}
  
  		if (!gethost(gname, &gate)) {
! 			msglog("bad gateway \"%s\" in %s entry \"%s\"",
! 			    gname, _PATH_GATEWAYS, lptr);
  			continue;
  		}
  
***************
*** 241,247 ****
  			if (metric == 0)
  				metric = 1;
  
! 		} else if (qual[0] == '\0') {
  			if (metric != 0) {
  				/* Entries that are neither "passive" nor
  				 * "external" are "remote" and must behave
--- 242,248 ----
  			if (metric == 0)
  				metric = 1;
  
! 		} else if (strcmp(qual, type = "active") == 0) {
  			if (metric != 0) {
  				/* Entries that are neither "passive" nor
  				 * "external" are "remote" and must behave
***************
*** 259,265 ****
  			}
  
  		} else {
! 			msglog("bad "_PATH_GATEWAYS" entry \"%s\"", lptr);
  			continue;
  		}
  
--- 260,267 ----
  			}
  
  		} else {
! 			msglog("bad qualifier \"%s\" in entry \"%s\"",
! 			    qual, lptr);
  			continue;
  		}
  
***************
*** 575,581 ****
--- 577,585 ----
  	if (np != 0) {
  		in.s_addr = (naddr)np->n_net;
  	} else if (inet_aton(name, &in) == 1) {
+ #if 0
  		HTONL(in.s_addr);
+ #endif
  	} else {
  		return 0;
  	}
diff -rc /usr/src.remote/sbin/routed/trace.c ./trace.c
*** /usr/src.remote/sbin/routed/trace.c	Mon Oct 14 11:46:03 1996
--- ./trace.c	Tue Nov  5 14:02:10 1996
***************
*** 499,507 ****
  	(void)fprintf(ftrace, "%s interface %-4s ", act, ifp->int_name);
  	(void)fprintf(ftrace, "%-15s-->%-15s ",
  		      naddr_ntoa(ifp->int_addr),
! 		      addrname(htonl((ifp->int_if_flags & IFF_POINTOPOINT)
  				     ? ifp->int_dstaddr
! 				     : ifp->int_net),
  			       ifp->int_mask, 1));
  	if (ifp->int_metric != 0)
  		(void)fprintf(ftrace, "metric=%d ", ifp->int_metric);
--- 499,507 ----
  	(void)fprintf(ftrace, "%s interface %-4s ", act, ifp->int_name);
  	(void)fprintf(ftrace, "%-15s-->%-15s ",
  		      naddr_ntoa(ifp->int_addr),
! 		      addrname((ifp->int_if_flags & IFF_POINTOPOINT)
  				     ? ifp->int_dstaddr
! 				     : ntohl(ifp->int_net),
  			       ifp->int_mask, 1));
  	if (ifp->int_metric != 0)
  		(void)fprintf(ftrace, "metric=%d ", ifp->int_metric);