Skip to content

Commit

Permalink
Support rsv1, rsv2, rsv3 reserved flags in in \{ws.* <reserved-flag>}
Browse files Browse the repository at this point in the history
  • Loading branch information
lwalkin committed Oct 7, 2016
1 parent cc675ea commit 5b147fe
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 497 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

1.x:
* Support rsv1, rsv2, rsv3 reserved flags in in \{ws.* <reserved-flag>}.

1.0: 2016-Sep-29
* Export --latency-connect and --latency-first-bytes to statsd.
* --latency-percentiles now affect --statsd reporting as well.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([tcpkali],[1.0],[[email protected]])
AC_INIT([tcpkali],[1.x],[[email protected]])

AC_CONFIG_SRCDIR([src/tcpkali.c])
AC_CONFIG_AUX_DIR(config)
Expand Down
4 changes: 2 additions & 2 deletions src/tcpkali_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ eval_expression(char **buf_p, size_t size, tk_expr_t *expr, expr_callback_f cb,
size_t hdr_size = websocket_frame_header(
(uint8_t *)buf, size,
client_mode ? WS_SIDE_CLIENT : WS_SIDE_SERVER,
expr->u.ws_frame.opcode, expr->u.ws_frame.fin,
expr->u.ws_frame.size);
expr->u.ws_frame.opcode, expr->u.ws_frame.rsvs,
expr->u.ws_frame.fin, expr->u.ws_frame.size);
memcpy(buf + hdr_size, expr->u.ws_frame.data,
expr->u.ws_frame.size);
return (hdr_size + expr->u.ws_frame.size);
Expand Down
1 change: 1 addition & 0 deletions src/tcpkali_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct tk_expr {
const char *data;
size_t size;
enum ws_frame_opcode opcode;
int rsvs;
int fin;
} ws_frame;
struct {
Expand Down
606 changes: 308 additions & 298 deletions src/tcpkali_expr_l.c

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/tcpkali_expr_l.l
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ WSP [\t\r\v\f\n ]
}
"." return '.';
"..." return TOK_ellipsis;
"rsv1" { yylval.tv_long = 0x4; return TOK_ws_reserved_flag; }
"rsv2" { yylval.tv_long = 0x2; return TOK_ws_reserved_flag; }
"rsv3" { yylval.tv_long = 0x1; return TOK_ws_reserved_flag; }
"%" return '%';


Expand Down
343 changes: 179 additions & 164 deletions src/tcpkali_expr_y.c

Large diffs are not rendered by default.

52 changes: 27 additions & 25 deletions src/tcpkali_expr_y.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,38 @@ extern int yydebug;
END = 0,
TOK_ws = 258,
TOK_ws_opcode = 259,
TOK_global = 260,
TOK_connection = 261,
TOK_ptr = 262,
TOK_uid = 263,
TOK_regex = 264,
TOK_ellipsis = 265,
string_token = 266,
class_range_token = 267,
repeat_range_token = 268,
quoted_string = 269,
filename = 270,
integer = 271
TOK_ws_reserved_flag = 260,
TOK_global = 261,
TOK_connection = 262,
TOK_ptr = 263,
TOK_uid = 264,
TOK_regex = 265,
TOK_ellipsis = 266,
string_token = 267,
class_range_token = 268,
repeat_range_token = 269,
quoted_string = 270,
filename = 271,
integer = 272
};
#endif
/* Tokens. */
#define END 0
#define TOK_ws 258
#define TOK_ws_opcode 259
#define TOK_global 260
#define TOK_connection 261
#define TOK_ptr 262
#define TOK_uid 263
#define TOK_regex 264
#define TOK_ellipsis 265
#define string_token 266
#define class_range_token 267
#define repeat_range_token 268
#define quoted_string 269
#define filename 270
#define integer 271
#define TOK_ws_reserved_flag 260
#define TOK_global 261
#define TOK_connection 262
#define TOK_ptr 263
#define TOK_uid 264
#define TOK_regex 265
#define TOK_ellipsis 266
#define string_token 267
#define class_range_token 268
#define repeat_range_token 269
#define quoted_string 270
#define filename 271
#define integer 272



Expand Down Expand Up @@ -108,7 +110,7 @@ typedef union YYSTYPE


/* Line 2058 of yacc.c */
#line 112 "tcpkali_expr_y.h"
#line 114 "tcpkali_expr_y.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
Expand Down
8 changes: 7 additions & 1 deletion src/tcpkali_expr_y.y
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int yyerror(tk_expr_t **, const char *);

%token TOK_ws "ws"
%token <tv_opcode> TOK_ws_opcode "text, binary, close, ping, pong, continuation"
%token <tv_long> TOK_ws_reserved_flag "rsv1, rsv2, rsv3"
%token TOK_global "global"
%token TOK_connection "connection"
%token TOK_ptr " ptr"
Expand Down Expand Up @@ -176,10 +177,15 @@ NumericExpr:
WSFrameFinalized:
WSFrameWithData
/* \{ws.ping ...} (yes, tree dots!) */
| WSFrameWithData TOK_ellipsis {
| WSFrameFinalized TOK_ellipsis {
$$ = $1;
$$->u.ws_frame.fin = 0; /* Expect continuation. */
}
/* \{ws.ping rsv1} */
| WSFrameFinalized TOK_ws_reserved_flag {
$$ = $1;
$$->u.ws_frame.rsvs |= $2;
}

WSFrameWithData:
WSBasicFrame
Expand Down
6 changes: 3 additions & 3 deletions src/tcpkali_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ transport_spec_from_message_collection(struct transport_data_spec *out_spec,
&& snip->flags & MSK_FRAMING_REQUESTED) {
estimate_ws_frame_size = websocket_frame_header(
tptr, data_spec->allocated_size - data_spec->total_size,
ws_side, WS_OP_TEXT_FRAME, 1,
ws_side, WS_OP_TEXT_FRAME, 0, 1,
snip->expr->estimate_size);
tptr += estimate_ws_frame_size;
}
Expand Down Expand Up @@ -413,7 +413,7 @@ transport_spec_from_message_collection(struct transport_data_spec *out_spec,
ws_frame_size = websocket_frame_header(
tptr,
data_spec->allocated_size - data_spec->total_size,
ws_side, WS_OP_TEXT_FRAME, 1, size);
ws_side, WS_OP_TEXT_FRAME, 0, 1, size);
/*
* Most of the time websocket frame will have the
* same length as the estimated one
Expand All @@ -435,7 +435,7 @@ transport_spec_from_message_collection(struct transport_data_spec *out_spec,
ws_frame_size = websocket_frame_header(
(uint8_t *)data_spec->ptr + data_spec->total_size,
data_spec->allocated_size - data_spec->total_size,
ws_side, WS_OP_TEXT_FRAME, 1, size);
ws_side, WS_OP_TEXT_FRAME, 0, 1, size);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tcpkali_websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
size_t
websocket_frame_header(uint8_t *buf, size_t size, enum websocket_side side,
enum ws_frame_opcode opcode, int fin,
enum ws_frame_opcode opcode, int reserved, int fin,
size_t payload_size) {
uint8_t tmpbuf[WEBSOCKET_MAX_FRAME_HDR_SIZE];
uint8_t *orig_buf_ptr;
Expand All @@ -67,7 +67,7 @@ websocket_frame_header(uint8_t *buf, size_t size, enum websocket_side side,
enum ws_frame_opcode opcode : 4;
unsigned int rsvs : 3;
unsigned int fin : 1;
} first_byte = {.opcode = opcode, .fin = (fin != 0)};
} first_byte = {.opcode = opcode, .rsvs = reserved, .fin = (fin != 0)};

*buf++ = *(uint8_t *)&first_byte;

Expand Down
2 changes: 1 addition & 1 deletion src/tcpkali_websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum websocket_side {
WS_SIDE_SERVER,
};
size_t websocket_frame_header(uint8_t *buf, size_t size, enum websocket_side,
enum ws_frame_opcode, int fin,
enum ws_frame_opcode, int reserved, int fin,
size_t payload_size);

/*
Expand Down

0 comments on commit 5b147fe

Please sign in to comment.