Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples: pktgen: add some helper functions for port parsing

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>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Daniel T. Lee and committed by
David S. Miller
226b96c2 a346abe0

+34
+34
samples/pktgen/functions.sh
··· 162 162 163 163 echo $node_cpu_list 164 164 } 165 + 166 + # Given a single or range of port(s), return minimum and maximum port number. 167 + function parse_ports() 168 + { 169 + local port_str=$1 170 + local port_list 171 + local min_port 172 + local max_port 173 + 174 + IFS="-" read -ra port_list <<< $port_str 175 + 176 + min_port=${port_list[0]} 177 + max_port=${port_list[1]:-$min_port} 178 + 179 + echo $min_port $max_port 180 + } 181 + 182 + # Given a minimum and maximum port, verify port number. 183 + function validate_ports() 184 + { 185 + local min_port=$1 186 + local max_port=$2 187 + 188 + # 0 < port < 65536 189 + if [[ $min_port -gt 0 && $min_port -lt 65536 ]]; then 190 + if [[ $max_port -gt 0 && $max_port -lt 65536 ]]; then 191 + if [[ $min_port -le $max_port ]]; then 192 + return 0 193 + fi 194 + fi 195 + fi 196 + 197 + err 5 "Invalid port(s): $min_port-$max_port" 198 + }