netfilter: fix warning about invalid const usage
[safe/jmp/linux-2.6] / net / bridge / netfilter / ebt_ulog.c
index 2e4cb24..80c78c5 100644 (file)
 #include <linux/timer.h>
 #include <linux/netlink.h>
 #include <linux/netdevice.h>
-#include <linux/module.h>
+#include <linux/netfilter/x_tables.h>
 #include <linux/netfilter_bridge/ebtables.h>
 #include <linux/netfilter_bridge/ebt_ulog.h>
+#include <net/netfilter/nf_log.h>
 #include <net/sock.h>
 #include "../br_private.h"
 
@@ -130,6 +131,7 @@ static void ebt_ulog_packet(unsigned int hooknr, const struct sk_buff *skb,
        unsigned int group = uloginfo->nlgroup;
        ebt_ulog_buff_t *ub = &ulog_buffers[group];
        spinlock_t *lock = &ub->lock;
+       ktime_t kt;
 
        if ((uloginfo->cprange == 0) ||
            (uloginfo->cprange > skb->len + ETH_HLEN))
@@ -164,9 +166,10 @@ static void ebt_ulog_packet(unsigned int hooknr, const struct sk_buff *skb,
 
        /* Fill in the ulog data */
        pm->version = EBT_ULOG_VERSION;
-       do_gettimeofday(&pm->stamp);
+       kt = ktime_get_real();
+       pm->stamp = ktime_to_timeval(kt);
        if (ub->qlen == 1)
-               skb_set_timestamp(ub->skb, &pm->stamp);
+               ub->skb->tstamp = kt;
        pm->data_len = copy_len;
        pm->mark = skb->mark;
        pm->hook = hooknr;
@@ -221,7 +224,7 @@ alloc_failure:
 }
 
 /* this function is registered with the netfilter core */
-static void ebt_log_packet(unsigned int pf, unsigned int hooknum,
+static void ebt_log_packet(u_int8_t pf, unsigned int hooknum,
    const struct sk_buff *skb, const struct net_device *in,
    const struct net_device *out, const struct nf_loginfo *li,
    const char *prefix)
@@ -243,24 +246,20 @@ static void ebt_log_packet(unsigned int pf, unsigned int hooknum,
        ebt_ulog_packet(hooknum, skb, in, out, &loginfo, prefix);
 }
 
-static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
-   const struct net_device *in, const struct net_device *out,
-   const void *data, unsigned int datalen)
+static unsigned int
+ebt_ulog_tg(struct sk_buff *skb, const struct xt_target_param *par)
 {
-       struct ebt_ulog_info *uloginfo = (struct ebt_ulog_info *)data;
-
-       ebt_ulog_packet(hooknr, skb, in, out, uloginfo, NULL);
+       ebt_ulog_packet(par->hooknum, skb, par->in, par->out,
+                       par->targinfo, NULL);
+       return EBT_CONTINUE;
 }
 
-
-static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
-   const struct ebt_entry *e, void *data, unsigned int datalen)
+static bool ebt_ulog_tg_check(const struct xt_tgchk_param *par)
 {
-       struct ebt_ulog_info *uloginfo = (struct ebt_ulog_info *)data;
+       struct ebt_ulog_info *uloginfo = par->targinfo;
 
-       if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
-           uloginfo->nlgroup > 31)
-               return -EINVAL;
+       if (uloginfo->nlgroup > 31)
+               return false;
 
        uloginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
 
@@ -270,51 +269,53 @@ static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
        return 0;
 }
 
-static struct ebt_watcher ulog = {
-       .name           = EBT_ULOG_WATCHER,
-       .watcher        = ebt_ulog,
-       .check          = ebt_ulog_check,
+static struct xt_target ebt_ulog_tg_reg __read_mostly = {
+       .name           = "ulog",
+       .revision       = 0,
+       .family         = NFPROTO_BRIDGE,
+       .target         = ebt_ulog_tg,
+       .checkentry     = ebt_ulog_tg_check,
+       .targetsize     = XT_ALIGN(sizeof(struct ebt_ulog_info)),
        .me             = THIS_MODULE,
 };
 
-static struct nf_logger ebt_ulog_logger = {
-       .name           = EBT_ULOG_WATCHER,
+static struct nf_logger ebt_ulog_logger __read_mostly = {
+       .name           = "ulog",
        .logfn          = &ebt_log_packet,
        .me             = THIS_MODULE,
 };
 
 static int __init ebt_ulog_init(void)
 {
-       int i, ret = 0;
+       bool ret = true;
+       int i;
 
        if (nlbufsiz >= 128*1024) {
                printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
                       " please try a smaller nlbufsiz parameter.\n");
-               return -EINVAL;
+               return false;
        }
 
        /* initialize ulog_buffers */
        for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
-               init_timer(&ulog_buffers[i].timer);
-               ulog_buffers[i].timer.function = ulog_timer;
-               ulog_buffers[i].timer.data = i;
+               setup_timer(&ulog_buffers[i].timer, ulog_timer, i);
                spin_lock_init(&ulog_buffers[i].lock);
        }
 
-       ebtulognl = netlink_kernel_create(NETLINK_NFLOG, EBT_ULOG_MAXNLGROUPS,
-                                         NULL, THIS_MODULE);
-       if (!ebtulognl)
-               ret = -ENOMEM;
-       else if ((ret = ebt_register_watcher(&ulog)))
-               sock_release(ebtulognl->sk_socket);
-
-       if (nf_log_register(PF_BRIDGE, &ebt_ulog_logger) < 0) {
-               printk(KERN_WARNING "ebt_ulog: not logging via ulog "
-                      "since somebody else already registered for PF_BRIDGE\n");
-               /* we cannot make module load fail here, since otherwise
-                * ebtables userspace would abort */
+       ebtulognl = netlink_kernel_create(&init_net, NETLINK_NFLOG,
+                                         EBT_ULOG_MAXNLGROUPS, NULL, NULL,
+                                         THIS_MODULE);
+       if (!ebtulognl) {
+               printk(KERN_WARNING KBUILD_MODNAME ": out of memory trying to "
+                      "call netlink_kernel_create\n");
+               ret = false;
+       } else if (xt_register_target(&ebt_ulog_tg_reg) != 0) {
+               netlink_kernel_release(ebtulognl);
        }
 
+       if (ret)
+               nf_log_register(NFPROTO_BRIDGE, &ebt_ulog_logger);
+
        return ret;
 }
 
@@ -323,8 +324,8 @@ static void __exit ebt_ulog_fini(void)
        ebt_ulog_buff_t *ub;
        int i;
 
-       nf_log_unregister_logger(&ebt_ulog_logger);
-       ebt_unregister_watcher(&ulog);
+       nf_log_unregister(&ebt_ulog_logger);
+       xt_unregister_target(&ebt_ulog_tg_reg);
        for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
                ub = &ulog_buffers[i];
                if (timer_pending(&ub->timer))
@@ -336,12 +337,11 @@ static void __exit ebt_ulog_fini(void)
                }
                spin_unlock_bh(&ub->lock);
        }
-       sock_release(ebtulognl->sk_socket);
+       netlink_kernel_release(ebtulognl);
 }
 
 module_init(ebt_ulog_init);
 module_exit(ebt_ulog_fini);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
-MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
-                  " frames");
+MODULE_DESCRIPTION("Ebtables: Packet logging to netlink using ULOG");