compat: fix compilation on 2.6.24 based on next-20130312
authorLuis R. Rodriguez <mcgrof@do-not-panic.com>
Thu, 14 Mar 2013 18:58:10 +0000 (11:58 -0700)
committerLuis R. Rodriguez <mcgrof@do-not-panic.com>
Thu, 14 Mar 2013 18:58:10 +0000 (11:58 -0700)
drivers/net/wireless/iwlwifi/mvm/mac80211.c ends up
including include/net/inet_hashtables.h which in 2.6.24
has a routine called __inet_lookup_established() that
uses the sk_for_each(1, 2, 3). The patch below by Hauke
backported the change that went into the kernel that
made sk_for_each(1, 3) use two arguments. It turns out
that upstream we realized that the second argument was
useless. The header however uses it though so the trick
didn't work for 2.6.24 if code used it there.

We fix it using a nasty hack by ensuring that when the
header file is included we redefine that routine to
something else, then we udef it, and then define our
new version that only uses the 2 argument form of
sk_for_each(). This is a nasty way to solve it but
not sure if there is anything cleaner.

commit dbc390647a841061954f67ea226221fc7f4b3836
Author: Hauke Mehrtens <hauke@hauke-m.de>
Date:   Sun Feb 10 20:10:10 2013 +0100

    compat: backport drop of node parameter from iterators

    This patch backports the following commit in mainline linux kernel:

      commit 0bbacca7c3911451cea923b0ad6389d58e3d9ce9
      Author: Sasha Levin <sasha.levin@oracle.com>
      Date:   Thu Feb 7 12:32:18 2013 +1100

          hlist: drop the node parameter from iterators

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
include/linux/compat-2.6.25.h

index 563b65f79b5fd3ab7c4c7b5b0aefdd1af98c2990..5ca6783eb299aeedc952b940d7f9a84b780bc420 100644 (file)
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/pci.h>
+#define __inet_lookup_established __inet_lookup_established_old
+#include <net/inet_hashtables.h>
+#undef __inet_lookup_established
+#include <linux/compat-3.9.h>
+/*
+ * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so we need
+ * not check it for lookups anymore, thanks Alexey. -DaveM
+ *
+ * Local BH must be disabled here.
+ */
+static inline struct sock *
+       __inet_lookup_established(struct inet_hashinfo *hashinfo,
+                                 const __be32 saddr, const __be16 sport,
+                                 const __be32 daddr, const u16 hnum,
+                                 const int dif)
+{
+       INET_ADDR_COOKIE(acookie, saddr, daddr)
+       const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
+       struct sock *sk;
+       /* Optimize here for direct hit, only listening connections can
+        * have wildcards anyways.
+        */
+       unsigned int hash = inet_ehashfn(daddr, hnum, saddr, sport);
+       struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash);
+       rwlock_t *lock = inet_ehash_lockp(hashinfo, hash);
+
+       prefetch(head->chain.first);
+       read_lock(lock);
+       sk_for_each(sk, &head->chain) {
+               if (INET_MATCH(sk, hash, acookie, saddr, daddr, ports, dif))
+                       goto hit; /* You sunk my battleship! */
+       }
+
+       /* Must check for a TIME_WAIT'er before going to listener hash. */
+       sk_for_each(sk, &head->twchain) {
+               if (INET_TW_MATCH(sk, hash, acookie, saddr, daddr, ports, dif))
+                       goto hit;
+       }
+       sk = NULL;
+out:
+       read_unlock(lock);
+       return sk;
+hit:
+       sock_hold(sk);
+       goto out;
+}
 
 /* Backports b718989da7 */
 int __must_check pci_enable_device_mem(struct pci_dev *dev);