route_struct.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * $Id$
  3. *
  4. *
  5. * Copyright (C) 2001-2003 FhG Fokus
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. /* History:
  29. * --------
  30. *
  31. * 2003-04-12 FORCE_RPORT_T added (andrei)
  32. * 2003-04-22 strip_tail added (jiri)
  33. * 2003-10-10 >,<,>=,<=, != and MSGLEN_O added (andrei)
  34. * 2003-10-28 FORCE_TCP_ALIAS added (andrei)
  35. * 2004-02-24 added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
  36. * 2005-12-11 added SND{IP,PORT,PROTO,AF}_O & TO{IP,PORT}_O (andrei)
  37. * 2005-12-19 select framework added SELECT_O and SELECT_ST (mma)
  38. * 2008-12-17 added UDP_MTU_TRY_PROTO_T (andrei)
  39. */
  40. #ifndef route_struct_h
  41. #define route_struct_h
  42. #include <sys/types.h>
  43. #include <regex.h>
  44. #include "select.h"
  45. #include "usr_avp.h"
  46. #define EXPR_DROP -127 /* used only by the expression and if evaluator */
  47. /*
  48. * Other important values (no macros for them yet):
  49. * expr true = 1
  50. * expr false = 0 (used only inside the expression and if evaluator)
  51. *
  52. * action continue or if used in condition true = 1
  53. * action drop/quit/stop script processing = 0
  54. * action error or if used in condition false = -1 (<0 and !=EXPR_DROP)
  55. *
  56. */
  57. /* expression type */
  58. enum expr_type { EXP_T=1, ELEM_T };
  59. enum expr_op {
  60. /* expression operator if type==EXP_T */
  61. LOGAND_OP=1, LOGOR_OP, NOT_OP, BINAND_OP, BINOR_OP,
  62. /* expression operator if type==ELEM_T */
  63. EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP
  64. };
  65. /* expression left member "special" type (if type==ELEM_T)
  66. (start at 51 for debugging purposes: it's better to not overlap with
  67. expr_r_type)
  68. */
  69. enum _expr_l_type{
  70. METHOD_O=51, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
  71. DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, ACTION_O,
  72. NUMBER_O, AVP_O, SNDIP_O, SNDPORT_O, TOIP_O, TOPORT_O, SNDPROTO_O,
  73. SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O};
  74. /* action types */
  75. enum action_type{
  76. FORWARD_T=1, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
  77. SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,
  78. SET_PORT_T, SET_URI_T, SET_HOSTPORTTRANS_T, SET_HOSTALL_T,
  79. SET_USERPHONE_T,
  80. IF_T, SWITCH_T /* only until fixup*/,
  81. BLOCK_T, EVAL_T, SWITCH_JT_T, SWITCH_COND_T, MATCH_COND_T, WHILE_T,
  82. /* module function calls with string only parameters */
  83. MODULE0_T, MODULE1_T, MODULE2_T, MODULE3_T, MODULE4_T, MODULE5_T,
  84. MODULE6_T, MODULEX_T,
  85. /* module function calls, that have some RVE parameters */
  86. MODULE1_RVE_T, MODULE2_RVE_T, MODULE3_RVE_T,
  87. MODULE4_RVE_T, MODULE5_RVE_T, MODULE6_RVE_T, MODULEX_RVE_T,
  88. SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
  89. AVPFLAG_OPER_T,
  90. LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
  91. APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
  92. REVERT_URI_T,
  93. FORWARD_TCP_T,
  94. FORWARD_UDP_T,
  95. FORWARD_TLS_T,
  96. FORWARD_SCTP_T,
  97. FORCE_RPORT_T,
  98. ADD_LOCAL_RPORT_T,
  99. SET_ADV_ADDR_T,
  100. SET_ADV_PORT_T,
  101. FORCE_TCP_ALIAS_T,
  102. LOAD_AVP_T,
  103. AVP_TO_URI_T,
  104. FORCE_SEND_SOCKET_T,
  105. ASSIGN_T,
  106. ADD_T,
  107. UDP_MTU_TRY_PROTO_T,
  108. SET_FWD_NO_CONNECT_T,
  109. SET_RPL_NO_CONNECT_T,
  110. SET_FWD_CLOSE_T,
  111. SET_RPL_CLOSE_T,
  112. CFG_SELECT_T,
  113. CFG_RESET_T
  114. };
  115. #define is_mod_func(a) ((a)->type>=MODULE0_T && (a)->type<=MODULEX_RVE_T)
  116. /* parameter types for actions or types for expression right operands
  117. (WARNING right operands only, not working for left operands) */
  118. enum _operand_subtype{
  119. NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
  120. EXPR_ST, ACTIONS_ST, MODEXP_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
  121. MYSELF_ST, STR_ST, SOCKID_ST, SOCKETINFO_ST, ACTION_ST, AVP_ST,
  122. SELECT_ST, PVAR_ST,
  123. LVAL_ST, RVE_ST,
  124. RETCODE_ST, CASE_ST,
  125. BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST,
  126. SELECT_UNFIXED_ST,
  127. STRING_RVE_ST /* RVE converted to a string (fparam hack) */,
  128. RVE_FREE_FIXUP_ST /* (str)RVE fixed up by a reversable fixup */,
  129. FPARAM_DYN_ST /* temporary only (fparam hack) */,
  130. CFG_GROUP_ST
  131. };
  132. typedef enum _expr_l_type expr_l_type;
  133. typedef enum _operand_subtype expr_r_type;
  134. typedef enum _operand_subtype action_param_type;
  135. /* run flags */
  136. #define EXIT_R_F 1
  137. #define RETURN_R_F 2
  138. #define BREAK_R_F 4
  139. #define DROP_R_F 8
  140. #define IGNORE_ON_BREAK_R_F 256
  141. struct cfg_pos{
  142. int s_line;
  143. int e_line;
  144. unsigned short s_col;
  145. unsigned short e_col;
  146. char *fname;
  147. char *rname;
  148. };
  149. /* Expression operand */
  150. union exp_op {
  151. void* param;
  152. long numval; /* must have the same size as a void*/
  153. struct expr* expr;
  154. char* string;
  155. avp_spec_t* attr;
  156. select_t* select;
  157. regex_t* re;
  158. struct net* net;
  159. struct _str str;
  160. };
  161. struct expr{
  162. enum expr_type type; /* exp, exp_elem */
  163. enum expr_op op; /* and, or, not | ==, =~ */
  164. expr_l_type l_type;
  165. expr_r_type r_type;
  166. union exp_op l;
  167. union exp_op r;
  168. };
  169. typedef struct {
  170. action_param_type type;
  171. union {
  172. long number;
  173. char* string;
  174. struct _str str;
  175. void* data;
  176. avp_spec_t* attr;
  177. select_t* select;
  178. } u;
  179. } action_u_t;
  180. /* maximum internal array/params
  181. * for module function calls val[0] and val[1] store a pointer to the
  182. * function and the number of params, the rest are the function params
  183. */
  184. #define MAX_ACTIONS (2+6)
  185. struct action{
  186. int cline;
  187. char *cfile;
  188. char *rname;
  189. enum action_type type; /* forward, drop, log, send ...*/
  190. int count;
  191. struct action* next;
  192. action_u_t val[MAX_ACTIONS];
  193. };
  194. typedef struct action cfg_action_t;
  195. struct expr* mk_exp(int op, struct expr* left, struct expr* right);
  196. struct expr* mk_elem(int op, expr_l_type ltype, void* lparam,
  197. expr_r_type rtype, void* rparam);
  198. /* @param type - type of the action
  199. @param count - count of couples {type,val} (variable number of parameters)*/
  200. struct action* mk_action(enum action_type type, int count, ...);
  201. struct action* append_action(struct action* a, struct action* b);
  202. void print_action(struct action* a);
  203. void print_actions(struct action* a);
  204. void print_expr(struct expr* exp);
  205. /** joins to cfg file positions into a new one. */
  206. void cfg_pos_join(struct cfg_pos* res,
  207. struct cfg_pos* pos1, struct cfg_pos* pos2);
  208. struct action *get_action_from_param(void **param, int param_no);
  209. #endif