00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef forward_h
00039 #define forward_h
00040
00041 #include "globals.h"
00042 #include "parser/msg_parser.h"
00043 #include "route.h"
00044 #include "proxy.h"
00045 #include "ip_addr.h"
00046
00047 #include "udp_server.h"
00048 #ifdef USE_TCP
00049 #include "tcp_server.h"
00050 #endif
00051
00052 #ifdef USE_SCTP
00053 #include "sctp_server.h"
00054 #endif
00055
00056
00057 struct socket_info* get_send_socket(struct sip_msg* msg,
00058 union sockaddr_union* su, int proto);
00059 struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
00060 int check_self(str* host, unsigned short port, unsigned short proto);
00061 int forward_request( struct sip_msg* msg, struct proxy_l* p);
00062 int update_sock_struct_from_via( union sockaddr_union* to,
00063 struct sip_msg* msg,
00064 struct via_body* via );
00065
00066
00067 #define update_sock_struct_from_ip( to, msg ) \
00068 init_su((to), &(msg)->rcv.src_ip, \
00069 (((msg)->via1->rport)||((msg)->msg_flags&FL_FORCE_RPORT))? \
00070 (msg)->rcv.src_port: \
00071 ((msg)->via1->port)?(msg)->via1->port: SIP_PORT )
00072
00073 int forward_reply( struct sip_msg* msg);
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static inline int msg_send( struct socket_info* send_sock, int proto,
00091 union sockaddr_union* to, int id,
00092 char* buf, int len)
00093 {
00094 if (send_sock==0)
00095 send_sock=get_send_socket(0, to, proto);
00096 if (send_sock==0){
00097 LM_ERR("no sending socket found for proto %d\n", proto);
00098 goto error;
00099 }
00100
00101 if (proto==PROTO_UDP){
00102 if (udp_send(send_sock, buf, len, to)==-1){
00103 LM_ERR("udp_send failed\n");
00104 goto error;
00105 }
00106 }
00107 #ifdef USE_TCP
00108 else if (proto==PROTO_TCP){
00109 if (tcp_disable){
00110 LM_WARN("attempt to send on tcp and tcp"
00111 " support is disabled\n");
00112 goto error;
00113 }else{
00114 if (tcp_send(send_sock, proto, buf, len, to, id)<0){
00115 LM_ERR("tcp_send failed\n");
00116 goto error;
00117 }
00118 }
00119 }
00120 #ifdef USE_TLS
00121 else if (proto==PROTO_TLS){
00122 if (tls_disable){
00123 LM_WARN("attempt to send on tls and tls"
00124 " support is disabled\n");
00125 goto error;
00126 }else{
00127 if (tcp_send(send_sock, proto, buf, len, to, id)<0){
00128 LM_ERR("tcp_send failed\n");
00129 goto error;
00130 }
00131 }
00132 }
00133 #endif
00134 #endif
00135 #ifdef USE_SCTP
00136 else if (proto==PROTO_SCTP){
00137 if (sctp_disable){
00138 LM_WARN("attempt to send on sctp and sctp"
00139 " support is disabled\n");
00140 goto error;
00141 }else{
00142 if (sctp_server_send(send_sock, buf, len, to)<0){
00143 LM_ERR("sctp_send failed\n");
00144 goto error;
00145 }
00146 }
00147 }
00148 #endif
00149 else{
00150 LM_CRIT("unknown proto %d\n", proto);
00151 goto error;
00152 }
00153 return 0;
00154 error:
00155 return -1;
00156 }
00157
00158 #endif