Visited by a famous

I’m talking about Carsten Bock, one the brightest minds behind the development of opensource VOIP projects. He came to Paraguay for business reasons and me and the guys here at Conexion had the pleasure of learning from him for almost two weeks. Not always we have the opportunity to hang out with such a great VOIP eminence around this part of the world so this situation deserves a blog post :D.

Reading pvars with Kamailio

It’s really hard to find documentation in some opensource projects, specially when you want to achieve something that’s not very common. I’m speaking about Kamailio project which is actually very well documented but its core development manual is not profound in topics that we may need to develop a fully functional module entirely in C. This post pretends to be the first of many short tutorials to access to certain parts of the core dev API on which I wasn’t able to find any documentation or when it was present, it was not sufficient.

Reading system pvars.

This time is about reading pseudo variables like $rU, $si or $fU. I won’t explain what pvars are because I’m assuming the reader has some basic knowledge but if you want to have  a better understanding, the development guide has a section dedicated to it but not with the approach I’m using here.

Ok, the code:


/**
* Get str value using its name
*
* msg: parsed SIP message
* pv_name: the name of the pseudo variable
* pv_Value: pointer to str in which the value will be stored
*
*/

static int get_str_pv(struct sip_msg* msg, str *pv_name, str *pv_value)

{
pv_spec_t spec;
pv_value_t value;
pv_parse_spec(&pv_name, &spec);

if (pv_get_spec_value(msg, &spec, &value) != 0)
{
LM_ERR("Can't get spec for [%.*s]n", pv_name->len, pv_name->s);
return -1;
}

if (pkg_str_dup(pv_value, &value.rs) != 0)
{
LM_ERR("No more pkg memory availablen");
return -1;
}

return 0;
}

And finally, the way we should call it:


str source_ip_pv = str_init("$si");
str value;

if (get_str_pv(msg, &source_ip_pv, &value) != 0)
return -1;

If you really want to learn the right way of doing things with Kamailio, the tool you should master is grep. Grepping code was much more useful than reading mailing lists or consulting the devel guide. Consider it an advice.

Openvpn

This post is a reminder to my brain who lately likes to forget basic things such an iptable rule to allow VPN clients to access internal LAN.

Yes, this afternoon I spent almost an hour and a half to try to figure out what went wrong with my newly installed openvpn. I was unable to access the LAN behind the server and I literally spent 90 minutes looking in the wrong place because my brain betrayed me and I completely forgot about adding a MASQUERADE rule to my firewall.

In my defense, I had problems with the installation, dependency problems and something close to the DLL hell that Windows has. This situation tricked me a lot because I assumed   this was the cause but when I decided to tcpdump the requests I saw the following:

[bash]

# tcpdump -i tun0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on tun0, link-type RAW (Raw IP), capture size 65535 bytes
17:27:38.136712 IP 10.8.0.6 > 192.168.0.1: ICMP echo request, id 30234, seq 1, length 64
17:27:39.137333 IP 10.8.0.6 > 192.168.0.1: ICMP echo request, id 30234, seq 2, length 64

[/bash]

What! direct ping from tun to an IP visible only from eth0? Then I realized that I missed the:

[bash]

# iptables -t nat -A POSTROUTING -j MASQUERADE

[/bash]

Voila!

[bash]

# tcpdump -i tun0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on tun0, link-type RAW (Raw IP), capture size 65535 bytes

17:39:55.968160 IP 10.8.0.6 > 192.168.0.1: ICMP echo request, id 30234, seq 738, length 64

17:39:55.968757 IP 192.168.0.1 > 10.8.0.6: ICMP echo reply, id 30234, seq 738, length 64

[/bash]

I must have installed openvpn at least 4 times before today, but still wasn’t enough to remember the right thing at the right moment. Won’t happen again, hopefully :D.