OCT 1. 优化QinQ解析以及数据包处理
This commit is contained in:
parent
8304f4eef6
commit
a356a7f9ef
|
@ -42,29 +42,7 @@ typedef struct vlan_hdr2 {
|
||||||
#endif
|
#endif
|
||||||
} VLAN_HDR2, *PVLAN_HDR2;
|
} VLAN_HDR2, *PVLAN_HDR2;
|
||||||
|
|
||||||
typedef struct {
|
VLAN_TYPE get_package_vlan_type(void *pBuf);
|
||||||
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;
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -211,22 +211,22 @@ static void add_eth_head(U8 *pRsp, struct ethhdr *pEth, int isBst) {
|
||||||
p->h_proto = pEth->h_proto;
|
p->h_proto = pEth->h_proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_vlan_head(U8 *pRsp, PVLAN_PKG_HDR1 pvHdr) {
|
static void add_vlan_head(U8 *pRsp, PVLAN_HDR pvHdr) {
|
||||||
PVLAN_PKG_HDR1 p = (PVLAN_PKG_HDR1)pRsp;
|
PVLAN_HDR p = (PVLAN_HDR)(pRsp + sizeof(struct ethhdr));
|
||||||
|
|
||||||
// QinQ 隧道
|
// QinQ 隧道
|
||||||
p->vlan.id = pvHdr->vlan.id;
|
p->id = pvHdr->id;
|
||||||
p->vlan.type = pvHdr->vlan.type;
|
p->type = pvHdr->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_vlan2_head(U8 *pRsp, PVLAN_PKG_HDR2 pvHdr) {
|
static void add_vlan2_head(U8 *pRsp, PVLAN_HDR2 pvHdr) {
|
||||||
PVLAN_PKG_HDR2 p = (PVLAN_PKG_HDR2)pRsp;
|
PVLAN_HDR2 p = (PVLAN_HDR2)(pRsp + sizeof(struct ethhdr));
|
||||||
|
|
||||||
// QinQ 隧道
|
// QinQ 隧道
|
||||||
p->vlan.id1 = pvHdr->vlan.id1;
|
p->id1 = pvHdr->id1;
|
||||||
p->vlan.h_type = pvHdr->vlan.h_type;
|
p->h_type = pvHdr->h_type;
|
||||||
p->vlan.id2 = pvHdr->vlan.id2;
|
p->id2 = pvHdr->id2;
|
||||||
p->vlan.type = pvHdr->vlan.type;
|
p->type = pvHdr->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_ip_head(struct iphdr *p, struct iphdr *pIp) {
|
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));
|
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR));
|
||||||
pUdp = (struct udphdr *)(pReq + UDP_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));
|
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);
|
p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR);
|
||||||
break;
|
break;
|
||||||
case VLAN_LEVEL2:
|
case VLAN_LEVEL2:
|
||||||
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR2));
|
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR2));
|
||||||
pUdp = (struct udphdr *)(pReq + UDP_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));
|
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);
|
p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ extern "C" {
|
||||||
#define PKG_MMAP_FRAMESIZ (1 << 11)
|
#define PKG_MMAP_FRAMESIZ (1 << 11)
|
||||||
#define PKG_MMAP_BLOCKNUM (64)
|
#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 {
|
typedef struct {
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_ll addr;
|
struct sockaddr_ll addr;
|
||||||
|
@ -51,12 +55,6 @@ typedef struct {
|
||||||
} RECV_CB_DATA, *PRECV_CB_DATA;
|
} RECV_CB_DATA, *PRECV_CB_DATA;
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
VLAN_PKG_HDR1 hdr;
|
|
||||||
DHCP_PROTO dhcp;
|
|
||||||
} DHCP_PACKAGE, *PDHCP_PACKAGE;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uv_work_t uvWork;
|
uv_work_t uvWork;
|
||||||
unsigned short nSize;
|
unsigned short nSize;
|
||||||
|
|
Loading…
Reference in New Issue