| 685 | |
| 686 | |
| 687 | static inline int do_dns_failover(struct cell *t) |
| 688 | { |
| 689 | static struct sip_msg faked_req; |
| 690 | struct sip_msg *shmem_msg; |
| 691 | struct sip_msg *req; |
| 692 | dlg_t dialog; |
| 693 | int ret, sip_msg_len; |
| 694 | struct ua_client* uac = & TM_BRANCH( t, picked_branch); |
| 695 | |
| 696 | /* check if the DNS resolver can get at least one new IP */ |
| 697 | if ( get_next_su( uac->proxy, &uac->request.dst.to, 1)!=0 ) |
| 698 | return -1; |
| 699 | |
| 700 | LM_DBG("new destination available\n"); |
| 701 | |
| 702 | if (t->uas.request==NULL) { |
| 703 | if (!is_local(t)) { |
| 704 | LM_CRIT("BUG: proxy transaction without UAS request :-/\n"); |
| 705 | return -1; |
| 706 | } |
| 707 | /* create the cloned SIP msg -> first create a new SIP msg */ |
| 708 | memset( &dialog, 0, sizeof(dialog)); |
| 709 | dialog.send_sock = uac->request.dst.send_sock; |
| 710 | dialog.hooks.next_hop = &uac->uri; |
| 711 | req = buf_to_sip_msg(uac->request.buffer.s, uac->request.buffer.len, |
| 712 | &dialog); |
| 713 | if (req==NULL) { |
| 714 | LM_ERR("failed to generate SIP msg from previous buffer\n"); |
| 715 | return -1; |
| 716 | } |
| 717 | /* now do the actual cloning of the SIP message */ |
| 718 | t->uas.request = sip_msg_cloner( req, &sip_msg_len, 1); |
| 719 | if (t->uas.request==NULL) { |
| 720 | LM_ERR("cloning failed\n"); |
| 721 | free_sip_msg(req); |
| 722 | pkg_free(req); |
| 723 | return -1; |
| 724 | } |
| 725 | t->uas.end_request = ((char*)t->uas.request) + sip_msg_len; |
| 726 | /* free the actual SIP message, keep the clone only */ |
| 727 | free_sip_msg(req); |
| 728 | pkg_free(req); |
| 729 | } |
| 730 | shmem_msg = t->uas.request; |
| 731 | |
| 732 | if (!fake_req(&faked_req, shmem_msg, &t->uas, uac)) { |
| 733 | LM_ERR("fake_req failed\n"); |
| 734 | return -1; |
| 735 | } |
| 736 | /* fake also the env. conforming to the fake msg */ |
| 737 | faked_env( t, &faked_req); |
| 738 | ret = -1; |
| 739 | |
| 740 | /* set info as current destination */ |
| 741 | if ( set_ruri( &faked_req, &uac->uri)!= 0) |
| 742 | goto done; |
| 743 | |
| 744 | setb0flags( &faked_req, uac->br_flags ); |
no test coverage detected