Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
60a471f6
Commit
60a471f6
authored
Nov 03, 2013
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug introduced by change in iproute single-line output.
parent
a0056b9d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
21 deletions
+29
-21
src/nemu/iproute.py
src/nemu/iproute.py
+29
-21
No files found.
src/nemu/iproute.py
View file @
60a471f6
...
...
@@ -422,40 +422,48 @@ def change_netns(iface, netns):
# Address handling
def
get_addr_data
():
ipdata
=
backticks
([
IP_PATH
,
"
-o"
,
"
addr"
,
"list"
])
ipdata
=
backticks
([
IP_PATH
,
"addr"
,
"list"
])
byidx
=
{}
bynam
=
{}
current
=
None
for
line
in
ipdata
.
split
(
"
\
n
"
):
if
line
==
""
:
continue
match
=
re
.
search
(
r'^(\
d+):
\s+(\
S+?)(:?)
\s+(.*)'
,
line
)
if
not
match
:
raise
RuntimeError
(
"Invalid `ip' command output"
)
idx
=
int
(
match
.
group
(
1
))
name
=
match
.
group
(
2
)
if
name
not
in
bynam
:
match
=
re
.
search
(
r'^(\
d+):
\s+(\
S+):
', line)
if match:
# First line of output.
idx = int(match.group(1))
name = match.group(2)
current = name
if name in bynam:
raise RuntimeError("Invalid `ip'
command
output
")
bynam[name] = byidx[idx] = []
if
match
.
group
(
3
):
# BBB: old iproute also shows link info
continue
bynam
[
name
].
append
(
_parse_ip_addr
(
match
.
group
(
4
)))
return
byidx
,
bynam
continue
def
_parse_ip_addr
(
line
):
match
=
re
.
search
(
r'^inet ([0-9.]+)/(\
d+)(?:
brd ([0-9.]+))?'
,
line
)
if
match
!=
None
:
return
ipv4address
(
if not current:
raise RuntimeError("
Invalid
`
ip
' command output")
match = re.search(r'
^
\
s
*
inet
([
0
-
9.
]
+
)
/
(
\
d
+
)(
?
:
brd
([
0
-
9.
]
+
))
?
', line)
if match:
bynam[current].append(ipv4address(
address = match.group(1),
prefix_len = match.group(2),
broadcast
=
match
.
group
(
3
))
broadcast = match.group(3)))
continue
match
=
re
.
search
(
r'^
inet6 ([0-9a-f:]+)/(\
d+)
', line)
if match != None
:
return
ipv6address(
match = re.search(r'
^
\
s
*
inet6
([
0
-
9
a
-
f
:]
+
)
/
(
\
d
+
)
', line)
if match
:
bynam[current].append(
ipv6address(
address = match.group(1),
prefix_len = match.group(2))
prefix_len = match.group(2)))
continue
# Extra info, ignored.
continue
r
aise RuntimeError("Problems parsing ip command output")
r
eturn byidx, bynam
def add_addr(iface, address):
ifname = _get_if_name(iface)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment