()
| 136 | } |
| 137 | |
| 138 | func (p *proxy) start() { |
| 139 | if p.process == nil || p.external == nil { |
| 140 | slog.Error("TCP proxy missing connection", "proxy", p) |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | // TODO: should we match the tracee's TCP options on the external side? |
| 145 | |
| 146 | // There's no need for Nagle's algorithm on the process side since it's a |
| 147 | // loopback connection. |
| 148 | if err := p.process.SetNoDelay(true); err != nil { |
| 149 | slog.Debug("failed to set TCP_NODELAY on process side", "proxy", p, "err", err) // not fatal |
| 150 | } |
| 151 | |
| 152 | slog.Debug("starting tcp proxy", "proxy", p) |
| 153 | defer func() { |
| 154 | if err := p.Close(); err != nil { |
| 155 | slog.Debug("failed close tcp proxy", "proxy", p, "err", err) // not fatal |
| 156 | } |
| 157 | }() |
| 158 | |
| 159 | cli, srv := newBufConn(p.process), newBufConn(p.external) |
| 160 | if !p.isOutgoing { |
| 161 | cli, srv = srv, cli |
| 162 | } |
| 163 | |
| 164 | if err := p.proxyOptimistic(cli, srv); err != nil { |
| 165 | slog.Error("failed to run tcp proxy", "proxy", p, "err", err) |
| 166 | } |
| 167 | |
| 168 | if p.skipCloseTCP.CompareAndSwap(false, true) { |
| 169 | // The target program has still not called the close(2) syscall on its file |
| 170 | // descriptor. When it does, the (*Socket).Close() handler will close the |
| 171 | // two underlying TCP connections. See the equivalent CAS in socket.go for |
| 172 | // the process.Close() and external.Close() calls. |
| 173 | } else { |
| 174 | p.process.Close() |
| 175 | p.external.Close() |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | var isHTTP2Enabled = true |
| 180 | var isWebsocketEnabled = false |
nothing calls this directly
no test coverage detected