From 142e502d0c3cf3b4d07e8414858f3bc86b9a0d4b Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Thu, 30 Nov 2023 12:04:35 -0800 Subject: [PATCH] Move out dest_info and host_sock_info into their own TUs. --- core_cmds.c | 4 +- forward.c | 8 +-- forward.h | 6 +- ip_addr.h | 62 ++----------------- modules/cgrates/cgrates_engine.h | 2 +- modules/clusterer/clusterer.c | 6 +- modules/clusterer/topology.c | 14 ++--- modules/dispatcher/dispatch.c | 2 +- modules/drouting/routing.c | 2 +- modules/load_balancer/lb_data.c | 2 +- modules/nat_traversal/nat_traversal.c | 2 +- modules/nathelper/nathelper.c | 4 +- modules/proto_bin/proto_bin.c | 5 +- modules/proto_bins/proto_bins.c | 9 +-- modules/proto_hep/hep.c | 4 +- modules/proto_hep/proto_hep.c | 21 ++++--- modules/proto_msrp/msrp_common.c | 2 +- modules/proto_msrp/msrp_common.h | 2 +- modules/proto_msrp/msrp_signaling.c | 10 +-- modules/proto_msrp/msrp_signaling.h | 1 + modules/proto_msrp/msrp_tls.c | 2 +- modules/proto_msrp/msrp_tls.h | 2 +- modules/proto_sctp/sctp_server.c | 2 +- modules/proto_sctp/sctp_server.h | 2 +- modules/proto_smpp/proto_smpp.c | 8 +-- modules/proto_smpp/smpp.c | 2 +- modules/proto_tls/proto_tls.c | 9 +-- modules/proto_ws/proto_ws.c | 9 +-- modules/proto_ws/ws_common.h | 4 +- modules/proto_wss/proto_wss.c | 9 +-- modules/rtpproxy/rtpproxy.c | 2 +- modules/sipcapture/sipcapture.c | 2 +- modules/sl/sl_funcs.c | 2 +- modules/tls_mgm/api.h | 4 +- modules/tls_mgm/tls_lib_api.h | 4 +- modules/tls_mgm/tls_mgm.c | 2 +- modules/tls_openssl/openssl.c | 2 +- modules/tls_openssl/openssl_conn_ops.c | 8 ++- modules/tls_wolfssl/wolfssl.c | 2 +- modules/tls_wolfssl/wolfssl_conn_ops.c | 2 +- modules/tm/dlg.h | 3 +- modules/tm/h_table.h | 1 + modules/tm/uac.c | 4 +- modules/tracer/tracer.c | 12 ++-- net/api_proto.h | 4 +- net/api_proto_net.h | 2 +- net/dest_info.h | 30 +++++++++ net/host_sock_info.h | 84 ++++++++++++++++++++++++++ net/net_tcp.c | 3 +- net/net_tcp.h | 4 +- net/proto_tcp/proto_tcp.c | 5 +- net/proto_udp/proto_udp.c | 5 +- net/tcp_common.c | 7 ++- net/tcp_common.h | 8 ++- proxy.h | 1 + resolve.c | 2 +- resolve.h | 2 +- sl_cb.c | 4 +- sl_cb.h | 7 ++- 59 files changed, 261 insertions(+), 174 deletions(-) create mode 100644 net/dest_info.h create mode 100644 net/host_sock_info.h diff --git a/core_cmds.c b/core_cmds.c index c214c6403f1..51464295299 100644 --- a/core_cmds.c +++ b/core_cmds.c @@ -745,12 +745,12 @@ 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; - struct sockaddr_hu* to; + struct host_sock_info* to; struct proxy_l* p; int len; char* tmp; - to=(struct sockaddr_hu*) + to=(struct host_sock_info*) pkg_malloc(sizeof(*to)); if (to==0){ LM_ERR("memory allocation failure\n"); diff --git a/forward.c b/forward.c index 717eb9a44fd..b1de3d7cb4f 100644 --- a/forward.c +++ b/forward.c @@ -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) { - struct sockaddr_hu to; + struct host_sock_info to; str buf; struct socket_info* send_sock; struct socket_info* last_sock; @@ -402,7 +402,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) -int update_sock_struct_from_via( struct sockaddr_hu* to, +int update_sock_struct_from_via( struct host_sock_info* to, struct sip_msg* msg, struct via_body* via ) { @@ -468,7 +468,7 @@ int update_sock_struct_from_via( struct sockaddr_hu* to, int forward_reply(struct sip_msg* msg) { char* new_buf; - struct sockaddr_hu *to; + struct host_sock_info *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=(struct sockaddr_hu *)pkg_malloc(sizeof(*to)); + to=(struct host_sock_info *)pkg_malloc(sizeof(*to)); if (to==0){ LM_ERR("out of pkg memory\n"); goto error; diff --git a/forward.h b/forward.h index bcc26e754b0..423fff5dbdb 100644 --- a/forward.h +++ b/forward.h @@ -52,13 +52,13 @@ struct socket_info* get_send_socket(struct sip_msg* msg, 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( struct sockaddr_hu* to, +int update_sock_struct_from_via( struct host_sock_info* 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 ) \ - *(to) = (struct sockaddr_hu){0}; \ + *(to) = (struct host_sock_info){0}; \ init_su(&((to)->su), &(msg)->rcv.src_ip, \ ((!msg->via1)||((msg)->via1->rport)||((msg)->msg_flags&FL_FORCE_RPORT))? \ (msg)->rcv.src_port: \ @@ -83,7 +83,7 @@ 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, - const struct sockaddr_hu* to_hu, unsigned int id, + const struct host_sock_info* to_hu, unsigned int id, char* buf, int len, struct sip_msg* msg) { str out_buff; diff --git a/ip_addr.h b/ip_addr.h index 72cd70ee5b7..e8d854c0314 100644 --- a/ip_addr.h +++ b/ip_addr.h @@ -34,7 +34,6 @@ #ifndef ip_addr_h #define ip_addr_h -#include #include #include #include @@ -83,21 +82,13 @@ struct net{ struct ip_addr mask; }; - union sockaddr_union{ - struct sockaddr s; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; + struct sockaddr s; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; }; -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 }; @@ -116,14 +107,6 @@ struct receive_info { }; -struct dest_info { - int proto; - unsigned int proto_reserved1; /*!< tcp stores the connection id here */ - struct sockaddr_hu to; - struct socket_info* send_sock; -}; - - struct socket_id { char* name; char* adv_name; @@ -365,7 +348,6 @@ static inline int init_su( union sockaddr_union* su, } - /*! \brief inits a struct sockaddr_union from a struct hostent, an address index in * the hostent structure and a port no. (host byte order) * WARNING: no index overflow checks! @@ -400,42 +382,6 @@ 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 r; -} - -static inline void hu_dup(const struct sockaddr_hu *hu_s, struct sockaddr_hu *hu_d) -{ - if (hu_s->hp != NULL) { - memcpy(hu_d, hu_s, sizeof(*hu_d)); - hu_d->_.hoststr.s = hu_d->_.hostname; - hu_d->hp = &hu_d->_.hoststr; - } else { - memcpy(hu_d, hu_s, sizeof(*hu_d) - offsetof(struct sockaddr_hu, _)); - } -} - /*! \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/cgrates/cgrates_engine.h b/modules/cgrates/cgrates_engine.h index 125284cf0b4..6543c1aa76e 100644 --- a/modules/cgrates/cgrates_engine.h +++ b/modules/cgrates/cgrates_engine.h @@ -29,7 +29,7 @@ struct cgr_engine { str host; int is_fqdn; - struct sockaddr_hu hu; + struct host_sock_info hu; time_t disable_time; struct cgr_conn *default_con; diff --git a/modules/clusterer/clusterer.c b/modules/clusterer/clusterer.c index 3ff5f36d6e7..1e35a2df5b3 100644 --- a/modules/clusterer/clusterer.c +++ b/modules/clusterer/clusterer.c @@ -322,7 +322,7 @@ 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}; + struct host_sock_info to = {.su = chosen_dest->addr}; if (msg_send(chosen_dest->cluster->send_sock, chosen_dest->proto, &to, 0, send_buffer.s, send_buffer.len, 0) < 0) { LM_ERR("msg_send() to node [%d] failed\n", chosen_dest->node_id); @@ -1476,7 +1476,7 @@ int send_single_cap_update(cluster_info_t *cluster, struct local_cap *cap, bin_get_buffer(&packet, &bin_buffer); for (i = 0; i < no_dests; i++) { - struct sockaddr_hu to = {.su = destinations[i]->addr}; + struct host_sock_info to = {.su = destinations[i]->addr}; if (msg_send(cluster->send_sock, destinations[i]->proto, &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { LM_ERR("Failed to send capability update to node [%d]\n", @@ -1570,7 +1570,7 @@ 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); - struct sockaddr_hu to = {.su = dest_node->addr}; + struct host_sock_info 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); diff --git a/modules/clusterer/topology.c b/modules/clusterer/topology.c index 0eada0af801..8886ba6be0c 100644 --- a/modules/clusterer/topology.c +++ b/modules/clusterer/topology.c @@ -57,7 +57,7 @@ static int send_ping(node_info_t *node, int req_node_list) set_proc_log_level(L_INFO); #endif - struct sockaddr_hu to = {.su = node->addr}; + struct host_sock_info to = {.su = node->addr}; rc = msg_send(node->cluster->send_sock, node->proto, &to, 0, send_buffer.s, send_buffer.len, 0); @@ -488,7 +488,7 @@ 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}; + struct host_sock_info to = {.su = destinations[i]->addr}; if (msg_send(cluster->send_sock, destinations[i]->proto, &to, 0, bin_buffer.s, bin_buffer.len, 0) < 0) { LM_ERR("Failed to flood message to node [%d]\n", @@ -603,7 +603,7 @@ 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); - struct sockaddr_hu to = {.su = dest_node->addr}; + struct host_sock_info 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); @@ -665,7 +665,7 @@ 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}; + struct host_sock_info to = {.su = destinations[i]->addr}; if (msg_send(destinations[i]->cluster->send_sock, destinations[i]->proto, &to, 0, send_buffer.s, send_buffer.len, 0) < 0) { LM_ERR("Failed to send link state update to node [%d]\n", @@ -1148,7 +1148,7 @@ 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); - struct sockaddr_hu to = {.su = *src_su}; + struct host_sock_info 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); @@ -1252,7 +1252,7 @@ void handle_unknown_id(node_info_t *src_node) bin_push_int(&packet, current_id); bin_get_buffer(&packet, &bin_buffer); - struct sockaddr_hu to = {.su = src_node->addr}; + struct host_sock_info 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); @@ -1300,7 +1300,7 @@ 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}; + struct host_sock_info to = {.su = src_node->addr}; send_rc = msg_send(src_node->cluster->send_sock, src_node->proto, &to, 0, bin_buffer.s, bin_buffer.len, 0); diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 71a264a5fd1..b8aff18c3de 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -186,7 +186,7 @@ int add_dest2list(int id, str uri, struct socket_info *sock, str *comsock, int s /* For DNS-Lookups */ struct proxy_l *proxy; - struct sockaddr_hu sau; + struct host_sock_info sau; /* check uri */ if(parse_uri(uri.s, uri.len, &puri)!=0 || puri.host.len>254) diff --git a/modules/drouting/routing.c b/modules/drouting/routing.c index 8edd4009208..2579d860b02 100644 --- a/modules/drouting/routing.c +++ b/modules/drouting/routing.c @@ -536,7 +536,7 @@ add_dst( #define GWABUF_MAX_SIZE 512 char gwabuf[GWABUF_MAX_SIZE]; char *p; - struct sockaddr_hu sau; + struct host_sock_info sau; struct proxy_l *proxy; unsigned int sip_prefix; str gwas; diff --git a/modules/load_balancer/lb_data.c b/modules/load_balancer/lb_data.c index 5ce62c18b26..243d1ab506b 100644 --- a/modules/load_balancer/lb_data.c +++ b/modules/load_balancer/lb_data.c @@ -227,7 +227,7 @@ int add_lb_dsturi( struct lb_data *data, int id, int group, char *uri, struct lb_resource *res; struct sip_uri puri; struct proxy_l *proxy; - struct sockaddr_hu sau; + struct host_sock_info sau; int uri_len, attrs_len; int i; str fs_url = { NULL, 0 }; diff --git a/modules/nat_traversal/nat_traversal.c b/modules/nat_traversal/nat_traversal.c index 0ced5a45f43..ab0daf3db9c 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, - const struct sockaddr_hu *dst, struct socket_info *sock, int proto) + const struct host_sock_info *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 50ee207ef96..97bdcbce60f 100644 --- a/modules/nathelper/nathelper.c +++ b/modules/nathelper/nathelper.c @@ -1423,7 +1423,7 @@ 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))) { - struct sockaddr_hu to_hu = {.su = to}; + struct host_sock_info 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"); } @@ -1432,7 +1432,7 @@ nh_timer(unsigned int ticks, void *timer_idx) LM_ERR("send_raw failed\n"); } } else { - struct sockaddr_hu to_hu = {.su = to}; + struct host_sock_info 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 5d2cd3c5630..e1449200744 100644 --- a/modules/proto_bin/proto_bin.c +++ b/modules/proto_bin/proto_bin.c @@ -33,6 +33,7 @@ #include "../../net/api_proto.h" #include "../../net/api_proto_net.h" #include "../../net/net_tcp.h" +#include "../../net/host_sock_info.h" #include "../../net/tcp_common.h" #include "../../socket_info.h" #include "../../tsend.h" @@ -47,7 +48,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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static int bin_read_req(struct tcp_connection* con, int* bytes_read); @@ -142,7 +143,7 @@ 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, const struct sockaddr_hu *to_hu, + char* buf, unsigned int len, const struct host_sock_info *to_hu, unsigned int id) { struct tcp_connection *c; diff --git a/modules/proto_bins/proto_bins.c b/modules/proto_bins/proto_bins.c index 683cd0ddeaf..3989b76b565 100644 --- a/modules/proto_bins/proto_bins.c +++ b/modules/proto_bins/proto_bins.c @@ -27,6 +27,7 @@ #include "../../net/net_tcp.h" #include "../../net/tcp_common.h" #include "../../net/net_tcp_report.h" +#include "../../net/host_sock_info.h" #include "../../socket_info.h" #include "../../tsend.h" #include "../../net/proto_tcp/tcp_common_defs.h" @@ -46,11 +47,11 @@ 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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* 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); -static int proto_bins_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu); +static int proto_bins_conn_init(struct tcp_connection* c, const struct host_sock_info *hu); static void proto_bins_conn_clean(struct tcp_connection* c); static void bins_report(int type, unsigned long long conn_id, int conn_flags, void *extra); @@ -225,7 +226,7 @@ static int proto_bins_init_listener(struct socket_info *si) return tcp_init_listener(si); } -static int proto_bins_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +static int proto_bins_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { struct tls_domain *dom; struct tls_data* data; @@ -337,7 +338,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, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id) { struct tcp_connection *c; diff --git a/modules/proto_hep/hep.c b/modules/proto_hep/hep.c index 87fb36a078d..fd46ec0d68f 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; - struct sockaddr_hu* to; + struct host_sock_info* 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=(struct sockaddr_hu *)pkg_malloc(sizeof(*to)); + to=(struct host_sock_info *)pkg_malloc(sizeof(*to)); if (to == 0) { LM_ERR("no more pkg mem!\n"); pkg_free(buf); diff --git a/modules/proto_hep/proto_hep.c b/modules/proto_hep/proto_hep.c index 838da1f1e06..00dfe1d54ba 100644 --- a/modules/proto_hep/proto_hep.c +++ b/modules/proto_hep/proto_hep.c @@ -37,6 +37,7 @@ #include "../../net/tcp_common.h" #include "../../net/net_tcp.h" #include "../../net/net_udp.h" +#include "../../net/host_sock_info.h" #include "../../socket_info.h" #include "../../receive.h" #include "../../net/proto_tcp/tcp_common_defs.h" @@ -61,20 +62,20 @@ 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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static int hep_tcp_or_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id, unsigned int is_tls); static int hep_tcp_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static int hep_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static void update_recv_info(struct receive_info* ri, struct hep_desc* h); void free_hep_context(void* ptr); -static int proto_hep_tls_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu); +static int proto_hep_tls_conn_init(struct tcp_connection* c, const struct host_sock_info *hu); static void proto_hep_tls_conn_clean(struct tcp_connection* c); static int hep_tls_write_on_socket(struct tcp_connection* c, int fd, char* buf, int len); @@ -345,7 +346,7 @@ 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, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id) { int n, tolen; @@ -368,21 +369,21 @@ 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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* 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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* 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, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id, unsigned int is_tls) { struct tcp_connection* c; @@ -1186,7 +1187,7 @@ static void update_recv_info(struct receive_info* ri, struct hep_desc* h) ri->dst_port = dport; } -static int proto_hep_tls_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +static int proto_hep_tls_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { struct tls_domain* dom; diff --git a/modules/proto_msrp/msrp_common.c b/modules/proto_msrp/msrp_common.c index 10a51b659f8..d708c7badd7 100644 --- a/modules/proto_msrp/msrp_common.c +++ b/modules/proto_msrp/msrp_common.c @@ -558,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, - const struct sockaddr_hu* to_hu, unsigned int id) + const struct host_sock_info* to_hu, unsigned int id) { struct tcp_connection *c; struct tcp_conn_profile prof; diff --git a/modules/proto_msrp/msrp_common.h b/modules/proto_msrp/msrp_common.h index 658f8f64173..f88d46ed8b0 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, - const struct sockaddr_hu* to, unsigned int id); + const struct host_sock_info* 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 4a90db5d4ff..1b176fd6dc2 100644 --- a/modules/proto_msrp/msrp_signaling.c +++ b/modules/proto_msrp/msrp_signaling.c @@ -190,7 +190,7 @@ 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}; + struct host_sock_info to = {.su = req->rcv.src_su}; i = msg_send( req->rcv.bind_address, PROTO_MSRP, &to, req->rcv.proto_reserved1, buf, len, NULL); @@ -425,7 +425,7 @@ int msrp_fwd_request( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no, } /* now, send it out*/ - struct sockaddr_hu to_hu = {.su = *to_su}; + struct host_sock_info 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 */ @@ -791,7 +791,7 @@ 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}; + struct host_sock_info to = {.su = req->rcv.src_su}; i = msg_send( req->rcv.bind_address, PROTO_MSRP, &to, req->rcv.proto_reserved1, buf, len, NULL); @@ -1057,7 +1057,7 @@ int msrp_send_request(void *hdl, enum msrp_method method_id, } /* now, send it out*/ - struct sockaddr_hu to_hu = {.su = *to_su}; + struct host_sock_info 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 */ @@ -1284,7 +1284,7 @@ static struct msrp_cell* _build_transaction(struct msrp_msg *req, int hash, req->failure_report->body.len); } - cell->recv.to = (struct sockaddr_hu){0}; + cell->recv.to = (struct host_sock_info){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; diff --git a/modules/proto_msrp/msrp_signaling.h b/modules/proto_msrp/msrp_signaling.h index b4bd4630f28..dd1f9294ee3 100644 --- a/modules/proto_msrp/msrp_signaling.h +++ b/modules/proto_msrp/msrp_signaling.h @@ -24,6 +24,7 @@ #ifndef _PROTO_MSRP_MSRP_SIGNALING_H_ #define _PROTO_MSRP_MSRP_SIGNALING_H_ +#include "../../net/dest_info.h" #include "msrp_parser.h" diff --git a/modules/proto_msrp/msrp_tls.c b/modules/proto_msrp/msrp_tls.c index 23355e68084..9a56e248817 100644 --- a/modules/proto_msrp/msrp_tls.c +++ b/modules/proto_msrp/msrp_tls.c @@ -32,7 +32,7 @@ int msrps_conn_extra_match(struct tcp_connection *c, void *id) } -int proto_msrps_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +int proto_msrps_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { struct tls_domain *dom; diff --git a/modules/proto_msrp/msrp_tls.h b/modules/proto_msrp/msrp_tls.h index fbb9701af95..2ab57249e46 100644 --- a/modules/proto_msrp/msrp_tls.h +++ b/modules/proto_msrp/msrp_tls.h @@ -25,7 +25,7 @@ int msrps_conn_extra_match(struct tcp_connection *c, void *id); -int proto_msrps_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu); +int proto_msrps_conn_init(struct tcp_connection* c, const struct host_sock_info *hu); void proto_msrps_conn_clean(struct tcp_connection* c); diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index f30262d175d..504451d611f 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -190,7 +190,7 @@ 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, - const struct sockaddr_hu *to, unsigned int id) + const struct host_sock_info *to, unsigned int id) { int n; int tolen; diff --git a/modules/proto_sctp/sctp_server.h b/modules/proto_sctp/sctp_server.h index edc0e831620..1ff71111d0a 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, - const struct sockaddr_hu* to, unsigned int id); + const struct host_sock_info* 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 9e77cc48f0f..d7cd10fc1e5 100644 --- a/modules/proto_smpp/proto_smpp.c +++ b/modules/proto_smpp/proto_smpp.c @@ -60,11 +60,11 @@ 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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* 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); -static int smpp_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu); +static int smpp_conn_init(struct tcp_connection* c, const struct host_sock_info *hu); static void smpp_conn_clean(struct tcp_connection* c); static int send_smpp_msg(struct sip_msg* msg, str *name, str *from, str *to, str *body, int *utf16, int *delivery_confirmation); @@ -211,7 +211,7 @@ static int child_init(int rank) return 0; } -static int smpp_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +static int smpp_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { LM_INFO("smpp_conn_init called\n"); return 0; @@ -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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* 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 aa4fdfe7223..134a28ba44e 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; - struct sockaddr_hu server = {0}; + struct host_sock_info server = {0}; struct socket_info *send_socket; struct tcp_conn_profile prof; diff --git a/modules/proto_tls/proto_tls.c b/modules/proto_tls/proto_tls.c index 079cf775d5b..669a978a370 100644 --- a/modules/proto_tls/proto_tls.c +++ b/modules/proto_tls/proto_tls.c @@ -50,6 +50,7 @@ #include "../../net/net_tcp.h" #include "../../net/tcp_common.h" #include "../../net/net_tcp_report.h" +#include "../../net/host_sock_info.h" #include "../../socket_info.h" #include "../../tsend.h" #include "../../timer.h" @@ -123,7 +124,7 @@ static int mod_init(void); static int proto_tls_init(struct proto_info *pi); static int proto_tls_init_listener(struct socket_info *si); static int proto_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static void tls_report(int type, unsigned long long conn_id, int conn_flags, void *extra); @@ -207,7 +208,7 @@ static struct script_route_ref *trace_filter_route_ref = NULL; static int tls_read_req(struct tcp_connection* con, int* bytes_read); static int tls_async_write(struct tcp_connection* con,int fd); -static int proto_tls_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu); +static int proto_tls_conn_init(struct tcp_connection* c, const struct host_sock_info *hu); static void proto_tls_conn_clean(struct tcp_connection* c); static const cmd_export_t cmds[] = { @@ -388,7 +389,7 @@ static int proto_tls_init_listener(struct socket_info *si) } -static int proto_tls_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +static int proto_tls_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { struct tls_data* data; struct tls_domain *dom; @@ -474,7 +475,7 @@ static void tls_report(int type, unsigned long long conn_id, int conn_flags, } static int proto_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id) { struct tcp_connection *c; diff --git a/modules/proto_ws/proto_ws.c b/modules/proto_ws/proto_ws.c index 2c2e512c15c..cbcafbded54 100644 --- a/modules/proto_ws/proto_ws.c +++ b/modules/proto_ws/proto_ws.c @@ -37,6 +37,7 @@ #include "../../net/api_proto_net.h" #include "../../net/net_tcp_report.h" #include "../../net/tcp_common.h" +#include "../../net/host_sock_info.h" #include "../../socket_info.h" #include "../../tsend.h" #include "../../receive.h" @@ -95,10 +96,10 @@ 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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* 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, const struct sockaddr_hu *hu); +static int ws_conn_init(struct tcp_connection* c, const struct host_sock_info *hu); static void ws_conn_clean(struct tcp_connection* c); static void ws_report(int type, unsigned long long conn_id, int conn_flags, void *extra); @@ -239,7 +240,7 @@ static int mod_init(void) } -static int ws_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +static int ws_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { struct ws_data *d; @@ -328,7 +329,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, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id) { struct tcp_connection *c; diff --git a/modules/proto_ws/ws_common.h b/modules/proto_ws/ws_common.h index 78e155c3ebb..d48fb6615f2 100644 --- a/modules/proto_ws/ws_common.h +++ b/modules/proto_ws/ws_common.h @@ -636,7 +636,7 @@ static void ws_close(struct tcp_connection *c) } static struct tcp_connection* ws_sync_connect(struct socket_info* send_sock, - const struct sockaddr_hu* server_hu, struct tcp_conn_profile *prof) + const struct host_sock_info* server_hu, struct tcp_conn_profile *prof) { int s; union sockaddr_union my_name; @@ -685,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, - const struct sockaddr_hu* to, struct tcp_conn_profile *prof, int *fd) + const struct host_sock_info* to, struct tcp_conn_profile *prof, int *fd) { struct tcp_connection *c; diff --git a/modules/proto_wss/proto_wss.c b/modules/proto_wss/proto_wss.c index 98024cc8975..b461068e8e4 100644 --- a/modules/proto_wss/proto_wss.c +++ b/modules/proto_wss/proto_wss.c @@ -44,6 +44,7 @@ #include "../../net/proto_tcp/tcp_common_defs.h" #include "../../net/trans_trace.h" #include "../../net/net_tcp_report.h" +#include "../../net/host_sock_info.h" #include "../proto_ws/proto_ws.h" #include "proto_wss.h" #include "../proto_ws/ws_common_defs.h" @@ -108,10 +109,10 @@ static int mod_init(void); static int proto_wss_init(struct proto_info *pi); static int proto_wss_init_listener(struct socket_info *si); static int proto_wss_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static int wss_read_req(struct tcp_connection* con, int* bytes_read); -static int wss_conn_init(struct tcp_connection* c, const struct sockaddr_hu *); +static int wss_conn_init(struct tcp_connection* c, const struct host_sock_info *); static void ws_conn_clean(struct tcp_connection* c); static void wss_report(int type, unsigned long long conn_id, int conn_flags, void *extra); @@ -262,7 +263,7 @@ static int mod_init(void) return 0; } -static int wss_conn_init(struct tcp_connection* c, const struct sockaddr_hu *hu) +static int wss_conn_init(struct tcp_connection* c, const struct host_sock_info *hu) { struct ws_data *d; struct tls_domain *dom; @@ -389,7 +390,7 @@ static void wss_report(int type, unsigned long long conn_id, int conn_flags, /*! \brief Finds a tcpconn & sends on it */ static int proto_wss_send(struct socket_info* send_sock, - char* buf, unsigned int len, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id) { struct tcp_connection *c; diff --git a/modules/rtpproxy/rtpproxy.c b/modules/rtpproxy/rtpproxy.c index ecea761dd01..475aa08c780 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; - struct sockaddr_hu to; + struct host_sock_info to; struct ip_addr ip; struct cell *trans; diff --git a/modules/sipcapture/sipcapture.c b/modules/sipcapture/sipcapture.c index 3286a6d85e6..7926170d8fd 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; - struct sockaddr_hu to; + struct host_sock_info to; str* uri_s; str buf_s; diff --git a/modules/sl/sl_funcs.c b/modules/sl/sl_funcs.c index 1a786c63417..66d9cdef604 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; - struct sockaddr_hu to; + struct host_sock_info to; char *dset; int dset_len; struct bookmark dummy_bm; diff --git a/modules/tls_mgm/api.h b/modules/tls_mgm/api.h index 43cbb5f6286..f9731d35bd4 100644 --- a/modules/tls_mgm/api.h +++ b/modules/tls_mgm/api.h @@ -42,6 +42,8 @@ #include "tls_helper.h" +struct host_sock_info; + typedef struct tls_domain * (*tls_find_server_domain_f) (struct ip_addr *, unsigned short); typedef struct tls_domain * (*tls_find_client_domain_f) (struct ip_addr *, unsigned short); typedef struct tls_domain * (*tls_find_client_domain_name_f) (str *); @@ -49,7 +51,7 @@ typedef void (*tls_release_domain_f) (struct tls_domain *); /* TLS conn ops */ typedef int (*tls_conn_init_f)(struct tcp_connection *c, - struct tls_domain *tls_dom, const struct sockaddr_hu *hu); + struct tls_domain *tls_dom, const struct host_sock_info *hu); typedef void (*tls_conn_clean_f)(struct tcp_connection* c, struct tls_domain **tls_dom); typedef int (*tls_update_fd_f)(struct tcp_connection* c, int fd); diff --git a/modules/tls_mgm/tls_lib_api.h b/modules/tls_mgm/tls_lib_api.h index 85dd77a7fba..1ecd6dcbc75 100644 --- a/modules/tls_mgm/tls_lib_api.h +++ b/modules/tls_mgm/tls_lib_api.h @@ -27,9 +27,11 @@ #include "../../trace_api.h" #include "tls_helper.h" +struct host_sock_info; + /* TLS library specific conn ops */ typedef int (*tls_lib_conn_init_f)(struct tcp_connection *c, - struct tls_domain *tls_dom, const struct sockaddr_hu *); + struct tls_domain *tls_dom, const struct host_sock_info *); typedef void (*tls_lib_conn_clean_f)(struct tcp_connection* c, struct tls_domain **tls_dom); typedef int (*tls_lib_update_fd_f)(struct tcp_connection* c, int fd); diff --git a/modules/tls_mgm/tls_mgm.c b/modules/tls_mgm/tls_mgm.c index cf5cc784ce4..0778caf9931 100644 --- a/modules/tls_mgm/tls_mgm.c +++ b/modules/tls_mgm/tls_mgm.c @@ -1348,7 +1348,7 @@ static mi_response_t *tls_list(const mi_params_t *params, return NULL; } -int tls_conn_init(struct tcp_connection *c, struct tls_domain *tls_dom, const struct sockaddr_hu *hu) +int tls_conn_init(struct tcp_connection *c, struct tls_domain *tls_dom, const struct host_sock_info *hu) { if (tls_library == TLS_LIB_OPENSSL) return openssl_api.tls_conn_init(c, tls_dom, hu); diff --git a/modules/tls_openssl/openssl.c b/modules/tls_openssl/openssl.c index f7b7bc5026d..d550709d3e0 100644 --- a/modules/tls_openssl/openssl.c +++ b/modules/tls_openssl/openssl.c @@ -58,7 +58,7 @@ static void mod_destroy(void); /* openssl conn ops */ int openssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom, - const struct sockaddr_hu *hu); + const struct host_sock_info *hu); void openssl_tls_conn_clean(struct tcp_connection *c, struct tls_domain **tls_dom); int openssl_tls_update_fd(struct tcp_connection *c, int fd); diff --git a/modules/tls_openssl/openssl_conn_ops.c b/modules/tls_openssl/openssl_conn_ops.c index 14979a7975c..c827556f520 100644 --- a/modules/tls_openssl/openssl_conn_ops.c +++ b/modules/tls_openssl/openssl_conn_ops.c @@ -33,6 +33,7 @@ #include #include "../../net/tcp_conn_defs.h" +#include "../../net/host_sock_info.h" #include "../../net/proto_tcp/tcp_common_defs.h" #include "../tls_mgm/tls_helper.h" @@ -198,7 +199,7 @@ int openssl_tls_update_fd(struct tcp_connection *c, int fd) return 0; } -int openssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom, const struct sockaddr_hu *hu) +int openssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom, const struct host_sock_info *hu) { X509_VERIFY_PARAM *param = NULL; @@ -222,13 +223,14 @@ int openssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom, } if (tls_dom->verify_hostname) { - if (hu == NULL || hu->hp == NULL) { + const str_const hostinfo = hu_gethost(hu); + if (hostinfo.len == 0) { LM_ERR("no hostinfo\n"); return -1; } param = SSL_get0_param(c->extra_data); X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); - if (!X509_VERIFY_PARAM_set1_host(param, hu->hp->s, hu->hp->len)) { + if (!X509_VERIFY_PARAM_set1_host(param, hostinfo.s, hostinfo.len)) { LM_ERR("failed to set hostname for SSL context\n"); return -1; } diff --git a/modules/tls_wolfssl/wolfssl.c b/modules/tls_wolfssl/wolfssl.c index 6b7ce845f7e..97ace604122 100644 --- a/modules/tls_wolfssl/wolfssl.c +++ b/modules/tls_wolfssl/wolfssl.c @@ -59,7 +59,7 @@ static int mod_init(void); static void mod_destroy(void); int _wolfssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom, - const struct sockaddr_hu *hu); + const struct host_sock_info *hu); void _wolfssl_tls_conn_clean(struct tcp_connection *c, struct tls_domain **tls_dom); int _wolfssl_tls_update_fd(struct tcp_connection *c, int fd); diff --git a/modules/tls_wolfssl/wolfssl_conn_ops.c b/modules/tls_wolfssl/wolfssl_conn_ops.c index 72b6927bc1b..b5bba428efd 100644 --- a/modules/tls_wolfssl/wolfssl_conn_ops.c +++ b/modules/tls_wolfssl/wolfssl_conn_ops.c @@ -173,7 +173,7 @@ int _wolfssl_tls_update_fd(struct tcp_connection *c, int fd) } int _wolfssl_tls_conn_init(struct tcp_connection* c, - struct tls_domain *tls_dom, const struct sockaddr_hu *hu) + struct tls_domain *tls_dom, const struct host_sock_info *hu) { /* * new connection within a single process, no lock necessary diff --git a/modules/tm/dlg.h b/modules/tm/dlg.h index ce35d86287a..edc2bcdaa69 100644 --- a/modules/tm/dlg.h +++ b/modules/tm/dlg.h @@ -32,6 +32,7 @@ #include "../../str.h" #include "../../parser/parse_rr.h" #include "../../parser/msg_parser.h" +#include "../../net/dest_info.h" #include "h_table.h" @@ -97,7 +98,7 @@ typedef struct dlg { str loc_uri; /* Local URI */ str rem_uri; /* Remote URI */ str obp; /* Outbound proxy */ - struct sockaddr_hu forced_to_hu; /* Forced remote sockaddr */ + struct host_sock_info 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/h_table.h b/modules/tm/h_table.h index 2d367681e78..889de31444e 100644 --- a/modules/tm/h_table.h +++ b/modules/tm/h_table.h @@ -58,6 +58,7 @@ struct retr_buf; #include "t_reply.h" #include "t_hooks.h" #include "timer.h" +#include "../../net/dest_info.h" #define LOCK_HASH(_h) lock_hash((_h)) #define UNLOCK_HASH(_h) unlock_hash((_h)) diff --git a/modules/tm/uac.c b/modules/tm/uac.c index a673ef99a8a..28aca8c945f 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; - struct sockaddr_hu new_to_hu; + struct host_sock_info new_to_hu; struct socket_info *new_send_sock; unsigned short dst_changed; char *buf1=NULL, *sipmsg_buf; @@ -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) { - struct sockaddr_hu to_hu; + struct host_sock_info to_hu; struct cell *new_cell; struct retr_buf *request; struct sip_msg *req = NULL; diff --git a/modules/tracer/tracer.c b/modules/tracer/tracer.c index fbc9734ecfe..2c64dcd9aa4 100644 --- a/modules/tracer/tracer.c +++ b/modules/tracer/tracer.c @@ -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, - const struct sockaddr_hu *to, struct socket_info *sock, int proto); + const struct host_sock_info *to, struct socket_info *sock, int proto); static void trace_slreply_out(struct sip_msg* req, str *buffer,int rpl_code, - const struct sockaddr_hu *dst, struct socket_info *sock, int proto); + const struct host_sock_info *dst, struct socket_info *sock, int proto); #if 0 static void trace_slack_in(struct sip_msg* req, str *buffer,int rpl_code, @@ -2304,7 +2304,7 @@ 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, - const struct sockaddr_hu *to_hu, struct socket_info *sock, int proto) + const struct host_sock_info *to_hu, struct socket_info *sock, int proto) { trace_info_p info; const union sockaddr_union *to = to_hu ? &to_hu->su : NULL; @@ -2318,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, - const struct sockaddr_hu *dst, struct socket_info *sock, int proto) + const struct host_sock_info *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]; @@ -3423,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) { - struct sockaddr_hu* to; + struct host_sock_info* to; struct socket_info* send_sock; struct proxy_l * p; int proto; @@ -3435,7 +3435,7 @@ static int trace_send_duplicate(char *buf, int len, struct sip_uri *uri) if(uri==NULL) return 0; - to=(struct sockaddr_hu*)pkg_malloc(sizeof(*to)); + to=(struct host_sock_info*)pkg_malloc(sizeof(*to)); if (to==0){ LM_ERR("out of pkg memory\n"); return -1; diff --git a/net/api_proto.h b/net/api_proto.h index 5efbcbf9818..2f0a3599045 100644 --- a/net/api_proto.h +++ b/net/api_proto.h @@ -30,9 +30,11 @@ #define PROTO_PREFIX "proto_" +struct host_sock_info; + typedef int (*proto_init_listener_f)(struct socket_info *si); typedef int (*proto_send_f)(struct socket_info *si, char* buf,unsigned int len, - const struct sockaddr_hu* to, int unsigned id); + const struct host_sock_info* to, int unsigned id); typedef int (*proto_dst_attr_f)(struct receive_info *rcv, int attr, void *value); diff --git a/net/api_proto_net.h b/net/api_proto_net.h index b2904e92fe7..eba010f3994 100644 --- a/net/api_proto_net.h +++ b/net/api_proto_net.h @@ -35,7 +35,7 @@ typedef int (*proto_net_write_f)(void *src, int fd); typedef int (*proto_net_read_f)(void *src, int *len); -typedef int (*proto_net_conn_init_f)(struct tcp_connection *c, const struct sockaddr_hu *hu); +typedef int (*proto_net_conn_init_f)(struct tcp_connection *c, const struct host_sock_info *hu); typedef void (*proto_net_conn_clean_f)(struct tcp_connection *c); typedef int (*proto_net_extra_match_f)(struct tcp_connection *c, void *id); typedef void (*proto_net_report_f)( int type, unsigned long long conn_id, diff --git a/net/dest_info.h b/net/dest_info.h new file mode 100644 index 00000000000..c48e907c643 --- /dev/null +++ b/net/dest_info.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2001-2003 FhG Fokus + * + * This file is part of opensips, a free SIP server. + * + * opensips is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * opensips is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "host_sock_info.h" + +struct dest_info { + int proto; + unsigned int proto_reserved1; /*!< tcp stores the connection id here */ + struct host_sock_info to; + struct socket_info* send_sock; +}; diff --git a/net/host_sock_info.h b/net/host_sock_info.h new file mode 100644 index 00000000000..61ada83788f --- /dev/null +++ b/net/host_sock_info.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2023 Sippy Software, Inc. + * + * This file is part of opensips, a free SIP server. + * + * opensips is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * opensips is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include + +#include "../ip_addr.h" + +struct host_sock_info{ + union sockaddr_union su; +#if 0 + const str_const *hp; +#endif + struct { + str_const hoststr; + char hostname[MAX_DNS_NAME]; + } _; +}; + +static inline int hostent2hu( struct host_sock_info *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; +#if 0 + hu->hp = &hu->_.hoststr; +#endif + } + return r; +} + +static inline void hu_dup(const struct host_sock_info *hu_s, struct host_sock_info *hu_d) +{ + if (hu_s->_.hoststr.len > 0) { + memcpy(hu_d, hu_s, sizeof(*hu_d)); + hu_d->_.hoststr.s = hu_d->_.hostname; +#if 0 + hu_d->hp = &hu_d->_.hoststr; +#endif + } else { + memcpy(hu_d, hu_s, sizeof(*hu_d) - offsetof(struct host_sock_info, _)); + } +} + +static inline const str_const hu_gethost(const struct host_sock_info *hu) +{ + + if (hu == NULL || hu->_.hoststr.len == 0) + return str_const_init(""); + return hu->_.hoststr; +} diff --git a/net/net_tcp.c b/net/net_tcp.c index 1844a34f371..8882760003b 100644 --- a/net/net_tcp.c +++ b/net/net_tcp.c @@ -60,6 +60,7 @@ #include "tcp_conn_profile.h" #include "trans.h" #include "net_tcp_dbg.h" +#include "host_sock_info.h" struct struct_hist_list *con_hist; @@ -951,7 +952,7 @@ static struct tcp_connection* tcpconn_new(int sock, const union sockaddr_union* * 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, const struct sockaddr_hu* hu, +struct tcp_connection* tcp_conn_create(int sock, const struct host_sock_info* hu, struct socket_info* si, struct tcp_conn_profile *prof, int state, int send2main) { diff --git a/net/net_tcp.h b/net/net_tcp.h index 0c2d137918d..8b6e60bc53a 100644 --- a/net/net_tcp.h +++ b/net/net_tcp.h @@ -32,6 +32,8 @@ #define TCP_PARTITION_SIZE 32 +struct host_sock_info; + extern int tcp_workers_max_no; /**************************** Control functions ******************************/ @@ -90,7 +92,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, const struct sockaddr_hu *su, +struct tcp_connection* tcp_conn_create(int sock, const struct host_sock_info *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 131159a32a4..dfe8e08e482 100644 --- a/net/proto_tcp/proto_tcp.c +++ b/net/proto_tcp/proto_tcp.c @@ -41,6 +41,7 @@ #include "../../tsend.h" #include "../../trace_api.h" #include "../../net/net_tcp_dbg.h" +#include "../../net/host_sock_info.h" #include "tcp_common_defs.h" #include "proto_tcp_handler.h" @@ -53,7 +54,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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); inline static int _tcp_write_on_socket(struct tcp_connection *c, int fd, char *buf, int len); @@ -362,7 +363,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, - const struct sockaddr_hu* to_hu, unsigned int id) + const struct host_sock_info* to_hu, unsigned int id) { struct tcp_connection *c; struct tcp_conn_profile prof; diff --git a/net/proto_udp/proto_udp.c b/net/proto_udp/proto_udp.c index 662c64b42a9..97ada8e9ab2 100644 --- a/net/proto_udp/proto_udp.c +++ b/net/proto_udp/proto_udp.c @@ -34,6 +34,7 @@ #include "../../timer.h" #include "../../socket_info.h" #include "../../receive.h" +#include "../../net/host_sock_info.h" #include "../api_proto.h" #include "../api_proto_net.h" #include "../net_udp.h" @@ -44,7 +45,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, const struct sockaddr_hu* to, + char* buf, unsigned int len, const struct host_sock_info* to, unsigned int id); static int udp_read_req(struct socket_info *src, int* bytes_read); @@ -199,7 +200,7 @@ 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, const struct sockaddr_hu* to_hu, + char* buf, unsigned int len, const struct host_sock_info* to_hu, unsigned int id) { int n, tolen; diff --git a/net/tcp_common.c b/net/tcp_common.c index da8127286d7..4007d0ed812 100644 --- a/net/tcp_common.c +++ b/net/tcp_common.c @@ -23,6 +23,7 @@ #include "net_tcp.h" #include "tcp_common.h" #include "tcp_conn_profile.h" +#include "host_sock_info.h" #include "../tsend.h" /*! \brief blocking connect on a non-blocking fd; it will timeout after @@ -140,7 +141,7 @@ int tcp_connect_blocking(int fd, const struct sockaddr *servaddr, tcp_connect_timeout); } -int tcp_sync_connect_fd(union sockaddr_union* src, const struct sockaddr_hu* hup, +int tcp_sync_connect_fd(union sockaddr_union* src, const struct host_sock_info* hup, enum sip_protos proto, struct tcp_conn_profile *prof, enum si_flags flags) { int s; @@ -183,7 +184,7 @@ int tcp_sync_connect_fd(union sockaddr_union* src, const struct sockaddr_hu* hu } struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, - const struct sockaddr_hu * server, struct tcp_conn_profile *prof, + const struct host_sock_info * server, struct tcp_conn_profile *prof, int *fd, int send2main) { struct tcp_connection* con; @@ -204,7 +205,7 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, } int tcp_async_connect(struct socket_info* send_sock, - const struct sockaddr_hu* server_hu, struct tcp_conn_profile *prof, + const struct host_sock_info* server_hu, struct tcp_conn_profile *prof, int timeout, struct tcp_connection** c, int *ret_fd, int send2main) { int fd, n; diff --git a/net/tcp_common.h b/net/tcp_common.h index 426f97ef4d6..0217a940b0f 100644 --- a/net/tcp_common.h +++ b/net/tcp_common.h @@ -21,6 +21,8 @@ #ifndef _NET_TCP_COMMON_H_ #define _NET_TCP_COMMON_H_ +struct host_sock_info; + /* blocking connect on a non-blocking socket */ int tcp_connect_blocking(int s, const struct sockaddr *servaddr, socklen_t addrlen); @@ -30,11 +32,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, const struct sockaddr_hu* dst, +int tcp_sync_connect_fd(union sockaddr_union* src, const struct host_sock_info* 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, - const struct sockaddr_hu* server, struct tcp_conn_profile *prof, + const struct host_sock_info* server, struct tcp_conn_profile *prof, int *fd, int send2main); /* Attempts do a connect to the given destination. It returns: @@ -43,7 +45,7 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, * -1 - error */ int tcp_async_connect(struct socket_info* send_sock, - const struct sockaddr_hu* server, struct tcp_conn_profile *prof, + const struct host_sock_info* 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/proxy.h b/proxy.h index d4943baf57b..c1c352cec79 100644 --- a/proxy.h +++ b/proxy.h @@ -31,6 +31,7 @@ #include #include "ip_addr.h" #include "str.h" +#include "net/host_sock_info.h" struct dns_node; diff --git a/resolve.c b/resolve.c index 6b15bfd3c4b..6f197a1d02a 100644 --- a/resolve.c +++ b/resolve.c @@ -2011,7 +2011,7 @@ void free_dns_res( struct proxy_l *p ) -int get_next_hu(struct proxy_l *p, struct sockaddr_hu* hu, int add_to_bl) +int get_next_hu(struct proxy_l *p, struct host_sock_info* hu, int add_to_bl) { struct hostent *he; struct bl_rule *list; diff --git a/resolve.h b/resolve.h index f5a282eed01..b0dfc5777bf 100644 --- a/resolve.h +++ b/resolve.h @@ -185,7 +185,7 @@ void free_dns_res( struct proxy_l *p ); struct dns_node *dns_res_copy(struct dns_node *s); /*! \brief taked the next destination from a resolver state machine */ -int get_next_hu(struct proxy_l *p, struct sockaddr_hu* su, int add_to_bl); +int get_next_hu(struct proxy_l *p, struct host_sock_info* su, int add_to_bl); int resolv_init(); diff --git a/sl_cb.c b/sl_cb.c index 64cf02452d8..2b5fb33ba08 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, - const struct sockaddr_hu *dst, int rpl_code) + const struct host_sock_info *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, - const struct sockaddr_hu *dst, struct socket_info *sock, int proto) + const struct host_sock_info *dst, struct socket_info *sock, int proto) { struct sl_callback *cbp; diff --git a/sl_cb.h b/sl_cb.h index bc9e9ec658a..355e20286e4 100644 --- a/sl_cb.h +++ b/sl_cb.h @@ -30,13 +30,14 @@ #include "ip_addr.h" #include "parser/msg_parser.h" +struct host_sock_info; enum sl_cb_type {SLCB_REPLY_OUT=0, SLCB_ACK_IN, SLCB_REQUEST_OUT, SLCB_LAST }; /* callback function prototype */ typedef void (sl_cb_t) (struct sip_msg* req, str *buffer, int rpl_code, - const struct sockaddr_hu *dst, struct socket_info *sock, int proto); + const struct host_sock_info *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 +52,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, - const struct sockaddr_hu *dst, int rpl_code); + const struct host_sock_info *dst, int rpl_code); void slcb_run_ack_in(struct sip_msg *req); void slcb_run_req_out(struct sip_msg *req, str *buffer, - const struct sockaddr_hu *dst, struct socket_info *sock, int proto); + const struct host_sock_info *dst, struct socket_info *sock, int proto); #endif