Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Jun 2008 20:57:39 GMT
From:      Gleb Kurtsou <gk@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 142850 for review
Message-ID:  <200806032057.m53Kvd4j026209@repoman.freebsd.org>

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

Change 142850 by gk@gk_h1 on 2008/06/03 20:57:06

	ifc

Affected files ...

.. //depot/projects/soc2008/gk_l2filter/sys-netinet/ip_carp.c#2 integrate
.. //depot/projects/soc2008/gk_l2filter/sys-netinet/ip_fw_nat.c#2 integrate
.. //depot/projects/soc2008/gk_l2filter/sys-netinet/libalias/alias.c#2 integrate
.. //depot/projects/soc2008/gk_l2filter/sys-netinet/libalias/alias_db.c#2 integrate
.. //depot/projects/soc2008/gk_l2filter/sys-netinet/libalias/alias_local.h#2 integrate
.. //depot/projects/soc2008/gk_l2filter/sys-netinet/tcp_subr.c#3 integrate
.. //depot/projects/soc2008/gk_l2filter/sys-netinet/tcp_timer.c#2 integrate

Differences ...

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/ip_carp.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/ip_carp.c,v 1.53 2008/02/07 13:18:59 glebius Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/ip_carp.c,v 1.54 2008/06/02 18:58:07 mlaier Exp $");
 
 #include "opt_carp.h"
 #include "opt_bpf.h"
@@ -241,9 +241,12 @@
 	u_int8_t version = CARP_VERSION, type = CARP_ADVERTISEMENT;
 	u_int8_t vhid = sc->sc_vhid & 0xff;
 	struct ifaddr *ifa;
-	int i;
+	int i, found;
+#ifdef INET
+	struct in_addr last, cur, in;
+#endif
 #ifdef INET6
-	struct in6_addr in6;
+	struct in6_addr last6, cur6, in6;
 #endif
 
 	if (sc->sc_carpdev)
@@ -264,21 +267,44 @@
 	SHA1Update(&sc->sc_sha1, (void *)&type, sizeof(type));
 	SHA1Update(&sc->sc_sha1, (void *)&vhid, sizeof(vhid));
 #ifdef INET
-	TAILQ_FOREACH(ifa, &SC2IFP(sc)->if_addrlist, ifa_list) {
-		if (ifa->ifa_addr->sa_family == AF_INET)
-			SHA1Update(&sc->sc_sha1,
-			    (void *)&ifatoia(ifa)->ia_addr.sin_addr.s_addr,
-			    sizeof(struct in_addr));
-	}
+	cur.s_addr = 0;
+	do {
+		found = 0;
+		last = cur;
+		cur.s_addr = 0xffffffff;
+		TAILQ_FOREACH(ifa, &SC2IFP(sc)->if_addrlist, ifa_list) {
+			in.s_addr = ifatoia(ifa)->ia_addr.sin_addr.s_addr;
+			if (ifa->ifa_addr->sa_family == AF_INET &&
+			    ntohl(in.s_addr) > ntohl(last.s_addr) &&
+			    ntohl(in.s_addr) < ntohl(cur.s_addr)) {
+				cur.s_addr = in.s_addr;
+				found++;
+			}
+		}
+		if (found)
+			SHA1Update(&sc->sc_sha1, (void *)&cur, sizeof(cur));
+	} while (found);
 #endif /* INET */
 #ifdef INET6
-	TAILQ_FOREACH(ifa, &SC2IFP(sc)->if_addrlist, ifa_list) {
-		if (ifa->ifa_addr->sa_family == AF_INET6) {
+	memset(&cur6, 0, sizeof(cur6));
+	do {
+		found = 0;
+		last6 = cur6;
+		memset(&cur6, 0xff, sizeof(cur6));
+		TAILQ_FOREACH(ifa, &SC2IFP(sc)->if_addrlist, ifa_list) {
 			in6 = ifatoia6(ifa)->ia_addr.sin6_addr;
-			in6_clearscope(&in6);
-			SHA1Update(&sc->sc_sha1, (void *)&in6, sizeof(in6));
+			if (IN6_IS_SCOPE_EMBED(&in6))
+				in6.s6_addr16[1] = 0;
+			if (ifa->ifa_addr->sa_family == AF_INET6 &&
+			    memcmp(&in6, &last6, sizeof(in6)) > 0 &&
+			    memcmp(&in6, &cur6, sizeof(in6)) < 0) {
+				cur6 = in6;
+				found++;
+			}
 		}
-	}
+		if (found)
+			SHA1Update(&sc->sc_sha1, (void *)&cur6, sizeof(cur6));
+	} while (found);
 #endif /* INET6 */
 
 	/* convert ipad to opad */

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/ip_fw_nat.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/ip_fw_nat.c,v 1.2 2008/03/03 22:32:01 piso Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/ip_fw_nat.c,v 1.3 2008/06/01 12:29:23 mav Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -318,11 +318,12 @@
 	c = mtod(mcl, char *);
 	if (args->oif == NULL)
 		retval = LibAliasIn(t->lib, c, 
-				    MCLBYTES);
+			mcl->m_len + M_TRAILINGSPACE(mcl));
 	else
 		retval = LibAliasOut(t->lib, c, 
-				     MCLBYTES);
-	if (retval != PKT_ALIAS_OK) {
+			mcl->m_len + M_TRAILINGSPACE(mcl));
+	if (retval != PKT_ALIAS_OK &&
+	    retval != PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
 		/* XXX - should i add some logging? */
 		m_free(mcl);
 	badnat:

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/libalias/alias.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias.c,v 1.61 2008/05/02 18:54:36 marck Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias.c,v 1.63 2008/06/01 17:52:40 mav Exp $");
 
 /*
     Alias.c provides supervisory control for the functions of the
@@ -1092,13 +1092,13 @@
 
 /* Local prototypes */
 static int	FragmentIn(struct libalias *la, struct in_addr ip_src, 
-		    struct in_addr *ip_dst, u_char ip_p, u_short *ip_sum);		    
+		    struct in_addr *ip_dst, u_short ip_id, u_short *ip_sum);		    
 static int	FragmentOut(struct libalias *, struct in_addr *ip_src, 
 		    u_short *ip_sum);
 
 static int
 FragmentIn(struct libalias *la, struct in_addr ip_src, struct in_addr *ip_dst,
-    u_char ip_id, u_short *ip_sum)
+    u_short ip_id, u_short *ip_sum)
 {
 	struct alias_link *lnk;
 
@@ -1656,29 +1656,49 @@
  * m_megapullup() - this function is a big hack.
  * Thankfully, it's only used in ng_nat and ipfw+nat.
  *
- * It allocates an mbuf with cluster and copies the whole chain into cluster,
- * so that it is all contiguous and the whole packet can be accessed via a
- * plain (char *) pointer.  This is required, because libalias doesn't know
- * how to handle mbuf chains.
+ * It allocates an mbuf with cluster and copies the specified part of the chain
+ * into cluster, so that it is all contiguous and can be accessed via a plain
+ * (char *) pointer. This is required, because libalias doesn't know how to
+ * handle mbuf chains.
  *
- * On success, m_megapullup returns an mbuf with cluster containing the input
- * packet, on failure NULL.  In both cases, the input packet is consumed.
+ * On success, m_megapullup returns an mbuf (possibly with cluster) containing
+ * the input packet, on failure NULL. The input packet is always consumed.
  */
 struct mbuf *
 m_megapullup(struct mbuf *m, int len) {
 	struct mbuf *mcl;
-	caddr_t cp;
 	
-	if (len > MCLBYTES)
+	if (len > m->m_pkthdr.len)
 		goto bad;
 	
-	if ((mcl = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR)) == NULL)
+	/* Do not reallocate packet if it is sequentional,
+	 * writable and has some extra space for expansion.
+	 * XXX: Constant 100bytes is completely empirical. */
+#define	RESERVE 100
+	if (m->m_next == NULL && M_WRITABLE(m) && M_TRAILINGSPACE(m) >= RESERVE)
+		return (m);
+
+	if (len <= MCLBYTES - RESERVE) {
+		mcl = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
+	} else if (len < MJUM16BYTES) {
+		int size;
+		if (len <= MJUMPAGESIZE - RESERVE) {
+			size = MJUMPAGESIZE;
+		} else if (len <= MJUM9BYTES - RESERVE) {
+			size = MJUM9BYTES;
+		} else {
+			size = MJUM16BYTES;
+		};
+		mcl = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, size);
+	} else {
+		goto bad;
+	}
+	if (mcl == NULL)
 		goto bad;
  
-	cp = mtod(mcl, caddr_t);
-	m_copydata(m, 0, len, cp);
 	m_move_pkthdr(mcl, m);
-	mcl->m_len = mcl->m_pkthdr.len;
+	m_copydata(m, 0, len, mtod(mcl, caddr_t));
+	mcl->m_len = mcl->m_pkthdr.len = len;
 	m_freem(m);
  
 	return (mcl);

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/libalias/alias_db.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_db.c,v 1.72 2008/03/06 21:50:40 piso Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_db.c,v 1.73 2008/06/01 18:34:58 mav Exp $");
 
 /*
     Alias_db.c encapsulates all data structures used for storing
@@ -180,8 +180,9 @@
 */
 
 /* Parameters used for cleanup of expired links */
-#define ALIAS_CLEANUP_INTERVAL_SECS  60
-#define ALIAS_CLEANUP_MAX_SPOKES     30
+/* NOTE: ALIAS_CLEANUP_INTERVAL_SECS must be less then LINK_TABLE_OUT_SIZE */
+#define ALIAS_CLEANUP_INTERVAL_SECS  64
+#define ALIAS_CLEANUP_MAX_SPOKES     (LINK_TABLE_OUT_SIZE/5)
 
 /* Timeouts (in seconds) for different link types */
 #define ICMP_EXPIRE_TIME             60
@@ -814,20 +815,12 @@
 CleanupAliasData(struct libalias *la)
 {
 	struct alias_link *lnk;
-	int i, icount;
+	int i;
 
 	LIBALIAS_LOCK_ASSERT(la);
-	icount = 0;
 	for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) {
-		lnk = LIST_FIRST(&la->linkTableOut[i]);
-		while (lnk != NULL) {
-			struct alias_link *link_next;
-
-			link_next = LIST_NEXT(lnk, list_out);
-			icount++;
+		while ((lnk = LIST_FIRST(&la->linkTableOut[i])) != NULL)
 			DeleteLink(lnk);
-			lnk = link_next;
-		}
 	}
 
 	la->cleanupIndex = 0;
@@ -837,39 +830,13 @@
 static void
 IncrementalCleanup(struct libalias *la)
 {
-	int icount;
-	struct alias_link *lnk;
+	struct alias_link *lnk, *lnk_tmp;
 
 	LIBALIAS_LOCK_ASSERT(la);
-	icount = 0;
-	lnk = LIST_FIRST(&la->linkTableOut[la->cleanupIndex++]);
-	while (lnk != NULL) {
-		int idelta;
-		struct alias_link *link_next;
-
-		link_next = LIST_NEXT(lnk, list_out);
-		idelta = la->timeStamp - lnk->timestamp;
-		switch (lnk->link_type) {
-		case LINK_TCP:
-			if (idelta > lnk->expire_time) {
-				struct tcp_dat *tcp_aux;
-
-				tcp_aux = lnk->data.tcp;
-				if (tcp_aux->state.in != ALIAS_TCP_STATE_CONNECTED
-				    || tcp_aux->state.out != ALIAS_TCP_STATE_CONNECTED) {
-					DeleteLink(lnk);
-					icount++;
-				}
-			}
-			break;
-		default:
-			if (idelta > lnk->expire_time) {
-				DeleteLink(lnk);
-				icount++;
-			}
-			break;
-		}
-		lnk = link_next;
+	LIST_FOREACH_SAFE(lnk, &la->linkTableOut[la->cleanupIndex++],
+	    list_out, lnk_tmp) {
+		if (la->timeStamp - lnk->timestamp > lnk->expire_time)
+			DeleteLink(lnk);
 	}
 
 	if (la->cleanupIndex == LINK_TABLE_OUT_SIZE)
@@ -1137,12 +1104,12 @@
 	LIBALIAS_LOCK_ASSERT(la);
 	i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type);
 	LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) {
-		if (lnk->src_addr.s_addr == src_addr.s_addr
-		    && lnk->server == NULL
-		    && lnk->dst_addr.s_addr == dst_addr.s_addr
-		    && lnk->dst_port == dst_port
-		    && lnk->src_port == src_port
-		    && lnk->link_type == link_type) {
+		if (lnk->dst_addr.s_addr == dst_addr.s_addr &&
+		    lnk->src_addr.s_addr == src_addr.s_addr &&
+		    lnk->src_port == src_port &&
+		    lnk->dst_port == dst_port &&
+		    lnk->link_type == link_type &&
+		    lnk->server == NULL) {
 			lnk->timestamp = la->timeStamp;
 			break;
 		}
@@ -2189,7 +2156,7 @@
 void
 HouseKeeping(struct libalias *la)
 {
-	int i, n, n100;
+	int i, n;
 #ifndef	_KERNEL
 	struct timeval tv;
 	struct timezone tz;
@@ -2209,33 +2176,22 @@
 #endif
 
 	/* Compute number of spokes (output table link chains) to cover */
-	n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual;
-	n100 *= la->timeStamp - la->lastCleanupTime;
-	n100 /= ALIAS_CLEANUP_INTERVAL_SECS;
+	n = LINK_TABLE_OUT_SIZE * (la->timeStamp - la->lastCleanupTime);
+	n /= ALIAS_CLEANUP_INTERVAL_SECS;
 
-	n = n100 / 100;
-
 	/* Handle different cases */
-	if (n > ALIAS_CLEANUP_MAX_SPOKES) {
-		n = ALIAS_CLEANUP_MAX_SPOKES;
+	if (n > 0) {
+		if (n > ALIAS_CLEANUP_MAX_SPOKES)
+			n = ALIAS_CLEANUP_MAX_SPOKES;
 		la->lastCleanupTime = la->timeStamp;
-		la->houseKeepingResidual = 0;
-
 		for (i = 0; i < n; i++)
 			IncrementalCleanup(la);
-	} else if (n > 0) {
-		la->lastCleanupTime = la->timeStamp;
-		la->houseKeepingResidual = n100 - 100 * n;
-
-		for (i = 0; i < n; i++)
-			IncrementalCleanup(la);
 	} else if (n < 0) {
 #ifdef LIBALIAS_DEBUG
 		fprintf(stderr, "PacketAlias/HouseKeeping(): ");
 		fprintf(stderr, "something unexpected in time values\n");
 #endif
 		la->lastCleanupTime = la->timeStamp;
-		la->houseKeepingResidual = 0;
 	}
 }
 
@@ -2529,7 +2485,6 @@
 		la->timeStamp = tv.tv_sec;
 		la->lastCleanupTime = tv.tv_sec;
 #endif
-		la->houseKeepingResidual = 0;
 
 		for (i = 0; i < LINK_TABLE_OUT_SIZE; i++)
 			LIST_INIT(&la->linkTableOut[i]);

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/libalias/alias_local.h#2 (text+ko) ====

@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/netinet/libalias/alias_local.h,v 1.35 2008/03/06 21:50:40 piso Exp $
+ * $FreeBSD: src/sys/netinet/libalias/alias_local.h,v 1.36 2008/06/01 18:34:58 mav Exp $
  */
 
 /*
@@ -60,7 +60,7 @@
 #endif
 
 /* Sizes of input and output link tables */
-#define LINK_TABLE_OUT_SIZE         101
+#define LINK_TABLE_OUT_SIZE        4001
 #define LINK_TABLE_IN_SIZE         4001
 
 struct proxy_entry;
@@ -110,8 +110,6 @@
 						 * IncrementalCleanup()  */
 	/* was called                      */
 
-	int		houseKeepingResidual;	/* used by HouseKeeping()          */
-
 	int		deleteAllLinks;	/* If equal to zero, DeleteLink()  */
 	/* will not remove permanent links */
 	

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/tcp_subr.c#3 (text+ko) ====

@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/tcp_subr.c,v 1.307 2008/05/29 14:28:26 rwatson Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/tcp_subr.c,v 1.308 2008/06/02 14:20:26 rwatson Exp $");
 
 #include "opt_compat.h"
 #include "opt_inet.h"
@@ -385,17 +385,13 @@
 struct tcptemp *
 tcpip_maketemplate(struct inpcb *inp)
 {
-	struct mbuf *m;
-	struct tcptemp *n;
+	struct tcptemp *t;
 
-	m = m_get(M_DONTWAIT, MT_DATA);
-	if (m == NULL)
-		return (0);
-	m->m_len = sizeof(struct tcptemp);
-	n = mtod(m, struct tcptemp *);
-
-	tcpip_fillheaders(inp, (void *)&n->tt_ipgen, (void *)&n->tt_t);
-	return (n);
+	t = malloc(sizeof(*t), M_TEMP, M_NOWAIT);
+	if (t == NULL)
+		return (NULL);
+	tcpip_fillheaders(inp, (void *)&t->tt_ipgen, (void *)&t->tt_t);
+	return (t);
 }
 
 /*

==== //depot/projects/soc2008/gk_l2filter/sys-netinet/tcp_timer.c#2 (text+ko) ====

@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/netinet/tcp_timer.c,v 1.100 2008/04/17 21:38:16 rwatson Exp $");
+__FBSDID("$FreeBSD: src/sys/netinet/tcp_timer.c,v 1.101 2008/06/02 14:20:26 rwatson Exp $");
 
 #include "opt_inet6.h"
 #include "opt_tcpdebug.h"
@@ -313,7 +313,7 @@
 			tcp_respond(tp, t_template->tt_ipgen,
 				    &t_template->tt_t, (struct mbuf *)NULL,
 				    tp->rcv_nxt, tp->snd_una - 1, 0);
-			(void) m_free(dtom(t_template));
+			free(t_template, M_TEMP);
 		}
 		callout_reset(&tp->t_timers->tt_keep, tcp_keepintvl, tcp_timer_keep, tp);
 	} else



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