010-Add-support-for-kernel-4.17.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From 831486ea6c7d7adfbdc453587a65bcba247d698b Mon Sep 17 00:00:00 2001
  2. From: Alberto Leiva Popper <ydahhrk@gmail.com>
  3. Date: Fri, 6 Jul 2018 13:19:21 -0500
  4. Subject: [PATCH 1/2] Add support for kernel 4.17
  5. Fixes #266.
  6. ---
  7. mod/common/hash_table.c | 14 +++-----------
  8. mod/stateful/fragment_db.c | 4 +---
  9. 2 files changed, 4 insertions(+), 14 deletions(-)
  10. diff --git a/mod/common/hash_table.c b/mod/common/hash_table.c
  11. index 25ddd7a6..4e9272f8 100644
  12. --- a/mod/common/hash_table.c
  13. +++ b/mod/common/hash_table.c
  14. @@ -23,8 +23,7 @@
  15. * @macro HTABLE_NAME name of the hash table structure to generate. Optional; Default: hash_table.
  16. * @macro KEY_TYPE data type of the table's keys.
  17. * @macro VALUE_TYPE data type of the table's values.
  18. - * @macro HASH_TABLE_SIZE The size of the internal array, in slots. Optional;
  19. - * Default = Max = 64k - 1.
  20. + * @macro HASH_TABLE_SIZE The size of the internal array, in slots. MUST be a power of 2.
  21. * @macro GENERATE_PRINT just define it if you want the print function; otherwise it will not be
  22. * generated.
  23. * @macro GENERATE_FOR_EACH just define it if you want the for_each function; otherwise it will not
  24. @@ -44,13 +43,6 @@
  25. #define HTABLE_NAME hash_table
  26. #endif
  27. -#ifndef HASH_TABLE_SIZE
  28. -/**
  29. - * This number should not exceed unsigned int's maximum.
  30. - */
  31. -#define HASH_TABLE_SIZE (64 * 1024 - 1)
  32. -#endif
  33. -
  34. /** Creates a token name by concatenating prefix and suffix. */
  35. #define CONCAT_AUX(prefix, suffix) prefix ## suffix
  36. /** Seems useless, but if not present, the compiler won't expand the HTABLE_NAME macro... */
  37. @@ -131,7 +123,7 @@ static struct KEY_VALUE_PAIR *GET_AUX(struct HTABLE_NAME *table, const KEY_TYPE
  38. if (WARN(!table, "The table is NULL."))
  39. return NULL;
  40. - hash_code = table->hash_function(key) % HASH_TABLE_SIZE;
  41. + hash_code = table->hash_function(key) & (HASH_TABLE_SIZE - 1);
  42. hlist_for_each(current_node, &table->table[hash_code]) {
  43. current_pair = hlist_entry(current_node, struct KEY_VALUE_PAIR, hlist_hook);
  44. if (table->equals_function(key, &current_pair->key))
  45. @@ -210,7 +202,7 @@ static int PUT(struct HTABLE_NAME *table, KEY_TYPE *key, VALUE_TYPE *value)
  46. key_value->value = value;
  47. /* Insert the key-value to the table. */
  48. - hash_code = table->hash_function(key) % HASH_TABLE_SIZE;
  49. + hash_code = table->hash_function(key) & (HASH_TABLE_SIZE - 1);
  50. hlist_add_head(&key_value->hlist_hook, &table->table[hash_code]);
  51. list_add_tail(&key_value->list_hook, &table->list);
  52. diff --git a/mod/stateful/fragment_db.c b/mod/stateful/fragment_db.c
  53. index 44f966aa..ef0b1f5a 100644
  54. --- a/mod/stateful/fragment_db.c
  55. +++ b/mod/stateful/fragment_db.c
  56. @@ -90,10 +90,8 @@ static bool equals_function(const struct packet *k1, const struct packet *k2)
  57. static unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
  58. const struct in6_addr *daddr, u32 rnd)
  59. {
  60. - u32 c;
  61. - c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
  62. + return jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
  63. (__force u32)id, rnd);
  64. - return c & (INETFRAGS_HASHSZ - 1);
  65. }
  66. #endif
  67. --
  68. 2.19.1