f-15: fix: error in netns creation
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
beed163b02
commit
74d7fc1425
1 changed files with 12 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
package netns
|
package netns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
|
@ -20,6 +21,12 @@ func create(name string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// si le fichier existe déjà, le démonter d'abord
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
unix.Unmount(path, unix.MNT_DETACH)
|
||||||
|
os.Remove(path)
|
||||||
|
}
|
||||||
|
|
||||||
// fichier cible
|
// fichier cible
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -39,9 +46,12 @@ func create(name string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind mount du netns courant vers /var/run/netns/<name>
|
// bind mount du netns du thread courant vers /var/run/netns/<name>
|
||||||
|
// /proc/self/ns/net pointe vers le ns du processus (thread principal),
|
||||||
|
// pas du thread courant — il faut utiliser le tid explicitement
|
||||||
|
threadNsPath := fmt.Sprintf("/proc/self/task/%d/ns/net", unix.Gettid())
|
||||||
if err := unix.Mount(
|
if err := unix.Mount(
|
||||||
"/proc/self/ns/net",
|
threadNsPath,
|
||||||
path,
|
path,
|
||||||
"",
|
"",
|
||||||
unix.MS_BIND,
|
unix.MS_BIND,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue