feature: packet IO support IP reassembly
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
#include "packet_parser.h"
|
||||
#include "packet_internal.h"
|
||||
|
||||
#define PACKET_CRAFT_LOG_DEBUG(format, ...) STELLAR_LOG_DEBUG(__thread_local_logger, "packet craft", format, ##__VA_ARGS__)
|
||||
#define PACKET_CRAFT_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet craft", format, ##__VA_ARGS__)
|
||||
#define PACKET_BUILD_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet build", format, ##__VA_ARGS__)
|
||||
|
||||
struct fingerprint
|
||||
{
|
||||
@@ -79,7 +78,7 @@ static void update_gtp1_hdr(struct gtp1_hdr *gtp, int trim_len)
|
||||
gtp1_hdr_set_msg_len(gtp, msg_len - trim_len);
|
||||
if (gtp1_hdr_get_seq_flag(gtp) && gtp1_hdr_get_seq(gtp))
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("build packets may be dropped by intermediate devices, the GTPv1 layer requires a sequence number");
|
||||
PACKET_BUILD_LOG_ERROR("build packets may be dropped by intermediate devices, the GTPv1 layer requires a sequence number");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ static void update_gtp2_hdr(struct gtp2_hdr *gtp, int trim_len)
|
||||
gtp2_hdr_set_msg_len(gtp, msg_len - trim_len);
|
||||
if (gtp2_hdr_get_seq(gtp))
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("build packets may be dropped by intermediate devices, the GTPv2 layer requires a sequence number");
|
||||
PACKET_BUILD_LOG_ERROR("build packets may be dropped by intermediate devices, the GTPv2 layer requires a sequence number");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +255,7 @@ struct packet *packet_build_tcp(const struct packet *origin_pkt, uint32_t tcp_se
|
||||
(tcp_payload == NULL && tcp_payload_len != 0) || (tcp_payload != NULL && tcp_payload_len == 0) ||
|
||||
(tcp_options_len && tcp_options_len % 4 != 0))
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft TCP packet failed, invalid arguments");
|
||||
PACKET_BUILD_LOG_ERROR("build TCP packet failed, invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -265,7 +264,7 @@ struct packet *packet_build_tcp(const struct packet *origin_pkt, uint32_t tcp_se
|
||||
const struct layer_private *tcp_layer = packet_get_layer(origin_pkt, layer_count - 1);
|
||||
if (tcp_layer == NULL || tcp_layer->proto != LAYER_PROTO_TCP)
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft TCP packet failed, the innermost layer of the original packet is not TCP");
|
||||
PACKET_BUILD_LOG_ERROR("build TCP packet failed, the innermost layer of the original packet is not TCP");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -275,7 +274,7 @@ struct packet *packet_build_tcp(const struct packet *origin_pkt, uint32_t tcp_se
|
||||
struct packet *new_pkt = packet_new(new_pkt_len);
|
||||
if (new_pkt == NULL)
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft TCP packet failed, no space to allocate new packet");
|
||||
PACKET_BUILD_LOG_ERROR("build TCP packet failed, no space to allocate new packet");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -297,7 +296,14 @@ struct packet *packet_build_tcp(const struct packet *origin_pkt, uint32_t tcp_se
|
||||
|
||||
packet_parse(new_pkt, new_pkt_data, new_pkt_len);
|
||||
memcpy(&new_pkt->meta, &origin_pkt->meta, sizeof(struct metadata));
|
||||
new_pkt->meta.origin_ctx = NULL;
|
||||
struct packet_origin origin = {
|
||||
.type = ORIGIN_TYPE_USER,
|
||||
.ctx = NULL,
|
||||
.cb = NULL,
|
||||
.args = NULL,
|
||||
.thr_idx = -1,
|
||||
};
|
||||
packet_set_origin(new_pkt, &origin);
|
||||
|
||||
return new_pkt;
|
||||
}
|
||||
@@ -307,7 +313,7 @@ struct packet *packet_build_udp(const struct packet *origin_pkt, const char *udp
|
||||
// check arguments
|
||||
if (origin_pkt == NULL || (udp_payload == NULL && udp_payload_len != 0) || (udp_payload != NULL && udp_payload_len == 0))
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft UDP packet failed, invalid arguments");
|
||||
PACKET_BUILD_LOG_ERROR("build UDP packet failed, invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -316,7 +322,7 @@ struct packet *packet_build_udp(const struct packet *origin_pkt, const char *udp
|
||||
const struct layer_private *udp_layer = packet_get_layer(origin_pkt, layer_count - 1);
|
||||
if (udp_layer == NULL || udp_layer->proto != LAYER_PROTO_UDP)
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft UDP packet failed, the innermost layer of the original packet is not UDP");
|
||||
PACKET_BUILD_LOG_ERROR("build UDP packet failed, the innermost layer of the original packet is not UDP");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -326,7 +332,7 @@ struct packet *packet_build_udp(const struct packet *origin_pkt, const char *udp
|
||||
struct packet *new_pkt = packet_new(new_pkt_len);
|
||||
if (new_pkt == NULL)
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft UDP packet failed, no space to allocate new packet");
|
||||
PACKET_BUILD_LOG_ERROR("build UDP packet failed, no space to allocate new packet");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -339,7 +345,14 @@ struct packet *packet_build_udp(const struct packet *origin_pkt, const char *udp
|
||||
|
||||
packet_parse(new_pkt, new_pkt_data, new_pkt_len);
|
||||
memcpy(&new_pkt->meta, &origin_pkt->meta, sizeof(struct metadata));
|
||||
new_pkt->meta.origin_ctx = NULL;
|
||||
struct packet_origin origin = {
|
||||
.type = ORIGIN_TYPE_USER,
|
||||
.ctx = NULL,
|
||||
.cb = NULL,
|
||||
.args = NULL,
|
||||
.thr_idx = -1,
|
||||
};
|
||||
packet_set_origin(new_pkt, &origin);
|
||||
|
||||
return new_pkt;
|
||||
}
|
||||
@@ -348,7 +361,7 @@ struct packet *packet_build_l3(const struct packet *origin_pkt, uint8_t ip_proto
|
||||
{
|
||||
if (origin_pkt == NULL || (l3_payload == NULL && l3_payload_len != 0) || (l3_payload != NULL && l3_payload_len == 0))
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft L3 packet failed, invalid arguments");
|
||||
PACKET_BUILD_LOG_ERROR("build L3 packet failed, invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -369,7 +382,7 @@ struct packet *packet_build_l3(const struct packet *origin_pkt, uint8_t ip_proto
|
||||
}
|
||||
if (l3_layer == NULL)
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft L3 packet failed, the original packet does not contain an IP layer");
|
||||
PACKET_BUILD_LOG_ERROR("build L3 packet failed, the original packet does not contain an IP layer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -382,7 +395,7 @@ struct packet *packet_build_l3(const struct packet *origin_pkt, uint8_t ip_proto
|
||||
struct packet *new_pkt = packet_new(new_pkt_len);
|
||||
if (new_pkt == NULL)
|
||||
{
|
||||
PACKET_CRAFT_LOG_ERROR("craft L3 packet failed, no space to allocate new packet");
|
||||
PACKET_BUILD_LOG_ERROR("build L3 packet failed, no space to allocate new packet");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -408,7 +421,14 @@ struct packet *packet_build_l3(const struct packet *origin_pkt, uint8_t ip_proto
|
||||
|
||||
packet_parse(new_pkt, new_pkt_data, new_pkt_len);
|
||||
memcpy(&new_pkt->meta, &origin_pkt->meta, sizeof(struct metadata));
|
||||
new_pkt->meta.origin_ctx = NULL;
|
||||
struct packet_origin origin = {
|
||||
.type = ORIGIN_TYPE_USER,
|
||||
.ctx = NULL,
|
||||
.cb = NULL,
|
||||
.args = NULL,
|
||||
.thr_idx = -1,
|
||||
};
|
||||
packet_set_origin(new_pkt, &origin);
|
||||
|
||||
return new_pkt;
|
||||
}
|
||||
Reference in New Issue
Block a user