Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ add_library(libef STATIC
src/ef-igmp.c
src/ef-ipv4.c
src/ef-ipv6.c
src/ef-llc.c
src/ef-mld.c
src/ef-mrp.c
src/ef-oam.c
Expand All @@ -82,6 +83,7 @@ add_library(libef STATIC
src/ef-profinet.c
src/ef-ptp.c
src/ef-rate.c
src/ef-stp.c
src/ef-sv.c
src/ef-txring.c
src/ef-udp.c
Expand Down Expand Up @@ -127,6 +129,8 @@ add_executable(ef-tests
test/test-mld-zero-width.cxx
test/test-rate-limit.cxx
test/test-rx-ign.cxx
test/test-llc.cxx
test/test-stp.cxx
)
target_compile_options(ef-tests PRIVATE ${EF_SANITIZE_FLAGS})

Expand Down
Binary file added fuzz/corpus-argc-frame/eth_llc_stp
Binary file not shown.
Binary file added fuzz/corpus-argc-frame/eth_llc_stp_rst
Binary file not shown.
Binary file added fuzz/corpus-argc-frame/eth_llc_stp_tcn
Binary file not shown.
33 changes: 33 additions & 0 deletions fuzz/ef.dict
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"mrp_topo"
"mrp_tst"

# Headers LLC
"llc"

# Headers STP
"stp"
"stp_rst"
"stp_tcn"

# Headers PTP
"ptp-announce"
"ptp-follow-up"
Expand Down Expand Up @@ -168,6 +176,31 @@
"hdr-flagField"
"hdr-logMessageInterval"

# Field names LLC
"dsap"
"ssap"
"ctrl"

# Field names STP
"tc"
"proposal"
"role"
"learning"
"forwarding"
"agreement"
"tcack"
"root_prio"
"root_mac"
"root_cost"
"bridge_prio"
"bridge_mac"
"port"
"msg_age"
"max_age"
"hello"
"fwd_delay"
"v1_len"

# Field names OAM
"opcode"
"mel"
Expand Down
81 changes: 81 additions & 0 deletions src/ef-llc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <stdio.h>
#include "ef.h"

// IEEE 802.2 Logical Link Control. An LLC header is preceded by a length and
// not by an EtherType, so we compute the 802.3 length and write it into the
// "et" field of the header below us -- eth, or the outermost VLAN tag, both
// of which carry that field last.
//
// This works because frame_to_buf() runs frame_fill_defaults from the top of
// the stack downwards: by the time eth_fill_defaults() calls
// ether_type_fill_defaults(), et->val is already set and is left alone.
static int llc_fill_defaults(struct frame *f, int stack_idx) {
char buf[16];
int i, len = 0;
hdr_t *ll;
field_t *et;

if (stack_idx < 1)
return 0;

ll = f->stack[stack_idx - 1];
et = find_field(ll, "et");

// An explicit "et" on the command line wins over the computed length.
if (!et || et->val)
return 0;

for (i = stack_idx; i < f->stack_size; ++i)
len += f->stack[i]->size;

// 802.3 clause 3.2.6: a type/length value above 1500 is not a length,
// and from 1536 up it is read as an EtherType. Refuse to emit one rather
// than silently write a frame the receiver will misparse.
if (len > 1500) {
pe("llc: 802.3 length %d exceeds 1500, set \"et\" explicitly\n",
len);
return -1;
}

snprintf(buf, 16, "%d", len);
buf[15] = 0;
et->val = parse_bytes(buf, 2);

return 0;
}

static field_t LLC_FIELDS[] = {
{ .name = "dsap",
.help = "Destination Service Access Point, e.g. 0x42 for STP",
.bit_width = 8 },
{ .name = "ssap",
.help = "Source Service Access Point, e.g. 0x42 for STP",
.bit_width = 8 },
{ .name = "ctrl",
.help = "Control, one byte for U-format frames, e.g. 0x03 for UI",
.bit_width = 8 },
};

static hdr_t HDR_LLC = {
.name = "llc",
.help = "IEEE 802.2 LLC, sets the 802.3 length below it, e.g. llc stp",
.fields = LLC_FIELDS,
.fields_size = sizeof(LLC_FIELDS) / sizeof(LLC_FIELDS[0]),
.frame_fill_defaults = llc_fill_defaults,
.parser = hdr_parse_fields,
};

void llc_init() {
def_offset(&HDR_LLC);
def_val(&HDR_LLC, "dsap", "0x42");
def_val(&HDR_LLC, "ssap", "0x42");
def_val(&HDR_LLC, "ctrl", "0x03");

hdr_tmpls[HDR_TMPL_LLC] = &HDR_LLC;
}

void llc_uninit() {
uninit_frame_data(&HDR_LLC);

hdr_tmpls[HDR_TMPL_LLC] = 0;
}
Loading
Loading