Skip to content

Add --net-fd flag for external networking#1205

Open
fkorotkov wants to merge 1 commit intomainfrom
codex/netfile-flag
Open

Add --net-fd flag for external networking#1205
fkorotkov wants to merge 1 commit intomainfrom
codex/netfile-flag

Conversation

@fkorotkov
Copy link
Contributor

Summary

  • add a hidden --net-fd option to tart run, validate mutual exclusion with other network flags, and pull in a NetworkFD implementation when present
  • implement NetworkFD to validate a connected datagram socket FD, provide the VZFileHandleNetworkDeviceAttachment, and keep run/stop as no-ops
  • document the advanced usage for externally managed networking and cover new flag validation plus NetworkFD behavior with tests

Testing

  • Not run (not requested)

@fkorotkov fkorotkov requested a review from edigaryev as a code owner February 25, 2026 14:17
[Softnet](https://github.com/cirruslabs/softnet) (via `tart run --net-softnet <VM NAME>)`, then the network isolation
is stricter and it's not possible to access the host.

## Using externally managed networking (`--net-fd`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the --net-fd option is hidden for now, what do you think about entirely skipping the FAQ entry for it too?

init(fd: Int32) throws {
self.fd = fd

try Self.validateFD(fd)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since getsockopt(2) used in validateSocketType() already returns ENOTSOCK, do you think we can just drop validateFD(fd) for simplicity's sake?

import XCTest
@testable import tart

final class RunNetworkValidationTests: XCTestCase {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this test suite is useful in the long-run?


if getsockopt(fd, SOL_SOCKET, SO_TYPE, &socketType, &optionLength) == -1 {
throw RuntimeError.VMConfigurationError(
"invalid --net-fd \(fd): file descriptor must reference a socket (\(errnoDescription(errno)))"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getsockopt(2) may return an error for other reasons than just ENOTSOCK.

The easiest fix is to probably return an error as is, without adding our very specific explanation.

}

private static func errnoDescription(_ code: CInt) -> String {
String(cString: strerror(code))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this any better than simply using Errno(rawValue: CInt(errno)) directly after system error, the approach which we already use in the rest of the codebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants