]> err.no Git - linux-2.6/blobdiff - net/ipv4/tcp_ipv4.c
Merge branch 'master' of git://git.infradead.org/~kmpark/onenand-mtd-2.6
[linux-2.6] / net / ipv4 / tcp_ipv4.c
index 010dff442a1134cbde41ca44ac6d5046d355573a..12de90a5047cf214cd4bd1851331ac14851c0783 100644 (file)
@@ -504,7 +504,7 @@ void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
                th->check = ~tcp_v4_check(th, len,
                                          inet->saddr, inet->daddr, 0);
-               skb->csum = offsetof(struct tcphdr, check);
+               skb->csum_offset = offsetof(struct tcphdr, check);
        } else {
                th->check = tcp_v4_check(th, len, inet->saddr, inet->daddr,
                                         csum_partial((char *)th,
@@ -526,7 +526,7 @@ int tcp_v4_gso_send_check(struct sk_buff *skb)
 
        th->check = 0;
        th->check = ~tcp_v4_check(th, skb->len, iph->saddr, iph->daddr, 0);
-       skb->csum = offsetof(struct tcphdr, check);
+       skb->csum_offset = offsetof(struct tcphdr, check);
        skb->ip_summed = CHECKSUM_PARTIAL;
        return 0;
 }
@@ -648,7 +648,7 @@ static void tcp_v4_send_ack(struct tcp_timewait_sock *twsk,
                                   TCPOLEN_TIMESTAMP);
                rep.opt[1] = htonl(tcp_time_stamp);
                rep.opt[2] = htonl(ts);
-               arg.iov[0].iov_len = TCPOLEN_TSTAMP_ALIGNED;
+               arg.iov[0].iov_len += TCPOLEN_TSTAMP_ALIGNED;
        }
 
        /* Swap the send and the receive. */
@@ -840,8 +840,8 @@ struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk,
 
 EXPORT_SYMBOL(tcp_v4_md5_lookup);
 
-struct tcp_md5sig_key *tcp_v4_reqsk_md5_lookup(struct sock *sk,
-                                              struct request_sock *req)
+static struct tcp_md5sig_key *tcp_v4_reqsk_md5_lookup(struct sock *sk,
+                                                     struct request_sock *req)
 {
        return tcp_v4_md5_do_lookup(sk, inet_rsk(req)->rmt_addr);
 }
@@ -855,15 +855,18 @@ int tcp_v4_md5_do_add(struct sock *sk, __be32 addr,
        struct tcp_sock *tp = tcp_sk(sk);
        struct tcp4_md5sig_key *keys;
 
-       key = (struct tcp4_md5sig_key *) tcp_v4_md5_do_lookup(sk, addr);
+       key = (struct tcp4_md5sig_key *)tcp_v4_md5_do_lookup(sk, addr);
        if (key) {
                /* Pre-existing entry - just update that one. */
-               kfree (key->key);
+               kfree(key->key);
                key->key = newkey;
                key->keylen = newkeylen;
        } else {
+               struct tcp_md5sig_info *md5sig;
+
                if (!tp->md5sig_info) {
-                       tp->md5sig_info = kzalloc(sizeof(*tp->md5sig_info), GFP_ATOMIC);
+                       tp->md5sig_info = kzalloc(sizeof(*tp->md5sig_info),
+                                                 GFP_ATOMIC);
                        if (!tp->md5sig_info) {
                                kfree(newkey);
                                return -ENOMEM;
@@ -873,30 +876,31 @@ int tcp_v4_md5_do_add(struct sock *sk, __be32 addr,
                        kfree(newkey);
                        return -ENOMEM;
                }
-               if (tp->md5sig_info->alloced4 == tp->md5sig_info->entries4) {
-                       keys = kmalloc((sizeof(struct tcp4_md5sig_key) *
-                                      (tp->md5sig_info->entries4 + 1)), GFP_ATOMIC);
+               md5sig = tp->md5sig_info;
+
+               if (md5sig->alloced4 == md5sig->entries4) {
+                       keys = kmalloc((sizeof(*keys) *
+                                       (md5sig->entries4 + 1)), GFP_ATOMIC);
                        if (!keys) {
                                kfree(newkey);
                                tcp_free_md5sig_pool();
                                return -ENOMEM;
                        }
 
-                       if (tp->md5sig_info->entries4)
-                               memcpy(keys, tp->md5sig_info->keys4,
-                                      (sizeof (struct tcp4_md5sig_key) *
-                                       tp->md5sig_info->entries4));
+                       if (md5sig->entries4)
+                               memcpy(keys, md5sig->keys4,
+                                      sizeof(*keys) * md5sig->entries4);
 
                        /* Free old key list, and reference new one */
-                       if (tp->md5sig_info->keys4)
-                               kfree(tp->md5sig_info->keys4);
-                       tp->md5sig_info->keys4 = keys;
-                       tp->md5sig_info->alloced4++;
+                       if (md5sig->keys4)
+                               kfree(md5sig->keys4);
+                       md5sig->keys4 = keys;
+                       md5sig->alloced4++;
                }
-               tp->md5sig_info->entries4++;
-               tp->md5sig_info->keys4[tp->md5sig_info->entries4 - 1].addr = addr;
-               tp->md5sig_info->keys4[tp->md5sig_info->entries4 - 1].key = newkey;
-               tp->md5sig_info->keys4[tp->md5sig_info->entries4 - 1].keylen = newkeylen;
+               md5sig->entries4++;
+               md5sig->keys4[md5sig->entries4 - 1].addr   = addr;
+               md5sig->keys4[md5sig->entries4 - 1].key    = newkey;
+               md5sig->keys4[md5sig->entries4 - 1].keylen = newkeylen;
        }
        return 0;
 }
@@ -924,6 +928,7 @@ int tcp_v4_md5_do_del(struct sock *sk, __be32 addr)
                        if (tp->md5sig_info->entries4 == 0) {
                                kfree(tp->md5sig_info->keys4);
                                tp->md5sig_info->keys4 = NULL;
+                               tp->md5sig_info->alloced4 = 0;
                        } else if (tp->md5sig_info->entries4 != i) {
                                /* Need to do some manipulation */
                                memcpy(&tp->md5sig_info->keys4[i],
@@ -998,10 +1003,9 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, char __user *optval,
 
        }
 
-       newkey = kmalloc(cmd.tcpm_keylen, GFP_KERNEL);
+       newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, GFP_KERNEL);
        if (!newkey)
                return -ENOMEM;
-       memcpy(newkey, cmd.tcpm_key, cmd.tcpm_keylen);
        return tcp_v4_md5_do_add(sk, sin->sin_addr.s_addr,
                                 newkey, cmd.tcpm_keylen);
 }
@@ -1014,10 +1018,7 @@ static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
        struct scatterlist sg[4];
        __u16 data_len;
        int block = 0;
-#ifdef CONFIG_TCP_MD5SIG_DEBUG
-       int i;
-#endif
-       __u16 old_checksum;
+       __sum16 old_checksum;
        struct tcp_md5sig_pool *hp;
        struct tcp4_pseudohdr *bp;
        struct hash_desc *desc;
@@ -1049,13 +1050,6 @@ static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
        sg_set_buf(&sg[block++], bp, sizeof(*bp));
        nbytes += sizeof(*bp);
 
-#ifdef CONFIG_TCP_MD5SIG_DEBUG
-       printk("Calcuating hash for: ");
-       for (i = 0; i < sizeof(*bp); i++)
-               printk("%02x ", (unsigned int)((unsigned char *)bp)[i]);
-       printk(" ");
-#endif
-
        /* 2. the TCP header, excluding options, and assuming a
         * checksum of zero/
         */
@@ -1063,10 +1057,7 @@ static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
        th->check = 0;
        sg_set_buf(&sg[block++], th, sizeof(struct tcphdr));
        nbytes += sizeof(struct tcphdr);
-#ifdef CONFIG_TCP_MD5SIG_DEBUG
-       for (i = 0; i < sizeof(struct tcphdr); i++)
-               printk(" %02x", (unsigned int)((unsigned char *)th)[i]);
-#endif
+
        /* 3. the TCP segment data (if any) */
        data_len = tcplen - (th->doff << 2);
        if (data_len > 0) {
@@ -1081,12 +1072,6 @@ static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
        sg_set_buf(&sg[block++], key->key, key->keylen);
        nbytes += key->keylen;
 
-#ifdef CONFIG_TCP_MD5SIG_DEBUG
-       printk("  and password: ");
-       for (i = 0; i < key->keylen; i++)
-               printk("%02x ", (unsigned int)key->key[i]);
-#endif
-
        /* Now store the Hash into the packet */
        err = crypto_hash_init(desc);
        if (err)
@@ -1103,12 +1088,6 @@ static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
        th->check = old_checksum;
 
 out:
-#ifdef CONFIG_TCP_MD5SIG_DEBUG
-       printk(" result:");
-       for (i = 0; i < 16; i++)
-               printk(" %02x", (unsigned int)(((u8*)md5_hash)[i]));
-       printk("\n");
-#endif
        return 0;
 clear_hash:
        tcp_put_md5sig_pool();
@@ -1207,7 +1186,7 @@ done_opts:
                return 0;
 
        if (hash_expected && !hash_location) {
-               LIMIT_NETDEBUG(KERN_INFO "MD5 Hash NOT expected but found "
+               LIMIT_NETDEBUG(KERN_INFO "MD5 Hash expected but NOT found "
                               "(" NIPQUAD_FMT ", %d)->(" NIPQUAD_FMT ", %d)\n",
                               NIPQUAD(iph->saddr), ntohs(th->source),
                               NIPQUAD(iph->daddr), ntohs(th->dest));
@@ -1238,20 +1217,6 @@ done_opts:
                               NIPQUAD(iph->saddr), ntohs(th->source),
                               NIPQUAD(iph->daddr), ntohs(th->dest),
                               genhash ? " tcp_v4_calc_md5_hash failed" : "");
-#ifdef CONFIG_TCP_MD5SIG_DEBUG
-                       do {
-                               int i;
-                               printk("Received: ");
-                               for (i = 0; i < 16; i++)
-                                       printk("%02x ",
-                                              0xff & (int)hash_location[i]);
-                               printk("\n");
-                               printk("Calculated: ");
-                               for (i = 0; i < 16; i++)
-                                       printk("%02x ", 0xff & (int)newhash[i]);
-                               printk("\n");
-                       } while(0);
-#endif
                }
                return 1;
        }
@@ -1269,11 +1234,11 @@ struct request_sock_ops tcp_request_sock_ops __read_mostly = {
        .send_reset     =       tcp_v4_send_reset,
 };
 
-struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
 #ifdef CONFIG_TCP_MD5SIG
+static struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
        .md5_lookup     =       tcp_v4_reqsk_md5_lookup,
-#endif
 };
+#endif
 
 static struct timewait_sock_ops tcp_timewait_sock_ops = {
        .twsk_obj_size  = sizeof(struct tcp_timewait_sock),
@@ -1494,12 +1459,10 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
                 * memory, then we end up not copying the key
                 * across. Shucks.
                 */
-               char *newkey = kmalloc(key->keylen, GFP_ATOMIC);
-               if (newkey) {
-                       memcpy(newkey, key->key, key->keylen);
+               char *newkey = kmemdup(key->key, key->keylen, GFP_ATOMIC);
+               if (newkey != NULL)
                        tcp_v4_md5_do_add(newsk, inet_sk(sk)->daddr,
                                          newkey, key->keylen);
-               }
        }
 #endif
 
@@ -1858,14 +1821,14 @@ struct inet_connection_sock_af_ops ipv4_specific = {
 #endif
 };
 
-struct tcp_sock_af_ops tcp_sock_ipv4_specific = {
 #ifdef CONFIG_TCP_MD5SIG
+static struct tcp_sock_af_ops tcp_sock_ipv4_specific = {
        .md5_lookup             = tcp_v4_md5_lookup,
        .calc_md5_hash          = tcp_v4_calc_md5_hash,
        .md5_add                = tcp_v4_md5_add_func,
        .md5_parse              = tcp_v4_parse_md5_keys,
-#endif
 };
+#endif
 
 /* NOTE: A lot of things set to zero explicitly by call to
  *       sk_alloc() so need not be done here.