Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/Containerization/LinuxContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,16 @@ extension LinuxContainer {
// For every interface asked for:
// 1. Add the address requested
// 2. Online the adapter
// 3. If a gateway IP address is present, add the default route.
// 3. For the first interface, add the default route
var defaultRouteSet = false
for (index, i) in self.interfaces.enumerated() {
let name = "eth\(index)"
self.logger?.debug("setting up interface \(name) with address \(i.ipv4Address)")
try await agent.addressAdd(name: name, ipv4Address: i.ipv4Address)
try await agent.up(name: name, mtu: i.mtu)
if defaultRouteSet {
continue
}
if let ipv4Gateway = i.ipv4Gateway {
if !i.ipv4Address.contains(ipv4Gateway) {
self.logger?.debug("gateway \(ipv4Gateway) is outside subnet \(i.ipv4Address), adding a route first")
Expand All @@ -606,6 +610,7 @@ extension LinuxContainer {
self.logger?.debug("no gateway for \(name)")
try await agent.routeAddDefault(name: name, ipv4Gateway: nil)
}
defaultRouteSet = true
}

// Setup /etc/resolv.conf and /etc/hosts if asked for.
Expand Down
7 changes: 6 additions & 1 deletion Sources/Containerization/LinuxPod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,16 @@ extension LinuxPod {
// For every interface asked for:
// 1. Add the address requested
// 2. Online the adapter
// 3. If a gateway IP address is present, add the default route.
// 3. For the first interface, add the default route
var defaultRouteSet = false
for (index, i) in self.interfaces.enumerated() {
let name = "eth\(index)"
self.logger?.debug("setting up interface \(name) with address \(i.ipv4Address)")
try await agent.addressAdd(name: name, ipv4Address: i.ipv4Address)
try await agent.up(name: name, mtu: i.mtu)
if defaultRouteSet {
continue
}
if let ipv4Gateway = i.ipv4Gateway {
if !i.ipv4Address.contains(ipv4Gateway) {
self.logger?.debug("gateway \(ipv4Gateway) is outside subnet \(i.ipv4Address), adding a route first")
Expand All @@ -460,6 +464,7 @@ extension LinuxPod {
self.logger?.debug("no gateway for \(name)")
try await agent.routeAddDefault(name: name, ipv4Gateway: nil)
}
defaultRouteSet = true
}

// Setup /etc/resolv.conf and /etc/hosts for each container.
Expand Down
Loading