Help me, kamailio step-bros, i'm stuck!
Im trying to build logic, where if target client was not located on this node - message is forwarded to the next node, until sip message make full circle, and it will be handled by its 'X-Visited-Nodes' header and fire 404 if no one consumed it. (I can see that check is buggy, but i will fix this later so don't pay much attention to it)
Im blocked by t_relay() behaviour, which is ignore destination selected by ds_select_dst; Instead of forwarding message, it comes on the same node again and again
my dispatcher config
927 route[DISPATCH] { 928 $var(destination_found) = 0; 929 $var(checked_nodes) = ""; # Keep track of locally checked nodes 930 $var(loop_behaviour) = 0; 931 932 # Initialize X-Visited-Nodes if it doesn't exist 933 if ($hdrc(X-Visited-Nodes) == 0) { 934 append_hf_value("X-Visited-Nodes", ""); # Initialize the header in the message 935 } 936 937 xlog("X-Visited-Nodes: $hdr(X-Visited-Nodes)"); 938 append_hf_value("X-Visited-Nodes", "$du"); 939 # Round-robin dispatching on gateways group '1' 940 while (ds_select_dst("1", "4") && $var(loop_behaviour) != 2) { 941 $var(loop_behaviour) = 0; 942 # Get the current proposed destination 943 $var(current_dest) = $du; 944 945 # 1. Skip if the proposed destination is self 946 if ($var(loop_behaviour) == 0 && $var(current_dest) =~ ".*" + $Ri + ".*") { 947 xlog("Skipping self destination <$var(current_dest)>\n"); 948 ds_mark_dst(); # Mark this node globally only because it's "self" 949 $var(loop_behaviour) = 1; #continue 950 } 951 952 # 2. Check if we've made a full circle 953 if ($var(loop_behaviour) == 0 && $var(checked_nodes) =~ "^" + $var(current_dest) + ".*") { 954 xlog("All nodes checked, no valid destination found\n"); 955 send_reply("404", "No user found, no new destination available"); 956 exit; 957 } 958 959 # 3. Check if the node is already in X-Visited-Nodes 960 if ($var(loop_behaviour) == 0 && $hdr(X-Visited-Nodes) =~ ".*" + $var(current_dest) + ".*") { 961 xlog("Node <$var(current_dest)> already in X-Visited-Nodes\n"); 962 $var(checked_nodes) = $var(checked_nodes) + "," + $var(current_dest); 963 $var(loop_behaviour) = 1; #continue 964 } 965 966 if($var(loop_behaviour) == 0){ 974 xlog("DISPATCHER: selected reqURI: <$ru> ; destURI: <$du> via <$var(current_dest)> (attrs: $xavp(_dsdst_=>attrs))\n"); 975 $var(destination_found) = 1; 976 $var(loop_behaviour) = 2; # Exit the loop as a valid destination is found 977 } 978 } 979 980 # If a destination is found, relay the message 981 if ($var(destination_found)) { 987 if (!t_relay()) { 988 sl_reply_error(); 989 } 990 exit; 991 } else { 992 return(-1); 993 } 994 }
INVITE message trace (every line was trimmed to not garbage this message with irrelevant info like process name or timestamp)
i have enabled config trace mode, so my invite message inside dispatcher route looks like this. And on my other node, there is not a trace of invite message
{1 22 INV CmLZ} <script>: Lookup for 02222 failed - no such client on this node <--- Trying to call user, which is not registered on this node, so location route returns fail and message should go on another node {1 22 INV CmLZ} trace(): request_route=[LOCATION] c=[/etc/kamailio/kamailio.cfg] l=845 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[LOCATION] c=[/etc/kamailio/kamailio.cfg] l=842 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[LOCATION] c=[/etc/kamailio/kamailio.cfg] l=843 a=2 n=return {1 22 INV CmLZ} trace(): request_route=[DEFAULT_ROUTE] c=[/etc/kamailio/kamailio.cfg] l=653 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DEFAULT_ROUTE] c=[/etc/kamailio/kamailio.cfg] l=650 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DEFAULT_ROUTE] c=[/etc/kamailio/kamailio.cfg] l=645 a=5 n=route {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=928 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=929 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=930 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=937 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=934 a=26 n=append_hf_value {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=937 a=25 n=xlog {1 22 INV CmLZ} <script>: X-Visited-Nodes: <null> {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=938 a=26 n=append_hf_value {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=978 a=23 n=while {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=940 a=26 n=ds_select_dst {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=941 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=943 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=953 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=960 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=966 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=978 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=974 a=25 n=xlog {1 22 INV CmLZ} <script>: DISPATCHER: selected reqURI: sip:02222@kamailio-nlb-test-40f4f509064551a6.elb.eu-west-1.amazonaws.com ; destURI: sip:10.197.200.228:5060 via sip:10.197.200.228:5060 (attrs: <null>) <--- destination uri is correct, message should be sent to next kamailio node isn't it? {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=975 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=976 a=63 n=assign {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=940 a=26 n=ds_select_dst {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=993 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=990 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=987 a=24 n=t_relay <-- should relay to $dU destination {1 22 INV CmLZ} tm [t_lookup.c:1868]: t_newtran(): msg (0x7d0ad3775368) id=28/25950 global id=28/25950 T start=(nil) {1 22 INV CmLZ} tm [t_lookup.c:781]: t_lookup_request(): start searching: hash=9408, isACK=0 {1 22 INV CmLZ} tm [t_lookup.c:499]: matching_3261(): RFC3261 transaction matching failed - via branch [z9hG4bK.YP1EiC6qX] {1 22 INV CmLZ} tm [t_lookup.c:981]: t_lookup_request(): no transaction found {1 22 INV CmLZ} tm [h_table.c:532]: tm_xdata_swap(): copy X/AVPs from msg context to txdata {1 22 INV CmLZ} tm [t_hooks.c:301]: run_reqin_callbacks_internal(): trans=0x7d0acdbf1168, callback type 1, id 0 entered {1 22 INV CmLZ} tm [h_table.c:551]: tm_xdata_swap(): restore X/AVPs msg context from txdata {1 22 INV CmLZ} tm [h_table.c:415]: build_cell(): created new cell 0x7d0acdbf1168 {1 22 INV CmLZ} tm [t_funcs.c:339]: t_relay_to(): new INVITE {1 22 INV CmLZ} tm [t_reply.c:634]: _reply_light(): reply sent out - buf=0x7d0ad3755d98: SIP/2.0 100 trying -... shmem=0x7d0acdbf4b10: SIP/2.0 100 trying - {1 22 INV CmLZ} tm [t_reply.c:645]: _reply_light(): finished {1 22 INV CmLZ} tm [t_funcs.c:386]: t_relay_to(): new transaction forwarded
{1 22 INV CmLZ} trace(): request_route=[DISPATCH] c=[/etc/kamailio/kamailio.cfg] l=990 a=2 n=exit <--- same invite appears on this node instead of being forwarded to next kamailio node {1 22 INV CmLZ} trace(): request_route=[DEFAULT_ROUTE] c=[/etc/kamailio/kamailio.cfg] l=585 a=5 n=route {1 22 INV CmLZ} trace(): request_route=[REQINIT] c=[/etc/kamailio/kamailio.cfg] l=699 a=67 n=set_rpl_no_connect {1 22 INV CmLZ} trace(): request_route=[REQINIT] c=[/etc/kamailio/kamailio.cfg] l=702 a=55 n=force_rport {1 22 INV CmLZ} trace(): request_route=[REQINIT] c=[/etc/kamailio/kamailio.cfg] l=727 a=16 n=if {1 22 INV CmLZ} trace(): request_route=[REQINIT] c=[/etc/kamailio/kamailio.cfg] l=732 a=16 n=if