[NETFILTER]: x_tables: mark matches and targets __read_mostly
[deliverable/linux.git] / net / ipv4 / netfilter / ipt_CLUSTERIP.c
index e965b333c997f41a9c1e55b73bbe68656375c96a..1cef3b09c3261973846969e6cf6ee566caf455f9 100644 (file)
 #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"
 
@@ -125,9 +122,8 @@ __clusterip_config_find(__be32 clusterip)
        list_for_each(pos, &clusterip_configs) {
                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;
        }
 
@@ -288,11 +283,11 @@ 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);
 }
@@ -310,15 +305,16 @@ 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
@@ -328,7 +324,7 @@ target(struct sk_buff **pskb,
 
        /* special case: ICMP error handling. conntrack distinguishes between
         * error messages (RELATED) and information requests (see below) */
-       if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP
+       if (ip_hdr(*pskb)->protocol == IPPROTO_ICMP
            && (ctinfo == IP_CT_RELATED
                || ctinfo == IP_CT_RELATED+IP_CT_IS_REPLY))
                return XT_CONTINUE;
@@ -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,7 +368,7 @@ 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,
@@ -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,32 +405,30 @@ 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,
@@ -442,7 +436,7 @@ checkentry(const char *tablename,
                        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 */
@@ -472,7 +466,7 @@ static void destroy(const struct xt_target *target, void *targinfo)
        nf_ct_l3proto_module_put(target->family);
 }
 
-static struct xt_target clusterip_tgt = {
+static struct xt_target clusterip_tgt __read_mostly = {
        .name           = "CLUSTERIP",
        .family         = AF_INET,
        .target         = target,
@@ -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;
 
This page took 0.029731 seconds and 5 git commands to generate.