From ab458eae56be4c2bd0291ab6b4d8fb518fa836eb Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Wed, 19 Apr 2023 09:55:14 +0200 Subject: [PATCH] pcapparse: Add support for Linux "cooked" capture encapsulation v2 See https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL2.html Part-of: --- .../gst-plugins-bad/gst/pcapparse/gstpcapparse.c | 12 ++++++++++-- .../gst-plugins-bad/gst/pcapparse/gstpcapparse.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.c b/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.c index a4922053d0..53e7ef6fc2 100644 --- a/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.c +++ b/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.c @@ -351,6 +351,7 @@ gst_pcap_parse_read_uint32 (GstPcapParse * self, const guint8 * p) #define ETH_HEADER_LEN 14 #define ETH_VLAN_HEADER_LEN 4 #define SLL_HEADER_LEN 16 +#define SLL2_HEADER_LEN 20 #define IP_HEADER_MIN_LEN 20 #define UDP_HEADER_LEN 8 @@ -404,6 +405,13 @@ gst_pcap_parse_scan_frame (GstPcapParse * self, eth_type = GUINT16_FROM_BE (*((guint16 *) (buf + 14))); buf_ip = buf + SLL_HEADER_LEN; break; + case LINKTYPE_SLL2: + if (buf_size < SLL2_HEADER_LEN + IP_HEADER_MIN_LEN + UDP_HEADER_LEN) + return FALSE; + + eth_type = GUINT16_FROM_BE (*((guint16 *) (buf))); + buf_ip = buf + SLL2_HEADER_LEN; + break; case LINKTYPE_RAW: if (buf_size < IP_HEADER_MIN_LEN + UDP_HEADER_LEN) return FALSE; @@ -641,9 +649,9 @@ gst_pcap_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) } if (linktype != LINKTYPE_ETHER && linktype != LINKTYPE_SLL && - linktype != LINKTYPE_RAW) { + linktype != LINKTYPE_RAW && linktype != LINKTYPE_SLL2) { GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL), - ("Only dumps of type Ethernet, raw IP or Linux Cooked (SLL) " + ("Only dumps of type Ethernet, raw IP or Linux Cooked (SLL/SLL2) " "understood; type %d unknown", linktype)); ret = GST_FLOW_ERROR; goto out; diff --git a/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.h b/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.h index 29e2188c72..9547ce4003 100644 --- a/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.h +++ b/subprojects/gst-plugins-bad/gst/pcapparse/gstpcapparse.h @@ -49,7 +49,8 @@ typedef enum { LINKTYPE_ETHER = 1, LINKTYPE_RAW = 101, - LINKTYPE_SLL = 113 + LINKTYPE_SLL = 113, + LINKTYPE_SLL2 = 276 } GstPcapParseLinktype; /**