Add aaa-12 添加VLAN转发模块功能代码

SOL 添加VLAN转发模块功能代码
修改人:yinbin
检视人:yinbin

Signed-off-by: yinbin <yinbin@cmhi.chinamobile.com>
This commit is contained in:
yinbin 2019-08-26 01:28:51 -07:00
parent ebc8d47cf0
commit 2b7698bc26
5 changed files with 2782 additions and 241 deletions

View File

@ -23,14 +23,15 @@
#define LOG_CONFIG_MODULE 0x00000004 #define LOG_CONFIG_MODULE 0x00000004
/*vlan config */
#define VLAN_CONFIG_MODULE 0x00000005
/*DHCP CONFIG*/
#define DHCP_CONFIG_MODULE 0x00000006
/*nat config */ /*nat config */
#define NAT_CONFIG_MODULE 0x00000008 #define NAT_CONFIG_MODULE 0x00000008
/*vlan config */
#define VLAN_CONFIG_MODULE 0x00000005
/*DHCP CONFIG*/
#define DHCP_CONFIG_MODULE 0x00000006
/************************* 模块定义结束 **********************/ /************************* 模块定义结束 **********************/
/************************ config id定义 **********************/ /************************ config id定义 **********************/
@ -55,14 +56,17 @@
#define LOG_CONFIG_REMOTE_LEVEL (uint64)((uint64)LOG_CONFIG_MODULE<<32|5) #define LOG_CONFIG_REMOTE_LEVEL (uint64)((uint64)LOG_CONFIG_MODULE<<32|5)
#define LOG_CONFIG_FILE (uint64)((uint64)LOG_CONFIG_MODULE<<32|6) #define LOG_CONFIG_FILE (uint64)((uint64)LOG_CONFIG_MODULE<<32|6)
#define VLAN_CONFIG (uint64)((uint64)VLAN_CONFIG_MODULE<<32|1)
#define DHCP_SUBNET_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|1)
#define DHCP_HOST_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|2)
#define DHCP_SHARED_NETWORK_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|3)
#define DHCP_RELAY_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|4)
#define DHCP_CLIENT_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|5)
#define DHCP_DHCPD_LEASE (uint64)((uint64)DHCP_CONFIG_MODULE<<32|6)
#define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1) #define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1)
#define DHCP_SUBNET_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|1)
#define DHCP_HOST_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|2)
#define DHCP_SHARED_NETWORK_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|3)
#define DHCP_RELAY_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|4)
#define DHCP_CLIENT_CONFIG (uint64)((uint64)DHCP_CONFIG_MODULE<<32|5)
#define DHCP_DHCPD_LEASE (uint64)((uint64)DHCP_CONFIG_MODULE<<32|6)
/************************ config id定义 end**********************/ /************************ config id定义 end**********************/

View File

@ -37,8 +37,8 @@ COMMON_SRCS = configserver.c \
user_manager_config/user_recover_config.c user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \ user_manager_config/user_recover_config.c user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \
user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \ user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \
log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c \ log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c \
nat_config/natconfig.c nat_config/natconfig.c \
vlan_config/vlan_config.c \
# MRS Board Source Files # MRS Board Source Files
PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_LINUX_SRCS = $(COMMON_SRCS)

View File

@ -24,7 +24,11 @@
{ \ { \
LOG_CONFIG_MODULE, \ LOG_CONFIG_MODULE, \
log_config_init \ log_config_init \
} \ }, \
{ \
VLAN_CONFIG_MODULE, \
vlan_config_init \
} \
} }
/* /*
@ -183,6 +187,15 @@
nat_config_proc, \ nat_config_proc, \
NULL, \ NULL, \
nat_config_get_all \ nat_config_get_all \
},\
{\
VLAN_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
vlan_config_chk, \
vlan_config_proc, \
vlan_config_get, \
vlan_config_get_all \
}\ }\
} }

View File

@ -0,0 +1,192 @@
#ifndef VLAN_CONFIG_H_
#define VLAN_CONFIG_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <cjson/cJSON.h>
#include "configm.h"
#include "rpc.h"
#include "parsefile.h"
#include "netconfig.h"
#define MAX_VLAN 4096/* 0用户识别帧优先级,4095保留,共4094个 */
#define VID_MIN 2 /* vid范围2-4094 */
#define VID_MAX MAX_VLAN - 2 /* vid范围2-4094 */
#define MAX_INTERFACES 20 /* 最大接口数目 */
#define IF_NAME_LEN 20 /* 接口名最大长度 */
#define BR_VLAN_NAME_LEN 50 /* br-vlan的名字最大长度 */
#define SYSCALL_BUF_LEN 100
#define BITSPERWORD 32
#define SHIFT 5
#define MASK 0x1F
#define FILE_BUF_LINE 100
#define EACH_PORT_MAX_VLAN_NUM 5
#define ERR_DATA_LEN 500
#define VLAN_TEST_ADD_PATH "/home/eric/code/test/eric/vlan/conf/vlan_test.conf.add"
#define VLAN_TEST_DEL_PATH "/home/eric/code/test/eric/vlan/conf/vlan_test.conf.del"
#define xfree(X) \
do{ \
if(X){ \
free(X); \
X = NULL; \
} \
}while(0);
/* 操作类型ADD、MOD、DEL */
typedef enum{
OP_NONE,
OP_ADD,
OP_MOD,
OP_DEL,
}operation_type;
/* 链路类型none、access、trunk */
typedef enum{
LINK_TYPE_NONE,
LINK_TYPE_ACCESS,
LINK_TYPE_TRUNK,
LINK_TYPE_HYBIRD,
LINK_TYPE_UNKNOWN,
}interface_link_attr;
/* 接口模型1 桥接; 2 路由桥接; 3 路由 */
typedef enum{
INTERFACE_MODEL_FORWARD,
INTERFACE_MODEL_ROUTE_FORWARD,
INTERFACE_MODEL_ROUTE,
}interface_model;
/* 接口网络类型LAN、WAN */
typedef enum{
IF_TYPE_LAN,
IF_TYPE_WAN,
}interface_network_type;
/* 接口VLAN信息 */
typedef struct interface_vlan_info_t{
interface_link_attr attr;
operation_type op_type;//操作类型ADD、DEL、MOD
interface_model if_model;//接口模型
int vidcnt;//vid数量
int vlan_bitmap[MAX_VLAN/BITSPERWORD];
char if_name[IF_NAME_LEN];
}interface_vlan_info;
/* vlan个数100、200、300、400、500、600、700、800、900、1000 */
#define ADD_100 "/home/eric/code/test/eric/vlan/conf/conf.add.100"
#define ADD_100_200 "/home/eric/code/test/eric/vlan/conf/conf.add.100_200"
#define ADD_100_1000 "/home/eric/code/test/eric/vlan/conf/conf.add.100_1000"
#define DEL_100 "/home/eric/code/test/eric/vlan/conf/conf.add.100"
#define DEL_100_200 "/home/eric/code/test/eric/vlan/conf/conf.add.100_200"
#define DEL_100_1000 "/home/eric/code/test/eric/vlan/conf/conf.add.100_1000"
/* void */
void vlan_bitmap_set(int *v, int i);
void vlan_bitmap_clear(int *v, int i);
void interface_vlan_init(void);
void vlan_set_struct_stub(interface_vlan_info *if_vlan_info, operation_type op_type, int *if_vlnum);
void vlan_config_stub(operation_type op_type);
void vlan_config_format_json_stub(int *interface);
void vlan_config_get_all_stub(uint source);
void vlan_config_get_stub(void);
void vlan_config_proc_test(operation_type op_type);
void vlan_config_init(void);
void vlan_config_stub1(void);
void vlan_config_stub1(void);
/* int */
int vlan_bitmap_check(int *v, int i);
int if_vlan2subif(char *if_name, int vid, char *subif);
int br_if_num_stub(char *br_name, operation_type op_type);
int br_if_num(char *br_name);
int create_br_stub(char *br_vlname);
int create_br(char *br_vlname);
int br_addif_stub(char *br_name, char *if_name);
int br_addif(char *br_name, char *if_name);
int interface_br_stub(char *if_name, char *br_name);
int interface_br(char *if_name, char *br_name);
int del_br_stub(char *br_name);
int del_br(char *br_name);
int add_bridge_vlan_access(char *if_name, int vid);
int check_config(char *if_name);
int add_interface_vlan_access(char *if_name, int *vlan_bitmap, interface_model if_model);
int add_bridge_vlan_trunk(char *if_name, int *vlan_bitmap);
int add_bridge_vlan_trunk(char *if_name, int *vlan_bitmap);
int del_bridge_vlan_access(char *if_name);
int del_bridge_vlan_access(char *if_name);
int del_bridge_vlan_trunk(char *if_name);
int get_ifnode_from_global(char *if_name);
int find_insert_ifnode_from_global(char *if_name);
int get_old_interface_attr(char *if_name, interface_link_attr *attr);
int if_model_is_change(interface_model old, interface_model new);
/* typedefine */
interface_link_attr get_attr_from_ifname(char *if_name);
interface_network_type lan_or_wan_stub(char *if_name);
interface_network_type lan_or_wan(char *if_name);
interface_model get_old_interface_model(char *if_name, interface_model *if_model);
interface_model which_interface_model(char *if_name);
/* ret_code */
ret_code add_interface_vlan_trunk(char *if_name, int *vlan_bitmap, interface_model if_model);
ret_code add_interface_vlan(interface_vlan_info *if_vlan_info);
ret_code del_vlan_sub_interface(char *if_name, int *vlan_bitmap);
ret_code add_vlan_sub_interface(char *if_name, int *vlan_bitmap);
ret_code del_interface_vlan_trunk(char *if_name, int *vlan_bitmap, interface_model if_model);
ret_code refresh_if_vlan_info_op_add(interface_vlan_info *if_vlan_info);
ret_code refresh_if_vlan_info_op_del(interface_vlan_info *if_vlan_info);
ret_code vlan_save_conf_file_add(interface_vlan_info *if_vlan_info);
ret_code vlan_save_conf_file_del(interface_vlan_info *if_vlan_info);
ret_code vlan_save_conf_file(interface_vlan_info *if_vlan_info);
ret_code refresh_if_vlan_info(interface_vlan_info *if_vlan_info);
ret_code del_interface_vlan(interface_vlan_info *if_vlan_info);
ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info, int *if_vlnum);
ret_code vlan_config_recovery(void);
ret_code vlan_get_json_parse(int *interface, pointer input);
ret_code vlan_config_format_json(int *interface, pointer output, int *output_len);
ret_code vlan_get_from_conf_file(int *interface);
ret_code vlan_config_get_all(uint source, pointer output, int *output_len);
ret_code vlan_config_json_parse_test(char *path, interface_vlan_info *if_vlan_info, int *if_vlnum);
ret_code vlan_config_json_parse_test1(operation_type op_type, interface_vlan_info *if_vlan_info, int *if_vlnum);
ret_code vlan_config_chk_test(operation_type op_type);
ret_code interface_vlan_check(interface_vlan_info *if_vlan_info);
ret_code if_attr_chk(interface_vlan_info *if_vlan_info);
ret_code op_type_chk(interface_vlan_info *if_vlan_info);
ret_code op_type_add_chk(interface_vlan_info *if_vlan_info);
ret_code op_type_del_chk(interface_vlan_info *if_vlan_info);
ret_code vid_value_chk(int vid);
ret_code vid_num_chk(char *if_name, operation_type op_type, int num);
ret_code if_name_chk(interface_vlan_info *if_vlan_info);
ret_code vlan_config_set_chk(uint source, pointer input);
ret_code vlan_operate_parse(pointer input, int *operate_type);
ret_code vlan_config_get_chk(uint source, pointer input);
ret_code vlan_config_get_all_chk(uint source, pointer input);
ret_code del_compose_if_vlan_info(char *if_name, interface_vlan_info *if_vlan_info);
ret_code interface_vlan_set(interface_vlan_info *if_vlan_info);
ret_code vlan_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len);
ret_code vlan_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len);
ret_code vlan_config_chk(uint source,uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len);
int del_interface_vlan_cb(BR_EVENT_TYPE event_type, br_event_t event_arg);
#endif /* VLAN_CONFIG_H_ */

File diff suppressed because it is too large Load Diff