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

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

Change 105274 by piso@piso_newluxor on 2006/08/29 17:01:29

	Style and cosmetic changes.
	While here, delete some 4.x/5.x compatibility code. 

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#6 edit

Differences ...

==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#6 (text+ko) ====

@@ -2037,39 +2037,8 @@
 	return match;
 }
 
-/* FIX for 5.x and 4.x branch: m_move_pkthdr is not mbuf_cluster safe there */
-#if __FreeBSD_version > 600000
-static void
-mym_move_pkthdr(struct mbuf *to, struct mbuf *from) {
-  m_move_pkthdr(to, from);
-}
-#else
 /*
- * "Move" mbuf pkthdr from "from" to "to".
- * "from" must have M_PKTHDR set, and "to" must be empty.
- */
-static void
-mym_move_pkthdr(struct mbuf *to, struct mbuf *from)
-{
-
-#ifdef MAC
-	/*
-	 * XXXMAC: It could be this should also occur for non-MAC?
-	 */
-	if (to->m_flags & M_PKTHDR)
-		m_tag_delete_chain(to, NULL);
-#endif
-	to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT);
-	if ((to->m_flags & M_EXT) == 0)
-		to->m_data = to->m_pktdat;
-	to->m_pkthdr = from->m_pkthdr;		/* especially tags */
-	SLIST_INIT(&from->m_pkthdr.tags);	/* purge tags from src */
-	from->m_flags &= ~M_PKTHDR;
-}
-#endif
-
-/*
- * m_megapullup() function is a big hack. (from ng_nat.c)
+ * m_megapullup() function (from ng_nat.c) is a big hack. 
  *
  * It allocates an mbuf with cluster and copies the whole
  * chain into cluster, so that it is all contigous and the
@@ -2094,7 +2063,7 @@
  
 	cp = mtod(mcl, caddr_t);
 	m_copydata(m, 0, len, cp);
-	mym_move_pkthdr(mcl, m);
+	m_move_pkthdr(mcl, m);
 	mcl->m_len = mcl->m_pkthdr.len;
 	m_freem(m);
  
@@ -2129,7 +2098,7 @@
 	return(NULL);
 }
 
-/* attach p to b chain */
+/* Attach p to b chain. */
 static void
 hook_entry(struct _chain **b, struct _chain *p) {
 		
@@ -2139,7 +2108,7 @@
 	*b = p;
 }
 
-/* remove p from b chain */
+/* Remove p from b chain. */
 static void
 unhook_entry(struct _chain **b, struct _chain *p) {
 	
@@ -2174,17 +2143,17 @@
 	int i, num;
 
 	while(r) {
-		num = 1; /* number of alias_link to delete */ 		       
-		switch(r->mode) {			
+		num = 1; /* Number of alias_link to delete. */
+		switch (r->mode) {			
 		case REDIR_PORT:
 			num = r->pport_cnt;
 		case REDIR_ADDR:
 		case REDIR_PROTO:
-			/* delete all libalias redirect entry */
+			/* Delete all libalias redirect entry. */
 			for (i = 0; i < num; i++)
 				LibAliasRedirectDelete(n->lib, 
 						       r->alink[i]);
-			/* del spool cfg if any */
+			/* Del spool cfg if any. */
 			while(r->spool_chain) {
 				tmp_s = r->spool_chain->next;
 				free(r->spool_chain, M_IPFW);
@@ -2213,13 +2182,13 @@
 	struct cfg_spool *s, *ser_s;		
 	int cnt, off, i;
 
-	for(cnt=0, off = 0; cnt<ptr->redir_cnt; cnt++) {
+	for(cnt = 0, off = 0; cnt < ptr->redir_cnt; cnt++) {
 		ser_r = (struct cfg_redir *)&buf[off];
 		r = malloc(sof_redir, M_IPFW, M_NOWAIT | M_ZERO);
 		if (r == NULL) {
-			/* try to recover: 
+			/* Try to recover: 
 			 * set the actual number of redir entries 
-			 * that were hooked succesfully
+			 * that were hooked succesfully.
 			 */
 			ptr->redir_cnt = cnt;
 			del_redir_spool_cfg(ptr, ptr->redir_chain);
@@ -2238,11 +2207,9 @@
 		}
 		switch(r->mode) {
 		case REDIR_ADDR:
-		{
 			r->alink[0] = LibAliasRedirectAddr(ptr->lib, 
 							   r->laddr, 
 							   r->paddr);
-		}
 			break;
 		case REDIR_PORT:
 			for (i = 0 ; i < r->pport_cnt; i++) {
@@ -2277,8 +2244,8 @@
 		if (r->alink[0] == NULL) { /* panic?!?!? */ 
 			free(r->alink, M_IPFW);
 			printf("previous LibAliasRedirect* returned NULL!!!\n");
-		} else /* handles LSNAT */			
-			for (i=0; i<r->spool_cnt; i++) {
+		} else /* LSNAT handling. */
+			for (i=0; i < r->spool_cnt; i++) {
 				ser_s = (struct cfg_spool *)&buf[off];
 				s = malloc(sof_redir, M_IPFW, M_NOWAIT | M_ZERO);
 				if (s == NULL) {
@@ -2287,17 +2254,17 @@
 					return (ENOSPC);
 				}
 				memcpy(s, ser_s, sof_spool);
-				LibAliasAddServer(ptr->lib, r->alink[0], // XXX - what about RedirectPort with many alink?
+				LibAliasAddServer(ptr->lib, r->alink[0], 
 						  s->addr, 
 						  htons(s->port));
 				off += sof_spool;
-				/* hook spool entry */
+				/* Hook spool entry. */
 				HOOK_SPOOL(&r->spool_chain, s);
-			}			
-		/* and finally hook this redir entry */
-		HOOK_REDIR(&ptr->redir_chain, r); 
+			}
+		/* And finally hook this redir entry. */
+		HOOK_REDIR(&ptr->redir_chain, r);
 	}
-	return(1);
+	return (1);
 }
 
 /*
@@ -3512,7 +3479,7 @@
 				int ldt = 0; 
 				char *c; 				
 				
-				args->rule = f;	/* report matching rule */
+				args->rule = f;	/* Report matching rule. */
 				retval = 0;
 				t = ((ipfw_insn_nat *)cmd)->nat;				
 				if (t == NULL) {
@@ -3521,24 +3488,19 @@
 					if (t == NULL) {
 						retval = IP_FW_DENY;
 						goto done;
-					} else ((ipfw_insn_nat *)cmd)->nat = t;					
+					} else 
+						((ipfw_insn_nat *)cmd)->nat = t;					
 				}
 				if ((mcl = m_megapullup(m, m->m_pkthdr.len)) == NULL)
 					goto badnat;
 				ip = mtod(mcl, struct ip *);
-				/* 
-				 * XXX - workaround for host-byte-order 4.x BSD well_known_bug:
-				 * due to 4.x BSD legacy, some fields in layer-3 packet COULD be
-				 * in host byte order instead of network byte order, so we have
-				 * to manually swap it before passing mbuf to libalias...
-				 */
-				if (args->eh == NULL) { /* host byte order */
+				if (args->eh == NULL) {
 					ip->ip_len = htons(ip->ip_len);
 					ip->ip_off = htons(ip->ip_off);                        
 				}
 
 				/* 
-				 * XXX - libalias checksum offload 'duct tape': 
+				 * XXX - Libalias checksum offload 'duct tape': 
 				 * 
 				 * locally generated packets have only pseudo-header
 				 * checksum calculated and libalias will screw it[1],
@@ -3574,8 +3536,6 @@
 				 * TODO:
 				 * -make libalias mbuf aware (so it can handle
 				 *  delayed checksum)
-				 * -maybe shrink the api? do we really need 23 
-				 *  functions?
 				 */
 
 				if (mcl->m_pkthdr.rcvif == NULL && 
@@ -3589,7 +3549,7 @@
 				else
 					retval = LibAliasOut(t->lib, c, MCLBYTES);
 				if (retval != PKT_ALIAS_OK) {
-					/* XXX - should i add some logging ? */
+					/* XXX - should i add some logging? */
 					m_free(mcl);
 				badnat:
 					args->m = NULL;
@@ -3623,10 +3583,10 @@
 						htons(ip->ip_p + ip->ip_len - (ip->ip_hl << 2))
 						);
 					
-					switch(ip->ip_p) {
+					switch (ip->ip_p) {
 					case IPPROTO_TCP:
 						th = (struct tcphdr *)(ip + 1);
-						/* maybe it was set in libalias... */
+						/* Maybe it was set in libalias... */
 						th->th_x2 = 0;
 						th->th_sum = cksum;
 						mcl->m_pkthdr.csum_data = 
@@ -3642,7 +3602,7 @@
 						break;
 						
 					}
-					/* no hw checksum offloading: do it by ourself */
+					/* No hw checksum offloading: do it by ourself. */
 					if ((mcl->m_pkthdr.csum_flags & CSUM_DELAY_DATA) == 0) {
 						in_delayed_cksum(mcl);
 						mcl->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
@@ -3650,8 +3610,7 @@
 					ip->ip_len = htons(ip->ip_len);
 				}
 
-				/* XXX - swap again some fields... see above */
-				if (args->eh == NULL) { /* host byte order */
+				if (args->eh == NULL) {
 					ip->ip_len = ntohs(ip->ip_len);
 					ip->ip_off = ntohs(ip->ip_off);                     
 				}
@@ -4394,9 +4353,9 @@
 	struct ifaddr *ifa;
 
 	NAT_WLOCK(&nat_chain);			
-	/* find every nat entry...*/
+	/* Check every nat entry... */
 	for (ptr = nat_chain.chain; ptr; ptr = ptr->next) {
-		/* ...using nic 'ifp->if_xname' as dynamic alias address */
+		/* ...using nic 'ifp->if_xname' as dynamic alias address. */
 		if (strncmp(ptr->if_name, ifp->if_xname, IF_NAMESIZE) == 0) {
 			mtx_lock(&ifp->if_addr_mtx);
 			TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
@@ -4649,11 +4608,14 @@
 		error = sooptcopyin(sopt, buf, NAT_BUF_LEN, sizeof(struct cfg_nat));
 		ser_n = (struct cfg_nat *)buf;
 		
-		/* FIND/CREATE NAT RULE */
+		/* 
+		 * Find/create nat rule.
+		 */
 		NAT_WLOCK(&nat_chain);
 		ptr = lookup_nat(ser_n->id);
-		if (ptr == NULL) { /* new rule: allocate and init new instance */					
-			ptr = malloc(sizeof(struct cfg_nat), M_IPFW, M_NOWAIT | M_ZERO);
+		if (ptr == NULL) { /* New rule: allocate and init new instance. */
+			ptr = malloc(sizeof(struct cfg_nat), 
+				     M_IPFW, M_NOWAIT | M_ZERO);
 			if (ptr == NULL) {		
 				free(buf, M_IPFW);
 				NAT_WUNLOCK(&nat_chain);				
@@ -4666,17 +4628,19 @@
 				NAT_WUNLOCK(&nat_chain);				
 				return(EINVAL);
 			}			
-		} else { /* entry already present: temporarly unhook it */			
+		} else { /* Entry already present: temporarly unhook it. */
 			UNHOOK_NAT(&nat_chain.chain, ptr);
 			flush_nat_ptrs(ser_n->id);						
 		}
 		NAT_WUNLOCK(&nat_chain);
 
-		/* BASIC NAT CONFIGURATION */
+		/* 
+		 * Basic nat configuration.
+		 */
 		ptr->id = ser_n->id;
 		/* 
 		 * XXX - what if this rule doesn't nat any ip and just redirect? 
-		 * do we set aliasaddress to 0.0.0.0? is it correct?
+		 * do we set aliasaddress to 0.0.0.0?
 		 */
 		ptr->ip = ser_n->ip;
 		ptr->redir_cnt = ser_n->redir_cnt;
@@ -4685,17 +4649,19 @@
 		LibAliasSetAddress(ptr->lib, ptr->ip);
 		memcpy(ptr->if_name, ser_n->if_name, IF_NAMESIZE);		
 
-		/* REDIR AND LSNAT CONFIGURATION */		
-		del_redir_spool_cfg(ptr, ptr->redir_chain);     /* delete old cfgs */		
+		/* 
+		 * Redir and LSNAT configuration.
+		 */
+		del_redir_spool_cfg(ptr, ptr->redir_chain);     /* Delete old cfgs. */
 		err = add_redir_spool_cfg(&buf[(sizeof(struct cfg_nat))], 
-					  ptr);                 /* add new entries */
+					  ptr);                 /* Add new entries. */
 		free(buf, M_IPFW);
 		if (err == 1) { 
 			NAT_WLOCK(&nat_chain);			
 			HOOK_NAT(&nat_chain.chain, ptr);
 			NAT_WUNLOCK(&nat_chain);			
-		} else /* something bad happened, redir cfg not added */			
-			return(EINVAL);			
+		} else /* Something bad happened, redir cfg not added. */
+			return(EINVAL);
 	}
 	break;
 
@@ -4736,7 +4702,7 @@
 		if (data == NULL)
 			return (ENOSPC);
 		NAT_RLOCK(&nat_chain);
-		/* serialize all the data */
+		/* Serialize all the data. */
 		for (n = nat_chain.chain; (n && (off + sof_nat < NAT_BUF_LEN)); 
 		     n = n->next) {
 			bcopy(n, &data[off], sof_nat);
@@ -4768,11 +4734,13 @@
 
 		NAT_RLOCK(&nat_chain);			
 		for (ptr = nat_chain.chain, size = i = 0; ptr; ptr = ptr->next) {
-			if (ptr->lib->logDesc == NULL) continue;
+			if (ptr->lib->logDesc == NULL) 
+				continue;
 			cnt++;
 			size = cnt * (sof + sizeof(int));
 			data = realloc(data, size, M_IPFW, M_NOWAIT | M_ZERO);
-			if (data == NULL) return (ENOSPC);
+			if (data == NULL) 
+				return (ENOSPC);
 			bcopy(&ptr->id, &data[i], sizeof(int));
 			i += sizeof(int);
 			bcopy(ptr->lib->logDesc, &data[i], sof);



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