OCT 1. 优化QinQ解析以及数据包处理

This commit is contained in:
黄昕 2023-05-16 14:59:42 +08:00
parent 8304f4eef6
commit a356a7f9ef
3 changed files with 17 additions and 41 deletions

View File

@ -42,29 +42,7 @@ typedef struct vlan_hdr2 {
#endif
} VLAN_HDR2, *PVLAN_HDR2;
typedef struct {
struct ethhdr eth;
struct iphdr ip;
struct udphdr udp;
} VLAN_PKG_HDR, *PVLAN_PKG_HDR;
typedef struct {
struct ethhdr eth;
#if VLAN_SUPPORT
struct vlan_hdr vlan;
#endif
struct iphdr ip;
struct udphdr udp;
} VLAN_PKG_HDR1, *PVLAN_PKG_HDR1;
typedef struct {
struct ethhdr eth;
#if VLAN_SUPPORT
struct vlan_hdr2 vlan;
#endif
struct iphdr ip;
struct udphdr udp;
} VLAN_PKG_HDR2, *PVLAN_PKG_HDR2;
VLAN_TYPE get_package_vlan_type(void *pBuf);
#pragma pack(pop)
#ifdef __cplusplus

View File

@ -211,22 +211,22 @@ static void add_eth_head(U8 *pRsp, struct ethhdr *pEth, int isBst) {
p->h_proto = pEth->h_proto;
}
static void add_vlan_head(U8 *pRsp, PVLAN_PKG_HDR1 pvHdr) {
PVLAN_PKG_HDR1 p = (PVLAN_PKG_HDR1)pRsp;
static void add_vlan_head(U8 *pRsp, PVLAN_HDR pvHdr) {
PVLAN_HDR p = (PVLAN_HDR)(pRsp + sizeof(struct ethhdr));
// QinQ 隧道
p->vlan.id = pvHdr->vlan.id;
p->vlan.type = pvHdr->vlan.type;
p->id = pvHdr->id;
p->type = pvHdr->type;
}
static void add_vlan2_head(U8 *pRsp, PVLAN_PKG_HDR2 pvHdr) {
PVLAN_PKG_HDR2 p = (PVLAN_PKG_HDR2)pRsp;
static void add_vlan2_head(U8 *pRsp, PVLAN_HDR2 pvHdr) {
PVLAN_HDR2 p = (PVLAN_HDR2)(pRsp + sizeof(struct ethhdr));
// QinQ 隧道
p->vlan.id1 = pvHdr->vlan.id1;
p->vlan.h_type = pvHdr->vlan.h_type;
p->vlan.id2 = pvHdr->vlan.id2;
p->vlan.type = pvHdr->vlan.type;
p->id1 = pvHdr->id1;
p->h_type = pvHdr->h_type;
p->id2 = pvHdr->id2;
p->type = pvHdr->type;
}
static void add_ip_head(struct iphdr *p, struct iphdr *pIp) {
@ -298,14 +298,14 @@ static PDHCP_PROTO fill_pkg(U8 *pRsp, U8 *pReq) {
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR));
pUdp = (struct udphdr *)(pReq + UDP_HDR_OFFSET + sizeof(VLAN_HDR));
pDhcp = (PDHCP_PROTO)((U8 *)pReq + DHCP_OFFSET + sizeof(VLAN_HDR));
add_vlan_head(pRsp, (PVLAN_PKG_HDR1)pReq);
add_vlan_head(pRsp, (PVLAN_HDR)(pReq + IP_HDR_OFFSET));
p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR);
break;
case VLAN_LEVEL2:
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR2));
pUdp = (struct udphdr *)(pReq + UDP_HDR_OFFSET + sizeof(VLAN_HDR2));
pDhcp = (PDHCP_PROTO)((U8 *)pReq + DHCP_OFFSET + sizeof(VLAN_HDR2));
add_vlan2_head(pRsp, (PVLAN_PKG_HDR2)pReq);
add_vlan2_head(pRsp, (PVLAN_HDR2)(pReq + IP_HDR_OFFSET));
p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR2);
break;
}

View File

@ -19,6 +19,10 @@ extern "C" {
#define PKG_MMAP_FRAMESIZ (1 << 11)
#define PKG_MMAP_BLOCKNUM (64)
#define IP_HDR_OFFSET (sizeof(struct ethhdr))
#define UDP_HDR_OFFSET (sizeof(struct ethhdr) + sizeof(struct iphdr))
#define DHCP_OFFSET (sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr))
typedef struct {
int sock;
struct sockaddr_ll addr;
@ -51,12 +55,6 @@ typedef struct {
} RECV_CB_DATA, *PRECV_CB_DATA;
#pragma pack(1)
typedef struct {
VLAN_PKG_HDR1 hdr;
DHCP_PROTO dhcp;
} DHCP_PACKAGE, *PDHCP_PACKAGE;
typedef struct {
uv_work_t uvWork;
unsigned short nSize;