From 201132d43ca816e9c3711bec3f9b0e85bc116efd Mon Sep 17 00:00:00 2001 From: wangshengjun Date: Thu, 14 Nov 2019 19:08:43 +0800 Subject: [PATCH] [config]: add the vid range check for creating vlan. (#634) Signed-off-by: wangshengjun --- config/main.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/config/main.py b/config/main.py index 98481e37b873..3f3fa63ebe90 100755 --- a/config/main.py +++ b/config/main.py @@ -835,11 +835,14 @@ def vlan(ctx, redis_unix_socket_path): @click.argument('vid', metavar='', required=True, type=int) @click.pass_context def add_vlan(ctx, vid): - db = ctx.obj['db'] - vlan = 'Vlan{}'.format(vid) - if len(db.get_entry('VLAN', vlan)) != 0: - ctx.fail("{} already exists".format(vlan)) - db.set_entry('VLAN', vlan, {'vlanid': vid}) + if vid >= 1 and vid <= 4094: + db = ctx.obj['db'] + vlan = 'Vlan{}'.format(vid) + if len(db.get_entry('VLAN', vlan)) != 0: + ctx.fail("{} already exists".format(vlan)) + db.set_entry('VLAN', vlan, {'vlanid': vid}) + else : + ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid)) @vlan.command('del') @click.argument('vid', metavar='', required=True, type=int)