LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2018, 01:14 AM   #1
canndrew
LQ Newbie
 
Registered: Nov 2016
Posts: 9

Rep: Reputation: Disabled
Question about network namespace and virtual interface APIs...


In a program I'm writing I have a network namespace with a virtual (TAP) network interface assigned to it. I would like it so that the interface is automatically destroyed when the namespace is destroyed (ie. when the last process in the namespace exits). I can't see any way to implement this..

I believe (although I can't find the relevant documentation right now) that when a namespace is destroyed all its interfaces are moved to the root namespace. If this is the case, is there anyway to detect when a namespace is moved so that I can close it manually? Alternatively, is there a way to detect when a namespace is destroyed? How about just when a process exits? Basically I'm looking for any event the Linux kernel can give me that I can use to implement what I want.

The only way I can see of doing this is using inotify on the one of the directories under /proc or /sys, but that seems really hacky and racy. Does linuxquestions have any better ideas?
 
Old 02-24-2018, 11:53 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I have not written any network namespace aware programs, but as no one else has stepped up I'll try to get things moving for you.

First off, when asking programming questions it is always helpful to others to mention the language you are using, and the OS and/or distro you are working with. Different languages will have differing support functions and libs available which will affect the replies you may receive - especially true of networking applications. Early on, different distros offered differing support for network namespaces, or none at all, but I am not sure how that may have changed in the past few years.

Looking for online help I found plenty of resources available, some of which may surely have the answer you want. One of the best I think after a quick browse was thie OpenStack article: Network Namespaces. Use your search engine of choice to find others.

Finally, if you do not receive useful replies in the Programming forum, you might want to have your question moved to the Netowrking forum. If you want to have it moved simply click the Report button at bottom of your post and ask a moderator to do that for you.

Good luck!
 
  


Reply

Tags
containers, programming, tap, tun



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setting up virtual network interface Alfwro13 SUSE / openSUSE 9 07-23-2018 04:50 AM
Virtual network interface for USB modem fandar Linux - Networking 2 02-21-2013 10:02 AM
[OpenSUSE 10.3] virtual network interface noir911 Linux - Server 3 10-23-2008 03:26 AM
Activating a virtual network interface bolek Programming 1 02-06-2008 09:50 PM
Activating a virtual network interface bolek Linux - Networking 1 02-05-2008 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration