@@ -19,10 +19,12 @@ const (
1919
2020// Request and Response are encoded as JSON with uint32le length header.
2121type Request struct {
22- Type string // "init" or "connect"
23- Proto string // "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"
24- IP string
25- Port int
22+ Type string // "init" or "connect"
23+ Proto string // "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"
24+ IP string
25+ Port int
26+ ParentIP string
27+ HostGatewayIP string
2628}
2729
2830// Reply may contain FD as OOB
@@ -48,14 +50,33 @@ func Initiate(c *net.UnixConn) error {
4850 return c .CloseRead ()
4951}
5052
53+ func hostGatewayIP () string {
54+ addrs , err := net .InterfaceAddrs ()
55+ if err != nil {
56+ return ""
57+ }
58+
59+ for _ , addr := range addrs {
60+ if ipnet , ok := addr .(* net.IPNet ); ok && ! ipnet .IP .IsLoopback () {
61+ if ipnet .IP .To4 () != nil {
62+ return ipnet .IP .String ()
63+ }
64+ }
65+ }
66+
67+ return ""
68+ }
69+
5170// ConnectToChild connects to the child UNIX socket, and obtains TCP or UDP socket FD
5271// that corresponds to the port spec.
5372func ConnectToChild (c * net.UnixConn , spec port.Spec ) (int , error ) {
5473 req := Request {
55- Type : RequestTypeConnect ,
56- Proto : spec .Proto ,
57- Port : spec .ChildPort ,
58- IP : spec .ChildIP ,
74+ Type : RequestTypeConnect ,
75+ Proto : spec .Proto ,
76+ Port : spec .ChildPort ,
77+ IP : spec .ChildIP ,
78+ ParentIP : spec .ParentIP ,
79+ HostGatewayIP : hostGatewayIP (),
5980 }
6081 if _ , err := lowlevelmsgutil .MarshalToWriter (c , & req ); err != nil {
6182 return 0 , err
0 commit comments