Binding socket to an interface in Network Extension

When trying to bind a socket to the tunnel interface via

setsockopt(socket, IPPROTO_IP, IP_BOUND_IF, &ifindex, len)

Within the PacketTunnel itself despite this call succeeding the data is still routed through the default interface.

This is observed when includeAllNetworks is true. When it is false it seems to send it on both interfaces.

Is there something wrong with how I'm doing it?

Answered by DTS Engineer in 727421022

When trying to bind a socket to the tunnel interface … Within the PacketTunnel itself

This technique won’t work because NECP works hard to prevent VPN loops. AFAIK the only way to run a connection through the tunnel from within your packet tunnel provider is to create the connection using either:

  • createTCPConnectionThroughTunnel(to:enableTLS:tlsParameters:delegate:), for a TCP connection (docs)

  • createUDPSessionThroughTunnel(to:from:), for a UDP flow (docs)

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

When trying to bind a socket to the tunnel interface … Within the PacketTunnel itself

This technique won’t work because NECP works hard to prevent VPN loops. AFAIK the only way to run a connection through the tunnel from within your packet tunnel provider is to create the connection using either:

  • createTCPConnectionThroughTunnel(to:enableTLS:tlsParameters:delegate:), for a TCP connection (docs)

  • createUDPSessionThroughTunnel(to:from:), for a UDP flow (docs)

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

That makes sense, thank you very much

One thing to note is that createTCPConnectionThroughTunnel does not work when includeAllNetworks is enabled.

A previous post noted this issue as well see here

One thing to note is that createTCPConnectionThroughTunnel(…) does not work when includeAllNetworks is enabled.

Well, that’s annoying. IMO that’s eminently bugworthy. I don’t see a bug number on that other thread. Did you file a bug about this? If not, and this is causing you grief, I encourage you do so. And please post your bug number, just for the record.

A previous post noted this issue as well see here

You’re assuming I look at the threads that Matt is helping out on (-: I’m way too busy for that, alas )-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Binding socket to an interface in Network Extension
 
 
Q