|
|
|
@ -39,6 +39,7 @@
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <zlog.h>
|
|
|
|
|
#include <uthash/uthash.h>
|
|
|
|
|
|
|
|
|
|
#include "lwip/opt.h"
|
|
|
|
|
#include "lwip/tcpip.h"
|
|
|
|
@ -76,6 +77,8 @@
|
|
|
|
|
#define RAWIF_DEBUG LWIP_DBG_OFF
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define USED_ENUMER_VXLAN (0)
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_GW_IPADDR (0xC0A80001)
|
|
|
|
|
|
|
|
|
|
#define VXLAN_PORT_NET_ORDER (0x12B5)
|
|
|
|
@ -91,8 +94,10 @@ struct sockaddr_ll {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
unsigned int vni;
|
|
|
|
|
unsigned char *output_head;
|
|
|
|
|
unsigned char *input_head;
|
|
|
|
|
|
|
|
|
|
UT_hash_handle hh;
|
|
|
|
|
} VXLAN_BUF, *PVXLAN_BUF;
|
|
|
|
|
|
|
|
|
|
struct rawif {
|
|
|
|
@ -103,9 +108,11 @@ struct rawif {
|
|
|
|
|
int vxlan_support;
|
|
|
|
|
unsigned char mac_addr[6];
|
|
|
|
|
|
|
|
|
|
VXLAN_BUF vxlan_buf;
|
|
|
|
|
PVXLAN_BUF pvxLan;
|
|
|
|
|
uv_rwlock_t lock_vxlan;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PVXLAN_BUF g_pvxLanBuf = NULL;
|
|
|
|
|
static unsigned int g_localIpAddrBegin = DEFAULT_GW_IPADDR + 1;
|
|
|
|
|
|
|
|
|
|
/* Forward declarations. */
|
|
|
|
@ -114,6 +121,12 @@ static void rawif_input(struct netif *netif);
|
|
|
|
|
_Noreturn static void rawif_thread(void *arg);
|
|
|
|
|
#endif /* !NO_SYS */
|
|
|
|
|
|
|
|
|
|
static int is_vxlan_package(const unsigned char *p) {
|
|
|
|
|
const struct vxlan_package *pkg = (const struct vxlan_package *)p;
|
|
|
|
|
|
|
|
|
|
return (pkg->ip_head._proto == IP_PROTO_UDP && lwip_ntohs(pkg->udp_head.dest) == VXLAN_PORT_NET_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
|
static void low_level_init(struct netif *netif) {
|
|
|
|
|
struct rawif *rawif;
|
|
|
|
@ -253,61 +266,57 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
|
|
|
|
|
dstAddr.sll_family = PF_PACKET;
|
|
|
|
|
|
|
|
|
|
// 网卡支持vxlan
|
|
|
|
|
if (rawif->vxlan_support && rawif->vxlan_buf.output_head) {
|
|
|
|
|
unsigned short checksum;
|
|
|
|
|
unsigned int dataSize = p->tot_len - sizeof(struct eth_hdr);
|
|
|
|
|
struct eth_hdr *eth = (struct eth_hdr *)buf;
|
|
|
|
|
struct vxlan_package *pkg = (struct vxlan_package *)sndBuf;
|
|
|
|
|
unsigned short udp_len = p->tot_len + sizeof(struct vxlan_hdr) + sizeof(struct qinq_hdr);
|
|
|
|
|
unsigned short ip_len = udp_len + 20;
|
|
|
|
|
if (rawif->vxlan_support) {
|
|
|
|
|
PVXLAN_BUF pvxlanBuf;
|
|
|
|
|
uv_rwlock_rdlock(&rawif->lock_vxlan);
|
|
|
|
|
HASH_FIND_INT(rawif->pvxLan, &pUser->vxlan.vni, pvxlanBuf);
|
|
|
|
|
uv_rwlock_rdunlock(&rawif->lock_vxlan);
|
|
|
|
|
|
|
|
|
|
memcpy(sndBuf, rawif->vxlan_buf.output_head, sizeof(struct vxlan_package));
|
|
|
|
|
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pUser->vxlan.vni));
|
|
|
|
|
if (pvxlanBuf) {
|
|
|
|
|
unsigned short checksum;
|
|
|
|
|
unsigned int dataSize = p->tot_len - sizeof(struct eth_hdr);
|
|
|
|
|
struct eth_hdr *eth = (struct eth_hdr *)buf;
|
|
|
|
|
struct vxlan_package *pkg = (struct vxlan_package *)sndBuf;
|
|
|
|
|
unsigned short udp_len =
|
|
|
|
|
p->tot_len + sizeof(struct vxlan_hdr) + sizeof(struct qinq_hdr) + sizeof(struct udp_hdr);
|
|
|
|
|
unsigned short ip_len = udp_len + 20;
|
|
|
|
|
unsigned int total_len = ip_len + sizeof(struct eth_hdr);
|
|
|
|
|
|
|
|
|
|
memcpy(pkg->eth_pkg.dest.addr, eth->dest.addr, ETH_HWADDR_LEN);
|
|
|
|
|
memcpy(pkg->eth_pkg.src.addr, eth->src.addr, ETH_HWADDR_LEN);
|
|
|
|
|
pkg->qinq_head.out_priority_cfi_and_id = lwip_htons(pUser->vxlan.q1);
|
|
|
|
|
pkg->qinq_head.in_priority_cfi_and_id = lwip_htons(pUser->vxlan.q2);
|
|
|
|
|
pkg->qinq_head.origin_type = eth->type;
|
|
|
|
|
dzlog_debug("Found user vxlan connect: %d --> %u\n", pUser->userid, pvxlanBuf->vni);
|
|
|
|
|
|
|
|
|
|
memcpy(pkg->data, &buf[sizeof(struct eth_hdr)], dataSize);
|
|
|
|
|
memcpy(sndBuf, pvxlanBuf->output_head, sizeof(struct vxlan_package));
|
|
|
|
|
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pUser->vxlan.vni));
|
|
|
|
|
|
|
|
|
|
pkg->udp_head.len = lwip_htons(udp_len);
|
|
|
|
|
pkg->ip_head._len = lwip_htons(ip_len);
|
|
|
|
|
memcpy(pkg->eth_pkg.dest.addr, eth->dest.addr, ETH_HWADDR_LEN);
|
|
|
|
|
memcpy(pkg->eth_pkg.src.addr, eth->src.addr, ETH_HWADDR_LEN);
|
|
|
|
|
pkg->qinq_head.out_priority_cfi_and_id = lwip_htons(pUser->vxlan.q1);
|
|
|
|
|
pkg->qinq_head.in_priority_cfi_and_id = lwip_htons(pUser->vxlan.q2);
|
|
|
|
|
pkg->qinq_head.origin_type = eth->type;
|
|
|
|
|
|
|
|
|
|
pkg->ip_head._chksum = 0x0000;
|
|
|
|
|
pkg->udp_head.chksum = 0x0000;
|
|
|
|
|
memcpy(pkg->data, &buf[sizeof(struct eth_hdr)], dataSize);
|
|
|
|
|
|
|
|
|
|
checksum = udp_checksum(sndBuf, ip_len + sizeof(struct eth_hdr));
|
|
|
|
|
pkg->udp_head.chksum = lwip_htons(checksum);
|
|
|
|
|
IPH_CHKSUM_SET(&pkg->ip_head, inet_chksum(&pkg->ip_head, 20));
|
|
|
|
|
#if 0
|
|
|
|
|
written = sendto(rawif->fd,
|
|
|
|
|
sndBuf,
|
|
|
|
|
pkg->ip_head._len + sizeof(struct eth_hdr),
|
|
|
|
|
0,
|
|
|
|
|
(struct sockaddr *)&dstAddr,
|
|
|
|
|
sizeof(dstAddr));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
pkg->udp_head.len = lwip_htons(udp_len);
|
|
|
|
|
pkg->ip_head._len = lwip_htons(ip_len);
|
|
|
|
|
|
|
|
|
|
/* signal that packet should be sent(); */
|
|
|
|
|
written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
|
|
|
|
|
pkg->ip_head._chksum = 0x0000;
|
|
|
|
|
pkg->udp_head.chksum = 0x0000;
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
dzlog_info("\n Send: \n");
|
|
|
|
|
hdzlog_info(buf, p->tot_len);
|
|
|
|
|
dzlog_info("\n");
|
|
|
|
|
#endif
|
|
|
|
|
checksum = udp_checksum(sndBuf, ip_len + sizeof(struct eth_hdr));
|
|
|
|
|
pkg->udp_head.chksum = checksum;
|
|
|
|
|
IPH_CHKSUM_SET(&pkg->ip_head, inet_chksum(&pkg->ip_head, 20));
|
|
|
|
|
|
|
|
|
|
if (written < p->tot_len) {
|
|
|
|
|
MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
|
|
|
|
|
perror("rawif: write");
|
|
|
|
|
return ERR_IF;
|
|
|
|
|
written = sendto(rawif->fd, sndBuf, total_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
|
|
|
|
|
return written == (total_len) ? ERR_OK : ERR_IF;
|
|
|
|
|
} else {
|
|
|
|
|
/* signal that packet should be sent(); */
|
|
|
|
|
written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, (u32_t)written);
|
|
|
|
|
return ERR_OK;
|
|
|
|
|
/* signal that packet should be sent(); */
|
|
|
|
|
written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (written == p->tot_len) ? ERR_OK : ERR_IF;
|
|
|
|
|
}
|
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
|
/*
|
|
|
|
@ -319,42 +328,49 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
|
|
|
|
|
*/
|
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
|
static struct pbuf *low_level_input(struct netif *netif) {
|
|
|
|
|
struct pbuf *p;
|
|
|
|
|
u16_t len;
|
|
|
|
|
int addrSize;
|
|
|
|
|
ssize_t readlen;
|
|
|
|
|
unsigned char bmac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
|
unsigned char buf[1518] = {0}; /* max packet size including VLAN excluding CRC */
|
|
|
|
|
struct pbuf *p;
|
|
|
|
|
u16_t len;
|
|
|
|
|
int addrSize;
|
|
|
|
|
ssize_t readlen;
|
|
|
|
|
//
|
|
|
|
|
unsigned char buf[4096] = {0}; /* max packet size including VLAN excluding CRC */
|
|
|
|
|
struct sockaddr from;
|
|
|
|
|
struct rawif *rawif = (struct rawif *)netif->state;
|
|
|
|
|
|
|
|
|
|
/* Obtain the size of the packet and put it into the "len"
|
|
|
|
|
variable. */
|
|
|
|
|
readlen = recvfrom(rawif->fd, buf, 1518, 0, &from, (socklen_t *)&addrSize);
|
|
|
|
|
readlen = recvfrom(rawif->fd, buf, 4096, 0, &from, (socklen_t *)&addrSize);
|
|
|
|
|
|
|
|
|
|
if (readlen < 0) {
|
|
|
|
|
perror("read returned -1");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
len = (u16_t)readlen;
|
|
|
|
|
|
|
|
|
|
if ((buf[0] == 0x00 && buf[1] == 0x0C && buf[2] == 0x01 && buf[3] == 0x02) || memcmp(buf, bmac, 6) == 0) {
|
|
|
|
|
MIB2_STATS_NETIF_ADD(netif, ifinoctets, len);
|
|
|
|
|
|
|
|
|
|
/* We allocate a pbuf chain of pbufs from the pool. */
|
|
|
|
|
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
|
|
|
|
|
if (p != NULL) {
|
|
|
|
|
pbuf_take(p, buf, len);
|
|
|
|
|
/* acknowledge that packet has been read(); */
|
|
|
|
|
} else {
|
|
|
|
|
/* drop packet(); */
|
|
|
|
|
MIB2_STATS_NETIF_INC(netif, ifindiscards);
|
|
|
|
|
LWIP_DEBUGF(NETIF_DEBUG, ("rawif_input: could not allocate pbuf\n"));
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(rawif->vxlan_support) {
|
|
|
|
|
if(!is_vxlan_package(buf)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
unsigned char bmac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
|
if (!(buf[0] == 0x00 && buf[1] == 0x0C && buf[2] == 0x01 && buf[3] == 0x02) && memcmp(buf, bmac, 6) != 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = (u16_t)readlen;
|
|
|
|
|
|
|
|
|
|
MIB2_STATS_NETIF_ADD(netif, ifinoctets, len);
|
|
|
|
|
|
|
|
|
|
/* We allocate a pbuf chain of pbufs from the pool. */
|
|
|
|
|
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
|
|
|
|
|
if (p != NULL) {
|
|
|
|
|
pbuf_take(p, buf, len);
|
|
|
|
|
/* acknowledge that packet has been read(); */
|
|
|
|
|
} else {
|
|
|
|
|
/* drop packet(); */
|
|
|
|
|
MIB2_STATS_NETIF_INC(netif, ifindiscards);
|
|
|
|
|
LWIP_DEBUGF(NETIF_DEBUG, ("rawif_input: could not allocate pbuf\n"));
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err_t rawif_output(struct netif *netif, struct pbuf *p) {
|
|
|
|
@ -478,51 +494,76 @@ static void link_callback(struct netif *state_netif) {
|
|
|
|
|
}
|
|
|
|
|
#endif /* LWIP_NETIF_LINK_CALLBACK */
|
|
|
|
|
|
|
|
|
|
static struct pbuf *vxlan_unpackag(const unsigned char *pBuf, int size) {
|
|
|
|
|
struct pbuf *q;
|
|
|
|
|
unsigned char buf[1500];
|
|
|
|
|
const struct vxlan_package *pkg = (const struct vxlan_package *)pBuf;
|
|
|
|
|
int eth_len = +sizeof(struct eth_hdr);
|
|
|
|
|
int pkgsize = size - sizeof(struct vxlan_package) + eth_len;
|
|
|
|
|
|
|
|
|
|
memcpy(buf, &pkg->eth_pkg, sizeof(struct eth_hdr));
|
|
|
|
|
memcpy(buf + eth_len - 2, pkg->data - 2, pkgsize - eth_len + 2);
|
|
|
|
|
|
|
|
|
|
/* We allocate a pbuf chain of pbufs from the pool. */
|
|
|
|
|
q = pbuf_alloc(PBUF_RAW, pkgsize, PBUF_RAM);
|
|
|
|
|
|
|
|
|
|
if (q != NULL) {
|
|
|
|
|
pbuf_take(q, buf, pkgsize);
|
|
|
|
|
/* acknowledge that packet has been read(); */
|
|
|
|
|
} else {
|
|
|
|
|
/* drop packet(); */
|
|
|
|
|
MIB2_STATS_NETIF_INC(netif, ifindiscards);
|
|
|
|
|
LWIP_DEBUGF(NETIF_DEBUG, ("rawif_input: could not allocate pbuf\n"));
|
|
|
|
|
}
|
|
|
|
|
return q;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
|
|
|
|
err_t err;
|
|
|
|
|
//struct netif *netif;
|
|
|
|
|
err_t err;
|
|
|
|
|
struct rawif *rawif = (struct rawif *)inp->state;
|
|
|
|
|
struct netif *netif;
|
|
|
|
|
#if USED_ENUMER_VXLAN
|
|
|
|
|
const unsigned char buf_test[] = {
|
|
|
|
|
0x00, 0x0c, 0x29, 0x07, 0xcb, 0x55, 0x00, 0x0c, 0x29, 0x49, 0xcb, 0x27, 0x08, 0x00, 0x45, 0x00, 0x00, 0x4a,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0xfd, 0x11, 0x13, 0x6f, 0xc0, 0xa8, 0x14, 0x70, 0xc0, 0xa8, 0x14, 0x73, 0x67, 0x3b,
|
|
|
|
|
0x12, 0xb5, 0x00, 0x36, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x5a, 0xfd, 0x0e, 0xac,
|
|
|
|
|
0x3e, 0x95, 0x5a, 0x17, 0xaf, 0x64, 0xe8, 0xba, 0x88, 0xa8, 0x00, 0x18, 0x81, 0x00, 0x01, 0x73, 0x88, 0x64,
|
|
|
|
|
0x11, 0x00, 0x00, 0x02, 0x00, 0x0a, 0xc0, 0x21, 0x09, 0xfc, 0x00, 0x08, 0x66, 0x33, 0x48, 0x73};
|
|
|
|
|
struct rawif *rawif = (struct rawif *)inp->state;
|
|
|
|
|
//struct rawif *rawif = (struct rawif *)inp->state;
|
|
|
|
|
//unsigned char buf[1500];
|
|
|
|
|
const unsigned char *pBuf = (const unsigned char *)p->payload;
|
|
|
|
|
const unsigned char *payload = buf_test;
|
|
|
|
|
|
|
|
|
|
LWIP_ASSERT_CORE_LOCKED();
|
|
|
|
|
const unsigned char *pBuf = buf_test;
|
|
|
|
|
#else
|
|
|
|
|
const unsigned char *pBuf = (const unsigned char *)p->payload;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// 网卡支持vxlan
|
|
|
|
|
if (rawif->vxlan_support) {
|
|
|
|
|
const struct vxlan_package *pkg = (const struct vxlan_package *)payload;
|
|
|
|
|
const struct vxlan_package *pkg = (const struct vxlan_package *)pBuf;
|
|
|
|
|
|
|
|
|
|
// UDP xvLan 数据包
|
|
|
|
|
if (pkg->ip_head._proto == IP_PROTO_UDP && lwip_ntohs(pkg->udp_head.dest) == VXLAN_PORT_NET_ORDER) {
|
|
|
|
|
if (is_vxlan_package((const unsigned char *)p->payload)) {
|
|
|
|
|
VXLAN_TAG tag;
|
|
|
|
|
PUSER_INFO_CONTEXT pContext;
|
|
|
|
|
PVXLAN_BUF pvxlanBuf;
|
|
|
|
|
#if USED_ENUMER_VXLAN
|
|
|
|
|
unsigned int vxlanId = 400;
|
|
|
|
|
#else
|
|
|
|
|
unsigned int vxlanId = VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
|
|
|
|
#endif
|
|
|
|
|
uv_rwlock_rdlock(&rawif->lock_vxlan);
|
|
|
|
|
HASH_FIND_INT(rawif->pvxLan, &vxlanId, pvxlanBuf);
|
|
|
|
|
uv_rwlock_rdunlock(&rawif->lock_vxlan);
|
|
|
|
|
|
|
|
|
|
// 首包
|
|
|
|
|
if (rawif->vxlan_buf.input_head == NULL) {
|
|
|
|
|
// 缓存第一包头部数据
|
|
|
|
|
rawif->vxlan_buf.input_head = (unsigned char *)mem_malloc(sizeof(struct vxlan_package));
|
|
|
|
|
if (rawif->vxlan_buf.input_head) {
|
|
|
|
|
memcpy(rawif->vxlan_buf.input_head, payload, sizeof(struct vxlan_package));
|
|
|
|
|
}
|
|
|
|
|
if (pvxlanBuf == NULL) {
|
|
|
|
|
pvxlanBuf = (PVXLAN_BUF)malloc(sizeof(VXLAN_BUF));
|
|
|
|
|
pvxlanBuf->vni = vxlanId;
|
|
|
|
|
pvxlanBuf->output_head = (unsigned char *)mem_malloc(sizeof(struct vxlan_package));
|
|
|
|
|
if (pvxlanBuf->output_head) {
|
|
|
|
|
struct vxlan_package *vxlanHead = (struct vxlan_package *)pvxlanBuf->output_head;
|
|
|
|
|
|
|
|
|
|
//hdzlog_debug(rawif->vxlan_buf.input_head, sizeof(struct vxlan_package));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 学习vxLan相关内容
|
|
|
|
|
if (rawif->vxlan_buf.output_head == NULL) {
|
|
|
|
|
unsigned char *pOutBuf = (unsigned char *)mem_malloc(sizeof(struct vxlan_package));
|
|
|
|
|
// 缓存第一包头部数据
|
|
|
|
|
|
|
|
|
|
if (pOutBuf) {
|
|
|
|
|
struct vxlan_package *vxlanHead = (struct vxlan_package *)pOutBuf;
|
|
|
|
|
|
|
|
|
|
memset(pOutBuf, 0, sizeof(struct vxlan_package));
|
|
|
|
|
memset(pvxlanBuf->output_head, 0, sizeof(struct vxlan_package));
|
|
|
|
|
|
|
|
|
|
// ETH 头部
|
|
|
|
|
memcpy(vxlanHead->eth_head.src.addr, pkg->eth_head.dest.addr, ETH_HWADDR_LEN);
|
|
|
|
@ -550,10 +591,14 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
|
|
|
|
// QinQ 头部
|
|
|
|
|
vxlanHead->qinq_head.in_type = pkg->qinq_head.in_type;
|
|
|
|
|
|
|
|
|
|
rawif->vxlan_buf.output_head = pOutBuf;
|
|
|
|
|
uv_rwlock_wrlock(&rawif->lock_vxlan);
|
|
|
|
|
HASH_ADD_INT(rawif->pvxLan, vni, pvxlanBuf);
|
|
|
|
|
uv_rwlock_wrunlock(&rawif->lock_vxlan);
|
|
|
|
|
} else {
|
|
|
|
|
free(pvxlanBuf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if USED_ENUMER_VXLAN
|
|
|
|
|
if (pBuf[4] == 0 && pBuf[5] == 0x02) {
|
|
|
|
|
tag.vni = 300;//VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
|
|
|
|
tag.q1 = 16; //lwip_ntohs(pkg->qinq_head.out_priority_cfi_and_id);
|
|
|
|
@ -567,14 +612,20 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
|
|
|
|
tag.q1 = 14; //lwip_ntohs(pkg->qinq_head.out_priority_cfi_and_id);
|
|
|
|
|
tag.q2 = 15; //lwip_ntohs(pkg->qinq_head.in_priority_cfi_and_id);
|
|
|
|
|
} else {
|
|
|
|
|
tag.vni = VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
|
|
|
|
tag.q1 = lwip_ntohs(pkg->qinq_head.out_priority_cfi_and_id);
|
|
|
|
|
tag.q2 = lwip_ntohs(pkg->qinq_head.in_priority_cfi_and_id);
|
|
|
|
|
tag.vni = 400;//VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
|
|
|
|
tag.q1 = 24; //lwip_ntohs(pkg->qinq_head.out_priority_cfi_and_id);
|
|
|
|
|
tag.q2 = 371;//lwip_ntohs(pkg->qinq_head.in_priority_cfi_and_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
tag.vni = VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
|
|
|
|
tag.q1 = lwip_ntohs(pkg->qinq_head.out_priority_cfi_and_id);
|
|
|
|
|
tag.q2 = lwip_ntohs(pkg->qinq_head.in_priority_cfi_and_id);
|
|
|
|
|
#endif
|
|
|
|
|
HASH_FIND(hh_vxlan, get_all_user_by_tag(), &tag, sizeof(VXLAN_TAG), pContext);
|
|
|
|
|
|
|
|
|
|
if (pContext && pContext->session.pppif) {
|
|
|
|
|
struct pbuf *ebuf;
|
|
|
|
|
|
|
|
|
|
if (strlen(pContext->session.data.svrBaseMac) == 0) {
|
|
|
|
|
sprintf(pContext->session.data.svrBaseMac,
|
|
|
|
|
"%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
|
@ -585,8 +636,26 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
|
|
|
|
pBuf[10],
|
|
|
|
|
pBuf[11]);
|
|
|
|
|
}
|
|
|
|
|
#if USED_ENUMER_VXLAN
|
|
|
|
|
ebuf = vxlan_unpackag(buf_test, sizeof(buf_test));
|
|
|
|
|
#else
|
|
|
|
|
ebuf = vxlan_unpackag((unsigned char *)p->payload, p->tot_len);
|
|
|
|
|
#endif
|
|
|
|
|
if ((err = pContext->session.nicif->input(ebuf, pContext->session.nicif)) != ERR_OK) {
|
|
|
|
|
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((err = pContext->session.nicif->input(p, pContext->session.nicif)) != ERR_OK) {
|
|
|
|
|
pbuf_free(p);
|
|
|
|
|
return err;
|
|
|
|
|
} else {
|
|
|
|
|
dzlog_error("Not found: %u, %u, %u\n", tag.vni, tag.q1, tag.q2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
NETIF_FOREACH(netif) {
|
|
|
|
|
if (netif->hwaddr_len == 6 && memcmp(pBuf, netif->hwaddr, netif->hwaddr_len) == 0) {
|
|
|
|
|
|
|
|
|
|
if ((err = netif->input(p, netif)) != ERR_OK) {
|
|
|
|
|
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
|
|
|
|
pbuf_free(p);
|
|
|
|
|
}
|
|
|
|
@ -595,29 +664,6 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
NETIF_FOREACH(netif) {
|
|
|
|
|
|
|
|
|
|
unsigned char *pMac = (unsigned char *)p->payload;
|
|
|
|
|
|
|
|
|
|
if (netif->hwaddr_len == 6 && memcmp(pMac, netif->hwaddr, netif->hwaddr_len) == 0) {
|
|
|
|
|
#if 0
|
|
|
|
|
printf("++++++receive %02X:%02X:%02X:%02X:%02X:%02X\n",
|
|
|
|
|
pMac[0], pMac[1], pMac[2], pMac[3], pMac[4], pMac[5]);
|
|
|
|
|
|
|
|
|
|
printf("---- Call netif(%c%c:%d) <%p>, input = <%p>, %02X:%02X\n",
|
|
|
|
|
netif->name[0], netif->name[1], netif->num,
|
|
|
|
|
(void*)netif, (void*)netif->input, netif->hwaddr[4], netif->hwaddr[5]);
|
|
|
|
|
#endif
|
|
|
|
|
if ((err = netif->input(p, netif)) != ERR_OK) {
|
|
|
|
|
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
|
|
|
|
pbuf_free(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return tcpip_input(p, inp);
|
|
|
|
|
}
|
|
|
|
@ -657,7 +703,9 @@ struct netif *bind_rawsocket_if(const char *eth_name) {
|
|
|
|
|
(g_localIpAddrBegin & 0xFF));
|
|
|
|
|
g_localIpAddrBegin++;
|
|
|
|
|
|
|
|
|
|
uv_rwlock_init(&rawif->lock_vxlan);
|
|
|
|
|
rawif->vxlan_support = cfg_get_support_vxlan();
|
|
|
|
|
rawif->pvxLan = g_pvxLanBuf;
|
|
|
|
|
rawif->mac_addr[0] = 0x00;
|
|
|
|
|
rawif->mac_addr[1] = 0x0C;
|
|
|
|
|
rawif->mac_addr[2] = 0x01;
|
|
|
|
|