[SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph
[pandora-kernel.git] / net / ipv4 / ipvs / ip_vs_app.c
index 9b176a9..c8a822c 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/stat.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/mutex.h>
 
 #include <net/ip_vs.h>
 
@@ -40,7 +41,7 @@ EXPORT_SYMBOL(register_ip_vs_app_inc);
 
 /* ipvs application list head */
 static LIST_HEAD(ip_vs_app_list);
-static DECLARE_MUTEX(__ip_vs_app_mutex);
+static DEFINE_MUTEX(__ip_vs_app_mutex);
 
 
 /*
@@ -79,10 +80,9 @@ ip_vs_app_inc_new(struct ip_vs_app *app, __u16 proto, __u16 port)
        if (!pp->unregister_app)
                return -EOPNOTSUPP;
 
-       inc = kmalloc(sizeof(struct ip_vs_app), GFP_KERNEL);
+       inc = kmemdup(app, sizeof(*inc), GFP_KERNEL);
        if (!inc)
                return -ENOMEM;
-       memcpy(inc, app, sizeof(*inc));
        INIT_LIST_HEAD(&inc->p_list);
        INIT_LIST_HEAD(&inc->incs_list);
        inc->app = app;
@@ -173,11 +173,11 @@ register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port)
 {
        int result;
 
-       down(&__ip_vs_app_mutex);
+       mutex_lock(&__ip_vs_app_mutex);
 
        result = ip_vs_app_inc_new(app, proto, port);
 
-       up(&__ip_vs_app_mutex);
+       mutex_unlock(&__ip_vs_app_mutex);
 
        return result;
 }
@@ -191,11 +191,11 @@ int register_ip_vs_app(struct ip_vs_app *app)
        /* increase the module use count */
        ip_vs_use_count_inc();
 
-       down(&__ip_vs_app_mutex);
+       mutex_lock(&__ip_vs_app_mutex);
 
        list_add(&app->a_list, &ip_vs_app_list);
 
-       up(&__ip_vs_app_mutex);
+       mutex_unlock(&__ip_vs_app_mutex);
 
        return 0;
 }
@@ -209,7 +209,7 @@ void unregister_ip_vs_app(struct ip_vs_app *app)
 {
        struct ip_vs_app *inc, *nxt;
 
-       down(&__ip_vs_app_mutex);
+       mutex_lock(&__ip_vs_app_mutex);
 
        list_for_each_entry_safe(inc, nxt, &app->incs_list, a_list) {
                ip_vs_app_inc_release(inc);
@@ -217,7 +217,7 @@ void unregister_ip_vs_app(struct ip_vs_app *app)
 
        list_del(&app->a_list);
 
-       up(&__ip_vs_app_mutex);
+       mutex_unlock(&__ip_vs_app_mutex);
 
        /* decrease the module use count */
        ip_vs_use_count_dec();
@@ -331,14 +331,14 @@ static inline int app_tcp_pkt_out(struct ip_vs_conn *cp, struct sk_buff **pskb,
                                  struct ip_vs_app *app)
 {
        int diff;
-       unsigned int tcp_offset = (*pskb)->nh.iph->ihl*4;
+       const unsigned int tcp_offset = ip_hdrlen(*pskb);
        struct tcphdr *th;
        __u32 seq;
 
        if (!ip_vs_make_skb_writable(pskb, tcp_offset + sizeof(*th)))
                return 0;
 
-       th = (struct tcphdr *)((*pskb)->nh.raw + tcp_offset);
+       th = (struct tcphdr *)(skb_network_header(*pskb) + tcp_offset);
 
        /*
         *      Remember seq number in case this pkt gets resized
@@ -406,14 +406,14 @@ static inline int app_tcp_pkt_in(struct ip_vs_conn *cp, struct sk_buff **pskb,
                                 struct ip_vs_app *app)
 {
        int diff;
-       unsigned int tcp_offset = (*pskb)->nh.iph->ihl*4;
+       const unsigned int tcp_offset = ip_hdrlen(*pskb);
        struct tcphdr *th;
        __u32 seq;
 
        if (!ip_vs_make_skb_writable(pskb, tcp_offset + sizeof(*th)))
                return 0;
 
-       th = (struct tcphdr *)((*pskb)->nh.raw + tcp_offset);
+       th = (struct tcphdr *)(skb_network_header(*pskb) + tcp_offset);
 
        /*
         *      Remember seq number in case this pkt gets resized
@@ -498,7 +498,7 @@ static struct ip_vs_app *ip_vs_app_idx(loff_t pos)
 
 static void *ip_vs_app_seq_start(struct seq_file *seq, loff_t *pos)
 {
-       down(&__ip_vs_app_mutex);
+       mutex_lock(&__ip_vs_app_mutex);
 
        return *pos ? ip_vs_app_idx(*pos - 1) : SEQ_START_TOKEN;
 }
@@ -530,7 +530,7 @@ static void *ip_vs_app_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 
 static void ip_vs_app_seq_stop(struct seq_file *seq, void *v)
 {
-       up(&__ip_vs_app_mutex);
+       mutex_unlock(&__ip_vs_app_mutex);
 }
 
 static int ip_vs_app_seq_show(struct seq_file *seq, void *v)
@@ -561,7 +561,7 @@ static int ip_vs_app_open(struct inode *inode, struct file *file)
        return seq_open(file, &ip_vs_app_seq_ops);
 }
 
-static struct file_operations ip_vs_app_fops = {
+static const struct file_operations ip_vs_app_fops = {
        .owner   = THIS_MODULE,
        .open    = ip_vs_app_open,
        .read    = seq_read,
@@ -577,7 +577,6 @@ static struct file_operations ip_vs_app_fops = {
 int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
                      char *o_buf, int o_len, char *n_buf, int n_len)
 {
-       struct iphdr *iph;
        int diff;
        int o_offset;
        int o_left;
@@ -607,8 +606,7 @@ int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
        }
 
        /* must update the iph total length here */
-       iph = skb->nh.iph;
-       iph->tot_len = htons(skb->len);
+       ip_hdr(skb)->tot_len = htons(skb->len);
 
        LeaveFunction(9);
        return 0;