Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
728c67c12a
|
@ -38,6 +38,7 @@ typedef enum {
|
||||||
RET_IPINVALID = 13,
|
RET_IPINVALID = 13,
|
||||||
RET_BR_INVALID = 14,
|
RET_BR_INVALID = 14,
|
||||||
RET_EXIST = 15,
|
RET_EXIST = 15,
|
||||||
|
RET_FULL = 16
|
||||||
} ret_code;
|
} ret_code;
|
||||||
|
|
||||||
#define RET_ERROR_DISC \
|
#define RET_ERROR_DISC \
|
||||||
|
@ -57,7 +58,8 @@ typedef enum {
|
||||||
{ RET_INPUTERR, "InputError"},\
|
{ RET_INPUTERR, "InputError"},\
|
||||||
{ RET_IPINVALID, "IpInvalid"},\
|
{ RET_IPINVALID, "IpInvalid"},\
|
||||||
{ RET_BR_INVALID, "BrNameInvalid"},\
|
{ RET_BR_INVALID, "BrNameInvalid"},\
|
||||||
{ RET_EXIST, "AlreadyExist"}\
|
{ RET_EXIST, "AlreadyExist"},\
|
||||||
|
{ RET_FULL, "FULL"}\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RET_BUFF_SIZE 256;
|
#define RET_BUFF_SIZE 256;
|
||||||
|
|
|
@ -3,9 +3,21 @@
|
||||||
#include "ipconfig.h"
|
#include "ipconfig.h"
|
||||||
#include "brconfig.h"
|
#include "brconfig.h"
|
||||||
|
|
||||||
|
#define PORT_MAX_VLAN (10)
|
||||||
|
|
||||||
|
/* 事件通知数据结构 */
|
||||||
|
struct _net_ifnum {
|
||||||
|
int wan_num;
|
||||||
|
int lan_num;
|
||||||
|
};
|
||||||
|
typedef struct _net_ifnum net_ifnum_t;
|
||||||
|
|
||||||
ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret);
|
ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret);
|
||||||
ret_code if_set_up(char *ifname, int *code);
|
ret_code if_set_up(char *ifname, int *code);
|
||||||
ret_code if_set_down(char *ifname, int *code);
|
ret_code if_set_down(char *ifname, int *code);
|
||||||
|
ret_code if_num_init();
|
||||||
|
int if_lan_num();
|
||||||
|
int if_wan_num();
|
||||||
|
|
||||||
ret_code net_main();
|
ret_code net_main();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,7 +21,7 @@ void ip_conf_file_del(char *if_name, char *conf_buff);
|
||||||
|
|
||||||
ret_code del_sub_string(char *str_in,char *str_sub);
|
ret_code del_sub_string(char *str_in,char *str_sub);
|
||||||
int if_read_dev_file(struct ifreq *ifcfg, int max_port);
|
int if_read_dev_file(struct ifreq *ifcfg, int max_port);
|
||||||
ret_code if_conf_file_init();
|
|
||||||
int if_read_conf_file(struct ifreq *ifcfg, int max_port);
|
int if_read_conf_file(struct ifreq *ifcfg, int max_port);
|
||||||
|
ret_code if_role_file_get(char *if_name, char *conf_buff);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,6 +19,17 @@
|
||||||
/* 事件通知函数 */
|
/* 事件通知函数 */
|
||||||
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};
|
||||||
|
|
||||||
|
int br_vlan_bridge(char *br_name)
|
||||||
|
{
|
||||||
|
if(br_name[0] == 'b' && br_name[1] == 'r'
|
||||||
|
&& br_name[2] == 'v' && br_name[3] == 'l')
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg)
|
int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg)
|
||||||
{
|
{
|
||||||
br_event_node_t *hnode;
|
br_event_node_t *hnode;
|
||||||
|
@ -327,6 +338,18 @@ ret_code br_bridge_add(char *br_name, int *sys_err)
|
||||||
br_event_t event_arg = {br_name, NULL};
|
br_event_t event_arg = {br_name, NULL};
|
||||||
int sys_ret = 0;
|
int sys_ret = 0;
|
||||||
|
|
||||||
|
if(br_vlan_bridge(br_name))
|
||||||
|
{
|
||||||
|
if(brvl_for_bridge_num() >= PORT_MAX_VLAN * if_lan_num())
|
||||||
|
{
|
||||||
|
return RET_FULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(br_for_bridge_num() >= if_lan_num())
|
||||||
|
{
|
||||||
|
return RET_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
br_invoke_event(BR_CREATE_EVENT_PRE, event_arg);
|
br_invoke_event(BR_CREATE_EVENT_PRE, event_arg);
|
||||||
|
|
||||||
sys_ret = br_add_bridge(br_name);
|
sys_ret = br_add_bridge(br_name);
|
||||||
|
@ -577,6 +600,10 @@ ret_code br_config_chk(uint source,uint *config_type,
|
||||||
{
|
{
|
||||||
case CM_CONFIG_ADD:
|
case CM_CONFIG_ADD:
|
||||||
case CM_CONFIG_DEL:
|
case CM_CONFIG_DEL:
|
||||||
|
if(strcasecmp(br_name, "br0") == 0)
|
||||||
|
{
|
||||||
|
ret = RET_NOTSUPPORT;
|
||||||
|
}
|
||||||
case CM_CONFIG_GET:
|
case CM_CONFIG_GET:
|
||||||
ret = br_name_chk(br_name);
|
ret = br_name_chk(br_name);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -120,4 +120,7 @@ extern int br_read_fdb(const char *br, struct fdb_entry *fdbs,
|
||||||
extern int br_set_hairpin_mode(const char *bridge, const char *dev,
|
extern int br_set_hairpin_mode(const char *bridge, const char *dev,
|
||||||
int hairpin_mode);
|
int hairpin_mode);
|
||||||
extern int br_for_port_num(const char *brname, int *cnt);
|
extern int br_for_port_num(const char *brname, int *cnt);
|
||||||
|
extern int br_for_bridge_num();
|
||||||
|
extern int brvl_for_bridge_num();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -150,21 +150,50 @@ int br_foreach_bridge(int (*iterator)(const char *, void *),
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int brvl_cnt_num(const char *name, void *arg)
|
||||||
|
{
|
||||||
|
int *cnt = arg;
|
||||||
|
|
||||||
|
if(name[0] == 'b' && name[1] == 'r'
|
||||||
|
&& name[2] == 'v' && name[3] == 'l')
|
||||||
|
{
|
||||||
|
(*cnt)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int brvl_for_bridge_num()
|
||||||
|
{
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
br_foreach_bridge(brvl_cnt_num, &cnt);
|
||||||
|
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int br_cnt_num(const char *name, void *arg)
|
int br_cnt_num(const char *name, void *arg)
|
||||||
{
|
{
|
||||||
int *cnt = arg;
|
int *cnt = arg;
|
||||||
|
|
||||||
|
if(name[0] != 'b' || name[1] != 'r'
|
||||||
|
|| name[2] != 'v' || name[3] != 'l')
|
||||||
|
{
|
||||||
(*cnt)++;
|
(*cnt)++;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int br_for_bridge_num(int *cnt)
|
int br_for_bridge_num()
|
||||||
{
|
{
|
||||||
*cnt = 0;
|
int cnt = 0;
|
||||||
br_foreach_bridge(br_cnt_num, cnt);
|
|
||||||
|
|
||||||
return 0;
|
br_foreach_bridge(br_cnt_num, &cnt);
|
||||||
|
|
||||||
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
|
|
||||||
#include "rpc.h"
|
#include "rpc.h"
|
||||||
#include "netconfig.h"
|
#include "netconfig.h"
|
||||||
|
#include "parsefile.h"
|
||||||
|
|
||||||
|
net_ifnum_t g_if_num = {.wan_num = 2, .lan_num = 4};
|
||||||
|
|
||||||
/* call ioctl system call */
|
/* call ioctl system call */
|
||||||
ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret)
|
ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret)
|
||||||
|
@ -104,4 +107,57 @@ ret_code if_set_down(char *ifname, int *code)
|
||||||
return if_clear_flag(ifname, IFF_UP, code);
|
return if_clear_flag(ifname, IFF_UP, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int if_lan_num()
|
||||||
|
{
|
||||||
|
return g_if_num.lan_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int if_wan_num()
|
||||||
|
{
|
||||||
|
return g_if_num.wan_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code if_num_init()
|
||||||
|
{
|
||||||
|
char role_str[IF_BUFF_LEN] = {0};
|
||||||
|
struct ifreq ifreq[MAX_IF_NUM];
|
||||||
|
int if_count = 0;
|
||||||
|
int lan_count = 0;
|
||||||
|
int wan_count = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(&ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq));
|
||||||
|
|
||||||
|
if_count = if_read_dev_file(ifreq, MAX_IF_NUM);
|
||||||
|
for(i = 0; i < if_count; i++)
|
||||||
|
{
|
||||||
|
memset(role_str, 0, IF_BUFF_LEN);
|
||||||
|
|
||||||
|
if(if_role_file_get(ifreq[i].ifr_name, role_str) != RET_OK)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcasecmp(role_str, "lan"))
|
||||||
|
{
|
||||||
|
lan_count++;
|
||||||
|
}
|
||||||
|
else if(strcasecmp(role_str, "wan"))
|
||||||
|
{
|
||||||
|
wan_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lan_count != 0)
|
||||||
|
{
|
||||||
|
g_if_num.lan_num = lan_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wan_count != 0)
|
||||||
|
{
|
||||||
|
g_if_num.wan_num = wan_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -333,16 +333,16 @@ ret_code if_get_prefix_all(pointer output, int *output_len, int *code)
|
||||||
int mask_ret;
|
int mask_ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(&ifc, 0, sizeof(struct ifconf));
|
memset(ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq));
|
||||||
memset(&ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq));
|
|
||||||
|
|
||||||
ifc.ifc_len = MAX_IF_NUM * sizeof(struct ifreq);
|
if_count = if_read_dev_file(ifreq, MAX_IF_NUM);
|
||||||
ifc.ifc_buf = (char *)ifreq;
|
|
||||||
|
|
||||||
if_count = if_read_dev_file(&ifreq, MAX_IF_NUM);
|
|
||||||
|
|
||||||
if(if_count == 0)
|
if(if_count == 0)
|
||||||
{
|
{
|
||||||
|
memset(&ifc, 0, sizeof(struct ifconf));
|
||||||
|
ifc.ifc_len = MAX_IF_NUM * sizeof(struct ifreq);
|
||||||
|
ifc.ifc_buf = (char *)ifreq;
|
||||||
|
|
||||||
ret = if_ioctl(SIOCGIFCONF, (caddr_t)&ifc, code);
|
ret = if_ioctl(SIOCGIFCONF, (caddr_t)&ifc, code);
|
||||||
ASSERT_RET(ret);
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
|
@ -358,12 +358,11 @@ ret_code if_get_prefix_all(pointer output, int *output_len, int *code)
|
||||||
ASSERT_RET(ret);
|
ASSERT_RET(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_conf = rpc_new(ip_config_t, MAX_IF_NUM);
|
ip_conf = rpc_new0(ip_config_t, MAX_IF_NUM);
|
||||||
if(ip_conf == NULL)
|
if(ip_conf == NULL)
|
||||||
{
|
{
|
||||||
return RET_NOMEM;
|
return RET_NOMEM;
|
||||||
}
|
}
|
||||||
memset(ip_conf, 0, MAX_IF_NUM * sizeof(ip_config_t));
|
|
||||||
|
|
||||||
for(i = 0; i < if_count; i++)
|
for(i = 0; i < if_count; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
|
|
||||||
ret_code net_main()
|
ret_code net_main()
|
||||||
{
|
{
|
||||||
/* 初始化/etc/network/interfaces配置文件 */
|
|
||||||
if_conf_file_init();
|
|
||||||
br_bridge_init();
|
br_bridge_init();
|
||||||
|
|
||||||
|
/* 初始化/etc/network/interfaces配置文件 */
|
||||||
|
if_num_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -868,33 +868,27 @@ void ip_conf_file_del(char *if_name, char *conf_buff)
|
||||||
ret_code if_role_file_get(char *if_name, char *conf_buff)
|
ret_code if_role_file_get(char *if_name, char *conf_buff)
|
||||||
{
|
{
|
||||||
char start_str[IF_BUFF_LEN] = {0};
|
char start_str[IF_BUFF_LEN] = {0};
|
||||||
|
char *p;
|
||||||
|
|
||||||
sprintf(start_str, "interface %s", if_name);
|
sprintf(start_str, "interface %s", if_name);
|
||||||
|
|
||||||
if(conf_value_in_block_get(ETC_PRODUCT, start_str,
|
if(conf_value_in_block_get(ETC_PRODUCT, start_str,
|
||||||
"interface", "role", conf_buff) == RET_NOTFOUND)
|
"interface", "role", conf_buff) == RET_OK)
|
||||||
{
|
{
|
||||||
strcpy(conf_buff, "lan");
|
p = conf_buff + strlen("role");
|
||||||
|
|
||||||
|
while(*p != '\0' && isspace(*p))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
}
|
}
|
||||||
return RET_OK;
|
if(*p != '\0')
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ret_code if_conf_file_init()
|
|
||||||
{
|
|
||||||
/*struct ifreq ifreq[MAX_IF_NUM];
|
|
||||||
int if_count = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
memset(&ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq));
|
|
||||||
|
|
||||||
if_count = if_read_dev_file(ifreq, MAX_IF_NUM);
|
|
||||||
for(i = 0; i < if_count; i++)
|
|
||||||
{
|
{
|
||||||
if_conf_file_add(ifreq[i].ifr_name);
|
strncpy(conf_buff, p, IF_BUFF_LEN);
|
||||||
}*/
|
|
||||||
|
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue