Skip to content

Commit 8246901

Browse files
committed
Linux: handle other DSA tags.
Many of those entries need their own LINKTYPE_/DLT_? values, including tcpdump and Wireshark support for same, but at least this lets you see raw hex data from a capture. Fixes #1367. Supercedes #1451. (backported from commit a8a6cd9)
1 parent cb26db3 commit 8246901

File tree

1 file changed

+283
-4
lines changed

1 file changed

+283
-4
lines changed

pcap-linux.c

Lines changed: 283 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5422,20 +5422,299 @@ iface_get_offload(pcap_t *handle _U_)
54225422
}
54235423
#endif /* SIOCETHTOOL */
54245424

5425+
/*
5426+
* As per
5427+
*
5428+
* https://www.kernel.org/doc/html/latest/networking/dsa/dsa.html#switch-tagging-protocols
5429+
*
5430+
* Type 1 means that the tag is prepended to the Ethernet packet.
5431+
* LINKTYPE_ETHERNET/DLT_EN10MB doesn't work, as it would try to
5432+
* dissect the tag data as the Ethernet header. These should get
5433+
* their own LINKTYPE_DLT_ values.
5434+
*
5435+
* Type 2 means that the tag is inserted into the Ethernet header
5436+
* after the source address and before the type/length field.
5437+
*
5438+
* Type 3 means that tag is a packet trailer. LINKTYPE_ETHERNET/DLT_EN10MB
5439+
* works, unless the next-layer protocol has no length field of its own,
5440+
* so that the tag might be treated as part of the payload. These should
5441+
* get their own LINKTYPE_/DLT_ values.
5442+
*
5443+
* If you get an "unsupported DSA tag" error, please add the tag to here,
5444+
* complete with a full comment indicating whether it's type 1, 2, or 3,
5445+
* and, for type 2, indicating whether it has an Ethertype and, if so
5446+
* what that type is, and whether it's registered with the IEEE or is
5447+
* self-assigned. Also, point to *something* that indicates the format
5448+
* of the tag.
5449+
*/
54255450
static struct dsa_proto {
54265451
const char *name;
54275452
bpf_u_int32 linktype;
54285453
} dsa_protos[] = {
54295454
/*
5430-
* None is special and indicates that the interface does not have
5431-
* any tagging protocol configured, and is therefore a standard
5432-
* Ethernet interface.
5455+
* Type 1. See
5456+
*
5457+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ar9331.c
5458+
*/
5459+
{ "ar9331", DLT_EN10MB },
5460+
5461+
/*
5462+
* Type 2, without an Ethertype at the beginning,
5463+
* assigned a LINKTYPE_/DLT_ value.
54335464
*/
5434-
{ "none", DLT_EN10MB },
54355465
{ "brcm", DLT_DSA_TAG_BRCM },
5466+
5467+
/*
5468+
* Type 2, with Ethertype 0x8874, assigned to Broadcom.
5469+
*
5470+
* This doies not require a LINKTYPE_/DLT_ value, it
5471+
* just requires that Ethertype 0x8874 be dissected
5472+
* properly.
5473+
*/
5474+
{ "brcm-legacy", DLT_EN10MB },
5475+
5476+
/*
5477+
* Type 1.
5478+
*/
54365479
{ "brcm-prepend", DLT_DSA_TAG_BRCM_PREPEND },
5480+
5481+
/*
5482+
* Type 2, without an Etherype at he beginning,
5483+
* assigned a LINKTYPE_/DLT_ value.
5484+
*/
54375485
{ "dsa", DLT_DSA_TAG_DSA },
5486+
5487+
/*
5488+
* Type 2, with an Ethertype field, but without
5489+
* an assigned Ethertype value that can be relied
5490+
* on; assigned a LINKTYPE_/DLT_ value.
5491+
*/
54385492
{ "edsa", DLT_DSA_TAG_EDSA },
5493+
5494+
/*
5495+
* Type 1, with different transmit and receive headers,
5496+
* so can't really be handled well with the current
5497+
* libpcap API and with pcap files. Use DLT_LINUX_SLL,
5498+
* to get the direction?
5499+
*
5500+
* See
5501+
*
5502+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_gswip.c
5503+
*/
5504+
{ "gswip", DLT_EN10MB },
5505+
5506+
/*
5507+
* Type 3. See
5508+
*
5509+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_hellcreek.c
5510+
*/
5511+
{ "hellcreek", DLT_EN10MB },
5512+
5513+
/*
5514+
* Type 3, with different transmit and receive headers,
5515+
* so can't really be handled well with the current
5516+
* libpcap API and with pcap files. Use DLT_LINUX_SLL,
5517+
* to get the direction?
5518+
*
5519+
* See
5520+
*
5521+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ksz.c#L102
5522+
*/
5523+
{ "ksz8795", DLT_EN10MB },
5524+
5525+
/*
5526+
* Type 3, with different transmit and receive headers,
5527+
* so can't really be handled well with the current
5528+
* libpcap API and with pcap files. Use DLT_LINUX_SLL,
5529+
* to get the direction?
5530+
*
5531+
* See
5532+
*
5533+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ksz.c#L160
5534+
*/
5535+
{ "ksz9477", DLT_EN10MB },
5536+
5537+
/*
5538+
* Type 3, with different transmit and receive headers,
5539+
* so can't really be handled well with the current
5540+
* libpcap API and with pcap files. Use DLT_LINUX_SLL,
5541+
* to get the direction?
5542+
*
5543+
* See
5544+
*
5545+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ksz.c#L341
5546+
*/
5547+
{ "ksz9893", DLT_EN10MB },
5548+
5549+
/*
5550+
* Type 3, with different transmit and receive headers,
5551+
* so can't really be handled well with the current
5552+
* libpcap API and with pcap files. Use DLT_LINUX_SLL,
5553+
* to get the direction?
5554+
*
5555+
* See
5556+
*
5557+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ksz.c#L386
5558+
*/
5559+
{ "lan937x", DLT_EN10MB },
5560+
5561+
/*
5562+
* Type 2, with Ethertype 0x8100; the VID can be interpreted
5563+
* as per
5564+
*
5565+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_lan9303.c#L24
5566+
*
5567+
* so giving its own LINKTYPE_/DLT_ value would allow a
5568+
* dissector to do so.
5569+
*/
5570+
{ "lan9303", DLT_EN10MB },
5571+
5572+
/*
5573+
* Type 2, without an Etherype at he beginning,
5574+
* should be assigned a LINKTYPE_/DLT_ value.
5575+
*
5576+
* See
5577+
*
5578+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_mtk.c#L15
5579+
*/
5580+
{ "mtk", DLT_EN10MB },
5581+
5582+
/*
5583+
* None is special and indicates that the interface does not have
5584+
* any tagging protocol configured, and is therefore a standard
5585+
* Ethernet interface.
5586+
*/
5587+
{ "none", DLT_EN10MB },
5588+
5589+
/*
5590+
* Type 1.
5591+
*
5592+
* See
5593+
*
5594+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ocelot.c
5595+
*/
5596+
{ "ocelot", DLT_EN10MB },
5597+
5598+
/*
5599+
* Type 1.
5600+
*
5601+
* See
5602+
*
5603+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_ocelot.c
5604+
*/
5605+
{ "seville", DLT_EN10MB },
5606+
5607+
/*
5608+
* Type 2, with Ethertype 0x8100; the VID can be interpreted
5609+
* as per
5610+
*
5611+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_8021q.c#L15
5612+
*
5613+
* so giving its own LINKTYPE_/DLT_ value would allow a
5614+
* dissector to do so.
5615+
*/
5616+
{ "ocelot-8021q", DLT_EN10MB },
5617+
5618+
/*
5619+
* Type 2, without an Etherype at he beginning,
5620+
* should be assigned a LINKTYPE_/DLT_ value.
5621+
*
5622+
* See
5623+
*
5624+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_qca.c
5625+
*/
5626+
{ "qca", DLT_EN10MB },
5627+
5628+
/*
5629+
* Type 2, with Ethertype 0x8899, assigned to Realtek;
5630+
* they use it for several on-the-Ethernet protocols
5631+
* as well, but there are fields that allow the two
5632+
* tag formats, and all the protocols in question,
5633+
* to be distinguiished from one another.
5634+
*
5635+
* This doies not require a LINKTYPE_/DLT_ value, it
5636+
* just requires that Ethertype 0x8899 be dissected
5637+
* properly.
5638+
*
5639+
* See
5640+
*
5641+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_rtl4_a.c
5642+
*
5643+
* http://realtek.info/pdf/rtl8306sd%28m%29_datasheet_1.1.pdf
5644+
*
5645+
* and various pages in tcpdump's print-realtek.c and Wireshark's
5646+
* epan/dissectors/packet-realtek.c for the other protocols.
5647+
*/
5648+
{ "rtl4a", DLT_EN10MB },
5649+
5650+
/*
5651+
* Type 2, with Ethertype 0x8899, assigned to Realtek;
5652+
* see above.
5653+
*/
5654+
{ "rtl8_4", DLT_EN10MB },
5655+
5656+
/*
5657+
* Type 3, with the same tag format as rtl8_4.
5658+
*/
5659+
{ "rtl8_4t", DLT_EN10MB },
5660+
5661+
/*
5662+
* Type 2, with Ethertype 0xe001; that's probably
5663+
* self-assigned, so this really should ahve its
5664+
* own LINKTYPE_/DLT_ value.
5665+
*
5666+
* See
5667+
*
5668+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_rzn1_a5psw.c
5669+
*/
5670+
{ "a5psw", DLT_EN10MB },
5671+
5672+
/*
5673+
* Type 2, with Ethertype 0x8100 or the self-assigned
5674+
* 0xdadb, so this really should ahve its own
5675+
* LINKTYPE_/DLT_ value; that would also allow the
5676+
* VID of the tag to be dissected as per
5677+
*
5678+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_8021q.c#L15
5679+
*/
5680+
{ "sja1105", DLT_EN10MB },
5681+
5682+
/*
5683+
* Type "none of the above", with both a header and trailer,
5684+
* with different transmit and receive tags. Has
5685+
* Ethertype 0xdadc, which is probably self-assigned.
5686+
* This should really have its own LINKTYPE_/DLT_ value.
5687+
*/
5688+
{ "sja1110", DLT_EN10MB },
5689+
5690+
/*
5691+
* Type 3, as the name suggests.
5692+
*
5693+
* See
5694+
*
5695+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_trailer.c
5696+
*/
5697+
{ "trailer", DLT_EN10MB },
5698+
5699+
/*
5700+
* Type 2, with Ethertype 0x8100; the VID can be interpreted
5701+
* as per
5702+
*
5703+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_8021q.c#L15
5704+
*
5705+
* so giving its own LINKTYPE_/DLT_ value would allow a
5706+
* dissector to do so.
5707+
*/
5708+
{ "vsc73xx-8021q", DLT_EN10MB },
5709+
5710+
/*
5711+
* Type 3.
5712+
*
5713+
* See
5714+
*
5715+
* https://elixir.bootlin.com/linux/v6.13.2/source/net/dsa/tag_xrs700x.c
5716+
*/
5717+
{ "xrs700x", DLT_EN10MB },
54395718
};
54405719

54415720
static int

0 commit comments

Comments
 (0)