204-tests-shell-add-flowtable-tests.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. From: Pablo Neira Ayuso <[email protected]>
  2. Date: Mon, 22 Jan 2018 19:54:36 +0100
  3. Subject: [PATCH] tests: shell: add flowtable tests
  4. Add basic flowtable tests.
  5. Signed-off-by: Pablo Neira Ayuso <[email protected]>
  6. ---
  7. create mode 100755 tests/shell/testcases/flowtable/0001flowtable_0
  8. create mode 100755 tests/shell/testcases/flowtable/0002create_flowtable_0
  9. create mode 100755 tests/shell/testcases/flowtable/0003add_after_flush_0
  10. create mode 100755 tests/shell/testcases/flowtable/0004delete_after_add0
  11. create mode 100755 tests/shell/testcases/flowtable/0005delete_in_use_1
  12. --- a/tests/shell/run-tests.sh
  13. +++ b/tests/shell/run-tests.sh
  14. @@ -68,7 +68,9 @@ kernel_cleanup() {
  15. nft_set_hash nft_set_rbtree nft_set_bitmap \
  16. nft_chain_nat_ipv4 nft_chain_nat_ipv6 \
  17. nf_tables_inet nf_tables_bridge nf_tables_arp \
  18. - nf_tables_ipv4 nf_tables_ipv6 nf_tables
  19. + nf_tables_ipv4 nf_tables_ipv6 nf_tables \
  20. + nf_flow_table nf_flow_table_ipv4 nf_flow_tables_ipv6 \
  21. + nf_flow_table_inet nft_flow_offload
  22. }
  23. find_tests() {
  24. --- /dev/null
  25. +++ b/tests/shell/testcases/flowtable/0001flowtable_0
  26. @@ -0,0 +1,33 @@
  27. +#!/bin/bash
  28. +
  29. +tmpfile=$(mktemp)
  30. +if [ ! -w $tmpfile ] ; then
  31. + echo "Failed to create tmp file" >&2
  32. + exit 0
  33. +fi
  34. +
  35. +trap "rm -rf $tmpfile" EXIT # cleanup if aborted
  36. +
  37. +
  38. +EXPECTED='table inet t {
  39. + flowtable f {
  40. + hook ingress priority 10
  41. + devices = { eth0, wlan0 }
  42. + }
  43. +
  44. + chain c {
  45. + flow offload @f
  46. + }
  47. +}'
  48. +
  49. +echo "$EXPECTED" > $tmpfile
  50. +set -e
  51. +$NFT -f $tmpfile
  52. +
  53. +GET="$($NFT list ruleset)"
  54. +
  55. +if [ "$EXPECTED" != "$GET" ] ; then
  56. + DIFF="$(which diff)"
  57. + [ -x $DIFF ] && $DIFF -u <(echo "$EXPECTED") <(echo "$GET")
  58. + exit 1
  59. +fi
  60. --- /dev/null
  61. +++ b/tests/shell/testcases/flowtable/0002create_flowtable_0
  62. @@ -0,0 +1,12 @@
  63. +#!/bin/bash
  64. +
  65. +set -e
  66. +$NFT add table t
  67. +$NFT add flowtable t f { hook ingress priority 10 \; devices = { eth0, wlan0 }\; }
  68. +if $NFT create flowtable t f { hook ingress priority 10 \; devices = { eth0, wlan0 }\; } 2>/dev/null ; then
  69. + echo "E: flowtable creation not failing on existing set" >&2
  70. + exit 1
  71. +fi
  72. +$NFT add flowtable t f { hook ingress priority 10 \; devices = { eth0, wlan0 }\; }
  73. +
  74. +exit 0
  75. --- /dev/null
  76. +++ b/tests/shell/testcases/flowtable/0003add_after_flush_0
  77. @@ -0,0 +1,8 @@
  78. +#!/bin/bash
  79. +
  80. +set -e
  81. +$NFT add table x
  82. +$NFT add flowtable x y { hook ingress priority 0\; devices = { eth0, wlan0 }\;}
  83. +$NFT flush ruleset
  84. +$NFT add table x
  85. +$NFT add flowtable x y { hook ingress priority 0\; devices = { eth0, wlan0 }\;}
  86. --- /dev/null
  87. +++ b/tests/shell/testcases/flowtable/0004delete_after_add0
  88. @@ -0,0 +1,6 @@
  89. +#!/bin/bash
  90. +
  91. +set -e
  92. +$NFT add table x
  93. +$NFT add flowtable x y { hook ingress priority 0\; devices = { eth0, wlan0 }\;}
  94. +$NFT delete flowtable x y
  95. --- /dev/null
  96. +++ b/tests/shell/testcases/flowtable/0005delete_in_use_1
  97. @@ -0,0 +1,9 @@
  98. +#!/bin/bash
  99. +
  100. +set -e
  101. +$NFT add table x
  102. +$NFT add chain x x
  103. +$NFT add flowtable x y { hook ingress priority 0\; devices = { eth0, wlan0 }\;}
  104. +$NFT add rule x x flow offload @y
  105. +$NFT delete flowtable x y
  106. +echo "E: delete flowtable in use"