Thread (13 messages) 13 messages, 2 authors, 2021-11-19

[PATCH net 02/11] selftests: netfilter: extend nfqueue tests to cover vrf device

flat view
STALE1793d SUPERSEDED

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: 2021-11-18 22:26:34
Also in: netfilter-devel
Subsystem: kernel selftest framework, the rest · Maintainers: Shuah Khan, Shuah Khan, Linus Torvalds

Revision v1 of 266 in this series.

Revisions (266)
  1. v1
  2. v1
  3. v1
  4. v1
  5. v1
  6. v1
  7. v1
  8. v1
  9. v1
  10. v1
  11. v1
  12. v1
  13. v1
  14. v1
  15. v1
  16. v1
  17. v1
  18. v1
  19. v1
  20. v1
  21. v1
  22. v1
  23. v1
  24. v1
  25. v1
  26. v1
  27. v1
  28. v1
  29. v1
  30. v1
  31. v1
  32. v1
  33. v1
  34. v1
  35. v1
  36. v1
  37. v1
  38. v1
  39. v1
  40. v1
  41. v1
  42. v1
  43. v1
  44. v1
  45. v1
  46. v1
  47. v1
  48. v1
  49. v1
  50. v1
  51. v1
  52. v1
  53. v1
  54. v1
  55. v1
  56. v1
  57. v1
  58. v1
  59. v1
  60. v1
  61. v1
  62. v1
  63. v1
  64. v1
  65. v1
  66. v1
  67. v1
  68. v1
  69. v1
  70. v1
  71. v1
  72. v1
  73. v1
  74. v1
  75. v1
  76. v1
  77. v1
  78. v1
  79. v1
  80. v1
  81. v1
  82. v1
  83. v1
  84. v1
  85. v1
  86. v1
  87. v1
  88. v1
  89. v1
  90. v1
  91. v1
  92. v1
  93. v1
  94. v1
  95. v1
  96. v1
  97. v1
  98. v1
  99. v1
  100. v1
  101. v1
  102. v1
  103. v1
  104. v1
  105. v1
  106. v1
  107. v1
  108. v1
  109. v1
  110. v1
  111. v1
  112. v1
  113. v1
  114. v1
  115. v1
  116. v1
  117. v1
  118. v1
  119. v1
  120. v1
  121. v1
  122. v1
  123. v1
  124. v1
  125. v1
  126. v1
  127. v1
  128. v1
  129. v1
  130. v1
  131. v1
  132. v1
  133. v1
  134. v1
  135. v1
  136. v1
  137. v1
  138. v1
  139. v1
  140. v1
  141. v1
  142. v1
  143. v1
  144. v1
  145. v2 [diff vs current]
  146. v1
  147. v1
  148. v1 current
  149. v1
  150. v1
  151. v1
  152. v1
  153. v1
  154. v1
  155. v1
  156. v1
  157. v2 [diff vs current]
  158. v1
  159. v1
  160. v1
  161. v1
  162. v1
  163. v1
  164. v1
  165. v1
  166. v1
  167. v1
  168. v1
  169. v1
  170. v1
  171. v1
  172. v1
  173. v1
  174. v1
  175. v1
  176. v1
  177. v1
  178. v1
  179. v1
  180. v1
  181. v1
  182. v1
  183. v1
  184. v1
  185. v1
  186. v1
  187. v1
  188. v1
  189. v1
  190. v1
  191. v1
  192. v1
  193. v1
  194. v1
  195. v1
  196. v1
  197. v1
  198. v1
  199. v1
  200. v1
  201. v1
  202. v1
  203. v1
  204. v1
  205. v1
  206. v1
  207. v1
  208. v1
  209. v1
  210. v2 [diff vs current]
  211. v1
  212. v1
  213. v1
  214. v2 [diff vs current]
  215. v1
  216. v1
  217. v1
  218. v1
  219. v1
  220. v2 [diff vs current]
  221. v1
  222. v1
  223. v1
  224. v1
  225. v1
  226. v2 [diff vs current]
  227. v3 [diff vs current]
  228. v1
  229. v1
  230. v1
  231. v1
  232. v1
  233. v1
  234. v1
  235. v2 [diff vs current]
  236. v1
  237. v1
  238. v1
  239. v2 [diff vs current]
  240. v1
  241. v1
  242. v1
  243. v1
  244. v1
  245. v2 [diff vs current]
  246. v1
  247. v1
  248. v1
  249. v1
  250. v1
  251. v1
  252. v1
  253. v1
  254. v2 [diff vs current]
  255. v1
  256. v2 [diff vs current]
  257. v1
  258. v1
  259. v1
  260. v1
  261. v2 [diff vs current]
  262. v1
  263. v1
  264. v2 [diff vs current]
  265. v2 [diff vs current]
  266. v2 [diff vs current]
From: Florian Westphal <fw@strlen.de>

VRF device calls the output/postrouting hooks so packet should be seeon
with oifname tvrf and once with eth0.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 .../testing/selftests/netfilter/nft_queue.sh  | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
diff --git a/tools/testing/selftests/netfilter/nft_queue.sh b/tools/testing/selftests/netfilter/nft_queue.sh
index 3d202b90b33d..7d27f1f3bc01 100755
--- a/tools/testing/selftests/netfilter/nft_queue.sh
+++ b/tools/testing/selftests/netfilter/nft_queue.sh
@@ -16,6 +16,10 @@ timeout=4
 
 cleanup()
 {
+	ip netns pids ${ns1} | xargs kill 2>/dev/null
+	ip netns pids ${ns2} | xargs kill 2>/dev/null
+	ip netns pids ${nsrouter} | xargs kill 2>/dev/null
+
 	ip netns del ${ns1}
 	ip netns del ${ns2}
 	ip netns del ${nsrouter}
@@ -332,6 +336,55 @@ EOF
 	echo "PASS: tcp via loopback and re-queueing"
 }
 
+test_icmp_vrf() {
+	ip -net $ns1 link add tvrf type vrf table 9876
+	if [ $? -ne 0 ];then
+		echo "SKIP: Could not add vrf device"
+		return
+	fi
+
+	ip -net $ns1 li set eth0 master tvrf
+	ip -net $ns1 li set tvrf up
+
+	ip -net $ns1 route add 10.0.2.0/24 via 10.0.1.1 dev eth0 table 9876
+ip netns exec ${ns1} nft -f /dev/stdin <<EOF
+flush ruleset
+table inet filter {
+	chain output {
+		type filter hook output priority 0; policy accept;
+		meta oifname "tvrf" icmp type echo-request counter queue num 1
+		meta oifname "eth0" icmp type echo-request counter queue num 1
+	}
+	chain post {
+		type filter hook postrouting priority 0; policy accept;
+		meta oifname "tvrf" icmp type echo-request counter queue num 1
+		meta oifname "eth0" icmp type echo-request counter queue num 1
+	}
+}
+EOF
+	ip netns exec ${ns1} ./nf-queue -q 1 -t $timeout &
+	local nfqpid=$!
+
+	sleep 1
+	ip netns exec ${ns1} ip vrf exec tvrf ping -c 1 10.0.2.99 > /dev/null
+
+	for n in output post; do
+		for d in tvrf eth0; do
+			ip netns exec ${ns1} nft list chain inet filter $n | grep -q "oifname \"$d\" icmp type echo-request counter packets 1"
+			if [ $? -ne 0 ] ; then
+				echo "FAIL: chain $n: icmp packet counter mismatch for device $d" 1>&2
+				ip netns exec ${ns1} nft list ruleset
+				ret=1
+				return
+			fi
+		done
+	done
+
+	wait $nfqpid
+	[ $? -eq 0 ] && echo "PASS: icmp+nfqueue via vrf"
+	wait 2>/dev/null
+}
+
 ip netns exec ${nsrouter} sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
 ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
 ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
@@ -372,5 +425,6 @@ test_queue 20
 test_tcp_forward
 test_tcp_localhost
 test_tcp_localhost_requeue
+test_icmp_vrf
 
 exit $ret
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help