#264 Add {s.encode.int} transformation

1.9.x
closed-invalid
core (47)
5
2013-04-10
2013-02-28
Umberto Mautone
No

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

Discussion

  •  
    Attachments
    • assigned_to: nobody --> bogdan_iancu
     
  • Just following up on this patch to see if there are any objections to its inclusion.

     
  • 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

     
    • assigned_to: bogdan_iancu --> vladut-paiu
     
  • 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.

     
    • status: open --> closed-invalid
     
  • Hello,

    I understand your issue, but perhaps you can re-use some of the existing modules for doing that.
    You could, for example, use the permissions module, and store your OpenSIPS listening IPs in the dababase, and have the appropriate load-balancing group for each IP in the attrs field.
    Then for a request, you'd just call check_address("0","$Ri","$Rp","$proto","$avp(lb_group)") and this will populate the attrs field ( the LB group in our case ) in the $avp(lb_group) pvar.

    This seems cleaner, without the need to have the actual LB group be some hardcoded number that represents the ip.pton value of the actual IP, and also has the advantage of more flexibility in the case where you would want to differentiate between two interface with same IP but different ports ( eg: 127.0.0.1:5060 and 127.0.0.1:5070 )

    For the moment, marking the current patch as invalid.

    Best Regards,
    Vlad