// // config.h // // Created by foxist on 2019/8/13. // #ifndef config_h #define config_h //#define NAT_DEBUG #include #include #include #include #include #ifndef NAT_DEBUG #include "rpc.h" #endif #ifdef NAT_DEBUG typedef enum ret_code { RET_OK, RET_ERR, RET_NOMEM, RET_INPUTERR } ret_code; #endif #define MAX_ERR_MSG 1024 #define MAX_LINE_LEN 384 #define MAX_ACTION 8 #define MAX_ID 5 #define MAX_CHAIN 15 #define MAX_TARGET 15 #define MAX_PROT 15 #define MAX_ADDR 45 #define MAX_IP 33 #define MAX_PORT 5 #define MAX_DEVICE 15 #define MAX_MATCH 6 #define MAX_MATCH_INFO 10 #define IPT_PARANUM 14 #define NF_PARANUM 8 #define SUCCESS 1 #define FAIL 0 typedef unsigned char uchar; typedef char *iptables_rule; typedef int boolean; struct ipt_config{ char action[MAX_ACTION]; // 动作:0: delete, 1: add, 2: save, 3: restore char id[MAX_ID]; // 配置删除id char chain[MAX_CHAIN]; // 链 char target[MAX_TARGET]; // char prot[MAX_PROT]; // 协议 char source[MAX_IP]; // 源地址 char destination[MAX_IP]; // 目的地址 char sport[MAX_PORT]; char dport[MAX_PORT]; // 端口号 char to[MAX_ADDR]; //union { char i_device[MAX_DEVICE]; char o_device[MAX_DEVICE]; //} char match[MAX_MATCH]; char match_info[MAX_MATCH_INFO]; }; typedef struct range_ipt_config { int begin; int offset; struct ipt_config conf; } range_ipt_config; typedef struct ip_port { char ip[MAX_IP]; char port[MAX_PORT]; } ip_port; typedef struct nf_conntrack { ip_port addr[4]; char prot[MAX_PROT]; } nf_conntrack; /* ======================== PUBLIC API ============================*/ // 从iptables-save配置文件中,获取json格式的nat配置信息 ret_code get_iptables_config(const char *json, const char * __restrict__ __filename, char *output, int *outlen, char **msg); // 使用json数据格式,配置ipables nat ret_code set_iptables_config(const char *json, char **msg); //ret_code get_nf_conntrack(const char * __restrict__ __filename, // char *output, int *outlen, char **msg); // linux系统命令执行函数, 返回shell信息 ret_code run_command(char *const cmd, char **msg); #endif /* config_h */