-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SO_BINDTODEVICE. Closes #6
- Loading branch information
1 parent
c685c43
commit 25613ab
Showing
5 changed files
with
126 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// +build !linux | ||
|
||
// servers_response.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
) | ||
|
||
/* | ||
Implements servers response of SOCKS5 for non Linux systems | ||
*/ | ||
func server_response(local_conn net.Conn, remote_address string) { | ||
load_balancer := get_load_balancer() | ||
|
||
local_tcpaddr, _ := net.ResolveTCPAddr("tcp4", load_balancer.address) | ||
remote_tcpaddr, _ := net.ResolveTCPAddr("tcp4", remote_address) | ||
remote_conn, err := net.DialTCP("tcp4", local_tcpaddr, remote_tcpaddr) | ||
|
||
if err != nil { | ||
log.Println("[WARN]", remote_address, "->", load_balancer.address, fmt.Sprintf("{%s}", err)) | ||
local_conn.Write([]byte{5, NETWORK_UNREACHABLE, 0, 1, 0, 0, 0, 0, 0, 0}) | ||
local_conn.Close() | ||
return | ||
} | ||
log.Println("[DEBUG]", remote_address, "->", load_balancer.address) | ||
local_conn.Write([]byte{5, SUCCESS, 0, 1, 0, 0, 0, 0, 0, 0}) | ||
pipe_connections(local_conn, remote_conn) | ||
} |
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,42 @@ | ||
// servers_response_linux.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"syscall" | ||
) | ||
|
||
/* | ||
Implements servers response of SOCKS5 for linux systems | ||
*/ | ||
func server_response(local_conn net.Conn, remote_address string) { | ||
load_balancer := get_load_balancer() | ||
local_tcpaddr, _ := net.ResolveTCPAddr("tcp4", load_balancer.address) | ||
|
||
dialer := net.Dialer{ | ||
LocalAddr: local_tcpaddr, | ||
Control: func(network, address string, c syscall.RawConn) error { | ||
return c.Control(func(fd uintptr) { | ||
// NOTE: Run with root or use setcap to allow interface binding | ||
// sudo setcap cap_net_raw=eip ./go-dispatch-proxy | ||
if err := syscall.BindToDevice(int(fd), load_balancer.iface); err != nil { | ||
log.Println("[WARN] Couldn't bind to interface", load_balancer.iface) | ||
} | ||
}) | ||
}, | ||
} | ||
|
||
remote_conn, err := dialer.Dial("tcp4", remote_address) | ||
if err != nil { | ||
log.Println("[WARN]", remote_address, "->", load_balancer.address, fmt.Sprintf("{%s}", err)) | ||
local_conn.Write([]byte{5, NETWORK_UNREACHABLE, 0, 1, 0, 0, 0, 0, 0, 0}) | ||
local_conn.Close() | ||
return | ||
} | ||
|
||
log.Println("[DEBUG]", remote_address, "->", load_balancer.address) | ||
local_conn.Write([]byte{5, SUCCESS, 0, 1, 0, 0, 0, 0, 0, 0}) | ||
pipe_connections(local_conn, remote_conn) | ||
} |
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