2019-08-26 08:28:51 +00:00
|
|
|
|
#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<>û<EFBFBD>ʶ<EFBFBD><CAB6>֡<EFBFBD><D6A1><EFBFBD>ȼ<EFBFBD>,4095<39><35><EFBFBD><EFBFBD>,<2C><>4094<39><34> */
|
|
|
|
|
#define VID_MIN 2 /* vid<69><64>Χ2-4094 */
|
|
|
|
|
#define VID_MAX MAX_VLAN - 2 /* vid<69><64>Χ2-4094 */
|
|
|
|
|
#define MAX_INTERFACES 20 /* <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>Ŀ */
|
|
|
|
|
#define IF_NAME_LEN 20 /* <20>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#define BR_VLAN_NAME_LEN 50 /* br-vlan<61><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>ADD<44><44>MOD<4F><44>DEL */
|
|
|
|
|
typedef enum{
|
|
|
|
|
OP_NONE,
|
|
|
|
|
OP_ADD,
|
|
|
|
|
OP_MOD,
|
|
|
|
|
OP_DEL,
|
|
|
|
|
}operation_type;
|
|
|
|
|
|
|
|
|
|
/* <20><>·<EFBFBD><C2B7><EFBFBD>ͣ<EFBFBD>none<6E><65>access<73><73>trunk */
|
|
|
|
|
typedef enum{
|
|
|
|
|
LINK_TYPE_NONE,
|
|
|
|
|
LINK_TYPE_ACCESS,
|
|
|
|
|
LINK_TYPE_TRUNK,
|
|
|
|
|
LINK_TYPE_HYBIRD,
|
|
|
|
|
LINK_TYPE_UNKNOWN,
|
|
|
|
|
}interface_link_attr;
|
|
|
|
|
|
|
|
|
|
/* <20>ӿ<EFBFBD>ģ<EFBFBD>ͣ<EFBFBD>1 <20>Ž<EFBFBD>; 2 ·<><C2B7><EFBFBD>Ž<EFBFBD>; 3 ·<><C2B7> */
|
|
|
|
|
typedef enum{
|
|
|
|
|
INTERFACE_MODEL_FORWARD,
|
|
|
|
|
INTERFACE_MODEL_ROUTE_FORWARD,
|
|
|
|
|
INTERFACE_MODEL_ROUTE,
|
|
|
|
|
}interface_model;
|
|
|
|
|
|
|
|
|
|
/* <20>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>LAN<41><4E>WAN */
|
|
|
|
|
typedef enum{
|
|
|
|
|
IF_TYPE_LAN,
|
|
|
|
|
IF_TYPE_WAN,
|
|
|
|
|
}interface_network_type;
|
|
|
|
|
|
|
|
|
|
/* <20>ӿ<EFBFBD>VLAN<41><4E>Ϣ */
|
|
|
|
|
typedef struct interface_vlan_info_t{
|
|
|
|
|
|
|
|
|
|
interface_link_attr attr;
|
|
|
|
|
operation_type op_type;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADD<44><44>DEL<45><4C>MOD
|
|
|
|
|
interface_model if_model;//<2F>ӿ<EFBFBD>ģ<EFBFBD><C4A3>
|
|
|
|
|
int vidcnt;//vid<69><64><EFBFBD><EFBFBD>
|
|
|
|
|
int vlan_bitmap[MAX_VLAN/BITSPERWORD];
|
|
|
|
|
char if_name[IF_NAME_LEN];
|
|
|
|
|
}interface_vlan_info;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* vlan<61><6E><EFBFBD><EFBFBD>100<30><30>200<30><30>300<30><30>400<30><30>500<30><30>600<30><30>700<30><30>800<30><30>900<30><30>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);
|
2019-09-02 07:56:35 +00:00
|
|
|
|
ret_code vlan_config_init(void);
|
2019-08-26 08:28:51 +00:00
|
|
|
|
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);
|
2019-08-30 10:18:37 +00:00
|
|
|
|
ret_code if_attr_chk(interface_link_attr attr);
|
2019-08-26 08:28:51 +00:00
|
|
|
|
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);
|
2019-08-30 10:18:37 +00:00
|
|
|
|
ret_code if_name_chk(char *if_name);
|
2019-08-26 08:28:51 +00:00
|
|
|
|
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_ */
|
|
|
|
|
|