142 lines
4.8 KiB
C
142 lines
4.8 KiB
C
#ifndef FREEAUTH_H_
|
||
#define FREEAUTH_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 "../../../../common/rpc/rpc_common.h"
|
||
|
||
#define DPORT_MIN_NUM 1
|
||
#define DPORT_MAX_NUM 65535
|
||
#define RULE_MAX_NUM 10
|
||
|
||
#define FREEAUTH_CONFIG_ADD 0
|
||
#define FREEAUTH_CONFIG_MOV 1
|
||
#define FREEAUTH_CONFIG_DEL 2
|
||
#define FREEAUTH_CONFIG_MOD 3
|
||
#define FREEAUTH_CONFIG_GET 4
|
||
#define FREEAUTH_CONFIG_DEL_ALL 5
|
||
|
||
#define UNAMESIZE (63)
|
||
|
||
/*配置消息 */
|
||
typedef struct {
|
||
int rule_priority; /*未认证权限优先级*/
|
||
char name[UNAMESIZE + 1]; /*未认证权限名称*/
|
||
uint32_t sip; /*未认证权限源IP地址*/
|
||
uint32_t dip; /*未认证权限目的IP地址*/
|
||
int dport; /*未认证权限目的端口号*/
|
||
int flag; /*状态标志位,0表示状态启动,1表示状态禁用*/
|
||
|
||
}freeauth_configure_t;
|
||
|
||
/*配置消息 */
|
||
typedef struct {
|
||
int rule_priority; /*未认证权限优先级*/
|
||
char name[UNAMESIZE + 1]; /*未认证权限名称*/
|
||
char sip[20]; /*未认证权限源IP地址*/
|
||
char dip[20]; /*未认证权限目的IP地址*/
|
||
int dport; /*未认证权限目的端口号*/
|
||
int flag; /*状态标志位,0表示状态启动,1表示状态禁用*/
|
||
|
||
}freeauth_configure_json_t;
|
||
|
||
|
||
/*修改权限消息*/
|
||
typedef struct {
|
||
char name[UNAMESIZE + 1];
|
||
int after;
|
||
}rule_mod_t;
|
||
|
||
typedef struct {
|
||
int resultcode;
|
||
char *message;
|
||
}authfree_result_t;
|
||
|
||
|
||
/* 判断IPv4格式是否正确*/
|
||
int isIpV4Addr(const char *ipAddr);
|
||
|
||
/*组播报文的目的地址使用D类IP地址,范围是从224.0.1.0到239.255.255.255*/
|
||
int isMulticastAddr(uint32_t address);
|
||
|
||
/*判断ip地址是广播地址 255.255.255.255*/
|
||
int isBroadcastIpV4Addr(const char *ipAddr);
|
||
|
||
/*下发配置到内核态 */
|
||
int set_freeauthcfg_waitack(freeauth_configure_t *struct_freeauth);
|
||
|
||
/*获取json串类型*/
|
||
ret_code freeauth_config_json_type(pointer input, uint *conf_type);
|
||
|
||
/*修改json字符串转为结构体 把未认证权限名称为name的序号移动到序号3前面*/
|
||
/*iuput格式:{"type": 1, "data": {"name": "armink", "after": 3}}*/
|
||
ret_code freeauth_mov_json_parse(pointer input, uint *conf_type, rule_mod_t *rule_mod);
|
||
|
||
|
||
/*json字符串转为结构体*/
|
||
/*iuput格式:{"type": 0, "data": {"rule_priority": 1, "name": "armink","sip": 1027824,"dip": 103427824,"dport": 24, "flag":0}}*/
|
||
ret_code freeauth_config_json_parse(pointer input, uint *conf_type, freeauth_configure_t *freeauth_buff);
|
||
|
||
|
||
/*iuput格式:
|
||
{
|
||
"type": 0,
|
||
"data": [
|
||
{"rule_priority": 1,"name": "cary","sip": 2323790,"dip": 13546465478,"dport": 120, "flag":0},
|
||
{"rule_priority": 2,"name": "nicole","sip": 2323790,"dip": 13546465478,"dport": 130, "flag":0},
|
||
{"rule_priority": 3,"name": "arwrgmink","sip": 2323790,"dip": 13546465478,"dport": 90, "flag":0}
|
||
]
|
||
}
|
||
*/
|
||
ret_code authfree_config_json_parse_array(pointer input, uint *conf_type, freeauth_configure_t **fb, int *cnt);
|
||
|
||
|
||
/*chk data格式 */
|
||
ret_code freeauth_config_chk(uint source, uint *config_type,
|
||
pointer input, int *input_len,
|
||
pointer output, int *output_len);
|
||
|
||
/*增加未认证权限规则 */
|
||
ret_code freeauth_config_add_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
/*移动未认证权限规则 */
|
||
ret_code freeauth_config_mov_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
/*删除未认证权限规则 */
|
||
ret_code freeauth_config_del_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
/*修改未认证权限规则*/
|
||
ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
/*查询未认证权限*/
|
||
ret_code freeauth_config_get_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
/*删除所有免认证规则*/
|
||
ret_code freeauth_config_del_all_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
ret_code freeauth_config_proc(uint source, uint config_type,
|
||
pointer input, int input_len,
|
||
pointer output, int *output_len);
|
||
|
||
|
||
#endif |