| 548 | } |
| 549 | |
| 550 | int |
| 551 | ProxyProtocol::set_additional_data(std::string_view data) |
| 552 | { |
| 553 | uint16_t len = data.length(); |
| 554 | Dbg(dbg_ctl_proxyprotocol_v2, "Parsing %d byte additional data", len); |
| 555 | additional_data.assign(data); |
| 556 | |
| 557 | const char *p = additional_data.data(); |
| 558 | const char *end = p + len; |
| 559 | while (p != end) { |
| 560 | if (end - p < 3) { |
| 561 | // The size of a TLV entry must be 3 bytes or more |
| 562 | Dbg(dbg_ctl_proxyprotocol_v2, "Remaining data (%ld bytes) is not enough for a TLV field", end - p); |
| 563 | return -2; |
| 564 | } |
| 565 | |
| 566 | // Type |
| 567 | uint8_t type = *p; |
| 568 | p += 1; |
| 569 | |
| 570 | // Length |
| 571 | uint16_t length = ntohs(*reinterpret_cast<const uint16_t *>(p)); |
| 572 | p += 2; |
| 573 | |
| 574 | // Value |
| 575 | if (end - p < length) { |
| 576 | // Does not have enough data |
| 577 | Dbg(dbg_ctl_proxyprotocol_v2, "Remaining data (%ld bytes) is not enough for a TLV field (ID:%u LEN:%hu)", end - p, type, |
| 578 | length); |
| 579 | return -3; |
| 580 | } |
| 581 | Dbg(dbg_ctl_proxyprotocol, "TLV: ID=%u LEN=%hu", type, length); |
| 582 | tlv.emplace(type, std::string_view(p, length)); |
| 583 | p += length; |
| 584 | } |
| 585 | |
| 586 | return 0; |
| 587 | } |
no test coverage detected