Skip to content

Commit

Permalink
Move out dest_info and host_sock_info into their own TUs.
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed Nov 30, 2023
1 parent a3a5a31 commit 142e502
Show file tree
Hide file tree
Showing 59 changed files with 261 additions and 174 deletions.
4 changes: 2 additions & 2 deletions core_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -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: \
Expand All @@ -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;
Expand Down
62 changes: 4 additions & 58 deletions ip_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#ifndef ip_addr_h
#define ip_addr_h

#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -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 };
Expand All @@ -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;
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/cgrates/cgrates_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions modules/clusterer/clusterer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions modules/clusterer/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion modules/dispatcher/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/drouting/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modules/load_balancer/lb_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion modules/nat_traversal/nat_traversal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions modules/nathelper/nathelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions modules/proto_bin/proto_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions modules/proto_bins/proto_bins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 142e502

Please sign in to comment.