All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Piyush Pangtey <gokuvsvegita@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH v3] libxt_multiport: Add translation to nft
Date: Thu, 10 Mar 2016 19:31:47 +0100	[thread overview]
Message-ID: <20160310183146.GA32439@salvia> (raw)
In-Reply-To: <56E16DA8.1060007@gmail.com>

On Thu, Mar 10, 2016 at 06:20:48PM +0530, Piyush Pangtey wrote:
> Added full translation for multiport
> 
> Examples :
> $ iptables-translate -A input -p tcp -m multiport --ports ssh:http -j ACCEPT
> nft add rule ip filter input ip protocol tcp tcp dport { ssh - http } tcp sport
> { ssh - http } counter accept
> 
> $ iptables-translate -A input -p sctp -m multiport --dports 11:18  -j ACCEPT
> nft add rule ip filter input ip protocol sctp sctp dport { 11 - 18 } counter
> accept
> 
> $ iptables-translate -A input -p dccp -m multiport --sports 11:18 -j ACCEPT
> nft add rule ip filter input ip protocol dccp dccp sport { 11 - 18 } counter
> accept
> 
> $ ip6tables-translate -A input -p udplite -m multiport --sports 11:18 -j ACCEPT
> nft add rule ip6 filter input meta l4proto udplite udplite sport { 11 - 18 }
> counter accept
> 
> Signed-off-by: Piyush Pangtey <gokuvsvegita@gmail.com>
> ---
> v2:
> 	Corrected the translations , as suggested by Arturo Borrero González
> v3:
> 	Removed static variable trick. Now utilizes ipt_ip and ip6t_ip which
> 	is now passed to xlate ,from the patch
> 	http://patchwork.ozlabs.org/patch/595128/
> 
> Signed-off-by: Piyush Pangtey <gokuvsvegita@gmail.com>
> ---
>  extensions/libxt_multiport.c | 199 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 199 insertions(+)
> 
> diff --git a/extensions/libxt_multiport.c b/extensions/libxt_multiport.c
> index 03af5a9..4dccc1b 100644
> --- a/extensions/libxt_multiport.c
> +++ b/extensions/libxt_multiport.c
> @@ -278,6 +278,18 @@ print_port(uint16_t port, uint8_t protocol, int numeric)
>  }
>  
>  static void
> +print_port_xlate(struct xt_xlate *xl, uint16_t port, uint8_t protocol,
> +		int numeric)
> +{
> +	const char *service;
> +
> +	if (numeric || (service = port_to_service(port, protocol)) == NULL)
> +		xt_xlate_add(xl, "%u", port);
> +	else
> +		xt_xlate_add(xl, "%s", service);
> +}
> +
> +static void
>  __multiport_print(const struct xt_entry_match *match, int numeric,
>                    uint16_t proto)
>  {
> @@ -318,6 +330,20 @@ static void multiport_print(const void *ip_void,
>  	__multiport_print(match, numeric, ip->proto);
>  }
>  
> +static void multiport_print_xlate(const struct xt_entry_match *match,
> +				 struct xt_xlate *xl, uint16_t proto,
> +				 int numeric)
> +{
> +	const struct xt_multiport_v1 *multiinfo =
> +		(const struct xt_multiport_v1 *)match->data;
> +	unsigned int i;

Missing line break here.

> +	for (i = 0; i < multiinfo->count; i++) {
> +		xt_xlate_add(xl, "%s", i ? "," : "");
> +		print_port_xlate(xl, multiinfo->ports[i],
> +				proto, numeric);
> +	}
> +}
> +
>  static void multiport_print6(const void *ip_void,
>                               const struct xt_entry_match *match, int numeric)
>  {
> @@ -372,6 +398,24 @@ static void multiport_print_v1(const void *ip_void,
>  	__multiport_print_v1(match, numeric, ip->proto);
>  }
>  
> +static void multiport_print_v1_xlate(const struct xt_entry_match *match,
> +				    struct xt_xlate *xl, uint16_t proto,
> +				    int numeric)
> +{
> +	const struct xt_multiport_v1 *multiinfo =
> +		(const struct xt_multiport_v1 *)match->data;
> +	unsigned int i;

Missing line break here to separate variable declaration and function
body.

> +	for (i = 0; i < multiinfo->count; i++) {
> +		xt_xlate_add(xl, "%s", i ? "," : "");
> +		print_port_xlate(xl, multiinfo->ports[i], proto, numeric);
> +		if (multiinfo->pflags[i]) {
> +			xt_xlate_add(xl, " - ");
> +			print_port_xlate(xl, multiinfo->ports[++i],
> +					proto, numeric);
> +		}
> +	}
> +}
> +
>  static void multiport_print6_v1(const void *ip_void,
>                                  const struct xt_entry_match *match, int numeric)
>  {
> @@ -468,6 +512,157 @@ 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, uint16_t protocol, int numeric)
> +{
> +	const struct xt_multiport_v1 *multiinfo =
> +		(const struct xt_multiport_v1 *)match->data;
> +	const char *proto_name;
> +	bool have_multiple = false, have_invert = false ;
                                                       ^
remove this space.

> +
> +	if((proto_name = proto_to_name(protocol)) != NULL){
          ^                                               ^

missing space after if.

> +		if (multiinfo->count > 1) have_multiple = true;

                if (multiinfo->count > 1)
                        have_multiple = true;

Please, review coding style and resubmit. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-03-10 18:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 21:21 [PATCHv3] extensions: libipt_icmp: Add translation to nft Laura Garcia Liebana
2016-03-08 10:53 ` Pablo Neira Ayuso
2016-03-09  6:58   ` [PATCH] libxt_multiport: " FaTe
2016-03-09 12:32     ` Pablo Neira Ayuso
2016-03-09 14:37       ` Piyush Pangtey
2016-03-09 14:39       ` [PATCH v2] " Piyush Pangtey
2016-03-09 17:30         ` Pablo Neira Ayuso
2016-03-10 12:50           ` [PATCH v3] " Piyush Pangtey
2016-03-10 18:31             ` Pablo Neira Ayuso [this message]
2016-03-09  7:05   ` Regarding libxt_multiport translation in nft FaTe
2016-03-09 10:06     ` Arturo Borrero Gonzalez
2016-03-09 14:34       ` Piyush Pangtey
2016-03-09  7:12   ` [PATCH] libip6t_hbh: Add translation to nft FaTe
2016-03-10 18:47     ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160310183146.GA32439@salvia \
    --to=pablo@netfilter.org \
    --cc=gokuvsvegita@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.