| 425 | } |
| 426 | |
| 427 | int check_tcp_proxy_protocol(struct tcp_connection *c) |
| 428 | { |
| 429 | static char pp_buf[PROXY_PROTOCOL_BUF_MAX]; |
| 430 | char *p; |
| 431 | int len; |
| 432 | |
| 433 | if (c->flags & F_CONN_DATA_READY) |
| 434 | return 1; |
| 435 | |
| 436 | if (!c->rcv.bind_address || |
| 437 | (c->rcv.bind_address->flags & SI_PROXY_IN) == 0) { |
| 438 | c->flags |= F_CONN_DATA_READY; |
| 439 | return 1; |
| 440 | } |
| 441 | |
| 442 | len = tcp_peek(c, pp_buf, PROXY_PROTOCOL_BUF_MAX); |
| 443 | if (len < 0) |
| 444 | return -1; |
| 445 | |
| 446 | switch (is_net_proxy_protocol(pp_buf, len)) { |
| 447 | case -1: |
| 448 | return 0; |
| 449 | case 0: |
| 450 | c->flags |= F_CONN_DATA_READY; |
| 451 | return 1; |
| 452 | default: |
| 453 | /* parse proxy_protocol fields */ |
| 454 | break; |
| 455 | } |
| 456 | |
| 457 | p = parse_net_proxy_protocol(pp_buf, len, &c->rcv.real_ep); |
| 458 | if (!p) { |
| 459 | if (c->rcv.real_ep.flags == PP_ERROR) { |
| 460 | LM_ERR("could not parse proxy_protocol header\n"); |
| 461 | return -1; |
| 462 | } |
| 463 | return 0; |
| 464 | } |
| 465 | if (c->rcv.real_ep.flags == PP_OK) { |
| 466 | LM_DBG("message proxy_protocol %s:%hu -> %s:%hu\n", |
| 467 | ip_addr2a(&c->rcv.real_ep.src_ip), c->rcv.real_ep.src_port, |
| 468 | ip_addr2a(&c->rcv.real_ep.dst_ip), c->rcv.real_ep.dst_port); |
| 469 | } else { |
| 470 | LM_DBG("message proxy_protocol UNKNOWN\n"); |
| 471 | } |
| 472 | |
| 473 | if (tcp_drain(c, pp_buf, p - pp_buf) < 0) { |
| 474 | LM_ERR("could not consume PROXY header\n"); |
| 475 | return -1; |
| 476 | } |
| 477 | |
| 478 | c->flags |= F_CONN_DATA_READY; |
| 479 | return 1; |
| 480 | } |
| 481 | |
| 482 | int check_udp_proxy_protocol(char **buf, int *size, struct receive_info *ri) |
| 483 | { |
no test coverage detected