Add test case: inject IPv4 based (TCP payload & TCP FIN & TCP RST) packet after recv C2S first payload

This commit is contained in:
luwenpeng
2024-05-22 18:15:08 +08:00
parent 22f7ddb361
commit 570c93e616
14 changed files with 98 additions and 5 deletions

View File

@@ -32,8 +32,9 @@ enum inject_type
INJECT_TYPE_TCP_RST = 1,
INJECT_TYPE_TCP_FIN = 2,
INJECT_TYPE_TCP_PAYLOAD = 3,
INJECT_TYPE_UDP_PAYLOAD = 4,
INJECT_TYPE_CTRL_MSG = 5,
INJECT_TYPE_TCP_PAYLOAD_FIN_RST = 4,
INJECT_TYPE_UDP_PAYLOAD = 5,
INJECT_TYPE_CTRL_MSG = 6,
};
struct inject_rule
@@ -57,7 +58,7 @@ static void usage(char *cmd)
printf(" -h <ip> Host IP address\n");
printf(" -p <port> Port number\n");
printf(" -t <type> Type of manipulation\n");
printf(" Options: tcp-rst, tcp-fin, tcp-payload, udp-payload, ctrl-msg\n");
printf(" Options: tcp-rst, tcp-fin, tcp-payload, tcp-payload-fin-rst, udp-payload, ctrl-msg\n");
printf(" -c <condition> Condition for manipulation\n");
printf(" Options: c2s-packet, s2c-packet\n");
printf(" -n <number> Number of packets received before injecting action\n\n");
@@ -138,6 +139,10 @@ static int packet_injector_on_init(int argc, char **argv, struct inject_rule *ru
{
rule->inject_type = INJECT_TYPE_TCP_PAYLOAD;
}
else if (strcmp(type, "tcp-payload-fin-rst") == 0)
{
rule->inject_type = INJECT_TYPE_TCP_PAYLOAD_FIN_RST;
}
else if (strcmp(type, "udp-payload") == 0)
{
rule->inject_type = INJECT_TYPE_UDP_PAYLOAD;
@@ -245,6 +250,16 @@ static void packet_injector_on_msg(struct session *sess, int topic_id, const voi
EXPECT_TRUE(stellar_inject_tcp_rst(sess, FLOW_DIRECTION_C2S) > 0); // inject RST to server
session_set_discard(sess);
break;
case INJECT_TYPE_TCP_PAYLOAD_FIN_RST:
snprintf(buffer, sizeof(buffer), "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s", 5 + 5 + 2, "Hello");
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_S2C, buffer, strlen(buffer)) > 0); // inject payload to client
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_S2C, "World\r\n", 7) > 0); // inject payload to client
EXPECT_TRUE(stellar_inject_tcp_fin(sess, FLOW_DIRECTION_S2C) > 0); // inject FIN to client
EXPECT_TRUE(stellar_inject_tcp_rst(sess, FLOW_DIRECTION_S2C) > 0); // inject RST to client
EXPECT_TRUE(stellar_inject_tcp_fin(sess, FLOW_DIRECTION_C2S) > 0); // inject FIN to server
EXPECT_TRUE(stellar_inject_tcp_rst(sess, FLOW_DIRECTION_C2S) > 0); // inject RST to server
session_set_discard(sess);
break;
case INJECT_TYPE_UDP_PAYLOAD:
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_C2S, "Hello Server", 12) > 0);
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_S2C, "Hello Client", 12) > 0);