-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* speedtest: move source bound Dialer setup to newDialerAddressBound(). * Add "--interface" option.
- Loading branch information
1 parent
6103965
commit 11183cb
Showing
7 changed files
with
124 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package speedtest | ||
|
||
import ( | ||
"net" | ||
"syscall" | ||
"time" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func newDialerInterfaceBound(iface string) (dialer *net.Dialer, err error) { | ||
// In linux there is the socket option SO_BINDTODEVICE. | ||
// Therefore we can really bind the socket to the device instead of binding to the address that | ||
// would be affected by the default routes. | ||
control := func(network, address string, c syscall.RawConn) error { | ||
var errSock error | ||
err := c.Control((func(fd uintptr) { | ||
errSock = unix.BindToDevice(int(fd), iface) | ||
})) | ||
if err != nil { | ||
return err | ||
} | ||
return errSock | ||
} | ||
|
||
dialer = &net.Dialer{ | ||
Timeout: 30 * time.Second, | ||
KeepAlive: 30 * time.Second, | ||
Control: control, | ||
} | ||
return dialer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package speedtest | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
func newDialerInterfaceBound(iface string) (dialer *net.Dialer, err error) { | ||
return nil, fmt.Errorf("cannot bound to interface on Windows") | ||
} |