netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] extensions: libipt_ah: Add translation to nft
@ 2015-12-24 17:30 Shivani Bhardwaj
  2015-12-25 12:07 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Shivani Bhardwaj @ 2015-12-24 17:30 UTC (permalink / raw)
  To: netfilter-devel

Add translation for Authentication Header to nftables.

Examples:

$ sudo iptables-translate -A INPUT -p 51 -m ah --ahspi 500 -j DROP
nft add rule ip filter INPUT ah spi 500 counter drop

$ sudo iptables-translate -A INPUT -p 51 -m ah --ahspi 500:600 -j DROP
nft add rule ip filter INPUT ah spi 500-600 counter drop

$ sudo iptables-translate -A INPUT -p 51 -m ah ! --ahspi 50 -j DROP
nft add rule ip filter INPUT ah spi != 50 counter drop

Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
 extensions/libipt_ah.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/extensions/libipt_ah.c b/extensions/libipt_ah.c
index a490729..b55079e 100644
--- a/extensions/libipt_ah.c
+++ b/extensions/libipt_ah.c
@@ -52,15 +52,15 @@ print_spis(const char *name, uint32_t min, uint32_t max,
 			printf("%u", min);
 		} else {
 			printf("s:%s", inv);
-			printf("%u",min);
+			printf("%u", min);
 			printf(":");
-			printf("%u",max);
+			printf("%u", max);
 		}
 	}
 }
 
 static void ah_print(const void *ip, const struct xt_entry_match *match,
-                     int numeric)
+		     int numeric)
 {
 	const struct ipt_ah *ah = (struct ipt_ah *)match->data;
 
@@ -92,18 +92,37 @@ static void ah_save(const void *ip, const struct xt_entry_match *match)
 
 }
 
+static int ah_xlate(const struct xt_entry_match *match,
+		    struct xt_buf *buf, int numeric)
+{
+	const struct ipt_ah *ahinfo = (struct ipt_ah *)match->data;
+
+	if (!(ahinfo->spis[0] == 0 && ahinfo->spis[1] == 0xFFFFFFFF)) {
+		xt_buf_add(buf, "ah spi%s ",
+			   (ahinfo->invflags & IPT_AH_INV_SPI) ? " !=" : "");
+		if (ahinfo->spis[0] != ahinfo->spis[1])
+			xt_buf_add(buf, "%u-%u ", ahinfo->spis[0],
+				   ahinfo->spis[1]);
+		else
+			xt_buf_add(buf, "%u ", ahinfo->spis[0]);
+	}
+
+	return 1;
+}
+
 static struct xtables_match ah_mt_reg = {
-	.name 		= "ah",
-	.version 	= XTABLES_VERSION,
+	.name		= "ah",
+	.version	= XTABLES_VERSION,
 	.family		= NFPROTO_IPV4,
 	.size		= XT_ALIGN(sizeof(struct ipt_ah)),
-	.userspacesize 	= XT_ALIGN(sizeof(struct ipt_ah)),
-	.help 		= ah_help,
+	.userspacesize	= XT_ALIGN(sizeof(struct ipt_ah)),
+	.help		= ah_help,
 	.init		= ah_init,
-	.print 		= ah_print,
-	.save 		= ah_save,
+	.print		= ah_print,
+	.save		= ah_save,
 	.x6_parse	= ah_parse,
 	.x6_options	= ah_opts,
+	.xlate		= ah_xlate,
 };
 
 void
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] extensions: libipt_ah: Add translation to nft
  2015-12-24 17:30 [PATCH] extensions: libipt_ah: Add translation to nft Shivani Bhardwaj
@ 2015-12-25 12:07 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2015-12-25 12:07 UTC (permalink / raw)
  To: Shivani Bhardwaj; +Cc: netfilter-devel

On Thu, Dec 24, 2015 at 11:00:58PM +0530, Shivani Bhardwaj wrote:
> Add translation for Authentication Header to nftables.
> 
> Examples:
> 
> $ sudo iptables-translate -A INPUT -p 51 -m ah --ahspi 500 -j DROP
> nft add rule ip filter INPUT ah spi 500 counter drop
> 
> $ sudo iptables-translate -A INPUT -p 51 -m ah --ahspi 500:600 -j DROP
> nft add rule ip filter INPUT ah spi 500-600 counter drop
> 
> $ sudo iptables-translate -A INPUT -p 51 -m ah ! --ahspi 50 -j DROP
> nft add rule ip filter INPUT ah spi != 50 counter drop

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-25 12:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-24 17:30 [PATCH] extensions: libipt_ah: Add translation to nft Shivani Bhardwaj
2015-12-25 12:07 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).