使用自定义的udp_hdr替换linux的udphdr

This commit is contained in:
luwenpeng
2023-02-17 17:53:21 +08:00
parent 0ba7fefba5
commit 551abde887
6 changed files with 33 additions and 25 deletions

View File

@@ -8,6 +8,7 @@
#include "log.h"
#include "sce.h"
#include "utils.h"
#include "g_vxlan.h"
#include "ctrl_packet.h"
@@ -759,7 +760,7 @@ static enum inject_pkt_action handle_inject_packet(struct packet_io *handle, mar
struct metadata meta;
memset(&meta, 0, sizeof(struct metadata));
meta.raw_data = (char *)g_vxlan_hdr + sizeof(struct g_vxlan);
meta.raw_len = raw_len - sizeof(struct ethhdr) - sizeof(struct ip) - sizeof(struct udphdr) - sizeof(struct g_vxlan);
meta.raw_len = raw_len - sizeof(struct ethhdr) - sizeof(struct ip) - sizeof(struct udp_hdr) - sizeof(struct g_vxlan);
meta.dir_is_e2i = g_vxlan_get_packet_dir(g_vxlan_hdr);
meta.traffic_is_decrypted = g_vxlan_get_traffic_type(g_vxlan_hdr);
meta.is_ctrl_pkt = 0;
@@ -879,10 +880,10 @@ static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff
// TODO get dst mac by dst ip
marsio_buff_reset(rx_buff);
struct ethhdr *eth_hdr = (struct ethhdr *)marsio_buff_prepend(rx_buff, sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udphdr) + sizeof(struct g_vxlan));
struct ethhdr *eth_hdr = (struct ethhdr *)marsio_buff_prepend(rx_buff, sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan));
struct ip *ip_hdr = (struct ip *)((char *)eth_hdr + sizeof(struct ethhdr));
struct udphdr *udp_hdr = (struct udphdr *)((char *)ip_hdr + sizeof(struct ip));
struct g_vxlan *g_vxlan_hdr = (struct g_vxlan *)((char *)udp_hdr + sizeof(struct udphdr));
struct udp_hdr *udp_hdr = (struct udp_hdr *)((char *)ip_hdr + sizeof(struct ip));
struct g_vxlan *g_vxlan_hdr = (struct g_vxlan *)((char *)udp_hdr + sizeof(struct udp_hdr));
memset(g_vxlan_hdr, 0, sizeof(struct g_vxlan));
g_vxlan_set_packet_dir(g_vxlan_hdr, meta->dir_is_e2i);
@@ -890,7 +891,7 @@ static int forward_packet_to_sf(struct packet_io *handle, marsio_buff_t *rx_buff
g_vxlan_set_traffic_type(g_vxlan_hdr, meta->traffic_is_decrypted);
build_ether_header(eth_hdr, ETH_P_IP, handle->config.default_src_mac, handle->config.default_dst_mac);
build_ip_header(ip_hdr, IPPROTO_UDP, handle->config.default_src_ip, handle->config.default_dst_ip, sizeof(struct udphdr) + sizeof(struct g_vxlan) + meta->raw_len);
build_ip_header(ip_hdr, IPPROTO_UDP, handle->config.default_src_ip, handle->config.default_dst_ip, sizeof(struct udp_hdr) + sizeof(struct g_vxlan) + meta->raw_len);
build_udp_header((const char *)&ip_hdr->ip_src, 8, udp_hdr, meta->session_id % (65535 - 49152) + 49152, 4789, sizeof(struct g_vxlan) + meta->raw_len);
if (marsio_send_burst(handle->dev_endpoint.mr_path, thread_seq, &rx_buff, 1) != 0)
@@ -1016,7 +1017,7 @@ static void forward_all_sf_packet_to_nf(struct packet_io *handle, marsio_buff_t
struct metadata meta;
memset(&meta, 0, sizeof(struct metadata));
meta.raw_data = (char *)g_vxlan_hdr + sizeof(struct g_vxlan);
meta.raw_len = raw_len - sizeof(struct ethhdr) - sizeof(struct ip) - sizeof(struct udphdr) - sizeof(struct g_vxlan);
meta.raw_len = raw_len - sizeof(struct ethhdr) - sizeof(struct ip) - sizeof(struct udp_hdr) - sizeof(struct g_vxlan);
meta.dir_is_e2i = g_vxlan_get_packet_dir(g_vxlan_hdr);
meta.traffic_is_decrypted = g_vxlan_get_traffic_type(g_vxlan_hdr);
meta.is_ctrl_pkt = 0;