REM:
1. 硬件网卡数据包收发增加libpcap功能,用于替换RawSocket模式。
2. 增加网卡数据包接收缓存队列,防止数据丢失
This commit is contained in:
huangxin 2022-06-12 18:00:43 +08:00
parent c182fef0d8
commit 25adf97758
12 changed files with 519 additions and 16 deletions

4
.gitignore vendored
View File

@ -1,5 +1,5 @@
/cmake-build-debug/ /cmake-build-debug/
/.idea/ /.idea/
*/__init__.py */__init__.py
/cmake-build-debug-ubuntuefc/ /cmake-build-debug-*/
/cmake-build-debug-vswith_dev/ /cmake-build-debug_*/

View File

@ -344,6 +344,10 @@ const char *config_item_dump_fmt(const char *titleMessage) {
case VALUE_TYPE_STRING: case VALUE_TYPE_STRING:
tmp = sdsempty(); tmp = sdsempty();
tmp = sdscatprintf(tmp, "\"%s\"", CFG_STRING_VALUE(pItem)); tmp = sdscatprintf(tmp, "\"%s\"", CFG_STRING_VALUE(pItem));
if(sdslen(tmp) > 43) {
sdsrange(tmp, 0, 39);
sdscat(tmp, "...\"");
}
s = sdscatprintf(s, "|%4d | %-25s | %-45s | %-44s |\n", pItem->cfgId, tmp2, pItem->pcfgKey, tmp); s = sdscatprintf(s, "|%4d | %-25s | %-45s | %-44s |\n", pItem->cfgId, tmp2, pItem->pcfgKey, tmp);
sdsfree(tmp); sdsfree(tmp);
break; break;
@ -482,10 +486,11 @@ do {
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"); \
/* vxLan 隧道配置 */ \ /* vxLan 隧道配置 */ \
ADD_CFG_ITEM(CFG_VXLAN_NIC_NAME, "application.vxlan.vxlan_nic", VALUE_TYPE_STRING, "", "Network card name to send data"); \ ADD_CFG_ITEM(CFG_VXLAN_NIC_NAME, "application.vxlan_wan.nic", VALUE_TYPE_STRING, "", "Network card name to send data"); \
ADD_CFG_ITEM(CFG_VXLAN_SUPPORT, "application.vxlan.vxlan_enable", VALUE_TYPE_BOOL, "1", "Is support vxLan tune"); \ ADD_CFG_ITEM(CFG_VXLAN_SUPPORT, "application.vxlan_wan.enable", VALUE_TYPE_BOOL, "1", "Is support vxLan tune"); \
ADD_CFG_ITEM(CFG_VXLAN_PEER_IP, "application.vxlan.vxlan_peer_ip", VALUE_TYPE_STRING, "", "vxLan peer ip address"); \ ADD_CFG_ITEM(CFG_VXLAN_PEER_IP, "application.vxlan_wan.peer_ip", VALUE_TYPE_STRING, "", "vxLan peer ip address"); \
ADD_CFG_ITEM(CFG_VXLAN_PEER_MAC, "application.vxlan.vxlan_peer_mac", VALUE_TYPE_STRING, "", "vxLan peer mac address"); \ ADD_CFG_ITEM(CFG_VXLAN_PEER_MAC, "application.vxlan_wan.peer_mac", VALUE_TYPE_STRING, "", "vxLan peer mac address"); \
ADD_CFG_ITEM(CFG_VXLAN_PKG_FILTER, "application.vxlan_wan.pkg_filter", VALUE_TYPE_STRING, "", "vxLan package filter"); \
} while (0)// clang-format on } while (0)// clang-format on
int init_config_system(const char *pCfgFile, const char *pKey) { int init_config_system(const char *pCfgFile, const char *pKey) {

View File

@ -3,18 +3,22 @@
// //
#include "config.h" #include "config.h"
const char*config_get_vxlan_nic_name() { const char *config_get_vxlan_nic_name() {
return cfg_get_string_value(CFG_VXLAN_NIC_NAME); return cfg_get_string_value(CFG_VXLAN_NIC_NAME);
} }
const char*config_get_vxlan_peer_ip() { const char *config_get_vxlan_peer_ip() {
return cfg_get_string_value(CFG_VXLAN_PEER_IP); return cfg_get_string_value(CFG_VXLAN_PEER_IP);
} }
const char*config_get_vxlan_peer_mac() { const char *config_get_vxlan_peer_mac() {
return cfg_get_string_value(CFG_VXLAN_PEER_MAC); return cfg_get_string_value(CFG_VXLAN_PEER_MAC);
} }
const char *config_get_vxlan_pkg_filter() {
return cfg_get_string_value(CFG_VXLAN_PKG_FILTER);
}
int cfg_get_support_vxlan() { int cfg_get_support_vxlan() {
return cfg_get_bool_value(CFG_VXLAN_SUPPORT); return cfg_get_bool_value(CFG_VXLAN_SUPPORT);
} }

View File

@ -46,6 +46,7 @@ typedef enum {
CFG_VXLAN_SUPPORT = 24, CFG_VXLAN_SUPPORT = 24,
CFG_VXLAN_PEER_IP = 25, CFG_VXLAN_PEER_IP = 25,
CFG_VXLAN_PEER_MAC = 26, CFG_VXLAN_PEER_MAC = 26,
CFG_VXLAN_PKG_FILTER = 27,
CONFIG_ITEM_ID_MAX CONFIG_ITEM_ID_MAX
} CONFIG_ITEM_ID; } CONFIG_ITEM_ID;
@ -88,6 +89,7 @@ int cfg_get_support_vxlan();
const char *config_get_vxlan_nic_name(); const char *config_get_vxlan_nic_name();
const char *config_get_vxlan_peer_mac(); const char *config_get_vxlan_peer_mac();
const char *config_get_vxlan_peer_ip(); const char *config_get_vxlan_peer_ip();
const char *config_get_vxlan_pkg_filter();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -35,3 +35,7 @@ target_link_libraries(${LWIP_LIB_NAME} ${LWIP_SANITIZER_LIBS})
find_library(LIBPTHREAD pthread) find_library(LIBPTHREAD pthread)
target_link_libraries(${LWIP_LIB_NAME} ${LIBPTHREAD}) target_link_libraries(${LWIP_LIB_NAME} ${LIBPTHREAD})
find_library(LIBPCAP pcap)
target_link_libraries(${LWIP_LIB_NAME} ${LIBPCAP})
find_library(LIBZMQ zmq)
target_link_libraries(${LWIP_LIB_NAME} ${LIBZMQ})

View File

@ -18,6 +18,7 @@ set(lwipcontribportunixnetifs_SRCS
${LWIP_DIR}/src/arch_linux/netif/rawif.c ${LWIP_DIR}/src/arch_linux/netif/rawif.c
${LWIP_DIR}/src/arch_linux/netif/sio.c ${LWIP_DIR}/src/arch_linux/netif/sio.c
${LWIP_DIR}/src/arch_linux/netif/pppoe_if.c ${LWIP_DIR}/src/arch_linux/netif/pppoe_if.c
${LWIP_DIR}/src/arch_linux/netif/pcapif.c
) )
if (FALSE) if (FALSE)

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
*/
#ifndef LWIP_PCAPIF_H
#define LWIP_PCAPIF_H
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
err_t pcapif_init(struct netif *netif);
void pcapif_poll(struct netif *netif);
err_t pcapif_output(struct netif *netif, struct pbuf *p);
struct netif *bind_pcap_if(const char *eth_name, const char *pkg_filter);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_PCAPIF_H */

View File

@ -35,6 +35,15 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "../../../../../include/pppoe_session.h" #include "../../../../../include/pppoe_session.h"
#define DUMP_IF_BUF(tag, buf, len) \
do { \
dzlog_debug("%s ++++++\n", (tag)); \
printf("\n"); \
hdzlog_debug((buf), (len)); \
printf("\n"); \
dzlog_debug("%s ------\n", (tag)); \
} while (0)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -0,0 +1,428 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
*/
#include <stdio.h>
#include <string.h>
#include <zlog.h>
#include <pcap/pcap.h>
#include "lwip/opt.h"
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/snmp.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "netif/etharp.h"
#include "netif/pcapif.h"
#if defined(LWIP_UNIX_LINUX)
#include <linux/if.h>
#include <zmq.h>
/* Define those to better describe your network interface. */
#define IFNAME0 'p'
#define IFNAME1 'c'
#ifndef PCAPIF_DEBUG
#define PCAPIF_DEBUG LWIP_DBG_OFF
#endif
#define MAX_BYTES_PACKAGE (1518)
#define MSQ_QUEUE_HANDLE ("inproc://pcapif_msg_fifo")
struct pcapif {
/* Add whatever per-interface state that is needed here. */
pcap_t *pcap;
const char *eth_name;
unsigned char mac_addr[6];
const char *pkg_filter;
void *msg_input;
void *msg_output;
};
#if !NO_SYS
_Noreturn static void pcapif_thread(void *arg);
#endif /* !NO_SYS */
static void pcapif_msg_thread(void *arg) {
struct netif *netif = (struct netif *)(void *)arg;
struct pcapif *pcapif = (struct pcapif *)netif->state;
while (pcapif && pcapif->msg_output) {
int size;
zmq_msg_t msg;
struct pbuf *p;
zmq_msg_init(&msg);
size = zmq_msg_recv(&msg, pcapif->msg_output, 0);
if (size > 0) {
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL);
if (p != NULL) {
pbuf_take(p, zmq_msg_data(&msg), size);
/* acknowledge that packet has been read(); */
if (netif->input(p, netif) != ERR_OK) {
LWIP_DEBUGF(NETIF_DEBUG, ("pcapif_input: netif input error\n"));
pbuf_free(p);
}
} else {
/* drop packet(); */
MIB2_STATS_NETIF_INC(netif, ifindiscards);
LWIP_DEBUGF(NETIF_DEBUG, ("pcapif_input: could not allocate pbuf\n"));
}
}
usleep(10);
}
}
static void pcap_pkg_cb(unsigned char *args, const struct pcap_pkthdr *pkthdr, const unsigned char *packet) {
struct netif *netif = (struct netif *)(void *)args;
//struct pbuf *p;
//u16_t len = pkthdr->caplen;
struct pcapif *pcapif = (struct pcapif *)netif->state;
if (pcapif && pcapif->msg_input) {
zmq_msg_t msg;
int rc;
zmq_msg_init_size(&msg, pkthdr->caplen);
memcpy(zmq_msg_data(&msg), packet, pkthdr->caplen);
rc = zmq_msg_send(&msg, pcapif->msg_input, 0);
if (rc == -1) {
dzlog_error("Send %d bytes message error: %s\n", pkthdr->caplen, strerror(errno));
}
zmq_msg_close(&msg);
}
}
/*-----------------------------------------------------------------------------------*/
static void low_level_init(struct netif *netif) {
char buf[2048];
bpf_u_int32 netaddr = 0, mask = 0;
pcap_t *pPcap = NULL;
struct bpf_program filter;
char errBuf[PCAP_ERRBUF_SIZE];
struct pcapif *pcapif = (struct pcapif *)netif->state;
memset(errBuf, 0, PCAP_ERRBUF_SIZE);
memset(buf, 0, 2048);
pPcap = pcap_open_live(pcapif->eth_name, MAX_BYTES_PACKAGE, 1, -1, errBuf);
pcap_lookupnet(pcapif->eth_name, &netaddr, &mask, errBuf);
snprintf(buf, 2048, "(%s) and (inbound)", pcapif->pkg_filter);
dzlog_debug("Pcap netif used filter: \"%s\"\n", buf);
if (pcap_compile(pPcap, &filter, buf, 1, mask) == -1) {
dzlog_error("Set package fileter[%s] error: %s\n", buf, pcap_geterr(pPcap));
}
if (pcap_setfilter(pPcap, &filter) == -1) {
dzlog_error("Set package fileter[%s] error: %s\n", buf, pcap_geterr(pPcap));
}
pcapif->pcap = pPcap;
/* Obtain MAC address from network interface. */
netif->hwaddr[0] = pcapif->mac_addr[0];
netif->hwaddr[1] = pcapif->mac_addr[1];
netif->hwaddr[2] = pcapif->mac_addr[2];
netif->hwaddr[3] = pcapif->mac_addr[3];
netif->hwaddr[4] = pcapif->mac_addr[4];
netif->hwaddr[5] = pcapif->mac_addr[5];
netif->hwaddr_len = 6;
/* device capabilities */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
netif_set_link_up(netif);
#if !NO_SYS
sys_thread_new("pcapif_thread", pcapif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
sys_thread_new("pcapif_msg_thread", pcapif_msg_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#endif /* !NO_SYS */
}
/*-----------------------------------------------------------------------------------*/
/*
* low_level_output():
*
* Should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
*/
/*-----------------------------------------------------------------------------------*/
static err_t low_level_output(struct netif *netif, struct pbuf *p) {
char buf[1518]; /* max packet size including VLAN excluding CRC */
ssize_t written;
struct pcapif *pcapif = (struct pcapif *)netif->state;
if (p->tot_len > sizeof(buf)) {
MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
perror("pcapif: packet too large");
return ERR_IF;
}
/* initiate transfer(); */
pbuf_copy_partial(p, buf, p->tot_len, 0);
/* signal that packet should be sent(); */
written = pcap_inject(pcapif->pcap, buf, p->tot_len);
#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("pcapif: write");
return ERR_IF;
} else {
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, (u32_t)written);
return ERR_OK;
}
}
err_t pcapif_output(struct netif *netif, struct pbuf *p) {
return low_level_output(netif, p);
}
/*-----------------------------------------------------------------------------------*/
/*
* pcapif_init():
*
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
*/
/*-----------------------------------------------------------------------------------*/
err_t pcapif_init(struct netif *netif) {
struct pcapif *pcapif = (struct pcapif *)netif->state;
if (pcapif == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, ("pcapif_init: out of memory for pcapif\n"));
return ERR_MEM;
}
MIB2_INIT_NETIF(netif, snmp_ifType_other, 100000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
#if LWIP_IPV4
netif->output = etharp_output;
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
netif->linkoutput = low_level_output;
netif->mtu = 1500;
low_level_init(netif);
return ERR_OK;
}
#if NO_SYS
int pcapif_select(struct netif *netif) {
fd_set fdset;
int ret;
struct timeval tv;
struct pcapif *pcapif;
u32_t msecs = sys_timeouts_sleeptime();
pcapif = (struct pcapif *)netif->state;
tv.tv_sec = msecs / 1000;
tv.tv_usec = (msecs % 1000) * 1000;
FD_ZERO(&fdset);
FD_SET(pcapif->fd, &fdset);
ret = select(pcapif->fd + 1, &fdset, NULL, NULL, &tv);
if (ret > 0) {
pcapif_input(netif);
}
return ret;
}
#else /* NO_SYS */
_Noreturn static void pcapif_thread(void *arg) {
struct netif *netif = (struct netif *)arg;
struct pcapif *pcapif = (struct pcapif *)netif->state;
do {
pcap_loop(pcapif->pcap, -1, pcap_pkg_cb, (unsigned char *)(void *)netif);
} while (1);
}
#endif /* NO_SYS */
#if LWIP_NETIF_STATUS_CALLBACK
static void status_callback(struct netif *state_netif) {
if (netif_is_up(state_netif)) {
#if LWIP_IPV4
dzlog_info("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif)));
#else
printf("status_callback==UP\n");
#endif
} else {
dzlog_error("status_callback==DOWN\n");
}
}
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
static void link_callback(struct netif *state_netif) {
if (netif_is_link_up(state_netif)) {
dzlog_info("link_callback==UP\n");
} else {
dzlog_error("link_callback==DOWN\n");
}
}
#endif /* LWIP_NETIF_LINK_CALLBACK */
static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
err_t err = ERR_OK;
struct netif *netif;
LWIP_UNUSED_ARG(inp);
NETIF_FOREACH(netif) {
if (netif->hwaddr_len == 6 && memcmp(p->payload, 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);
}
return err;
}
}
return err;
}
struct netif *bind_pcap_if(const char *eth_name, const char *pkg_filter) {
void *msg_context = zmq_ctx_new();
struct netif *netif;
struct ifreq ifr;
ip4_addr_t ipaddr, netmask, gw;
struct pcapif *pcapif = (struct pcapif *)mem_malloc(sizeof(struct pcapif));
if (pcapif == NULL) {
dzlog_error("bind_pcapsocket_if: out of memory for pcapif\n");
return NULL;
}
memset(pcapif, 0, sizeof(struct pcapif));
if (eth_name && strlen(eth_name) > 0) {
pcapif->eth_name = eth_name;
}
pcapif->pkg_filter = pkg_filter;
#if 0
if (vxlan_link_init(eth_name) != ERR_OK) {
dzlog_error("bind_pcapsocket_if: Get local nic info failed\n");
return NULL;
}
#endif
ip4_addr_set_zero(&gw);
ip4_addr_set_zero(&ipaddr);
ip4_addr_set_zero(&netmask);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&ipaddr, 192, 168, 100, 32);
IP4_ADDR(&gw, 192, 168, 100, 250);
#if 0
IP4_ADDR(&gw,
(DEFAULT_GW_IPADDR & 0xFF000000),
(DEFAULT_GW_IPADDR & 0xFF0000),
(DEFAULT_GW_IPADDR & 0xFF00),
(DEFAULT_GW_IPADDR & 0xFF));
IP4_ADDR(&ipaddr,
(g_localIpAddrBegin & 0xFF000000),
(g_localIpAddrBegin & 0xFF0000),
(g_localIpAddrBegin & 0xFF00),
(g_localIpAddrBegin & 0xFF));
pcapif->vxlan_support = cfg_get_support_vxlan();
pcapif->pvxLan = g_pvxLanBuf;
#endif
pcapif->mac_addr[0] = 0x00;
pcapif->mac_addr[1] = 0x0C;
pcapif->mac_addr[2] = 0x01;
pcapif->mac_addr[3] = 0x02;
pcapif->mac_addr[4] = 0x00;
pcapif->mac_addr[5] = 0x0a;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, pcapif->eth_name);
if (msg_context) {
pcapif->msg_input = zmq_socket(msg_context, ZMQ_PAIR);
pcapif->msg_output = zmq_socket(msg_context, ZMQ_PAIR);
zmq_bind(pcapif->msg_output, MSQ_QUEUE_HANDLE);
zmq_connect(pcapif->msg_input, MSQ_QUEUE_HANDLE);
}
netif = (struct netif *)mem_malloc(sizeof(struct netif));
if (!netif) {
mem_free(pcapif);
dzlog_error("Create netif error\n");
return NULL;
}
netif_add(netif, &ipaddr, &netmask, &gw, pcapif, pcapif_init, netif_input_data);
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(netif, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
netif_set_link_callback(netif, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
netif_set_default(netif);
return netif;
}
#endif

View File

@ -48,7 +48,7 @@
#include "netif/pppoeif.h" #include "netif/pppoeif.h"
#include "netif/rawif.h" #include "netif/rawif.h"
#include "pppoe_session.h" #include "pppoe_session.h"
#include "netif/pcapif.h"
#if defined(LWIP_UNIX_LINUX) #if defined(LWIP_UNIX_LINUX)
@ -62,7 +62,6 @@
#define DEFAULT_GW_IPADDR (0xC0A80001) #define DEFAULT_GW_IPADDR (0xC0A80001)
static unsigned int g_localIpAddrBegin = DEFAULT_GW_IPADDR + 1; static unsigned int g_localIpAddrBegin = DEFAULT_GW_IPADDR + 1;
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -126,8 +125,8 @@ static void low_level_init(struct netif *netif) {
static err_t low_level_output(struct netif *netif, struct pbuf *p) { static err_t low_level_output(struct netif *netif, struct pbuf *p) {
struct netif *rs_if = get_rawsocket_if(); struct netif *rs_if = get_rawsocket_if();
p->extra = netif->state; p->extra = netif->state;
return rawif_output(rs_if, p); return pcapif_output(rs_if, p);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -17,6 +17,7 @@
#include "config.h" #include "config.h"
#include "msg_queue.h" #include "msg_queue.h"
#include "vxlan_pkg.h" #include "vxlan_pkg.h"
#include "netif/pcapif.h"
typedef struct PPPOE_CACHE { typedef struct PPPOE_CACHE {
PPPPOE_SESSION_DATA pSessionData; PPPPOE_SESSION_DATA pSessionData;
@ -259,10 +260,12 @@ int pppoe_session_init() {
static uv_thread_t uvThread, cacheThread; static uv_thread_t uvThread, cacheThread;
uv_rwlock_init(&g_cacheLock); uv_rwlock_init(&g_cacheLock);
g_rawSocketIf = bind_rawsocket_if(config_get_vxlan_nic_name()); g_rawSocketIf = bind_pcap_if(config_get_vxlan_nic_name(), config_get_vxlan_pkg_filter());
if (g_rawSocketIf) { if (g_rawSocketIf) {
dzlog_info("Create Raw Socket netif: <%p>\n", (void *)g_rawSocketIf); dzlog_info("Create Raw Socket netif: <%p>\n", (void *)g_rawSocketIf);
} else {
dzlog_info("Create Raw Socket error: <%p>\n", (void *)g_rawSocketIf);
} }
// 启动Session状态机线程 // 启动Session状态机线程

View File

@ -13,14 +13,16 @@ static USER_PARAMS g_userInfo[] = {
{0, 400, 24, 371, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x03}, "user1", "password1"}, {0, 400, 24, 371, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x03}, "user1", "password1"},
{1, 300, 16, 12, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x02}, "user2", "password1"}, {1, 300, 16, 12, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x02}, "user2", "password1"},
{2, 300, 14, 15, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x04}, "user3", "password1"}, {2, 300, 14, 15, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x04}, "user3", "password1"},
{3, 400, 24, 17, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x04}, "xajhuang", "aaaHuang1"},
}; };
void user_info_init() { 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]);
user_info_add(3, &g_userInfo[3]);
} }
void user_info_change_status(PUSER_INFO_CONTEXT pInfo, USER_STATUS status) { void user_info_change_status(PUSER_INFO_CONTEXT pInfo, USER_STATUS status) {