Refactored packet API to support struct layer (using union to contain different types of encapsulation headers)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "macro.h"
|
||||
#include "dumpfile_io.h"
|
||||
#include "packet_priv.h"
|
||||
#include "packet_utils.h"
|
||||
#include "lock_free_queue.h"
|
||||
|
||||
#define MAX_PACKET_QUEUE_SIZE (4096 * 1000)
|
||||
@@ -81,7 +82,7 @@ static void save_packet(const char *work_dir, struct packet *pkt, uint64_t idx)
|
||||
char src_addr[INET6_ADDRSTRLEN] = {0};
|
||||
char dst_addr[INET6_ADDRSTRLEN] = {0};
|
||||
|
||||
len = packet_get_len(pkt);
|
||||
len = packet_get_raw_len(pkt);
|
||||
memset(&tuple, 0, sizeof(struct tuple6));
|
||||
packet_get_innermost_tuple6(pkt, &tuple);
|
||||
|
||||
@@ -109,7 +110,7 @@ static void save_packet(const char *work_dir, struct packet *pkt, uint64_t idx)
|
||||
|
||||
fwrite(&DEFAULT_PCAP_FILE_HDR, sizeof(DEFAULT_PCAP_FILE_HDR), 1, fp);
|
||||
fwrite(&pcap_hdr, sizeof(struct pcap_pkt_hdr), 1, fp);
|
||||
fwrite(packet_get_data(pkt), 1, len, fp);
|
||||
fwrite(packet_get_raw_data(pkt), 1, len, fp);
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
PACKET_IO_LOG_STATE("save packet to %s", file);
|
||||
@@ -200,6 +201,7 @@ static void pcap_packet_handler(u_char *user, const struct pcap_pkthdr *h, const
|
||||
|
||||
// calculate packet hash
|
||||
struct packet pkt;
|
||||
memset(&pkt, 0, sizeof(struct packet));
|
||||
packet_parse(&pkt, pcap_pkt->data, pcap_pkt->len);
|
||||
uint64_t hash = packet_get_hash(&pkt, LDBC_METHOD_HASH_INT_IP_AND_EXT_IP, 0);
|
||||
|
||||
@@ -400,7 +402,6 @@ int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct pac
|
||||
memset(pkt, 0, sizeof(struct packet));
|
||||
packet_parse(pkt, pcap_pkt->data, pcap_pkt->len);
|
||||
packet_set_origin_ctx(pkt, pcap_pkt);
|
||||
packet_set_origin(pkt, PACKET_ORIGIN_DUMPFILE);
|
||||
packet_set_action(pkt, PACKET_ACTION_FORWARD);
|
||||
nr_parsed++;
|
||||
}
|
||||
@@ -418,7 +419,7 @@ void dumpfile_io_egress(struct dumpfile_io *handle, uint16_t thr_idx, struct pac
|
||||
for (int i = 0; i < nr_pkts; i++)
|
||||
{
|
||||
pkt = &pkts[i];
|
||||
len = packet_get_len(pkt);
|
||||
len = packet_get_raw_len(pkt);
|
||||
|
||||
stat->dev_tx_pkts++;
|
||||
stat->dev_tx_bytes += len;
|
||||
@@ -447,7 +448,7 @@ void dumpfile_io_drop(struct dumpfile_io *handle, uint16_t thr_idx, struct packe
|
||||
if (pcap_pkt)
|
||||
{
|
||||
stat->drop_pkts++;
|
||||
stat->drop_bytes += packet_get_len(pkt);
|
||||
stat->drop_bytes += packet_get_raw_len(pkt);
|
||||
free(pcap_pkt);
|
||||
}
|
||||
packet_free(pkt);
|
||||
@@ -463,7 +464,7 @@ int dumpfile_io_inject(struct dumpfile_io *handle, uint16_t thr_idx, struct pack
|
||||
for (int i = 0; i < nr_pkts; i++)
|
||||
{
|
||||
pkt = &pkts[i];
|
||||
len = packet_get_len(pkt);
|
||||
len = packet_get_raw_len(pkt);
|
||||
|
||||
stat->inject_pkts++;
|
||||
stat->inject_bytes += len;
|
||||
|
||||
Reference in New Issue
Block a user