[PATCH 23/26] IPVS: Add hash functions for IPv6 services and real servers.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Julius R. Volz
Date: Wednesday, June 11, 2008 - 10:12 am

Add hashing functions ip_vs_svc_hashkey_v6() for hashing IPv6 service
entries and ip_vs_rs_hashkey_v6() for hashing real servers.

Signed-off-by: Julius R. Volz <juliusv@google.com>

 1 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index cf52034..ca198b9 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -37,6 +37,10 @@
 
 #include <net/net_namespace.h>
 #include <net/ip.h>
+#ifdef CONFIG_IP_VS_IPV6
+#include <net/ipv6.h>
+#include <net/ip6_route.h>
+#endif
 #include <net/route.h>
 #include <net/sock.h>
 
@@ -308,6 +312,20 @@ ip_vs_svc_hashkey(unsigned proto, __be32 addr, __be16 port)
 		& IP_VS_SVC_TAB_MASK;
 }
 
+#ifdef CONFIG_IP_VS_IPV6
+static __inline__ unsigned
+ip_vs_svc_hashkey_v6(unsigned proto, const struct in6_addr *addr, __be16 port)
+{
+	register unsigned porth = ntohs(port);
+
+	/* TODO IPv6: is this a good way to hash IPv6 entries? */
+	int addr_fold = addr->s6_addr32[0]^addr->s6_addr32[1]^
+			addr->s6_addr32[2]^addr->s6_addr32[3];
+	return (proto^ntohl(addr_fold)^(porth>>IP_VS_SVC_TAB_BITS)^porth)
+		& IP_VS_SVC_TAB_MASK;
+}
+#endif
+
 /*
  *	Returns hash value of fwmark for virtual service lookup
  */
@@ -335,7 +353,13 @@ static int ip_vs_svc_hash(struct ip_vs_service *svc)
 		/*
 		 *  Hash it by <protocol,addr,port> in ip_vs_svc_table
 		 */
-		hash = ip_vs_svc_hashkey(svc->protocol, svc->addr, svc->port);
+#ifdef CONFIG_IP_VS_IPV6
+		hash = (svc->af == AF_INET)
+			? ip_vs_svc_hashkey(svc->protocol, svc->addr.v4, svc->port)
+			: ip_vs_svc_hashkey_v6(svc->protocol, &svc->addr.v6, svc->port);
+#else
+		hash = ip_vs_svc_hashkey(svc->protocol, svc->addr.v4, svc->port);
+#endif
 		list_add(&svc->s_list, &ip_vs_svc_table[hash]);
 	} else {
 		/*
@@ -506,6 +530,20 @@ static __inline__ unsigned ip_vs_rs_hashkey(__be32 addr, __be16 port)
 		& IP_VS_RTAB_MASK;
 }
 
+#ifdef CONFIG_IP_VS_IPV6
+static __inline__ unsigned ip_vs_rs_hashkey_v6(const struct in6_addr *addr,
+					       __be16 port)
+{
+	register unsigned porth = ntohs(port);
+
+	/* TODO IPv6: is this a good way to hash IPv6 entries? */
+	int addr_fold = addr->s6_addr32[0]^addr->s6_addr32[1]^
+			addr->s6_addr32[2]^addr->s6_addr32[3];
+	return (ntohl(addr_fold)^(porth>>IP_VS_RTAB_BITS)^porth)
+		& IP_VS_RTAB_MASK;
+}
+#endif
+
 /*
  *	Hashes ip_vs_dest in ip_vs_rtable by <proto,addr,port>.
  *	should be called with locked tables.
@@ -522,7 +560,13 @@ static int ip_vs_rs_hash(struct ip_vs_dest *dest)
 	 *	Hash by proto,addr,port,
 	 *	which are the parameters of the real service.
 	 */
-	hash = ip_vs_rs_hashkey(dest->addr, dest->port);
+#ifdef CONFIG_IP_VS_IPV6
+	if (dest->af == AF_INET6)
+		hash = ip_vs_rs_hashkey_v6(&dest->addr.v6, dest->port);
+	else
+#endif
+		hash = ip_vs_rs_hashkey(dest->addr.v4, dest->port);
+
 	list_add(&dest->d_list, &ip_vs_rtable[hash]);
 
 	return 1;
-- 
1.5.3.6

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius R. Volz, (Wed Jun 11, 10:11 am)
[PATCH 11/26] IPVS: Add supports_ipv6 flag to schedulers., Julius R. Volz, (Wed Jun 11, 10:11 am)
[PATCH 15/26] IPVS: Modify IP_VS_XMIT() to support IPv6., Julius R. Volz, (Wed Jun 11, 10:11 am)
[PATCH 16/26] IPVS: Add IPv6 xmit forwarding functions., Julius R. Volz, (Wed Jun 11, 10:11 am)
[PATCH 23/26] IPVS: Add hash functions for IPv6 services a ..., Julius R. Volz, (Wed Jun 11, 10:12 am)
[PATCH 24/26] IPVS: Add IPv6 support to userspace interface., Julius R. Volz, (Wed Jun 11, 10:12 am)
[PATCH 26/26] IPVS: Add some blame/credits for IPv6 version., Julius R. Volz, (Wed Jun 11, 10:12 am)
Re: [PATCH 10/26] IPVS: Add IPv6 handler functions to UDP ..., Patrick McHardy, (Wed Jun 11, 10:18 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 11, 10:23 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius Volz, (Wed Jun 11, 11:23 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 11, 11:42 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius Volz, (Wed Jun 11, 12:05 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 11, 12:10 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius Volz, (Wed Jun 11, 12:29 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 11, 12:31 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius Volz, (Wed Jun 11, 12:53 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Simon Horman, (Wed Jun 11, 6:45 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Thu Jun 12, 6:38 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Thu Jun 12, 8:46 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius Volz, (Thu Jun 12, 12:33 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Simon Horman, (Thu Jun 12, 11:26 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Fri Jun 13, 8:14 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Mon Jun 16, 4:47 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Tue Jun 17, 4:52 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Julius Volz, (Tue Jun 17, 10:18 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Tue Jun 17, 1:08 pm)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 18, 1:57 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 18, 7:19 am)
Re: [PATCH 00/26] IPVS: Add first IPv6 support to IPVS., Patrick McHardy, (Wed Jun 18, 7:30 am)