update inject packet API
This commit is contained in:
@@ -54,7 +54,8 @@ uint16_t stellar_get_current_thread_index();
|
||||
// return inject packet length, return 0 if failed
|
||||
int stellar_inject_tcp_rst(struct stellar *st, const struct session *sess, enum flow_direction inject_dir);
|
||||
int stellar_inject_tcp_fin(struct stellar *st, const struct session *sess, enum flow_direction inject_dir);
|
||||
int stellar_inject_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len);
|
||||
int stellar_inject_tcp_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len);
|
||||
int stellar_inject_udp_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len);
|
||||
int stellar_inject_ctrl_msg(struct stellar *st, const struct session *sess, const struct sid_list *sids, const char *msg, uint16_t len);
|
||||
|
||||
int stellar_main(int argc, char **argv);
|
||||
|
||||
@@ -543,17 +543,14 @@ int stellar_inject_tcp_fin(struct stellar *st, const struct session *sess, enum
|
||||
return inject_tcp_packet(st, sess, inject_dir, TH_FIN | TH_ACK, NULL, 0);
|
||||
}
|
||||
|
||||
int stellar_inject_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
int stellar_inject_tcp_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
{
|
||||
switch (session_get_type(sess))
|
||||
{
|
||||
case SESSION_TYPE_TCP:
|
||||
return inject_tcp_packet(st, sess, inject_dir, TH_ACK, payload, len);
|
||||
case SESSION_TYPE_UDP:
|
||||
}
|
||||
|
||||
int stellar_inject_udp_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
{
|
||||
return inject_udp_packet(st, sess, inject_dir, payload, len);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int stellar_inject_ctrl_msg(struct stellar *st, const struct session *sess, const struct sid_list *sids, const char *msg, uint16_t len)
|
||||
|
||||
@@ -59,7 +59,8 @@ global:
|
||||
stellar_get_current_thread_index;
|
||||
stellar_inject_tcp_rst;
|
||||
stellar_inject_tcp_fin;
|
||||
stellar_inject_payload;
|
||||
stellar_inject_tcp_payload;
|
||||
stellar_inject_udp_payload;
|
||||
stellar_inject_ctrl_msg;
|
||||
stellar_main;
|
||||
|
||||
|
||||
@@ -82,16 +82,16 @@ static void on_sess_msg(struct session *sess, int topic_id, const void *msg, voi
|
||||
break;
|
||||
case INJECT_TYPE_TCP_PAYLOAD:
|
||||
snprintf(buffer, sizeof(buffer), "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s", 5 + 5 + 2, "Hello");
|
||||
stellar_inject_payload(ctx->st, sess, FLOW_DIRECTION_S2C, buffer, strlen(buffer)); // inject payload to client
|
||||
stellar_inject_payload(ctx->st, sess, FLOW_DIRECTION_S2C, "World\r\n", 7); // inject payload to client
|
||||
stellar_inject_tcp_payload(ctx->st, sess, FLOW_DIRECTION_S2C, buffer, strlen(buffer)); // inject payload to client
|
||||
stellar_inject_tcp_payload(ctx->st, sess, FLOW_DIRECTION_S2C, "World\r\n", 7); // inject payload to client
|
||||
stellar_inject_tcp_rst(ctx->st, sess, FLOW_DIRECTION_S2C); // inject RST to client
|
||||
stellar_inject_tcp_rst(ctx->st, sess, FLOW_DIRECTION_C2S); // 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");
|
||||
stellar_inject_payload(ctx->st, sess, FLOW_DIRECTION_S2C, buffer, strlen(buffer)); // inject payload to client
|
||||
stellar_inject_payload(ctx->st, sess, FLOW_DIRECTION_S2C, "World\r\n", 7); // inject payload to client
|
||||
stellar_inject_tcp_payload(ctx->st, sess, FLOW_DIRECTION_S2C, buffer, strlen(buffer)); // inject payload to client
|
||||
stellar_inject_tcp_payload(ctx->st, sess, FLOW_DIRECTION_S2C, "World\r\n", 7); // inject payload to client
|
||||
stellar_inject_tcp_fin(ctx->st, sess, FLOW_DIRECTION_S2C); // inject FIN to client
|
||||
stellar_inject_tcp_rst(ctx->st, sess, FLOW_DIRECTION_S2C); // inject RST to client
|
||||
stellar_inject_tcp_fin(ctx->st, sess, FLOW_DIRECTION_C2S); // inject FIN to server
|
||||
@@ -99,8 +99,8 @@ static void on_sess_msg(struct session *sess, int topic_id, const void *msg, voi
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_TYPE_UDP_PAYLOAD:
|
||||
stellar_inject_payload(ctx->st, sess, FLOW_DIRECTION_C2S, "Hello Server", 12);
|
||||
stellar_inject_payload(ctx->st, sess, FLOW_DIRECTION_S2C, "Hello Client", 12);
|
||||
stellar_inject_udp_payload(ctx->st, sess, FLOW_DIRECTION_C2S, "Hello Server", 12);
|
||||
stellar_inject_udp_payload(ctx->st, sess, FLOW_DIRECTION_S2C, "Hello Client", 12);
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_TYPE_CTRL_MSG:
|
||||
|
||||
Reference in New Issue
Block a user