test: add imitate_tcp_packet test case (TCP over GREv0: GRE enable checksum)
This commit is contained in:
@@ -317,28 +317,28 @@ static inline uint32_t uint32_add(uint32_t seq, uint32_t inc)
|
||||
return seq;
|
||||
}
|
||||
|
||||
static void imitate_and_send_udp_packet(struct stellar *st, struct session *sess, struct packet_exdata *pkt_exdata,
|
||||
enum flow_direction inject_dir, const char *udp_payload, uint16_t udp_payload_len)
|
||||
static void craft_and_send_udp_packet(struct stellar *st, struct session *sess, struct packet_exdata *pkt_exdata,
|
||||
enum flow_direction inject_dir, const char *udp_payload, uint16_t udp_payload_len)
|
||||
{
|
||||
const struct packet *origin_pkt = session_get_first_packet(sess, inject_dir);
|
||||
if (origin_pkt == NULL)
|
||||
{
|
||||
LOG_ERR("imitate UDP packet failed, %s origin packet is NULL\n", inject_dir == FLOW_DIRECTION_C2S ? "C2S" : "S2C");
|
||||
LOG_ERR("craft UDP packet failed, %s origin packet is NULL\n", inject_dir == FLOW_DIRECTION_C2S ? "C2S" : "S2C");
|
||||
return;
|
||||
}
|
||||
|
||||
struct packet *imitate_pkt = imitate_udp_packet(origin_pkt, udp_payload, udp_payload_len);
|
||||
if (imitate_pkt == NULL)
|
||||
struct packet *craft_pkt = craft_udp_packet(origin_pkt, udp_payload, udp_payload_len);
|
||||
if (craft_pkt == NULL)
|
||||
{
|
||||
LOG_ERR("imitate UDP packet failed\n");
|
||||
LOG_ERR("craft UDP packet failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
stellar_send_crafted_packet(st, imitate_pkt);
|
||||
stellar_send_crafted_packet(st, craft_pkt);
|
||||
}
|
||||
|
||||
static void imitate_and_send_tcp_packet(struct stellar *st, struct session *sess, struct packet_exdata *pkt_exdata,
|
||||
enum flow_direction inject_dir, uint8_t tcp_flags, const char *tcp_payload, uint16_t tcp_payload_len)
|
||||
static void craft_and_send_tcp_packet(struct stellar *st, struct session *sess, struct packet_exdata *pkt_exdata,
|
||||
enum flow_direction inject_dir, uint8_t tcp_flags, const char *tcp_payload, uint16_t tcp_payload_len)
|
||||
{
|
||||
uint32_t tcp_seq = 0;
|
||||
uint32_t tcp_ack = 0;
|
||||
@@ -384,18 +384,18 @@ static void imitate_and_send_tcp_packet(struct stellar *st, struct session *sess
|
||||
const struct packet *origin_pkt = session_get_first_packet(sess, inject_dir);
|
||||
if (origin_pkt == NULL)
|
||||
{
|
||||
LOG_ERR("imitate TCP packet failed, %s origin packet is NULL\n", inject_dir == FLOW_DIRECTION_C2S ? "C2S" : "S2C");
|
||||
LOG_ERR("craft TCP packet failed, %s origin packet is NULL\n", inject_dir == FLOW_DIRECTION_C2S ? "C2S" : "S2C");
|
||||
return;
|
||||
}
|
||||
|
||||
struct packet *imitate_pkt = imitate_tcp_packet(origin_pkt, tcp_seq, tcp_ack, tcp_flags, NULL, 0, tcp_payload, tcp_payload_len);
|
||||
if (imitate_pkt == NULL)
|
||||
struct packet *craft_pkt = craft_tcp_packet(origin_pkt, tcp_seq, tcp_ack, tcp_flags, NULL, 0, tcp_payload, tcp_payload_len);
|
||||
if (craft_pkt == NULL)
|
||||
{
|
||||
LOG_ERR("imitate TCP packet failed\n");
|
||||
LOG_ERR("craft TCP packet failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
stellar_send_crafted_packet(st, imitate_pkt);
|
||||
stellar_send_crafted_packet(st, craft_pkt);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -480,36 +480,36 @@ static void on_sess_msg(struct session *sess, int topic_id, const void *msg, voi
|
||||
switch (config->type)
|
||||
{
|
||||
case INJECT_TCP_RST:
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_RST | TH_ACK, NULL, 0);
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_RST | TH_ACK, NULL, 0);
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_RST | TH_ACK, NULL, 0);
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_RST | TH_ACK, NULL, 0);
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_TCP_FIN:
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_FIN | TH_ACK, NULL, 0);
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_FIN | TH_ACK, NULL, 0);
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_FIN | TH_ACK, NULL, 0);
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_FIN | TH_ACK, NULL, 0);
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_TCP_PAYLOAD:
|
||||
snprintf(buffer, sizeof(buffer), "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s", 5 + 5 + 2, "Hello");
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, buffer, strlen(buffer)); // inject payload to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, "World\r\n", 7); // inject payload to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_RST | TH_ACK, NULL, 0); // inject RST to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_RST | TH_ACK, NULL, 0); // inject RST to server
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, buffer, strlen(buffer)); // inject payload to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, "World\r\n", 7); // inject payload to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_RST | TH_ACK, NULL, 0); // inject RST to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_RST | TH_ACK, NULL, 0); // inject RST to server
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_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");
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, buffer, strlen(buffer)); // inject payload to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, "World\r\n", 7); // inject payload to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_FIN | TH_ACK, NULL, 0); // inject FIN to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_RST | TH_ACK, NULL, 0); // inject RST to client
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_FIN | TH_ACK, NULL, 0); // inject FIN to server
|
||||
imitate_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_RST | TH_ACK, NULL, 0); // inject RST to server
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, buffer, strlen(buffer)); // inject payload to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_ACK, "World\r\n", 7); // inject payload to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_FIN | TH_ACK, NULL, 0); // inject FIN to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, TH_RST | TH_ACK, NULL, 0); // inject RST to client
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_FIN | TH_ACK, NULL, 0); // inject FIN to server
|
||||
craft_and_send_tcp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, TH_RST | TH_ACK, NULL, 0); // inject RST to server
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_UDP_PAYLOAD:
|
||||
imitate_and_send_udp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, "Hello Server", 12);
|
||||
imitate_and_send_udp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, "Hello Client", 12);
|
||||
craft_and_send_udp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_C2S, "Hello Server", 12);
|
||||
craft_and_send_udp_packet(st, sess, &pkt_exdata, FLOW_DIRECTION_S2C, "Hello Client", 12);
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_CTRL_MSG:
|
||||
|
||||
Reference in New Issue
Block a user