parent
7fb5eeddd5
commit
625d1c146f
|
@ -51,8 +51,8 @@ application:
|
||||||
# 网络相关
|
# 网络相关
|
||||||
network:
|
network:
|
||||||
{
|
{
|
||||||
nic_card = "ens160" # 收发数据使用的网卡名称
|
nic_card = "ens36"; # 收发数据使用的网卡名称
|
||||||
nic_mac = "00:0C:01:02:00:01" # 收发数据使用的网卡Mac地址
|
nic_mac = "00:0C:01:02:00:01"; # 收发数据使用的网卡Mac地址
|
||||||
vxlan_support = true; # 是否支持vxLan封装
|
vxlan_support = true; # 是否支持vxLan封装
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -481,7 +481,7 @@ do {
|
||||||
/* ZeroMq配置 */ \
|
/* ZeroMq配置 */ \
|
||||||
ADD_CFG_ITEM(CFG_MQ_SVR_PORT, "application.zero_mq.svr_port", VALUE_TYPE_INTEGRAL, "6278", "ZeroMQ server port"); \
|
ADD_CFG_ITEM(CFG_MQ_SVR_PORT, "application.zero_mq.svr_port", VALUE_TYPE_INTEGRAL, "6278", "ZeroMQ server port"); \
|
||||||
ADD_CFG_ITEM(CFG_MQ_DATA_CH, "application.zero_mq.agent_port", VALUE_TYPE_INTEGRAL, "6279", "ZeroMQ Agent server port"); \
|
ADD_CFG_ITEM(CFG_MQ_DATA_CH, "application.zero_mq.agent_port", VALUE_TYPE_INTEGRAL, "6279", "ZeroMQ Agent server port"); \
|
||||||
ADD_CFG_ITEM(CFG_NIC_CARD_NAME, "application.network.svr_port", VALUE_TYPE_STRING, "ens160", "Network card name to send data"); \
|
ADD_CFG_ITEM(CFG_NIC_CARD_NAME, "application.network.nic_card", VALUE_TYPE_STRING, "ens160", "Network card name to send data"); \
|
||||||
ADD_CFG_ITEM(CFG_VXLAN_SUPPORT, "application.network.vxlan_support", VALUE_TYPE_BOOL, "1", "Is support vxLan tune"); \
|
ADD_CFG_ITEM(CFG_VXLAN_SUPPORT, "application.network.vxlan_support", VALUE_TYPE_BOOL, "1", "Is support vxLan tune"); \
|
||||||
} while (0)// clang-format on
|
} while (0)// clang-format on
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <zlog.h>
|
#include <zlog.h>
|
||||||
|
#include <uthash/uthash.h>
|
||||||
|
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
#include "lwip/tcpip.h"
|
#include "lwip/tcpip.h"
|
||||||
|
@ -76,6 +77,8 @@
|
||||||
#define RAWIF_DEBUG LWIP_DBG_OFF
|
#define RAWIF_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define USED_ENUMER_VXLAN (0)
|
||||||
|
|
||||||
#define DEFAULT_GW_IPADDR (0xC0A80001)
|
#define DEFAULT_GW_IPADDR (0xC0A80001)
|
||||||
|
|
||||||
#define VXLAN_PORT_NET_ORDER (0x12B5)
|
#define VXLAN_PORT_NET_ORDER (0x12B5)
|
||||||
|
@ -91,8 +94,10 @@ struct sockaddr_ll {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
unsigned int vni;
|
||||||
unsigned char *output_head;
|
unsigned char *output_head;
|
||||||
unsigned char *input_head;
|
|
||||||
|
UT_hash_handle hh;
|
||||||
} VXLAN_BUF, *PVXLAN_BUF;
|
} VXLAN_BUF, *PVXLAN_BUF;
|
||||||
|
|
||||||
struct rawif {
|
struct rawif {
|
||||||
|
@ -103,9 +108,11 @@ struct rawif {
|
||||||
int vxlan_support;
|
int vxlan_support;
|
||||||
unsigned char mac_addr[6];
|
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;
|
static unsigned int g_localIpAddrBegin = DEFAULT_GW_IPADDR + 1;
|
||||||
|
|
||||||
/* Forward declarations. */
|
/* Forward declarations. */
|
||||||
|
@ -114,6 +121,12 @@ static void rawif_input(struct netif *netif);
|
||||||
_Noreturn static void rawif_thread(void *arg);
|
_Noreturn static void rawif_thread(void *arg);
|
||||||
#endif /* !NO_SYS */
|
#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) {
|
static void low_level_init(struct netif *netif) {
|
||||||
struct rawif *rawif;
|
struct rawif *rawif;
|
||||||
|
@ -253,15 +266,25 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
|
||||||
dstAddr.sll_family = PF_PACKET;
|
dstAddr.sll_family = PF_PACKET;
|
||||||
|
|
||||||
// 网卡支持vxlan
|
// 网卡支持vxlan
|
||||||
if (rawif->vxlan_support && rawif->vxlan_buf.output_head) {
|
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);
|
||||||
|
|
||||||
|
if (pvxlanBuf) {
|
||||||
unsigned short checksum;
|
unsigned short checksum;
|
||||||
unsigned int dataSize = p->tot_len - sizeof(struct eth_hdr);
|
unsigned int dataSize = p->tot_len - sizeof(struct eth_hdr);
|
||||||
struct eth_hdr *eth = (struct eth_hdr *)buf;
|
struct eth_hdr *eth = (struct eth_hdr *)buf;
|
||||||
struct vxlan_package *pkg = (struct vxlan_package *)sndBuf;
|
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 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 short ip_len = udp_len + 20;
|
||||||
|
unsigned int total_len = ip_len + sizeof(struct eth_hdr);
|
||||||
|
|
||||||
memcpy(sndBuf, rawif->vxlan_buf.output_head, sizeof(struct vxlan_package));
|
dzlog_debug("Found user vxlan connect: %d --> %u\n", pUser->userid, pvxlanBuf->vni);
|
||||||
|
|
||||||
|
memcpy(sndBuf, pvxlanBuf->output_head, sizeof(struct vxlan_package));
|
||||||
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pUser->vxlan.vni));
|
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pUser->vxlan.vni));
|
||||||
|
|
||||||
memcpy(pkg->eth_pkg.dest.addr, eth->dest.addr, ETH_HWADDR_LEN);
|
memcpy(pkg->eth_pkg.dest.addr, eth->dest.addr, ETH_HWADDR_LEN);
|
||||||
|
@ -279,35 +302,21 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
|
||||||
pkg->udp_head.chksum = 0x0000;
|
pkg->udp_head.chksum = 0x0000;
|
||||||
|
|
||||||
checksum = udp_checksum(sndBuf, ip_len + sizeof(struct eth_hdr));
|
checksum = udp_checksum(sndBuf, ip_len + sizeof(struct eth_hdr));
|
||||||
pkg->udp_head.chksum = lwip_htons(checksum);
|
pkg->udp_head.chksum = checksum;
|
||||||
IPH_CHKSUM_SET(&pkg->ip_head, inet_chksum(&pkg->ip_head, 20));
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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(); */
|
/* signal that packet should be sent(); */
|
||||||
written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
|
written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
|
||||||
|
|
||||||
#if 0
|
|
||||||
dzlog_info("\n Send: \n");
|
|
||||||
hdzlog_info(buf, p->tot_len);
|
|
||||||
dzlog_info("\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (written < p->tot_len) {
|
|
||||||
MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
|
|
||||||
perror("rawif: write");
|
|
||||||
return ERR_IF;
|
|
||||||
} else {
|
|
||||||
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, (u32_t)written);
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
|
@ -323,22 +332,32 @@ static struct pbuf *low_level_input(struct netif *netif) {
|
||||||
u16_t len;
|
u16_t len;
|
||||||
int addrSize;
|
int addrSize;
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
unsigned char bmac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
//
|
||||||
unsigned char buf[1518] = {0}; /* max packet size including VLAN excluding CRC */
|
unsigned char buf[4096] = {0}; /* max packet size including VLAN excluding CRC */
|
||||||
struct sockaddr from;
|
struct sockaddr from;
|
||||||
struct rawif *rawif = (struct rawif *)netif->state;
|
struct rawif *rawif = (struct rawif *)netif->state;
|
||||||
|
|
||||||
/* Obtain the size of the packet and put it into the "len"
|
/* Obtain the size of the packet and put it into the "len"
|
||||||
variable. */
|
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) {
|
if (readlen < 0) {
|
||||||
perror("read returned -1");
|
return NULL;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
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);
|
MIB2_STATS_NETIF_ADD(netif, ifinoctets, len);
|
||||||
|
|
||||||
/* We allocate a pbuf chain of pbufs from the pool. */
|
/* We allocate a pbuf chain of pbufs from the pool. */
|
||||||
|
@ -352,9 +371,6 @@ static struct pbuf *low_level_input(struct netif *netif) {
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("rawif_input: could not allocate pbuf\n"));
|
LWIP_DEBUGF(NETIF_DEBUG, ("rawif_input: could not allocate pbuf\n"));
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t rawif_output(struct netif *netif, struct pbuf *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 */
|
#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) {
|
static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
||||||
err_t err;
|
err_t err;
|
||||||
//struct netif *netif;
|
struct rawif *rawif = (struct rawif *)inp->state;
|
||||||
|
struct netif *netif;
|
||||||
|
#if USED_ENUMER_VXLAN
|
||||||
const unsigned char buf_test[] = {
|
const unsigned char buf_test[] = {
|
||||||
0x00, 0x0c, 0x29, 0x07, 0xcb, 0x55, 0x00, 0x0c, 0x29, 0x49, 0xcb, 0x27, 0x08, 0x00, 0x45, 0x00, 0x00, 0x4a,
|
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,
|
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,
|
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,
|
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};
|
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];
|
//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
|
// 网卡支持vxlan
|
||||||
if (rawif->vxlan_support) {
|
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 数据包
|
// 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;
|
VXLAN_TAG tag;
|
||||||
PUSER_INFO_CONTEXT pContext;
|
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) {
|
if (pvxlanBuf == NULL) {
|
||||||
// 缓存第一包头部数据
|
pvxlanBuf = (PVXLAN_BUF)malloc(sizeof(VXLAN_BUF));
|
||||||
rawif->vxlan_buf.input_head = (unsigned char *)mem_malloc(sizeof(struct vxlan_package));
|
pvxlanBuf->vni = vxlanId;
|
||||||
if (rawif->vxlan_buf.input_head) {
|
pvxlanBuf->output_head = (unsigned char *)mem_malloc(sizeof(struct vxlan_package));
|
||||||
memcpy(rawif->vxlan_buf.input_head, payload, 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));
|
memset(pvxlanBuf->output_head, 0, 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));
|
|
||||||
|
|
||||||
// ETH 头部
|
// ETH 头部
|
||||||
memcpy(vxlanHead->eth_head.src.addr, pkg->eth_head.dest.addr, ETH_HWADDR_LEN);
|
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 头部
|
// QinQ 头部
|
||||||
vxlanHead->qinq_head.in_type = pkg->qinq_head.in_type;
|
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) {
|
if (pBuf[4] == 0 && pBuf[5] == 0x02) {
|
||||||
tag.vni = 300;//VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
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);
|
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.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);
|
tag.q2 = 15; //lwip_ntohs(pkg->qinq_head.in_priority_cfi_and_id);
|
||||||
} else {
|
} else {
|
||||||
|
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.vni = VXLAN_VIN_ID(lwip_htonl(pkg->vxlan_head.vni_reserved));
|
||||||
tag.q1 = lwip_ntohs(pkg->qinq_head.out_priority_cfi_and_id);
|
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.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);
|
HASH_FIND(hh_vxlan, get_all_user_by_tag(), &tag, sizeof(VXLAN_TAG), pContext);
|
||||||
|
|
||||||
if (pContext && pContext->session.pppif) {
|
if (pContext && pContext->session.pppif) {
|
||||||
|
struct pbuf *ebuf;
|
||||||
|
|
||||||
if (strlen(pContext->session.data.svrBaseMac) == 0) {
|
if (strlen(pContext->session.data.svrBaseMac) == 0) {
|
||||||
sprintf(pContext->session.data.svrBaseMac,
|
sprintf(pContext->session.data.svrBaseMac,
|
||||||
"%02X:%02X:%02X:%02X:%02X:%02X",
|
"%02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
|
@ -585,30 +636,25 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
||||||
pBuf[10],
|
pBuf[10],
|
||||||
pBuf[11]);
|
pBuf[11]);
|
||||||
}
|
}
|
||||||
|
#if USED_ENUMER_VXLAN
|
||||||
if ((err = pContext->session.nicif->input(p, pContext->session.nicif)) != ERR_OK) {
|
ebuf = vxlan_unpackag(buf_test, sizeof(buf_test));
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
#else
|
||||||
pbuf_free(p);
|
ebuf = vxlan_unpackag((unsigned char *)p->payload, p->tot_len);
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#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
|
#endif
|
||||||
|
if ((err = pContext->session.nicif->input(ebuf, pContext->session.nicif)) != ERR_OK) {
|
||||||
|
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
if ((err = netif->input(p, netif)) != ERR_OK) {
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
@ -617,7 +663,7 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
return tcpip_input(p, inp);
|
return tcpip_input(p, inp);
|
||||||
}
|
}
|
||||||
|
@ -657,7 +703,9 @@ struct netif *bind_rawsocket_if(const char *eth_name) {
|
||||||
(g_localIpAddrBegin & 0xFF));
|
(g_localIpAddrBegin & 0xFF));
|
||||||
g_localIpAddrBegin++;
|
g_localIpAddrBegin++;
|
||||||
|
|
||||||
|
uv_rwlock_init(&rawif->lock_vxlan);
|
||||||
rawif->vxlan_support = cfg_get_support_vxlan();
|
rawif->vxlan_support = cfg_get_support_vxlan();
|
||||||
|
rawif->pvxLan = g_pvxLanBuf;
|
||||||
rawif->mac_addr[0] = 0x00;
|
rawif->mac_addr[0] = 0x00;
|
||||||
rawif->mac_addr[1] = 0x0C;
|
rawif->mac_addr[1] = 0x0C;
|
||||||
rawif->mac_addr[2] = 0x01;
|
rawif->mac_addr[2] = 0x01;
|
||||||
|
|
|
@ -61,7 +61,6 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
|
||||||
pcb->lcp_gotoptions.magicnumber,
|
pcb->lcp_gotoptions.magicnumber,
|
||||||
sc->sc_session);
|
sc->sc_session);
|
||||||
#if LWIP_IPV4
|
#if LWIP_IPV4
|
||||||
memset(&pUser->session.data, 0, sizeof(PPPOE_SESSION_DATA));
|
|
||||||
pUser->session.data.sessionId = sc->sc_session;
|
pUser->session.data.sessionId = sc->sc_session;
|
||||||
strncpy(pUser->session.data.clientIp, ip4addr_ntoa(netif_ip4_addr(pppif)), MAX_IP_V4_STR);
|
strncpy(pUser->session.data.clientIp, ip4addr_ntoa(netif_ip4_addr(pppif)), MAX_IP_V4_STR);
|
||||||
strncpy(pUser->session.data.clientGw, ip4addr_ntoa(netif_ip4_gw(pppif)), MAX_IP_V4_STR);
|
strncpy(pUser->session.data.clientGw, ip4addr_ntoa(netif_ip4_gw(pppif)), MAX_IP_V4_STR);
|
||||||
|
@ -180,6 +179,7 @@ _Noreturn void sessionCalcCb(void *UNUSED(pArg)) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS_TASK_DISCONNECTED:
|
case STATUS_TASK_DISCONNECTED:
|
||||||
|
dzlog_error("User %s disconnect, auto reconnect\n", pUser->user_info.pppoe_user);
|
||||||
// 自动重新拨号
|
// 自动重新拨号
|
||||||
pSession->status = STATUS_TASK_DIAL;
|
pSession->status = STATUS_TASK_DIAL;
|
||||||
break;
|
break;
|
||||||
|
@ -243,7 +243,7 @@ _Noreturn void cacheCalcCb(void *UNUSED(pArg)) {
|
||||||
}
|
}
|
||||||
uv_rwlock_wrunlock(&g_cacheLock);
|
uv_rwlock_wrunlock(&g_cacheLock);
|
||||||
cJSON_AddItemToObject(pRoot, "params", pSession);
|
cJSON_AddItemToObject(pRoot, "params", pSession);
|
||||||
pJsonString = cJSON_PrintUnformatted(pRoot);
|
pJsonString = cJSON_Print(pRoot);
|
||||||
mq_data_send_msg(pJsonString);
|
mq_data_send_msg(pJsonString);
|
||||||
cJSON_Delete(pRoot);
|
cJSON_Delete(pRoot);
|
||||||
free((void *)pJsonString);
|
free((void *)pJsonString);
|
||||||
|
|
|
@ -10,8 +10,8 @@ static PUSER_INFO_CONTEXT g_pUserByTagsList = NULL;
|
||||||
static uv_rwlock_t g_userLock;
|
static uv_rwlock_t g_userLock;
|
||||||
|
|
||||||
static USER_PARAMS g_userInfo[] = {
|
static USER_PARAMS g_userInfo[] = {
|
||||||
{0, 300, 16, 12, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x02}, "xajhuang3", "aaaHuang1"},
|
{0, 400, 24, 371, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x03}, "user1", "password1"},
|
||||||
{1, 400, 24, 371, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x03}, "xajhuang2", "aaaHuang1"},
|
{1, 300, 16, 12, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x02}, "user2", "password1"},
|
||||||
{2, 300, 14, 15, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x04}, "xajhuang1", "aaaHuang1"},
|
{2, 300, 14, 15, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x04}, "xajhuang1", "aaaHuang1"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ void user_info_init() {
|
||||||
uv_rwlock_init(&g_userLock);
|
uv_rwlock_init(&g_userLock);
|
||||||
|
|
||||||
user_info_add(0, &g_userInfo[0]);
|
user_info_add(0, &g_userInfo[0]);
|
||||||
user_info_add(1, &g_userInfo[1]);
|
//user_info_add(1, &g_userInfo[1]);
|
||||||
user_info_add(2, &g_userInfo[2]);
|
//user_info_add(2, &g_userInfo[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_info_change_status(PUSER_INFO_CONTEXT pInfo, USER_STATUS status) {
|
void user_info_change_status(PUSER_INFO_CONTEXT pInfo, USER_STATUS status) {
|
||||||
|
|
Loading…
Reference in New Issue