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

Re: system/3704: routed has byte ordering issues on non-network



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

From: Otto Moerbeek <otto_(_at_)_drijf_(_dot_)_net>
To: Don Kindred <kindred_(_at_)_purdue_(_dot_)_edu>
Cc: Otto Moerbeek <otto_(_at_)_drijf_(_dot_)_net>, gnats_(_at_)_openbsd_(_dot_)_org
Subject: Re: system/3704: routed has byte ordering issues on non-network
Date: Tue, 9 Mar 2004 10:04:33 +0100 (CET)

 On Mon, 8 Mar 2004, Don Kindred wrote:
 
 > > Please provide both. Any big change will not make it into 3.5, 
 > > but it is good to have the diffs anyway.
 > > 
 > > 	-Otto
 > 
 > Below is my context diff for /usr/src/sbin/routed/parms.c suitable
 > for "patch"ing the OpenBSD source.  The only things I changed were
 > comments and byte ordering.
 > 
 > This just fixes the "subnet=" directive.  I haven't really tested
 > any of the other directives that use the getnet() function.  I
 > wouldn't be at all suprised if there are byte ordering problems
 > elsewhere.
 > 
 > At some point in the near future I'll send you the cdiffs for
 > the mods I made to the FreeBSD routed to get it to compile cleanly
 > under OpenBSD.  The mods were very minor... but I don't have
 > easy access to them at the moment.
 
 - Please send unified diffs (diff -u), they are much easier to read.
 
 - Your diff makes routed deviate from both NetBSD and FreeBSD. Below is a
 diff based on NetBSD, which should solve your problem, leaving the
 arguments to getnet() both in host byte order. FreeBSD contains similar
 changes. As you can read from getnetbyname(3), networks numbers are
 normally processed in host byte order.  Please test (also the gateway file
 and the -F option) and report back.
 
 	-Otto
 
 Index: main.c
 ===================================================================
 RCS file: /cvs/src/sbin/routed/main.c,v
 retrieving revision 1.16
 diff -u -p -r1.16 main.c
 --- main.c	2 Jun 2003 20:06:17 -0000	1.16
 +++ main.c	9 Mar 2004 08:43:44 -0000
 @@ -182,7 +182,7 @@ main(int argc,
  				break;
  			}
  			bzero(&parm, sizeof(parm));
 -			parm.parm_addr_h = ntohl(p_addr);
 +			parm.parm_addr_h = p_addr;
  			parm.parm_mask = p_mask;
  			parm.parm_d_metric = n;
  			p = check_parms(&parm);
 Index: parms.c
 ===================================================================
 RCS file: /cvs/src/sbin/routed/parms.c,v
 retrieving revision 1.10
 diff -u -p -r1.10 parms.c
 --- parms.c	2 Jun 2003 20:06:17 -0000	1.10
 +++ parms.c	9 Mar 2004 08:50:27 -0000
 @@ -139,8 +139,6 @@ gwkludge(void)
  	int metric, n;
  	u_int state;
  	char *type;
 -	struct parm *parmp;
 -
  
  	fp = fopen(_PATH_GATEWAYS, "r");
  	if (fp == 0)
 @@ -202,6 +200,7 @@ gwkludge(void)
  				       " entry \"%s\"", dname, lptr);
  				continue;
  			}
 +			HTONL(dst);	/* make network # into IP address */
  		} else {
  			msglog("bad \"%s\" in "_PATH_GATEWAYS
  			       " entry \"%s\"", lptr);
 @@ -271,15 +270,6 @@ gwkludge(void)
  		    == (IS_NO_RIP|IS_NO_RDISC))
  			state |= IS_PASSIVE;
  
 -		parmp = (struct parm*)malloc(sizeof(*parmp));
 -		bzero(parmp, sizeof(*parmp));
 -		parmp->parm_next = parms;
 -		parms = parmp;
 -		parmp->parm_addr_h = ntohl(dst);
 -		parmp->parm_mask = -1;
 -		parmp->parm_d_metric = 0;
 -		parmp->parm_int_state = state;
 -
  		/* See if this new interface duplicates an existing
  		 * interface.
  		 */
 @@ -367,6 +357,7 @@ parse_parms(char *line)
  			free(intnetp);
  			return line;
  		}
 +		HTONL(intnetp->intnet_addr);
  		intnetp->intnet_next = intnets;
  		intnets = intnetp;
  		return 0;
 @@ -544,13 +535,13 @@ check_parms(struct parm *new)
   */
  int					/* 0=bad */
  getnet(char *name,
 -       naddr *addrp,			/* host byte order */
 -       naddr *maskp)
 +       naddr *addrp,			/* network in host byte order */
 +       naddr *maskp)			/* masks are always in host order */
  {
  	int i;
  	struct netent *np;
 -	naddr mask;
 -	struct in_addr in;
 +	naddr mask;			/* in host byte order */
 +	struct in_addr in;		/* a network and so host byte order */
  	char hname[MAXHOSTNAMELEN+1];
  	char *mname, *p;
  
 @@ -571,7 +562,7 @@ getnet(char *name,
  	if (np != 0) {
  		in.s_addr = (naddr)np->n_net;
  	} else if (inet_aton(name, &in) == 1) {
 -		HTONL(in.s_addr);
 +		NTOHL(in.s_addr);
  	} else {
  		return 0;
  	}
 @@ -580,8 +571,8 @@ getnet(char *name,
  		/* we cannot use the interfaces here because we have not
  		 * looked at them yet.
  		 */
 -		mask = std_mask(in.s_addr);
 -		if ((~mask & ntohl(in.s_addr)) != 0)
 +		mask = std_mask(htonl(in.s_addr));
 +		if ((~mask & in.s_addr) != 0)
  			mask = HOST_MASK;
  	} else {
  		mask = (naddr)strtoul(mname, &p, 0);
 @@ -591,7 +582,7 @@ getnet(char *name,
  	}
  	if (mask != 0 && in.s_addr == RIP_DEFAULT)
  		return 0;
 -	if ((~mask & ntohl(in.s_addr)) != 0)
 +	if ((~mask & in.s_addr) != 0)
  		return 0;
  
  	*addrp = in.s_addr;



Visit your host, monkey.org