diff options
| author | luwenpeng <[email protected]> | 2024-10-23 14:34:20 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-10-23 14:34:26 +0800 |
| commit | 99d933bd8d0026d9fa0dbf61a80d2775e98f0971 (patch) | |
| tree | b8e09931ce7b64360f87f26c09d0403de9acd7c5 | |
| parent | 3d4e6a2cd51ce933d1d182246b3fb5277c91d665 (diff) | |
bugfix: GTP-U only header no payload
| -rw-r--r-- | infra/packet_manager/packet_parser.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/infra/packet_manager/packet_parser.c b/infra/packet_manager/packet_parser.c index e4de9f5..76c4706 100644 --- a/infra/packet_manager/packet_parser.c +++ b/infra/packet_manager/packet_parser.c @@ -819,29 +819,43 @@ static inline const char *parse_gtp_u(struct packet *pkt, const char *data, uint return data; } - uint8_t next_proto = (((const uint8_t *)(data + hdr_len))[0]) >> 4; - if (next_proto != 4 && next_proto != 6) + if (hdr_len == len) { - // next_proto is not IPv4 or IPv6, this is not a normal GTP-U packet, fallback to UDP - return data; + // only GTP-U header, no payload + struct layer_private *layer = get_free_layer(pkt); + if (unlikely(layer == NULL)) + { + return data; + } + SET_LAYER(pkt, layer, LAYER_PROTO_GTP_U, hdr_len, data, len, 0); + return layer->pld_ptr; } - - struct layer_private *layer = get_free_layer(pkt); - if (unlikely(layer == NULL)) + else { - return data; - } - SET_LAYER(pkt, layer, LAYER_PROTO_GTP_U, hdr_len, data, len, 0); + uint8_t next_proto = (((const uint8_t *)(data + hdr_len))[0]) >> 4; + if (next_proto != 4 && next_proto != 6) + { + // next_proto is not IPv4 or IPv6, this is not a normal GTP-U packet, fallback to UDP + return data; + } - switch (next_proto) - { - case 4: - return parse_ipv4(pkt, layer->pld_ptr, layer->pld_len); - case 6: - return parse_ipv6(pkt, layer->pld_ptr, layer->pld_len); - default: - PACKET_LOG_UNSUPPORT_PROTO(pkt, LAYER_PROTO_GTP_U, next_proto); - return layer->pld_ptr; + struct layer_private *layer = get_free_layer(pkt); + if (unlikely(layer == NULL)) + { + return data; + } + SET_LAYER(pkt, layer, LAYER_PROTO_GTP_U, hdr_len, data, len, 0); + + switch (next_proto) + { + case 4: + return parse_ipv4(pkt, layer->pld_ptr, layer->pld_len); + case 6: + return parse_ipv6(pkt, layer->pld_ptr, layer->pld_len); + default: + PACKET_LOG_UNSUPPORT_PROTO(pkt, LAYER_PROTO_GTP_U, next_proto); + return layer->pld_ptr; + } } } |
