From 933400b37d0966980d07d32b64403830429761ed Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 11 Apr 2014 12:31:39 +0200 Subject: nft: xtables: add the infrastructure to translate from iptables to nft This patch provides the infrastructure and two new utilities to translate iptables commands to nft, they are: 1) iptables-restore-translate which basically takes a file that contains the ruleset in iptables-restore format and converts it to the nft syntax, eg. % iptables-restore-translate -f ipt-ruleset > nft-ruleset % cat nft-ruleset # Translated by iptables-restore-translate v1.4.21 on Mon Apr 14 12:18:14 2014 add table ip filter add chain ip filter INPUT { type filter hook input priority 0; } add chain ip filter FORWARD { type filter hook forward priority 0; } add chain ip filter OUTPUT { type filter hook output priority 0; } add rule ip filter INPUT iifname lo counter accept # -t filter -A INPUT -m state --state INVALID -j LOG --log-prefix invalid: ... The rules that cannot be translated are left commented. Users should be able to run this to track down the nft progress to see at what point it can fully replace iptables and their filtering policy. 2) iptables-translate which suggests a translation for an iptables command: $ iptables-translate -I OUTPUT -p udp -d 8.8.8.8 -j ACCEPT nft add rule filter OUTPUT ip protocol udp ip dst 8.8.8.8 counter accept Signed-off-by: Pablo Neira Ayuso --- iptables/nft.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'iptables/nft.h') diff --git a/iptables/nft.h b/iptables/nft.h index 2cf78fda..192050a4 100644 --- a/iptables/nft.h +++ b/iptables/nft.h @@ -155,6 +155,16 @@ enum { int nft_xtables_config_load(struct nft_handle *h, const char *filename, uint32_t flags); +/* + * Translation from iptables to nft + */ +struct xt_buf; + +bool xlate_find_match(const struct iptables_command_state *cs, const char *p_name); +int xlate_matches(const struct iptables_command_state *cs, struct xt_buf *buf); +int xlate_action(const struct iptables_command_state *cs, bool goto_set, + struct xt_buf *buf); + /* * ARP */ -- cgit v1.2.3