Browse code

- added the missing force_send_socket script command

Andrei Pelinescu-Onciul authored on 30/11/2004 16:28:23
Showing 12 changed files
... ...
@@ -50,7 +50,7 @@ MAIN_NAME=ser
50 50
 VERSION = 0
51 51
 PATCHLEVEL = 8
52 52
 SUBLEVEL =   99
53
-EXTRAVERSION = -dev19
53
+EXTRAVERSION = -dev20
54 54
 
55 55
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
56 56
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -107,6 +107,11 @@ core:
107 107
    unix_tx_timeout = 2000
108 108
        Timeout (in ms) used when sending replies through unix sockets.
109 109
  - new script commands:
110
+   force_send_socket([proto:]address[:port])
111
+       sends the message from the specified socket (it _must_ be one of the
112
+       sockets ser listens on). If the protocol doesn't match (e.g. udp
113
+       message "forced" to a tcp socket) the closest socket of the same
114
+       protocol is used.
110 115
    force_tcp_alias()
111 116
    force_tcp_alias(port)
112 117
        adds a tcp port alias for the current connection (if tcp).
... ...
@@ -36,6 +36,7 @@
36 36
  *  2003-04-22  strip_tail added (jiri)
37 37
  *  2003-10-02  added SET_ADV_ADDR_T & SET_ADV_PORT_T (andrei)
38 38
  *  2003-10-29  added FORCE_TCP_ALIAS_T (andrei)
39
+ *  2004-11-30  added FORCE_SEND_SOCKET_T (andrei)
39 40
  */
40 41
 
41 42
 
... ...
@@ -663,6 +664,16 @@ int do_action(struct action* a, struct sip_msg* msg)
663 663
 #endif
664 664
 			ret=1; /* continue processing */
665 665
 			break;
666
+		case FORCE_SEND_SOCKET_T:
667
+			if (a->p1_type!=SOCKETINFO_ST){
668
+				LOG(L_CRIT, "BUG: do_action: bad force_send_socket argument"
669
+						" type: %d\n", a->p1_type);
670
+				ret=E_BUG;
671
+				break;
672
+			}
673
+			msg->force_send_socket=(struct socket_info*)a->p1.data;
674
+			ret=1; /* continue processing */
675
+			break;
666 676
 		default:
667 677
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
668 678
 	}
... ...
@@ -51,6 +51,7 @@
51 51
  *              added MCAST_TTL (andrei)
52 52
  *  2004-10-08  more escapes: \", \xHH, \nnn and minor optimizations (andrei)
53 53
  *  2004-10-19  added FROM_URI and TO_URI (andrei)
54
+ *  2004-11-30  added force_send_socket
54 55
  */
55 56
 
56 57
 
... ...
@@ -129,6 +130,7 @@ IF				"if"
129 129
 ELSE			"else"
130 130
 SET_ADV_ADDRESS	"set_advertised_address"
131 131
 SET_ADV_PORT	"set_advertised_port"
132
+FORCE_SEND_SOCKET	"force_send_socket"
132 133
 
133 134
 /*ACTION LVALUES*/
134 135
 URIHOST			"uri:host"
... ...
@@ -321,6 +323,8 @@ EAT_ABLE	[\ \t\b\r]
321 321
 										return SET_ADV_ADDRESS; }
322 322
 <INITIAL>{SET_ADV_PORT}	{ count(); yylval.strval=yytext;
323 323
 										return SET_ADV_PORT; }
324
+<INITIAL>{FORCE_SEND_SOCKET}	{	count(); yylval.strval=yytext;
325
+									return FORCE_SEND_SOCKET; }
324 326
 
325 327
 <INITIAL>{URIHOST}	{ count(); yylval.strval=yytext; return URIHOST; }
326 328
 <INITIAL>{URIPORT}	{ count(); yylval.strval=yytext; return URIPORT; }
... ...
@@ -57,6 +57,7 @@
57 57
  * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
58 58
  *              (andrei)
59 59
  * 2004-10-19  added FROM_URI, TO_URI (andrei)
60
+ * 2004-11-30  added force_send_socket (andrei)
60 61
  */
61 62
 
62 63
 
... ...
@@ -97,26 +98,20 @@
97 97
  with no built in alloca, like icc*/
98 98
 #undef _ALLOCA_H
99 99
 
100
-struct id_list{
101
-	char* name;
102
-	int proto;
103
-	int port;
104
-	struct id_list* next;
105
-};
106 100
 
107 101
 extern int yylex();
108 102
 static void yyerror(char* s);
109 103
 static char* tmp;
110 104
 static int i_tmp;
111 105
 static void* f_tmp;
112
-static struct id_list* lst_tmp;
106
+static struct socket_id* lst_tmp;
113 107
 static int rt;  /* Type of route block for find_export */
114 108
 static str* str_tmp;
115 109
 static str s_tmp;
116 110
 static struct ip_addr* ip_tmp;
117 111
 
118 112
 static void warn(char* s);
119
-static struct id_list* mk_listen_id(char*, int, int);
113
+static struct socket_id* mk_listen_id(char*, int, int);
120 114
  
121 115
 
122 116
 %}
... ...
@@ -129,7 +124,7 @@ static struct id_list* mk_listen_id(char*, int, int);
129 129
 	struct action* action;
130 130
 	struct net* ipnet;
131 131
 	struct ip_addr* ipaddr;
132
-	struct id_list* idlst;
132
+	struct socket_id* sockid;
133 133
 }
134 134
 
135 135
 /* terminals */
... ...
@@ -166,6 +161,7 @@ static struct id_list* mk_listen_id(char*, int, int);
166 166
 %token ELSE
167 167
 %token SET_ADV_ADDRESS
168 168
 %token SET_ADV_PORT
169
+%token FORCE_SEND_SOCKET
169 170
 %token URIHOST
170 171
 %token URIPORT
171 172
 %token MAX_LEN
... ...
@@ -297,8 +293,8 @@ static struct id_list* mk_listen_id(char*, int, int);
297 297
 %type <ipnet> ipnet
298 298
 %type <strval> host
299 299
 %type <strval> listen_id
300
-%type <idlst>  id_lst
301
-%type <idlst>  phostport
300
+%type <sockid>  id_lst
301
+%type <sockid>  phostport
302 302
 %type <intval> proto port
303 303
 %type <intval> equalop strop intop
304 304
 %type <strval> host_sep
... ...
@@ -1609,6 +1605,13 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1609 1609
 		| SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1610 1610
 														"string expected"); }
1611 1611
 		| SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
1612
+		| FORCE_SEND_SOCKET LPAREN phostport RPAREN {
1613
+										$$=mk_action(FORCE_SEND_SOCKET_T,
1614
+														SOCKID_ST, 0, $3, 0);
1615
+													}
1616
+		| FORCE_SEND_SOCKET LPAREN error RPAREN { $$=0; yyerror("bad argument,"
1617
+											" [proto:]host[:port] expected"); }
1618
+		| FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
1612 1619
 		| ID LPAREN RPAREN			{ f_tmp=(void*)find_export($1, 0, rt);
1613 1620
 									   if (f_tmp==0){
1614 1621
 										   if (find_export($1, 0, 0)) {
... ...
@@ -1690,10 +1693,10 @@ static void yyerror(char* s)
1690 1690
 }
1691 1691
 
1692 1692
 
1693
-static struct id_list* mk_listen_id(char* host, int proto, int port)
1693
+static struct socket_id* mk_listen_id(char* host, int proto, int port)
1694 1694
 {
1695
-	struct id_list* l;
1696
-	l=pkg_malloc(sizeof(struct id_list));
1695
+	struct socket_id* l;
1696
+	l=pkg_malloc(sizeof(struct socket_id));
1697 1697
 	if (l==0){
1698 1698
 		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
1699 1699
 	}else{
... ...
@@ -80,6 +80,12 @@ route{
80 80
 		sl_send_reply("513", "Message too big");
81 81
 		break;
82 82
 	};
83
+	
84
+	if (src_ip==193.175.135.0/24){
85
+		force_send_socket(smaug:5080);
86
+		forward(193.175.135.179);
87
+		break;
88
+	}
83 89
 
84 90
 	# we record-route all messages -- to make sure that
85 91
 	# subsequent messages will go through our proxy; that's
... ...
@@ -118,6 +118,14 @@ struct dest_info{
118 118
 };
119 119
 
120 120
 
121
+struct socket_id{
122
+	char* name;
123
+	int proto;
124
+	int port;
125
+	struct socket_id* next;
126
+};
127
+
128
+
121 129
 
122 130
 /* len of the sockaddr */
123 131
 #ifdef HAVE_SOCKADDR_SA_LEN
... ...
@@ -1431,7 +1431,7 @@ try_again:
1431 1431
 	}
1432 1432
 	/* fix routing lists */
1433 1433
 	if ( (r=fix_rls())!=0){
1434
-		fprintf(stderr, "ERROR: error %x while trying to fix configuration\n",
1434
+		fprintf(stderr, "ERROR: error %d while trying to fix configuration\n",
1435 1435
 						r);
1436 1436
 		goto error;
1437 1437
 	};
... ...
@@ -61,6 +61,7 @@
61 61
 #include "sr_module.h"
62 62
 #include "ip_addr.h"
63 63
 #include "resolve.h"
64
+#include "socket_info.h"
64 65
 #include "parser/parse_uri.h"
65 66
 #include "parser/parse_from.h"
66 67
 #include "parser/parse_to.h"
... ...
@@ -154,6 +155,9 @@ static int fix_actions(struct action* a)
154 154
 	cmd_export_t* cmd;
155 155
 	struct sr_module* mod;
156 156
 	str s;
157
+	struct hostent* he;
158
+	struct ip_addr ip;
159
+	struct socket_info* si;
157 160
 	
158 161
 	if (a==0){
159 162
 		LOG(L_CRIT,"BUG: fix_actions: null pointer\n");
... ...
@@ -242,7 +246,29 @@ static int fix_actions(struct action* a)
242 242
 						}
243 243
 					}
244 244
 				}
245
-			
245
+				break;
246
+			case FORCE_SEND_SOCKET_T:
247
+				if (t->p1_type!=SOCKID_ST){
248
+					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
249
+								"%d for force_send_socket\n",
250
+								t->p1_type);
251
+					return E_BUG;
252
+				}
253
+				he=resolvehost(((struct socket_id*)t->p1.data)->name);
254
+				if (he==0) return E_BAD_ADDRESS;
255
+				hostent2ip_addr(&ip, he, 0);
256
+				si=find_si(&ip, ((struct socket_id*)t->p1.data)->port,
257
+								((struct socket_id*)t->p1.data)->proto);
258
+				if (si==0){
259
+					LOG(L_ERR, "ERROR: fix_actions: bad force_send_socket"
260
+							" argument: %s:%d (ser doesn't listen on it)\n",
261
+							((struct socket_id*)t->p1.data)->name,
262
+							((struct socket_id*)t->p1.data)->port);
263
+					return E_BAD_ADDRESS;
264
+				}
265
+				t->p1.data=si;
266
+				t->p1_type=SOCKETINFO_ST;
267
+				break;
246 268
 		}
247 269
 	}
248 270
 	return 0;
... ...
@@ -340,6 +340,9 @@ void print_action(struct action* a)
340 340
 			case AVP_TO_URI_T:
341 341
 					DBG("avp_to_attr");
342 342
 					break;
343
+			case FORCE_SEND_SOCKET_T:
344
+					DBG("force_send_socket");
345
+					break;
343 346
 			default:
344 347
 					DBG("UNKNOWN(");
345 348
 		}
... ...
@@ -362,6 +365,13 @@ void print_action(struct action* a)
362 362
 			case CMDF_ST:
363 363
 					DBG("f_ptr<%p>",t->p1.data);
364 364
 					break;
365
+			case SOCKID_ST:
366
+					DBG("%d:%s:%d",
367
+							((struct socket_id*)t->p1.data)->proto,
368
+							((struct socket_id*)t->p1.data)->name,
369
+							((struct socket_id*)t->p1.data)->port
370
+							);
371
+					break;
365 372
 			default:
366 373
 					DBG("type<%d>", t->p1_type);
367 374
 		}
... ...
@@ -381,6 +391,13 @@ void print_action(struct action* a)
381 381
 			case ACTIONS_ST:
382 382
 					print_action((struct action*)t->p2.data);
383 383
 					break;
384
+			case SOCKID_ST:
385
+					DBG("%d:%s:%d",
386
+							((struct socket_id*)t->p1.data)->proto,
387
+							((struct socket_id*)t->p1.data)->name,
388
+							((struct socket_id*)t->p1.data)->port
389
+							);
390
+					break;
384 391
 			default:
385 392
 					DBG(", type<%d>", t->p2_type);
386 393
 		}
... ...
@@ -400,6 +417,13 @@ void print_action(struct action* a)
400 400
 			case ACTIONS_ST:
401 401
 					print_action((struct action*)t->p3.data);
402 402
 					break;
403
+			case SOCKID_ST:
404
+					DBG("%d:%s:%d",
405
+							((struct socket_id*)t->p1.data)->proto,
406
+							((struct socket_id*)t->p1.data)->name,
407
+							((struct socket_id*)t->p1.data)->port
408
+							);
409
+					break;
403 410
 			default:
404 411
 					DBG(", type<%d>", t->p3_type);
405 412
 		}
... ...
@@ -75,11 +75,12 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
75 75
 		SET_ADV_PORT_T,
76 76
 		FORCE_TCP_ALIAS_T,
77 77
 		LOAD_AVP_T,
78
-		AVP_TO_URI_T
78
+		AVP_TO_URI_T,
79
+		FORCE_SEND_SOCKET_T
79 80
 };
80 81
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
81 82
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
82
-		MYSELF_ST, STR_ST };
83
+		MYSELF_ST, STR_ST, SOCKID_ST, SOCKETINFO_ST };
83 84
 
84 85
 	
85 86
 struct expr{
... ...
@@ -361,6 +361,13 @@ int add_listen_iface(char* name, unsigned short port, unsigned short proto,
361 361
 			LOG(L_ERR, "ERROR: add_listen_iface: get_sock_info_list failed\n");
362 362
 			goto error;
363 363
 		}
364
+		if (port==0){ /* use default port */
365
+			port=
366
+#ifdef USE_TLS
367
+				((c_proto)==PROTO_TLS)?tls_port_no:
368
+#endif
369
+				port_no;
370
+		}
364 371
 		if (new_sock2list(name, port, c_proto, flags, list)<0){
365 372
 			LOG(L_ERR, "ERROR: add_listen_iface: new_sock2list failed\n");
366 373
 			goto error;