From 342daa9c9b8fe4b946b7bcd1b79e1c5ab40ef480 Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Wed, 29 Nov 2023 15:19:23 -0800 Subject: [PATCH] Re-work hostname validation support to not require every user of sockaddr_union to store a copy of the hostname. Do this by creating a new "struct sockaddr_hu" struct, which includes sockaddr_union as well as an optional hostname. Extend various relevant APIs to use this structure instead. Untested. --- core_cmds.c | 8 ++-- forward.c | 26 +++++----- forward.h | 14 +++--- ip_addr.h | 69 +++++++++++++++++++-------- modules/clusterer/clusterer.c | 15 +++--- modules/clusterer/topology.c | 21 +++++--- modules/nat_traversal/nat_traversal.c | 2 +- modules/nathelper/nathelper.c | 6 ++- modules/proto_bin/proto_bin.c | 9 ++-- modules/proto_bins/proto_bins.c | 9 ++-- modules/proto_hep/hep.c | 8 ++-- modules/proto_hep/proto_hep.c | 22 +++++---- modules/proto_msrp/msrp_common.c | 6 ++- modules/proto_msrp/msrp_common.h | 2 +- modules/proto_msrp/msrp_signaling.c | 15 ++++-- modules/proto_sctp/sctp_server.c | 8 ++-- modules/proto_sctp/sctp_server.h | 2 +- modules/proto_smpp/proto_smpp.c | 4 +- modules/proto_smpp/smpp.c | 6 +-- modules/proto_ws/proto_ws.c | 7 +-- modules/proto_ws/ws_common.h | 7 +-- modules/rtpproxy/rtpproxy.c | 4 +- modules/sipcapture/sipcapture.c | 10 ++-- modules/sl/sl_funcs.c | 2 +- modules/tcp_mgm/tcp_path.c | 2 +- modules/tcp_mgm/tcp_path.h | 2 +- modules/tm/dlg.h | 2 +- modules/tm/t_funcs.c | 4 +- modules/tm/t_fwd.c | 12 ++--- modules/tm/t_reply.c | 4 +- modules/tm/uac.c | 22 ++++----- modules/tracer/tracer.c | 37 +++++++------- modules/uac_registrant/registrant.c | 16 +++---- net/api_proto.h | 2 +- net/net_tcp.c | 17 +++++-- net/net_tcp.h | 2 +- net/proto_tcp/proto_tcp.c | 9 ++-- net/proto_udp/proto_udp.c | 5 +- net/tcp_common.c | 12 +++-- net/tcp_common.h | 6 +-- net/tcp_conn_profile.c | 4 +- net/tcp_conn_profile.h | 2 +- resolve.h | 3 +- sl_cb.c | 4 +- sl_cb.h | 6 +-- 45 files changed, 262 insertions(+), 193 deletions(-) diff --git a/core_cmds.c b/core_cmds.c index 32b569f0d17..c214c6403f1 100644 --- a/core_cmds.c +++ b/core_cmds.c @@ -745,13 +745,13 @@ static int w_forward(struct sip_msg *msg, struct proxy_l *dest) static int w_send(struct sip_msg *msg, struct proxy_l *dest, str *headers) { int ret; - union sockaddr_union* to; + struct sockaddr_hu* to; struct proxy_l* p; int len; char* tmp; - to=(union sockaddr_union*) - pkg_malloc(sizeof(union sockaddr_union)); + to=(struct sockaddr_hu*) + pkg_malloc(sizeof(*to)); if (to==0){ LM_ERR("memory allocation failure\n"); return E_OUT_OF_MEM; @@ -760,7 +760,7 @@ static int w_send(struct sip_msg *msg, struct proxy_l *dest, str *headers) LM_ERR("failed to clone proxy, dropping packet\n"); return E_OUT_OF_MEM; } - ret=hostent2su(to, &p->host, p->addr_idx, + ret=hostent2hu(to, &p->host, p->addr_idx, (p->port)?p->port:SIP_PORT ); if (ret==0){ if (headers) { diff --git a/forward.c b/forward.c index 7a87d714c1e..e8d1308265f 100644 --- a/forward.c +++ b/forward.c @@ -90,7 +90,7 @@ * be very likely noticeably slower, but it can deal better with * multihomed hosts */ -struct socket_info* get_out_socket(union sockaddr_union* to, int proto) +struct socket_info* get_out_socket(const union sockaddr_union* to, int proto) { int temp_sock; socklen_t len; @@ -143,7 +143,7 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto) * \note if msg!=null and msg->force_send_socket, the force_send_socket will be used */ struct socket_info* get_send_socket(struct sip_msg *msg, - union sockaddr_union* to, int proto) + const union sockaddr_union* to, int proto) { struct socket_info* send_sock; @@ -306,7 +306,7 @@ static inline int set_sl_branch(struct sip_msg* msg) int forward_request( struct sip_msg* msg, struct proxy_l * p) { - union sockaddr_union to; + struct sockaddr_hu to; str buf; struct socket_info* send_sock; struct socket_info* last_sock; @@ -327,17 +327,17 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) msg_callback_process(msg, REQ_PRE_FORWARD, (void *)p); - hostent2su( &to, &p->host, p->addr_idx, (p->port)?p->port:SIP_PORT); + hostent2hu( &to, &p->host, p->addr_idx, (p->port)?p->port:SIP_PORT); last_sock = 0; if (getb0flags(msg) & tcp_no_new_conn_bflag) tcp_no_new_conn = 1; do { - send_sock=get_send_socket( msg, &to, p->proto); + send_sock=get_send_socket( msg, &to.su, p->proto); if (send_sock==0){ LM_ERR("cannot forward to af %d, proto %d no corresponding" - "listening socket\n", to.s.sa_family, p->proto); + "listening socket\n", to.su.s.sa_family, p->proto); ser_error=E_NO_SOCKET; continue; } @@ -358,7 +358,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) last_sock = send_sock; } - if (check_blacklists( p->proto, &to, buf.s, buf.len)) { + if (check_blacklists( p->proto, &to.su, buf.s, buf.len)) { LM_DBG("blocked by blacklists\n"); ser_error=E_IP_BLOCKED; continue; @@ -379,7 +379,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) ser_error = 0; break; - }while( get_next_su( p, &to, (ser_error==E_IP_BLOCKED)?0:1)==0 ); + }while( get_next_su( p, &to.su, (ser_error==E_IP_BLOCKED)?0:1)==0 ); tcp_no_new_conn = 0; @@ -402,7 +402,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) -int update_sock_struct_from_via( union sockaddr_union* to, +int update_sock_struct_from_via( struct sockaddr_hu* to, struct sip_msg* msg, struct via_body* via ) { @@ -458,7 +458,7 @@ int update_sock_struct_from_via( union sockaddr_union* to, return -1; } - hostent2su( to, he, 0, port); + hostent2hu( to, he, 0, port); return 1; } @@ -468,7 +468,7 @@ int update_sock_struct_from_via( union sockaddr_union* to, int forward_reply(struct sip_msg* msg) { char* new_buf; - union sockaddr_union* to; + struct sockaddr_hu *to; unsigned int new_len; struct sr_module *mod; int proto; @@ -517,7 +517,7 @@ int forward_reply(struct sip_msg* msg) goto error; } - to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union)); + to=(struct sockaddr_hu *)pkg_malloc(sizeof(*to)); if (to==0){ LM_ERR("out of pkg memory\n"); goto error; @@ -536,7 +536,7 @@ int forward_reply(struct sip_msg* msg) } } - send_sock = get_send_socket(msg, to, proto); + send_sock = get_send_socket(msg, &to->su, proto); new_buf = build_res_buf_from_sip_res( msg, &new_len, send_sock,0); if (!new_buf){ diff --git a/forward.h b/forward.h index 37005982989..bcc26e754b0 100644 --- a/forward.h +++ b/forward.h @@ -48,17 +48,18 @@ #include "socket_info.h" struct socket_info* get_send_socket(struct sip_msg* msg, - union sockaddr_union* su, int proto); -struct socket_info* get_out_socket(union sockaddr_union* to, int proto); + const union sockaddr_union* su, int proto); +struct socket_info* get_out_socket(const union sockaddr_union* to, int proto); int check_self(str* host, unsigned short port, unsigned short proto); int forward_request( struct sip_msg* msg, struct proxy_l* p); -int update_sock_struct_from_via( union sockaddr_union* to, +int update_sock_struct_from_via( struct sockaddr_hu* to, struct sip_msg* msg, struct via_body* via ); /*! \brief use src_ip, port=src_port if rport, via port if via port, 5060 otherwise */ #define update_sock_struct_from_ip( to, msg ) \ - init_su((to), &(msg)->rcv.src_ip, \ + *(to) = (struct sockaddr_hu){0}; \ + init_su(&((to)->su), &(msg)->rcv.src_ip, \ ((!msg->via1)||((msg)->via1->rport)||((msg)->msg_flags&FL_FORCE_RPORT))? \ (msg)->rcv.src_port: \ ((msg)->via1->port)?(msg)->via1->port: SIP_PORT ) @@ -82,12 +83,13 @@ int forward_reply( struct sip_msg* msg); * \return 0 if ok, -1 on error */ static inline int msg_send( struct socket_info* send_sock, int proto, - union sockaddr_union* to, unsigned int id, + const struct sockaddr_hu* to_hu, unsigned int id, char* buf, int len, struct sip_msg* msg) { str out_buff; unsigned short port; char *ip; + const union sockaddr_union *to = &to_hu->su; if (proto<=PROTO_NONE || proto>=PROTO_OTHER) { LM_BUG("bogus proto %s/%d received!\n",proto2a(proto),proto); @@ -120,7 +122,7 @@ static inline int msg_send( struct socket_info* send_sock, int proto, /* update the length for further processing */ len = out_buff.len; - if (protos[proto].tran.send(send_sock, out_buff.s, out_buff.len, to,id)<0){ + if (protos[proto].tran.send(send_sock, out_buff.s, out_buff.len, to_hu,id)<0){ get_su_info(to, ip, port); LM_ERR("send() to %s:%hu for proto %s/%d failed\n", ip, port, proto2a(proto),proto); diff --git a/ip_addr.h b/ip_addr.h index 838e4c26e91..0d2684a6c6a 100644 --- a/ip_addr.h +++ b/ip_addr.h @@ -45,6 +45,8 @@ #include "dprint.h" +#define MAX_DNS_NAME 256 + #define MAX_RECV_BUFFER_SIZE 256*1024 #define MAX_SEND_BUFFER_SIZE 512*1024 #define BUFFER_INCREMENT 2048 @@ -80,22 +82,21 @@ struct net{ struct ip_addr mask; }; -union sockaddr_union_no_hostname{ - struct sockaddr s; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; -}; + union sockaddr_union{ struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; - struct { - union sockaddr_union_no_hostname _padding; - char hostname[256]; - } h; }; - +struct sockaddr_hu{ + union sockaddr_union su; + const str_const *hp; + struct { + str_const hoststr; + char hostname[MAX_DNS_NAME]; + } _; +}; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANYCAST=8, SI_FRAG=16, SI_REUSEPORT=32 }; @@ -117,7 +118,7 @@ struct receive_info { struct dest_info { int proto; unsigned int proto_reserved1; /*!< tcp stores the connection id here */ - union sockaddr_union to; + struct sockaddr_hu to; struct socket_info* send_sock; }; @@ -221,7 +222,7 @@ inline static int matchnet(struct ip_addr* ip, struct net* net) /*! \brief inits an ip_addr pointer from a sockaddr structure*/ -static inline void sockaddr2ip_addr(struct ip_addr* ip, struct sockaddr* sa) +static inline void sockaddr2ip_addr(struct ip_addr* ip, const struct sockaddr* sa) { void *copyfrom; @@ -275,7 +276,7 @@ static inline int su_cmp(union sockaddr_union* s1, union sockaddr_union* s2) /*! \brief gets the port number (host byte order) */ -static inline unsigned short su_getport(union sockaddr_union* su) +static inline unsigned short su_getport(const union sockaddr_union* su) { if(su==0) return 0; @@ -307,7 +308,7 @@ static inline void su_setport(union sockaddr_union* su, unsigned short port) } /*! \brief inits an ip_addr pointer from a sockaddr_union ip address */ -static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su) +static inline void su2ip_addr(struct ip_addr* ip, const union sockaddr_union* su) { switch(su->s.sa_family){ case AF_INET: @@ -368,17 +369,13 @@ static inline int init_su( union sockaddr_union* su, * the hostent structure and a port no. (host byte order) * WARNING: no index overflow checks! * \return 0 if ok, -1 on error (unknown address family) */ -static inline int hostent2su( union sockaddr_union* su, - struct hostent* he, +static inline int hostent2su( union sockaddr_union *su, + const struct hostent* he, unsigned int idx, unsigned short port ) { memset(su, 0, sizeof(union sockaddr_union)); /*needed on freebsd*/ - /* copy the hostname into the sockaddr_union */ - strncpy(su->h.hostname, he->h_name, sizeof(su->h.hostname)-1); - su->h.hostname[sizeof(su->h.hostname)-1] = 0; - su->s.sa_family=he->h_addrtype; switch(he->h_addrtype){ case AF_INET6: @@ -402,6 +399,38 @@ static inline int hostent2su( union sockaddr_union* su, return 0; } +static inline int hostent2hu( struct sockaddr_hu *hu, + struct hostent* he, + unsigned int idx, + unsigned short port ) +{ + union sockaddr_union* su = &hu->su; + size_t nlen = strlen(he->h_name); + + if (nlen >= sizeof(hu->_.hostname)) { + LM_CRIT("Hostname is too long: \"%s\"", he->h_name); + return -1; + } + + int r = hostent2su(su, he, idx, port); + + if (r == 0) { + memcpy(hu->_.hostname, he->h_name, nlen); + hu->_.hostname[nlen] = 0; + hu->_.hoststr.s = hu->_.hostname; + hu->_.hoststr.len = nlen; + hu->hp = &hu->_.hoststr; + } + return 0; +} + +static inline void hu_dup(const struct sockaddr_hu *hu_s, struct sockaddr_hu *hu_d) +{ + memcpy(hu_d, hu_s, sizeof(*hu_d)); + hu_d->_.hoststr.s = hu_d->_.hostname; + hu_d->hp = &hu_d->_.hoststr; +} + /*! \brief maximum size of a str returned by ip_addr2a (including \\0') */ #define IP_ADDR_MAX_STR_SIZE 40 /* 1234:5678:9012:3456:7890:1234:5678:9012\0 */ #define IP_ADDR2STR_BUF_NO 4 diff --git a/modules/clusterer/clusterer.c b/modules/clusterer/clusterer.c index 93636e22e94..3ff5f36d6e7 100644 --- a/modules/clusterer/clusterer.c +++ b/modules/clusterer/clusterer.c @@ -322,8 +322,9 @@ static int msg_send_retry(bin_packet_t *packet, node_info_t *dest, } bin_get_buffer(packet, &send_buffer); + struct sockaddr_hu to = {.su = chosen_dest->addr}; if (msg_send(chosen_dest->cluster->send_sock, chosen_dest->proto, - &chosen_dest->addr, 0, send_buffer.s, send_buffer.len, 0) < 0) { + &to, 0, send_buffer.s, send_buffer.len, 0) < 0) { LM_ERR("msg_send() to node [%d] failed\n", chosen_dest->node_id); retr_send = 1; @@ -1474,15 +1475,17 @@ int send_single_cap_update(cluster_info_t *cluster, struct local_cap *cap, bin_push_int(&packet, current_id); bin_get_buffer(&packet, &bin_buffer); - for (i = 0; i < no_dests; i++) + for (i = 0; i < no_dests; i++) { + struct sockaddr_hu to = {.su = destinations[i]->addr}; if (msg_send(cluster->send_sock, destinations[i]->proto, - &destinations[i]->addr, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { + &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { LM_ERR("Failed to send capability update to node [%d]\n", destinations[i]->node_id); set_link_w_neigh_adv(-1, LS_RESTART_PINGING, destinations[i]); } else LM_DBG("Sent capability update to node [%d]\n", destinations[i]->node_id); + } bin_free_packet(&packet); @@ -1567,8 +1570,8 @@ int send_cap_update(node_info_t *dest_node, int require_reply) bin_push_int(&packet, 1); /* path length is 1, only current node at this point */ bin_push_int(&packet, current_id); bin_get_buffer(&packet, &bin_buffer); - - if (msg_send(dest_node->cluster->send_sock, dest_node->proto, &dest_node->addr, + struct sockaddr_hu to = {.su = dest_node->addr}; + if (msg_send(dest_node->cluster->send_sock, dest_node->proto, &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { LM_ERR("Failed to send capability update to node [%d]\n", dest_node->node_id); set_link_w_neigh_adv(-1, LS_RESTART_PINGING, dest_node); @@ -1851,4 +1854,4 @@ unsigned long clusterer_get_num_nodes(int state) lock_stop_read(cl_list_lock); return nodecount; -} \ No newline at end of file +} diff --git a/modules/clusterer/topology.c b/modules/clusterer/topology.c index e5fe1e94d44..0eada0af801 100644 --- a/modules/clusterer/topology.c +++ b/modules/clusterer/topology.c @@ -57,7 +57,8 @@ static int send_ping(node_info_t *node, int req_node_list) set_proc_log_level(L_INFO); #endif - rc = msg_send(node->cluster->send_sock, node->proto, &node->addr, 0, + struct sockaddr_hu to = {.su = node->addr}; + rc = msg_send(node->cluster->send_sock, node->proto, &to, 0, send_buffer.s, send_buffer.len, 0); #ifndef CLUSTERER_EXTRA_BIN_DBG @@ -487,8 +488,9 @@ int flood_message(bin_packet_t *packet, cluster_info_t *cluster, lock_release(cluster->current_node->lock); for (i = 0; i < no_dests; i++) { + struct sockaddr_hu to = {.su = destinations[i]->addr}; if (msg_send(cluster->send_sock, destinations[i]->proto, - &destinations[i]->addr, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { + &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { LM_ERR("Failed to flood message to node [%d]\n", destinations[i]->node_id); @@ -601,7 +603,8 @@ static int send_full_top_update(node_info_t *dest_node, int nr_nodes, int *node_ bin_push_int(&packet, current_id); bin_get_buffer(&packet, &bin_buffer); - if (msg_send(dest_node->cluster->send_sock, dest_node->proto, &dest_node->addr, + struct sockaddr_hu to = {.su = dest_node->addr}; + if (msg_send(dest_node->cluster->send_sock, dest_node->proto, &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { LM_ERR("Failed to send topology update to node [%d]\n", dest_node->node_id); set_link_w_neigh_adv(-1, LS_RESTART_PINGING, dest_node); @@ -662,8 +665,9 @@ static int send_ls_update(node_info_t *node, clusterer_link_state new_ls) bin_get_buffer(&packet, &send_buffer); for (i = 0; i < no_dests; i++) { + struct sockaddr_hu to = {.su = destinations[i]->addr}; if (msg_send(destinations[i]->cluster->send_sock, destinations[i]->proto, - &destinations[i]->addr, 0, send_buffer.s, send_buffer.len, 0) < 0) { + &to, 0, send_buffer.s, send_buffer.len, 0) < 0) { LM_ERR("Failed to send link state update to node [%d]\n", destinations[i]->node_id); /* this node was supposed to be up, restart pinging */ @@ -1144,7 +1148,8 @@ void handle_internal_msg_unknown(bin_packet_t *received, cluster_info_t *cl, bin_push_int(&packet, current_id); bin_get_buffer(&packet, &bin_buffer); - if (msg_send(cl->send_sock, proto, src_su, 0, bin_buffer.s, + struct sockaddr_hu to = {.su = *src_su}; + if (msg_send(cl->send_sock, proto, &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) LM_ERR("Failed to reply to ping from unknown node, id [%d]\n", src_node_id); else @@ -1247,7 +1252,8 @@ void handle_unknown_id(node_info_t *src_node) bin_push_int(&packet, current_id); bin_get_buffer(&packet, &bin_buffer); - if (msg_send(src_node->cluster->send_sock, src_node->proto, &src_node->addr, + struct sockaddr_hu to = {.su = src_node->addr}; + if (msg_send(src_node->cluster->send_sock, src_node->proto, &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) LM_ERR("Failed to send node description to node [%d]\n", src_node->node_id); else @@ -1294,8 +1300,9 @@ void handle_ping(bin_packet_t *received, node_info_t *src_node, set_proc_log_level(L_INFO); #endif + struct sockaddr_hu to = {.su = src_node->addr}; send_rc = msg_send(src_node->cluster->send_sock, src_node->proto, - &src_node->addr, 0, bin_buffer.s, bin_buffer.len, 0); + &to, 0, bin_buffer.s, bin_buffer.len, 0); #ifndef CLUSTERER_EXTRA_BIN_DBG reset_proc_log_level(); diff --git a/modules/nat_traversal/nat_traversal.c b/modules/nat_traversal/nat_traversal.c index 6ee94a7de87..0ced5a45f43 100644 --- a/modules/nat_traversal/nat_traversal.c +++ b/modules/nat_traversal/nat_traversal.c @@ -1189,7 +1189,7 @@ __dialog_destroy(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params) // static void __sl_reply_out(struct sip_msg* request, str *buffer, int rpl_code, - union sockaddr_union *dst, struct socket_info *sock, int proto) + const struct sockaddr_hu *dst, struct socket_info *sock, int proto) { struct sip_msg reply; time_t expire; diff --git a/modules/nathelper/nathelper.c b/modules/nathelper/nathelper.c index d41ad2e23b1..50ee207ef96 100644 --- a/modules/nathelper/nathelper.c +++ b/modules/nathelper/nathelper.c @@ -1423,7 +1423,8 @@ nh_timer(unsigned int ticks, void *timer_idx) if ((flags & sipping_flag) && (opt.s = build_sipping(d, &c, send_sock, &path, &opt.len, ct_coords, flags))) { - if (msg_send(send_sock, next_hop.proto, &to, 0, opt.s, opt.len, NULL) < 0) { + struct sockaddr_hu to_hu = {.su = to}; + if (msg_send(send_sock, next_hop.proto, &to_hu, 0, opt.s, opt.len, NULL) < 0) { LM_ERR("sip msg_send failed\n"); } } else if (raw_ip && next_hop.proto == PROTO_UDP) { @@ -1431,7 +1432,8 @@ nh_timer(unsigned int ticks, void *timer_idx) LM_ERR("send_raw failed\n"); } } else { - if (msg_send(send_sock, next_hop.proto, &to, 0, + struct sockaddr_hu to_hu = {.su = to}; + if (msg_send(send_sock, next_hop.proto, &to_hu, 0, (char *)sbuf, sizeof(sbuf), NULL) < 0) { LM_ERR("sip msg_send failed!\n"); } diff --git a/modules/proto_bin/proto_bin.c b/modules/proto_bin/proto_bin.c index 312696f4421..5d2cd3c5630 100644 --- a/modules/proto_bin/proto_bin.c +++ b/modules/proto_bin/proto_bin.c @@ -47,7 +47,7 @@ static int mod_init(void); static int proto_bin_init(struct proto_info *pi); static int proto_bin_init_listener(struct socket_info *si); static int proto_bin_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int bin_read_req(struct tcp_connection* con, int* bytes_read); @@ -142,13 +142,14 @@ static int proto_bin_init_listener(struct socket_info *si) } static int proto_bin_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu *to_hu, unsigned int id) { struct tcp_connection *c; struct ip_addr ip; int port; int fd, n; + const union sockaddr_union *to = to_hu ? &to_hu->su : NULL; port=0; @@ -184,7 +185,7 @@ static int proto_bin_send(struct socket_info* send_sock, LM_DBG("no open tcp connection found, opening new one, async = %d\n",bin_async); /* create tcp connection */ if (bin_async) { - n = tcp_async_connect(send_sock, to, &prof, + n = tcp_async_connect(send_sock, to_hu, &prof, bin_async_local_connect_timeout, &c, &fd, 1); if ( n<0 ) { LM_ERR("async TCP connect failed\n"); @@ -211,7 +212,7 @@ static int proto_bin_send(struct socket_info* send_sock, return len; } /* our first connect attempt succeeded - go ahead as normal */ - } else if ((c=tcp_sync_connect(send_sock, to, &prof, &fd, 1))==0) { + } else if ((c=tcp_sync_connect(send_sock, to_hu, &prof, &fd, 1))==0) { LM_ERR("connect failed\n"); return -1; } diff --git a/modules/proto_bins/proto_bins.c b/modules/proto_bins/proto_bins.c index a823cc497f2..45c8753a214 100644 --- a/modules/proto_bins/proto_bins.c +++ b/modules/proto_bins/proto_bins.c @@ -46,7 +46,7 @@ static int mod_init(void); static int proto_bins_init(struct proto_info *pi); static int proto_bins_init_listener(struct socket_info *si); static int proto_bins_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int bins_read_req(struct tcp_connection* con, int* bytes_read); static int bins_async_write(struct tcp_connection* con,int fd); @@ -337,7 +337,7 @@ static int bins_write_on_socket(struct tcp_connection* c, int fd, } static int proto_bins_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to_hu, unsigned int id) { struct tcp_connection *c; @@ -345,6 +345,7 @@ static int proto_bins_send(struct socket_info* send_sock, int port; int fd, n; int send2main = 0; + const union sockaddr_union *to = to_hu ? &to_hu->su : NULL; port=0; @@ -381,7 +382,7 @@ static int proto_bins_send(struct socket_info* send_sock, bins_async); /* create tcp connection */ if (bins_async) { - n = tcp_async_connect(send_sock, to, &prof, + n = tcp_async_connect(send_sock, to_hu, &prof, bins_async_local_connect_timeout, &c, &fd, 1); if ( n<0 ) { LM_ERR("async TCP connect failed\n"); @@ -438,7 +439,7 @@ static int proto_bins_send(struct socket_info* send_sock, LM_DBG("First TLS handshake attempt succeeded in less than %dms, " "proceed to writing \n",bins_async_handshake_connect_timeout); } else { - if ((c=tcp_sync_connect(send_sock, to, &prof, &fd, 0))==0) { + if ((c=tcp_sync_connect(send_sock, to_hu, &prof, &fd, 0))==0) { LM_ERR("connect failed\n"); return -1; } diff --git a/modules/proto_hep/hep.c b/modules/proto_hep/hep.c index f286c00f37b..64cc81f7fc1 100644 --- a/modules/proto_hep/hep.c +++ b/modules/proto_hep/hep.c @@ -1684,7 +1684,7 @@ int send_hep_message(trace_message message, trace_dest dest, struct socket_info* char* buf=0; struct proxy_l* p; - union sockaddr_union* to; + struct sockaddr_hu* to; hid_list_p hep_dest = (hid_list_p) dest; @@ -1715,7 +1715,7 @@ int send_hep_message(trace_message message, trace_dest dest, struct socket_info* goto end; } - to=(union sockaddr_union *)pkg_malloc(sizeof(union sockaddr_union)); + to=(struct sockaddr_hu *)pkg_malloc(sizeof(*to)); if (to == 0) { LM_ERR("no more pkg mem!\n"); pkg_free(buf); @@ -1724,7 +1724,7 @@ int send_hep_message(trace_message message, trace_dest dest, struct socket_info* goto end; } - hostent2su(to, &p->host, p->addr_idx, p->port?p->port:HEP_PORT); + hostent2hu(to, &p->host, p->addr_idx, p->port?p->port:HEP_PORT); do { if (msg_send(send_sock, hep_dest->transport, to, 0, buf, len, NULL) < 0) { @@ -1733,7 +1733,7 @@ int send_hep_message(trace_message message, trace_dest dest, struct socket_info* } ret=0; break; - } while ( get_next_su( p, to, 0)==0); + } while ( get_next_su( p, &to->su, 0)==0); free_proxy(p); pkg_free(p); diff --git a/modules/proto_hep/proto_hep.c b/modules/proto_hep/proto_hep.c index eed77381faf..c7827aa5a3b 100644 --- a/modules/proto_hep/proto_hep.c +++ b/modules/proto_hep/proto_hep.c @@ -61,16 +61,16 @@ static int hep_tcp_or_tls_read_req(struct tcp_connection* con, int* bytes_read, unsigned int is_tls); static int hep_udp_read_req(struct socket_info* si, int* bytes_read); static int hep_udp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int hep_tcp_or_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id, unsigned int is_tls); static int hep_tcp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int hep_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static void update_recv_info(struct receive_info* ri, struct hep_desc* h); void free_hep_context(void* ptr); @@ -345,10 +345,11 @@ static int proto_hep_init_udp_listener(struct socket_info* si) } static int hep_udp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to_hu, unsigned int id) { int n, tolen; + const union sockaddr_union *to = &to_hu->su; tolen = sockaddru_len(*to); again: @@ -367,27 +368,28 @@ static int hep_udp_send(struct socket_info* send_sock, } static int hep_tcp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id) { return hep_tcp_or_tls_send(send_sock, buf, len, to, id, 0); } static int hep_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id) { return hep_tcp_or_tls_send(send_sock, buf, len, to, id, 1); } static int hep_tcp_or_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to_hu, unsigned int id, unsigned int is_tls) { struct tcp_connection* c; int port = 0; struct ip_addr ip; int fd, n; + const union sockaddr_union* to = to_hu ? &to_hu->su : NULL; if (to) { su2ip_addr(&ip, to); @@ -421,7 +423,7 @@ static int hep_tcp_or_tls_send(struct socket_info* send_sock, LM_DBG("no open tcp connection found, opening new one, async = %d\n", hep_async); /* create tcp connection */ if (hep_async) { - n = tcp_async_connect(send_sock, to, &prof, + n = tcp_async_connect(send_sock, to_hu, &prof, hep_async_local_connect_timeout, &c, &fd, 1); if (n < 0) { LM_ERR("async TCP connect failed\n"); @@ -479,7 +481,7 @@ static int hep_tcp_or_tls_send(struct socket_info* send_sock, LM_DBG("first TLS handshake attempt succeeded in less than %dms, " "proceed to writing \n", hep_tls_async_handshake_connect_timeout); } - } else if ((c = tcp_sync_connect(send_sock, to, &prof, &fd, 1)) == 0) { + } else if ((c = tcp_sync_connect(send_sock, to_hu, &prof, &fd, 1)) == 0) { LM_ERR("connect failed\n"); return -1; } diff --git a/modules/proto_msrp/msrp_common.c b/modules/proto_msrp/msrp_common.c index d0cd4626433..10a51b659f8 100644 --- a/modules/proto_msrp/msrp_common.c +++ b/modules/proto_msrp/msrp_common.c @@ -30,6 +30,7 @@ #include "../../ut.h" #include "../../net/trans_trace.h" #include "../../net/tcp_common.h" +#include "../../timer.h" #include "msrp_handler.h" #include "msrp_plain.h" #include "msrp_common.h" @@ -557,7 +558,7 @@ int msrp_read_req(struct tcp_connection* con, int* bytes_read) /*! \brief Finds a tcpconn & sends on it */ int proto_msrp_send(struct socket_info* send_sock, char* buf, unsigned int len, - union sockaddr_union* to, unsigned int id) + const struct sockaddr_hu* to_hu, unsigned int id) { struct tcp_connection *c; struct tcp_conn_profile prof; @@ -566,6 +567,7 @@ int proto_msrp_send(struct socket_info* send_sock, union sockaddr_union src_su, dst_su; int port = 0, fd, n, matched; struct tls_domain *dom; + const union sockaddr_union *to = to_hu ? &to_hu->su : NULL; matched = tcp_con_get_profile(to, &send_sock->su, send_sock->proto, &prof); @@ -606,7 +608,7 @@ int proto_msrp_send(struct socket_info* send_sock, } LM_DBG("no open tcp connection found, opening new one\n"); /* create tcp connection */ - if ((c=tcp_sync_connect(send_sock, to, &prof, &fd, 1))==0) { + if ((c=tcp_sync_connect(send_sock, to_hu, &prof, &fd, 1))==0) { LM_ERR("connect failed\n"); get_time_difference(get,prof.send_threshold,tcp_timeout_con_get); return -1; diff --git a/modules/proto_msrp/msrp_common.h b/modules/proto_msrp/msrp_common.h index db33a9625b4..658f8f64173 100644 --- a/modules/proto_msrp/msrp_common.h +++ b/modules/proto_msrp/msrp_common.h @@ -86,7 +86,7 @@ void msrp_brief_parse_msg(struct msrp_req *r); int proto_msrp_send(struct socket_info* send_sock, char* buf, unsigned int len, - union sockaddr_union* to, unsigned int id); + const struct sockaddr_hu* to, unsigned int id); int msrp_read_req(struct tcp_connection* con, int* bytes_read); diff --git a/modules/proto_msrp/msrp_signaling.c b/modules/proto_msrp/msrp_signaling.c index 901fb25ab96..4a90db5d4ff 100644 --- a/modules/proto_msrp/msrp_signaling.c +++ b/modules/proto_msrp/msrp_signaling.c @@ -190,8 +190,9 @@ int msrp_send_reply( void *hdl, struct msrp_msg *req, int code, str* reason, } /* now, send it out*/ + struct sockaddr_hu to = {.su = req->rcv.src_su}; i = msg_send( req->rcv.bind_address, PROTO_MSRP, - &req->rcv.src_su, req->rcv.proto_reserved1, + &to, req->rcv.proto_reserved1, buf, len, NULL); if (i<0) { /* sending failed, FIXME - close the connection */ @@ -424,7 +425,8 @@ int msrp_fwd_request( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no, } /* now, send it out*/ - i = msg_send( sock, sock->proto, to_su , 0 /*conn-id*/, buf, len, NULL); + struct sockaddr_hu to_hu = {.su = *to_su}; + i = msg_send( sock, sock->proto, &to_hu , 0 /*conn-id*/, buf, len, NULL); if (i<0) { /* sending failed, TODO - close the connection */ LM_ERR("failed to fwd MSRP request\n"); @@ -789,8 +791,9 @@ int msrp_send_report(void *hdl, str *status, &cell->recv.to, cell->recv.proto_reserved1, buf, len, NULL); } else { + struct sockaddr_hu to = {.su = req->rcv.src_su}; i = msg_send( req->rcv.bind_address, PROTO_MSRP, - &req->rcv.src_su, req->rcv.proto_reserved1, + &to, req->rcv.proto_reserved1, buf, len, NULL); } if (i<0) { @@ -1054,7 +1057,8 @@ int msrp_send_request(void *hdl, enum msrp_method method_id, } /* now, send it out*/ - i = msg_send( sock, sock->proto, to_su, 0 /*conn-id*/, buf, len, NULL); + struct sockaddr_hu to_hu = {.su = *to_su}; + i = msg_send( sock, sock->proto, &to_hu, 0 /*conn-id*/, buf, len, NULL); if (i<0) { /* sending failed, TODO - close the connection */ LM_ERR("failed to fwd MSRP request\n"); @@ -1280,7 +1284,8 @@ static struct msrp_cell* _build_transaction(struct msrp_msg *req, int hash, req->failure_report->body.len); } - init_su( &cell->recv.to, &req->rcv.src_ip, req->rcv.src_port); + cell->recv.to = (struct sockaddr_hu){0}; + init_su( &cell->recv.to.su, &req->rcv.src_ip, req->rcv.src_port); cell->recv.proto = req->rcv.proto; cell->recv.proto_reserved1 = req->rcv.proto_reserved1; cell->recv.send_sock = req->rcv.bind_address; diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index e48f4d56be7..0696f44d362 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -190,20 +190,20 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) /*! \brief which socket to use? main socket or new one? */ int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, - union sockaddr_union* to, unsigned int id) + const struct sockaddr_hu *to, unsigned int id) { int n; int tolen; - tolen=sockaddru_len(*to); + tolen=sockaddru_len(to->su); again: - n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, 0, 0, 0, 0); + n=sctp_sendmsg(source->socket, buf, len, &to->su.s, tolen, 0, 0, 0, 0, 0); #ifdef XL_DEBUG LM_INFO("send status: %d\n", n); #endif if (n==-1){ LM_ERR("sctp_sendmsg(sock,%p,%d,%p,%d,0,0,0,0,0): %s(%d)\n", - buf,len,&to->s,tolen, strerror(errno),errno); + buf,len,&to->su.s,tolen, strerror(errno),errno); if (errno==EINTR) goto again; if (errno==EINVAL) { diff --git a/modules/proto_sctp/sctp_server.h b/modules/proto_sctp/sctp_server.h index 57700703f4f..edc0e831620 100644 --- a/modules/proto_sctp/sctp_server.h +++ b/modules/proto_sctp/sctp_server.h @@ -37,7 +37,7 @@ int proto_sctp_init_listener(struct socket_info* si); int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, - union sockaddr_union* to, unsigned int id); + const struct sockaddr_hu* to, unsigned int id); int proto_sctp_read(struct socket_info *si, int* bytes_read); diff --git a/modules/proto_smpp/proto_smpp.c b/modules/proto_smpp/proto_smpp.c index a43776f91c0..b7a3fe37ffb 100644 --- a/modules/proto_smpp/proto_smpp.c +++ b/modules/proto_smpp/proto_smpp.c @@ -60,7 +60,7 @@ static int child_init(int rank); static int smpp_init(struct proto_info *pi); static int smpp_init_listener(struct socket_info *si); static int smpp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int smpp_read_req(struct tcp_connection* conn, int* bytes_read); static int smpp_write_async_req(struct tcp_connection* con,int fd); @@ -230,7 +230,7 @@ static int smpp_init_listener(struct socket_info *si) } static int smpp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id) { LM_INFO("smpp_send called\n"); diff --git a/modules/proto_smpp/smpp.c b/modules/proto_smpp/smpp.c index afb86fbf4fe..aa4fdfe7223 100644 --- a/modules/proto_smpp/smpp.c +++ b/modules/proto_smpp/smpp.c @@ -791,7 +791,7 @@ int send_outbind(smpp_session_t *session) static struct tcp_connection *smpp_connect(smpp_session_t *session, int *fd) { union sockaddr_union to; - union sockaddr_union server; + struct sockaddr_hu server = {0}; struct socket_info *send_socket; struct tcp_conn_profile prof; @@ -799,7 +799,7 @@ static struct tcp_connection *smpp_connect(smpp_session_t *session, int *fd) LM_ERR("error creating su from ipaddr and port\n"); return NULL; } - if (init_su(&server, &session->ip, session->port)) { + if (init_su(&server.su, &session->ip, session->port)) { LM_ERR("error creating su from ipaddr and port\n"); return NULL; } @@ -809,7 +809,7 @@ static struct tcp_connection *smpp_connect(smpp_session_t *session, int *fd) return NULL; } - tcp_con_get_profile(&server, &send_socket->su, PROTO_SMPP, &prof); + tcp_con_get_profile(&server.su, &send_socket->su, PROTO_SMPP, &prof); return tcp_sync_connect(send_socket, &server, &prof, fd, 1); } diff --git a/modules/proto_ws/proto_ws.c b/modules/proto_ws/proto_ws.c index ee73bbfc16d..bfa63c45490 100644 --- a/modules/proto_ws/proto_ws.c +++ b/modules/proto_ws/proto_ws.c @@ -95,7 +95,7 @@ static int mod_init(void); static int proto_ws_init(struct proto_info *pi); static int proto_ws_init_listener(struct socket_info *si); static int proto_ws_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int ws_read_req(struct tcp_connection* con, int* bytes_read); static int ws_conn_init(struct tcp_connection* c); @@ -328,7 +328,7 @@ static void ws_report(int type, unsigned long long conn_id, int conn_flags, /*! \brief Finds a tcpconn & sends on it */ static int proto_ws_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to_hu, unsigned int id) { struct tcp_connection *c; @@ -337,6 +337,7 @@ static int proto_ws_send(struct socket_info* send_sock, struct ip_addr ip; struct ws_data* d; int port = 0, fd, n, matched; + const union sockaddr_union *to = to_hu ? &to_hu->su : NULL; matched = tcp_con_get_profile(to, &send_sock->su, send_sock->proto, &prof); @@ -373,7 +374,7 @@ static int proto_ws_send(struct socket_info* send_sock, } LM_DBG("no open tcp connection found, opening new one\n"); /* create tcp connection */ - if ((c=ws_connect(send_sock, to, &prof, &fd))==0) { + if ((c=ws_connect(send_sock, to_hu, &prof, &fd))==0) { LM_ERR("connect failed\n"); return -1; } diff --git a/modules/proto_ws/ws_common.h b/modules/proto_ws/ws_common.h index 201e0ccb7e8..78e155c3ebb 100644 --- a/modules/proto_ws/ws_common.h +++ b/modules/proto_ws/ws_common.h @@ -636,12 +636,13 @@ static void ws_close(struct tcp_connection *c) } static struct tcp_connection* ws_sync_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof) + const struct sockaddr_hu* server_hu, struct tcp_conn_profile *prof) { int s; union sockaddr_union my_name; socklen_t my_name_len; struct tcp_connection* con; + const union sockaddr_union *server = &server_hu->su; s=socket(AF2PF(server->s.sa_family), SOCK_STREAM, 0); if (s==-1){ @@ -667,7 +668,7 @@ static struct tcp_connection* ws_sync_connect(struct socket_info* send_sock, LM_ERR("tcp_blocking_connect failed\n"); goto error; } - con=tcp_conn_create(s, server, send_sock, prof, S_CONN_OK, 0); + con=tcp_conn_create(s, server_hu, send_sock, prof, S_CONN_OK, 0); if (con==NULL){ LM_ERR("tcp_conn_create failed, closing the socket\n"); goto error; @@ -684,7 +685,7 @@ static struct tcp_connection* ws_sync_connect(struct socket_info* send_sock, static struct tcp_connection* ws_connect(struct socket_info* send_sock, - union sockaddr_union* to, struct tcp_conn_profile *prof, int *fd) + const struct sockaddr_hu* to, struct tcp_conn_profile *prof, int *fd) { struct tcp_connection *c; diff --git a/modules/rtpproxy/rtpproxy.c b/modules/rtpproxy/rtpproxy.c index 371a345a4d6..ecea761dd01 100644 --- a/modules/rtpproxy/rtpproxy.c +++ b/modules/rtpproxy/rtpproxy.c @@ -3287,7 +3287,7 @@ force_rtpproxy_body_part(struct sip_msg *msg, struct rtpp_args *args, { int ret = 0; struct rtpp_args *ap; - union sockaddr_union to; + struct sockaddr_hu to; struct ip_addr ip; struct cell *trans; @@ -3349,7 +3349,7 @@ force_rtpproxy_body_part(struct sip_msg *msg, struct rtpp_args *args, } else if (parse_headers(msg, HDR_VIA2_F, 0) != -1 && (msg->via2 != NULL) && (msg->via2->error == PARSE_OK) && update_sock_struct_from_via(&to, msg, msg->via2)!=-1) { - su2ip_addr(&ip, &to); + su2ip_addr(&ip, &to.su); args->raddr.s = ip_addr2a(&ip); args->raddr.len = strlen(args->raddr.s); } else { diff --git a/modules/sipcapture/sipcapture.c b/modules/sipcapture/sipcapture.c index a07f26e7a6f..029f6e5f786 100644 --- a/modules/sipcapture/sipcapture.c +++ b/modules/sipcapture/sipcapture.c @@ -4252,7 +4252,7 @@ static int w_hep_relay(struct sip_msg *msg) struct socket_info* send_sock; - union sockaddr_union to; + struct sockaddr_hu to; str* uri_s; str buf_s; @@ -4316,14 +4316,14 @@ static int w_hep_relay(struct sip_msg *msg) return 0; } - hostent2su( &to, &proxy->host, proxy->addr_idx, + hostent2hu( &to, &proxy->host, proxy->addr_idx, (proxy->port)?proxy->port:SIP_PORT); /* FIXME */ - send_sock=get_send_socket(0, &to, hep_proto); + send_sock=get_send_socket(0, &to.su, hep_proto); if (send_sock==0){ LM_ERR("cannot forward to af %d, proto %d no corresponding" - "listening socket\n", to.s.sa_family, proxy->proto); + "listening socket\n", to.su.s.sa_family, proxy->proto); return -1; } @@ -4334,7 +4334,7 @@ static int w_hep_relay(struct sip_msg *msg) } break; - } while( get_next_su( proxy, &to, 0)==0 ); + } while( get_next_su( proxy, &to.su, 0)==0 ); free_proxy(proxy); pkg_free(proxy); diff --git a/modules/sl/sl_funcs.c b/modules/sl/sl_funcs.c index 0b482811790..1a786c63417 100644 --- a/modules/sl/sl_funcs.c +++ b/modules/sl/sl_funcs.c @@ -144,7 +144,7 @@ static inline void update_sl_reply_stat(int code) int sl_send_reply_helper(struct sip_msg *msg ,int code, const str *text) { str buf; - union sockaddr_union to; + struct sockaddr_hu to; char *dset; int dset_len; struct bookmark dummy_bm; diff --git a/modules/tcp_mgm/tcp_path.c b/modules/tcp_mgm/tcp_path.c index 721be6b623a..712951ab77b 100644 --- a/modules/tcp_mgm/tcp_path.c +++ b/modules/tcp_mgm/tcp_path.c @@ -52,7 +52,7 @@ int tcp_path_init(void) } -int tcp_mgm_get_profile(union sockaddr_union *remote, +int tcp_mgm_get_profile(const union sockaddr_union *remote, union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile) { diff --git a/modules/tcp_mgm/tcp_path.h b/modules/tcp_mgm/tcp_path.h index ce3e215c636..ba035539aa6 100644 --- a/modules/tcp_mgm/tcp_path.h +++ b/modules/tcp_mgm/tcp_path.h @@ -54,7 +54,7 @@ void tcp_path_destroy(void); int tcp_store_path(int *int_vals, char **str_vals, struct tcp_path *path); -int tcp_mgm_get_profile(union sockaddr_union *remote, +int tcp_mgm_get_profile(const union sockaddr_union *remote, union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile); diff --git a/modules/tm/dlg.h b/modules/tm/dlg.h index 71d0531a5fd..ce35d86287a 100644 --- a/modules/tm/dlg.h +++ b/modules/tm/dlg.h @@ -97,7 +97,7 @@ typedef struct dlg { str loc_uri; /* Local URI */ str rem_uri; /* Remote URI */ str obp; /* Outbound proxy */ - union sockaddr_union forced_to_su; /* Forced remote sockaddr */ + struct sockaddr_hu forced_to_hu; /* Forced remote sockaddr */ str rem_target; /* Remote target URI */ str loc_dname; /* Local Display Name */ str rem_dname; /* Remote Display Name */ diff --git a/modules/tm/t_funcs.c b/modules/tm/t_funcs.c index 385f1848391..bc3b180311e 100644 --- a/modules/tm/t_funcs.c +++ b/modules/tm/t_funcs.c @@ -64,10 +64,10 @@ int send_pr_buffer( struct retr_buf *rb, void *buf, int len, #endif void* ctx) { - if (buf && len && rb ) + if (buf && len && rb ) { return msg_send( rb->dst.send_sock, rb->dst.proto, &rb->dst.to, rb->dst.proto_reserved1, buf, len, ctx); - else { + } else { #ifdef EXTRA_DEBUG LM_CRIT("sending an empty buffer from %s: %s (%d)\n",file, function, line); diff --git a/modules/tm/t_fwd.c b/modules/tm/t_fwd.c index 6d9029a7d68..81ef1456826 100644 --- a/modules/tm/t_fwd.c +++ b/modules/tm/t_fwd.c @@ -329,12 +329,12 @@ static inline int update_uac_dst( struct sip_msg *request, char *shbuf; unsigned int len; - send_sock = get_send_socket( request, &uac->request.dst.to , + send_sock = get_send_socket( request, &uac->request.dst.to.su , uac->request.dst.proto ); if (send_sock==0) { LM_ERR("failed to fwd to af %d, proto %d " " (no corresponding listening socket)\n", - uac->request.dst.to.s.sa_family, uac->request.dst.proto ); + uac->request.dst.to.su.s.sa_family, uac->request.dst.proto ); ser_error=E_NO_SOCKET; return -1; } @@ -455,7 +455,7 @@ static int add_uac( struct cell *t, struct sip_msg *request, const str *uri, } /* use the first address */ - hostent2su( &t->uac[branch].request.dst.to, + hostent2hu( &t->uac[branch].request.dst.to, &proxy->host, proxy->addr_idx, proxy->port ? proxy->port:SIP_PORT); t->uac[branch].request.dst.proto = proxy->proto; @@ -747,7 +747,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg , /* check if the UAS retranmission port needs to be updated */ if ( (p_msg->msg_flags ^ t->uas.request->msg_flags) & FL_FORCE_RPORT ) - su_setport( &t->uas.response.dst.to, p_msg->rcv.src_port ); + su_setport( &t->uas.response.dst.to.su, p_msg->rcv.src_port ); /* if no more specific error code is known, use this */ lowest_ret=E_BUG; @@ -832,7 +832,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg , do { if (check_blacklists( t->uac[i].request.dst.proto, - &t->uac[i].request.dst.to, + &t->uac[i].request.dst.to.su, t->uac[i].request.buffer.s, t->uac[i].request.buffer.len)) { LM_DBG("blocked by blacklists\n"); @@ -855,7 +855,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg , } /* get next dns entry */ if ( t->uac[i].proxy==0 || - get_next_su( t->uac[i].proxy, &t->uac[i].request.dst.to, + get_next_su( t->uac[i].proxy, &t->uac[i].request.dst.to.su, (ser_error==E_IP_BLOCKED)?0:1)!=0 ) break; t->uac[i].request.dst.proto = t->uac[i].proxy->proto; diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c index db2775ae9f8..23ddfd70323 100644 --- a/modules/tm/t_reply.c +++ b/modules/tm/t_reply.c @@ -520,7 +520,7 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg, /* check if the UAS retranmission port needs to be updated */ if ( (p_msg->msg_flags ^ trans->uas.request->msg_flags) & FL_FORCE_RPORT ) - su_setport( &trans->uas.response.dst.to, p_msg->rcv.src_port ); + su_setport( &trans->uas.response.dst.to.su, p_msg->rcv.src_port ); if (code>=180 && p_msg->to && (get_to(p_msg)->tag_value.s==0 @@ -681,7 +681,7 @@ static inline int do_dns_failover(struct cell *t) uac = &t->uac[picked_branch]; /* check if the DNS resolver can get at least one new IP */ - if ( get_next_su( uac->proxy, &uac->request.dst.to, 1)!=0 ) + if ( get_next_su( uac->proxy, &uac->request.dst.to.su, 1)!=0 ) return -1; LM_DBG("new destination available\n"); diff --git a/modules/tm/uac.c b/modules/tm/uac.c index a82ee564cb1..a673ef99a8a 100644 --- a/modules/tm/uac.c +++ b/modules/tm/uac.c @@ -170,7 +170,7 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len, int backup_route_type; struct retr_buf *request; struct proxy_l *new_proxy = NULL; - union sockaddr_union new_to_su; + struct sockaddr_hu new_to_hu; struct socket_info *new_send_sock; unsigned short dst_changed; char *buf1=NULL, *sipmsg_buf; @@ -235,7 +235,7 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len, if (new_proxy==0) goto skip_update; /* use the first address */ - hostent2su( &new_to_su, + hostent2hu( &new_to_hu, &new_proxy->host, new_proxy->addr_idx, new_proxy->port ? new_proxy->port:SIP_PORT); /* get the send socket */ @@ -245,7 +245,7 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len, dialog->pref_sock->proto==new_proxy->proto) { new_send_sock = dialog->pref_sock; } else { - new_send_sock = get_send_socket( req, &new_to_su, + new_send_sock = get_send_socket( req, &new_to_hu.su, new_proxy->proto); if (new_send_sock==NULL) { free_proxy( new_proxy ); @@ -337,7 +337,7 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len, request->dst.proto_reserved1 = 0; } if (new_proxy) { - request->dst.to = new_to_su; + hu_dup(&new_to_hu, &request->dst.to); /* for DNS based failover, copy the DNS proxy into transaction */ if (!disable_dns_failover) { new_cell->uac[0].proxy = shm_clone_proxy( new_proxy, @@ -410,7 +410,7 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len, int t_uac(str* method, str* headers, str* body, dlg_t* dialog, transaction_cb cb, void* cbp,release_tmcb_param release_func) { - union sockaddr_union to_su; + struct sockaddr_hu to_hu; struct cell *new_cell; struct retr_buf *request; struct sip_msg *req = NULL; @@ -446,7 +446,7 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog, goto error_out; } /* use the first address */ - hostent2su( &to_su, + hostent2hu( &to_hu, &proxy->host, proxy->addr_idx, proxy->port ? proxy->port:SIP_PORT); /* check/discover the send socket */ @@ -461,11 +461,11 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog, dialog->send_sock = dialog->pref_sock; } else { /* get the send socket */ - dialog->send_sock = get_send_socket(NULL/*msg*/, &to_su, + dialog->send_sock = get_send_socket(NULL/*msg*/, &to_hu.su, proxy->proto); if (!dialog->send_sock) { LM_ERR("no corresponding socket for af %d\n", - to_su.s.sa_family); + to_hu.su.s.sa_family); ser_error = E_NO_SOCKET; goto error3; } @@ -511,10 +511,10 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog, new_cell->flags |= T_IS_LOCAL_FLAG; request = &new_cell->uac[0].request; - if (dialog->forced_to_su.s.sa_family == AF_UNSPEC) - request->dst.to = to_su; + if (dialog->forced_to_hu.su.s.sa_family == AF_UNSPEC) + hu_dup(&to_hu, &request->dst.to); else - request->dst.to = dialog->forced_to_su; + hu_dup(&dialog->forced_to_hu, &request->dst.to); request->dst.send_sock = dialog->send_sock; request->dst.proto = dialog->send_sock->proto; request->dst.proto_reserved1 = 0; diff --git a/modules/tracer/tracer.c b/modules/tracer/tracer.c index b69ea870615..7af560a0d44 100644 --- a/modules/tracer/tracer.c +++ b/modules/tracer/tracer.c @@ -154,7 +154,7 @@ static void trace_tm_in_rev(struct cell* t, int type, struct tmcb_params *ps); static void trace_tm_out(struct cell* t, int type, struct tmcb_params *ps); static void trace_tm_out_rev(struct cell* t, int type, struct tmcb_params *ps); static void trace_msg_out(struct sip_msg* req, str *buffer, - struct socket_info* send_sock, int proto, union sockaddr_union *to, + struct socket_info* send_sock, int proto, const union sockaddr_union *to, trace_info_p info, int leg_flag); static void siptrace_dlg_cancel(struct cell* t, int type, struct tmcb_params *param); @@ -163,9 +163,9 @@ static void siptrace_dlg_cancel(struct cell* t, int type, struct tmcb_params *pa * stateful transaction */ static void trace_slreq_out(struct sip_msg* req, str *buffer,int rpl_code, - union sockaddr_union *to, struct socket_info *sock, int proto); + const struct sockaddr_hu *to, struct socket_info *sock, int proto); static void trace_slreply_out(struct sip_msg* req, str *buffer,int rpl_code, - union sockaddr_union *dst, struct socket_info *sock, int proto); + const struct sockaddr_hu *dst, struct socket_info *sock, int proto); #if 0 static void trace_slack_in(struct sip_msg* req, str *buffer,int rpl_code, @@ -1978,7 +1978,7 @@ static int sip_trace_handle(struct sip_msg *msg, tlist_elem_p el, s.s = msg->buf; s.len = msg->len; trace_msg_out( msg, &s, msg->rcv.bind_address, msg->rcv.proto, - &tmb.t_gett()->uac[0].request.dst.to, info, TRACE_C_CALLEE); + &tmb.t_gett()->uac[0].request.dst.to.su, info, TRACE_C_CALLEE); } else /* otherwise trace only if per-message or not in local route * (UAC trans do not have IN msg) */ @@ -2292,7 +2292,7 @@ static void trace_onreq_out(struct cell* t, int type, struct tmcb_params *ps, trace_msg_out( ps->req, (str*)ps->extra1, dest->send_sock, dest->proto, - &dest->to, + &dest->to.su, &info, leg_flag); } else { @@ -2304,9 +2304,10 @@ static void trace_onreq_out(struct cell* t, int type, struct tmcb_params *ps, } static void trace_slreq_out(struct sip_msg* req, str *buffer,int rpl_code, - union sockaddr_union *to, struct socket_info *sock, int proto) + const struct sockaddr_hu *to_hu, struct socket_info *sock, int proto) { trace_info_p info; + const union sockaddr_union *to = to_hu ? &to_hu->su : NULL; info = GET_TRACER_CONTEXT; @@ -2317,7 +2318,7 @@ static void trace_slreq_out(struct sip_msg* req, str *buffer,int rpl_code, } static void trace_slreply_out(struct sip_msg* req, str *buffer,int rpl_code, - union sockaddr_union *dst, struct socket_info *sock, int proto) + const struct sockaddr_hu *dst, struct socket_info *sock, int proto) { static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12]; static char toip_buff[IP_ADDR_MAX_STR_SIZE+12]; @@ -2379,9 +2380,9 @@ static void trace_slreply_out(struct sip_msg* req, str *buffer,int rpl_code, { set_columns_to_any(db_vals[7], db_vals[8], db_vals[9]); } else { - su2ip_addr(&to_ip, dst); + su2ip_addr(&to_ip, &dst->su); set_sock_columns( db_vals[7], db_vals[8],db_vals[9], toip_buff, &to_ip, - (unsigned short)su_getport(dst), req->rcv.proto); + (unsigned short)su_getport(&dst->su), req->rcv.proto); } db_vals[10].val.time_val = time(NULL); @@ -2456,7 +2457,7 @@ static int parse_from_and_callid(struct sip_msg* msg, str *from_tag) { } static void trace_msg_out(struct sip_msg* msg, str *sbuf, - struct socket_info* send_sock, int proto, union sockaddr_union *to, + struct socket_info* send_sock, int proto, const union sockaddr_union *to, trace_info_p info, int leg_flag) { static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12]; @@ -2818,11 +2819,11 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps, set_columns_to_any( db_vals[7], db_vals[8], db_vals[9]); } else { memset(&to_ip, 0, sizeof(struct ip_addr)); - su2ip_addr(&to_ip, &dst->to); + su2ip_addr(&to_ip, &dst->to.su); set_sock_columns( db_vals[7], db_vals[8], db_vals[9], toip_buff, &to_ip, (unsigned long)(dst->send_sock && dst->send_sock->last_remote_real_port? - dst->send_sock->last_remote_real_port:su_getport(&dst->to)), + dst->send_sock->last_remote_real_port:su_getport(&dst->to.su)), dst->proto); } @@ -3422,7 +3423,7 @@ static mi_response_t *sip_trace_mi_2(const mi_params_t *params, static int trace_send_duplicate(char *buf, int len, struct sip_uri *uri) { - union sockaddr_union* to; + struct sockaddr_hu* to; struct socket_info* send_sock; struct proxy_l * p; int proto; @@ -3434,7 +3435,7 @@ static int trace_send_duplicate(char *buf, int len, struct sip_uri *uri) if(uri==NULL) return 0; - to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union)); + to=(struct sockaddr_hu*)pkg_malloc(sizeof(*to)); if (to==0){ LM_ERR("out of pkg memory\n"); return -1; @@ -3450,16 +3451,16 @@ static int trace_send_duplicate(char *buf, int len, struct sip_uri *uri) return -1; } - hostent2su(to, &p->host, p->addr_idx, + hostent2hu(to, &p->host, p->addr_idx, (p->port)?p->port:SIP_PORT); ret = -1; do { - send_sock=get_send_socket(0, to, proto); + send_sock=get_send_socket(0, &to->su, proto); if (send_sock==0){ LM_ERR("can't forward to af %d, proto %d no corresponding listening socket\n", - to->s.sa_family,proto); + to->su.s.sa_family,proto); continue; } @@ -3469,7 +3470,7 @@ static int trace_send_duplicate(char *buf, int len, struct sip_uri *uri) } ret = 0; break; - }while( get_next_su( p, to, 0)==0 ); + }while( get_next_su( p, &to->su, 0)==0 ); free_proxy(p); /* frees only p content, not p itself */ pkg_free(p); diff --git a/modules/uac_registrant/registrant.c b/modules/uac_registrant/registrant.c index b12339c9d94..3ff82fb61be 100644 --- a/modules/uac_registrant/registrant.c +++ b/modules/uac_registrant/registrant.c @@ -383,9 +383,9 @@ int run_reg_tm_cback(void *e_data, void *data, void *r_data) reg_print_record(rec); if (ps->rpl==FAKED_REPLY) - memset(&rec->td.forced_to_su, 0, sizeof(union sockaddr_union)); - else if (rec->td.forced_to_su.s.sa_family == AF_UNSPEC) - rec->td.forced_to_su = t->uac[0].request.dst.to; + memset(&rec->td.forced_to_hu, 0, sizeof(rec->td.forced_to_hu)); + else if (rec->td.forced_to_hu.su.s.sa_family == AF_UNSPEC) + hu_dup(&t->uac[0].request.dst.to, &rec->td.forced_to_hu); statuscode = ps->code; switch(statuscode) { @@ -1130,15 +1130,15 @@ int run_mi_reg_list(void *e_data, void *data, void *r_data) rec->td.obp.s, rec->td.obp.len) < 0) goto error; - switch(rec->td.forced_to_su.s.sa_family) { + switch(rec->td.forced_to_hu.su.s.sa_family) { case AF_UNSPEC: break; case AF_INET: case AF_INET6: if (add_mi_string(record_item, MI_SSTR("dst_IP"), - (rec->td.forced_to_su.s.sa_family==AF_INET)?"IPv4":"IPv6", 4) < 0) + (rec->td.forced_to_hu.su.s.sa_family==AF_INET)?"IPv4":"IPv6", 4) < 0) goto error; - sockaddr2ip_addr(&addr, &rec->td.forced_to_su.s); + sockaddr2ip_addr(&addr, &rec->td.forced_to_hu.su.s); p = ip_addr2a(&addr); if (p == NULL) goto error; len = strlen(p); @@ -1146,12 +1146,12 @@ int run_mi_reg_list(void *e_data, void *data, void *r_data) goto error; break; default: - LM_ERR("unexpected sa_family [%d]\n", rec->td.forced_to_su.s.sa_family); + LM_ERR("unexpected sa_family [%d]\n", rec->td.forced_to_hu.su.s.sa_family); if (add_mi_string(record_item, MI_SSTR("dst_IP"), "Error", 5) < 0) goto error; if (add_mi_number(record_item, MI_SSTR("sa_family"), - rec->td.forced_to_su.s.sa_family) < 0) + rec->td.forced_to_hu.su.s.sa_family) < 0) goto error; } diff --git a/net/api_proto.h b/net/api_proto.h index 39f708f2a2d..5efbcbf9818 100644 --- a/net/api_proto.h +++ b/net/api_proto.h @@ -32,7 +32,7 @@ typedef int (*proto_init_listener_f)(struct socket_info *si); typedef int (*proto_send_f)(struct socket_info *si, char* buf,unsigned int len, - union sockaddr_union* to, int unsigned id); + const struct sockaddr_hu* to, int unsigned id); typedef int (*proto_dst_attr_f)(struct receive_info *rcv, int attr, void *value); diff --git a/net/net_tcp.c b/net/net_tcp.c index aa3b3667383..0b71e9262e3 100644 --- a/net/net_tcp.c +++ b/net/net_tcp.c @@ -864,7 +864,7 @@ static inline void tcpconn_ref(struct tcp_connection* c) } -static struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su, +static struct tcp_connection* tcpconn_new(int sock, const union sockaddr_union* su, struct socket_info* si, struct tcp_conn_profile *prof, int state, int flags) { @@ -951,12 +951,21 @@ static struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su, * IMPORTANT - the function assumes you want to create a new TCP conn as * a result of a connect operation - the conn will be set as connect !! * Accepted connection are triggered internally only */ -struct tcp_connection* tcp_conn_create(int sock, union sockaddr_union* su, +struct tcp_connection* tcp_conn_create(int sock, const struct sockaddr_hu* shu, struct socket_info* si, struct tcp_conn_profile *prof, int state, int send2main) { struct tcp_connection *c; + const union sockaddr_union *su = &shu->su; + if (shu->hp == NULL) { + LM_ERR("tcpconn_new: no hostinfo"); + return NULL; + } + if (shu->hp->len >= sizeof(c->hostname)) { + LM_ERR("tcpconn_new: host name is too long %d", shu->hp->len); + return NULL; + } if (!prof) tcp_con_get_profile(su, &si->su, si->proto, prof); @@ -969,8 +978,8 @@ struct tcp_connection* tcp_conn_create(int sock, union sockaddr_union* su, /* copy peer hostname into the tcp_connection so that tls_openssl can verify * the certificate hostname */ - strncpy(c->hostname, su->h.hostname, sizeof(c->hostname)-1); - c->hostname[sizeof(c->hostname)-1] = 0; + memcpy(c->hostname, shu->hp->s, shu->hp->len); + c->hostname[shu->hp->len] = 0; if (protos[c->type].net.conn_init && protos[c->type].net.conn_init(c) < 0) { diff --git a/net/net_tcp.h b/net/net_tcp.h index f99d34c1f99..0c2d137918d 100644 --- a/net/net_tcp.h +++ b/net/net_tcp.h @@ -90,7 +90,7 @@ int tcp_conn_get(int unsigned id, struct ip_addr* ip, int port, struct socket_info* send_sock); /* creates a new tcp conn around a newly connected socket */ -struct tcp_connection* tcp_conn_create(int sock, union sockaddr_union* su, +struct tcp_connection* tcp_conn_create(int sock, const struct sockaddr_hu *su, struct socket_info* si, struct tcp_conn_profile *prof, int state, int send2main); diff --git a/net/proto_tcp/proto_tcp.c b/net/proto_tcp/proto_tcp.c index ce4e67263c4..131159a32a4 100644 --- a/net/proto_tcp/proto_tcp.c +++ b/net/proto_tcp/proto_tcp.c @@ -53,7 +53,7 @@ static int mod_init(void); static int proto_tcp_init(struct proto_info *pi); static int proto_tcp_init_listener(struct socket_info *si); static int proto_tcp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); inline static int _tcp_write_on_socket(struct tcp_connection *c, int fd, char *buf, int len); @@ -362,7 +362,7 @@ inline static int _tcp_write_on_socket(struct tcp_connection *c, int fd, /*! \brief Finds a tcpconn & sends on it */ static int proto_tcp_send(struct socket_info* send_sock, char* buf, unsigned int len, - union sockaddr_union* to, unsigned int id) + const struct sockaddr_hu* to_hu, unsigned int id) { struct tcp_connection *c; struct tcp_conn_profile prof; @@ -370,6 +370,7 @@ static int proto_tcp_send(struct socket_info* send_sock, struct timeval get,snd; union sockaddr_union src_su, dst_su; int port = 0, fd, n, matched; + const union sockaddr_union *to = (to_hu != NULL) ? &to_hu->su : NULL; matched = tcp_con_get_profile(to, &send_sock->su, send_sock->proto, &prof); @@ -408,7 +409,7 @@ static int proto_tcp_send(struct socket_info* send_sock, tcp_async); /* create tcp connection */ if (tcp_async) { - n = tcp_async_connect(send_sock, to, &prof, + n = tcp_async_connect(send_sock, to_hu, &prof, tcp_async_local_connect_timeout, &c, &fd, 1); if ( n<0 ) { LM_ERR("async TCP connect failed\n"); @@ -470,7 +471,7 @@ static int proto_tcp_send(struct socket_info* send_sock, } } } else { - if ((c=tcp_sync_connect(send_sock, to, &prof, &fd, 1))==0) { + if ((c=tcp_sync_connect(send_sock, to_hu, &prof, &fd, 1))==0) { LM_ERR("connect failed\n"); get_time_difference(get,prof.send_threshold,tcp_timeout_con_get); return -1; diff --git a/net/proto_udp/proto_udp.c b/net/proto_udp/proto_udp.c index bc7ed56d4ed..662c64b42a9 100644 --- a/net/proto_udp/proto_udp.c +++ b/net/proto_udp/proto_udp.c @@ -44,7 +44,7 @@ static int mod_init(void); static int proto_udp_init(struct proto_info *pi); static int proto_udp_init_listener(struct socket_info *si); static int proto_udp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to, unsigned int id); static int udp_read_req(struct socket_info *src, int* bytes_read); @@ -199,10 +199,11 @@ static int udp_read_req(struct socket_info *si, int* bytes_read) * \return -1 on error, the return value from sento on success */ static int proto_udp_send(struct socket_info* source, - char* buf, unsigned int len, union sockaddr_union* to, + char* buf, unsigned int len, const struct sockaddr_hu* to_hu, unsigned int id) { int n, tolen; + const union sockaddr_union *to = &to_hu->su; tolen=sockaddru_len(*to); again: diff --git a/net/tcp_common.c b/net/tcp_common.c index 76ffeec1c30..ed3a4f87997 100644 --- a/net/tcp_common.c +++ b/net/tcp_common.c @@ -140,12 +140,13 @@ int tcp_connect_blocking(int fd, const struct sockaddr *servaddr, tcp_connect_timeout); } -int tcp_sync_connect_fd(union sockaddr_union* src, union sockaddr_union* dst, +int tcp_sync_connect_fd(union sockaddr_union* src, const struct sockaddr_hu* hup, enum sip_protos proto, struct tcp_conn_profile *prof, enum si_flags flags) { int s; union sockaddr_union my_name; socklen_t my_name_len; + const union sockaddr_union *dst = &hup->su; s=socket(AF2PF(dst->s.sa_family), SOCK_STREAM, 0); if (s==-1){ @@ -182,7 +183,7 @@ int tcp_sync_connect_fd(union sockaddr_union* src, union sockaddr_union* dst, } struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, + const struct sockaddr_hu * server, struct tcp_conn_profile *prof, int *fd, int send2main) { struct tcp_connection* con; @@ -203,10 +204,11 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, } int tcp_async_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, + const struct sockaddr_hu* hsu, struct tcp_conn_profile *prof, int timeout, struct tcp_connection** c, int *ret_fd, int send2main) { int fd, n; + const union sockaddr_union *server = &hsu->su; union sockaddr_union my_name; socklen_t my_name_len; struct tcp_connection* con; @@ -330,7 +332,7 @@ int tcp_async_connect(struct socket_info* send_sock, async_connect: LM_DBG("Create connection for async connect\n"); /* create a new dummy connection */ - con=tcp_conn_create(fd, server, send_sock, + con=tcp_conn_create(fd, hsu, send_sock, prof, S_CONN_CONNECTING, send2main); if (con==NULL) { LM_ERR("tcp_conn_create failed\n"); @@ -341,7 +343,7 @@ int tcp_async_connect(struct socket_info* send_sock, return 0; local_connect: - con=tcp_conn_create(fd, server, send_sock, prof, S_CONN_OK, send2main); + con=tcp_conn_create(fd, hsu, send_sock, prof, S_CONN_OK, send2main); if (con==NULL) { LM_ERR("tcp_conn_create failed, closing the socket\n"); goto error; diff --git a/net/tcp_common.h b/net/tcp_common.h index 5d95b2c5e94..426f97ef4d6 100644 --- a/net/tcp_common.h +++ b/net/tcp_common.h @@ -30,11 +30,11 @@ int tcp_connect_blocking_timeout(int fd, const struct sockaddr *servaddr, socklen_t addrlen, int timeout_ms); -int tcp_sync_connect_fd(union sockaddr_union* src, union sockaddr_union* dst, +int tcp_sync_connect_fd(union sockaddr_union* src, const struct sockaddr_hu* dst, enum sip_protos proto, struct tcp_conn_profile *prof, enum si_flags flags); struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, + const struct sockaddr_hu* server, struct tcp_conn_profile *prof, int *fd, int send2main); /* Attempts do a connect to the given destination. It returns: @@ -43,7 +43,7 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, * -1 - error */ int tcp_async_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, + const struct sockaddr_hu* server, struct tcp_conn_profile *prof, int timeout, struct tcp_connection** c, int *ret_fd, int send2main); /* Responsible for writing the TCP send chunks - called under con write lock diff --git a/net/tcp_conn_profile.c b/net/tcp_conn_profile.c index d9990fd8726..505033ba40c 100644 --- a/net/tcp_conn_profile.c +++ b/net/tcp_conn_profile.c @@ -26,7 +26,7 @@ * by defining specific settings (per TCP path) using the "tcp_mgm" module */ struct tcp_conn_profile tcp_con_df_profile; -static int tcp_con_get_df_profile(union sockaddr_union *_, +static int tcp_con_get_df_profile(const union sockaddr_union *_, union sockaddr_union *__, enum sip_protos ___, struct tcp_conn_profile *out_profile) { @@ -36,7 +36,7 @@ static int tcp_con_get_df_profile(union sockaddr_union *_, /* global function/variable which may be overridden by tcp_mgm */ -int (*tcp_con_get_profile)(union sockaddr_union *remote, +int (*tcp_con_get_profile)(const union sockaddr_union *remote, union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile) = tcp_con_get_df_profile; diff --git a/net/tcp_conn_profile.h b/net/tcp_conn_profile.h index 3061e12e352..eebddeaa289 100644 --- a/net/tcp_conn_profile.h +++ b/net/tcp_conn_profile.h @@ -44,7 +44,7 @@ enum tcp_conn_attr { * 0 (success, but just the default TCP profile was returned) * 1 (success, a custom TCP profile from tcp_mgm DB was matched) */ -extern int (*tcp_con_get_profile)(union sockaddr_union *remote, +extern int (*tcp_con_get_profile)(const union sockaddr_union *remote, union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile); diff --git a/resolve.h b/resolve.h index 1c7babcebc8..3e0f0346585 100644 --- a/resolve.h +++ b/resolve.h @@ -54,8 +54,7 @@ #define MAX_QUERY_SIZE 8192 #define ANS_SIZE 8192 #define DNS_HDR_SIZE 12 -#define MAX_DNS_NAME 256 -#define MAX_DNS_STRING 255 +#define MAX_DNS_STRING (MAX_DNS_NAME-1) /*! \brief this is not official yet */ #define T_EBL 65300 diff --git a/sl_cb.c b/sl_cb.c index 7c91e27fbdf..64cf02452d8 100644 --- a/sl_cb.c +++ b/sl_cb.c @@ -75,7 +75,7 @@ int register_slcb(enum sl_cb_type type, unsigned int fmask, sl_cb_t f) void slcb_run_reply_out(struct sip_msg *req, str *buffer, - union sockaddr_union *dst, int rpl_code) + const struct sockaddr_hu *dst, int rpl_code) { struct sl_callback *cbp; @@ -100,7 +100,7 @@ void slcb_run_ack_in(struct sip_msg *req) void slcb_run_req_out(struct sip_msg *req, str *buffer, - union sockaddr_union *dst, struct socket_info *sock, int proto) + const struct sockaddr_hu *dst, struct socket_info *sock, int proto) { struct sl_callback *cbp; diff --git a/sl_cb.h b/sl_cb.h index 27005d48246..bc9e9ec658a 100644 --- a/sl_cb.h +++ b/sl_cb.h @@ -36,7 +36,7 @@ enum sl_cb_type {SLCB_REPLY_OUT=0, SLCB_ACK_IN, SLCB_REQUEST_OUT, /* callback function prototype */ typedef void (sl_cb_t) (struct sip_msg* req, str *buffer, int rpl_code, - union sockaddr_union *dst, struct socket_info *sock, int proto); + const struct sockaddr_hu *dst, struct socket_info *sock, int proto); /* register callback function prototype */ typedef int (*register_slcb_t)(enum sl_cb_type, unsigned int fmask, sl_cb_t f); @@ -51,10 +51,10 @@ int register_slcb(enum sl_cb_type, unsigned int fmask, sl_cb_t f); /* run SL callbacks for a given type */ void slcb_run_reply_out(struct sip_msg *req, str *buffer, - union sockaddr_union *dst, int rpl_code); + const struct sockaddr_hu *dst, int rpl_code); void slcb_run_ack_in(struct sip_msg *req); void slcb_run_req_out(struct sip_msg *req, str *buffer, - union sockaddr_union *dst, struct socket_info *sock, int proto); + const struct sockaddr_hu *dst, struct socket_info *sock, int proto); #endif