(key conntrack.Tuple, parsed pkt, p platform.Packet)
| 158 | } |
| 159 | |
| 160 | func (e *Engine) handleOutbound(key conntrack.Tuple, parsed pkt, p platform.Packet) { |
| 161 | switch { |
| 162 | case parsed.isSYNOnly(): |
| 163 | fake, sni, err := e.newFakeClientHello() |
| 164 | if err != nil { |
| 165 | e.warnf("build fake ClientHello: %v", err) |
| 166 | p.Verdict(platform.Accept) |
| 167 | return |
| 168 | } |
| 169 | conn := conntrack.New(key, fake) |
| 170 | conn.Mu.Lock() |
| 171 | conn.SynSeq = parsed.seqNum |
| 172 | conn.Stage = conntrack.StageSynSent |
| 173 | conn.Mu.Unlock() |
| 174 | |
| 175 | fs := &flowState{ |
| 176 | sni: sni, |
| 177 | strategy: e.rnd.PickStrategy(e.cfg.Strategy), |
| 178 | delta: e.rnd.IPIDDelta(), |
| 179 | } |
| 180 | e.flows.Store(key, fs) |
| 181 | |
| 182 | if !e.table.Add(conn) { |
| 183 | if existing, ok := e.table.Get(key); ok { |
| 184 | existing.Mu.Lock() |
| 185 | existing.SynSeq = parsed.seqNum |
| 186 | existing.Mu.Unlock() |
| 187 | } |
| 188 | } |
| 189 | p.Verdict(platform.Accept) |
| 190 | return |
| 191 | |
| 192 | case parsed.isACKOnly() && !parsed.hasPayload(): |
| 193 | conn, ok := e.table.Get(key) |
| 194 | if !ok { |
| 195 | p.Verdict(platform.Accept) |
| 196 | return |
| 197 | } |
| 198 | conn.Mu.Lock() |
| 199 | doInject := conn.Stage == conntrack.StageSynAckSeen |
| 200 | if doInject { |
| 201 | conn.Stage = conntrack.StageAckSent |
| 202 | } |
| 203 | synSeq := conn.SynSeq |
| 204 | fakeData := conn.FakePayload |
| 205 | conn.Mu.Unlock() |
| 206 | |
| 207 | p.Verdict(platform.Accept) |
| 208 | |
| 209 | if doInject { |
| 210 | fsAny, ok := e.flows.Load(key) |
| 211 | if !ok { |
| 212 | // Defensive: the flow entry should always exist because we |
| 213 | // stored it on the SYN before allowing the handshake to |
| 214 | // progress, but if it does not, skip injection rather than |
| 215 | // panic. We intentionally do NOT Finish the conn here because |
| 216 | // the handshake itself is still valid — the user just loses |
| 217 | // bypass for this one flow. |
no test coverage detected