Skip to content

Commit

Permalink
Changes the IP range for the veth pair.
Browse files Browse the repository at this point in the history
Signed-off-by: Nino Kodabande <nkodabande@suse.com>
  • Loading branch information
Nino-K committed Sep 12, 2024
1 parent 17e8d39 commit 23474dc
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/go/networking/cmd/network/setup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ var (
)

const (
nsenter = "/usr/bin/nsenter"
unshare = "/usr/bin/unshare"
vsockHandshakePort = 6669
vsockDialPort = 6656
defaultTapDevice = "eth0"
defaultNSVeth = "veth-rd0"
rancherDesktopNSVeth = "veth-rd1"
defaultNamespacePID = 1
cidrOnes = 24
cidrBits = 32
nsenter = "/usr/bin/nsenter"
unshare = "/usr/bin/unshare"
vsockHandshakePort = 6669
vsockDialPort = 6656
defaultTapDevice = "eth0"
WSLVeth = "veth-rd-wsl"
WSLVethIP = "192.168.143.2"
namespaceVeth = "veth-rd-ns"
namespaceVethIP = "192.168.143.1"
defaultNamespacePID = 1
cidrOnes = 24
cidrBits = 32
)

func main() {
Expand Down Expand Up @@ -126,23 +128,23 @@ func main() {

err = createVethPair(defaultNamespacePID,
vmSwitchCmd.Process.Pid,
defaultNSVeth,
rancherDesktopNSVeth)
WSLVeth,
namespaceVeth)
if err != nil {
logrus.Fatalf("failed to create veth pair: %v", err)
}
defer cleanupVethLink(originNS)

if err := configureVethPair(rancherDesktopNSVeth, "192.168.1.2"); err != nil {
logrus.Fatalf("failed setting up veth: %s for rancher desktop namespace: %v", rancherDesktopNSVeth, err)
if err := configureVethPair(namespaceVeth, namespaceVethIP); err != nil {
logrus.Fatalf("failed setting up veth: %s for rancher desktop namespace: %v", namespaceVeth, err)
}

// switch back to the original namespace to configure veth0
if err := netns.Set(originNS); err != nil {
logrus.Fatalf("failed to switch back to original namespace: %v", err)
}
if err := configureVethPair(defaultNSVeth, "192.168.1.1"); err != nil {
logrus.Fatalf("failed setting up veth: %s for rancher desktop namespace: %v", rancherDesktopNSVeth, err)
if err := configureVethPair(WSLVeth, WSLVethIP); err != nil {
logrus.Fatalf("failed setting up veth: %s for rancher desktop namespace: %v", WSLVeth, err)
}

if err := originNS.Close(); err != nil {
Expand Down Expand Up @@ -237,9 +239,9 @@ func cleanupVethLink(originNS netns.NsHandle) {
// First, though, switch back to the default namespace if available.
// This would fail if we already switched to it (and closed the handle).
_ = netns.Set(originNS)
if link, err := netlink.LinkByName(defaultNSVeth); err == nil {
if link, err := netlink.LinkByName(WSLVeth); err == nil {
err = netlink.LinkDel(link)
logrus.Infof("tearing down link %s: %v", defaultNSVeth, err)
logrus.Infof("tearing down link %s: %v", WSLVeth, err)
}
}

Expand Down

0 comments on commit 23474dc

Please sign in to comment.