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
a77b99f3
Commit
a77b99f3
authored
Sep 01, 2011
by
alina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tun device interface added.
parent
f4d2c774
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
src/netns/interface.py
src/netns/interface.py
+27
-0
src/netns/iproute.py
src/netns/iproute.py
+25
-0
No files found.
src/netns/interface.py
View file @
a77b99f3
...
@@ -252,6 +252,33 @@ class TapNodeInterface(NSInterface):
...
@@ -252,6 +252,33 @@ class TapNodeInterface(NSInterface):
except
:
except
:
pass
pass
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
):
"""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
)
netns
.
iproute
.
change_netns
(
iface
.
name
,
node
.
pid
)
super
(
TunNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
@
property
def
fd
(
self
):
return
self
.
_fd
def
destroy
(
self
):
if
not
self
.
_fd
:
return
debug
(
"TunNodeInterface(0x%x).destroy()"
%
id
(
self
))
try
:
os
.
close
(
self
.
_fd
)
except
:
pass
class
ExternalInterface
(
Interface
):
class
ExternalInterface
(
Interface
):
"""Add user-facing methods for interfaces that run in the main
"""Add user-facing methods for interfaces that run in the main
namespace."""
namespace."""
...
...
src/netns/iproute.py
View file @
a77b99f3
...
@@ -929,3 +929,28 @@ def create_tap(iface, use_pi = False):
...
@@ -929,3 +929,28 @@ def create_tap(iface, use_pi = False):
interfaces = get_if_data()[1]
interfaces = get_if_data()[1]
return interfaces[iface.name], fd
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
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