1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00
Sam Tannous d3ad131ee8 Make ifupdown2 print meaningful error when interface name length exceeds 15 characters
Ticket: CM-5882
Reviewed By: gospo
Testing Done: unit tested

When a user enters an interface name longer than 15 characters,
the error message is not clear about what the problem is.

   warning: netlink: Numerical result out of range <<<<<<<<<<<<<<<<

This patch catches the error before netlink gets the call and
prints

    error: the following interface names are too long: bond-xconnect.1006
2015-07-02 17:10:04 -04:00

61 lines
1.7 KiB
Python

#!/usr/bin/python
#
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
#
# utils --
# helper class
#
import os
import fcntl
import re
class utils():
@classmethod
def importName(cls, modulename, name):
""" Import a named object """
try:
module = __import__(modulename, globals(), locals(), [name])
except ImportError:
return None
return getattr(module, name)
@classmethod
def lockFile(cls, lockfile):
try:
fp = os.open(lockfile, os.O_CREAT | os.O_TRUNC | os.O_WRONLY)
fcntl.flock(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
return False
return True
@classmethod
def parse_iface_range(cls, name):
range_match = re.match("^([\w\.]+)\[([\d]+)-([\d]+)\]", name)
if range_match:
range_groups = range_match.groups()
if range_groups[1] and range_groups[2]:
return (range_groups[0], int(range_groups[1], 10),
int(range_groups[2], 10))
return None
@classmethod
def expand_iface_range(cls, name):
ifacenames = []
iface_range = cls.parse_iface_range(name)
if iface_range:
for i in range(iface_range[1], iface_range[2]):
ifacenames.append('%s-%d' %(iface_range[0], i))
return ifacenames
@classmethod
def check_ifname_size_invalid(cls, name=''):
""" IFNAMSIZ in include/linux/if.h is 16 so we check this """
IFNAMSIZ = 16
if len(name) > IFNAMSIZ - 1:
return True
else:
return False