Module: sip-router
Branch: master
Commit: 949e1f3c3e1f1afa02c696403399a093905c3f0a
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=949e1f3…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Sep 19 15:45:43 2013 +0200
parser: refactored a bit sip_msg_t struct for extra fields needed per process
- a new structure to keep cached decoded flow for outbound, previously
was declared inline
- easier to reset it for shm clone and tm faked environment
- new fields that are needed inside the sip_msg_t but not cloned in shm,
must be added in the msg_ldata_t structure, accessible via ldv field
---
parser/msg_parser.c | 11 +++++++++++
parser/msg_parser.h | 25 +++++++++++++++++++++----
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index 02ad583..1631401 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -734,6 +734,7 @@ void free_sip_msg(struct sip_msg* const msg)
if (msg->add_rm) free_lump_list(msg->add_rm);
if (msg->body_lumps) free_lump_list(msg->body_lumps);
if (msg->reply_lump) free_reply_lump(msg->reply_lump);
+ msg_ldata_reset(msg);
/* don't free anymore -- now a pointer to a static buffer */
# ifdef DYN_BUF
pkg_free(msg->buf);
@@ -952,6 +953,16 @@ void reset_ua(struct sip_msg* const msg)
msg->location_ua.len = 0;
}
+/**
+ * reset content of msg->ldv (msg_ldata_t structure)
+ */
+void msg_ldata_reset(sip_msg_t *msg)
+{
+ if(msg==NULL)
+ return;
+ memset(&msg->ldv, 0, sizeof(msg_ldata_t));
+}
+
hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
{
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index 08b76ed..d6df9b3 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -253,6 +253,19 @@ typedef struct msg_body {
/* pre-declaration, to include sys/time.h in .c */
struct timeval;
+/* structure for cached decoded flow for outbound */
+typedef struct ocd_flow {
+ int decoded;
+ struct receive_info rcv;
+} ocd_flow_t;
+
+/* structure holding fields that don't have to be cloned in shm
+ * - its content is memset'ed to in shm clone
+ * - add to msg_ldata_reset() if a field uses dynamic memory */
+typedef struct msg_ldata {
+ ocd_flow_t flow;
+} msg_ldata_t;
+
/*! \brief The SIP message */
typedef struct sip_msg {
unsigned int id; /*!< message id, unique/process*/
@@ -363,10 +376,9 @@ typedef struct sip_msg {
str ruid;
str location_ua;
- struct {
- int decoded;
- struct receive_info rcv;
- } flow;
+ /* structure with fields that are needed for local processing
+ * - not cloned to shm, reset to 0 in the clone */
+ msg_ldata_t ldv;
/* IMPORTANT: when adding new fields in this structure (sip_msg_t),
* be sure it is freed in free_sip_msg() and it is cloned or reset
@@ -514,4 +526,9 @@ int msg_ctx_id_match(const sip_msg_t* const msg, const msg_ctx_id_t* const mid);
*/
int msg_set_time(sip_msg_t* const msg);
+/**
+ * reset content of msg->ldv (msg_ldata_t structure)
+ */
+void msg_ldata_reset(sip_msg_t*);
+
#endif
Module: sip-router
Branch: master
Commit: 10cc1dd7a3f4481c677022e7ff0da87f004077f0
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=10cc1dd…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Sep 19 15:12:29 2013 +0200
parser: added note about new fields in sip_msg_t
---
parser/msg_parser.h | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index 5d481e0..08b76ed 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -367,6 +367,12 @@ typedef struct sip_msg {
int decoded;
struct receive_info rcv;
} flow;
+
+ /* IMPORTANT: when adding new fields in this structure (sip_msg_t),
+ * be sure it is freed in free_sip_msg() and it is cloned or reset
+ * to shm structure for transaction - see sip_msg_clone.c. In tm
+ * module, take care of these fields for faked environemt used for
+ * runing failure handlers - see modules/tm/t_reply.c */
} sip_msg_t;
/*! \brief pointer to a fakes message which was never received ;
THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.
Víctor Seva has taken ownership of the following task:
FS#346 - avpops: use xavp semantic on second parameter
More information can be found at the following URL:
https://sip-router.org/tracker/index.php?do=details&task_id=346
You are receiving this message because you have requested it from the Flyspray bugtracking system. If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.
Hello,
some (not so) recently fields added to sip_msg_t structure were not
handled properly. These are instance (added by Juha), ruid, location_ua
(added by Crocodile patches), so I explicitely put to repicients the
people working with them to check my changes I did for fixing some
related issues.
The issues:
1) sip_msg_t is cloned in shm for transaction. So each new field added
to this structure has to be handled in the function that clones to shm,
otherwise their values will stay referencing to pkg. Then, same fields
have to be handled in tm when running sip failure handlers -- there a
faked environment and sip msg structure are created from shm back to pkg.
2) if the new fields allocate memory, the free sip msg function has to
clean that, otherwise will be a memory leak
The reason writing here is that for 1) I didn't clone the values in shm,
just reset the pointers to NULL (same is done for path vector). But if
you need these values to be in transaction, then you have to clone them.
What I did fixes a crash when trying to use lookup() in failure route --
because these fields are set, when the new values have a lower lenght,
it will just write in buffer, which is invalid as either the pkg pointer
was freed or the failure route is executed in another process (resulting
in writing at inappropriate addresses in current process). My assumption
was that no one used these fields from transaction, because would have
reported a crash as well, thus I didn't clone and set them to NULL.
Cheers,
Daniel
--
Daniel-Constantin Mierla - http://www.asipto.comhttp://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Trainings - Berlin, Oct 21-24; Miami, Nov 11-13, 2013
- more details about Kamailio trainings at http://www.asipto.com -