080-00-fib_trie-Fix-proc-net-fib_trie-when-CONFIG_IP_MULTIP.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. From: Alexander Duyck <alexander.h.duyck@redhat.com>
  2. Date: Tue, 2 Dec 2014 10:58:21 -0800
  3. Subject: [PATCH] fib_trie: Fix /proc/net/fib_trie when
  4. CONFIG_IP_MULTIPLE_TABLES is not defined
  5. In recent testing I had disabled CONFIG_IP_MULTIPLE_TABLES and as a result
  6. when I ran "cat /proc/net/fib_trie" the main trie was displayed multiple
  7. times. I found that the problem line of code was in the function
  8. fib_trie_seq_next. Specifically the line below caused the indexes to go in
  9. the opposite direction of our traversal:
  10. h = tb->tb_id & (FIB_TABLE_HASHSZ - 1);
  11. This issue was that the RT tables are defined such that RT_TABLE_LOCAL is ID
  12. 255, while it is located at TABLE_LOCAL_INDEX of 0, and RT_TABLE_MAIN is 254
  13. with a TABLE_MAIN_INDEX of 1. This means that the above line will return 1
  14. for the local table and 0 for main. The result is that fib_trie_seq_next
  15. will return NULL at the end of the local table, fib_trie_seq_start will
  16. return the start of the main table, and then fib_trie_seq_next will loop on
  17. main forever as h will always return 0.
  18. The fix for this is to reverse the ordering of the two tables. It has the
  19. advantage of making it so that the tables now print in the same order
  20. regardless of if multiple tables are enabled or not. In order to make the
  21. definition consistent with the multiple tables case I simply masked the to
  22. RT_TABLE_XXX values by (FIB_TABLE_HASHSZ - 1). This way the two table
  23. layouts should always stay consistent.
  24. Fixes: 93456b6 ("[IPV4]: Unify access to the routing tables")
  25. Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
  26. Signed-off-by: David S. Miller <davem@davemloft.net>
  27. ---
  28. --- a/include/net/ip_fib.h
  29. +++ b/include/net/ip_fib.h
  30. @@ -201,8 +201,8 @@ void fib_free_table(struct fib_table *tb
  31. #ifndef CONFIG_IP_MULTIPLE_TABLES
  32. -#define TABLE_LOCAL_INDEX 0
  33. -#define TABLE_MAIN_INDEX 1
  34. +#define TABLE_LOCAL_INDEX (RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1))
  35. +#define TABLE_MAIN_INDEX (RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1))
  36. static inline struct fib_table *fib_get_table(struct net *net, u32 id)
  37. {