secgateway/Platform/user/configm/config-server/include/vlan_config.h

192 lines
7.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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);
ret_code vlan_config_init(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_link_attr attr);
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(char *if_name);
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_ */