Browse code

modules/outbound: cache decoded flow-token in sip_msg structure

- Saves multiple OpenSSL calls if the same flow-token is needed in more
than one place

Peter Dunkley authored on 29/03/2013 23:11:24
Showing 2 changed files
... ...
@@ -28,7 +28,7 @@
28 28
 #include "../../sr_module.h"
29 29
 
30 30
 typedef int (*encode_flow_token_t)(str *, struct receive_info);
31
-typedef int (*decode_flow_token_t)(struct receive_info *, str);
31
+typedef int (*decode_flow_token_t)(struct sip_msg *, struct receive_info *, str);
32 32
 typedef int (*use_outbound_t)(struct sip_msg *);
33 33
 
34 34
 typedef struct ob_binds {
... ...
@@ -185,15 +185,12 @@ int encode_flow_token(str *flow_token, struct receive_info rcv)
185 185
 	return 0;
186 186
 }
187 187
 
188
-int decode_flow_token(struct receive_info *rcv, str flow_token)
188
+int decode_flow_token(struct sip_msg *msg, struct receive_info *rcv, str flow_token)
189 189
 {
190 190
 	int pos = FLOW_TOKEN_START_POS, flow_length, i;
191 191
 
192
-	if (rcv == NULL)
193
-	{
194
-		LM_ERR("bad receive_info structure provided\n");
195
-		return -1;
196
-	}
192
+	if (msg->flow.decoded)
193
+		goto end;
197 194
 
198 195
 	if (flow_token.s == NULL)
199 196
 	{
... ...
@@ -241,28 +238,31 @@ int decode_flow_token(struct receive_info *rcv, str flow_token)
241 241
 	/* Decode protocol information */
242 242
 	if (unenc_flow_token[pos] & 0x80)
243 243
 	{
244
-		rcv->dst_ip.af = rcv->src_ip.af = AF_INET6;
245
-		rcv->dst_ip.len = rcv->src_ip.len = 16;
244
+		msg->flow.rcv.dst_ip.af = msg->flow.rcv.src_ip.af = AF_INET6;
245
+		msg->flow.rcv.dst_ip.len = msg->flow.rcv.src_ip.len = 16;
246 246
 	}
247 247
 	else
248 248
 	{
249
-		rcv->dst_ip.af = rcv->src_ip.af = AF_INET;
250
-		rcv->dst_ip.len = rcv->src_ip.len = 4;
249
+		msg->flow.rcv.dst_ip.af = msg->flow.rcv.src_ip.af = AF_INET;
250
+		msg->flow.rcv.dst_ip.len = msg->flow.rcv.src_ip.len = 4;
251 251
 	}
252
-	rcv->proto = unenc_flow_token[pos++] & 0x7f;
252
+	msg->flow.rcv.proto = unenc_flow_token[pos++] & 0x7f;
253 253
 
254 254
 	/* Decode destination address */
255
-	for (i = 0; i < (rcv->dst_ip.af == AF_INET6 ? 16 : 4); i++)
256
-		rcv->dst_ip.u.addr[i] = unenc_flow_token[pos++];
257
-	rcv->dst_port = unenc_flow_token[pos++] << 8;
258
-	rcv->dst_port |= unenc_flow_token[pos++];
255
+	for (i = 0; i < (msg->flow.rcv.dst_ip.af == AF_INET6 ? 16 : 4); i++)
256
+		msg->flow.rcv.dst_ip.u.addr[i] = unenc_flow_token[pos++];
257
+	msg->flow.rcv.dst_port = unenc_flow_token[pos++] << 8;
258
+	msg->flow.rcv.dst_port |= unenc_flow_token[pos++];
259 259
 
260 260
 	/* Decode source address */
261
-	for (i = 0; i < (rcv->src_ip.af == AF_INET6 ? 16 : 4); i++)
262
-		rcv->src_ip.u.addr[i] = unenc_flow_token[pos++];
263
-	rcv->src_port = unenc_flow_token[pos++] << 8;
264
-	rcv->src_port |= unenc_flow_token[pos++];
265
-
261
+	for (i = 0; i < (msg->flow.rcv.src_ip.af == AF_INET6 ? 16 : 4); i++)
262
+		msg->flow.rcv.src_ip.u.addr[i] = unenc_flow_token[pos++];
263
+	msg->flow.rcv.src_port = unenc_flow_token[pos++] << 8;
264
+	msg->flow.rcv.src_port |= unenc_flow_token[pos++];
265
+	msg->flow.decoded = 1;
266
+
267
+end:
268
+	rcv = &msg->flow.rcv;
266 269
 	return 0;
267 270
 }
268 271
 
... ...
@@ -315,7 +315,7 @@ static int use_outbound_non_reg(struct sip_msg *msg)
315 315
 	param_hooks_t hooks;
316 316
 	param_t *params;
317 317
 	int ret;
318
-	struct receive_info rcv;
318
+	struct receive_info *rcv = NULL;
319 319
 
320 320
 	/* Check to see if the top Route-URI is me and has a ;ob parameter */
321 321
 	if (msg->route
... ...
@@ -361,10 +361,10 @@ static int use_outbound_non_reg(struct sip_msg *msg)
361 361
 			LM_INFO("found ;ob parameter on Route-URI - outbound"
362 362
 				" used\n");
363 363
 
364
-			if (decode_flow_token(&rcv, puri.user) == 0)
364
+			if (decode_flow_token(msg, rcv, puri.user) == 0)
365 365
 			{
366
-				if (!ip_addr_cmp(&rcv.src_ip, &msg->rcv.src_ip)
367
-					|| rcv.src_port != msg->rcv.src_port)
366
+				if (!ip_addr_cmp(&rcv->src_ip, &msg->rcv.src_ip)
367
+					|| rcv->src_port != msg->rcv.src_port)
368 368
 				{
369 369
 					LM_INFO("\"incoming\" request found\n");
370 370
 					return 2;