f-15: fix: error in netns creation

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-02 23:49:48 +02:00
commit 74d7fc1425
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632

View file

@ -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,