* [PATCH v2] extensions: libxt_sctp: Add translation to nft
@ 2016-03-02 19:28 Shivani Bhardwaj
2016-03-03 12:22 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Shivani Bhardwaj @ 2016-03-02 19:28 UTC (permalink / raw)
To: netfilter-devel
Add translation for sctp to nftables.
Full translation of this match awaits the support for --chunk-types
option.
Examples:
$ sudo iptables-translate -A INPUT -p sctp --dport 80 -j DROP
nft add rule ip filter INPUT sctp dport 80 counter drop
$ sudo iptables-translate -A INPUT -p sctp ! --sport 80:100 -j ACCEPT
nft add rule ip filter INPUT sctp sport != 80-100 counter accept
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
Changes in v2:
Add code to check if flags is set
extensions/libxt_sctp.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/extensions/libxt_sctp.c b/extensions/libxt_sctp.c
index 56a4cdf..3b0b048 100644
--- a/extensions/libxt_sctp.c
+++ b/extensions/libxt_sctp.c
@@ -485,6 +485,42 @@ static void sctp_save(const void *ip, const struct xt_entry_match *match)
}
}
+static int sctp_xlate(const struct xt_entry_match *match,
+ struct xt_xlate *xl, int numeric)
+{
+ const struct xt_sctp_info *einfo =
+ (const struct xt_sctp_info *)match->data;
+
+ if (!einfo->flags)
+ return 0;
+
+ xt_xlate_add(xl, "sctp ");
+
+ if (einfo->flags & XT_SCTP_SRC_PORTS) {
+ if (einfo->spts[0] != einfo->spts[1])
+ xt_xlate_add(xl, "sport%s %u-%u ",
+ einfo->invflags & XT_SCTP_SRC_PORTS ? " !=" : "",
+ einfo->spts[0], einfo->spts[1]);
+ else
+ xt_xlate_add(xl, "sport%s %u ",
+ einfo->invflags & XT_SCTP_SRC_PORTS ? " !=" : "",
+ einfo->spts[0]);
+ }
+
+ if (einfo->flags & XT_SCTP_DEST_PORTS) {
+ if (einfo->dpts[0] != einfo->dpts[1])
+ xt_xlate_add(xl, "dport%s %u-%u ",
+ einfo->invflags & XT_SCTP_DEST_PORTS ? " !=" : "",
+ einfo->dpts[0], einfo->dpts[1]);
+ else
+ xt_xlate_add(xl, "dport%s %u ",
+ einfo->invflags & XT_SCTP_DEST_PORTS ? " !=" : "",
+ einfo->dpts[0]);
+ }
+
+ return 1;
+}
+
static struct xtables_match sctp_match = {
.name = "sctp",
.family = NFPROTO_UNSPEC,
@@ -497,6 +533,7 @@ static struct xtables_match sctp_match = {
.print = sctp_print,
.save = sctp_save,
.extra_opts = sctp_opts,
+ .xlate = sctp_xlate,
};
void _init(void)
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] extensions: libxt_sctp: Add translation to nft
2016-03-02 19:28 [PATCH v2] extensions: libxt_sctp: Add translation to nft Shivani Bhardwaj
@ 2016-03-03 12:22 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2016-03-03 12:22 UTC (permalink / raw)
To: Shivani Bhardwaj; +Cc: netfilter-devel
On Thu, Mar 03, 2016 at 12:58:48AM +0530, Shivani Bhardwaj wrote:
> Add translation for sctp to nftables.
> Full translation of this match awaits the support for --chunk-types
> option.
>
> Examples:
>
> $ sudo iptables-translate -A INPUT -p sctp --dport 80 -j DROP
> nft add rule ip filter INPUT sctp dport 80 counter drop
>
> $ sudo iptables-translate -A INPUT -p sctp ! --sport 80:100 -j ACCEPT
> nft add rule ip filter INPUT sctp sport != 80-100 counter accept
Also applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-03-03 12:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-02 19:28 [PATCH v2] extensions: libxt_sctp: Add translation to nft Shivani Bhardwaj
2016-03-03 12:22 ` 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).