351-v4.18-netfilter-nf_flow_table-cache-mtu-in-struct-flow_off.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Fri, 16 Feb 2018 10:57:23 +0100
  3. Subject: [PATCH] netfilter: nf_flow_table: cache mtu in struct
  4. flow_offload_tuple
  5. Reduces the number of cache lines touched in the offload forwarding path
  6. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  7. ---
  8. --- a/include/net/netfilter/nf_flow_table.h
  9. +++ b/include/net/netfilter/nf_flow_table.h
  10. @@ -55,6 +55,8 @@ struct flow_offload_tuple {
  11. int oifidx;
  12. + u16 mtu;
  13. +
  14. struct dst_entry *dst_cache;
  15. };
  16. --- a/net/ipv4/netfilter/nf_flow_table_ipv4.c
  17. +++ b/net/ipv4/netfilter/nf_flow_table_ipv4.c
  18. @@ -177,7 +177,7 @@ static int nf_flow_tuple_ip(struct sk_bu
  19. }
  20. /* Based on ip_exceeds_mtu(). */
  21. -static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
  22. +static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
  23. {
  24. if (skb->len <= mtu)
  25. return false;
  26. @@ -191,17 +191,6 @@ static bool __nf_flow_exceeds_mtu(const
  27. return true;
  28. }
  29. -static bool nf_flow_exceeds_mtu(struct sk_buff *skb, const struct rtable *rt)
  30. -{
  31. - u32 mtu;
  32. -
  33. - mtu = ip_dst_mtu_maybe_forward(&rt->dst, true);
  34. - if (__nf_flow_exceeds_mtu(skb, mtu))
  35. - return true;
  36. -
  37. - return false;
  38. -}
  39. -
  40. unsigned int
  41. nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
  42. const struct nf_hook_state *state)
  43. @@ -232,9 +221,9 @@ nf_flow_offload_ip_hook(void *priv, stru
  44. dir = tuplehash->tuple.dir;
  45. flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
  46. -
  47. rt = (const struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
  48. - if (unlikely(nf_flow_exceeds_mtu(skb, rt)))
  49. +
  50. + if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
  51. return NF_ACCEPT;
  52. if (skb_try_make_writable(skb, sizeof(*iph)))
  53. --- a/net/ipv6/netfilter/nf_flow_table_ipv6.c
  54. +++ b/net/ipv6/netfilter/nf_flow_table_ipv6.c
  55. @@ -173,7 +173,7 @@ static int nf_flow_tuple_ipv6(struct sk_
  56. }
  57. /* Based on ip_exceeds_mtu(). */
  58. -static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
  59. +static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
  60. {
  61. if (skb->len <= mtu)
  62. return false;
  63. @@ -184,17 +184,6 @@ static bool __nf_flow_exceeds_mtu(const
  64. return true;
  65. }
  66. -static bool nf_flow_exceeds_mtu(struct sk_buff *skb, const struct rt6_info *rt)
  67. -{
  68. - u32 mtu;
  69. -
  70. - mtu = ip6_dst_mtu_forward(&rt->dst);
  71. - if (__nf_flow_exceeds_mtu(skb, mtu))
  72. - return true;
  73. -
  74. - return false;
  75. -}
  76. -
  77. unsigned int
  78. nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
  79. const struct nf_hook_state *state)
  80. @@ -225,9 +214,9 @@ nf_flow_offload_ipv6_hook(void *priv, st
  81. dir = tuplehash->tuple.dir;
  82. flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
  83. -
  84. rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache;
  85. - if (unlikely(nf_flow_exceeds_mtu(skb, rt)))
  86. +
  87. + if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
  88. return NF_ACCEPT;
  89. if (skb_try_make_writable(skb, sizeof(*ip6h)))
  90. --- a/net/netfilter/nf_flow_table.c
  91. +++ b/net/netfilter/nf_flow_table.c
  92. @@ -4,6 +4,8 @@
  93. #include <linux/netfilter.h>
  94. #include <linux/rhashtable.h>
  95. #include <linux/netdevice.h>
  96. +#include <net/ip.h>
  97. +#include <net/ip6_route.h>
  98. #include <net/netfilter/nf_tables.h>
  99. #include <net/netfilter/nf_flow_table.h>
  100. #include <net/netfilter/nf_conntrack.h>
  101. @@ -23,6 +25,7 @@ flow_offload_fill_dir(struct flow_offloa
  102. {
  103. struct flow_offload_tuple *ft = &flow->tuplehash[dir].tuple;
  104. struct nf_conntrack_tuple *ctt = &ct->tuplehash[dir].tuple;
  105. + struct dst_entry *dst = route->tuple[dir].dst;
  106. ft->dir = dir;
  107. @@ -30,10 +33,12 @@ flow_offload_fill_dir(struct flow_offloa
  108. case NFPROTO_IPV4:
  109. ft->src_v4 = ctt->src.u3.in;
  110. ft->dst_v4 = ctt->dst.u3.in;
  111. + ft->mtu = ip_dst_mtu_maybe_forward(dst, true);
  112. break;
  113. case NFPROTO_IPV6:
  114. ft->src_v6 = ctt->src.u3.in6;
  115. ft->dst_v6 = ctt->dst.u3.in6;
  116. + ft->mtu = ip6_dst_mtu_forward(dst);
  117. break;
  118. }
  119. @@ -44,8 +49,7 @@ flow_offload_fill_dir(struct flow_offloa
  120. ft->iifidx = route->tuple[dir].ifindex;
  121. ft->oifidx = route->tuple[!dir].ifindex;
  122. -
  123. - ft->dst_cache = route->tuple[dir].dst;
  124. + ft->dst_cache = dst;
  125. }
  126. struct flow_offload *