Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Jun 2021 18:06:03 GMT
From:      Lutz Donnerhacke <donner@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: cac129e60300 - main - libalias: Restructure - Table for partially links
Message-ID:  <202106191806.15JI63Yf093326@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by donner:

URL: https://cgit.FreeBSD.org/src/commit/?id=cac129e6030095c33e95c5ce1cdcb9c5c21efce9

commit cac129e6030095c33e95c5ce1cdcb9c5c21efce9
Author:     Lutz Donnerhacke <donner@FreeBSD.org>
AuthorDate: 2021-05-25 16:27:33 +0000
Commit:     Lutz Donnerhacke <donner@FreeBSD.org>
CommitDate: 2021-06-19 18:03:08 +0000

    libalias: Restructure - Table for partially links
    
    Separate the partially specified links into a separate data structure.
    
    This would causes a major parformance impact, if there are many of
    them.  Use a (smaller) hash table to speed up the partially link
    access.
    
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D30570
---
 sys/netinet/libalias/alias_db.c    | 74 +++++++++++++++++++++++++-------------
 sys/netinet/libalias/alias_local.h |  2 ++
 2 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/sys/netinet/libalias/alias_db.c b/sys/netinet/libalias/alias_db.c
index dfb4cd9c8287..39b82d9d3a01 100644
--- a/sys/netinet/libalias/alias_db.c
+++ b/sys/netinet/libalias/alias_db.c
@@ -401,6 +401,13 @@ static void	UninitPacketAliasLog(struct libalias *);
 
 void		SctpShowAliasStats(struct libalias *la);
 
+static u_int
+StartPartialIn(u_short alias_port, int link_type)
+{
+	return (link_type == LINK_PPTP) ? 0
+	    : (alias_port % LINK_PARTIAL_SIZE);
+}
+
 static u_int
 StartPointIn(struct in_addr alias_addr,
     u_short alias_port,
@@ -1036,8 +1043,13 @@ AddLink(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr,
 		LIST_INSERT_HEAD(&la->linkTableOut[start_point], lnk, list_out);
 
 		/* Set up pointers for input lookup table */
-		start_point = StartPointIn(alias_addr, lnk->alias_port, link_type);
-		LIST_INSERT_HEAD(&la->linkTableIn[start_point], lnk, list_in);
+		if (lnk->flags & LINK_PARTIALLY_SPECIFIED) {
+			start_point = StartPartialIn(lnk->alias_port, link_type);
+			LIST_INSERT_HEAD(&la->linkPartialIn[start_point], lnk, list_in);
+		} else {
+			start_point = StartPointIn(alias_addr, lnk->alias_port, link_type);
+			LIST_INSERT_HEAD(&la->linkTableIn[start_point], lnk, list_in);
+		}
 
 		/* Include the element into the housekeeping list */
 		TAILQ_INSERT_TAIL(&la->checkExpire, lnk, list_expire);
@@ -1213,8 +1225,6 @@ _FindLinkIn(struct libalias *la, struct in_addr dst_addr,
 	if (!(flags_in & LINK_PARTIALLY_SPECIFIED)) {
 		LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) {
 			INGUARD;
-			if (lnk->flags & LINK_PARTIALLY_SPECIFIED)
-				continue;
 			if (lnk->dst_addr.s_addr == dst_addr.s_addr
 			    && lnk->dst_port == dst_port) {
 				CleanupLink(la, &lnk);
@@ -1224,28 +1234,44 @@ _FindLinkIn(struct libalias *la, struct in_addr dst_addr,
 				}
 			}
 		}
-	}
-	LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) {
-		int flags;
+	} else {
+		LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) {
+			int flags = flags_in & LINK_PARTIALLY_SPECIFIED;
 
-		INGUARD;
-		flags = flags_in | lnk->flags;
-		if ((flags & LINK_UNKNOWN_DEST_ADDR)
-		    && (flags & LINK_UNKNOWN_DEST_PORT)) {
-			if (lnk_unknown_all == NULL)
+			INGUARD;
+			if (flags == LINK_PARTIALLY_SPECIFIED &&
+			    lnk_unknown_all == NULL)
 				lnk_unknown_all = lnk;
-		} else if (flags & LINK_UNKNOWN_DEST_ADDR) {
-			if (lnk->dst_port == dst_port) {
-				if (lnk_unknown_dst_addr == NULL)
-					lnk_unknown_dst_addr = lnk;
-			}
-		} else if (flags & LINK_UNKNOWN_DEST_PORT) {
-			if (lnk->dst_addr.s_addr == dst_addr.s_addr) {
-				if (lnk_unknown_dst_port == NULL)
-					lnk_unknown_dst_port = lnk;
+			if (flags == LINK_UNKNOWN_DEST_ADDR &&
+			    lnk->dst_port == dst_port &&
+			    lnk_unknown_dst_addr == NULL)
+				lnk_unknown_dst_addr = lnk;
+			if (flags == LINK_UNKNOWN_DEST_PORT &&
+			    lnk->dst_addr.s_addr == dst_addr.s_addr) {
+				lnk_unknown_dst_port = lnk;
+				break;
 			}
 		}
 	}
+
+	start_point = StartPartialIn(alias_port, link_type);
+	LIST_FOREACH(lnk, &la->linkPartialIn[start_point], list_in) {
+		int flags = (flags_in | lnk->flags) & LINK_PARTIALLY_SPECIFIED;
+
+		INGUARD;
+		if (flags == LINK_PARTIALLY_SPECIFIED &&
+		    lnk_unknown_all == NULL)
+			lnk_unknown_all = lnk;
+		if (flags == LINK_UNKNOWN_DEST_ADDR &&
+		    lnk->dst_port == dst_port &&
+		    lnk_unknown_dst_addr == NULL)
+			lnk_unknown_dst_addr = lnk;
+		if (flags == LINK_UNKNOWN_DEST_PORT &&
+		    lnk->dst_addr.s_addr == dst_addr.s_addr) {
+			lnk_unknown_dst_port = lnk;
+			break;
+		}
+	}
 #undef INGUARD
 
 	if (lnk_unknown_dst_port != NULL)
@@ -1612,12 +1638,10 @@ FindPptpInByCallId(struct libalias *la, struct in_addr dst_addr,
     struct in_addr alias_addr,
     u_int16_t dst_call_id)
 {
-	u_int i;
 	struct alias_link *lnk;
 
 	LIBALIAS_LOCK_ASSERT(la);
-	i = StartPointIn(alias_addr, 0, LINK_PPTP);
-	LIST_FOREACH(lnk, &la->linkTableIn[i], list_in)
+	LIST_FOREACH(lnk, &la->linkPartialIn[0], list_in)
 		if (lnk->link_type == LINK_PPTP &&
 		    lnk->dst_addr.s_addr == dst_addr.s_addr &&
 		    lnk->alias_addr.s_addr == alias_addr.s_addr &&
@@ -2447,6 +2471,8 @@ LibAliasInit(struct libalias *la)
 			LIST_INIT(&la->linkTableOut[i]);
 		for (i = 0; i < LINK_TABLE_IN_SIZE; i++)
 			LIST_INIT(&la->linkTableIn[i]);
+		for (i = 0; i < LINK_PARTIAL_SIZE; i++)
+			LIST_INIT(&la->linkPartialIn[i]);
 		TAILQ_INIT(&la->checkExpire);
 #ifdef _KERNEL
 		AliasSctpInit(la);
diff --git a/sys/netinet/libalias/alias_local.h b/sys/netinet/libalias/alias_local.h
index f1b40f0438da..47123d769375 100644
--- a/sys/netinet/libalias/alias_local.h
+++ b/sys/netinet/libalias/alias_local.h
@@ -68,6 +68,7 @@
 /* Sizes of input and output link tables */
 #define LINK_TABLE_OUT_SIZE	4001
 #define LINK_TABLE_IN_SIZE	4001
+#define LINK_PARTIAL_SIZE	401
 
 #define	GET_ALIAS_PORT		-1
 #define	GET_ALIAS_ID		GET_ALIAS_PORT
@@ -94,6 +95,7 @@ struct libalias {
 	 * output lookup tables. */
 	LIST_HEAD     (, alias_link) linkTableOut[LINK_TABLE_OUT_SIZE];
 	LIST_HEAD     (, alias_link) linkTableIn[LINK_TABLE_IN_SIZE];
+	LIST_HEAD     (, alias_link) linkPartialIn[LINK_PARTIAL_SIZE];
 	/* HouseKeeping */
 	TAILQ_HEAD    (, alias_link) checkExpire;
 	/* Link statistics */



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