[NETFILTER]: nf_nat: fix NF_NAT dependency
[safe/jmp/linux-2.6] / net / ipv4 / netfilter / ipt_ULOG.c
index 38641cd..dbd3478 100644 (file)
  * each nlgroup you are using, so the total kernel memory usage increases
  * by that factor.
  *
+ * Actually you should use nlbufsiz a bit smaller than PAGE_SIZE, since
+ * nlbufsiz is used with alloc_skb, which adds another
+ * sizeof(struct skb_shared_info).  Use NLMSG_GOODSIZE instead.
+ *
  * flushtimeout:
  *   Specify, after how many hundredths of a second the queue should be
  *   flushed even if it is not full yet.
@@ -43,7 +47,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/spinlock.h>
 #include <linux/socket.h>
 #include <linux/skbuff.h>
@@ -76,7 +79,7 @@ MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_NFLOG);
 
 #define PRINTR(format, args...) do { if (net_ratelimit()) printk(format , ## args); } while (0)
 
-static unsigned int nlbufsiz = 4096;
+static unsigned int nlbufsiz = NLMSG_GOODSIZE;
 module_param(nlbufsiz, uint, 0400);
 MODULE_PARM_DESC(nlbufsiz, "netlink buffer size");
 
@@ -112,6 +115,11 @@ static void ulog_send(unsigned int nlgroupnum)
                del_timer(&ub->timer);
        }
 
+       if (!ub->skb) {
+               DEBUGP("ipt_ULOG: ulog_send: nothing to send\n");
+               return;
+       }
+
        /* last nlmsg needs NLMSG_DONE */
        if (ub->qlen > 1)
                ub->lastnlh->nlmsg_type = NLMSG_DONE;
@@ -143,22 +151,26 @@ static void ulog_timer(unsigned long data)
 static struct sk_buff *ulog_alloc_skb(unsigned int size)
 {
        struct sk_buff *skb;
+       unsigned int n;
 
        /* alloc skb which should be big enough for a whole
         * multipart message. WARNING: has to be <= 131000
         * due to slab allocator restrictions */
 
-       skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
+       n = max(size, nlbufsiz);
+       skb = alloc_skb(n, GFP_ATOMIC);
        if (!skb) {
-               PRINTR("ipt_ULOG: can't alloc whole buffer %ub!\n",
-                       nlbufsiz);
+               PRINTR("ipt_ULOG: can't alloc whole buffer %ub!\n", n);
 
-               /* try to allocate only as much as we need for 
-                * current packet */
+               if (n > size) {
+                       /* try to allocate only as much as we need for 
+                        * current packet */
 
-               skb = alloc_skb(size, GFP_ATOMIC);
-               if (!skb)
-                       PRINTR("ipt_ULOG: can't even allocate %ub\n", size);
+                       skb = alloc_skb(size, GFP_ATOMIC);
+                       if (!skb)
+                               PRINTR("ipt_ULOG: can't even allocate %ub\n",
+                                      size);
+               }
        }
 
        return skb;
@@ -227,7 +239,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
        pm->data_len = copy_len;
        pm->timestamp_sec = skb->tstamp.off_sec;
        pm->timestamp_usec = skb->tstamp.off_usec;
-       pm->mark = skb->nfmark;
+       pm->mark = skb->mark;
        pm->hook = hooknum;
        if (prefix != NULL)
                strncpy(pm->prefix, prefix, sizeof(pm->prefix));
@@ -295,7 +307,8 @@ static unsigned int ipt_ulog_target(struct sk_buff **pskb,
                                    const struct net_device *in,
                                    const struct net_device *out,
                                    unsigned int hooknum,
-                                   const void *targinfo, void *userinfo)
+                                   const struct xt_target *target,
+                                   const void *targinfo)
 {
        struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo;
 
@@ -330,47 +343,41 @@ static void ipt_logfn(unsigned int pf,
 }
 
 static int ipt_ulog_checkentry(const char *tablename,
-                              const struct ipt_entry *e,
+                              const void *e,
+                              const struct xt_target *target,
                               void *targinfo,
-                              unsigned int targinfosize,
                               unsigned int hookmask)
 {
        struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo;
 
-       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ulog_info))) {
-               DEBUGP("ipt_ULOG: targinfosize %u != 0\n", targinfosize);
-               return 0;
-       }
-
        if (loginfo->prefix[sizeof(loginfo->prefix) - 1] != '\0') {
                DEBUGP("ipt_ULOG: prefix term %i\n",
                       loginfo->prefix[sizeof(loginfo->prefix) - 1]);
                return 0;
        }
-
        if (loginfo->qthreshold > ULOG_MAX_QLEN) {
                DEBUGP("ipt_ULOG: queue threshold %i > MAX_QLEN\n",
                        loginfo->qthreshold);
                return 0;
        }
-
        return 1;
 }
 
 static struct ipt_target ipt_ulog_reg = {
        .name           = "ULOG",
        .target         = ipt_ulog_target,
+       .targetsize     = sizeof(struct ipt_ulog_info),
        .checkentry     = ipt_ulog_checkentry,
        .me             = THIS_MODULE,
 };
 
 static struct nf_logger ipt_ulog_logger = {
        .name           = "ipt_ULOG",
-       .logfn          = &ipt_logfn,
+       .logfn          = ipt_logfn,
        .me             = THIS_MODULE,
 };
 
-static int __init init(void)
+static int __init ipt_ulog_init(void)
 {
        int i;
 
@@ -403,7 +410,7 @@ static int __init init(void)
        return 0;
 }
 
-static void __exit fini(void)
+static void __exit ipt_ulog_fini(void)
 {
        ulog_buff_t *ub;
        int i;
@@ -431,5 +438,5 @@ static void __exit fini(void)
 
 }
 
-module_init(init);
-module_exit(fini);
+module_init(ipt_ulog_init);
+module_exit(ipt_ulog_fini);