Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Aug 2006 15:56:02 GMT
From:      Paolo Pisati <piso@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 105269 for review
Message-ID:  <200608291556.k7TFu2em012189@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=105269

Change 105269 by piso@piso_newluxor on 2006/08/29 15:55:03

	Style and cosmetic changes.

Affected files ...

.. //depot/projects/soc2005/libalias/sbin/ipfw/ipfw2.c#6 edit

Differences ...

==== //depot/projects/soc2005/libalias/sbin/ipfw/ipfw2.c#6 (text+ko) ====

@@ -67,7 +67,7 @@
 		do_time,		/* Show time stamps */
 		do_quiet,		/* Be quiet in add and flush */
 		do_pipe,		/* this cmd refers to a pipe */
-	        do_nat, 		/* nat configuration */
+	        do_nat, 		/* Nat configuration. */
 		do_sort,		/* field to sort results (0 = no) */
 		do_dynamic,		/* display dynamic rules */
 		do_expired,		/* display expired dynamic rules */
@@ -407,7 +407,7 @@
 	{ "unreach",		TOK_UNREACH },
 	{ "check-state",	TOK_CHECKSTATE },
 	{ "//",			TOK_COMMENT },
-	{ "nat",                TOK_NAT},
+	{ "nat",                TOK_NAT },
 	{ NULL, 0 }	/* terminator */
 };
 
@@ -515,7 +515,7 @@
 {
 	static int s = -1;	/* the socket */
 	int i;
-	
+
 	if (test_only)
 		return 0;
 
@@ -3189,8 +3189,7 @@
 			exitval = do_cmd(IP_FW_NAT_DEL, &i, sizeof i);
 			if (exitval) {
 				exitval = EX_UNAVAILABLE;
-				warn("rule %u not available",
-				     i);
+				warn("rule %u not available", i);
 			}
  		} else if (do_pipe) {
 			if (do_pipe == 1)
@@ -3217,6 +3216,7 @@
 		exit(exitval);
 }
 
+
 /*
  * fill the interface structure. We do not check the name as we can
  * create interfaces dynamically, so checking them at insert time
@@ -3261,9 +3261,9 @@
 	mib[0] = CTL_NET;
 	mib[1] = PF_ROUTE;
 	mib[2] = 0;
-	mib[3] = AF_INET;	/* Only IP addresses please */
+	mib[3] = AF_INET;	
 	mib[4] = NET_RT_IFLIST;
-	mib[5] = 0;		/* ifIndex??? */
+	mib[5] = 0;		
 /*
  * Get interface data.
  */
@@ -3341,10 +3341,10 @@
 }
 
 /* 
- * XXX: the following functions, macros and definitions come from natd.c:
- * it would be better to move them outside of natd.c, in a file 
+ * XXX - The following functions, macros and definitions come from natd.c:
+ * it would be better to move them outside natd.c, in a file 
  * (redirect_support.[ch]?) shared by ipfw and natd, but for now i can live 
- * with it...
+ * with it.
  */
 
 /*
@@ -3453,7 +3453,7 @@
 	return StrToPortRange (ptr, proto, portRange);
 }
 
-/* end of stuff taken from natd.c */
+/* End of stuff taken from natd.c. */
 
 #define INC_ARGCV() do {        \
 	(*_av)++;               \
@@ -3496,8 +3496,8 @@
 setup_redir_addr(char *spool_buf, int len,
 		 int *_ac, char ***_av) 
 {
-	char **av = *_av, *sep; /* token separator */
-	/* temporary buffer used to hold server pool ip's */
+	char **av = *_av, *sep; /* Token separator. */
+	/* Temporary buffer used to hold server pool ip's. */
 	char tmp_spool_buf[NAT_BUF_LEN]; 
 	int ac = *_ac, i, space = 0, lsnat = 0;
 	int sof_redir = sizeof(struct cfg_redir);
@@ -3505,33 +3505,33 @@
 
 	if (len >= sof_redir) {
 		r = (struct cfg_redir *)spool_buf;
-		/* skip cfg_redir at beginning of buf */
+		/* Skip cfg_redir at beginning of buf. */
 		spool_buf = &spool_buf[sof_redir];
 		space = sof_redir;
 		len -= sof_redir;
 	} else 
 		goto nospace; 
 	r->mode = REDIR_ADDR;
-	/* extract local address */
+	/* Extract local address. */
 	if (ac == 0) 
 		errx(EX_DATAERR, "redir_addr: missing local address");
 	sep = strchr(*av, ',');
 	if (sep) {		/* LSNAT redirection syntax. */
 		r->laddr.s_addr = INADDR_NONE;
-		/* preserve av, copy spool servers to tmp_spool_buf */		 
+		/* Preserve av, copy spool servers to tmp_spool_buf. */
 		strncpy(tmp_spool_buf, *av, strlen(*av)+1);
 		lsnat = 1;
 	} else 
 		StrToAddr(*av, &r->laddr);		
 	INC_ARGCV();
 
-	/* extract public address */
+	/* Extract public address. */
 	if (ac == 0) 
 		errx(EX_DATAERR, "redir_addr: missing public address");
 	StrToAddr(*av, &r->paddr);
 	INC_ARGCV();
 
-	/* setup LSNAT server pool */
+	/* Setup LSNAT server pool. */
 	if (sep) {
 		int                     sof_spool = sizeof(struct cfg_spool);
 		struct cfg_spool        *tmp;		
@@ -3545,10 +3545,10 @@
 			space += sof_spool;			
 			StrToAddr(sep, &tmp->addr);
 			tmp->port = ~0;
-			r->spool_cnt++;	
-			/* point to the next possible cfg_spool */
+			r->spool_cnt++;
+			/* Point to the next possible cfg_spool. */
 			spool_buf = &spool_buf[sof_spool];
-			sep = strtok(NULL, ",");			
+			sep = strtok(NULL, ",");
 		}
 	}
 	return(space);
@@ -3570,7 +3570,7 @@
 
 	if (len >= sof_redir) {
 		r = (struct cfg_redir *)spool_buf;
-		/* skip cfg_redir at beginning of buf */
+		/* Skip cfg_redir at beginning of buf. */
 		spool_buf = &spool_buf[sof_redir];
 		space = sof_redir;
 		len -= sof_redir;
@@ -3597,14 +3597,14 @@
 		r->laddr.s_addr = INADDR_NONE;
 		r->lport = ~0;
 		numLocalPorts = 1;
-		/* preserve av, copy spool servers to tmp_spool_buf */		 
+		/* Preserve av, copy spool servers to tmp_spool_buf. */		 
 		strncpy(tmp_spool_buf, *av, strlen(*av)+1);
 		lsnat = 1;
 	} else {
-		if ( StrToAddrAndPortRange (*av, &r->laddr, protoName, &portRange) != 0 )
-			errx (EX_DATAERR, "redirect_port: invalid local port range");
+		if (StrToAddrAndPortRange (*av, &r->laddr, protoName, &portRange) != 0)
+			errx(EX_DATAERR, "redirect_port: invalid local port range");
 
-		r->lport     = GETLOPORT(portRange);
+		r->lport = GETLOPORT(portRange);
 		numLocalPorts = GETNUMPORTS(portRange);
 	}	
 	INC_ARGCV();	
@@ -3617,15 +3617,15 @@
 
 	sep = strchr (*av, ':');
 	if (sep) {
-	        if (StrToAddrAndPortRange (*av, &r->paddr, protoName, &portRange) != 0 )
-		        errx (EX_DATAERR, "redirect_port: invalid public port range");
-	} else {	
+	        if (StrToAddrAndPortRange (*av, &r->paddr, protoName, &portRange) != 0)
+		        errx(EX_DATAERR, "redirect_port: invalid public port range");
+	} else {
 		r->paddr.s_addr = INADDR_ANY;
 		if (StrToPortRange (*av, protoName, &portRange) != 0)
-		        errx (EX_DATAERR, "redirect_port: invalid public port range");
+		        errx(EX_DATAERR, "redirect_port: invalid public port range");
 	}
 
-	r->pport     = GETLOPORT(portRange);
+	r->pport = GETLOPORT(portRange);
 	r->pport_cnt = GETNUMPORTS(portRange);
 	INC_ARGCV();
 
@@ -3633,14 +3633,14 @@
 	 * Extract remote address and optionally port.
 	 */	
 	/* 
-	 * isalpha(**av) => we've to check that next parameter is really an
-	 * option for this redirect entry, else stop here processing arg[cv]
+	 * NB: isalpha(**av) => we've to check that next parameter is really an
+	 * option for this redirect entry, else stop here processing arg[cv].
 	 */
 	if (ac != 0 && !isalpha(**av)) { 
 		sep = strchr (*av, ':');
 		if (sep) {
 		        if (StrToAddrAndPortRange (*av, &r->raddr, protoName, &portRange) != 0)
-			        errx (EX_DATAERR, "redirect_port: invalid remote port range");
+			        errx(EX_DATAERR, "redirect_port: invalid remote port range");
 		} else {
 		        SETLOPORT(portRange, 0);
 			SETNUMPORTS(portRange, 1);
@@ -3652,7 +3652,7 @@
 		SETNUMPORTS(portRange, 1);
 		r->raddr.s_addr = INADDR_ANY;
 	}
-	r->rport     = GETLOPORT(portRange);
+	r->rport = GETLOPORT(portRange);
 	r->rport_cnt = GETNUMPORTS(portRange);
 
 	/* 
@@ -3669,8 +3669,8 @@
 	 * Setup LSNAT server pool.
 	 */
 	if (lsnat) {
-		int                     sof_spool = sizeof(struct cfg_spool);
-		struct cfg_spool        *tmp;
+		int sof_spool = sizeof(struct cfg_spool);
+		struct cfg_spool *tmp;
 		
 		sep = strtok(tmp_spool_buf, ",");
 		while (sep != NULL) {
@@ -3685,12 +3685,12 @@
 				errx(EX_DATAERR, "redirect_port: local port must be single in this context");
 			tmp->port = GETLOPORT(portRange);
 			r->spool_cnt++;	
-			/* point to the next possible cfg_spool */
+			/* Point to the next possible cfg_spool. */
 			spool_buf = &spool_buf[sof_spool];
 			sep = strtok(NULL, ",");
 		}
 	}
-	return(space);
+	return (space);
 nospace:
 	errx(EX_DATAERR, "redir_port: buf is too small\n");
 }
@@ -3707,7 +3707,7 @@
 	
 	if (len >= sof_redir) {
 		r = (struct cfg_redir *)spool_buf;
-		/* skip cfg_redir at beginning of buf */
+		/* Skip cfg_redir at beginning of buf. */
 		spool_buf = &spool_buf[sof_redir];
 		space = sof_redir;
 		len -= sof_redir;
@@ -3760,7 +3760,7 @@
 			}
 		}		
 	}
-	return(space);
+	return (space);
 nospace:
 	errx(EX_DATAERR, "redir_proto: buf is too small\n");
 }
@@ -3807,17 +3807,17 @@
 			n->mode &= ~PKT_ALIAS_PROXY_ONLY;
 		}
 	}
-	/* print all the redirect's data configuration */
+	/* Print all the redirect's data configuration. */
 	for (cnt=0; cnt < n->redir_cnt; cnt++) {
 		t = (struct cfg_redir *)&buf[off];
 		off += sof_redir;
-		switch(t->mode) {
+		switch (t->mode) {
 		case REDIR_ADDR:
 			printf(" redir_addr");
 			if (t->spool_cnt == 0)
 				printf(" %s", inet_ntoa(t->laddr));
 			else
-				for (i=0; i<t->spool_cnt; i++) {
+				for (i=0; i < t->spool_cnt; i++) {
 					s = (struct cfg_spool *)&buf[off];
 					if (i)
 						printf(",");
@@ -3836,7 +3836,7 @@
 				if (t->pport_cnt > 1)
 					printf("-%u", t->lport+t->pport_cnt-1);		       
 			} else
-				for (i=0; i<t->spool_cnt; i++) {
+				for (i=0; i < t->spool_cnt; i++) {
 					s = (struct cfg_spool *)&buf[off];
 					if (i)
 						printf(",");
@@ -3881,24 +3881,27 @@
 static void
 config_nat(int ac, char **av)
 {
-	struct cfg_nat *n;              /* nat instance configuration */
+	struct cfg_nat *n;              /* Nat instance configuration. */
 	struct in_addr ip;
 	int i, len = NAT_BUF_LEN;
-	/* offset in buf: save space for a n at the beginning */
-	int off=sizeof(*n);              
-	char *id, buf[NAT_BUF_LEN]; 	/* buffer for serialized data */
+	/* Offset in buf: save space for n at the beginning. */
+	int off = sizeof(*n);              
+	char *id, buf[NAT_BUF_LEN]; 	/* Buffer for serialized data. */
 	
 	memset(buf, 0, sizeof(buf));
 	n = (struct cfg_nat *)buf;
 
 	av++; ac--;
-	/* Nat id */
+	/* Nat id. */
 	if (ac && isdigit(**av)) {
 		id = *av;
-		i = atoi(*av); av++; ac--;
+		i = atoi(*av); 
+		ac--; av++;		
 		n->id = i;
-	} else errx(EX_DATAERR, "missing nat id");
-	if (ac == 0) errx(EX_DATAERR, "missing option");
+	} else 
+		errx(EX_DATAERR, "missing nat id");
+	if (ac == 0) 
+		errx(EX_DATAERR, "missing option");
 
 	while (ac > 0) {
 	  int tok = match_token(nat_params, *av);
@@ -3906,9 +3909,10 @@
 
 	  ac--; av++;
 
-	  switch(tok) {
+	  switch (tok) {
 	  case TOK_IP:
-	    if (ac == 0) errx(EX_DATAERR, "missing option");
+	    if (ac == 0) 
+		    errx(EX_DATAERR, "missing option");
 	    if (!inet_aton(av[0], &(n->ip)))
 	      errx(EX_DATAERR, "bad ip address ``%s''", av[0]);
 	    ac--; av++;
@@ -3948,13 +3952,13 @@
 	    break;
 
 	    /* 
-	     * all the setup_redir_* functions work directly in the final 
-	     * buffer, see above for details
+	     * All the setup_redir_* functions work directly in the final 
+	     * buffer, see above for details.
 	     */
 	  case TOK_REDIR_ADDR:
 	  case TOK_REDIR_PORT:
 	  case TOK_REDIR_PROTO:
-		  switch(tok) {
+		  switch (tok) {
 		  case TOK_REDIR_ADDR:
 			  i = setup_redir_addr(&buf[off], len, &ac, &av);
 			  break;
@@ -3981,7 +3985,7 @@
 	if (i)
 		err(1, "setsockopt(%s)", "IP_FW_NAT_CFG");
 
-	/* after every rule modification, we show the resultant rule */
+	/* After every modification, we show the resultant rule. */
 	int _ac = 3;
 	char *_av[] = {"show", "config", id};
 	show_nat(_ac, _av);
@@ -5830,21 +5834,22 @@
 	u_int8_t *data = NULL, *p;
 	char **lav, *endptr;
 
-	av++; ac--;
+	ac--; av++; 
 
-	/* parse parameters */
+	/* Parse parameters. */
 	for (cmd = IP_FW_NAT_GET_LOG, do_cfg = 0; ac != 0; ac--, av++) {
 		if (!strncmp(av[0], "config", strlen(av[0]))) {
-			cmd = IP_FW_NAT_GET_CONFIG, do_cfg = 1; continue;
+			cmd = IP_FW_NAT_GET_CONFIG, do_cfg = 1; 
+			continue;
 		}
-		/* convert command line rule # */
+		/* Convert command line rule #. */
 		frule = lrule = strtoul(av[0], &endptr, 10);
 		if (*endptr == '-')
 			lrule = strtoul(endptr+1, &endptr, 10);
 		if (lrule == 0)			
 			err(EX_USAGE, "invalid rule number: %s", av[0]);
 		do_rule = 1;
-	}	
+	}
 
 	nbytes = nalloc;
 	while (nbytes >= nalloc) {
@@ -5856,13 +5861,16 @@
 			err(EX_OSERR, "getsockopt(IP_FW_GET_%s)",
 			    (cmd == IP_FW_NAT_GET_LOG) ? "LOG" : "CONFIG");
 	}
-	if (nbytes == 0) exit(0); 
+	if (nbytes == 0) 
+		exit(0); 
 	if (do_cfg) {
 		for (i = 0, loop = 1; loop; ) {
 			n = (struct cfg_nat *)&data[i];
-			if (n->next == NULL) loop = 0;
+			if (n->next == NULL) 
+				loop = 0;
 			if (do_rule)
-				if (!(frule <= n->id && lrule >= n->id)) continue;
+				if (!(frule <= n->id && lrule >= n->id)) 
+					continue;
 			print_nat_config(&data[i]);
 			i += sizeof(struct cfg_nat);
 			e = (struct cfg_redir *)&data[i];
@@ -5874,10 +5882,12 @@
 	} else {		
 		for (i = 0; 1; i += LIBALIAS_BUF_SIZE + sizeof(int)) {
 			p = &data[i];
-			if (p == data + nbytes) break;
+			if (p == data + nbytes) 
+				break;
 			bcopy(p, &r, sizeof(int));
 			if (do_rule)				
-				if (!(frule <= r && lrule >= r)) continue;
+				if (!(frule <= r && lrule >= r)) 
+					continue;
 			printf("nat %u: %s\n", r, p+sizeof(int));			
 		}
 	}
@@ -6071,7 +6081,7 @@
 	}
 
 	/*
-	 * optional: pipe, queue or nat
+	 * Optional: pipe, queue or nat.
 	 */
 	do_nat = 0;
 	do_pipe = 0;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608291556.k7TFu2em012189>