[OpenSIPS-Devel] [ opensips-Patches-3606324 ] Add {s.encode.int} transformation

SourceForge.net noreply at sourceforge.net
Mon Apr 8 20:14:54 CEST 2013


Patches item #3606324, was opened at 2013-02-27 23:57
Message generated for change (Comment added) made by umautone
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086412&aid=3606324&group_id=232389

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: core
Group: 1.9.x
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Umberto Mautone (umautone)
Assigned to: Vladut-Stefan Paiu (vladut-paiu)
Summary: Add {s.encode.int} transformation

Initial Comment:
This patch adds the {s.encode.int} transformation to convert a 4-byte or 8-byte binary data into an unsigned integer. An example of this feature's use would be to convert IP addresses directly to unsigned integers to be used as dynamic group ID values by the load balancer or dispatcher. The patch utilizes "ntohl()" on the converted value to correctly manage endian.

$var(ip) = $(Ri{ip.pton}{s.encode.int});

The patch applies to 1.9.0-tls

----------------------------------------------------------------------

>Comment By: Umberto Mautone (umautone)
Date: 2013-04-08 11:14

Message:
Yeah, I just noticed I had said 4-byte or 8-byte. My head was somewhere
else that day. Is there a PV_VAL_* entity to handle unsigned integers? I've
got to think about the 16 byte conversion. 

The idea behind this patch is to reference the "group_id" field in the load
balancer table according to the receiving IP when a proxy is set up to
listen on multiple IPs without hard coding the actual IPs in the script.
For example:

$var(ip) = $(Ri{ip.pton}{s.encode.int});
...
if( !load_balance("$(var(ip){s.int})","pstn", "1") ) {
..

This would reference the appropriate group of endpoints in the load
balancer table that belong to the proxy's receiving IP.

----------------------------------------------------------------------

Comment By: Vladut-Stefan Paiu (vladut-paiu)
Date: 2013-04-08 10:08

Message:
Hello,

First of all, not sure I understand why you are treating either 4-byte or
8-byte binary data ? If the purpose is to use the output of ip.pton, then
that returns either 4 or 16 bytes, depending on the IP type ( v4 vs v6 ).
Am I missing something here ?

Also, is the purpose of the function to return the value as an integer (
because I see the PV_VAL_INT being set ) ? If so, it will be a little bit
funky, since for IPV4, you might end up with overflows due to the fact that
the IPv4 address is 32 bits, while the pvar structures in the OpenSIPS code
use integers, thus only 31 bits for the actual number ( 1 bit for the sign
).
The situation for IPv6 would be even worse then.

Probably we'd need to re-work this patch, or change the approach entirely
for this to work for IPv4 and IPv6 as well.

Best Regards,
Vlad

----------------------------------------------------------------------

Comment By: Umberto Mautone (umautone)
Date: 2013-04-07 04:03

Message:
Just following up on this patch to see if there are any objections to its
inclusion.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086412&aid=3606324&group_id=232389



More information about the Devel mailing list