00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef route_struct_h
00043 #define route_struct_h
00044
00045 #include <sys/types.h>
00046 #include <regex.h>
00047 #include "select.h"
00048 #include "usr_avp.h"
00049
00050 #define EXPR_DROP -127
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 enum expr_type { EXP_T=1, ELEM_T };
00065 enum expr_op {
00066
00067 LOGAND_OP=1, LOGOR_OP, NOT_OP, BINAND_OP, BINOR_OP,
00068
00069 EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP
00070 };
00071
00072
00073
00074
00075 enum _expr_l_type{
00076 METHOD_O=51, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
00077 DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, ACTION_O,
00078 NUMBER_O, AVP_O, SNDIP_O, SNDPORT_O, TOIP_O, TOPORT_O, SNDPROTO_O,
00079 SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O};
00080
00081 enum action_type{
00082 FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
00083 SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,
00084 SET_PORT_T, SET_URI_T, SET_HOSTPORTTRANS_T, SET_HOSTALL_T,
00085 SET_USERPHONE_T,
00086 IF_T, SWITCH_T ,
00087 BLOCK_T, EVAL_T, SWITCH_JT_T, SWITCH_COND_T, MATCH_COND_T, WHILE_T,
00088
00089 MODULE0_T, MODULE1_T, MODULE2_T, MODULE3_T, MODULE4_T, MODULE5_T,
00090 MODULE6_T, MODULEX_T,
00091
00092 MODULE1_RVE_T, MODULE2_RVE_T, MODULE3_RVE_T,
00093 MODULE4_RVE_T, MODULE5_RVE_T, MODULE6_RVE_T, MODULEX_RVE_T,
00094 SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
00095 AVPFLAG_OPER_T,
00096 LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
00097 APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
00098 REVERT_URI_T,
00099 FORWARD_TCP_T,
00100 FORWARD_UDP_T,
00101 FORWARD_TLS_T,
00102 FORWARD_SCTP_T,
00103 SEND_TCP_T,
00104 FORCE_RPORT_T,
00105 ADD_LOCAL_RPORT_T,
00106 SET_ADV_ADDR_T,
00107 SET_ADV_PORT_T,
00108 FORCE_TCP_ALIAS_T,
00109 LOAD_AVP_T,
00110 AVP_TO_URI_T,
00111 FORCE_SEND_SOCKET_T,
00112 ASSIGN_T,
00113 ADD_T,
00114 UDP_MTU_TRY_PROTO_T,
00115 SET_FWD_NO_CONNECT_T,
00116 SET_RPL_NO_CONNECT_T,
00117 SET_FWD_CLOSE_T,
00118 SET_RPL_CLOSE_T,
00119 CFG_SELECT_T,
00120 CFG_RESET_T
00121 };
00122
00123 #define is_mod_func(a) ((a)->type>=MODULE0_T && (a)->type<=MODULEX_RVE_T)
00124
00125
00126
00127 enum _operand_subtype{
00128 NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
00129 EXPR_ST, ACTIONS_ST, MODEXP_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
00130 MYSELF_ST, STR_ST, SOCKID_ST, SOCKETINFO_ST, ACTION_ST, AVP_ST,
00131 SELECT_ST, PVAR_ST,
00132 LVAL_ST, RVE_ST,
00133 RETCODE_ST, CASE_ST,
00134 BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST,
00135 SELECT_UNFIXED_ST,
00136 STRING_RVE_ST ,
00137 RVE_FREE_FIXUP_ST ,
00138 FPARAM_DYN_ST ,
00139 CFG_GROUP_ST
00140 };
00141
00142 typedef enum _expr_l_type expr_l_type;
00143 typedef enum _operand_subtype expr_r_type;
00144 typedef enum _operand_subtype action_param_type;
00145
00146
00147 #define EXIT_R_F 1
00148 #define RETURN_R_F 2
00149 #define BREAK_R_F 4
00150 #define DROP_R_F 8
00151 #define IGNORE_ON_BREAK_R_F 256
00152
00153
00154 struct cfg_pos{
00155 int s_line;
00156 int e_line;
00157 unsigned short s_col;
00158 unsigned short e_col;
00159 char *fname;
00160 };
00161
00162
00163
00164 union exp_op {
00165 void* param;
00166 long numval;
00167 struct expr* expr;
00168 char* string;
00169 avp_spec_t* attr;
00170 select_t* select;
00171 regex_t* re;
00172 struct net* net;
00173 struct _str str;
00174 };
00175
00176 struct expr{
00177 enum expr_type type;
00178 enum expr_op op;
00179 expr_l_type l_type;
00180 expr_r_type r_type;
00181 union exp_op l;
00182 union exp_op r;
00183 };
00184
00185 typedef struct {
00186 action_param_type type;
00187 union {
00188 long number;
00189 char* string;
00190 struct _str str;
00191 void* data;
00192 avp_spec_t* attr;
00193 select_t* select;
00194 } u;
00195 } action_u_t;
00196
00197
00198
00199
00200
00201 #define MAX_ACTIONS (2+6)
00202
00203 struct action{
00204 int cline;
00205 char *cfile;
00206 enum action_type type;
00207 int count;
00208 struct action* next;
00209 action_u_t val[MAX_ACTIONS];
00210 };
00211
00212 typedef struct action cfg_action_t;
00213
00214 struct expr* mk_exp(int op, struct expr* left, struct expr* right);
00215 struct expr* mk_elem(int op, expr_l_type ltype, void* lparam,
00216 expr_r_type rtype, void* rparam);
00217
00218
00219
00220 struct action* mk_action(enum action_type type, int count, ...);
00221
00222 struct action* append_action(struct action* a, struct action* b);
00223
00224 void print_action(struct action* a);
00225 void print_actions(struct action* a);
00226 void print_expr(struct expr* exp);
00227
00229 void cfg_pos_join(struct cfg_pos* res,
00230 struct cfg_pos* pos1, struct cfg_pos* pos2);
00231
00232 struct action *get_action_from_param(void **param, int param_no);
00233 #endif
00234