+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
assert(n);
if (n->raw_size < sizeof(struct ether_header)) {
- log_lldp("Recieved truncated packet, ignoring.");
+ log_lldp("Received truncated packet, ignoring.");
return -EBADMSG;
}
log_lldp("End marker TLV not zero-sized, ignoring datagram.");
return -EBADMSG;
}
- if (left != 0) {
- log_lldp("Trailing garbage in datagram, ignoring datagram.");
- return -EBADMSG;
- }
+
+ /* Note that after processing the SD_LLDP_TYPE_END left could still be > 0
+ * as the message may contain padding (see IEEE 802.1AB-2016, sec. 8.5.12) */
goto end_marker;
if (r < 0)
return r;
- *ret = n;
- n = NULL;
+ *ret = TAKE_PTR(n);
return r;
}
assert(n->raw_size >= sizeof(struct ether_header));
n->rindex = sizeof(struct ether_header);
- return 0;
+ return n->rindex < n->raw_size;
}
_public_ int sd_lldp_neighbor_tlv_next(sd_lldp_neighbor *n) {
if (n->rindex + 2 > n->raw_size) /* Truncated message */
return -EBADMSG;
- length = LLDP_NEIGHBOR_LENGTH(n);
+ length = LLDP_NEIGHBOR_TLV_LENGTH(n);
if (n->rindex + 2 + length > n->raw_size)
return -EBADMSG;
if (n->rindex + 2 > n->raw_size)
return -EBADMSG;
- *type = LLDP_NEIGHBOR_TYPE(n);
+ *type = LLDP_NEIGHBOR_TLV_TYPE(n);
return 0;
}
if (r == 0)
return -ENXIO;
- length = LLDP_NEIGHBOR_LENGTH(n);
+ length = LLDP_NEIGHBOR_TLV_LENGTH(n);
if (length < 4)
return -EBADMSG;
if (n->rindex + 2 + length > n->raw_size)
return -EBADMSG;
- d = LLDP_NEIGHBOR_DATA(n);
+ d = LLDP_NEIGHBOR_TLV_DATA(n);
memcpy(oui, d, 3);
*subtype = d[3];
if (n->rindex + 2 > n->raw_size)
return -EBADMSG;
- length = LLDP_NEIGHBOR_LENGTH(n);
-
+ length = LLDP_NEIGHBOR_TLV_LENGTH(n);
if (n->rindex + 2 + length > n->raw_size)
return -EBADMSG;