Reject sends a RST packet. It is only valid to call this once, when the stream state is SynReceived
()
| 202 | |
| 203 | // Reject sends a RST packet. It is only valid to call this once, when the stream state is SynReceived |
| 204 | func (s *tcpStream) Reject() { |
| 205 | // reply to the subprocess as if the connection were already good to go |
| 206 | replytcp := layers.TCP{ |
| 207 | SrcPort: layers.TCPPort(s.world.Port), |
| 208 | DstPort: layers.TCPPort(s.subprocess.Port), |
| 209 | RST: true, |
| 210 | ACK: true, |
| 211 | Seq: atomic.AddUint32(&s.seq, 1) - 1, |
| 212 | Ack: atomic.LoadUint32(&s.ack) + 1, |
| 213 | Window: 64240, // number of bytes we are willing to receive |
| 214 | } |
| 215 | |
| 216 | replyipv4 := layers.IPv4{ |
| 217 | Version: 4, // indicates IPv4 |
| 218 | TTL: ttl, |
| 219 | Protocol: layers.IPProtocolTCP, |
| 220 | SrcIP: s.world.Addr, |
| 221 | DstIP: s.subprocess.Addr, |
| 222 | } |
| 223 | |
| 224 | replytcp.SetNetworkLayerForChecksum(&replyipv4) |
| 225 | |
| 226 | // log |
| 227 | verbosef("sending RST to subprocess: %s", summarizeTCP(&replyipv4, &replytcp, nil)) |
| 228 | |
| 229 | // serialize the packet |
| 230 | serialized, err := serializeTCP(&replyipv4, &replytcp, nil, s.serializeBuf) |
| 231 | if err != nil { |
| 232 | errorf("error serializing reply TCP: %w, dropping", err) |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | // make a copy of the data |
| 237 | cp := make([]byte, len(serialized)) |
| 238 | copy(cp, serialized) |
| 239 | |
| 240 | // send to the channel that goes to the subprocess |
| 241 | select { |
| 242 | case s.toSubprocess <- cp: |
| 243 | default: |
| 244 | verbosef("channel for sending to subprocess would have blocked, dropping %d bytes", len(cp)) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Read reads packets sent by the subprocess and intercepted by us |
| 249 | func (s *tcpStream) Read(buf []byte) (int, error) { |
nothing calls this directly
no test coverage detected