#!/bin/sh

# When the lts and stable kernel is switched to version 3.18 or greater
# this script can be simplified to:
#
#     nft flush ruleset

for family in ip ip6 inet arp bridge; do
  nft list tables $family | while read _ table; do
    nft flush table $family $table
    nft list table $family $table |
      awk '/^[[:blank:]]+chain [[:alnum:]]+ {$/ { print $2 }' |
      while read chain; do
      nft flush chain $family $table $chain
      nft delete chain $family $table $chain
    done
    nft delete table $family $table
  done
done
