netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: "Daniel T. Lee" <danieltimlee@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, brouer@redhat.com,
	Robert Olsson <robert@herjulf.net>
Subject: Re: [PATCH 1/2] samples: pktgen: add some helper functions for port parsing
Date: Mon, 1 Jul 2019 16:51:11 +0200	[thread overview]
Message-ID: <20190701165111.3e68cd6c@carbon> (raw)
In-Reply-To: <20190629133358.8251-1-danieltimlee@gmail.com>

On Sat, 29 Jun 2019 22:33:57 +0900
"Daniel T. Lee" <danieltimlee@gmail.com> wrote:

> This commit adds port parsing and port validate helper function to parse
> single or range of port(s) from a given string. (e.g. 1234, 443-444)
> 
> Helpers will be used in prior to set target port(s) in samples/pktgen.
> 
> Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
> ---
>  samples/pktgen/functions.sh | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)


Nice bash shellcode with use of array variables.

Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>

> diff --git a/samples/pktgen/functions.sh b/samples/pktgen/functions.sh
> index f8bb3cd0f4ce..4af4046d71be 100644
> --- a/samples/pktgen/functions.sh
> +++ b/samples/pktgen/functions.sh
> @@ -162,3 +162,37 @@ function get_node_cpus()
>  
>  	echo $node_cpu_list
>  }
> +
> +# Given a single or range of port(s), return minimum and maximum port number.
> +function parse_ports()
> +{
> +    local port_str=$1
> +    local port_list
> +    local min_port
> +    local max_port
> +
> +    IFS="-" read -ra port_list <<< $port_str
> +
> +    min_port=${port_list[0]}
> +    max_port=${port_list[1]:-$min_port}
> +
> +    echo $min_port $max_port
> +}
> +
> +# Given a minimum and maximum port, verify port number.
> +function validate_ports()
> +{
> +    local min_port=$1
> +    local max_port=$2
> +
> +    # 0 < port < 65536
> +    if [[ $min_port -gt 0 && $min_port -lt 65536 ]]; then
> +	if [[ $max_port -gt 0 && $max_port -lt 65536 ]]; then
> +	    if [[ $min_port -le $max_port ]]; then
> +		return 0
> +	    fi
> +	fi
> +    fi
> +
> +    err 5 "Invalid port(s): $min_port-$max_port"
> +}



-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

  parent reply	other threads:[~2019-07-01 14:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-29 13:33 [PATCH 1/2] samples: pktgen: add some helper functions for port parsing Daniel T. Lee
2019-06-29 13:33 ` [PATCH 2/2] samples: pktgen: allow to specify destination port Daniel T. Lee
2019-07-01 15:08   ` Jesper Dangaard Brouer
2019-07-01 20:01     ` Daniel T. Lee
2019-07-01 18:02   ` David Miller
2019-07-01 14:51 ` Jesper Dangaard Brouer [this message]
2019-07-01 18:02 ` [PATCH 1/2] samples: pktgen: add some helper functions for port parsing David Miller

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=20190701165111.3e68cd6c@carbon \
    --to=brouer@redhat.com \
    --cc=danieltimlee@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=robert@herjulf.net \
    /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 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).