[Asterisk-Dev] Making libiax2 speak TCP (through udp tunneling)

Alessandro Muzzetta ale.muzzetta at studiotecnia.it
Sat May 15 21:44:36 MST 2004


Hello folks,

I am trying to make an iax client talk to asterisk through a udp tunneling
program.

The client is supposed to open a tcp connection via the libiax2 calls to the
tunneling
server.  The tunneling server then sends out the encapsulated packets it
receives
by udp to asterisk.  Udp replies sent by asterisk to that same udp port are
tunneled
back to the client.  The tunneling works perfectly.

The problem is that while client and asterisk are able to exchange packets
through
the tunnel, they are unable to establish a proper connection.  Below is a
sample
packet capture.  192.168.24.198 is the tunneling program and 192.168.55.55
is asterisk.

     No. Time        Source                Destination           Protocol
Info
      1 0.000000    192.168.24.198         192.168.55.55          IAX2
IAX NEW, source call# 20916, timestamp 3ms
      2 0.023458    192.168.24.198         192.168.55.55          IAX2
IAX NEW, source call# 20916, timestamp 3ms
      3 0.127116    192.168.55.55          192.168.24.198         IAX2
IAX AUTHREQ, source call# 4, timestamp 1ms
      4 0.151087    192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 3ms
      5 0.264549    192.168.24.198         192.168.55.55          IAX2
IAX NEW, source call# 20916, timestamp 3ms
      6 0.392809    192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 3ms
      7 1.223209    192.168.24.198         192.168.55.55          IAX2
IAX NEW, source call# 20916, timestamp 3ms
      8 1.349853    192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 3ms
      9 2.141140    192.168.55.55          192.168.24.198         IAX2
IAX AUTHREQ, source call# 4, timestamp 1ms
     10 5.074529    192.168.24.198         192.168.55.55          IAX2
IAX NEW, source call# 20916, timestamp 3ms
     11 5.202042    192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 3ms
     12 9.959151    192.168.24.198         192.168.55.55          IAX2
IAX PING, source call# 20916, timestamp 9995ms
     13 10.017928   192.168.24.198         192.168.55.55          IAX2
IAX PING, source call# 20916, timestamp 9995ms
     14 10.085294   192.168.55.55          192.168.24.198         IAX2
IAX PONG, source call# 4, timestamp 9995ms
     15 10.145127   192.168.55.55          192.168.24.198         IAX2
IAX LAGRQ, source call# 4, timestamp 10014ms
     16 10.147178   192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 9995ms
     17 10.259910   192.168.24.198         192.168.55.55          IAX2
IAX PING, source call# 20916, timestamp 9995ms
     18 10.384938   192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 9995ms
     19 11.218197   192.168.24.198         192.168.55.55          IAX2
IAX PING, source call# 20916, timestamp 9995ms
     20 11.341935   192.168.55.55          192.168.24.198         IAX2
IAX ACK, source call# 4, timestamp 9995ms

iax_init creates a tcp connection with socket netfd to the tunneling server:
    netfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
    ....
    server_address.sin_family = AF_INET;
    server_address.sin_port = htons(4569);
    server_address.sin_addr.s_addr = inet_addr("192.168.24.198");

    if (connect(netfd, (struct sockaddr *) &sin, sinlen) != 0)
    ....


iax_xmit_frame encapsulates frames as udp packets and sends them through the
tunnel:
    struct
    {
     short length;
     char buffer[65536];
     } packet;

    packet.length = htons(f->datalen);
    memcpy(packet.buffer, (const char *) f->data, f->datalen);
    return send(netfd, (const char *) &packet, f->datalen + 2,
IAX_SOCKOPTS);

iax_net_read reads packets from the tunnel:
    res = recv(netfd, buf, sizeof buf, 0);
    ....
    return iax_net_process(buf, res, &server_address);

server_address is initialized once in iax_init and remains unaltered
thereafter.

The problem lies in iax_net_process on this line:
    session = iax_find_session(sin, ntohs(fh->scallno), 0, 0);

session always returns null.

Thanks in advance for your time.


Alessandro




More information about the asterisk-dev mailing list