@miconda I would mainly love some pointers as to how/where to implement this.

My initial thought was to modify `handle_new_connect()` to change the 
connection state to `S_CONN_OK` instead of `S_CONN_ACCEPT`, and then peek the 
connection to see if we are getting a PROXY v1/v2 header, and the override the 
connection information structs. However, this obviously runs amuck of clean 
code, and obviously might wait a long time if the header isn't sent immediately.

Would it, instead, make more sense to attempt to parse it in a fashion not 
unlike the `tcp_read_hep3`/`tcp_header_headers` combination in `tcp_read.c` 
around line 1490:

```c
if(unlikely(ksr_tcp_accept_hep3!=0)) {
  bytes=tcp_read_hep3(con, read_flags);
  if (bytes>=0) {
    if(!(con->req.flags & F_TCP_REQ_HEP3)) {
      /* not hep3, try to read headers */
      bytes=tcp_read_headers(con, read_flags);
    }
  }
} else {
  bytes=tcp_read_headers(con, read_flags);
}
```

So for example:

```c
if(unlikely(ksr_tcp_accept_hep3!=0)) {
  bytes=tcp_read_hep3(con, read_flags);
  if (bytes>=0) {
    if(!(con->req.flags & F_TCP_REQ_HEP3)) {
      /* not hep3, try to read headers */
      goto read_headers
    }
  }
} else {
read_headers:
  if (unlikely(read_proxy_protocol!=0)) {
    tcp_read_proxy_protocol(con, read_flags);
  }
  bytes=tcp_read_headers(con, read_flags);
}
```

Obviously, the above is just imaginary pseudocode. Thoughts?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1757#issuecomment-444910587
_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to