Commit 60a471f6 authored by Martín Ferrari's avatar Martín Ferrari

Fix bug introduced by change in iproute single-line output.

parent a0056b9d
...@@ -422,40 +422,48 @@ def change_netns(iface, netns): ...@@ -422,40 +422,48 @@ def change_netns(iface, netns):
# Address handling # Address handling
def get_addr_data(): def get_addr_data():
ipdata = backticks([IP_PATH, "-o", "addr", "list"]) ipdata = backticks([IP_PATH, "addr", "list"])
byidx = {} byidx = {}
bynam = {} bynam = {}
current = None
for line in ipdata.split("\n"): for line in ipdata.split("\n"):
if line == "": if line == "":
continue continue
match = re.search(r'^(\d+):\s+(\S+?)(:?)\s+(.*)', line) match = re.search(r'^(\d+):\s+(\S+):', line)
if not match: if match:
raise RuntimeError("Invalid `ip' command output") # First line of output.
idx = int(match.group(1)) idx = int(match.group(1))
name = match.group(2) name = match.group(2)
if name not in bynam: current = name
if name in bynam:
raise RuntimeError("Invalid `ip' command output")
bynam[name] = byidx[idx] = [] bynam[name] = byidx[idx] = []
if match.group(3): # BBB: old iproute also shows link info continue
continue
bynam[name].append(_parse_ip_addr(match.group(4)))
return byidx, bynam
def _parse_ip_addr(line): if not current:
match = re.search(r'^inet ([0-9.]+)/(\d+)(?: brd ([0-9.]+))?', line) raise RuntimeError("Invalid `ip' command output")
if match != None:
return ipv4address( match = re.search(r'^\s*inet ([0-9.]+)/(\d+)(?: brd ([0-9.]+))?', line)
if match:
bynam[current].append(ipv4address(
address = match.group(1), address = match.group(1),
prefix_len = match.group(2), prefix_len = match.group(2),
broadcast = match.group(3)) broadcast = match.group(3)))
continue
match = re.search(r'^inet6 ([0-9a-f:]+)/(\d+)', line) match = re.search(r'^\s*inet6 ([0-9a-f:]+)/(\d+)', line)
if match != None: if match:
return ipv6address( bynam[current].append(ipv6address(
address = match.group(1), address = match.group(1),
prefix_len = match.group(2)) prefix_len = match.group(2)))
continue
# Extra info, ignored.
continue
raise RuntimeError("Problems parsing ip command output") return byidx, bynam
def add_addr(iface, address): def add_addr(iface, address):
ifname = _get_if_name(iface) ifname = _get_if_name(iface)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment