MOD aaa-12 桥接口自测问题解决,桥接口创建之后自动up
SOL 桥接口自测问题解决 修改人:zhangliang 检视人:zhangliang
This commit is contained in:
parent
9853dbeebf
commit
5c71c16363
|
@ -27,7 +27,8 @@ VPATH = ../user/configm/config-server
|
||||||
# set the source file, don't used .o because of ...
|
# set the source file, don't used .o because of ...
|
||||||
|
|
||||||
COMMON_SRCS = configserver.c \
|
COMMON_SRCS = configserver.c \
|
||||||
netconfig/ipconfig/ipconfig.c netconfig/parsefile.c \
|
netconfig/parsefile.c netconfig/ifconfig.c netconfig/netmain.c\
|
||||||
|
netconfig/ipconfig/ipconfig.c \
|
||||||
netconfig/bridge/brconfig.c netconfig/bridge/brnetlink.c \
|
netconfig/bridge/brconfig.c netconfig/bridge/brnetlink.c \
|
||||||
netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\
|
netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\
|
||||||
authfree_config/authfree.c \
|
authfree_config/authfree.c \
|
||||||
|
@ -43,7 +44,7 @@ COMMON_SRCS = configserver.c \
|
||||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||||
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||||
|
|
||||||
COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog -I../user/configm/config-server/netconfig/bridge/include
|
COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog -I../user/configm/config-server/netconfig/ -I../user/configm/config-server/netconfig/bridge/include
|
||||||
# gcc CFLAGS
|
# gcc CFLAGS
|
||||||
PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/arm64/usr/local/include
|
PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/arm64/usr/local/include
|
||||||
PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/x86_64/usr/local/include
|
PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/x86_64/usr/local/include
|
||||||
|
|
|
@ -3,17 +3,16 @@
|
||||||
|
|
||||||
#include "s2j/s2j.h"
|
#include "s2j/s2j.h"
|
||||||
#include "../../../../common/rpc/rpc_common.h"
|
#include "../../../../common/rpc/rpc_common.h"
|
||||||
#include "ipconfig.h"
|
|
||||||
#include "../../../../../Common/commuapinl.h"
|
#include "../../../../../Common/commuapinl.h"
|
||||||
#include "../user_manager_config/user_group_config.h"
|
#include "../user_manager_config/user_group_config.h"
|
||||||
#include "../user_manager_config/user_account_config.h"
|
#include "../user_manager_config/user_account_config.h"
|
||||||
|
#include "netconfig.h"
|
||||||
#include "log_config.h"
|
#include "log_config.h"
|
||||||
#include "authfree.h"
|
#include "authfree.h"
|
||||||
#include "localportal.h"
|
#include "localportal.h"
|
||||||
#include "jumppage.h"
|
#include "jumppage.h"
|
||||||
#include "userlock.h"
|
#include "userlock.h"
|
||||||
#include "agingtime.h"
|
#include "agingtime.h"
|
||||||
#include "brconfig.h"
|
|
||||||
|
|
||||||
/* 类型定义 */
|
/* 类型定义 */
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@
|
||||||
{\
|
{\
|
||||||
{ \
|
{ \
|
||||||
NETCONFIG_MODULE, \
|
NETCONFIG_MODULE, \
|
||||||
br_bridge_init \
|
net_main \
|
||||||
}, \
|
}, \
|
||||||
{ \
|
{ \
|
||||||
LOG_CONFIG_MODULE, \
|
LOG_CONFIG_MODULE, \
|
||||||
|
@ -96,22 +95,22 @@
|
||||||
NULL \
|
NULL \
|
||||||
},\
|
},\
|
||||||
{\
|
{\
|
||||||
BRIF_CONFIG, \
|
BRIF_CONFIG, \
|
||||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||||
FALSE, \
|
FALSE, \
|
||||||
br_if_config_chk, \
|
br_if_config_chk, \
|
||||||
br_if_config_proc, \
|
br_if_config_proc, \
|
||||||
br_if_config_get, \
|
br_if_config_get, \
|
||||||
br_if_config_get_all \
|
br_if_config_get_all \
|
||||||
},\
|
},\
|
||||||
{\
|
{\
|
||||||
BRFDB_CONFIG, \
|
BRFDB_CONFIG, \
|
||||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||||
FALSE, \
|
FALSE, \
|
||||||
br_fdb_config_chk, \
|
br_fdb_config_chk, \
|
||||||
NULL, \
|
NULL, \
|
||||||
br_fdb_config_get, \
|
br_fdb_config_get, \
|
||||||
NULL \
|
NULL \
|
||||||
},\
|
},\
|
||||||
{\
|
{\
|
||||||
USER_MANAGER_CONFIG_GROUP, \
|
USER_MANAGER_CONFIG_GROUP, \
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "parsefile.h"
|
#include "parsefile.h"
|
||||||
#include "libbridge.h"
|
#include "libbridge.h"
|
||||||
#include "libbridge_private.h"
|
#include "libbridge_private.h"
|
||||||
|
#include "netconfig.h"
|
||||||
|
|
||||||
/* 事件通知函数 */
|
/* 事件通知函数 */
|
||||||
br_event_head_t br_event_tbl = {.head.first = NULL, .lock = 0, .init = FALSE};
|
br_event_head_t br_event_tbl = {.head.first = NULL, .lock = 0, .init = FALSE};
|
||||||
|
|
|
@ -0,0 +1,238 @@
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <net/if_arp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#include "rpc.h"
|
||||||
|
#include "ipconfig.h"
|
||||||
|
|
||||||
|
/* call ioctl system call */
|
||||||
|
ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret)
|
||||||
|
{
|
||||||
|
int sock;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
*ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (sock < 0)
|
||||||
|
{
|
||||||
|
rpc_log_error("Cannot create UDP socket");
|
||||||
|
return RET_SOCKERR;
|
||||||
|
}
|
||||||
|
if ((err = ioctl(sock, request, ifreq)) < 0)
|
||||||
|
{
|
||||||
|
rpc_log_error("Ioctl error: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
close(sock);
|
||||||
|
|
||||||
|
if (err < 0)
|
||||||
|
{
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
*ret = err;
|
||||||
|
}
|
||||||
|
return RET_SYSERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Set a certain interface flag. */
|
||||||
|
static int if_set_flag(char *ifname, short flag, int *code)
|
||||||
|
{
|
||||||
|
struct ifreq ifr = {0};
|
||||||
|
ret_code ret = RET_OK;
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCGIFFLAGS, &ifr, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
|
||||||
|
ifr.ifr_flags |= flag;
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCSIFFLAGS, &ifr, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Clear a certain interface flag. */
|
||||||
|
static int if_clear_flag(char *ifname, short flag, int *code)
|
||||||
|
{
|
||||||
|
struct ifreq ifr = {0};
|
||||||
|
ret_code ret;
|
||||||
|
|
||||||
|
safe_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCGIFFLAGS, &ifr, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
safe_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
|
||||||
|
ifr.ifr_flags &= ~flag;
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCSIFFLAGS, &ifr)
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code if_set_prefix(ip_config_t *ip_conf, int *code)
|
||||||
|
{
|
||||||
|
ret_code ret;
|
||||||
|
struct ifreq ifreq = {0};
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
struct sockaddr_in mask;
|
||||||
|
|
||||||
|
strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1);
|
||||||
|
addr.sin_addr = ip_conf->prefix;
|
||||||
|
addr.sin_family = ip_conf->family;
|
||||||
|
memcpy(&ifreq.ifr_addr, &addr, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCSIFADDR, (caddr_t)&ifreq, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
if(ip_conf->prefix.s_addr != 0)
|
||||||
|
{
|
||||||
|
masklen2ip(ip_conf->prefixlen, &mask.sin_addr);
|
||||||
|
mask.sin_family = ip_conf->family;
|
||||||
|
memcpy(&ifreq.ifr_netmask, &mask, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCSIFNETMASK, (caddr_t)&ifreq, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code if_get_prefix_all(pointer output, int *output_len, int *code)
|
||||||
|
{
|
||||||
|
struct ifreq ifreq[MAX_IF_NUM];
|
||||||
|
struct sockaddr_in *addr;
|
||||||
|
struct ifreq netmask;
|
||||||
|
ip_config_t *ip_conf;
|
||||||
|
struct ifconf ifc;
|
||||||
|
int if_count = 0;
|
||||||
|
ret_code ret;
|
||||||
|
int mask_ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(&ifc, 0, sizeof(struct ifconf));
|
||||||
|
memset(&ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq));
|
||||||
|
|
||||||
|
ifc.ifc_len = MAX_IF_NUM * sizeof(struct ifreq);
|
||||||
|
ifc.ifc_buf = (char *)ifreq;
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCGIFCONF, (caddr_t)&ifc, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
if_count = ifc.ifc_len / (sizeof(struct ifreq));
|
||||||
|
|
||||||
|
rpc_log_info("if num is %d\n", if_count);
|
||||||
|
|
||||||
|
if((if_count * sizeof(ip_config_t) > CM_BUFF_SIZE)
|
||||||
|
|| (if_count == 0))
|
||||||
|
{
|
||||||
|
ret = RET_NOMEM;
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_conf = rpc_new(ip_config_t, MAX_IF_NUM);
|
||||||
|
if(ip_conf == NULL)
|
||||||
|
{
|
||||||
|
return RET_NOMEM;
|
||||||
|
}
|
||||||
|
memset(ip_conf, 0, MAX_IF_NUM * sizeof(ip_config_t));
|
||||||
|
|
||||||
|
for(i = 0; i < if_count; i++)
|
||||||
|
{
|
||||||
|
rpc_log_info("get interface %s info\n", ifreq[i].ifr_name);
|
||||||
|
strncpy(ip_conf[i].ifname, ifreq[i].ifr_name, INTERFACE_NAMSIZ - 1);
|
||||||
|
ip_conf[i].family = AF_INET;
|
||||||
|
ip_conf[i].prefix = ((struct sockaddr_in *)&(ifreq[i].ifr_addr))->sin_addr;
|
||||||
|
|
||||||
|
memset(&netmask, 0, sizeof(netmask));
|
||||||
|
strncpy(netmask.ifr_name, ifreq[i].ifr_name, sizeof(netmask.ifr_name) - 1);
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCGIFNETMASK, (caddr_t)&netmask, &mask_ret);
|
||||||
|
ASSERT_RET_NO(ret);
|
||||||
|
|
||||||
|
addr = ( struct sockaddr_in * )&(netmask.ifr_netmask );
|
||||||
|
ip_conf[i].prefixlen = ip_masklen(addr->sin_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_config_format_json_array(CM_CONFIG_GET, ip_conf, if_count, output, output_len);
|
||||||
|
|
||||||
|
rpc_free(ip_conf);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code if_get_prefix(ip_config_t *ip_conf, int *code)
|
||||||
|
{
|
||||||
|
struct sockaddr_in *addr;
|
||||||
|
struct ifreq netmask;
|
||||||
|
struct ifreq ifreq;
|
||||||
|
ret_code ret = RET_OK;
|
||||||
|
int mask_ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(ip_conf->family != AF_INET)
|
||||||
|
{
|
||||||
|
ret = RET_INPUTERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
memset(&ifreq, 0, sizeof(struct ifreq));
|
||||||
|
|
||||||
|
rpc_log_info("get interface %s info\n", ip_conf->ifname);
|
||||||
|
|
||||||
|
strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1);
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCGIFADDR, (caddr_t)&ifreq, code);
|
||||||
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
|
||||||
|
ip_conf->prefix = ((struct sockaddr_in *)&(ifreq.ifr_addr))->sin_addr;
|
||||||
|
|
||||||
|
memset(&ifreq, 0, sizeof(ifreq));
|
||||||
|
strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1);
|
||||||
|
|
||||||
|
ret = if_ioctl(SIOCGIFNETMASK, (caddr_t)&ifreq, &mask_ret);
|
||||||
|
ASSERT_RET_NO(ret);
|
||||||
|
|
||||||
|
addr = ( struct sockaddr_in * )&(ifreq.ifr_netmask);
|
||||||
|
ip_conf->prefixlen = ip_masklen(addr->sin_addr);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code if_set_up(char *ifname, int *code)
|
||||||
|
{
|
||||||
|
return if_set_flag(ifname, (IFF_UP | IFF_RUNNING), code);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code if_set_down(char *ifname, int *code)
|
||||||
|
{
|
||||||
|
return if_clear_flag(ifname, IFF_UP, code);
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ipconfig.h"
|
#include "ipconfig.h"
|
||||||
#include "rpc.h"
|
#include "rpc.h"
|
||||||
#include "parsefile.h"
|
#include "parsefile.h"
|
||||||
|
#include "netconfig.h"
|
||||||
|
|
||||||
uchar ip_masklen(struct in_addr netmask)
|
uchar ip_masklen(struct in_addr netmask)
|
||||||
{
|
{
|
||||||
|
@ -61,39 +62,6 @@ void ip_save_file(ip_config_t *ip_conf, uint config_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call ioctl system call */
|
|
||||||
ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret)
|
|
||||||
{
|
|
||||||
int sock;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
*ret = 0;
|
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
if (sock < 0)
|
|
||||||
{
|
|
||||||
rpc_log_error("Cannot create UDP socket");
|
|
||||||
return RET_SOCKERR;
|
|
||||||
}
|
|
||||||
if ((*ret = ioctl(sock, request, ifreq)) < 0)
|
|
||||||
{
|
|
||||||
err = errno;
|
|
||||||
rpc_log_error("Ioctl error: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
close(sock);
|
|
||||||
|
|
||||||
if (*ret < 0)
|
|
||||||
{
|
|
||||||
errno = err;
|
|
||||||
*ret = err;
|
|
||||||
return RET_SYSERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ret_code ip_config_json_parse(pointer input, uint *conf_type, ip_config_t *config_buff)
|
ret_code ip_config_json_parse(pointer input, uint *conf_type, ip_config_t *config_buff)
|
||||||
{
|
{
|
||||||
|
@ -290,138 +258,6 @@ ret_code ip_config_format_json_array(int config_type, ip_config_t *config_buff,
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ret_code if_set_prefix(ip_config_t *ip_conf, int *code)
|
|
||||||
{
|
|
||||||
ret_code ret;
|
|
||||||
struct ifreq ifreq = {0};
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
struct sockaddr_in mask;
|
|
||||||
|
|
||||||
strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1);
|
|
||||||
addr.sin_addr = ip_conf->prefix;
|
|
||||||
addr.sin_family = ip_conf->family;
|
|
||||||
memcpy(&ifreq.ifr_addr, &addr, sizeof(struct sockaddr_in));
|
|
||||||
|
|
||||||
ret = if_ioctl(SIOCSIFADDR, (caddr_t)&ifreq, code);
|
|
||||||
ASSERT_RET(ret);
|
|
||||||
|
|
||||||
if(ip_conf->prefix.s_addr != 0)
|
|
||||||
{
|
|
||||||
masklen2ip(ip_conf->prefixlen, &mask.sin_addr);
|
|
||||||
mask.sin_family = ip_conf->family;
|
|
||||||
memcpy(&ifreq.ifr_netmask, &mask, sizeof(struct sockaddr_in));
|
|
||||||
|
|
||||||
ret = if_ioctl(SIOCSIFNETMASK, (caddr_t)&ifreq, code);
|
|
||||||
ASSERT_RET(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_code if_get_prefix_all(pointer output, int *output_len, int *code)
|
|
||||||
{
|
|
||||||
struct ifreq ifreq[MAX_IF_NUM];
|
|
||||||
struct sockaddr_in *addr;
|
|
||||||
struct ifreq netmask;
|
|
||||||
ip_config_t *ip_conf;
|
|
||||||
struct ifconf ifc;
|
|
||||||
int if_count = 0;
|
|
||||||
ret_code ret;
|
|
||||||
int mask_ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
memset(&ifc, 0, sizeof(struct ifconf));
|
|
||||||
memset(&ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq));
|
|
||||||
|
|
||||||
ifc.ifc_len = MAX_IF_NUM * sizeof(struct ifreq);
|
|
||||||
ifc.ifc_buf = (char *)ifreq;
|
|
||||||
|
|
||||||
ret = if_ioctl(SIOCGIFCONF, (caddr_t)&ifc, code);
|
|
||||||
ASSERT_RET(ret);
|
|
||||||
|
|
||||||
if_count = ifc.ifc_len / (sizeof(struct ifreq));
|
|
||||||
|
|
||||||
rpc_log_info("if num is %d\n", if_count);
|
|
||||||
|
|
||||||
if((if_count * sizeof(ip_config_t) > CM_BUFF_SIZE)
|
|
||||||
|| (if_count == 0))
|
|
||||||
{
|
|
||||||
ret = RET_NOMEM;
|
|
||||||
ASSERT_RET(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
ip_conf = rpc_new(ip_config_t, MAX_IF_NUM);
|
|
||||||
if(ip_conf == NULL)
|
|
||||||
{
|
|
||||||
return RET_NOMEM;
|
|
||||||
}
|
|
||||||
memset(ip_conf, 0, MAX_IF_NUM * sizeof(ip_config_t));
|
|
||||||
|
|
||||||
for(i = 0; i < if_count; i++)
|
|
||||||
{
|
|
||||||
rpc_log_info("get interface %s info\n", ifreq[i].ifr_name);
|
|
||||||
strncpy(ip_conf[i].ifname, ifreq[i].ifr_name, INTERFACE_NAMSIZ - 1);
|
|
||||||
ip_conf[i].family = AF_INET;
|
|
||||||
ip_conf[i].prefix = ((struct sockaddr_in *)&(ifreq[i].ifr_addr))->sin_addr;
|
|
||||||
|
|
||||||
memset(&netmask, 0, sizeof(netmask));
|
|
||||||
strncpy(netmask.ifr_name, ifreq[i].ifr_name, sizeof(netmask.ifr_name) - 1);
|
|
||||||
|
|
||||||
ret = if_ioctl(SIOCGIFNETMASK, (caddr_t)&netmask, &mask_ret);
|
|
||||||
ASSERT_RET_NO(ret);
|
|
||||||
|
|
||||||
addr = ( struct sockaddr_in * )&(netmask.ifr_netmask );
|
|
||||||
ip_conf[i].prefixlen = ip_masklen(addr->sin_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
ip_config_format_json_array(CM_CONFIG_GET, ip_conf, if_count, output, output_len);
|
|
||||||
|
|
||||||
rpc_free(ip_conf);
|
|
||||||
return RET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_code if_get_prefix(ip_config_t *ip_conf, int *code)
|
|
||||||
{
|
|
||||||
struct sockaddr_in *addr;
|
|
||||||
struct ifreq netmask;
|
|
||||||
struct ifreq ifreq;
|
|
||||||
ret_code ret = RET_OK;
|
|
||||||
int mask_ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if(ip_conf->family != AF_INET)
|
|
||||||
{
|
|
||||||
ret = RET_INPUTERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_RET(ret);
|
|
||||||
|
|
||||||
memset(&ifreq, 0, sizeof(struct ifreq));
|
|
||||||
|
|
||||||
rpc_log_info("get interface %s info\n", ip_conf->ifname);
|
|
||||||
|
|
||||||
strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1);
|
|
||||||
|
|
||||||
ret = if_ioctl(SIOCGIFADDR, (caddr_t)&ifreq, code);
|
|
||||||
ASSERT_RET(ret);
|
|
||||||
|
|
||||||
|
|
||||||
ip_conf->prefix = ((struct sockaddr_in *)&(ifreq.ifr_addr))->sin_addr;
|
|
||||||
|
|
||||||
memset(&ifreq, 0, sizeof(ifreq));
|
|
||||||
strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1);
|
|
||||||
|
|
||||||
ret = if_ioctl(SIOCGIFNETMASK, (caddr_t)&ifreq, &mask_ret);
|
|
||||||
ASSERT_RET_NO(ret);
|
|
||||||
|
|
||||||
addr = ( struct sockaddr_in * )&(ifreq.ifr_netmask);
|
|
||||||
ip_conf->prefixlen = ip_masklen(addr->sin_addr);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_code ip_config_set_chk(uint source,uint config_type,
|
ret_code ip_config_set_chk(uint source,uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len)
|
pointer output, int *output_len)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef NETCONFIG_H_
|
||||||
|
#define NETCONFIG_H_
|
||||||
|
#include "ipconfig.h"
|
||||||
|
#include "brconfig.h"
|
||||||
|
|
||||||
|
ret_code if_set_prefix(ip_config_t *ip_conf, int *code);
|
||||||
|
ret_code if_get_prefix_all(pointer output, int *output_len, int *code);
|
||||||
|
ret_code if_get_prefix(ip_config_t *ip_conf, int *code);
|
||||||
|
ret_code if_set_up(char *ifname, int *code);
|
||||||
|
ret_code if_set_down(char *ifname, int *code);
|
||||||
|
|
||||||
|
int net_main();
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "netconfig.h"
|
||||||
|
|
||||||
|
|
||||||
|
int net_main()
|
||||||
|
{
|
||||||
|
br_bridge_init();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue