Hi,

I found a small bug in the msrp_cmap_lookup() function - fix now in git master.

The final version of my MSRP event-route is:

event_route[msrp:frame-in] {
        msrp_reply_flags("1");

        if ((($Rp == MY_WS_PORT || $Rp == MY_WSS_PORT)
                && !(proto == WS || proto == WSS)) && $Rp != MY_MSRP_PORT) {
                xlog("L_WARN", "MSRP request received on $Rp\n");
                msrp_reply("403", "Action-not-allowed");
                exit;
        }

        if (msrp_is_reply()) {
                msrp_relay();
        } else if($msrp(method)=="AUTH") {
                if($msrp(nexthops)>0) {
                        msrp_relay();
                        exit;
                }

                if (!www_authenticate("MY_DOMAIN", "subscriber",
                                        "$msrp(method)")) {
                        if (auth_get_www_authenticate("MY_DOMAIN", "1",
                                                        "$var(wauth)")) {
                                msrp_reply("401", "Unauthorized",
                                                        "$var(wauth)");
                        } else {
                                msrp_reply("500", "Server Error");
                        }
                        exit;
                }

                msrp_cmap_save();
        } else if ($msrp(method)=="SEND" || $msrp(method)=="REPORT") {
                if ($msrp(nexthops)>1) {
                        if ($msrp(method)!="REPORT") {
                                msrp_reply("200", "OK");
                        }
                        msrp_relay();
                        exit;
                }

                if (msrp_cmap_lookup()) {
                        if ($msrp(method)!="REPORT") {
                                msrp_reply("200", "OK");
                        }
                        msrp_relay_flags("1");
                        msrp_relay();
                } else {
                        msrp_reply("481", "Session-does-not-exist");
                }
        } else {
                msrp_reply("501", "Request-method-not-understood");
        }
}

Regards,

Peter

On Wed, 2013-02-06 at 10:35 +0000, Peter Dunkley wrote:

Hello,

I have the following configuration:

MSRP Client 1  ---> MSRP Relay ---> MSRP Relay ---> MSRP Client 2

Note: There is only one MSRP Relay here but as each client AUTHs with the relay it appears twice in the To-Path for MSRP SENDs and REPORTs and the MSRP requests get hair-pinned as they are routed.

Each MSRP client AUTHs against the MSRP Relay (authentication steps skipped for clarity):
MSRP Client 1 Authenticates
MSRP embt3epk AUTH
To-Path: msrp://james@192.168.0.74
From-Path: msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws
Authorization: Digest username="james", realm="example.com", nonce="URIsFlESKuoaIDis1UKPL0uU8e+IavWWW3aO/4A=", uri="msrp://james@192.168.0.74", response="8d6e1842dd2791f35772a0d8aa3d0237", qop=auth, cnonce="9he680vjcwdv", nc=00000001
-------embt3epk$

MSRP embt3epk 200 OK
To-Path: msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws
From-Path: msrp://james@192.168.0.74
Use-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp
Expires: 360
-------embt3epk$

MSRP Client 2 Authenticates
MSRP t1fm54qj AUTH
To-Path: msrp://peter@192.168.0.74
From-Path: msrp://hegodxou.invalid:2855/hc3n26dpvd;ws
Authorization: Digest username="peter", realm="example.com", nonce="URIsGVESKu3ejM4oZiRERc40yd1jeCbHW3aRAYA=", uri="msrp://peter@192.168.0.74", response="f230810364a0ea18afb451299a0be19c", qop=auth, cnonce="j5efxrn0mufs", nc=00000001
-------t1fm54qj$

MSRP t1fm54qj 200 OK
To-Path: msrp://hegodxou.invalid:2855/hc3n26dpvd;ws
From-Path: msrp://peter@192.168.0.74
Use-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp
Expires: 360
-------t1fm54qj$

The MSRP module parses these correctly and saves the entry in the connection map:
12(2636) DEBUG: msrp [msrp_parser.c:173]: MSRP FLine: [1] [MSRP] [embt3epk] [AUTH] [2] []
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b97f0) [To-Path] [2] [msrp://james@192.168.0.74]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3570) [From-Path] [1] [msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b35f0) [Authorization] [9] [Digest username="james", realm="example.com", nonce="URIsFlESKuoaIDis1UKPL0uU8e+IavWWW3aO/4A=", uri="msrp://james@192.168.0.74", response="8d6e1842dd2791f35772a0d8aa3d0237", qop=auth, cnonce="9he680vjcwdv", nc=00000001]
12(2636) DEBUG: msrp [msrp_mod.c:459]: executing event_route[msrp:frame-in] (3)
12(2636) DEBUG: msrp [msrp_cmap.c:230]: saving connection info for [msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws] [msrp-51122ad5-a4c-1] (174/4060267182)
12(2636) DEBUG: msrp [msrp_cmap.c:232]: frame received from [msrp://192.168.0.158:49662] via [tcp:192.168.0.74:80]

11(2635) DEBUG: msrp [msrp_parser.c:173]: MSRP FLine: [1] [MSRP] [t1fm54qj] [AUTH] [2] []
11(2635) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3570) [To-Path] [2] [msrp://peter@192.168.0.74]
11(2635) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b35f0) [From-Path] [1] [msrp://hegodxou.invalid:2855/hc3n26dpvd;ws]
11(2635) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3670) [Authorization] [9] [Digest username="peter", realm="example.com", nonce="URIsGVESKu3ejM4oZiRERc40yd1jeCbHW3aRAYA=", uri="msrp://peter@192.168.0.74", response="f230810364a0ea18afb451299a0be19c", qop=auth, cnonce="j5efxrn0mufs", nc=00000001]
11(2635) DEBUG: msrp [msrp_mod.c:459]: executing event_route[msrp:frame-in] (3)
11(2635) DEBUG: msrp [msrp_cmap.c:230]: saving connection info for [msrp://hegodxou.invalid:2855/hc3n26dpvd;ws] [msrp-51122ad5-a4b-1] (139/4060209803)
11(2635) DEBUG: msrp [msrp_cmap.c:232]: frame received from [msrp://192.168.0.158:49663] via [tcp:192.168.0.74:80]

Then MSRP Client 1 sends an MSRP SEND to MSRP client 2:
SEND from MSRP Client 1 to MSRP Relay
SRP sis9mer0 SEND
To-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp msrp://hegodxou.invalid:2855/hc3n26dpvd;ws
From-Path: msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws
Message-ID: 3569133935.vs42vpro
Success-Report: yes
Failure-Report: yes
Byte-Range: 1-0/0
-------sis9mer0$

MSRP sis9mer0 200 OK
To-Path: msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws
From-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp
Message-ID: 3569133935.vs42vpro
-------sis9mer0$

SEND from MSRP Relay to MSRP Relay
MSRP sis9mer0 SEND
To-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp msrp://hegodxou.invalid:2855/hc3n26dpvd;ws
From-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws
Message-ID: 3569133935.vs42vpro
Success-Report: yes
Failure-Report: yes
Byte-Range: 1-0/0
-------sis9mer0$

MSRP sis9mer0 481 Session-does-not-exist
To-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp
From-Path: msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp
Message-ID: 3569133935.vs42vpro
-------sis9mer0$

It looks like the MSRP module cannot find the entry in the connection map:
12(2636) DEBUG: msrp [msrp_parser.c:173]: MSRP FLine: [1] [MSRP] [sis9mer0] [SEND] [1] []
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b97f0) [To-Path] [2] [msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp msrp://hegodxou.invalid:2855/hc3n26dpvd;ws]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3570) [From-Path] [1] [msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b35f0) [Message-ID] [4] [3569133935.vs42vpro]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3670) [Success-Report] [7] [yes]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b36f0) [Failure-Report] [0] [yes]
12(2636) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b9940) [Byte-Range] [5] [1-0/0]
12(2636) DEBUG: msrp [msrp_mod.c:459]: executing event_route[msrp:frame-in] (3)
12(2636) ERROR: <script>: Relaying to next relay hop
12(2636) DEBUG: msrp [msrp_parser.c:536]: MSRP URI: [msrp] [] [192.168.0.74] [2855] [msrp-51122ad5-a4b-1] [tcp] []

10(2634) DEBUG: msrp [msrp_parser.c:173]: MSRP FLine: [1] [MSRP] [sis9mer0] [SEND] [1] []
10(2634) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9ac4d0) [To-Path] [2] [msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp msrp://hegodxou.invalid:2855/hc3n26dpvd;ws]
10(2634) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9ac550) [From-Path] [1] [msrp://192.168.0.74:2855/msrp-51122ad5-a4c-1;tcp msrp://4qc1y0p3.invalid:2855/pdbcph4zb2;ws]
10(2634) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9ac5d0) [Message-ID] [4] [3569133935.vs42vpro]
10(2634) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3570) [Success-Report] [7] [yes]
10(2634) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b35f0) [Failure-Report] [0] [yes]
10(2634) DEBUG: msrp [msrp_parser.c:296]: MSRP Header: (0x7f536e9b3670) [Byte-Range] [5] [1-0/0]
10(2634) DEBUG: msrp [msrp_mod.c:459]: executing event_route[msrp:frame-in] (3)
10(2634) ERROR: <script>: Relaying to destination
10(2634) ERROR: <script>: ... Current hop: msrp://192.168.0.74:2855/msrp-51122ad5-a4b-1;tcp, Next hop: msrp://hegodxou.invalid:2855/hc3n26dpvd;ws, Last hop: msrp://hegodxou.invalid:2855/hc3n26dpvd;ws
10(2634) DEBUG: msrp [msrp_parser.c:536]: MSRP URI: [msrp] [] [192.168.0.74] [2855] [msrp-51122ad5-a4b-1] [tcp] []
10(2634) DEBUG: msrp [msrp_cmap.c:346]: searching for session [msrp-51122ad5-a4b-1]
10(2634) ERROR: <script>: ... destination not in map

Here is my MSRP event route:

event_route[msrp:frame-in] {
        msrp_reply_flags("1");

        if ((($Rp == MY_WS_PORT || $Rp == MY_WSS_PORT)
                && !(proto == WS || proto == WSS)) && $Rp != MY_MSRP_PORT) {
                xlog("L_WARN", "MSRP request received on $Rp\n");
                msrp_reply("403", "Action-not-allowed");
                exit;
        }

        if (msrp_is_reply()) {
                msrp_relay();
        } else if($msrp(method)=="AUTH") {
                if($msrp(nexthops)>0) {
                        msrp_relay();
                        exit;
                }

                if (!www_authenticate("MY_DOMAIN", "subscriber",
                                        "$msrp(method)")) {
                        if (auth_get_www_authenticate("MY_DOMAIN", "1",
                                                        "$var(wauth)")) {
                                msrp_reply("401", "Unauthorized",
                                                        "$var(wauth)");
                        } else {
                                msrp_reply("500", "Server Error");
                        }
                        exit;
                }

                msrp_cmap_save();
        } else if ($msrp(method)=="SEND" || $msrp(method)=="REPORT") {
                if ($msrp(nexthops)>1) {
                        if ($msrp(method)!="REPORT") {
                                msrp_reply("200", "OK");
                        }
                        xlog("Relaying to next relay hop\n");
                        msrp_relay();
                        exit;
                }

                xlog("Relaying to destination\n");
                xlog("... Current hop: $msrp(crthop), Next hop: $msrp(nexthop), Last hop: $msrp(lasthop)\n");
                if (msrp_cmap_lookup()) {
                        if ($msrp(method)!="REPORT") {
                                msrp_reply("200", "OK");
                        }
                        xlog("... found destination in map\n");
                        msrp_relay();
                } else {
                        xlog("... destination not in map\n");
                        msrp_reply("481", "Session-does-not-exist");
                }
        } else {
                msrp_reply("501", "Request-method-not-understood");
        }
}

Regards,

Peter

_______________________________________________
sr-dev mailing list
sr-dev@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

-- 
Peter Dunkley
Technical Director
Crocodile RCS Ltd