Use packet_base() and extract headers using IOV_REMOVE_HEADER()
and iov_peek_header_() rather than packet_get().
Signed-off-by: Laurent Vivier
---
tcp.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/tcp.c b/tcp.c
index a4c840e6721c..790714a08793 100644
--- a/tcp.c
+++ b/tcp.c
@@ -310,6 +310,8 @@
#include "tcp_buf.h"
#include "tcp_vu.h"
+#define OPTLEN_MAX (((1UL << 4) - 6) * 4UL)
+
#ifndef __USE_MISC
/* From Linux UAPI, missing in netinet/tcp.h provided by musl */
struct tcp_repair_opt {
@@ -1957,7 +1959,10 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
{
struct tcp_tap_conn *conn;
const struct tcphdr *th;
+ char optsc[OPTLEN_MAX];
+ struct iov_tail data;
size_t optlen, len;
+ struct tcphdr thc;
const char *opts;
union flow *flow;
flow_sidx_t sidx;
@@ -1966,15 +1971,19 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
(void)pif;
- th = packet_get(p, idx, 0, sizeof(*th), &len);
+ if (!packet_base(p, idx, &data))
+ return 1;
+
+ len = iov_tail_size(&data);
+
+ th = IOV_REMOVE_HEADER(&data, thc);
if (!th)
return 1;
- len += sizeof(*th);
optlen = th->doff * 4UL - sizeof(*th);
/* Static checkers might fail to see this: */
- optlen = MIN(optlen, ((1UL << 4) /* from doff width */ - 6) * 4UL);
- opts = packet_get(p, idx, sizeof(*th), optlen, NULL);
+ optlen = MIN(optlen, OPTLEN_MAX);
+ opts = (char *)iov_peek_header_(&data, &optsc[0], optlen, 1);
sidx = flow_lookup_af(c, IPPROTO_TCP, PIF_TAP, af, saddr, daddr,
ntohs(th->source), ntohs(th->dest));
--
2.49.0