Browse code

- @next_hop.src_ip: source ip of outgoing message

Tomas Mandys authored on 02/06/2009 20:46:05
Showing 2 changed files
... ...
@@ -61,6 +61,8 @@
61 61
 #include "parser/parse_body.h"
62 62
 #include "dset.h"
63 63
 #include "sr_module.h"
64
+#include "resolve.h"
65
+#include "forward.h"
64 66
 
65 67
 #define RETURN0_res(x) {*res=(x);return 0;}
66 68
 #define TRIM_RET0_res(x) {*res=(x);trim(res);return 0;} 
... ...
@@ -103,6 +105,55 @@ int select_next_hop(str* res, select_t* s, struct sip_msg* msg)
103 105
 	return -1;
104 106
 }
105 107
 
108
+int select_next_hop_src_ip(str* res, select_t* s, struct sip_msg* msg) {
109
+	struct socket_info* socket_info;
110
+	union sockaddr_union to;
111
+	char proto;
112
+	struct sip_uri *u, next_hop;
113
+	str *dst_host;
114
+
115
+	if (msg->first_line.type!=SIP_REQUEST) 
116
+		return -1;
117
+
118
+	if (msg->force_send_socket) {
119
+		*res = msg->force_send_socket->address_str;
120
+		return 0;
121
+	}
122
+
123
+	if (msg->dst_uri.len) {
124
+		if (parse_uri(msg->dst_uri.s, msg->dst_uri.len, &next_hop) < 0)
125
+			return -1;
126
+		u = &next_hop;
127
+	}
128
+	else {
129
+		if (parse_sip_msg_uri(msg) < 0)
130
+			return -1;
131
+		u = &msg->parsed_uri;
132
+	}
133
+#ifdef USE_TLS
134
+	if (u->type==SIPS_URI_T)
135
+		proto = PROTO_TLS;
136
+	else
137
+#endif
138
+		proto = u->proto;
139
+
140
+#ifdef HONOR_MADDR
141
+	if (u->maddr_val.s && u->maddr_val.len)
142
+		dst_host = &u->maddr_val;
143
+	else
144
+#endif
145
+		dst_host = &u->host;
146
+
147
+	if (sip_hostport2su(&to, dst_host, u->port_no, &proto) < 0)
148
+		return -1;
149
+	socket_info = get_send_socket(msg, &to, proto);
150
+	if (!socket_info)
151
+		return -1;
152
+
153
+	*res = socket_info->address_str;
154
+	return 0;
155
+}
156
+
106 157
 #define SELECT_uri_header(_name_) \
107 158
 int select_##_name_(str* res, select_t* s, struct sip_msg* msg) \
108 159
 { \
... ...
@@ -86,6 +86,7 @@ enum {
86 86
 SELECT_F(select_ruri)
87 87
 SELECT_F(select_dst_uri)
88 88
 SELECT_F(select_next_hop)
89
+SELECT_F(select_next_hop_src_ip)
89 90
 SELECT_F(select_from)
90 91
 SELECT_F(select_from_uri)
91 92
 SELECT_F(select_from_tag)
... ...
@@ -221,6 +222,7 @@ static select_row_t select_core[] = {
221 222
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("dst_uri"), select_dst_uri, 0},
222 223
 	{ select_dst_uri, SEL_PARAM_STR, STR_NULL, select_any_uri, NESTED},
223 224
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("next_hop"), select_next_hop, 0},
225
+	{ select_next_hop, SEL_PARAM_STR, STR_STATIC_INIT("src_ip"), select_next_hop_src_ip, 0},
224 226
 	{ select_next_hop, SEL_PARAM_STR, STR_NULL, select_any_uri, NESTED},
225 227
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("from"), select_from, 0},
226 228
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("f"), select_from, 0},