| 480 | } |
| 481 | |
| 482 | int check_udp_proxy_protocol(char **buf, int *size, struct receive_info *ri) |
| 483 | { |
| 484 | char *p, *msg; |
| 485 | int len; |
| 486 | |
| 487 | if (!buf || !*buf || !size || !ri) |
| 488 | return -1; |
| 489 | |
| 490 | ri->real_ep.flags = PP_INIT; |
| 491 | |
| 492 | if (!ri->bind_address || (ri->bind_address->flags & SI_PROXY_IN) == 0) |
| 493 | return 1; |
| 494 | |
| 495 | msg = *buf; |
| 496 | len = *size; |
| 497 | |
| 498 | switch (is_net_proxy_protocol(msg, len)) { |
| 499 | case -1: |
| 500 | case 0: |
| 501 | return 1; |
| 502 | default: |
| 503 | break; |
| 504 | } |
| 505 | |
| 506 | p = parse_net_proxy_protocol(msg, len, &ri->real_ep); |
| 507 | if (!p) { |
| 508 | if (ri->real_ep.flags == PP_ERROR) { |
| 509 | LM_ERR("could not parse proxy_protocol header\n"); |
| 510 | } else { |
| 511 | LM_ERR("incomplete proxy_protocol header in UDP packet\n"); |
| 512 | } |
| 513 | return -1; |
| 514 | } |
| 515 | |
| 516 | if (ri->real_ep.flags == PP_OK) { |
| 517 | LM_DBG("message proxy_protocol %s:%hu -> %s:%hu\n", |
| 518 | ip_addr2a(&ri->real_ep.src_ip), ri->real_ep.src_port, |
| 519 | ip_addr2a(&ri->real_ep.dst_ip), ri->real_ep.dst_port); |
| 520 | } else { |
| 521 | LM_DBG("message proxy_protocol UNKNOWN\n"); |
| 522 | } |
| 523 | |
| 524 | *size -= p - msg; |
| 525 | *buf = p; |
| 526 | return 1; |
| 527 | } |
no test coverage detected