]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: libxt_cpu: Add translation to nft
authorShivani Bhardwaj <shivanib134@gmail.com>
Wed, 23 Dec 2015 16:41:58 +0000 (22:11 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 16 Feb 2016 18:30:23 +0000 (19:30 +0100)
Add translation for module cpu to nftables.

Examples:

$ sudo iptables-translate -A INPUT -p tcp --dport 80 -m cpu --cpu 0 -j ACCEPT
nft add rule ip filter INPUT tcp dport 80 cpu 0 counter accept

$ sudo iptables-translate -A INPUT -p tcp --dport 80 -m cpu ! --cpu 1 -j ACCEPT
nft add rule ip filter INPUT tcp dport 80 cpu != 1 counter accept

Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
extensions/libxt_cpu.c

index 404a6a66a5a0c9d7d52ae2de69f658c6a42afe03..74e6077eb1d953a5fba7198bb5d094e776342666 100644 (file)
@@ -44,9 +44,19 @@ static void cpu_save(const void *ip, const struct xt_entry_match *match)
        printf("%s --cpu %u", info->invert ? " !" : "", info->cpu);
 }
 
+static int cpu_xlate(const struct xt_entry_match *match,
+                    struct xt_buf *buf, int numeric)
+{
+       const struct xt_cpu_info *info = (void *)match->data;
+
+       xt_buf_add(buf, "cpu%s %u ", info->invert ? " !=" : "", info->cpu);
+
+       return 1;
+}
+
 static struct xtables_match cpu_match = {
        .family         = NFPROTO_UNSPEC,
-       .name           = "cpu",
+       .name           = "cpu",
        .version        = XTABLES_VERSION,
        .size           = XT_ALIGN(sizeof(struct xt_cpu_info)),
        .userspacesize  = XT_ALIGN(sizeof(struct xt_cpu_info)),
@@ -55,6 +65,7 @@ static struct xtables_match cpu_match = {
        .save           = cpu_save,
        .x6_parse       = cpu_parse,
        .x6_options     = cpu_opts,
+       .xlate          = cpu_xlate,
 };
 
 void _init(void)