Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2007/0419/1

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/sys/src/9/ip/ip.c
% cat >/sys/lib/dist/changes/1176957006.0.txt << EOF
Code cleanup.
• Whitespace / comments
• Add comments describing route flags
• Add function ipifcadd6, replacing ipifcaddpref6
• Condense ipifcsendra6 and ipifcrecvra6 and ipifcsetpar6 
into ipifcra6

EOF
 [geoff] --rw-rw-r-- M 43 glenda sys 15288 Apr 19 00:30 sys/src/9/ip/ip.c
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.c:145,151 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.c:145,150
	  void		ipfragfree4(IP*, Fragment4*);
	  Fragment4*	ipfragallo4(IP*);
	  
	- 
	  void
	  ip_init_6(Fs *f)
	  {
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.c:152,174 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.c:151,172
	  	v6params *v6p;
	  
	  	v6p = smalloc(sizeof(v6params));
	- 	
	- 	v6p->rp.mflag		= 0;		// default not managed
	+ 
	+ 	v6p->rp.mflag		= 0;		/* default not managed */
	  	v6p->rp.oflag		= 0;
	- 	v6p->rp.maxraint	= 600000;	// millisecs
	+ 	v6p->rp.maxraint	= 600000;	/* millisecs */
	  	v6p->rp.minraint	= 200000;
	- 	v6p->rp.linkmtu		= 0;		// no mtu sent
	+ 	v6p->rp.linkmtu		= 0;		/* no mtu sent */
	  	v6p->rp.reachtime	= 0;
	  	v6p->rp.rxmitra		= 0;
	  	v6p->rp.ttl		= MAXTTL;
	- 	v6p->rp.routerlt	= 3*(v6p->rp.maxraint);	
	+ 	v6p->rp.routerlt	= 3 * v6p->rp.maxraint;
	  
	- 	v6p->hp.rxmithost	= 1000;		// v6 RETRANS_TIMER
	+ 	v6p->hp.rxmithost	= 1000;		/* v6 RETRANS_TIMER */
	  
	  	v6p->cdrouter 		= -1;
	  
	  	f->v6p			= v6p;
	- 
	  }
	  
	  void
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.c:217,223 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.c:215,221
	  	if(f->ip->iprouting==0)
	  		f->ip->stats[Forwarding] = 2;
	  	else
	- 		f->ip->stats[Forwarding] = 1;	
	+ 		f->ip->stats[Forwarding] = 1;
	  }
	  
	  int
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.c:362,368 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.c:360,366
	  			seglen = dlen - fragoff;
	  			hnputs(feh->frag, fragoff>>3);
	  		}
	- 		else	
	+ 		else
	  			hnputs(feh->frag, (fragoff>>3)|IP_MF);
	  
	  		hnputs(feh->length, seglen + IP4HDR);
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.c:387,393 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.c:385,391
	  			chunk -= blklen;
	  			if(xp->rp == xp->wp)
	  				xp = xp->next;
	- 		} 
	+ 		}
	  
	  		feh->cksum[0] = 0;
	  		feh->cksum[1] = 0;
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.c:723,729 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.c:721,727
	  			hnputs(ih->length, len);
	  			qunlock(&ip->fraglock4);
	  			ip->stats[ReasmOKs]++;
	- 			return bl;		
	+ 			return bl;
	  		}
	  		pktposn += BKFG(bl)->flen;
	  	}
 [geoff] --rw-rw-r-- M 43 glenda sys 15982 Apr 19 00:32 sys/src/9/ip/ip.h
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.h:188,206 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.h:188,206
	  	int	ref;
	  };
	  
	- /* rfc 2461, pp.40--43. */
	+ /* rfc 2461, pp.40—43. */
	  
	  /* default values, one per stack */
	  struct Routerparams {
	- 	int	mflag;
	- 	int	oflag;
	- 	int 	maxraint;
	- 	int	minraint;
	- 	int	linkmtu;
	- 	int	reachtime;
	- 	int	rxmitra;
	- 	int	ttl;
	- 	int	routerlt;	
	+ 	int	mflag;		/* flag: managed address configuration */
	+ 	int	oflag;		/* flag: other stateful configuration */
	+ 	int 	maxraint;	/* max. router adv interval (ms) */
	+ 	int	minraint;	/* min. router adv interval (ms) */
	+ 	int	linkmtu;	/* mtu options */
	+ 	int	reachtime;	/* reachable time */
	+ 	int	rxmitra;	/* retransmit interval */
	+ 	int	ttl;		/* cur hop count limit */
	+ 	int	routerlt;	/* router lifetime */
	  };
	  
	  struct Hostparams {
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.h:210,216 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.h:210,216
	  struct Ipifc
	  {
	  	RWlock;
	- 	
	+ 
	  	Conv	*conv;		/* link to its conversation structure */
	  	char	dev[64];	/* device we're attached to */
	  	Medium	*m;		/* Media pointer */
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.h:234,242 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.h:234,242
	  	ulong	in, out;	/* message statistics */
	  	ulong	inerr, outerr;	/* ... */
	  
	- 	uchar	sendra6;	/* == 1 => send router advs on this ifc	*/
	- 	uchar	recvra6;	/* == 1 => recv router advs on this ifc */
	- 	Routerparams rp;	/* router parameters as in RFC 2461, pp.40--43. 
	+ 	uchar	sendra6;	/* flag: send router advs on this ifc */
	+ 	uchar	recvra6;	/* flag: recv router advs on this ifc */
	+ 	Routerparams rp;	/* router parameters as in RFC 2461, pp.40—43.
	  					used only if node is router */
	  };
	  
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.h:361,367 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.h:361,367
	  	Routerparams	rp;		/* v6 params, one copy per node now */
	  	Hostparams	hp;
	  	v6router	v6rlist[3];	/* max 3 default routers, currently */
	- 	int		cdrouter;	/* uses only v6rlist[cdrouter] if   */ 
	+ 	int		cdrouter;	/* uses only v6rlist[cdrouter] if   */
	  					/* cdrouter >= 0. */
	  };
	  
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.h:379,385 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.h:379,385
	  char*	Fsstdbind(Conv*, char**, int);
	  ulong	scalednconv(void);
	  void	closeconv(Conv*);
	- /* 
	+ /*
	   *  logging
	   */
	  enum
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ip.h:605,612 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ip.h:605,611
	  extern char*	ipifcrem(Ipifc *ifc, char **argv, int argc);
	  extern char*	ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp);
	  extern long	ipselftabread(Fs*, char *a, ulong offset, int n);
	- extern char*	ipifcaddpref6(Ipifc *ifc, char**argv, int argc);
	- extern void	ipsendra6(Fs *f, int on);
	+ extern char*	ipifcadd6(Ipifc *ifc, char**argv, int argc);
	  /*
	   *  ip.c
	   */
 [geoff] --rw-rw-r-- M 43 glenda sys 33517 Apr 19 00:32 sys/src/9/ip/ipifc.c
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:415,426 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:415,426
	  		if(ipcmp(lifc->local, ip) == 0) {
	  			if(lifc->tentative != tentative)
	  				lifc->tentative = tentative;
	- 			if(lifcp != nil) {
	- 				lifc->onlink = lifcp->onlink;
	+ 			if(lifcp) {
	+ 				lifc->onlink   = lifcp->onlink;
	  				lifc->autoflag = lifcp->autoflag;
	- 				lifc->validlt = lifcp->validlt;
	- 				lifc->preflt = lifcp->preflt;
	- 				lifc->origint = lifcp->origint;
	+ 				lifc->validlt  = lifcp->validlt;
	+ 				lifc->preflt   = lifcp->preflt;
	+ 				lifc->origint  = lifcp->origint;
	  			}
	  			goto out;
	  		}
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:432,449 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:432,447
	  	ipmove(lifc->remote, rem);
	  	ipmove(lifc->net, net);
	  	lifc->tentative = tentative;
	- 	if(lifcp != nil) {
	- 		lifc->onlink = lifcp->onlink;
	+ 	if(lifcp) {
	+ 		lifc->onlink   = lifcp->onlink;
	  		lifc->autoflag = lifcp->autoflag;
	- 		lifc->validlt = lifcp->validlt;
	- 		lifc->preflt = lifcp->preflt;
	- 		lifc->origint = lifcp->origint;
	+ 		lifc->validlt  = lifcp->validlt;
	+ 		lifc->preflt   = lifcp->preflt;
	+ 		lifc->origint  = lifcp->origint;
	  	} else {		/* default values */
	- 		lifc->onlink = 1;
	- 		lifc->autoflag = 1;
	- 		lifc->validlt = ~0L;
	- 		lifc->preflt = ~0L;
	- 		lifc->origint = NOW / 1000;
	+ 		lifc->onlink   = lifc->autoflag = 1;
	+ 		lifc->validlt  = lifc->preflt = ~0L;
	+ 		lifc->origint  = NOW / 1000;
	  	}
	  	lifc->next = nil;
	  
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:687,693 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:685,691
	  }
	  
	  char*
	- ipifcsetpar6(Ipifc *ifc, char **argv, int argc)
	+ ipifcra6(Ipifc *ifc, char **argv, int argc)
	  {
	  	int i, argsleft, vmax = ifc->rp.maxraint, vmin = ifc->rp.minraint;
	  
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:736,755 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:734,739
	  	return nil;
	  }
	  
	- char*
	- ipifcsendra6(Ipifc *ifc, char **argv, int argc)
	- {
	- 	ifc->sendra6 = ((argc > 1? atoi(argv[1]): 0) != 0);
	- 	return nil;
	- }
	- 
	- char*
	- ipifcrecvra6(Ipifc *ifc, char **argv, int argc)
	- {
	- 	ifc->recvra6 = ((argc > 1? atoi(argv[1]): 0) != 0);
	- 	return nil;
	- }
	- 
	  /*
	   *  non-standard control messages.
	   *  called with c->car locked.
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:780,794 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:764,775
	  	} else if(strcmp(argv[0], "iprouting") == 0){
	  		iprouting(c->p->f, (argc > 1? atoi(argv[1]): 1));
	  		return nil;
	- 	} else if(strcmp(argv[0], "addpref6") == 0)
	- 		return ipifcaddpref6(ifc, argv, argc);
	- 	else if(strcmp(argv[0], "setpar6") == 0)
	- 		return ipifcsetpar6(ifc, argv, argc);
	- 	else if(strcmp(argv[0], "sendra6") == 0)
	- 		return ipifcsendra6(ifc, argv, argc);
	- 	else if(strcmp(argv[0], "recvra6") == 0)
	- 		return ipifcrecvra6(ifc, argv, argc);
	- 	return "unsupported ctl";
	+ 	} else if(strcmp(argv[0], "add6") == 0)
	+ 		return ipifcadd6(ifc, argv, argc);
	+ 	else if(strcmp(argv[0], "ra6") == 0)
	+ 		return ipifcra6(ifc, argv, argc);
	+ 	else
	+ 		return "unsupported ctl";
	  }
	  
	  int
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:1583,1589 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:1564,1570
	  };
	  
	  char*
	- ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
	+ ipifcadd6(Ipifc *ifc, char**argv, int argc)
	  {
	  	int plen = 64;
	  	long origint = NOW / 1000, preflt = ~0L, validlt = ~0L;
	/n/sourcesdump/2007/0419/plan9/sys/src/9/ip/ipifc.c:1620,1636 - 
	/n/sourcesdump/2007/0420/plan9/sys/src/9/ip/ipifc.c:1601,1616
	  		return Ebadarg;
	  
	  	lifc = smalloc(sizeof(Iplifc));
	- 	lifc->onlink = (onlink!=0);
	- 	lifc->autoflag = (autoflag!=0);
	+ 	lifc->onlink = (onlink != 0);
	+ 	lifc->autoflag = (autoflag != 0);
	  	lifc->validlt = validlt;
	  	lifc->preflt = preflt;
	  	lifc->origint = origint;
	  
	- 	if(ifc->m->pref2addr)
	- 		ifc->m->pref2addr(prefix, ifc->mac);
	- 	else
	+ 	/* issue "add" ctl msg for v6 link-local addr and prefix len */
	+ 	if(!ifc->m->pref2addr)
	  		return Ebadarg;
	- 
	+ 	ifc->m->pref2addr(prefix, ifc->mac);	/* mac → v6 link-local addr */
	  	sprint(addr, "%I", prefix);
	  	sprint(preflen, "/%d", plen);
	  	params[0] = "add";


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].