inject TCP RST test pass
This commit is contained in:
@@ -16,7 +16,7 @@ extern "C"
|
||||
#define PACKET_MAX_LAYERS 32
|
||||
#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__)
|
||||
#define PACKET_LOG_DEBUG(format, ...) void(0)
|
||||
//#define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
||||
// #define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
||||
|
||||
enum ldbc_method
|
||||
{
|
||||
@@ -29,9 +29,10 @@ enum ldbc_method
|
||||
|
||||
enum packet_origin
|
||||
{
|
||||
PACKET_ORIGIN_MARSIO = 0x1,
|
||||
PACKET_ORIGIN_DUMPFILE = 0x2,
|
||||
PACKET_ORIGIN_USER = 0x3,
|
||||
PACKET_ORIGIN_MARSIO = 0x1, // packet data in mbuff (eg: packet I/O mrzcpd mode)
|
||||
PACKET_ORIGIN_DUMPFILE = 0x2, // packet data in pcap (eg: packet I/O dumpfile mode)
|
||||
PACKET_ORIGIN_USERSTACK = 0x3, // packet data in user stack (eg: inject packet)
|
||||
PACKET_ORIGIN_USERHEAP = 0x4, // packet data in user heap (eg: ip reassembly)
|
||||
};
|
||||
|
||||
struct packet
|
||||
@@ -45,7 +46,7 @@ struct packet
|
||||
uint16_t data_len;
|
||||
|
||||
int need_drop;
|
||||
void *io_ctx;
|
||||
void *origin_ctx; // mbuff or pcap pointer
|
||||
enum packet_origin origin;
|
||||
};
|
||||
|
||||
@@ -64,8 +65,8 @@ uint64_t packet_get_hash(const struct packet *pkt, enum ldbc_method method, int
|
||||
void packet_set_origin(struct packet *pkt, enum packet_origin origin);
|
||||
enum packet_origin packet_get_origin(const struct packet *pkt);
|
||||
|
||||
void packet_set_io_ctx(struct packet *pkt, void *ctx);
|
||||
void *packet_get_io_ctx(const struct packet *pkt);
|
||||
void packet_set_origin_ctx(struct packet *pkt, void *ctx);
|
||||
void *packet_get_origin_ctx(const struct packet *pkt);
|
||||
|
||||
int packet_is_fragment(const struct packet *pkt);
|
||||
|
||||
@@ -78,8 +79,14 @@ struct packet *packet_dup(const struct packet *pkt);
|
||||
void packet_set_domain(struct packet *pkt, uint64_t domain);
|
||||
uint64_t packet_get_domain(const struct packet *pkt);
|
||||
|
||||
void packet_set_route_ctx(struct packet *pkt, const char *route, int len);
|
||||
int packet_get_route_ctx(const struct packet *pkt, char *buff, int size); // return len of route ctx
|
||||
#define MAX_ROUTE_CTX 64
|
||||
struct route_ctx
|
||||
{
|
||||
char data[MAX_ROUTE_CTX];
|
||||
int used;
|
||||
};
|
||||
void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx);
|
||||
void packet_get_route_ctx(const struct packet *pkt, struct route_ctx *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -71,14 +71,14 @@ void packet_set_drop(struct packet *pkt)
|
||||
pkt->need_drop = 1;
|
||||
}
|
||||
|
||||
void packet_set_io_ctx(struct packet *pkt, void *ctx)
|
||||
void packet_set_origin_ctx(struct packet *pkt, void *ctx)
|
||||
{
|
||||
pkt->io_ctx = ctx;
|
||||
pkt->origin_ctx = ctx;
|
||||
}
|
||||
|
||||
void *packet_get_io_ctx(const struct packet *pkt)
|
||||
void *packet_get_origin_ctx(const struct packet *pkt)
|
||||
{
|
||||
return pkt->io_ctx;
|
||||
return pkt->origin_ctx;
|
||||
}
|
||||
|
||||
int packet_is_fragment(const struct packet *pkt)
|
||||
@@ -95,14 +95,14 @@ struct packet *packet_new(uint16_t pkt_len)
|
||||
}
|
||||
pkt->data_len = pkt_len;
|
||||
pkt->data_ptr = (const char *)pkt + sizeof(struct packet);
|
||||
pkt->origin = PACKET_ORIGIN_USER;
|
||||
pkt->origin = PACKET_ORIGIN_USERHEAP;
|
||||
|
||||
return pkt;
|
||||
}
|
||||
|
||||
void packet_free(struct packet *pkt)
|
||||
{
|
||||
if (pkt && pkt->origin == PACKET_ORIGIN_USER)
|
||||
if (pkt && pkt->origin == PACKET_ORIGIN_USERHEAP)
|
||||
{
|
||||
free((void *)pkt);
|
||||
}
|
||||
@@ -122,8 +122,8 @@ struct packet *packet_dup(const struct packet *pkt)
|
||||
}
|
||||
memcpy(dup_pkt, pkt, sizeof(struct packet));
|
||||
memcpy((char *)dup_pkt->data_ptr, pkt->data_ptr, pkt->data_len);
|
||||
dup_pkt->origin = PACKET_ORIGIN_USER;
|
||||
dup_pkt->io_ctx = dup_pkt;
|
||||
dup_pkt->origin = PACKET_ORIGIN_USERHEAP;
|
||||
dup_pkt->origin_ctx = NULL;
|
||||
|
||||
// update layers
|
||||
for (int8_t i = 0; i < pkt->layers_used; i++)
|
||||
@@ -149,22 +149,27 @@ void packet_set_ctrl(struct packet *pkt)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
marsio_buff_set_ctrlbuf(mbuff);
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to set ctrl");
|
||||
}
|
||||
}
|
||||
|
||||
int packet_is_ctrl(const struct packet *pkt)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
return marsio_buff_is_ctrlbuf(mbuff);
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to check ctrl");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -174,13 +179,17 @@ void packet_set_direction(struct packet *pkt, int dir)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_set_metadata(mbuff, MR_BUFF_DIR, &dir, sizeof(dir)) != 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to set direction");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to set direction");
|
||||
}
|
||||
}
|
||||
|
||||
// 1: E2I, 0: I2E
|
||||
@@ -189,13 +198,17 @@ int packet_get_direction(const struct packet *pkt)
|
||||
int direction = 0;
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_get_metadata(mbuff, MR_BUFF_DIR, &direction, sizeof(direction)) <= 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to get direction");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to get direction");
|
||||
}
|
||||
|
||||
return direction;
|
||||
}
|
||||
@@ -204,13 +217,17 @@ void packet_set_session_id(struct packet *pkt, uint64_t sess_id)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_set_metadata(mbuff, MR_BUFF_SESSION_ID, &sess_id, sizeof(sess_id)) != 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to set session id");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to set session id");
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t packet_get_session_id(const struct packet *pkt)
|
||||
@@ -218,13 +235,17 @@ uint64_t packet_get_session_id(const struct packet *pkt)
|
||||
uint64_t sess_id = 0;
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_get_metadata(mbuff, MR_BUFF_SESSION_ID, &sess_id, sizeof(sess_id)) <= 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to get session id");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to get session id");
|
||||
}
|
||||
|
||||
return sess_id;
|
||||
}
|
||||
@@ -233,7 +254,7 @@ void packet_set_domain(struct packet *pkt, uint64_t domain)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
// TODO
|
||||
#if 0
|
||||
@@ -243,6 +264,10 @@ void packet_set_domain(struct packet *pkt, uint64_t domain)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to set domain");
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t packet_get_domain(const struct packet *pkt)
|
||||
@@ -250,7 +275,7 @@ uint64_t packet_get_domain(const struct packet *pkt)
|
||||
uint64_t domain = 0;
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
// TODO
|
||||
#if 0
|
||||
@@ -260,89 +285,112 @@ uint64_t packet_get_domain(const struct packet *pkt)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to get domain");
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
void packet_set_route_ctx(struct packet *pkt, const char *route, int len)
|
||||
void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_set_metadata(mbuff, MR_BUFF_ROUTE_CTX, (void *)route, len) != 0)
|
||||
if (marsio_buff_set_metadata(mbuff, MR_BUFF_ROUTE_CTX, (void *)ctx->data, ctx->used) != 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to set route ctx");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to set route ctx");
|
||||
}
|
||||
}
|
||||
|
||||
// return len of route ctx
|
||||
int packet_get_route_ctx(const struct packet *pkt, char *buff, int size)
|
||||
void packet_get_route_ctx(const struct packet *pkt, struct route_ctx *ctx)
|
||||
{
|
||||
int len = 0;
|
||||
ctx->used = 0;
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
len = marsio_buff_get_metadata(mbuff, MR_BUFF_ROUTE_CTX, buff, size);
|
||||
if (len <= 0)
|
||||
ctx->used = marsio_buff_get_metadata(mbuff, MR_BUFF_ROUTE_CTX, ctx->data, sizeof(ctx->data));
|
||||
if (ctx->used <= 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to get route ctx");
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to get route ctx");
|
||||
}
|
||||
}
|
||||
|
||||
void packet_set_sid_list(struct packet *pkt, uint16_t *sid, int num)
|
||||
void packet_set_sid_list(struct packet *pkt, const struct sid_list *list)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_set_sid_list(mbuff, sid, num) != 0)
|
||||
if (marsio_buff_set_sid_list(mbuff, (sid_t *)list->sid, list->used) != 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to set sid list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return number of sid
|
||||
int packet_get_sid_list(const struct packet *pkt, uint16_t *sid, int num)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
else
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
return marsio_buff_get_sid_list(mbuff, sid, num);
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to set sid list");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void packet_prepend_sid_list(struct packet *pkt, uint16_t *sid, int num)
|
||||
void packet_get_sid_list(const struct packet *pkt, struct sid_list *list)
|
||||
{
|
||||
list->used = 0;
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
list->used = marsio_buff_get_sid_list(mbuff, (sid_t *)list->sid, sizeof(list->sid) / sizeof(list->sid[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to get sid list");
|
||||
}
|
||||
}
|
||||
|
||||
void packet_prepend_sid_list(struct packet *pkt, const struct sid_list *list)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_prepend_sid_list(mbuff, sid, num) != 0)
|
||||
if (marsio_buff_prepend_sid_list(mbuff, (sid_t *)list->sid, list->used) != 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to prepend sid list");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to prepend sid list");
|
||||
}
|
||||
}
|
||||
|
||||
void packet_append_sid_list(struct packet *pkt, uint16_t *sid, int num)
|
||||
void packet_append_sid_list(struct packet *pkt, const struct sid_list *list)
|
||||
{
|
||||
if (packet_get_origin(pkt) == PACKET_ORIGIN_MARSIO)
|
||||
{
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_origin_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
if (marsio_buff_append_sid_list(mbuff, sid, num) != 0)
|
||||
if (marsio_buff_append_sid_list(mbuff, (sid_t *)list->sid, list->used) != 0)
|
||||
{
|
||||
PACKET_LOG_ERROR("failed to append sid list");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_LOG_ERROR("packet origin is not marsio, failed to append sid list");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user