]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: libxt_esp: Add translation to nft
authorShivani Bhardwaj <shivanib134@gmail.com>
Sun, 20 Dec 2015 18:13:21 +0000 (23:43 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 16 Feb 2016 18:30:22 +0000 (19:30 +0100)
Add translation for ESP Protocol to nftables.

Examples:

$ sudo iptables-translate -A FORWARD -p esp -j ACCEPT
nft add rule ip filter FORWARD ip protocol esp counter accept

$ sudo iptables-translate -A INPUT  --in-interface  wan --protocol esp -j ACCEPT
nft add rule ip filter INPUT iifname wan ip protocol esp counter accept

$ sudo iptables-translate -A INPUT -p 50 -m esp --espspi 500 -j DROP
nft add rule ip filter INPUT esp spi 500 counter drop

$ sudo iptables-translate -A INPUT -p 50 -m esp --espspi 500:600 -j DROP
nft add rule ip filter INPUT esp spi 500-600 counter drop

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

index 773d6af8a748ee05b10566972f70ad73c9e255c0..e04daf82e2f3c86508ae25505cd7d2f345b99777 100644 (file)
@@ -86,10 +86,28 @@ static void esp_save(const void *ip, const struct xt_entry_match *match)
 
 }
 
+static int esp_xlate(const struct xt_entry_match *match,
+                    struct xt_buf *buf, int numeric)
+{
+       const struct xt_esp *espinfo = (struct xt_esp *)match->data;
+
+       if (!(espinfo->spis[0] == 0 && espinfo->spis[1] == 0xFFFFFFFF)) {
+               xt_buf_add(buf, "esp spi%s",
+                          (espinfo->invflags & XT_ESP_INV_SPI) ? " !=" : "");
+               if (espinfo->spis[0] != espinfo->spis[1])
+                       xt_buf_add(buf, " %u-%u ", espinfo->spis[0],
+                                  espinfo->spis[1]);
+               else
+                       xt_buf_add(buf, " %u ", espinfo->spis[0]);
+       }
+
+       return 1;
+}
+
 static struct xtables_match esp_match = {
        .family         = NFPROTO_UNSPEC,
-       .name           = "esp",
-       .version        = XTABLES_VERSION,
+       .name           = "esp",
+       .version        = XTABLES_VERSION,
        .size           = XT_ALIGN(sizeof(struct xt_esp)),
        .userspacesize  = XT_ALIGN(sizeof(struct xt_esp)),
        .help           = esp_help,
@@ -98,6 +116,7 @@ static struct xtables_match esp_match = {
        .save           = esp_save,
        .x6_parse       = esp_parse,
        .x6_options     = esp_opts,
+       .xlate          = esp_xlate,
 };
 
 void