summaryrefslogtreecommitdiff
path: root/src/libnet_checksum.c
diff options
context:
space:
mode:
authorValery Ivanov <ivalery111@gmail.com>2023-04-16 20:46:29 +0300
committerValery Ivanov <ivalery111@gmail.com>2023-05-03 22:01:02 +0300
commit4b3af3b99e5ccb82a66f5f961cc603ed16e7cb87 (patch)
tree812bbf7f2eb20c04a0ed834692f69581b8ef0e00 /src/libnet_checksum.c
parentb19e727ab52d4cd1c54f725c7d30e0c3db669c36 (diff)
downloadlibnet-4b3af3b99e5ccb82a66f5f961cc603ed16e7cb87.tar.gz
udld: initial support
Summary of changes: - Complete UDLD protocol support was added according to RFC5171 - UDLD checksum implementation was added - UDLD unit tests were added - CI has been updated to run UDLD unit tests That's how sample/udld looks in tcpdump: tcpdump: listening on lo0, link-type EN10MB (Ethernet), capture size 262144 bytes 06:23:33.536964 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x03), length 60 Checksum 0x6d85 (unverified) Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG Port-ID TLV (0x0002) TLV, length 9, Gi0/1 Echo TLV (0x0003) TLV, length 8, ^@^@^@^@ Message Interval TLV (0x0004) TLV, length 5, 7s Timeout Interval TLV (0x0005) TLV, length 5, 5s Device Name TLV (0x0006) TLV, length 6, S1 Sequence Number TLV (0x0007) TLV, length 8, 1 0x0000: 2103 6d85 0001 000f 464f 4331 3033 315a !.m.....FOC1031Z 0x0010: 374a 4700 0200 0947 6930 2f31 0003 0008 7JG....Gi0/1.... 0x0020: 0000 0000 0004 0005 0700 0500 0505 0006 ................ 0x0030: 0006 5331 0007 0008 0000 0001 ..S1........ Signed-off-by: Valery Ivanov <ivalery111@gmail.com>
Diffstat (limited to 'src/libnet_checksum.c')
-rw-r--r--src/libnet_checksum.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libnet_checksum.c b/src/libnet_checksum.c
index 16995de..3bbcc36 100644
--- a/src/libnet_checksum.c
+++ b/src/libnet_checksum.c
@@ -526,6 +526,32 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
* the ISL frame itself. Use the libnet_crc function.
*/
}
+ case LIBNET_PROTO_UDLD:
+ {
+ /**
+ * Once again.
+ * iphdr points to the packet, which has the following structure:
+ * IEEE 802.3 Ethernet 14 bytes
+ * LLC 8 bytes
+ * UDLD <<<<---- udld_hdr_offset
+ */
+ /* FIXME: should we use ptrdiff_t for pointer arithmetics? */
+ int whole_packet_length = (end - iphdr); /* The length of IEEE 802.3 Ethernet + LLC + UDLD(include TLVs) */
+ if (whole_packet_length < 0)
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): cannot calculate packet lenght", __func__);
+ return (-1);
+ }
+ const uint8_t udld_hdr_offset = (LIBNET_802_3_H + LIBNET_802_2SNAP_H);
+ int udld_packet_length = (whole_packet_length - udld_hdr_offset);
+
+ const uint16_t checksum = libnet_ip_check((uint16_t *)iphdr + (udld_hdr_offset/sizeof(uint16_t)), udld_packet_length);
+
+ struct libnet_udld_hdr *udld_hdr = (struct libnet_udld_hdr *)(iphdr + udld_hdr_offset);
+ udld_hdr->checksum = checksum;
+ break;
+ }
default:
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,