rtpengine - IPv4 and IPv6 configuration

781 views
Skip to first unread message

Troy Changfoot

unread,
Sep 26, 2023, 1:46:24 PM9/26/23
to rtpengine
Hi there!

I'm pretty new to IPv4/IPv6 bridging of RTP communication using Kamailio.

We wanting to make use of an external Kamailio proxy that listens on IPv4/IPv6 and handles RTPengine proxying for both respectively, however we want this to act as a relay for our IPv4 Kamailio which is sitting in K8s.

So the IPv6/IPv4 Kamailio sits in a VM outside of K8s along with the rtpengine :

Trying to figure out how to get basic config on the RTPengine working,

Is something like this this posssibe ?

[rtpengine]
interface=10.0.0.8
interface=[fd12:3456:789a::2]
foreground=true
log-stderr=true
listen-ng=0.0.0.0:22222
listen-ng=[::]:22222   <---- rtpengine only seems to work on one or the other, in this case IPv6 was the last listen-ng parameter so it seems to ignore the first one.   Do we only need one listen-ng? 
port-min=23000
port-max=32768
recording-dir=/tmp
recording-method=pcap
recording-format=eth
log-level=6
delete-delay=0
listen-http=0.0.0.0:8080
listen-http=[::]:8080


In kamailio example config :

####### RTPEngine Config ##########
loadmodule "rtpengine.so"
modparam("rtpengine", "rtpengine_sock", "udp:10.0.0.8:22222") <--- should we have multiple rtpengine_sock params here one for IPv4 and one for IPv6?

####### Routing Logic #########
request_route {
    # Initial checks
    if(!sanity_check("1511", "7")) {
        xlog("L_ERR", "Malformed SIP message from $si:$sp\n");
        exit;
    }
   
    if (!mf_process_maxfwd_header("10")) {
        sl_send_reply("483", "Too Many Hops");
        exit;
    }

    if(is_method("OPTIONS") && uri==myself) {
        sl_send_reply("200", "Keepalive");
        exit;
    }

    if(is_method("INVITE")) {
        xlog("L_INFO", "Incoming INVITE: \n----------------------------------------------------------- \n");
        # If the source IP is IPv6, apply specific RTPengine directives
        if(is_ipv6($si)) {
            xlog("L_INFO", "This INVITE is from an IPv6 source. Engaging RTPengine for SDP rewriting.\n");
            rtpengine_manage("replace-origin replace-session-connection ICE=remove RTP/AVP");    <---- over here  I want the SDP to use IPv4 address of the rtpengine if it is an IPv6 INVITE
        } else {
            # For IPv4 INVITES or other scenarios
            xlog("L_INFO", "This INVITE is from an IPv4 source. Engaging RTPengine.\n");
            rtpengine_manage();
        }
    }

    # Relay logic
    $du = "sip:10.0.0.5:5062;transport=tcp";
    xlog("L_INFO", "Relaying to: $du\n");
    xlog("L_INFO", "Calling t_relay()...\n");
    if (!t_relay()) {
        xlog("L_ERR", "t_relay failed. Error: $retcode\n");
        sl_reply_error();
    }
    exit;
}


Hopefully this is clear.   Your help is much appreciated!


Regards,


Troy


Richard Fuchs

unread,
Sep 26, 2023, 2:32:56 PM9/26/23
to rtpe...@googlegroups.com
On 26/09/2023 13.46, [EXT] Troy Changfoot wrote:
Hi there!

I'm pretty new to IPv4/IPv6 bridging of RTP communication using Kamailio.
...

Is something like this this posssibe ?

[rtpengine]
interface=10.0.0.8
interface=[fd12:3456:789a::2]
You can have only one interface= line – to list multiple interfaces or addresses, separate them by semicolons.
...

listen-ng=0.0.0.0:22222
listen-ng=[::]:22222   <---- rtpengine only seems to work on one or the other, in this case IPv6 was the last listen-ng parameter so it seems to ignore the first one.   Do we only need one listen-ng? 
The newest versions of rtpengine (11.5+, released just today) actually do support multiple listening sockets (you'd have to put them all in one line and separate by semicolons, same as for interface=), but in your case you can just leave it as listen-ng=2222 and you will get an ANY socket for both protocols.
...

modparam("rtpengine", "rtpengine_sock", "udp:10.0.0.8:22222") <--- should we have multiple rtpengine_sock params here one for IPv4 and one for IPv6?
You only need one control connection to rtpengine, and the address family/protocol used for it is unrelated to which media protocols you want to support.

        # If the source IP is IPv6, apply specific RTPengine directives
        if(is_ipv6($si)) {
            xlog("L_INFO", "This INVITE is from an IPv6 source. Engaging RTPengine for SDP rewriting.\n");
            rtpengine_manage("replace-origin replace-session-connection ICE=remove RTP/AVP");    <---- over here  I want the SDP to use IPv4 address of the rtpengine if it is an IPv6 INVITE
        } else {
            # For IPv4 INVITES or other scenarios
            xlog("L_INFO", "This INVITE is from an IPv4 source. Engaging RTPengine.\n");
            rtpengine_manage();
        }

You don't need to tell rtpengine what protocol the source is using – it already knows this from what's in the SDP. But you need to tell rtpengine the destination: based on where the invite is going, and what protocol the destination is using. You can do this with address-family=IP4 or ...=IP6.

If you're feeling fancy, it's worth distinguishing between offers and answers (i.e use rtpengine_offer() and _answer() instead of _manage()) as generally in the answer (and also re-invites) you can omit most of the options since rtpengine already knows which protocols etc the client in question supports.

Cheers

Troy Changfoot

unread,
Sep 27, 2023, 3:24:44 AM9/27/23
to rtpe...@googlegroups.com
Hi Richard,

Thank you for your input!  Your assistance is greatly appreciated.  :- )

I've amended configuration inline with your comments, as follows :

rtpengine config:
[rtpengine]
interface=10.0.0.8;[fd12:3456:789a::2]
foreground=true
log-stderr=true
listen-ng=22222
port-min=23000
port-max=32768
recording-dir=/tmp
recording-method=pcap
recording-format=eth
log-level=7
delete-delay=0
listen-http=10.0.0.8:8080;[fd12:3456:789a::2]:8080



and in kamailio.cfg:

listen=10.0.0.21
listen=[fd12:3456:789a::3]

####### RTPEngine Config ##########
loadmodule "rtpengine.so"
modparam("rtpengine", "rtpengine_sock", "udp:10.0.0.8:22222")


####### Routing Logic #########
request_route {
    # Initial checks
    if(!sanity_check("1511", "7")) {
        xlog("L_ERR", "Malformed SIP message from $si:$sp\n");
        exit;
    }
    
    if (!mf_process_maxfwd_header("10")) {
        sl_send_reply("483", "Too Many Hops");
        exit;
    }

    if(is_method("OPTIONS") && uri==myself) {
        sl_send_reply("200", "Keepalive");
        exit;
    }

    if (is_method("INVITE")) {
        if (!has_totag()) {
            # This block handles initial INVITEs
            if (is_ipv6($si)) {
                xlog("L_INFO", "IPv6 INVITE. Processing offer with RTPengine.\n");
                rtpengine_offer("address-family=IP4 replace-origin replace-session-connection ICE=remove RTP/AVP");  <--- Updated rtpengine_manage with _offer
            } else {
                xlog("L_INFO", "IPv4 INVITE. Processing offer with RTPengine.\n");
                rtpengine_offer();
            }
        } else {
            # This block handles re-INVITEs
            xlog("L_INFO", "Processing answer with RTPengine for re-INVITE.\n");
            rtpengine_answer();  <--- Added rtpengine_answer for re-invites
        }
    } 

    # Relay logic
    $du = "sip:10.0.0.5:5062;transport=tcp";
    xlog("L_INFO", "Relaying to: $du\n"); 
    xlog("L_INFO", "Calling t_relay()...\n");
    if (!t_relay()) {
        xlog("L_ERR", "t_relay failed. Error: $retcode\n");
        sl_reply_error();
    }
    exit;
}


# Handling for initial INVITE responses.
onreply_route {
    if (!has_totag()) {
        return;  # Ignore responses to in-dialog requests
    }

    if (status =~ "1[0-9][0-9]") {
        # Provisional 1xx response, add handling if necessary
        return;
    }

    if (status == 200) {
        xlog("L_INFO", "200 OK received. Processing answer with RTPengine.\n");
        rtpengine_answer(); <--- Added rtpengine_answer for invite repsonse
    }
}


# Cleanup on failure to release any reserved resources in rtpengine
failure_route {
    rtpengine_delete();
}


but alas, when I send a test call in, the SDP still reflects the IPv6 of the kamailio, logs on kamailio seem to indicate that rtpengine can't allocate ports:

 6(5918) WARNING: rtpengine [rtpengine.c:2763]: rtpp_function_call(): proxy udp:10.0.0.8:22222: Ran out of ports 6(5918) INFO: rtpengine [rtpengine.c:2929]: rtpp_test(): rtpengine instance <udp:10.0.0.8:22222> found, support for it enabled
 6(5918) ERROR: rtpengine [rtpengine.c:3365]: select_rtpp_node(): rtpengine failed to select new for calllen=24 callid=1-5945@fd12:3456:789a::3
 6(5918) ERROR: rtpengine [rtpengine.c:2706]: rtpp_function_call(): no available proxies


Upon closer inspection of the rtpengine logs : 

[1695799029.088055] INFO: [crypto] Generating new DTLS certificate
[1695799029.094131] ERR: [http] libwebsockets: ERROR on binding fd 9 to port 8080 (-1 99)    <---  I have no firewall rules and port 8080 is not bound to any other service, is it perhaps something in the rtpengine conf?
[1695799029.094786] ERR: [http] libwebsockets: VH fd12:3456:789a::2: iface fd12:3456:789a::2 port 8080 DOESN'T EXIST
[1695799029.095322] INFO: [core] Startup complete, version 10.5.3.5-1
[1695799029.096603] INFO: [http] Websocket listener thread running
[1695799035.615371] INFO: [1-6691@fd12:3456:789a::3]: [control] Received command 'offer' from 10.0.0.21:48541
[1695799035.615469] NOTICE: [1-6691@fd12:3456:789a::3]: [core] Creating new call
[1695799035.641627] ERR: [1-6691@fd12:3456:789a::3]: [core] Failed to get 2 consecutive ports on interface fd12:3456:789a::2 for media relay (last error: Cannot assign requested address)
[1695799035.642462] ERR: [1-6691@fd12:3456:789a::3]: [core] Failed to get 2 consecutive ports on all locals of logical 'default'
[1695799035.644559] ERR: [1-6691@fd12:3456:789a::3]: [core] Error allocating media ports
[1695799035.645117] ERR: [1-6691@fd12:3456:789a::3]: [core] Destroying call
[1695799035.645515] INFO: [1-6691@fd12:3456:789a::3]: [core] Final packet stats:
[1695799035.645523] INFO: [1-6691@fd12:3456:789a::3]: [core] --- Tag '1', created 0:00 ago for branch ''
[1695799035.645527] INFO: [1-6691@fd12:3456:789a::3]: [core] ---     subscribed to ''
[1695799035.645531] INFO: [1-6691@fd12:3456:789a::3]: [core] ---     subscription for ''
[1695799035.645537] INFO: [1-6691@fd12:3456:789a::3]: [core] ------ Media #1 (audio over RTP/AVP) using unknown codec
[1695799035.645544] INFO: [1-6691@fd12:3456:789a::3]: [core] --------- Port         0.0.0.0:0     <>                :0    , SSRC 0, 0 p, 0 b, 0 e, 0 ts
[1695799035.645548] INFO: [1-6691@fd12:3456:789a::3]: [core] --------- Port         0.0.0.0:0     <>                :0    , SSRC 0, 0 p, 0 b, 0 e, 0 ts
[1695799035.645552] INFO: [1-6691@fd12:3456:789a::3]: [core] --- Tag '', created 0:00 ago for branch ''
[1695799035.645555] INFO: [1-6691@fd12:3456:789a::3]: [core] ---     subscribed to '1'
[1695799035.645559] INFO: [1-6691@fd12:3456:789a::3]: [core] ---     subscription for '1'
[1695799035.645563] INFO: [1-6691@fd12:3456:789a::3]: [core] ------ Media #1 (audio over RTP/AVP) using unknown codec
[1695799035.645567] INFO: [1-6691@fd12:3456:789a::3]: [core] --------- Port        10.0.0.8:23000 <>                :0    , SSRC 0, 0 p, 0 b, 0 e, 0 ts
[1695799035.645571] INFO: [1-6691@fd12:3456:789a::3]: [core] --------- Port        10.0.0.8:23001 <>                :0    , SSRC 0, 0 p, 0 b, 0 e, 0 ts
[1695799035.645607] WARNING: [1-6691@fd12:3456:789a::3]: [control] Protocol error in packet from 10.0.0.21:48541: Ran out of ports [d8:supportsl10:load limite3:sdp208:v=0
o=user1 53655765 2353687637 IN IP6 [fd12:3456:789a::3]
s=-
c=IN IP6 [fd12:3456:789a::3]
t=0 0
m=audio 6000 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-11,16
14:address-family3:IP43:ICE6:remove7:replacel6:origin18:session-connectione18:transport-protocol7:RTP/AVP7:call-id24:1-6691@fd12:3456:789a::313:received-froml3:IP617:fd12:3456:789a::3e8:from-tag1:17:command5:offere]
[1695799035.647430] INFO: [control] Received command 'ping' from 10.0.0.21:48541
[1695799035.647463] INFO: [control] Replying to 'ping' from 10.0.0.21:48541 (elapsed time 0.000001 sec)
[1695799059.123355] ERR: [http] libwebsockets: ERROR on binding fd 9 to port 8080 (-1 99)
[1695799089.151539] ERR: [http] libwebsockets: ERROR on binding fd 9 to port 8080 (-1 99)


Some guidance here would be most awesome!


Regards,

Troy

--
You received this message because you are subscribed to the Google Groups "rtpengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtpengine+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rtpengine/6352245b-0e1b-4d5a-af42-ec571ce96492%40sipwise.com.

Troy Changfoot

unread,
Sep 27, 2023, 4:09:33 AM9/27/23
to rtpengine
Hi  Richard,

Please ignore this last one... I had an IP issue, SDP rewrite is now happening, but have an issue further in the sip flow..  I'll post when I know more,  thank you so much for you assistance!

Have a great day!
Reply all
Reply to author
Forward
0 new messages