Discussion:
[OpenSIPS-Users] remove_hf() doesn't always work
Jeff Pyle
2009-03-07 03:40:14 UTC
Permalink
Hello,

I¹m using serial forking to send requests to multiple PSTN carriers. Some
of these carriers want P-Asserted-Identity/Privacy, and others want
Remote-Party-ID. After selecting a carrier I remove any of these headers so
I can build new ones and insert them.

The insert works fine, but the remove_hf() isn¹t removing the headers.
Here¹s the config:

# Clear identity / privacy headers
if (is_present_hf("Remote-Party-ID")) {
remove_hf("Remote-Party-ID");
xlog("L_INFO", "Removed Remote-Party-ID header\n");
}
if (is_present_hf("P-Asserted-Identity")) {
remove_hf("P-Asserted-Identity");
xlog("L_INFO", "Removed P-Asserted-Identity header\n");
}
if (is_present_hf("Privacy")) {
remove_hf("Privacy");
xlog("L_INFO", "Removed Privacy header\n");
}

Requests come into the proxy with either PAI/Privacy or RPID. After parsing
them I remove them with the above code. It seems some odd things are going
on.

Take the following example: A request comes into the proxy with RPID. RPID
is detected and removed. The first carrier requires PAI, so it is built and
inserted. The request is related to the first carrier where it arrives with
only PAI. So far, so good.

The carrier sends a 503 into a failure_route. The above config is also in
the failure_route, where it oddly detects an RPID. The 503 didn't have an
RPID, nor did the INVITE before it. Anyway, the route block is called to
prepare the next carrier. The above config is called again in that route
block. It also shows that it detected and removed and RPID header, even
though as far as I can tell none was present. This second carrier prefers
RPID, so a new RPID header is constructed and inserted. The request is
forwarded to the carrier. When the carrier gets it, it has both an RPID and
a PAI header.

It doesn't matter what the UAC sends initially to this proxy, RPID or PAI,
or which order the carriers receive the INVITEs. The second carrier always
has both headers, and the xlogs from the above code don't seem to make
sense.

I'm at a loss on this one. Especially since I use remove_hf() to take out
P-Charge-Info and some other custom headers after they're parsed at the
beginning of the route[0]. And that works fine.


Thanks in advance for any insight anyone may have.

- Jeff
Richard Revels
2009-03-07 16:25:27 UTC
Permalink
Add the headers in branch routes. Headers added in primary routing
can't be removed in later processing.
Post by Jeff Pyle
Hello,
I’m using serial forking to send requests to multiple PSTN
carriers. Some
of these carriers want P-Asserted-Identity/Privacy, and others want
Remote-Party-ID. After selecting a carrier I remove any of these headers so
I can build new ones and insert them.
The insert works fine, but the remove_hf() isn’t removing the headers.
# Clear identity / privacy headers
if (is_present_hf("Remote-Party-ID")) {
remove_hf("Remote-Party-ID");
xlog("L_INFO", "Removed Remote-Party-ID header\n");
}
if (is_present_hf("P-Asserted-Identity")) {
remove_hf("P-Asserted-Identity");
xlog("L_INFO", "Removed P-Asserted-Identity header\n");
}
if (is_present_hf("Privacy")) {
remove_hf("Privacy");
xlog("L_INFO", "Removed Privacy header\n");
}
Requests come into the proxy with either PAI/Privacy or RPID. After parsing
them I remove them with the above code. It seems some odd things are going
on.
Take the following example: A request comes into the proxy with RPID. RPID
is detected and removed. The first carrier requires PAI, so it is built and
inserted. The request is related to the first carrier where it arrives with
only PAI. So far, so good.
The carrier sends a 503 into a failure_route. The above config is also in
the failure_route, where it oddly detects an RPID. The 503 didn't have an
RPID, nor did the INVITE before it. Anyway, the route block is called to
prepare the next carrier. The above config is called again in that route
block. It also shows that it detected and removed and RPID header, even
though as far as I can tell none was present. This second carrier prefers
RPID, so a new RPID header is constructed and inserted. The request is
forwarded to the carrier. When the carrier gets it, it has both an RPID and
a PAI header.
It doesn't matter what the UAC sends initially to this proxy, RPID or PAI,
or which order the carriers receive the INVITEs. The second carrier always
has both headers, and the xlogs from the above code don't seem to make
sense.
I'm at a loss on this one. Especially since I use remove_hf() to take out
P-Charge-Info and some other custom headers after they're parsed at the
beginning of the route[0]. And that works fine.
Thanks in advance for any insight anyone may have.
- Jeff
_______________________________________________
Users mailing list
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Jeff Pyle
2009-03-07 20:33:27 UTC
Permalink
Richard,

Branch routing is something I've never been able to completely wrap my mind
around. I'm not using any branch routing in my current configuration, at
least to the best of my knowledge. I'll read up on the different types of
routes to see if I can figure this one out. Do you have any quick
suggestions on how to adapt a branch-less config into something where I can
add and delete the headers I need to?


Thanks,
Jeff
Post by Richard Revels
Add the headers in branch routes. Headers added in primary routing
can't be removed in later processing.
Bogdan-Andrei Iancu
2009-03-09 15:00:27 UTC
Permalink
Hi Jeff,

There is no way around the branch_route[] because you wan to perform
per-branch changes - to have different RPID/PAI for each branch.

As Richard said, whatever changes you do in request route (route[0]),
they will be visible in all later branches, so you should not add an
RPID/PAI there.

the logic should be something like:

route[0] {
....
remove_all_pai_hdrs;
remove_all_rpid_hdrs;
.....
set_first_destination;
prepare_new_identity_for_first_destination(rpid or pai);
.....
t_on_branch[1];
t_relay();
}

t_on_branch[1] {
append_hf("rpid/pai with the identity\n")
}

t_on_failure {
choose_next_destination;
prepare_new_identity_for_nexr_destination(rpid or pai);
....
t_on_branch[1];
t_relay();
}


you can pass the identity to branch route via an AVP for example.


Regards,
Bogdan
Post by Jeff Pyle
Richard,
Branch routing is something I've never been able to completely wrap my mind
around. I'm not using any branch routing in my current configuration, at
least to the best of my knowledge. I'll read up on the different types of
routes to see if I can figure this one out. Do you have any quick
suggestions on how to adapt a branch-less config into something where I can
add and delete the headers I need to?
Thanks,
Jeff
Post by Richard Revels
Add the headers in branch routes. Headers added in primary routing
can't be removed in later processing.
_______________________________________________
Users mailing list
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Richard Revels
2009-03-11 02:08:49 UTC
Permalink
The branch routes in the config files are simply blocks of code that
get hit as the message leaves the door. In your config instead of
inserting the header in one of your routes use t_on_branch("1"). Then
in the branch route look at the request domain and insert your header
as needed. The t_on_branch arms which branch gets hit so you can set
one branch for a call going out initially and another for calls that
go out from failure routes. Or not. Whatever works best. I'm
putting a sample below that assumes you have built the avp named cpid
and removed any headers from the initial invite that you desire. You
might have to play with this a little. For instance I can't remember
if the module parameter is needed to insure the avp is available in
the branch route after a failure response or not. They can get a
little more involved if you do parallel forking but that doesn't seem
to be the case here.

#this might be needed
modparam("tm", "onreply_avp_mode", 1)

....

branch_route[1]
{
if( is_gflag("0") )
xlog("L_INFO", "In branch route 1 - request domain is $rd \n");
switch($rd)
{
case "1.2.3.4": #carrier-1
case "5.6.7.8": #carrier-1
insert_hf("P-Charge-Info: $avp(s:cpid)\r\n", "CALL-ID");
return;
break;
case "2.3.4.5": #carrier2
case "6.7.8.9": #carrier2
append_hf("P-Asserted-Identity: <$avp(s:cpid)>\r\n");
return;
break;
default:
#dont bother with headers
}
return;
}
Post by Jeff Pyle
Richard,
Branch routing is something I've never been able to completely wrap my mind
around. I'm not using any branch routing in my current
configuration, at
least to the best of my knowledge. I'll read up on the different types of
routes to see if I can figure this one out. Do you have any quick
suggestions on how to adapt a branch-less config into something where I can
add and delete the headers I need to?
Thanks,
Jeff
Post by Richard Revels
Add the headers in branch routes. Headers added in primary routing
can't be removed in later processing.
Loading...