net/tcp: Add tcp_hash_fail() ratelimited logs
[linux-2.6-microblaze.git] / net / ipv4 / tcp.c
index eb71212..1be6467 100644 (file)
@@ -4383,7 +4383,6 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
         * o MD5 hash and we're not expecting one.
         * o MD5 hash and its wrong.
         */
-       const struct tcphdr *th = tcp_hdr(skb);
        const struct tcp_sock *tp = tcp_sk(sk);
        struct tcp_md5sig_key *key;
        u8 newhash[16];
@@ -4393,6 +4392,7 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 
        if (!key && hash_location) {
                NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED);
+               tcp_hash_fail("Unexpected MD5 Hash found", family, skb, "");
                return SKB_DROP_REASON_TCP_MD5UNEXPECTED;
        }
 
@@ -4408,16 +4408,19 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
        if (genhash || memcmp(hash_location, newhash, 16) != 0) {
                NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE);
                if (family == AF_INET) {
-                       net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n",
-                                       saddr, ntohs(th->source),
-                                       daddr, ntohs(th->dest),
-                                       genhash ? " tcp_v4_calc_md5_hash failed"
-                                       : "", l3index);
+                       tcp_hash_fail("MD5 Hash failed", AF_INET, skb, "%s L3 index %d",
+                                     genhash ? "tcp_v4_calc_md5_hash failed"
+                                     : "", l3index);
                } else {
-                       net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u L3 index %d\n",
-                                       genhash ? "failed" : "mismatch",
-                                       saddr, ntohs(th->source),
-                                       daddr, ntohs(th->dest), l3index);
+                       if (genhash) {
+                               tcp_hash_fail("MD5 Hash failed",
+                                             AF_INET6, skb, "L3 index %d",
+                                             l3index);
+                       } else {
+                               tcp_hash_fail("MD5 Hash mismatch",
+                                             AF_INET6, skb, "L3 index %d",
+                                             l3index);
+                       }
                }
                return SKB_DROP_REASON_TCP_MD5FAILURE;
        }