Module: sip-router Branch: andrei/send_flags Commit: 67c9277aaa07fb6b8c91fc38e761d30426ded8b5 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=67c9277a...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Tue Sep 15 17:38:06 2009 +0200
core: send flags support
Added support for send flags and per message send flags. Right now there are 2 flags defined: - SND_F_FORCE_CON_REUSE (forces connection reuse, send will fail if a connection does not already exist to the destination) - SND_F_CON_CLOSE (hint that after the send completes the connection should be closed). The send flags can be passed directly to msg_send() via dest_info.send_flags or they can be set for each sip_msg, in which case forward_request() and forward_reply() will obey them. The sip_msg flags can be set for replies or for forwarding.
---
forward.c | 15 ++++++++++----- ip_addr.h | 9 +++++++++ parser/msg_parser.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/forward.c b/forward.c index dea7584..d7fb827 100644 --- a/forward.c +++ b/forward.c @@ -384,9 +384,12 @@ int check_self_port(unsigned short port, unsigned short proto) * default port or non srv. lookup is desired, the port must * be !=0 * port - used only if dst!=0 (else the port in send_info->to is used) - * send_info - filled dest_info structure: - * if the send_socket member is null, a send_socket will be - * chosen automatically + * send_info - value/result partially filled dest_info structure: + * - send_info->proto and comp are used + * - send_info->to will be filled (dns) + * - send_info->send_flags is filled from the message + * - if the send_socket member is null, a send_socket will be + * chosen automatically * WARNING: don't forget to zero-fill all the unused members (a non-zero * random id along with proto==PROTO_TCP can have bad consequences, same for * a bogus send_socket value) @@ -438,13 +441,14 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port, goto error; } }/* dst */ + send_info->send_flags=msg->fwd_send_flags; /* calculate branch for outbound request; if syn_branch is turned off, calculate is from transaction key, i.e., as an md5 of From/To/CallID/ CSeq exactly the same way as TM does; good for reboot -- than messages belonging to transaction lost due to reboot will still be forwarded with the same branch parameter and will be match-able downstream - - if it is turned on, we don't care about reboot; we simply put a simple + + if it is turned on, we don't care about reboot; we simply put a simple value in there; better for performance */ if (syn_branch ) { @@ -694,6 +698,7 @@ int forward_reply(struct sip_msg* msg) }
dst.proto=msg->via2->proto; + dst.send_flags=msg->fwd_send_flags | msg->rpl_send_flags; if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error; #ifdef USE_COMP dst.comp=msg->via2->comp_no; diff --git a/ip_addr.h b/ip_addr.h index 50bcbe4..355fc77 100644 --- a/ip_addr.h +++ b/ip_addr.h @@ -34,6 +34,7 @@ * 2006-04-21 added init_dst_from_rcv (andrei) * 2007-06-26 added ip_addr_mk_any() (andrei) * 2008-05-21 added su2a(), ip_addr2sbuf(), ip4tosbuf(), ip62sbuf() (andrei) + * 2009-09-14 added send flags support to dest_info (andrei) */
#ifndef ip_addr_h @@ -136,11 +137,18 @@ struct receive_info{ };
+/* send flags */ +#define SND_F_FORCE_CON_REUSE 1 /* reuse an existing connection or fail */ +#define SND_F_CON_CLOSE 2 /* close the connection after sending */ + +typedef unsigned char snd_flags_t; + struct dest_info{ struct socket_info* send_sock; union sockaddr_union to; int id; /* tcp stores the connection id here */ char proto; + snd_flags_t send_flags; #ifdef USE_COMP short comp; #endif @@ -748,6 +756,7 @@ inline static void init_dst_from_rcv(struct dest_info* dst, dst->to=rcv->src_su; dst->id=rcv->proto_reserved1; dst->proto=rcv->proto; + dst->send_flags=0; #ifdef USE_COMP dst->comp=rcv->comp; #endif diff --git a/parser/msg_parser.h b/parser/msg_parser.h index 1ce00bb..22b3167 100644 --- a/parser/msg_parser.h +++ b/parser/msg_parser.h @@ -246,6 +246,8 @@ typedef struct msg_body {
typedef struct sip_msg { unsigned int id; /* message id, unique/process*/ + snd_flags_t fwd_send_flags; /* send flags for forwarding */ + snd_flags_t rpl_send_flags; /* send flags for replies */ struct msg_start first_line; /* Message first line */ struct via_body* via1; /* The first via */ struct via_body* via2; /* The second via */