parent
d7659f5124
commit
05d6c5ee60
|
@ -163,9 +163,9 @@ PMQ_DATA_ADD_USER decode_add_user_msg(const char *pStrJson, PMQ_DATA_ADD_USER *p
|
|||
int j;
|
||||
memset(pCurrent->pUser, 0, sizeof(ADD_USER_USER) * nUser);
|
||||
for (j = 0; j < nUser; j++) {
|
||||
PADD_USER_USER p = &pCurrent->pUser[j];
|
||||
cJSON *pJsonU = cJSON_GetArrayItem(puser, j);
|
||||
PADD_USER_USER pTmp = j2s_add_user(pJsonU);
|
||||
PADD_USER_USER p = &pCurrent->pUser[j];
|
||||
cJSON *pJsonU = cJSON_GetArrayItem(puser, j);
|
||||
PADD_USER_USER pTmp = j2s_add_user(pJsonU);
|
||||
|
||||
if (pTmp) {
|
||||
memcpy(p, pTmp, sizeof(ADD_USER_USER));
|
||||
|
@ -246,6 +246,7 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) {
|
|||
int m, n;
|
||||
for (m = 0; m < p->infoCount; m++) {
|
||||
PADD_INFO pInfo = &(p->pInfo[m]);
|
||||
vxlan_peer_add(pInfo->vxlan.vsvxlanIP, pInfo->vxlan.vsvxlanMac);
|
||||
for (n = 0; n < pInfo->userCount; n++) {
|
||||
PADD_USER_USER pUser = &(pInfo->pUser[n]);
|
||||
USER_PARAMS userInfo;
|
||||
|
@ -254,12 +255,11 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) {
|
|||
|
||||
userInfo.pppoe_user = pUser->pppoeUser;
|
||||
userInfo.pppoe_passwd = pUser->pppoePass;
|
||||
userInfo.vni = pUser->vni;
|
||||
userInfo.userid = pUser->userId;
|
||||
userInfo.q1 = pUser->c_tag_in;
|
||||
userInfo.q2 = pUser->s_tag_in;
|
||||
userInfo.vni = pUser->vni;
|
||||
userInfo.userid = pUser->userId;
|
||||
userInfo.q1 = pUser->c_tag_in;
|
||||
userInfo.q2 = pUser->s_tag_in;
|
||||
str_to_mac(pUser->clientMac, userInfo.mac_addr);
|
||||
vxlan_peer_add(pUser->vni, pInfo->vxlan.vsvxlanIP, pInfo->vxlan.vsvxlanMac);
|
||||
user_info_add(userInfo.userid, &userInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,21 +25,19 @@ typedef struct {
|
|||
} NIC_INFO, *PNIC_INFO;
|
||||
|
||||
typedef struct {
|
||||
unsigned int vni;
|
||||
unsigned char peerMac[ETH_HWADDR_LEN];
|
||||
unsigned int peerIp;
|
||||
unsigned char snd_pkg_head[VXLAN_HEAD_SIZE];
|
||||
UT_hash_handle hh;
|
||||
} VXLAN_PEER, *PVXLAN_PEER;
|
||||
unsigned int peerIp;
|
||||
unsigned char peerMac[ETH_HWADDR_LEN];
|
||||
unsigned char snd_pkg_head[VXLAN_HEAD_SIZE];
|
||||
} VXLAN_PKG_HEAD, *PVXLAN_PKG_HEAD;
|
||||
|
||||
|
||||
typedef struct {
|
||||
NIC_INFO nic_info;
|
||||
PVXLAN_PEER vxlan_peer;
|
||||
uv_rwlock_t lock_peer;
|
||||
NIC_INFO nic_info;
|
||||
PVXLAN_PKG_HEAD pkg_head;
|
||||
uv_rwlock_t lock_peer;
|
||||
} VXLAN_LINK_CONFIG, *PVXLAN_LINK_CONFIG;
|
||||
|
||||
static VXLAN_LINK_CONFIG g_vxLanLinks;
|
||||
static PVXLAN_PEER g_pAllvxLanPeers = NULL;
|
||||
|
||||
static struct pbuf *vxlan_pkg_recombine(const unsigned char *pBuf, unsigned short size) {
|
||||
struct pbuf *q;
|
||||
|
@ -118,13 +116,8 @@ unsigned char *vxlan_pkg_encode(const unsigned char *pInBuf, int inSize, PVXLAN_
|
|||
unsigned short udp_len = inSize + sizeof(vxlan_hdr_t) + sizeof(qinq_hdr_t) + sizeof(udp_hdr_t);
|
||||
unsigned short ip_len = udp_len + 20;
|
||||
unsigned int total_len = ip_len + sizeof(struct eth_hdr);
|
||||
PVXLAN_PEER pvxlanBuf;
|
||||
|
||||
uv_rwlock_rdlock(&g_vxLanLinks.lock_peer);
|
||||
HASH_FIND_INT(g_pAllvxLanPeers, &pTag->vni, pvxlanBuf);
|
||||
uv_rwlock_rdunlock(&g_vxLanLinks.lock_peer);
|
||||
|
||||
if (pvxlanBuf == NULL || outSize == NULL) {
|
||||
if(g_vxLanLinks.pkg_head == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -139,7 +132,7 @@ unsigned char *vxlan_pkg_encode(const unsigned char *pInBuf, int inSize, PVXLAN_
|
|||
pkg = (struct vxlan_package *)pBuf;
|
||||
|
||||
// 复制优先构造好的头部数据
|
||||
memcpy(pBuf, pvxlanBuf->snd_pkg_head, VXLAN_HEAD_SIZE);
|
||||
memcpy(pBuf, g_vxLanLinks.pkg_head->snd_pkg_head, VXLAN_HEAD_SIZE);
|
||||
// 设置VNI ID
|
||||
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pTag->vni));
|
||||
|
||||
|
@ -172,7 +165,7 @@ unsigned char *vxlan_pkg_encode(const unsigned char *pInBuf, int inSize, PVXLAN_
|
|||
return pBuf;
|
||||
}
|
||||
|
||||
static void vxlan_pkg_head_init(PVXLAN_PEER pvxLan) {
|
||||
static void vxlan_pkg_head_init(PVXLAN_PKG_HEAD pvxLan) {
|
||||
struct vxlan_package *pkg = (struct vxlan_package *)pvxLan->snd_pkg_head;
|
||||
|
||||
// 设置目的Mac
|
||||
|
@ -210,7 +203,7 @@ static void vxlan_pkg_head_init(PVXLAN_PEER pvxLan) {
|
|||
pkg->vxlan_head.res1 = 0x00;
|
||||
pkg->vxlan_head.res2 = 0x00;
|
||||
pkg->vxlan_head.res3 = 0x00;
|
||||
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pvxLan->vni));
|
||||
//pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pvxLan->vni));
|
||||
|
||||
// 设置内层ETH头部
|
||||
// 设置内层报文类型
|
||||
|
@ -220,21 +213,16 @@ static void vxlan_pkg_head_init(PVXLAN_PEER pvxLan) {
|
|||
pkg->qinq_head.in_type = lwip_htons(QINQ_802_1_AD);
|
||||
}
|
||||
|
||||
int vxlan_peer_add(unsigned int vni, const char *pIp, const char *pMac) {
|
||||
PVXLAN_PEER vxlan_peer;
|
||||
|
||||
int vxlan_peer_add(const char *pIp, const char *pMac) {
|
||||
if (!VERIFY_STRING(pIp) || !VERIFY_STRING(pMac)) {
|
||||
dzlog_error("Input parameters error: %s, %s\n", SAFETY_STR_STRING(pIp), SAFETY_STR_STRING(pMac));
|
||||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
uv_rwlock_rdlock(&g_vxLanLinks.lock_peer);
|
||||
HASH_FIND_INT(g_pAllvxLanPeers, &vni, vxlan_peer);
|
||||
uv_rwlock_rdunlock(&g_vxLanLinks.lock_peer);
|
||||
|
||||
if (vxlan_peer == NULL) {
|
||||
if(g_vxLanLinks.pkg_head == NULL) {
|
||||
unsigned int peerIp;
|
||||
unsigned char peerMac[6];
|
||||
PVXLAN_PKG_HEAD pkg;
|
||||
|
||||
str_to_mac(pMac, peerMac);
|
||||
|
||||
|
@ -243,25 +231,20 @@ int vxlan_peer_add(unsigned int vni, const char *pIp, const char *pMac) {
|
|||
return -ERR_SYS_INIT;
|
||||
}
|
||||
|
||||
vxlan_peer = (PVXLAN_PEER)malloc(sizeof(VXLAN_PEER));
|
||||
pkg = (PVXLAN_PKG_HEAD)malloc(sizeof(VXLAN_PKG_HEAD));
|
||||
|
||||
if (vxlan_peer == NULL) {
|
||||
if (pkg == NULL) {
|
||||
return -ERR_MALLOC_MEMORY;
|
||||
}
|
||||
|
||||
memset(vxlan_peer, 0, sizeof(VXLAN_PEER));
|
||||
memset(pkg, 0, sizeof(VXLAN_PKG_HEAD));
|
||||
|
||||
vxlan_peer->vni = vni;
|
||||
vxlan_peer->peerIp = lwip_htonl(peerIp);
|
||||
memcpy(vxlan_peer->peerMac, peerMac, ETH_HWADDR_LEN);
|
||||
pkg->peerIp = lwip_htonl(peerIp);
|
||||
memcpy(pkg->peerMac, peerMac, ETH_HWADDR_LEN);
|
||||
// 对发送报文的头部进行初始化
|
||||
vxlan_pkg_head_init(vxlan_peer);
|
||||
vxlan_pkg_head_init(pkg);
|
||||
|
||||
uv_rwlock_wrlock(&g_vxLanLinks.lock_peer);
|
||||
HASH_ADD_INT(g_pAllvxLanPeers, vni, vxlan_peer);
|
||||
uv_rwlock_wrunlock(&g_vxLanLinks.lock_peer);
|
||||
|
||||
dzlog_debug("Add vxLan[vni = %d]: vSwitch: %s, %s\n", vni, pIp, pMac);
|
||||
dzlog_debug("Add vxLan Link: vSwitch: %s, %s\n", pIp, pMac);
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
|
@ -276,7 +259,6 @@ int vxlan_link_init(const char *pEthName) {
|
|||
memset(&g_vxLanLinks, 0, sizeof(VXLAN_LINK_CONFIG));
|
||||
|
||||
uv_rwlock_init(&g_vxLanLinks.lock_peer);
|
||||
g_vxLanLinks.vxlan_peer = g_pAllvxLanPeers;
|
||||
|
||||
strncpy(g_vxLanLinks.nic_info.ethName, pEthName, ETH_NAME_MAX);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ extern "C" {
|
|||
|
||||
int vxlan_link_init(const char *pEthName);
|
||||
int vxlan_pkg_decode(const struct pbuf *p, struct pbuf **pOut, PVXLAN_TAG pTag);
|
||||
int vxlan_peer_add(unsigned int vni, const char* pIp, const char* pMac);
|
||||
int vxlan_peer_add(const char *pIp, const char *pMac);
|
||||
unsigned char *vxlan_pkg_encode(const unsigned char *pInBuf, int inSize, PVXLAN_TAG pTag, unsigned int *outSize);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue