Skip to content

Commit

Permalink
outbound: pass recv info struct by address
Browse files Browse the repository at this point in the history
- fix performance inefficiency for passing large structs by value

(cherry picked from commit 56ea88e)
(cherry picked from commit 40e3773)
  • Loading branch information
miconda committed Jul 16, 2020
1 parent ea10a5f commit 8eb99e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/modules/outbound/api.h
Expand Up @@ -30,7 +30,7 @@
#include "../../core/str.h"
#include "../../core/sr_module.h"

typedef int (*encode_flow_token_t)(str *, struct receive_info);
typedef int (*encode_flow_token_t)(str *, struct receive_info *);
typedef int (*decode_flow_token_t)(struct sip_msg *, struct receive_info **, str);
typedef int (*use_outbound_t)(struct sip_msg *);

Expand Down
20 changes: 10 additions & 10 deletions src/modules/outbound/outbound_mod.c
Expand Up @@ -156,7 +156,7 @@ static void destroy(void)
static unsigned char unenc_flow_token[UNENC_FLOW_TOKEN_MAX_LENGTH];
static unsigned char hmac_sha1[EVP_MAX_MD_SIZE];

int encode_flow_token(str *flow_token, struct receive_info rcv)
int encode_flow_token(str *flow_token, struct receive_info *rcv)
{
int pos = FLOW_TOKEN_START_POS, i;

Expand All @@ -168,19 +168,19 @@ int encode_flow_token(str *flow_token, struct receive_info rcv)

/* Encode protocol information */
unenc_flow_token[pos++] =
(rcv.dst_ip.af == AF_INET6 ? 0x80 : 0x00) | rcv.proto;
(rcv->dst_ip.af == AF_INET6 ? 0x80 : 0x00) | rcv->proto;

/* Encode destination address */
for (i = 0; i < (rcv.dst_ip.af == AF_INET6 ? 16 : 4); i++)
unenc_flow_token[pos++] = rcv.dst_ip.u.addr[i];
unenc_flow_token[pos++] = (rcv.dst_port >> 8) & 0xff;
unenc_flow_token[pos++] = rcv.dst_port & 0xff;
for (i = 0; i < (rcv->dst_ip.af == AF_INET6 ? 16 : 4); i++)
unenc_flow_token[pos++] = rcv->dst_ip.u.addr[i];
unenc_flow_token[pos++] = (rcv->dst_port >> 8) & 0xff;
unenc_flow_token[pos++] = rcv->dst_port & 0xff;

/* Encode source address */
for (i = 0; i < (rcv.src_ip.af == AF_INET6 ? 16 : 4); i++)
unenc_flow_token[pos++] = rcv.src_ip.u.addr[i];
unenc_flow_token[pos++] = (rcv.src_port >> 8) & 0xff;
unenc_flow_token[pos++] = rcv.src_port & 0xff;
for (i = 0; i < (rcv->src_ip.af == AF_INET6 ? 16 : 4); i++)
unenc_flow_token[pos++] = rcv->src_ip.u.addr[i];
unenc_flow_token[pos++] = (rcv->src_port >> 8) & 0xff;
unenc_flow_token[pos++] = rcv->src_port & 0xff;

/* HMAC-SHA1 the calculated flow-token, truncate to 80 bits, and
prepend onto the flow-token */
Expand Down

0 comments on commit 8eb99e9

Please sign in to comment.