Skip to content

Commit b374bb7

Browse files
committed
set MTU default in Utility, remove MTU from network helper
1 parent 8c9ef87 commit b374bb7

8 files changed

Lines changed: 30 additions & 32 deletions

File tree

Sources/ContainerResource/Network/Attachment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct Attachment: Codable, Sendable {
3131
public let ipv6Address: CIDRv6?
3232
/// The MAC address associated with the attachment (optional).
3333
public let macAddress: MACAddress?
34-
/// The MTU for the network interface (optional). Defaults to 1280 if not specified.
34+
/// The MTU for the network interface.
3535
public let mtu: UInt32?
3636

3737
public init(

Sources/ContainerResource/Network/AttachmentConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public struct AttachmentOptions: Codable, Sendable {
3838
/// The MAC address associated with the attachment (optional).
3939
public let macAddress: MACAddress?
4040

41-
/// The MTU for the network interface (optional). Defaults to 1280 if not specified.
41+
/// The MTU for the network interface.
4242
public let mtu: UInt32?
4343

4444
public init(hostname: String, macAddress: MACAddress? = nil, mtu: UInt32? = nil) {

Sources/Services/ContainerAPIService/Client/Utility.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,16 @@ public struct Utility {
297297
// attach the first network using the fqdn, and the rest using just the container ID
298298
return try networks.enumerated().map { item in
299299
let macAddress = try item.element.macAddress.map { try MACAddress($0) }
300+
let mtu = item.element.mtu ?? 1280
300301
guard item.offset == 0 else {
301302
return AttachmentConfiguration(
302303
network: item.element.name,
303-
options: AttachmentOptions(hostname: containerId, macAddress: macAddress, mtu: item.element.mtu)
304+
options: AttachmentOptions(hostname: containerId, macAddress: macAddress, mtu: mtu)
304305
)
305306
}
306307
return AttachmentConfiguration(
307308
network: item.element.name,
308-
options: AttachmentOptions(hostname: fqdn ?? containerId, macAddress: macAddress, mtu: item.element.mtu)
309+
options: AttachmentOptions(hostname: fqdn ?? containerId, macAddress: macAddress, mtu: mtu)
309310
)
310311
}
311312
}
@@ -314,7 +315,7 @@ public struct Utility {
314315
guard let builtinNetworkId else {
315316
throw ContainerizationError(.invalidState, message: "builtin network is not present")
316317
}
317-
return [AttachmentConfiguration(network: builtinNetworkId, options: AttachmentOptions(hostname: fqdn ?? containerId, macAddress: nil))]
318+
return [AttachmentConfiguration(network: builtinNetworkId, options: AttachmentOptions(hostname: fqdn ?? containerId, macAddress: nil, mtu: 1280))]
318319
}
319320

320321
private static func getKernel(management: Flags.Management) async throws -> Kernel {

Sources/Services/ContainerAPIService/Server/Containers/ContainersService.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,28 @@ public actor ContainersService {
415415
let allocatedAttach = try await self.networksService?.allocate(
416416
id: n.network,
417417
hostname: n.options.hostname,
418-
macAddress: n.options.macAddress,
419-
mtu: n.options.mtu
418+
macAddress: n.options.macAddress
420419
)
421-
guard let allocatedAttach = allocatedAttach else {
420+
guard var allocatedAttach = allocatedAttach else {
422421
throw ContainerizationError(.internalError, message: "failed to allocate a network")
423422
}
423+
424+
if let mtu = n.options.mtu {
425+
let a = allocatedAttach.attachment
426+
allocatedAttach = AllocatedAttachment(
427+
attachment: Attachment(
428+
network: a.network,
429+
hostname: a.hostname,
430+
ipv4Address: a.ipv4Address,
431+
ipv4Gateway: a.ipv4Gateway,
432+
ipv6Address: a.ipv6Address,
433+
macAddress: a.macAddress,
434+
mtu: mtu
435+
),
436+
additionalData: allocatedAttach.additionalData,
437+
pluginInfo: allocatedAttach.pluginInfo
438+
)
439+
}
424440
allocatedAttachments.append(allocatedAttach)
425441
}
426442

Sources/Services/ContainerAPIService/Server/Networks/NetworksService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ public actor NetworksService {
351351
}
352352
}
353353

354-
public func allocate(id: String, hostname: String, macAddress: MACAddress?, mtu: UInt32?) async throws -> AllocatedAttachment {
354+
public func allocate(id: String, hostname: String, macAddress: MACAddress?) async throws -> AllocatedAttachment {
355355
guard let serviceState = serviceStates[id] else {
356356
throw ContainerizationError(.notFound, message: "no network for id \(id)")
357357
}
358358
guard let pluginInfo = serviceState.networkState.pluginInfo else {
359359
throw ContainerizationError(.internalError, message: "network \(id) missing plugin information")
360360
}
361-
let (attach, additionalData) = try await serviceState.client.allocate(hostname: hostname, macAddress: macAddress, mtu: mtu)
361+
let (attach, additionalData) = try await serviceState.client.allocate(hostname: hostname, macAddress: macAddress)
362362
return AllocatedAttachment(
363363
attachment: attach,
364364
additionalData: additionalData,

Sources/Services/ContainerNetworkService/Client/NetworkClient.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,13 @@ extension NetworkClient {
5555

5656
public func allocate(
5757
hostname: String,
58-
macAddress: MACAddress? = nil,
59-
mtu: UInt32? = nil
58+
macAddress: MACAddress? = nil
6059
) async throws -> (attachment: Attachment, additionalData: XPCMessage?) {
6160
let request = XPCMessage(route: NetworkRoutes.allocate.rawValue)
6261
request.set(key: NetworkKeys.hostname.rawValue, value: hostname)
6362
if let macAddress = macAddress {
6463
request.set(key: NetworkKeys.macAddress.rawValue, value: macAddress.description)
6564
}
66-
if let mtu = mtu {
67-
request.set(key: NetworkKeys.mtu.rawValue, value: String(mtu))
68-
}
6965

7066
let client = createClient()
7167

Sources/Services/ContainerNetworkService/Client/NetworkKeys.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public enum NetworkKeys: String {
2020
case attachment
2121
case hostname
2222
case macAddress
23-
case mtu
2423
case network
2524
case state
2625
}

Sources/Services/ContainerNetworkService/Server/NetworkService.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public actor NetworkService: Sendable {
2727
private let log: Logger
2828
private var allocator: AttachmentAllocator
2929
private var macAddresses: [UInt32: MACAddress]
30-
private var mtus: [UInt32: UInt32]
3130

3231
/// Set up a network service for the specified network.
3332
public init(
@@ -44,7 +43,6 @@ public actor NetworkService: Sendable {
4443
let size = Int(subnet.upper.value - subnet.lower.value - 3)
4544
self.allocator = try AttachmentAllocator(lower: subnet.lower.value + 2, size: size)
4645
self.macAddresses = [:]
47-
self.mtus = [:]
4846
self.network = network
4947
self.log = log
5048
}
@@ -72,12 +70,6 @@ public actor NetworkService: Sendable {
7270
try message.string(key: NetworkKeys.macAddress.rawValue)
7371
.map { try MACAddress($0) }
7472
?? MACAddress((UInt64.random(in: 0...UInt64.max) & 0x0cff_ffff_ffff) | 0xf200_0000_0000)
75-
let mtu = try message.string(key: NetworkKeys.mtu.rawValue).map {
76-
guard let value = UInt32($0), value > 0 else {
77-
throw ContainerizationError(.invalidArgument, message: "invalid mtu value: \($0)")
78-
}
79-
return value
80-
}
8173
let index = try await allocator.allocate(hostname: hostname)
8274
let ipv6Address = try status.ipv6Subnet
8375
.map { try CIDRv6(macAddress.ipv6Address(network: $0.lower), prefix: $0.prefix) }
@@ -88,8 +80,7 @@ public actor NetworkService: Sendable {
8880
ipv4Address: try CIDRv4(ip, prefix: status.ipv4Subnet.prefix),
8981
ipv4Gateway: status.ipv4Gateway,
9082
ipv6Address: ipv6Address,
91-
macAddress: macAddress,
92-
mtu: mtu
83+
macAddress: macAddress
9384
)
9485
log.info(
9586
"allocated attachment",
@@ -108,9 +99,6 @@ public actor NetworkService: Sendable {
10899
}
109100
}
110101
macAddresses[index] = macAddress
111-
if let mtu {
112-
mtus[index] = mtu
113-
}
114102
return reply
115103
}
116104

@@ -122,7 +110,6 @@ public actor NetworkService: Sendable {
122110
let hostname = try message.hostname()
123111
if let index = try await allocator.deallocate(hostname: hostname) {
124112
macAddresses.removeValue(forKey: index)
125-
mtus.removeValue(forKey: index)
126113
}
127114
log.info("released attachments", metadata: ["hostname": "\(hostname)"])
128115
return message.reply()
@@ -158,8 +145,7 @@ public actor NetworkService: Sendable {
158145
ipv4Address: ipv4Address,
159146
ipv4Gateway: status.ipv4Gateway,
160147
ipv6Address: ipv6Address,
161-
macAddress: macAddress,
162-
mtu: mtus[index]
148+
macAddress: macAddress
163149
)
164150
log.debug(
165151
"lookup attachment",

0 commit comments

Comments
 (0)