Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 1/2] controller: fix checking invalid server address
Date: Fri, 25 Jan 2019 12:37:30 +0900	[thread overview]
Message-ID: <1548387451-29818-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1548387451-29818-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

For value of `--bind-addr` or `-b` option, SPP CLI checks if it matches
to `*.*.*.*` for IPv4 address, but it is inadeaute because no checkings
for the range of values. This update is to add methods for the
validation.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell_lib/common.py | 22 ++++++++++++++++++++++
 src/controller/spp.py              |  8 ++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/controller/shell_lib/common.py b/src/controller/shell_lib/common.py
index 360d601..3c59cca 100644
--- a/src/controller/shell_lib/common.py
+++ b/src/controller/shell_lib/common.py
@@ -100,3 +100,25 @@ def is_comment_line(line):
             return True
         else:
             return False
+
+
+def is_valid_ipv4_addr(ipaddr):
+    ip_nums = ipaddr.split('.')
+
+    if len(ip_nums) != 4:
+        return False
+
+    for num in ip_nums:
+        num = int(num)
+        if (num < 0) or (num > 255):
+            return False
+
+    return True
+
+
+def is_valid_port(port_num):
+    num = int(port_num)
+    if (num < 1023) or (num > 65535):
+        return False
+
+    return True
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 7b7316c..a74209b 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -7,6 +7,7 @@ from __future__ import absolute_import
 import argparse
 import re
 from .shell import Shell
+from .shell_lib import common
 from . import spp_ctl_client
 import sys
 
@@ -30,11 +31,14 @@ def main(argv):
     for addr in args.bind_addr:
         if ':' in addr:
             api_ipaddr, api_port = addr.split(':')
+            if common.is_valid_port(api_port) is False:
+                print('Error: Invalid port in "{}"'.format(addr))
+                exit()
         else:
             api_ipaddr = addr
 
-        if not re.match(r'\d*\.\d*\.\d*\.\d*', addr):
-            print('Invalid address "%s"' % args.bind_addr)
+        if common.is_valid_ipv4_addr(api_ipaddr) is False:
+            print('Error: Invalid address "{}"'.format(addr))
             exit()
 
         spp_ctl_cli = spp_ctl_client.SppCtlClient(api_ipaddr, int(api_port))
-- 
2.7.4

  reply	other threads:[~2019-01-25  3:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25  3:37 [spp] [PATCH 0/2] Add registering to server command ogawa.yasufumi
2019-01-25  3:37 ` ogawa.yasufumi [this message]
2019-01-25  3:37 ` [spp] [PATCH 2/2] controller: add " ogawa.yasufumi

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=1548387451-29818-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.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 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).