Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: fix/recalculate header checksum for ipv6-frag(mentation) pac… #900

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions src/tcpedit/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Returns -1 on error and 0 on success, 1 on warn
*/
int
do_checksum(tcpedit_t *tcpedit, uint8_t *data, int proto, int len, const u_char *end_ptr)

Check warning on line 35 in src/tcpedit/checksum.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/checksum.c:35:1 [readability-function-cognitive-complexity]

function 'do_checksum' has cognitive complexity of 29 (threshold 25)
{
ipv4_hdr_t *ipv4;
ipv6_hdr_t *ipv6;
Expand Down Expand Up @@ -78,6 +78,7 @@

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 @@
} 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 @@
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 @@ -18,7 +18,7 @@
* along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
*/

#include "defines.h"

Check failure on line 21 in src/tcpedit/tcpedit.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/tcpedit.c:21:10 [clang-diagnostic-error]

'defines.h' file not found
#include "config.h"
#include "common.h"
#include "edit_packet.h"
Expand Down Expand Up @@ -320,11 +320,13 @@
/* 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 @@ -142,8 +142,8 @@
* size: 8 bytes
*/
struct tcpr_802_1q_hdr {
uint16_t vlan_tci; /* VLAN TCI */

Check failure on line 145 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:145:5 [clang-diagnostic-error]

unknown type name 'uint16_t'
uint16_t vlan_tpid; /* Next ETH_TYPE */

Check failure on line 146 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:146:5 [clang-diagnostic-error]

unknown type name 'uint16_t'
#define TCPR_802_1Q_PRIMASK 0xe000 /**< priority mask */
#define TCPR_802_1Q_CFIMASK 0x1000 /**< CFI mask */
#define TCPR_802_1Q_VIDMASK 0x0fff /**< vid mask */
Expand All @@ -154,14 +154,14 @@
* size: 4 bytes
*/
struct tcpr_802_1x_hdr {
uint8_t dot1x_version; /**< protocol version */

Check failure on line 157 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:157:5 [clang-diagnostic-error]

unknown type name 'uint8_t'
uint8_t dot1x_type; /**< frame type */

Check failure on line 158 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:158:5 [clang-diagnostic-error]

unknown type name 'uint8_t'
#define TCPR_802_1X_PACKET 0x00 /**< 802.1x packet */
#define TCPR_802_1X_START 0x01 /**< 802.1x start */
#define TCPR_802_1X_LOGOFF 0x02 /**< 802.1x logoff */
#define TCPR_802_1X_KEY 0x03 /**< 802.1x key */
#define TCPR_802_1X_ENCASFAL 0x04 /**< 802.1x encasfal */
uint16_t dot1x_length; /**< total frame length */

Check failure on line 164 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:164:5 [clang-diagnostic-error]

unknown type name 'uint16_t'
};

/*
Expand All @@ -170,11 +170,11 @@
* static header size: 4 bytes
*/
struct tcpr_802_2_hdr {
uint8_t llc_dsap; /* destination service access point */

Check failure on line 173 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:173:5 [clang-diagnostic-error]

unknown type name 'uint8_t'
uint8_t llc_ssap; /* source service access point */

Check failure on line 174 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:174:5 [clang-diagnostic-error]

unknown type name 'uint8_t'
#define TCPR_SAP_STP 0x42
#define TCPR_SAP_SNAP 0xaa
uint16_t llc_control; /* control field */

Check failure on line 177 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:177:5 [clang-diagnostic-error]

unknown type name 'uint16_t'
};

/*
Expand All @@ -183,7 +183,7 @@
* static header size: 8 bytes
*/
struct tcpr_802_2snap_hdr {
uint8_t snap_dsap; /* destination service access point */

Check failure on line 186 in src/tcpr.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpr.h:186:5 [clang-diagnostic-error]

unknown type name 'uint8_t'
uint8_t snap_ssap; /* destination service access point */
uint8_t snap_control; /* control field */
uint8_t snap_oui[3]; /* OUI */
Expand Down Expand Up @@ -652,6 +652,9 @@
#ifndef IPPROTO_GRE
#define IPPROTO_GRE 47
#endif
#ifndef IPPROTO_TCP_V6FRAG
#define IPPROTO_TCP_V6FRAG 0x2c
#endif

/*
* Source Route Entries (SRE)
Expand Down
Loading