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

Add support of tcp option wildcard "wscale *" #10

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
4 changes: 4 additions & 0 deletions gtests/net/packetdrill/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,10 @@ tcp_option
}
$$->data.window_scale.shift_count = $2;
}
| WSCALE '*' {
$$ = tcp_option_new(TCPOPT_WINDOW | TCPOPT_WILDCARD, TCPOLEN_WINDOW);
$$->data.window_scale.shift_count = 0;
}
| SACKOK {
$$ = tcp_option_new(TCPOPT_SACK_PERMITTED,
TCPOLEN_SACK_PERMITTED);
Expand Down
12 changes: 8 additions & 4 deletions gtests/net/packetdrill/run_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,14 +1248,18 @@ static int verify_outbound_live_tcp_options(
/* TCP options are expected to be a deterministic order. */
while (a_opt != NULL || s_opt != NULL) {
if (a_opt == NULL || s_opt == NULL ||
a_opt->kind != s_opt->kind) {
(a_opt->kind & ~TCPOPT_WILDCARD) !=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would ignore cases where the actual packet has bit 0x80 set for some reason; AFAICT this would indicate a kernel bug, and is not something we should ignore.

There is also the case for an actual TCP option number that sets the 0x80 bit:
#define TCPOPT_EXP 254 /* Experimental */

If the script says the option type is supposed to be TCPOPT_EXP then we should check that all bits really match TCPOPT_EXP.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest tightening this up with something like:

if (a_opt == NULL || s_opt == NULL ||
(a_opt->kind != s_opt->kind &&
!(s_opt->kind == (TCPOPT_WILDCARD | TCPOPT_WINDOW) &&
a_opt->kind == TCPOPT_WINDOW)) {

(s_opt->kind & ~TCPOPT_WILDCARD)) {
asprintf(error, "bad outbound TCP options");
return STATUS_ERR;
}

if (verify_outbound_tcp_option(config, actual_packet,
script_packet, a_opt, s_opt,
error) != STATUS_OK) {
/* skip btye-to-byte comparison of wildcard option */
if ((a_opt->kind | s_opt->kind) & TCPOPT_WILDCARD)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only want to skip the verify_outbound_tcp_option() call if the script packet has the TCPOPT_WILDCARD bit set. If the actual packet has bit 0x80 set for some reason then AFAICT this indicates a kernel bug, and not something we should ignore. How about:

if (s_opt->kind & TCPOPT_WILDCARD)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are options with the 0x80 bit set:
https://www.iana.org/assignments/tcp-parameters/tcp-parameters.xhtml

So I would suggest tightening this up:

            /* Sometimes skip btye-to-byte comparison of wildcard option */
	if (s_opt->kind == (TCPOPT_WILDCARD | TCPOPT_WINDOW))

;
else if (verify_outbound_tcp_option(config, actual_packet,
script_packet, a_opt, s_opt,
error) != STATUS_OK) {
return STATUS_ERR;
}

Expand Down
11 changes: 11 additions & 0 deletions gtests/net/packetdrill/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@

#define TCP_MD5_DIGEST_LEN 16 /* bytes in RFC2385 TCP MD5 digest */

/*
* To compare subset of options between script packet and actual packet,
* we use * for "option with any value". For example, "wscale *" in the
* script packet means wscale option of any value.
*
* TCPOPT_WILDCARD is used to mark a option in the script packet as
* "any value". A script packet of kind "TCPOPT_WINDOW | TCPOPT_WILDCARD"
* means "wscale option of any value".
*/
#define TCPOPT_WILDCARD 0x80

/* A portable TCP header definition (Linux and *BSD use different names). */
struct tcp {
__be16 src_port;
Expand Down
1 change: 1 addition & 0 deletions gtests/net/packetdrill/tcp_options_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static int get_expected_tcp_option_length(u8 kind, u8 *expected_length,
break;

case TCPOPT_WINDOW:
case TCPOPT_WINDOW | TCPOPT_WILDCARD:
*expected_length = TCPOLEN_WINDOW;
break;

Expand Down
4 changes: 4 additions & 0 deletions gtests/net/packetdrill/tcp_options_to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ int tcp_options_to_string(struct packet *packet,
option->data.window_scale.shift_count);
break;

case TCPOPT_WINDOW | TCPOPT_WILDCARD:
fprintf(s, "wscale *");
break;

case TCPOPT_SACK_PERMITTED:
fputs("sackOK", s);
break;
Expand Down