Fix namespacing

This commit is contained in:
Scott Yeager 2025-06-20 19:51:10 -07:00
parent 88ad00ae93
commit 9bdaf13797

37
main.go
View File

@ -216,26 +216,47 @@ func configureContainerInterface(containerNS netns.NsHandle, ifName string, cont
return err
}
// Get host veth link-local address for routing
// Switch to main namespace to get host veth address
if err := netns.Set(originalNS); err != nil {
return err
}
// Get host veth link-local address
hostVeth, err := netlink.LinkByName(hostVethName)
if err == nil {
if err != nil {
return err
}
hostAddrs, err := netlink.AddrList(hostVeth, netlink.FAMILY_V6)
if err == nil {
if err != nil {
return err
}
var hostLLAddr net.IP
for _, addr := range hostAddrs {
if addr.IP.IsLinkLocalUnicast() {
hostLLAddr = addr.IP
break
}
}
// Switch back to container namespace to add route
if err := netns.Set(containerNS); err != nil {
return err
}
if hostLLAddr != nil {
// Add route to Mycelium network via host veth
route := &netlink.Route{
Dst: &net.IPNet{
IP: net.ParseIP("400::"),
Mask: net.CIDRMask(7, 128),
},
Gw: addr.IP,
Gw: hostLLAddr,
LinkIndex: link.Attrs().Index,
}
netlink.RouteAdd(route)
break
}
}
if err := netlink.RouteAdd(route); err != nil {
return err
}
}