Skip to content

Commit d61de85

Browse files
committed
bessctl: take DNS names and IPs in daemon connect
`daemon connect` currently accpets `name` tokens for its HOST argument. `name` is overly restrictive, so this commit add a new token called `host` which matches DNS names and IPv4 addresses.
1 parent 78c6c00 commit d61de85

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

bessctl/commands.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def get_var_attrs(cli, var_token, partial_word):
386386
var_desc = 'bess daemon command-line options (see "bessd -h")'
387387

388388
elif var_token == '[HOST]':
389-
var_type = 'name'
389+
var_type = 'host'
390390
var_desc = 'host address'
391391

392392
elif var_token == '[TCP_PORT]':
@@ -418,7 +418,8 @@ def get_var_attrs(cli, var_token, partial_word):
418418
# tail: the rest of input line
419419
# You can assume that 'line == head + tail'
420420
def split_var(cli, var_type, line):
421-
if var_type in ['name', 'optional_name', 'gate', 'confname', 'filename',
421+
if var_type in [
422+
'host', 'name', 'optional_name', 'gate', 'confname', 'filename',
422423
'endis', 'int', 'socket', 'pause_workers', 'dir']:
423424
pos = line.find(' ')
424425
if pos == -1:
@@ -476,6 +477,13 @@ def bind_var(cli, var_type, line):
476477
raise cli.BindError('"wid" must be a positive number')
477478
val = sorted(list(set(val)))
478479

480+
elif var_type == 'host':
481+
dns = re.match(r'^[a-zA-Z0-9][a-zA-Z0-9\-.]*$', val)
482+
ip = re.match(r'^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$', val)
483+
if dns is None and ip is None:
484+
raise cli.BindError(
485+
'"host" must be a valid DNS name or IPv4 address')
486+
479487
elif var_type == 'name':
480488
if re.match(r'^[_a-zA-Z][\w]*$', val) is None:
481489
raise cli.BindError('"name" must be [_a-zA-Z][_a-zA-Z0-9]*')

0 commit comments

Comments
 (0)