Skip to content

Commit

Permalink
stream-update command (tcp-flags)
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Feb 28, 2024
1 parent e3f983f commit e64d507
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const char *schema_all_args[] = {
"result-code", "error-code", "error-message",
"disconnect-code", "disconnect-protocol",
"disconnect-direction", "disconnect-message",
"ldp-instance-id",
"ldp-instance-id", "tcp-flags",
NULL
};

Expand Down Expand Up @@ -212,6 +212,7 @@ struct action actions[] = {
{"stream-start", bbl_stream_ctrl_start, schema_all_args, true},
{"stream-stop", bbl_stream_ctrl_stop, schema_all_args, true},
{"stream-stop-verfied", bbl_stream_ctrl_stop_verfied, schema_all_args, true},
{"stream-update", bbl_stream_ctrl_update, schema_all_args, true},
{"session-traffic-start", bbl_session_ctrl_traffic_start, schema_all_args, true},
{"session-traffic-stop", bbl_session_ctrl_traffic_stop, schema_all_args, true},
{"multicast-traffic-start", bbl_ctrl_multicast_traffic_start, schema_all_args, false},
Expand Down
50 changes: 50 additions & 0 deletions code/bngblaster/src/bbl_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,10 @@ bbl_stream_update_tcp(bbl_stream_s *stream)
uint8_t *tcp_buf = (uint8_t*)(stream->tx_buf + (stream->tx_len - tcp_len));
uint16_t *checksum = (uint16_t*)(tcp_buf+16);

if(stream->tcp_flags) {
*(tcp_buf+13) = stream->tcp_flags & 0x3f;
}

*checksum = 0;
if(stream->ipv6_src && stream->ipv6_dst) {
*checksum = bbl_ipv6_tcp_checksum(stream->ipv6_src, stream->ipv6_dst, tcp_buf, tcp_len);
Expand Down Expand Up @@ -2911,4 +2915,50 @@ int
bbl_stream_ctrl_stop_verfied(int fd, uint32_t session_id, json_t *arguments)
{
return bbl_stream_ctrl_enabled(fd, session_id, arguments, false, true);
}

int
bbl_stream_ctrl_update(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments)
{
bbl_stream_s *stream;
const char *s = NULL;

int number = 0;
uint64_t flow_id;

/* Unpack further arguments */
if(json_unpack(arguments, "{s:i}", "flow-id", &number) != 0) {
return bbl_ctrl_status(fd, "error", 400, "missing flow-id");
}

uint8_t tcp_flags = 0;

if(json_unpack(arguments, "{s:s}", "tcp-flags", &s) == 0) {
if(strcmp(s, "ack") == 0) {
tcp_flags = 0x10;
} else if(strcmp(s, "fin") == 0) {
tcp_flags = 0x01;
} else if(strcmp(s, "fin-ack") == 0) {
tcp_flags = 0x11;
} else if(strcmp(s, "syn") == 0) {
tcp_flags = 0x02;
} else if(strcmp(s, "syn-ack") == 0) {
tcp_flags = 0x12;
} else if(strcmp(s, "rst") == 0) {
tcp_flags = 0x04;
} else {
return bbl_ctrl_status(fd, "error", 400, "invalid tcp-flags (ack|fin|fin-ack|syn|syn-ack|rst)");
}
}

flow_id = number;
stream = bbl_stream_index_get(flow_id);
if(stream) {
if(tcp_flags) {
stream->tcp_flags = tcp_flags;
}
} else {
return bbl_ctrl_status(fd, "warning", 404, "stream not found");
}
return bbl_ctrl_status(fd, "ok", 200, NULL);
}
4 changes: 4 additions & 0 deletions code/bngblaster/src/bbl_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef struct bbl_stream_
uint8_t type;
uint8_t sub_type;
uint8_t direction;
uint8_t tcp_flags;

bool enabled;
bool threaded;
Expand Down Expand Up @@ -269,4 +270,7 @@ bbl_stream_ctrl_stop(int fd, uint32_t session_id, json_t *arguments);
int
bbl_stream_ctrl_stop_verfied(int fd, uint32_t session_id, json_t *arguments);

int
bbl_stream_ctrl_update(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments);

#endif

0 comments on commit e64d507

Please sign in to comment.