MCPcopy Create free account
hub / github.com/apache/trafficserver / set_additional_data

Method set_additional_data

src/iocore/net/ProxyProtocol.cc:550–587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

548}
549
550int
551ProxyProtocol::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}

Callers 2

proxy_protocol_v2_parseFunction · 0.80

Calls 4

emplaceMethod · 0.80
lengthMethod · 0.45
assignMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected