TSG-13630 tsg-service-chaining-engine使用mrzcpd捕获报文/回注报文
TSG-13685 tsg-service-chaining-engine使用VXLAN封装Steering/Mirroring的Package
This commit is contained in:
67
common/src/g_vxlan.cpp
Normal file
67
common/src/g_vxlan.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ether.h>
|
||||
|
||||
#include "g_vxlan.h"
|
||||
|
||||
void g_vxlan_set_packet_dir(struct g_vxlan *hdr, int dir_is_e2i)
|
||||
{
|
||||
hdr->dir_is_e2i = (!!dir_is_e2i);
|
||||
}
|
||||
|
||||
void g_vxlan_set_chain_index(struct g_vxlan *hdr, int chain_index)
|
||||
{
|
||||
hdr->chain_index = (0x1f & chain_index);
|
||||
}
|
||||
|
||||
void g_vxlan_set_traffic_type(struct g_vxlan *hdr, int traffic_is_decrypted)
|
||||
{
|
||||
hdr->traffic_is_decrypted = (!!traffic_is_decrypted);
|
||||
}
|
||||
|
||||
int g_vxlan_get_packet_dir(struct g_vxlan *hdr)
|
||||
{
|
||||
return (!!hdr->dir_is_e2i);
|
||||
}
|
||||
|
||||
int g_vxlan_get_chain_index(struct g_vxlan *hdr)
|
||||
{
|
||||
return hdr->chain_index;
|
||||
}
|
||||
|
||||
int g_vxlan_get_traffic_type(struct g_vxlan *hdr)
|
||||
{
|
||||
return (!!hdr->traffic_is_decrypted);
|
||||
}
|
||||
|
||||
// return 0 : success
|
||||
// return -1 : error
|
||||
int g_vxlan_decode(struct g_vxlan **g_vxlan_hdr, const char *raw_data, int raw_len)
|
||||
{
|
||||
if (raw_len <= (int)(sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udphdr) + sizeof(struct g_vxlan)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ethhdr *eth_hdr = (struct ethhdr *)raw_data;
|
||||
if (eth_hdr->h_proto != htons(ETH_P_IP))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ip *ip_hdr = (struct ip *)((char *)eth_hdr + sizeof(struct ethhdr));
|
||||
if (ip_hdr->ip_p != IPPROTO_UDP)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct udphdr *udp_hdr = (struct udphdr *)((char *)ip_hdr + sizeof(struct ip));
|
||||
if (udp_hdr->uh_dport != htons(4789))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*g_vxlan_hdr = (struct g_vxlan *)((char *)udp_hdr + sizeof(struct udphdr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user