Nordeus / ansible_iptables_raw

iptables module for Ansible which keeps state
MIT License
126 stars 42 forks source link

Add compatibility with netfilter backend #36

Open papamoose opened 2 years ago

papamoose commented 2 years ago

Fixes from #30 and #35 plus small tweaks of my own.

nft -j list tables ip returns metainfo as a key in the json we get back. So check to make sure the key 'table' exists we can ignore metainfo key in the loop.

Additionally, nft command seems to want the -j before all other arguments.

[
  {
    "metainfo": {
      "version": "0.9.3",
      "release_name": "Topsy",
      "json_schema_version": 1
    }
  },
  {
    "table": {
      "family": "ip",
      "name": "security",
      "handle": 44
    }
  },
  {
    "table": {
      "family": "ip",
      "name": "raw",
      "handle": 45
    }
  },
  {
    "table": {
      "family": "ip",
      "name": "mangle",
      "handle": 46
    }
  },
  {
    "table": {
      "family": "ip",
      "name": "nat",
      "handle": 47
    }
  },
  {
    "table": {
      "family": "ip",
      "name": "filter",
      "handle": 54
    }
  }
johan-adriaans commented 2 years ago

A small note for anyone running into the problem where their IPv6 iptables rules are ignored. For me, on ubuntu 22.04, the sudo nft list tables command will not return the filter table for IPv6 (table ip6 filter) if there are no IPv6 filter rules present. That caused iptables_raw to ignore all ip6 filter rules (any INPUT DROP, ACCEPT, etc).

To solve this, I bootstrapped the ip6tables INPUT chain with a single dummy rule. That caused the IPv6 filter table to show up in nft, and after that everything went smooth.