IPVS: Add IPv6 support to LBLC/LBLCR schedulers
Subsystems (4)
PATCH 1/1 IPVS: Add IPv6 support to LBLC/LBLCR schedulers
Add IPv6 support to LBLC and LBLCR schedulers. These were the last schedulers without IPv6 support, but we might want to keep the supports_ipv6 flag in the case of future schedulers without IPv6 support.
--- net/netfilter/ipvs/ip_vs_lblc.c | 63 ++++++++++++++++---------- net/netfilter/ipvs/ip_vs_lblcr.c | 90 ++++++++++++++++++++++--------------- 2 files changed, 92 insertions(+), 61 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +39 -24
@@ -86,7 +86,8 @@ static int sysctl_ip_vs_lblc_expiration = 24*60*60*HZ;*/ struct ip_vs_lblc_entry {struct list_head list; -__be32 addr;/* destination IP address */ +int af;/* address family */ +union nf_inet_addr addr;/* destination IP address */ struct ip_vs_dest *dest;/* real server (cache) */ unsigned long lastuse;/* last used time */ };
@@ -137,9 +138,17 @@ static inline void ip_vs_lblc_free(struct ip_vs_lblc_entry *en)/* * Returns hash value for IPVS LBLC entry */ -static inline unsigned ip_vs_lblc_hashkey (__be32 addr) +static inline unsigned +ip_vs_lblc_hashkey (int af,const union nf_inet_addr *addr) { -return (ntohl (addr)*2654435761UL ) &IP_VS_LBLC_TAB_MASK ; +__be32 addr_fold = addr->ip; + +#ifdef CONFIG_IP_VS_IPV6 +if (af ==AF_INET6 ) + addr_fold = addr->ip6[0 ]^addr->ip6[1 ]^ + addr->ip6[2 ]^addr->ip6[3 ]; +#endif +return (ntohl (addr_fold)*2654435761UL ) &IP_VS_LBLC_TAB_MASK ; }
@@ -150,7 +159,7 @@ static inline unsigned ip_vs_lblc_hashkey(__be32 addr)static void ip_vs_lblc_hash (struct ip_vs_lblc_table *tbl,struct ip_vs_lblc_entry *en) { -unsigned hash =ip_vs_lblc_hashkey (en->addr); +unsigned hash =ip_vs_lblc_hashkey (en->af, &en->addr);list_add (&en->list, &tbl->bucket[hash]);atomic_inc (&tbl->entries);
@@ -162,13 +171,14 @@ ip_vs_lblc_hash(struct ip_vs_lblc_table *tbl, struct ip_vs_lblc_entry *en)* lock */ static inline struct ip_vs_lblc_entry * -ip_vs_lblc_get (struct ip_vs_lblc_table *tbl,__be32 addr) +ip_vs_lblc_get (int af,struct ip_vs_lblc_table *tbl, +const union nf_inet_addr *addr) { -unsigned hash =ip_vs_lblc_hashkey (addr); +unsigned hash =ip_vs_lblc_hashkey (af, addr);struct ip_vs_lblc_entry *en;list_for_each_entry (en, &tbl->bucket[hash], list) -if (en->addr == addr) +if (ip_vs_addr_equal (af, &en->addr, addr))return en;return NULL ;
@@ -180,12 +190,12 @@ ip_vs_lblc_get(struct ip_vs_lblc_table *tbl, __be32 addr)* address to a server. Called under write lock. */ static inline struct ip_vs_lblc_entry * -ip_vs_lblc_new (struct ip_vs_lblc_table *tbl,__be32 daddr, +ip_vs_lblc_new (struct ip_vs_lblc_table *tbl,const union nf_inet_addr *daddr,struct ip_vs_dest *dest) {struct ip_vs_lblc_entry *en; - en =ip_vs_lblc_get (tbl, daddr); + en =ip_vs_lblc_get (dest->af, tbl, daddr);if (!en) { en =kmalloc (sizeof (*en),GFP_ATOMIC );if (!en) {
@@ -193,7 +203,8 @@ ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, __be32 daddr,return NULL ; } - en->addr = daddr; + en->af = dest->af; +ip_vs_addr_copy (dest->af, &en->addr, daddr); en->lastuse = jiffies;atomic_inc (&dest->refcnt);
@@ -369,7 +380,7 @@ static int ip_vs_lblc_done_svc(struct ip_vs_service *svc)static inline struct ip_vs_dest * -__ip_vs_lblc_schedule (struct ip_vs_service *svc,struct iphdr *iph) +__ip_vs_lblc_schedule (struct ip_vs_service *svc) {struct ip_vs_dest *dest, *least;int loh, doh;
@@ -420,12 +431,13 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc, struct iphdr *iph) } } -IP_VS_DBG (6 ,"LBLC: server %pI4:%d " -"activeconns %d refcnt %d weight %d overhead %d\n" , - &least->addr.ip,ntohs (least->port), -atomic_read (&least->activeconns), -atomic_read (&least->refcnt), -atomic_read (&least->weight), loh); +IP_VS_DBG_BUF (6 ,"LBLC: server %s:%d " +"activeconns %d refcnt %d weight %d overhead %d\n" , +IP_VS_DBG_ADDR (least->af, &least->addr), +ntohs (least->port), +atomic_read (&least->activeconns), +atomic_read (&least->refcnt), +atomic_read (&least->weight), loh);return least; }
@@ -459,15 +471,17 @@ static struct ip_vs_dest * ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) { struct ip_vs_lblc_table *tbl = svc->sched_data; -struct iphdr *iph =ip_hdr (skb); +struct ip_vs_iphdr iph;struct ip_vs_dest *dest =NULL ;struct ip_vs_lblc_entry *en; +ip_vs_fill_iphdr (svc->af,skb_network_header (skb), &iph); +IP_VS_DBG (6 ,"ip_vs_lblc_schedule(): Scheduling...\n" );/* First look in our cache */ read_lock (&svc->sched_lock); - en =ip_vs_lblc_get (tbl, iph->daddr); + en =ip_vs_lblc_get (svc->af, tbl, &iph.daddr);if (en) {/* We only hold a read lock, but this is atomic */ en->lastuse = jiffies;
@@ -491,7 +505,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) goto out;/* No cache entry or it is invalid, time to schedule */ - dest =__ip_vs_lblc_schedule (svc, iph); + dest =__ip_vs_lblc_schedule (svc);if (!dest) {IP_VS_DBG (1 ,"no destination available\n" );return NULL ;
@@ -499,12 +513,13 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)/* If we fail to create a cache entry, we'll just use the valid dest */ write_lock (&svc->sched_lock); -ip_vs_lblc_new (tbl, iph->daddr, dest); +ip_vs_lblc_new (tbl, &iph.daddr, dest);write_unlock (&svc->sched_lock); out: -IP_VS_DBG (6 ,"LBLC: destination IP address %pI4 --> server %pI4:%d\n" , - &iph->daddr, &dest->addr.ip,ntohs (dest->port)); +IP_VS_DBG_BUF (6 ,"LBLC: destination IP address %s --> server %s:%d\n" , +IP_VS_DBG_ADDR (svc->af, &iph.daddr), +IP_VS_DBG_ADDR (svc->af, &dest->addr),ntohs (dest->port));return dest; }
@@ -520,7 +535,7 @@ static struct ip_vs_scheduler ip_vs_lblc_scheduler = .module = THIS_MODULE, .n_list =LIST_HEAD_INIT (ip_vs_lblc_scheduler.n_list), #ifdef CONFIG_IP_VS_IPV6 - .supports_ipv6 = 0, + .supports_ipv6 = 1, #endif .init_service = ip_vs_lblc_init_svc, .done_service = ip_vs_lblc_done_svc,
net/netfilter/ipvs/ip_vs_lblcr.c +53 -37
199 lines not on this page · raw message
Signature · 1 line
1.5.3.7
Quoted 4 lines · Julius Volz
Add IPv6 support to LBLC and LBLCR schedulers. These were the last schedulers without IPv6 support, but we might want to keep the
supports_ipv6flag in the case of future schedulers without IPv6 support.
Hi Julius,
this patch looks fine to me.
With regards to supports_ipv6, I think that it would be better to remove it, now that it is unused, and add it (or something similar) back if needed as I'm not entirely sure it will ever be needed again.
Signature · 3 lines
Simon Horman VA Linux Systems Japan K.K., Sydney, Australia Satellite Office H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
Quoted 11 lines · Simon Horman
Quoted 4 lines · Julius Volz
Add IPv6 support to LBLC and LBLCR schedulers. These were the last schedulers without IPv6 support, but we might want to keep the
supports_ipv6flag in the case of future schedulers without IPv6 support.Hi Julius,
this patch looks fine to me.
Acked-by Simon Horman <[email protected]>
Thanks!
Quoted 3 lines
With regards to
supports_ipv6, I think that it would be better to remove it, now that it is unused, and add it (or something similar) back if needed as I'm not entirely sure it will ever be needed again.
Agreed and patch sent!
Julius
From: Simon Horman <[email protected]>
Date: Tue, 4 Nov 2008 11:14:52 +1100
Quoted 11 lines · Julius Volz
Quoted 4 lines
Add IPv6 support to LBLC and LBLCR schedulers. These were the last schedulers without IPv6 support, but we might want to keep the
supports_ipv6flag in the case of future schedulers without IPv6 support.Hi Julius,
this patch looks fine to me.
Acked-by Simon Horman <[email protected]>
Applied to net-next-2.6