[NETFILTER]: add some consts, remove some casts
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / ipv4 / netfilter / ipt_LOG.c
index c96de16fefae67ed9a634fd2ad8c2f56edf65289..bcc43a625e72988e5f8b6de63f3cec38ccae06d3 100644 (file)
@@ -20,7 +20,7 @@
 #include <net/route.h>
 
 #include <linux/netfilter.h>
-#include <linux/netfilter_ipv4/ip_tables.h>
+#include <linux/netfilter/x_tables.h>
 #include <linux/netfilter_ipv4/ipt_LOG.h>
 
 MODULE_LICENSE("GPL");
@@ -41,7 +41,8 @@ static void dump_packet(const struct nf_loginfo *info,
                        const struct sk_buff *skb,
                        unsigned int iphoff)
 {
-       struct iphdr _iph, *ih;
+       struct iphdr _iph;
+       const struct iphdr *ih;
        unsigned int logflags;
 
        if (info->type == NF_LOG_TYPE_LOG)
@@ -100,7 +101,8 @@ static void dump_packet(const struct nf_loginfo *info,
 
        switch (ih->protocol) {
        case IPPROTO_TCP: {
-               struct tcphdr _tcph, *th;
+               struct tcphdr _tcph;
+               const struct tcphdr *th;
 
                /* Max length: 10 "PROTO=TCP " */
                printk("PROTO=TCP ");
@@ -151,7 +153,7 @@ static void dump_packet(const struct nf_loginfo *info,
                if ((logflags & IPT_LOG_TCPOPT)
                    && th->doff * 4 > sizeof(struct tcphdr)) {
                        unsigned char _opt[4 * 15 - sizeof(struct tcphdr)];
-                       unsigned char *op;
+                       const unsigned char *op;
                        unsigned int i, optsize;
 
                        optsize = th->doff * 4 - sizeof(struct tcphdr);
@@ -173,7 +175,8 @@ static void dump_packet(const struct nf_loginfo *info,
        }
        case IPPROTO_UDP:
        case IPPROTO_UDPLITE: {
-               struct udphdr _udph, *uh;
+               struct udphdr _udph;
+               const struct udphdr *uh;
 
                if (ih->protocol == IPPROTO_UDP)
                        /* Max length: 10 "PROTO=UDP "     */
@@ -200,7 +203,8 @@ static void dump_packet(const struct nf_loginfo *info,
                break;
        }
        case IPPROTO_ICMP: {
-               struct icmphdr _icmph, *ich;
+               struct icmphdr _icmph;
+               const struct icmphdr *ich;
                static const size_t required_len[NR_ICMP_TYPES+1]
                        = { [ICMP_ECHOREPLY] = 4,
                            [ICMP_DEST_UNREACH]
@@ -285,11 +289,12 @@ static void dump_packet(const struct nf_loginfo *info,
        }
        /* Max Length */
        case IPPROTO_AH: {
-               struct ip_auth_hdr _ahdr, *ah;
+               struct ip_auth_hdr _ahdr;
+               const struct ip_auth_hdr *ah;
 
                if (ntohs(ih->frag_off) & IP_OFFSET)
                        break;
-               
+
                /* Max length: 9 "PROTO=AH " */
                printk("PROTO=AH ");
 
@@ -307,7 +312,8 @@ static void dump_packet(const struct nf_loginfo *info,
                break;
        }
        case IPPROTO_ESP: {
-               struct ip_esp_hdr _esph, *eh;
+               struct ip_esp_hdr _esph;
+               const struct ip_esp_hdr *eh;
 
                /* Max length: 10 "PROTO=ESP " */
                printk("PROTO=ESP ");
@@ -334,10 +340,10 @@ static void dump_packet(const struct nf_loginfo *info,
        }
 
        /* Max length: 15 "UID=4294967295 " */
-       if ((logflags & IPT_LOG_UID) && !iphoff && skb->sk) {
+       if ((logflags & IPT_LOG_UID) && !iphoff && skb->sk) {
                read_lock_bh(&skb->sk->sk_callback_lock);
                if (skb->sk->sk_socket && skb->sk->sk_socket->file)
-                       printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
+                       printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
                read_unlock_bh(&skb->sk->sk_callback_lock);
        }
 
@@ -385,11 +391,13 @@ ipt_log_packet(unsigned int pf,
               out ? out->name : "");
 #ifdef CONFIG_BRIDGE_NETFILTER
        if (skb->nf_bridge) {
-               struct net_device *physindev = skb->nf_bridge->physindev;
-               struct net_device *physoutdev = skb->nf_bridge->physoutdev;
+               const struct net_device *physindev;
+               const struct net_device *physoutdev;
 
+               physindev = skb->nf_bridge->physindev;
                if (physindev && in != physindev)
                        printk("PHYSIN=%s ", physindev->name);
+               physoutdev = skb->nf_bridge->physoutdev;
                if (physoutdev && out != physoutdev)
                        printk("PHYSOUT=%s ", physoutdev->name);
        }
@@ -399,9 +407,9 @@ ipt_log_packet(unsigned int pf,
                /* MAC logging for input chain only. */
                printk("MAC=");
                if (skb->dev && skb->dev->hard_header_len
-                   && skb->mac.raw != (void*)skb->nh.iph) {
+                   && skb->mac_header != skb->network_header) {
                        int i;
-                       unsigned char *p = skb->mac.raw;
+                       const unsigned char *p = skb_mac_header(skb);
                        for (i = 0; i < skb->dev->hard_header_len; i++,p++)
                                printk("%02x%c", *p,
                                       i==skb->dev->hard_header_len - 1
@@ -431,32 +439,33 @@ ipt_log_target(struct sk_buff **pskb,
        li.u.log.logflags = loginfo->logflags;
 
        ipt_log_packet(PF_INET, hooknum, *pskb, in, out, &li,
-                      loginfo->prefix);
-       return IPT_CONTINUE;
+                      loginfo->prefix);
+       return XT_CONTINUE;
 }
 
-static int ipt_log_checkentry(const char *tablename,
-                             const void *e,
-                             const struct xt_target *target,
-                             void *targinfo,
-                             unsigned int hook_mask)
+static bool ipt_log_checkentry(const char *tablename,
+                              const void *e,
+                              const struct xt_target *target,
+                              void *targinfo,
+                              unsigned int hook_mask)
 {
        const struct ipt_log_info *loginfo = targinfo;
 
        if (loginfo->level >= 8) {
                DEBUGP("LOG: level %u >= 8\n", loginfo->level);
-               return 0;
+               return false;
        }
        if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
                DEBUGP("LOG: prefix term %i\n",
                       loginfo->prefix[sizeof(loginfo->prefix)-1]);
-               return 0;
+               return false;
        }
-       return 1;
+       return true;
 }
 
-static struct ipt_target ipt_log_reg = {
+static struct xt_target ipt_log_reg = {
        .name           = "LOG",
+       .family         = AF_INET,
        .target         = ipt_log_target,
        .targetsize     = sizeof(struct ipt_log_info),
        .checkentry     = ipt_log_checkentry,
@@ -471,22 +480,21 @@ static struct nf_logger ipt_log_logger ={
 
 static int __init ipt_log_init(void)
 {
-       if (ipt_register_target(&ipt_log_reg))
-               return -EINVAL;
-       if (nf_log_register(PF_INET, &ipt_log_logger) < 0) {
-               printk(KERN_WARNING "ipt_LOG: not logging via system console "
-                      "since somebody else already registered for PF_INET\n");
-               /* we cannot make module load fail here, since otherwise
-                * iptables userspace would abort */
-       }
-       
-       return 0;
+       int ret;
+
+       ret = xt_register_target(&ipt_log_reg);
+       if (ret < 0)
+               return ret;
+       ret = nf_log_register(PF_INET, &ipt_log_logger);
+       if (ret < 0 && ret != -EEXIST)
+               xt_unregister_target(&ipt_log_reg);
+       return ret;
 }
 
 static void __exit ipt_log_fini(void)
 {
-       nf_log_unregister_logger(&ipt_log_logger);
-       ipt_unregister_target(&ipt_log_reg);
+       nf_log_unregister(&ipt_log_logger);
+       xt_unregister_target(&ipt_log_reg);
 }
 
 module_init(ipt_log_init);