Skip to content

Commit

Permalink
feature: fix/recalculate header checksum for ipv6-frag(mentation) pac…
Browse files Browse the repository at this point in the history
…kets
  • Loading branch information
ChuckCottrill committed Sep 2, 2024
1 parent 6fcbf03 commit ba4cd31
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/tcpedit/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ do_checksum(tcpedit_t *tcpedit, uint8_t *data, int proto, int len, const u_char

switch (proto) {
case IPPROTO_TCP:
case IPPROTO_TCP_V6FRAG:
if (len < (int)sizeof(tcp_hdr_t)) {
tcpedit_setwarn(tcpedit, "%s", "Unable to checksum TCP with insufficient L4 data");
return TCPEDIT_WARN;
Expand All @@ -98,6 +99,7 @@ do_checksum(tcpedit_t *tcpedit, uint8_t *data, int proto, int len, const u_char
} else {
sum = do_checksum_math((uint16_t *)&ipv4->ip_src, 8);
}

sum += ntohs(IPPROTO_TCP + len);
sum += do_checksum_math((uint16_t *)tcp, len);
tcp->th_sum = CHECKSUM_CARRY(sum);
Expand Down
1 change: 1 addition & 0 deletions src/tcpedit/plugins/dlt_en10mb/en10mb.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ dlt_en10mb_parse_subsmac(tcpeditdlt_t *ctx, en10mb_config_t *config, const char
size_t input_len = strlen(input);
size_t possible_entries_number = (input_len / (SUBSMAC_ENTRY_LEN + 1)) + 1;
size_t entry;
unsigned int entry;

Check warning on line 188 in src/tcpedit/plugins/dlt_en10mb/en10mb.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/plugins/dlt_en10mb/en10mb.c:188:18 [cppcoreguidelines-init-variables]

variable 'entry' is not initialized

en10mb_sub_entry_t *entries = safe_malloc(possible_entries_number * sizeof(en10mb_sub_entry_t));

Expand Down
4 changes: 3 additions & 1 deletion src/tcpedit/tcpedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, u_char **pktdata
/* do we need to fix checksums? -- must always do this last! */
if (tcpedit->fixhdrlen) {
/* ensure IP header length is correct */
/* when packet change? then needtorecalc checksum */
int changed = 0;
if (ip_hdr != NULL) {
/* did the packet change? if so, checksum */
changed = fix_ipv4_length(*pkthdr, ip_hdr, l2len);
} else if (ip6_hdr != NULL) {
changed = fix_ipv6_length(*pkthdr, ip6_hdr, l2len);
changed |= fix_ipv6_length(*pkthdr, ip6_hdr, l2len);
}
/* did the packet change? then needtorecalc checksum */
if (changed > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/tcpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ struct tcpr_gre_hdr {
#ifndef IPPROTO_GRE
#define IPPROTO_GRE 47
#endif
#ifndef IPPROTO_TCP_V6FRAG
#define IPPROTO_TCP_V6FRAG 0x2c
#endif

/*
* Source Route Entries (SRE)
Expand Down

0 comments on commit ba4cd31

Please sign in to comment.