Skip to content

Commit 201132d

Browse files
wangshengjunlguohan
authored andcommitted
[config]: add the vid range check for creating vlan. (sonic-net#634)
Signed-off-by: wangshengjun <[email protected]>
1 parent fe4446a commit 201132d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

config/main.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,14 @@ def vlan(ctx, redis_unix_socket_path):
835835
@click.argument('vid', metavar='<vid>', required=True, type=int)
836836
@click.pass_context
837837
def add_vlan(ctx, vid):
838-
db = ctx.obj['db']
839-
vlan = 'Vlan{}'.format(vid)
840-
if len(db.get_entry('VLAN', vlan)) != 0:
841-
ctx.fail("{} already exists".format(vlan))
842-
db.set_entry('VLAN', vlan, {'vlanid': vid})
838+
if vid >= 1 and vid <= 4094:
839+
db = ctx.obj['db']
840+
vlan = 'Vlan{}'.format(vid)
841+
if len(db.get_entry('VLAN', vlan)) != 0:
842+
ctx.fail("{} already exists".format(vlan))
843+
db.set_entry('VLAN', vlan, {'vlanid': vid})
844+
else :
845+
ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))
843846

844847
@vlan.command('del')
845848
@click.argument('vid', metavar='<vid>', required=True, type=int)

0 commit comments

Comments
 (0)