diff --git a/gtests/net/packetdrill/lexer.l b/gtests/net/packetdrill/lexer.l index b8aaa23fa06d402079d95f9cd0baefeb7d3ea2da..9f07914d4607f23bd951ea5abe3c8fb272356c90 100644 --- a/gtests/net/packetdrill/lexer.l +++ b/gtests/net/packetdrill/lexer.l @@ -384,6 +384,9 @@ sn_length return SN_LENGTH; sn_flags return SN_FLAGS; gaids_number_of_ids return GAIDS_NUMBER_OF_IDS; gaids_assoc_id return GAIDS_ASSOC_ID; +gauth_assoc_id return GAUTH_ASSOC_ID; +gauth_number_of_chunks return GAUTH_NUMBER_OF_CHUNKS; +gauth_chunks return GAUTH_CHUNKS; CHUNK return CHUNK; DATA return DATA; INIT return INIT; diff --git a/gtests/net/packetdrill/parser.y b/gtests/net/packetdrill/parser.y index 1e15b1b81301762627e2476146afc78b09d8bc9c..6a6f2deb820759eaa2c6de4b178c49f934bc761b 100644 --- a/gtests/net/packetdrill/parser.y +++ b/gtests/net/packetdrill/parser.y @@ -513,7 +513,7 @@ static struct tcp_option *new_tcp_fast_open_option(const char *cookie_string, %token <reserved> SSTAT_INSTRMS SSTAT_OUTSTRMS SSTAT_FRAGMENTATION_POINT %token <reserved> SSTAT_PRIMARY %token <reserved> SPINFO_ASSOC_ID SPINFO_ADDRESS SPINFO_STATE SPINFO_CWND SPINFO_SRTT SPINFO_RTO -%token <reserved> SPINFO_MTU +%token <reserved> SPINFO_MTU GAUTH_ASSOC_ID GAUTH_NUMBER_OF_CHUNKS GAUTH_CHUNKS %token <reserved> CHUNK DATA INIT INIT_ACK HEARTBEAT HEARTBEAT_ACK ABORT %token <reserved> SHUTDOWN SHUTDOWN_ACK ERROR COOKIE_ECHO COOKIE_ACK ECNE CWR %token <reserved> SHUTDOWN_COMPLETE I_DATA PAD @@ -614,6 +614,7 @@ static struct tcp_option *new_tcp_fast_open_option(const char *cookie_string, %type <expression> sctp_paddrparams spp_address spp_hbinterval spp_pathmtu spp_pathmaxrxt %type <expression> spp_flags spp_ipv6_flowlabel spp_dscp ssp_addr %type <expression> spinfo_address spinfo_state spinfo_cwnd spinfo_srtt spinfo_rto spinfo_mtu +%type <expression> sctp_authchunks gauth_number_of_chunks %type <expression> sasoc_asocmaxrxt sasoc_number_peer_destinations sasoc_peer_rwnd %type <expression> sasoc_local_rwnd sasoc_cookie_life sctp_assocparams %type <expression> sctp_sndinfo snd_sid snd_flags snd_ppid snd_context @@ -2551,6 +2552,9 @@ expression | sctp_assoc_ids { $$ = $1; } +| sctp_authchunks { + $$ = $1; +} | null { $$ = $1; } @@ -4785,6 +4789,32 @@ sctp_assoc_ids $$->value.sctp_assoc_ids->gaids_assoc_id = $6; }; +gauth_number_of_chunks +: GAUTH_NUMBER_OF_CHUNKS '=' INTEGER { + if (!is_valid_u32($3)) { + semantic_error("gauth_number_of_chunks out of range"); + } + $$ = new_integer_expression($3, "%u"); +} +| GAUTH_NUMBER_OF_CHUNKS '=' ELLIPSIS { $$ = new_expression(EXPR_ELLIPSIS); } +; + +sctp_authchunks +: '{' GAUTH_ASSOC_ID '=' sctp_assoc_id ',' gauth_number_of_chunks ',' GAUTH_CHUNKS '=' array '}' { + $$ = new_expression(EXPR_SCTP_AUTHCHUNKS); + $$->value.sctp_authchunks = calloc(1, sizeof(struct sctp_authchunks_expr)); + $$->value.sctp_authchunks->gauth_assoc_id = $4; + $$->value.sctp_authchunks->gauth_number_of_chunks = $6; + $$->value.sctp_authchunks->gauth_chunks = $10; +} +| '{' gauth_number_of_chunks ',' GAUTH_CHUNKS '=' array '}' { + $$ = new_expression(EXPR_SCTP_AUTHCHUNKS); + $$->value.sctp_authchunks = calloc(1, sizeof(struct sctp_authchunks_expr)); + $$->value.sctp_authchunks->gauth_assoc_id = new_expression(EXPR_ELLIPSIS); + $$->value.sctp_authchunks->gauth_number_of_chunks = $2; + $$->value.sctp_authchunks->gauth_chunks = $6; +}; + opt_errno : { $$ = NULL; } | WORD note { diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index c1d65ded205fa81859d4b09d88dd9812f9f89963..990a34e9488529306155d622dc5046df822a63de 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -2965,6 +2965,7 @@ static int check_sctp_setadaptation(struct sctp_setadaptation_expr *expr, } #endif +#ifdef SCTP_HMAC_IDENT static int check_sctp_hamcalgo(struct sctp_hmacalgo_expr *expr, struct sctp_hmacalgo *sctp_hmacalgo, char **error) { @@ -2981,7 +2982,9 @@ static int check_sctp_hamcalgo(struct sctp_hmacalgo_expr *expr, return STATUS_OK; } +#endif +#ifdef SCTP_GET_ASSOC_ID_LIST static int check_sctp_assoc_ids(struct sctp_assoc_ids_expr *expr, struct sctp_assoc_ids *sctp_assoc_ids, char **error) { @@ -3020,6 +3023,26 @@ static int check_sctp_assoc_ids(struct sctp_assoc_ids_expr *expr, } return STATUS_OK; } +#endif + +#if defined(SCTP_PEER_AUTH_CHUNKS) || defined(SCTP_LOCAL_AUTH_CHUNKS) +static int check_sctp_authchunks(struct sctp_authchunks_expr *expr, + struct sctp_authchunks *sctp_authchunks, + char **error) { + if (check_sctp_assoc_t_expr(expr->gauth_assoc_id, sctp_authchunks->gauth_assoc_id, + "sctp_authchunks.gauth_assoc_id", error)) + return STATUS_ERR; + if (check_u32_expr(expr->gauth_number_of_chunks, sctp_authchunks->gauth_number_of_chunks, + "sctp_authchunks.gauth_number_of_chunks", error)) + return STATUS_ERR; + if (check_u8array_expr(expr->gauth_chunks, sctp_authchunks->gauth_chunks, + sctp_authchunks->gauth_number_of_chunks, + "sctp_authchunks.gauth_chunks", error)) + return STATUS_ERR; + + return STATUS_OK; +} +#endif static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall, struct expression_list *args, char **error) @@ -3268,11 +3291,25 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall, #endif #ifdef SCTP_GET_ASSOC_ID_LIST case EXPR_SCTP_ASSOC_IDS: { - s32 len = expression_list_length(val_expression->value.sctp_assoc_ids->gaids_assoc_id->value.list); + int len = expression_list_length(val_expression->value.sctp_assoc_ids->gaids_assoc_id->value.list); live_optval = malloc(sizeof(u32) + (sizeof(sctp_assoc_t) * len)); live_optlen = sizeof(u32) + (sizeof(sctp_assoc_t) * len); break; } +#endif +#if defined(SCTP_PEER_AUTH_CHUNKS) || defined(SCTP_LOCAL_AUTH_CHUNKS) + case EXPR_SCTP_AUTHCHUNKS: { + int len = expression_list_length(val_expression->value.sctp_authchunks->gauth_chunks->value.list); + live_optval = malloc(sizeof(sctp_assoc_t) + sizeof(u32) + (sizeof(u8) * len)); + live_optlen = sizeof(sctp_assoc_t) + sizeof(u32) + (sizeof(u8) * len); + if (get_sctp_assoc_t(val_expression->value.sctp_authchunks->gauth_assoc_id, + &((struct sctp_authchunks *)live_optval)->gauth_assoc_id, + error)) { + free(live_optval); + return STATUS_ERR; + } + break; + } #endif case EXPR_LIST: s32_bracketed_arg(args, 3, &script_optval, error); @@ -3396,10 +3433,14 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall, break; #endif #ifdef SCTP_GET_ASSOC_ID_LIST - case EXPR_SCTP_ASSOC_IDS: { + case EXPR_SCTP_ASSOC_IDS: result = check_sctp_assoc_ids(val_expression->value.sctp_assoc_ids, live_optval, error); break; - } +#endif +#if defined(SCTP_PEER_AUTH_CHUNKS) || defined(SCTP_LOCAL_AUTH_CHUNKS) + case EXPR_SCTP_AUTHCHUNKS: + result = check_sctp_authchunks(val_expression->value.sctp_authchunks, live_optval, error); + break; #endif case EXPR_LIST: if (*(int*)live_optval != script_optval) { diff --git a/gtests/net/packetdrill/script.c b/gtests/net/packetdrill/script.c index dc0cd46e66630a8fdae75c1f2d93d6e04d46a3cf..41744e150ab993c2400c252758c16c69ac582ead 100644 --- a/gtests/net/packetdrill/script.c +++ b/gtests/net/packetdrill/script.c @@ -104,6 +104,7 @@ struct expression_type_entry expression_type_table[] = { { EXPR_SCTP_TLV, "sctp_tlv" }, { EXPR_SCTP_EXTRCVINFO, "sctp_extrcvinfo" }, { EXPR_SCTP_ASSOC_IDS, "sctp_assoc_ids" }, + { EXPR_SCTP_AUTHCHUNKS, "sctp_authchunks" }, { NUM_EXPR_TYPES, NULL} }; @@ -585,6 +586,11 @@ void free_expression(struct expression *expression) free_expression(expression->value.sctp_assoc_ids->gaids_number_of_ids); free_expression(expression->value.sctp_assoc_ids->gaids_assoc_id); break; + case EXPR_SCTP_AUTHCHUNKS: + free_expression(expression->value.sctp_authchunks->gauth_assoc_id); + free_expression(expression->value.sctp_authchunks->gauth_number_of_chunks); + free_expression(expression->value.sctp_authchunks->gauth_chunks); + break; case EXPR_WORD: assert(expression->value.string); free(expression->value.string); @@ -2279,6 +2285,37 @@ static int evaluate_sctp_assoc_ids_expression(struct expression *in, return STATUS_OK; } +static int evaluate_sctp_authchunks_expression(struct expression *in, + struct expression *out, + char **error) +{ + struct sctp_authchunks_expr *in_chunks; + struct sctp_authchunks_expr *out_chunks; + + assert(in->type == EXPR_SCTP_AUTHCHUNKS); + assert(in->value.sctp_authchunks); + assert(out->type == EXPR_SCTP_AUTHCHUNKS); + + out->value.sctp_authchunks = calloc(1, sizeof(struct sctp_authchunks_expr)); + + in_chunks = in->value.sctp_authchunks; + out_chunks = out->value.sctp_authchunks; + + if (evaluate(in_chunks->gauth_assoc_id, + &out_chunks->gauth_assoc_id, + error)) + return STATUS_ERR; + if (evaluate(in_chunks->gauth_number_of_chunks, + &out_chunks->gauth_number_of_chunks, + error)) + return STATUS_ERR; + if (evaluate(in_chunks->gauth_chunks, + &out_chunks->gauth_chunks, + error)) + return STATUS_ERR; + return STATUS_OK; +} + static int evaluate(struct expression *in, struct expression **out_ptr, char **error) { @@ -2415,6 +2452,9 @@ static int evaluate(struct expression *in, case EXPR_SCTP_ASSOC_IDS: result = evaluate_sctp_assoc_ids_expression(in, out, error); break; + case EXPR_SCTP_AUTHCHUNKS: + result = evaluate_sctp_authchunks_expression(in, out, error); + break; case EXPR_WORD: out->type = EXPR_INTEGER; if (symbol_to_int(in->value.string, diff --git a/gtests/net/packetdrill/script.h b/gtests/net/packetdrill/script.h index 56388a4b5c7c64bc211af5fb5474c73f75c42073..1913bef6554f737f703418688c295b2b8af32224 100644 --- a/gtests/net/packetdrill/script.h +++ b/gtests/net/packetdrill/script.h @@ -84,6 +84,7 @@ enum expression_t { EXPR_SCTP_TLV, /* expression tree for sctp_notifications_stopped_event */ EXPR_SCTP_EXTRCVINFO, /* expression tree for sctp_extrcvinfo struct in cmsghdr */ EXPR_SCTP_ASSOC_IDS, /* expression tree for sctp_assoc_ids struct for [gs]etsockopt */ + EXPR_SCTP_AUTHCHUNKS, /* expression tree for sctp_authchunks struct for [gs]etsockopt */ NUM_EXPR_TYPES, }; /* Convert an expression type to a human-readable string */ @@ -141,6 +142,7 @@ struct expression { struct sctp_tlv_expr *sctp_tlv; struct sctp_extrcvinfo_expr *sctp_extrcvinfo; struct sctp_assoc_ids_expr *sctp_assoc_ids; + struct sctp_authchunks_expr *sctp_authchunks; } value; const char *format; /* the printf format for printing the value */ }; @@ -525,12 +527,19 @@ struct sctp_extrcvinfo_expr { struct expression *sinfo_assoc_id; }; -/* Parse tree for sctp_extrcvinfo struct for cmsg. */ +/* Parse tree for sctp_extrcvinfo struct for [gs]etsockopt. */ struct sctp_assoc_ids_expr { struct expression *gaids_number_of_ids; struct expression *gaids_assoc_id; }; +/* Parse tree for sctp_authchunks struct for [gs]etsockopt. */ +struct sctp_authchunks_expr { + struct expression *gauth_assoc_id; + struct expression *gauth_number_of_chunks; + struct expression *gauth_chunks; +}; + /* The errno-related info from strace to summarize a system call error */ struct errno_spec { const char *errno_macro; /* errno symbol (C macro name) */ diff --git a/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_local_auth_chunks.pkt b/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_local_auth_chunks.pkt index e3c5b939186ed358384fd415cce6b580111fbe57..41b5c2fcc3690d7c7cc093dcc8f65f8cb2d23ad5 100644 --- a/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_local_auth_chunks.pkt +++ b/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_local_auth_chunks.pkt @@ -11,10 +11,10 @@ +0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 +0 getsockopt(3, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, {gauth_assoc_id=0, - gauth_number_of_chunks=..., - gauth_chunks=[...]}, [10]) = 0 + gauth_number_of_chunks=0, + gauth_chunks=[]}, [8]) = 0 -+0 getsockopt(3, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, {gauth_number_of_chunks=..., - gauth_chunks=[...]}, [10]) = 0 ++0 getsockopt(3, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, {gauth_number_of_chunks=0, + gauth_chunks=[]}, [8]) = 0 +0 close(3) = 0 diff --git a/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_peer_auth_chunks.pkt b/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_peer_auth_chunks.pkt index fa74d57b5b437e96adf8bc5483b87c30263c3e89..e97bfe5954fd2e17b74e0a5676bf2f9ef11108ab 100644 --- a/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_peer_auth_chunks.pkt +++ b/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_peer_auth_chunks.pkt @@ -11,7 +11,7 @@ +0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 //only dummy values, unimplemented in packetdrill -+0 getsockopt(3, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, {gauth_assoc_id=..., gauth_number_of_chunks=2, gauth_chunks=[0x00, 0x01]}, [10]) = 0 -+0 getsockopt(3, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, {gauth_number_of_chunks=2, gauth_chunks=[0x00, 0x01]}, [10]) = 0 ++0 getsockopt(3, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, {gauth_assoc_id=..., gauth_number_of_chunks=0, gauth_chunks=[]}, [8]) = 0 ++0 getsockopt(3, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, {gauth_number_of_chunks=0, gauth_chunks=[]}, [8]) = 0 +0 close(3) = 0