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
5fab780a
Commit
5fab780a
authored
Sep 01, 2011
by
alina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small changes in tun/tap interface creation
parent
9b8ee6f2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
33 deletions
+13
-33
src/netns/interface.py
src/netns/interface.py
+4
-3
src/netns/iproute.py
src/netns/iproute.py
+7
-28
src/netns/node.py
src/netns/node.py
+2
-2
No files found.
src/netns/interface.py
View file @
5fab780a
...
...
@@ -235,7 +235,7 @@ class TapNodeInterface(NSInterface):
self
.
_fd
=
None
self
.
_slave
=
None
iface
=
netns
.
iproute
.
interface
(
name
=
self
.
_gen_if_name
())
iface
,
self
.
_fd
=
netns
.
iproute
.
create_tap
(
iface
,
use_pi
)
iface
,
self
.
_fd
=
netns
.
iproute
.
create_tap
(
iface
,
use_pi
=
use_pi
)
netns
.
iproute
.
change_netns
(
iface
.
name
,
node
.
pid
)
super
(
TapNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
...
...
@@ -256,13 +256,14 @@ class TunNodeInterface(NSInterface):
"""Class to create a tun interface inside a name space, it
can be connected to a Switch object with emulation of link
characteristics."""
def
__init__
(
self
,
node
):
def
__init__
(
self
,
node
,
use_pi
=
False
):
"""Create a new tap interface. 'node' is the name space in which this
interface should be put."""
self
.
_fd
=
None
self
.
_slave
=
None
iface
=
netns
.
iproute
.
interface
(
name
=
self
.
_gen_if_name
())
iface
,
self
.
_fd
=
netns
.
iproute
.
create_tun
(
iface
)
iface
,
self
.
_fd
=
netns
.
iproute
.
create_tap
(
iface
,
use_pi
=
use_pi
,
tun
=
True
)
netns
.
iproute
.
change_netns
(
iface
.
name
,
node
.
pid
)
super
(
TunNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
...
...
src/netns/iproute.py
View file @
5fab780a
...
...
@@ -901,15 +901,19 @@ def set_tc(iface, bandwidth = None, delay = None, delay_jitter = None,
for c in commands:
execute(c)
def create_tap(iface, use_pi = False):
"""Creates a tap device and returns the associated file descriptor"""
def create_tap(iface, use_pi = False
, tun = False
):
"""Creates a tap
/tun
device and returns the associated file descriptor"""
if isinstance(iface, str):
iface = interface(name = iface)
assert iface.name
IFF_TUN = 0x0001
IFF_TAP = 0x0002
IFF_NO_PI = 0x1000
TUNSETIFF = 0x400454ca
if tun:
mode = IFF_TUN
else:
mode = IFF_TAP
if not use_pi:
mode |= IFF_NO_PI
...
...
@@ -929,28 +933,3 @@ def create_tap(iface, use_pi = False):
interfaces = get_if_data()[1]
return interfaces[iface.name], fd
def create_tun(iface):
"""Creates a tun device and returns the associated file descriptor"""
if isinstance(iface, str):
iface = interface(name = iface)
assert iface.name
IFF_TUN = 0x0001
TUNSETIFF = 0x400454ca
mode = IFF_TUN
fd = os.open("/dev/net/tun", os.O_RDWR)
err = fcntl.ioctl(fd, TUNSETIFF, struct.pack("16sH", iface.name, mode))
if err < 0:
os.close(fd)
raise RuntimeError("Could not configure device %s" % iface.name)
try:
set_if(iface)
except:
os.close(fd)
raise
interfaces = get_if_data()[1]
return interfaces[iface.name], fd
src/netns/node.py
View file @
5fab780a
...
...
@@ -116,8 +116,8 @@ class Node(object):
setattr
(
i
,
k
,
v
)
return
i
def
add_tun
(
self
,
**
kwargs
):
i
=
netns
.
interface
.
TunNodeInterface
(
self
)
def
add_tun
(
self
,
use_pi
=
False
,
**
kwargs
):
i
=
netns
.
interface
.
TunNodeInterface
(
self
,
use_pi
)
for
k
,
v
in
kwargs
.
items
():
setattr
(
i
,
k
,
v
)
return
i
...
...
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