X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=blobdiff_plain;f=src%2Ffunctions%2Ffunctions.vlan;h=ee2fb3400062a62c49f35b49a73f5a4b563f3e1b;hp=9a70c95480e3a99609e3e7e5c66b0a729e5f411f;hb=fc1e91cca425c8e929df76dad4488066070879dd;hpb=f24529e498b1c3fe60196c34356e5b005a22ae4c diff --git a/src/functions/functions.vlan b/src/functions/functions.vlan index 9a70c954..ee2fb340 100644 --- a/src/functions/functions.vlan +++ b/src/functions/functions.vlan @@ -24,6 +24,23 @@ PROC_NET_VLAN_CONFIG="${PROC_NET_VLAN}/config" VLAN_PORT_INTERFIX="v" +vlan_valid_id() { + local id="${1}" + + # Must be an integer + if ! isinteger id; then + return ${EXIT_FALSE} + fi + + # Must be between 1 and 4095 + if [ ${id} -ge 1 ] && [ ${id} -le 4096 ]; then + return ${EXIT_TRUE} + fi + + # Otherwise this is invalid + return ${EXIT_FALSE} +} + vlan_create() { local device="${1}" shift @@ -31,7 +48,7 @@ vlan_create() { assert isset device local address - local id + local id=1 local parent # Parse command line arguments @@ -65,6 +82,12 @@ vlan_create() { return ${EXIT_ERROR} fi + # Check VLAN ID + if ! vlan_valid_id "${id}"; then + log ERROR "Invalid VLAN ID: ${id}" + return ${EXIT_ERROR} + fi + # Check if a device with the name does already exist if device_exists "${device}"; then log ERROR "Device '${device}' already exists"