netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* extensions: libxt_multiport: Multiport translations
@ 2016-03-03 18:02 Piyush Pangtey
  2016-03-05 12:42 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Piyush Pangtey @ 2016-03-03 18:02 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

Added multiport translations for ipv4 only .
It's for review pupose only , it definitely needs changes .

example :
iptables-translate -A INPUT -p tcp -m multiport --dports 22,http,ssh -j ACCEPT
nft add rule ip filter INPUT ip protocol tcp dport  { 22,80,22 } counter accept

diff --git a/extensions/libxt_multiport.c b/extensions/libxt_multiport.c
index 03af5a9..6b46f93 100644
--- a/extensions/libxt_multiport.c
+++ b/extensions/libxt_multiport.c
@@ -468,6 +468,67 @@ static void multiport_save6_v1(const void *ip_void,
     __multiport_save_v1(match, ip->proto);
 }

+static int multiport_xlate(const struct xt_entry_match *match, struct
xt_xlate *xl,
+             int numeric)
+{
+    const struct xt_multiport_v1 *multiinfo
+        = (const struct xt_multiport_v1 *)match->data;
+    unsigned int i;
+
+    switch (multiinfo->flags) {
+    case XT_MULTIPORT_SOURCE:
+        xt_xlate_add(xl,"sport ");
+        break;
+
+    case XT_MULTIPORT_DESTINATION:
+        xt_xlate_add(xl,"dport ");
+        break;
+
+    default:
+        return 1;
+    }
+    xt_xlate_add(xl," { ");
+    for (i=0; i < multiinfo->count; i++) {
+        xt_xlate_add(xl,"%u%s", multiinfo->ports[i],
+                (i+1) != multiinfo->count ? "," : "");
+    }
+    xt_xlate_add(xl," } ");
+    return 1;
+}
+
+static int multiport_xlate_v1(const struct xt_entry_match *match,
struct xt_xlate *xl,
+             int numeric)
+{
+    const struct xt_multiport_v1 *multiinfo
+        = (const struct xt_multiport_v1 *)match->data;
+    unsigned int i;
+
+    switch (multiinfo->flags) {
+    case XT_MULTIPORT_SOURCE:
+        xt_xlate_add(xl,"sport ");
+        break;
+
+    case XT_MULTIPORT_DESTINATION:
+        xt_xlate_add(xl,"dport ");
+        break;
+
+    default:
+        return 1;
+    }
+    xt_xlate_add(xl," { ");
+    for (i=0; i < multiinfo->count; i++) {
+        xt_xlate_add(xl,"%u%s", multiinfo->ports[i],
+                (i+1) != multiinfo->count ? "," : "");
+        if (multiinfo->pflags[i]) {
+            i++;
+            xt_xlate_add(xl,"%u%s", multiinfo->ports[i],
+                (i) != multiinfo->count ? "," : "");
+        }
+    }
+    xt_xlate_add(xl," } ");
+    return 1;
+}
+
 static struct xtables_match multiport_mt_reg[] = {
     {
         .family        = NFPROTO_IPV4,
@@ -482,6 +543,7 @@ static struct xtables_match multiport_mt_reg[] = {
         .print         = multiport_print,
         .save          = multiport_save,
         .x6_options    = multiport_opts,
+        .xlate         = multiport_xlate,
     },
     {
         .family        = NFPROTO_IPV6,
@@ -510,6 +572,7 @@ static struct xtables_match multiport_mt_reg[] = {
         .print         = multiport_print_v1,
         .save          = multiport_save_v1,
         .x6_options    = multiport_opts,
+        .xlate           = multiport_xlate_v1,
     },
     {
         .family        = NFPROTO_IPV6,

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

* Re: extensions: libxt_multiport: Multiport translations
  2016-03-03 18:02 extensions: libxt_multiport: Multiport translations Piyush Pangtey
@ 2016-03-05 12:42 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2016-03-05 12:42 UTC (permalink / raw)
  To: ppang; +Cc: netfilter-devel

On Thu, Mar 03, 2016 at 06:02:41PM +0000, Piyush Pangtey wrote:
> Added multiport translations for ipv4 only .
> It's for review pupose only , it definitely needs changes .
> 
> example :
> iptables-translate -A INPUT -p tcp -m multiport --dports 22,http,ssh -j ACCEPT
> nft add rule ip filter INPUT ip protocol tcp dport  { 22,80,22 } counter accept
> 
> diff --git a/extensions/libxt_multiport.c b/extensions/libxt_multiport.c
> index 03af5a9..6b46f93 100644
> --- a/extensions/libxt_multiport.c
> +++ b/extensions/libxt_multiport.c
> @@ -468,6 +468,67 @@ static void multiport_save6_v1(const void *ip_void,
>      __multiport_save_v1(match, ip->proto);
>  }
> 
> +static int multiport_xlate(const struct xt_entry_match *match, struct
> xt_xlate *xl,
> +             int numeric)
> +{
> +    const struct xt_multiport_v1 *multiinfo
> +        = (const struct xt_multiport_v1 *)match->data;

The = should be on the first line, ie.

        const struct xt_multiport_v1 *multiinfo =
                (const struct xt_multiport_v1 *)match->data;

> +    unsigned int i;
   ^^^^
I see spaces here, there should be an 8-chars tab indentation there.

Please, make sure coding style is correct.

> +    switch (multiinfo->flags) {
> +    case XT_MULTIPORT_SOURCE:
> +        xt_xlate_add(xl,"sport ");
                           ^
                          add space after comma

> +        break;
> +

No need for this extra line break;

> +    case XT_MULTIPORT_DESTINATION:
> +        xt_xlate_add(xl,"dport ");
> +        break;
> +
> +    default:
> +        return 1;
> +    }
> +    xt_xlate_add(xl," { ");
> +    for (i=0; i < multiinfo->count; i++) {
             ^
add space betwen variable and value, ie.

        i = 0

this is preferred.

> +        xt_xlate_add(xl,"%u%s", multiinfo->ports[i],
> +                (i+1) != multiinfo->count ? "," : "");

Align this line with the parens:

        xt_xlate_add(xl,"%u%s", multiinfo->ports[i],
                    i + 1 != multiinfo->count ? "," : "");


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

end of thread, other threads:[~2016-03-05 12:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-03 18:02 extensions: libxt_multiport: Multiport translations Piyush Pangtey
2016-03-05 12:42 ` 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).