Skip to content

Commit b0149a0

Browse files
committed
network: Use newFileHandleDupFd in newVZFileHandleNetworkDeviceAttachment
NewFileHandleNetworkDeviceAttachment has similar limitations as NewDiskBlockDeviceStorageDeviceAttachment. This commit fixes this by using newFileHandleDupFd to implement it. Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
1 parent 30674fc commit b0149a0

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

network.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,20 @@ func NewFileHandleNetworkDeviceAttachment(file *os.File) (*FileHandleNetworkDevi
192192
return nil, err
193193
}
194194

195+
nserrPtr := newNSErrorAsNil()
196+
195197
attachment := &FileHandleNetworkDeviceAttachment{
196198
pointer: objc.NewPointer(
197199
C.newVZFileHandleNetworkDeviceAttachment(
198200
C.int(file.Fd()),
201+
&nserrPtr,
199202
),
200203
),
201204
mtu: 1500, // The default MTU is 1500.
202205
}
206+
if err := newNSError(nserrPtr); err != nil {
207+
return nil, err
208+
}
203209
objc.SetFinalizer(attachment, func(self *FileHandleNetworkDeviceAttachment) {
204210
objc.Release(self)
205211
})

virtualization_11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const char *VZBridgedNetworkInterface_identifier(void *networkInterface);
9494
const char *VZBridgedNetworkInterface_localizedDisplayName(void *networkInterface);
9595
void *newVZBridgedNetworkDeviceAttachment(void *networkInterface);
9696
void *newVZNATNetworkDeviceAttachment(void);
97-
void *newVZFileHandleNetworkDeviceAttachment(int fileDescriptor);
97+
void *newVZFileHandleNetworkDeviceAttachment(int fileDescriptor, void **error);
9898
void *newVZVirtioNetworkDeviceConfiguration(void *attachment);
9999
void setNetworkDevicesVZMACAddress(void *config, void *macAddress);
100100
void *newVZVirtioEntropyDeviceConfiguration(void);

virtualization_11.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,15 @@ void setStorageDevicesVZVirtualMachineConfiguration(void *config,
602602
@see VZNetworkDeviceConfiguration
603603
@see VZVirtioNetworkDeviceConfiguration
604604
*/
605-
void *newVZFileHandleNetworkDeviceAttachment(int fileDescriptor)
605+
void *newVZFileHandleNetworkDeviceAttachment(int fileDescriptor, void **error)
606606
{
607607
if (@available(macOS 11, *)) {
608608
VZFileHandleNetworkDeviceAttachment *ret;
609609
@autoreleasepool {
610-
NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileDescriptor];
610+
NSFileHandle *fileHandle = newFileHandleDupFd(fileDescriptor, error);
611+
if (fileHandle == nil) {
612+
return nil;
613+
}
611614
ret = [[VZFileHandleNetworkDeviceAttachment alloc] initWithFileHandle:fileHandle];
612615
}
613616
return ret;

0 commit comments

Comments
 (0)