[NETFILTER]: Remove redundant parentheses/braces
[deliverable/linux.git] / net / ipv4 / netfilter / ipt_CLUSTERIP.c
index 343c2abdc1a0829d458a202fe00012376d48a8fb..5de13b44b1ca8942181657ae727b55ab94174711 100644 (file)
@@ -1,4 +1,4 @@
-/* Cluster IP hashmark target 
+/* Cluster IP hashmark target
  * (C) 2003-2004 by Harald Welte <laforge@netfilter.org>
  * based on ideas of Fabio Olive Leite <olive@unixforge.org>
  *
 #include <linux/if_arp.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-
-#include <net/checksum.h>
-
 #include <linux/netfilter_arp.h>
-
 #include <linux/netfilter/x_tables.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 #include <linux/netfilter_ipv4/ipt_CLUSTERIP.h>
-#include <net/netfilter/nf_conntrack_compat.h>
+#include <net/netfilter/nf_conntrack.h>
+#include <net/checksum.h>
 
 #define CLUSTERIP_VERSION "0.8"
 
@@ -70,7 +67,7 @@ static LIST_HEAD(clusterip_configs);
 static DEFINE_RWLOCK(clusterip_lock);
 
 #ifdef CONFIG_PROC_FS
-static struct file_operations clusterip_proc_fops;
+static const struct file_operations clusterip_proc_fops;
 static struct proc_dir_entry *clusterip_procdir;
 #endif
 
@@ -123,11 +120,10 @@ __clusterip_config_find(__be32 clusterip)
        struct list_head *pos;
 
        list_for_each(pos, &clusterip_configs) {
-               struct clusterip_config *c = list_entry(pos, 
+               struct clusterip_config *c = list_entry(pos,
                                        struct clusterip_config, list);
-               if (c->clusterip == clusterip) {
+               if (c->clusterip == clusterip)
                        return c;
-               }
        }
 
        return NULL;
@@ -158,9 +154,8 @@ clusterip_config_init_nodelist(struct clusterip_config *c,
 {
        int n;
 
-       for (n = 0; n < i->num_local_nodes; n++) {
+       for (n = 0; n < i->num_local_nodes; n++)
                set_bit(i->local_nodes[n] - 1, &c->local_nodes);
-       }
 }
 
 static struct clusterip_config *
@@ -223,27 +218,28 @@ clusterip_add_node(struct clusterip_config *c, u_int16_t nodenum)
        return 0;
 }
 
-static int
+static bool
 clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum)
 {
        if (nodenum == 0 ||
            nodenum > c->num_total_nodes)
-               return 1;
-               
+               return true;
+
        if (test_and_clear_bit(nodenum - 1, &c->local_nodes))
-               return 0;
+               return false;
 
-       return 1;
+       return true;
 }
 #endif
 
 static inline u_int32_t
-clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
+clusterip_hashfn(const struct sk_buff *skb,
+                const struct clusterip_config *config)
 {
-       struct iphdr *iph = skb->nh.iph;
+       const struct iphdr *iph = ip_hdr(skb);
        unsigned long hashval;
        u_int16_t sport, dport;
-       u_int16_t *ports;
+       const u_int16_t *ports;
 
        switch (iph->protocol) {
        case IPPROTO_TCP:
@@ -252,15 +248,14 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
        case IPPROTO_SCTP:
        case IPPROTO_DCCP:
        case IPPROTO_ICMP:
-               ports = (void *)iph+iph->ihl*4;
+               ports = (const void *)iph+iph->ihl*4;
                sport = ports[0];
                dport = ports[1];
                break;
        default:
-               if (net_ratelimit()) {
+               if (net_ratelimit())
                        printk(KERN_NOTICE "CLUSTERIP: unknown protocol `%u'\n",
                                iph->protocol);
-               }
                sport = dport = 0;
        }
 
@@ -270,7 +265,7 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
                                      config->hash_initval);
                break;
        case CLUSTERIP_HASHMODE_SIP_SPT:
-               hashval = jhash_2words(ntohl(iph->saddr), sport, 
+               hashval = jhash_2words(ntohl(iph->saddr), sport,
                                       config->hash_initval);
                break;
        case CLUSTERIP_HASHMODE_SIP_SPT_DPT:
@@ -288,17 +283,17 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
        }
 
        /* node numbers are 1..n, not 0..n */
-       return ((hashval % config->num_total_nodes)+1);
+       return (hashval % config->num_total_nodes) + 1;
 }
 
 static inline int
-clusterip_responsible(struct clusterip_config *config, u_int32_t hash)
+clusterip_responsible(const struct clusterip_config *config, u_int32_t hash)
 {
        return test_bit(hash - 1, &config->local_nodes);
 }
 
-/*********************************************************************** 
- * IPTABLES TARGET 
+/***********************************************************************
+ * IPTABLES TARGET
  ***********************************************************************/
 
 static unsigned int
@@ -310,30 +305,31 @@ target(struct sk_buff **pskb,
        const void *targinfo)
 {
        const struct ipt_clusterip_tgt_info *cipinfo = targinfo;
+       struct nf_conn *ct;
        enum ip_conntrack_info ctinfo;
-       u_int32_t *mark, hash;
+       u_int32_t hash;
 
        /* don't need to clusterip_config_get() here, since refcount
         * is only decremented by destroy() - and ip_tables guarantees
         * that the ->target() function isn't called after ->destroy() */
 
-       mark = nf_ct_get_mark((*pskb), &ctinfo);
-       if (mark == NULL) {
+       ct = nf_ct_get(*pskb, &ctinfo);
+       if (ct == NULL) {
                printk(KERN_ERR "CLUSTERIP: no conntrack!\n");
                        /* FIXME: need to drop invalid ones, since replies
-                        * to outgoing connections of other nodes will be 
+                        * to outgoing connections of other nodes will be
                         * marked as INVALID */
                return NF_DROP;
        }
 
        /* special case: ICMP error handling. conntrack distinguishes between
         * error messages (RELATED) and information requests (see below) */
-       if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP
-           && (ctinfo == IP_CT_RELATED 
+       if (ip_hdr(*pskb)->protocol == IPPROTO_ICMP
+           && (ctinfo == IP_CT_RELATED
                || ctinfo == IP_CT_RELATED+IP_CT_IS_REPLY))
                return XT_CONTINUE;
 
-       /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO, 
+       /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO,
         * TIMESTAMP, INFO_REQUEST or ADDRESS type icmp packets from here
         * on, which all have an ID field [relevant for hashing]. */
 
@@ -341,7 +337,7 @@ target(struct sk_buff **pskb,
 
        switch (ctinfo) {
                case IP_CT_NEW:
-                       *mark = hash;
+                       ct->mark = hash;
                        break;
                case IP_CT_RELATED:
                case IP_CT_RELATED+IP_CT_IS_REPLY:
@@ -358,7 +354,7 @@ target(struct sk_buff **pskb,
 #ifdef DEBUG_CLUSTERP
        DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
 #endif
-       DEBUGP("hash=%u ct_hash=%u ", hash, *mark);
+       DEBUGP("hash=%u ct_hash=%u ", hash, ct->mark);
        if (!clusterip_responsible(cipinfo->config, hash)) {
                DEBUGP("not responsible\n");
                return NF_DROP;
@@ -372,12 +368,12 @@ target(struct sk_buff **pskb,
        return XT_CONTINUE;
 }
 
-static int
+static bool
 checkentry(const char *tablename,
           const void *e_void,
           const struct xt_target *target,
-           void *targinfo,
-           unsigned int hook_mask)
+          void *targinfo,
+          unsigned int hook_mask)
 {
        struct ipt_clusterip_tgt_info *cipinfo = targinfo;
        const struct ipt_entry *e = e_void;
@@ -389,13 +385,13 @@ checkentry(const char *tablename,
            cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT_DPT) {
                printk(KERN_WARNING "CLUSTERIP: unknown mode `%u'\n",
                        cipinfo->hash_mode);
-               return 0;
+               return false;
 
        }
        if (e->ip.dmsk.s_addr != htonl(0xffffffff)
            || e->ip.dst.s_addr == 0) {
                printk(KERN_ERR "CLUSTERIP: Please specify destination IP\n");
-               return 0;
+               return false;
        }
 
        /* FIXME: further sanity checks */
@@ -409,40 +405,38 @@ checkentry(const char *tablename,
                        if (cipinfo->config != config) {
                                printk(KERN_ERR "CLUSTERIP: Reloaded entry "
                                       "has invalid config pointer!\n");
-                               return 0;
+                               return false;
                        }
-                       clusterip_config_entry_get(cipinfo->config);
                } else {
                        /* Case B: This is a new rule referring to an existing
                         * clusterip config. */
                        cipinfo->config = config;
-                       clusterip_config_entry_get(cipinfo->config);
                }
        } else {
                /* Case C: This is a completely new clusterip config */
                if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) {
                        printk(KERN_WARNING "CLUSTERIP: no config found for %u.%u.%u.%u, need 'new'\n", NIPQUAD(e->ip.dst.s_addr));
-                       return 0;
+                       return false;
                } else {
                        struct net_device *dev;
 
                        if (e->ip.iniface[0] == '\0') {
                                printk(KERN_WARNING "CLUSTERIP: Please specify an interface name\n");
-                               return 0;
+                               return false;
                        }
 
                        dev = dev_get_by_name(e->ip.iniface);
                        if (!dev) {
                                printk(KERN_WARNING "CLUSTERIP: no such interface %s\n", e->ip.iniface);
-                               return 0;
+                               return false;
                        }
 
-                       config = clusterip_config_init(cipinfo, 
+                       config = clusterip_config_init(cipinfo,
                                                        e->ip.dst.s_addr, dev);
                        if (!config) {
                                printk(KERN_WARNING "CLUSTERIP: cannot allocate config\n");
                                dev_put(dev);
-                               return 0;
+                               return false;
                        }
                        dev_mc_add(config->dev,config->clustermac, ETH_ALEN, 0);
                }
@@ -452,10 +446,10 @@ checkentry(const char *tablename,
        if (nf_ct_l3proto_try_module_get(target->family) < 0) {
                printk(KERN_WARNING "can't load conntrack support for "
                                    "proto=%d\n", target->family);
-               return 0;
+               return false;
        }
 
-       return 1;
+       return true;
 }
 
 /* drop reference count of cluster config when rule is deleted */
@@ -483,8 +477,8 @@ static struct xt_target clusterip_tgt = {
 };
 
 
-/*********************************************************************** 
- * ARP MANGLING CODE 
+/***********************************************************************
+ * ARP MANGLING CODE
  ***********************************************************************/
 
 /* hardcoded for 48bit ethernet and 32bit ipv4 addresses */
@@ -496,7 +490,7 @@ struct arp_payload {
 } __attribute__ ((packed));
 
 #ifdef CLUSTERIP_DEBUG
-static void arp_print(struct arp_payload *payload) 
+static void arp_print(struct arp_payload *payload)
 {
 #define HBUFFERLEN 30
        char hbuffer[HBUFFERLEN];
@@ -510,7 +504,7 @@ static void arp_print(struct arp_payload *payload)
        }
        hbuffer[--k]='\0';
 
-       printk("src %u.%u.%u.%u@%s, dst %u.%u.%u.%u\n", 
+       printk("src %u.%u.%u.%u@%s, dst %u.%u.%u.%u\n",
                NIPQUAD(payload->src_ip), hbuffer,
                NIPQUAD(payload->dst_ip));
 }
@@ -523,7 +517,7 @@ arp_mangle(unsigned int hook,
           const struct net_device *out,
           int (*okfn)(struct sk_buff *))
 {
-       struct arphdr *arp = (*pskb)->nh.arph;
+       struct arphdr *arp = arp_hdr(*pskb);
        struct arp_payload *payload;
        struct clusterip_config *c;
 
@@ -540,13 +534,13 @@ arp_mangle(unsigned int hook,
 
        payload = (void *)(arp+1);
 
-       /* if there is no clusterip configuration for the arp reply's 
+       /* if there is no clusterip configuration for the arp reply's
         * source ip, we don't want to mangle it */
        c = clusterip_config_find_get(payload->src_ip, 0);
        if (!c)
                return NF_ACCEPT;
 
-       /* normally the linux kernel always replies to arp queries of 
+       /* normally the linux kernel always replies to arp queries of
         * addresses on different interfacs.  However, in the CLUSTERIP case
         * this wouldn't work, since we didn't subscribe the mcast group on
         * other interfaces */
@@ -577,8 +571,8 @@ static struct nf_hook_ops cip_arp_ops = {
        .priority = -1
 };
 
-/*********************************************************************** 
- * PROC DIR HANDLING 
+/***********************************************************************
+ * PROC DIR HANDLING
  ***********************************************************************/
 
 #ifdef CONFIG_PROC_FS
@@ -640,7 +634,7 @@ static int clusterip_seq_show(struct seq_file *s, void *v)
 {
        struct clusterip_seq_position *idx = (struct clusterip_seq_position *)v;
 
-       if (idx->pos != 0) 
+       if (idx->pos != 0)
                seq_putc(s, ',');
 
        seq_printf(s, "%u", idx->bit);
@@ -715,7 +709,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
        return size;
 }
 
-static struct file_operations clusterip_proc_fops = {
+static const struct file_operations clusterip_proc_fops = {
        .owner   = THIS_MODULE,
        .open    = clusterip_proc_open,
        .read    = seq_read,
This page took 0.031546 seconds and 5 git commands to generate.