]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/netfilter/ipvs/ip_vs_lblc.c
IPVS: use pr_err and friends instead of IP_VS_ERR and friends
[net-next-2.6.git] / net / netfilter / ipvs / ip_vs_lblc.c
index 6ecef3518cac190090e3748039c7aa4e4f2053c6..c1757f3620cd502a5d16e3ef743273ac63b5f56d 100644 (file)
@@ -39,6 +39,9 @@
  * me to write this module.
  */
 
+#define KMSG_COMPONENT "IPVS"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
 #include <linux/ip.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -86,7 +89,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 */
 };
@@ -115,7 +119,7 @@ static ctl_table vs_vars_table[] = {
                .data           = &sysctl_ip_vs_lblc_expiration,
                .maxlen         = sizeof(int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_jiffies,
+               .proc_handler   = proc_dointvec_jiffies,
        },
        { .ctl_name = 0 }
 };
@@ -137,9 +141,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 +162,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 +174,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,20 +193,21 @@ 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) {
-                       IP_VS_ERR("ip_vs_lblc_new(): no memory\n");
+                       pr_err("%s(): no memory\n", __func__);
                        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);
@@ -321,7 +335,7 @@ static int ip_vs_lblc_init_svc(struct ip_vs_service *svc)
         */
        tbl = kmalloc(sizeof(*tbl), GFP_ATOMIC);
        if (tbl == NULL) {
-               IP_VS_ERR("ip_vs_lblc_init_svc(): no memory\n");
+               pr_err("%s(): no memory\n", __func__);
                return -ENOMEM;
        }
        svc->sched_data = tbl;
@@ -369,7 +383,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 +434,13 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc, struct iphdr *iph)
                }
        }
 
-       IP_VS_DBG(6, "LBLC: server %d.%d.%d.%d:%d "
-                 "activeconns %d refcnt %d weight %d overhead %d\n",
-                 NIPQUAD(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 +474,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_DBG(6, "ip_vs_lblc_schedule(): Scheduling...\n");
+       ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
+
+       IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
 
        /* 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,23 +508,21 @@ 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");
+               IP_VS_ERR_RL("LBLC: no destination available\n");
                return NULL;
        }
 
        /* 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 %u.%u.%u.%u "
-                 "--> server %u.%u.%u.%u:%d\n",
-                 NIPQUAD(iph->daddr),
-                 NIPQUAD(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;
 }
@@ -522,9 +537,6 @@ static struct ip_vs_scheduler ip_vs_lblc_scheduler =
        .refcnt =               ATOMIC_INIT(0),
        .module =               THIS_MODULE,
        .n_list =               LIST_HEAD_INIT(ip_vs_lblc_scheduler.n_list),
-#ifdef CONFIG_IP_VS_IPV6
-       .supports_ipv6 =        0,
-#endif
        .init_service =         ip_vs_lblc_init_svc,
        .done_service =         ip_vs_lblc_done_svc,
        .schedule =             ip_vs_lblc_schedule,