diff --git a/core_cmds.c b/core_cmds.c index 32b569f0d17..43b12aad879 100644 --- a/core_cmds.c +++ b/core_cmds.c @@ -498,7 +498,7 @@ static int fixup_f_send_sock(void** param) str host, host_nt; int proto=PROTO_NONE, port; struct hostent* he; - struct socket_info* si; + const struct socket_info* si; struct ip_addr ip; if (parse_phostport(s->s, s->len, &host.s, &host.len, &port, &proto) != 0) { @@ -526,7 +526,8 @@ static int fixup_f_send_sock(void** param) pkg_free(host_nt.s); - *param = si; + const void **_param = (const void **)param; + *_param = si; return 0; error: @@ -1056,7 +1057,7 @@ static int w_set_adv_port(struct sip_msg *msg, str *adv_port) static int w_f_send_sock(struct sip_msg *msg, struct socket_info *si) { - msg->force_send_socket=si; + msg->force_send_socket=(const struct socket_info *)si; return 1; } diff --git a/dset.c b/dset.c index 98a3b593d71..b636d01e721 100644 --- a/dset.c +++ b/dset.c @@ -62,7 +62,7 @@ struct branch unsigned int path_len; int q; /* Preference of the contact among contact within the array */ - struct socket_info* force_send_socket; + const struct socket_info* force_send_socket; unsigned int flags; }; @@ -220,7 +220,7 @@ void set_dset_state(unsigned char enable) * more branches */ char* get_branch(unsigned int idx, int* len, qvalue_t* q, str* dst_uri, - str* path, unsigned int *flags, struct socket_info** force_socket) + str* path, unsigned int *flags, const struct socket_info** force_socket) { struct dset_ctx *dsct = get_dset_ctx(); struct branch *branches; @@ -275,7 +275,7 @@ void clear_branches(void) * Add a new branch to current transaction */ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, - qvalue_t q, unsigned int flags, struct socket_info* force_socket) + qvalue_t q, unsigned int flags, const struct socket_info* force_socket) { str luri; int nr_branches; @@ -382,7 +382,7 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, * Updates one or more fields of an already appended branch */ int update_branch(unsigned int idx, str** uri, str** dst_uri, str** path, - qvalue_t* q, unsigned int* flags, struct socket_info** force_socket) + qvalue_t* q, unsigned int* flags, const struct socket_info** force_socket) { struct dset_ctx *dsct = get_dset_ctx(); struct branch *branches; diff --git a/dset.h b/dset.h index c265cf21aa5..66afe747402 100644 --- a/dset.h +++ b/dset.h @@ -43,7 +43,7 @@ int init_dset(void); * Add a new branch to current transaction */ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, - qvalue_t q, unsigned int flags, struct socket_info* force_socket); + qvalue_t q, unsigned int flags, const struct socket_info* force_socket); @@ -51,14 +51,14 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, * Updates an already created branches */ int update_branch(unsigned int idx, str** uri, str** dst_uri, str** path, - qvalue_t* q, unsigned int* flags, struct socket_info** force_socket); + qvalue_t* q, unsigned int* flags, const struct socket_info** force_socket); /*! \brief * Get the next branch in the current transaction */ char* get_branch( unsigned int idx, int* len, qvalue_t* q, str* dst_uri, - str* path, unsigned int *flags, struct socket_info** force_socket); + str* path, unsigned int *flags, const struct socket_info** force_socket); /*! \brief diff --git a/forward.c b/forward.c index 7a87d714c1e..98ce0d03fb5 100644 --- a/forward.c +++ b/forward.c @@ -90,12 +90,12 @@ * 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) +const struct socket_info* get_out_socket(const union sockaddr_union* to, int proto) { int temp_sock; socklen_t len; union sockaddr_union from; - struct socket_info* si; + const struct socket_info* si; struct ip_addr ip, ip_dst; if (proto!=PROTO_UDP) { @@ -142,10 +142,10 @@ 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 struct socket_info* get_send_socket(struct sip_msg *msg, + const union sockaddr_union* to, int proto) { - struct socket_info* send_sock; + const struct socket_info* send_sock; /* check if send interface is not forced */ if (msg && msg->force_send_socket){ @@ -308,8 +308,8 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) { union sockaddr_union to; str buf; - struct socket_info* send_sock; - struct socket_info* last_sock; + const struct socket_info* send_sock; + const struct socket_info* last_sock; buf.s=NULL; @@ -473,7 +473,7 @@ int forward_reply(struct sip_msg* msg) struct sr_module *mod; int proto; unsigned int id; /* used only by tcp*/ - struct socket_info *send_sock; + const struct socket_info *send_sock; char* s; int len; diff --git a/forward.h b/forward.h index 37005982989..d064a7a9c60 100644 --- a/forward.h +++ b/forward.h @@ -47,9 +47,9 @@ #include "net/trans.h" #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 struct socket_info* get_send_socket(struct sip_msg* msg, + const union sockaddr_union* su, int proto); +const 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, @@ -81,7 +81,7 @@ int forward_reply( struct sip_msg* msg); * \param len - the length of the message to be sent * \return 0 if ok, -1 on error */ -static inline int msg_send( struct socket_info* send_sock, int proto, +static inline int msg_send( const struct socket_info* send_sock, int proto, union sockaddr_union* to, unsigned int id, char* buf, int len, struct sip_msg* msg) { diff --git a/globals.c b/globals.c index f418205c638..724d4f18b3b 100644 --- a/globals.c +++ b/globals.c @@ -138,7 +138,7 @@ int mcast_ttl = -1; /* if -1, don't touch it, use the default (usually 1) */ int tos = IPTOS_LOWDELAY; // lgtm [cpp/short-global-name] -struct socket_info* bind_address=NULL; /* pointer to the crt. proc. +const struct socket_info* bind_address=NULL; /* pointer to the crt. proc. listening address*/ /* if aliases should be automatically discovered and added diff --git a/globals.h b/globals.h index f3b0008ce26..daa4e27f513 100644 --- a/globals.h +++ b/globals.h @@ -44,7 +44,7 @@ extern char *stat_file; extern char* pid_file; extern char* pgid_file; -extern struct socket_info* bind_address; /*!< pointer to the crt. proc. listening address */ +extern const struct socket_info* bind_address; /*!< pointer to the crt. proc. listening address */ extern int auto_aliases; diff --git a/ip_addr.c b/ip_addr.c index 1b5b7498d73..8dbac458954 100644 --- a/ip_addr.c +++ b/ip_addr.c @@ -40,7 +40,7 @@ char _ip_addr_A_buffs[IP_ADDR2STR_BUF_NO][IP_ADDR_MAX_STR_SIZE]; -struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask) +struct net* mk_net(const struct ip_addr* ip, struct ip_addr* mask) { struct net* n; int warning; @@ -78,7 +78,7 @@ struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask) -struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen) +struct net* mk_net_bitlen(const struct ip_addr* ip, unsigned int bitlen) { struct ip_addr mask; unsigned int r; @@ -100,7 +100,7 @@ struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen) -void print_ip(char* p, struct ip_addr* ip, char *s) +void print_ip(char* p, const struct ip_addr* ip, char *s) { switch(ip->af){ case AF_INET: diff --git a/ip_addr.h b/ip_addr.h index 8b9be14888c..20323068186 100644 --- a/ip_addr.h +++ b/ip_addr.h @@ -100,7 +100,7 @@ struct receive_info { unsigned int proto_reserved1; /*!< tcp stores the connection id here */ unsigned int proto_reserved2; union sockaddr_union src_su; /*!< useful for replies*/ - struct socket_info* bind_address; /*!< sock_info structure on which the msg was received*/ + const struct socket_info* bind_address; /*!< sock_info structure on which the msg was received*/ /* no need for dst_su yet */ }; @@ -109,7 +109,7 @@ struct dest_info { int proto; unsigned int proto_reserved1; /*!< tcp stores the connection id here */ union sockaddr_union to; - struct socket_info* send_sock; + const struct socket_info* send_sock; }; @@ -171,12 +171,12 @@ struct socket_id { * we rely here on the fact at all the SIP protos are in a sequance */ #define is_sip_proto(_proto) (PROTO_UDP<=(_proto) && (_proto)<=PROTO_WSS) -struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask); -struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen); +struct net* mk_net(const struct ip_addr* ip, struct ip_addr* mask); +struct net* mk_net_bitlen(const struct ip_addr* ip, unsigned int bitlen); /* parse a (struct net) out of a CIDR v4 or v6 address such as 1.2.3.4/28 */ int mk_net_cidr(const str *cidr, struct net *out_net); -void print_ip(char* prefix, struct ip_addr* ip, char* suffix); +void print_ip(char* prefix, const struct ip_addr* ip, char* suffix); void stdout_print_ip(struct ip_addr* ip); void print_net(struct net* net); @@ -212,7 +212,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; @@ -266,7 +266,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; @@ -298,7 +298,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: @@ -326,7 +326,7 @@ static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su) * \return 0 if ok, -1 on error (unknown address family) * \note the port number is in host byte order */ static inline int init_su( union sockaddr_union* su, - struct ip_addr* ip, + const struct ip_addr* ip, unsigned short port ) { memset(su, 0, sizeof(union sockaddr_union));/*needed on freebsd*/ @@ -360,7 +360,7 @@ static inline int init_su( union sockaddr_union* su, * 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, + const struct hostent* he, unsigned int idx, unsigned short port ) { diff --git a/mi/mi_trace.c b/mi/mi_trace.c index 2e013a77ce4..99dcab355f4 100644 --- a/mi/mi_trace.c +++ b/mi/mi_trace.c @@ -130,7 +130,7 @@ char* generate_correlation_id(int* len) } -int trace_mi_message(union sockaddr_union* src, union sockaddr_union* dst, +int trace_mi_message(const union sockaddr_union* src, const union sockaddr_union* dst, struct mi_trace_param* pld_param, str* correlation_val, trace_dest trace_dst) { /* FIXME is this the case for all mi impelementations?? */ diff --git a/mi/mi_trace.h b/mi/mi_trace.h index c88ff8fd85b..658792b28ee 100644 --- a/mi/mi_trace.h +++ b/mi/mi_trace.h @@ -55,7 +55,7 @@ extern struct mi_trace_param mi_tparam; void try_load_trace_api(void); -int trace_mi_message(union sockaddr_union* src, union sockaddr_union* dst, +int trace_mi_message(const union sockaddr_union* src, const union sockaddr_union* dst, struct mi_trace_param* pld_param, str* correlation_value, trace_dest trace_dst); struct mi_trace_req* build_mi_trace_request(str *cmd, mi_item_t *params, @@ -65,7 +65,7 @@ str *build_mi_trace_reply(str *rpl_msg); char* generate_correlation_id(int* len);; int load_correlation_id(void); -static inline void mi_trace_reply( union sockaddr_union* src, union sockaddr_union* dst, +static inline void mi_trace_reply( const union sockaddr_union* src, const union sockaddr_union* dst, str* message, trace_dest t_dst) { /* trace disabled */ @@ -91,7 +91,7 @@ static inline void mi_trace_reply( union sockaddr_union* src, union sockaddr_uni } -static inline void mi_trace_request( union sockaddr_union* src, union sockaddr_union* dst, +static inline void mi_trace_request( const union sockaddr_union* src, const union sockaddr_union* dst, char* command, int len, mi_item_t *params, str* backend, trace_dest t_dst ) { str comm_s = { command, len }; diff --git a/modules/b2b_entities/b2be_clustering.c b/modules/b2b_entities/b2be_clustering.c index df157f21ada..7867f7c6b19 100644 --- a/modules/b2b_entities/b2be_clustering.c +++ b/modules/b2b_entities/b2be_clustering.c @@ -315,9 +315,9 @@ void replicate_entity_delete(b2b_dlg_t *dlg, int etype, unsigned int hash_index, return; } -static struct socket_info *fetch_socket_info(str *addr) +static const struct socket_info *fetch_socket_info(str *addr) { - struct socket_info *sock; + const struct socket_info *sock; if (!addr || !addr->len) return NULL; diff --git a/modules/b2b_entities/b2be_load.h b/modules/b2b_entities/b2be_load.h index 40b9b5c80e3..063c8106e5b 100644 --- a/modules/b2b_entities/b2be_load.h +++ b/modules/b2b_entities/b2be_load.h @@ -75,8 +75,8 @@ typedef struct client_info str local_contact; unsigned int cseq; unsigned int maxfwd; - struct socket_info* send_sock; - struct socket_info* pref_sock; + const struct socket_info* send_sock; + const struct socket_info* pref_sock; struct usr_avp *avps; }client_info_t; diff --git a/modules/b2b_entities/dlg.h b/modules/b2b_entities/dlg.h index 3cccb5cebdc..b8d5488ad44 100644 --- a/modules/b2b_entities/dlg.h +++ b/modules/b2b_entities/dlg.h @@ -110,7 +110,7 @@ typedef struct b2b_dlg struct cell* prack_tran; struct cell* cancel_tm_tran; dlg_leg_t* legs; - struct socket_info* send_sock; + const struct socket_info* send_sock; unsigned int last_reply_code; int db_flag; int replicated; diff --git a/modules/b2b_logic/logic.c b/modules/b2b_logic/logic.c index 70d3575d034..b95ba86def6 100644 --- a/modules/b2b_logic/logic.c +++ b/modules/b2b_logic/logic.c @@ -475,7 +475,7 @@ void b2b_mark_todel( b2bl_tuple_t* tuple) int b2b_get_local_contact(struct sip_msg *msg, str *from_uri, str *local_contact) { struct sip_uri ct_uri; - struct socket_info *send_sock = msg ? + const struct socket_info *send_sock = msg ? (msg->force_send_socket?msg->force_send_socket:msg->rcv.bind_address):NULL; if (server_address.len) { diff --git a/modules/b2b_sdp_demux/b2b_sdp_demux.c b/modules/b2b_sdp_demux/b2b_sdp_demux.c index 53b5c3d4a69..793a42e10b6 100644 --- a/modules/b2b_sdp_demux/b2b_sdp_demux.c +++ b/modules/b2b_sdp_demux/b2b_sdp_demux.c @@ -1673,8 +1673,8 @@ static int b2b_sdp_demux_start(struct sip_msg *msg, str *uri, struct list_head *it; struct b2b_sdp_client *client; client_info_t ci; - struct socket_info *si; - str *sess_ip; + const struct socket_info *si; + const str *sess_ip; if (!msg->force_send_socket) { si = uri2sock(msg, uri, &tmp_su, PROTO_NONE); diff --git a/modules/clusterer/node_info.h b/modules/clusterer/node_info.h index 3df2faaf671..e974ae1b70d 100644 --- a/modules/clusterer/node_info.h +++ b/modules/clusterer/node_info.h @@ -110,7 +110,7 @@ struct cluster_info { int no_nodes; /* number of nodes in the cluster */ struct node_info *node_list; struct node_info *current_node; /* current node's info in this cluster */ - struct socket_info *send_sock; + const struct socket_info *send_sock; gen_lock_t *lock; diff --git a/modules/dialog/dlg_db_handler.c b/modules/dialog/dlg_db_handler.c index 9deb08f4f1d..968167c661c 100644 --- a/modules/dialog/dlg_db_handler.c +++ b/modules/dialog/dlg_db_handler.c @@ -294,9 +294,9 @@ static int select_entire_dialog_table(db_res_t ** res, int *no_rows) -struct socket_info * create_socket_info(db_val_t * vals, int n){ +const struct socket_info * create_socket_info(db_val_t * vals, int n){ - struct socket_info * sock; + const struct socket_info * sock; str p; /* socket name */ @@ -571,7 +571,7 @@ static int load_dialog_info_from_db(int dlg_hash_size) str callid, from_uri, to_uri, from_tag, to_tag; str cseq1,cseq2,contact1,contact2,rroute1,rroute2,mangled_fu,mangled_tu; int no_rows = 10; - struct socket_info *caller_sock,*callee_sock; + const struct socket_info *caller_sock,*callee_sock; int found_ended_dlgs=0; unsigned int hash_entry,hash_id; int_str tag_name; @@ -1874,7 +1874,7 @@ static int sync_dlg_db_mem(void) int no_rows = 10; unsigned int db_caller_cseq = 0, db_callee_cseq = 0; unsigned int dlg_caller_cseq = 0, dlg_callee_cseq = 0; - struct socket_info *caller_sock,*callee_sock; + const struct socket_info *caller_sock,*callee_sock; str callid, from_uri, to_uri, from_tag, to_tag; str cseq1,cseq2,contact1,contact2,rroute1,rroute2,mangled_fu,mangled_tu; unsigned int hash_entry, hash_id; diff --git a/modules/dialog/dlg_hash.c b/modules/dialog/dlg_hash.c index a90a10bf4a0..dee16cdacca 100644 --- a/modules/dialog/dlg_hash.c +++ b/modules/dialog/dlg_hash.c @@ -393,7 +393,7 @@ int dlg_clone_callee_leg(struct dlg_cell *dlg, int cloned_leg_idx) } -static inline int translate_contact_ipport( str *ct, struct socket_info *sock, +static inline int translate_contact_ipport( str *ct, const struct socket_info *sock, str *dst) { struct hdr_field ct_hdr; @@ -401,7 +401,7 @@ static inline int translate_contact_ipport( str *ct, struct socket_info *sock, contact_t *c; struct sip_uri puri; str hostport; - str *send_address_str, *send_port_str; + const str *send_address_str, *send_port_str; char *p; /* rely on the fact that the replicated hdr is well formated, so @@ -487,7 +487,7 @@ static inline int translate_contact_ipport( str *ct, struct socket_info *sock, be no leg allocated, so automatically CALLER gets the first position, while the CALLEE legs will follow into the array in the same order they came */ int dlg_update_leg_info(int leg_idx, struct dlg_cell *dlg, str* tag, str *rr, - str *contact, str *adv_ct, str *cseq, struct socket_info *sock, + str *contact, str *adv_ct, str *cseq, const struct socket_info *sock, str *mangled_from,str *mangled_to,str *in_sdp, str *out_sdp) { struct dlg_leg *leg; diff --git a/modules/dialog/dlg_hash.h b/modules/dialog/dlg_hash.h index cdd15537832..c22021d2640 100644 --- a/modules/dialog/dlg_hash.h +++ b/modules/dialog/dlg_hash.h @@ -111,7 +111,7 @@ struct dlg_leg { struct dlg_leg_cseq_map *cseq_maps; /* used when translating ACKs */ char reply_received; char reinvite_confirmed; - struct socket_info *bind_addr; + const struct socket_info *bind_addr; }; #define leg_is_answered(dlg_leg) ((dlg_leg)->tag.s) @@ -409,7 +409,7 @@ struct dlg_cell* build_new_dlg(str *callid, str *from_uri, int dlg_clone_callee_leg(struct dlg_cell *dlg, int cloned_leg_idx); int dlg_update_leg_info(int leg_idx, struct dlg_cell *dlg, str* tag, str *rr, - str *contact, str *adv_ct, str *cseq, struct socket_info *sock, + str *contact, str *adv_ct, str *cseq, const struct socket_info *sock, str *mangled_from,str *mangled_to,str *in_sdp, str *out_sdp); int dlg_update_cseq(struct dlg_cell *dlg, unsigned int leg, str *cseq, diff --git a/modules/dialog/dlg_replication.c b/modules/dialog/dlg_replication.c index 7e32222cd6f..ed532ebdec5 100644 --- a/modules/dialog/dlg_replication.c +++ b/modules/dialog/dlg_replication.c @@ -49,9 +49,9 @@ char *dlg_sync_in_progress; static int get_shtag_sync_status(struct dlg_cell *dlg); -static struct socket_info * fetch_socket_info(str *addr) +const static struct socket_info * fetch_socket_info(str *addr) { - struct socket_info *sock; + const struct socket_info *sock; if (!addr || !addr->len) return NULL; sock = parse_sock_info(addr); @@ -176,7 +176,7 @@ int dlg_replicated_create(bin_packet_t *packet, struct dlg_cell *cell, str sdp1, sdp2, sdp3, sdp4; str sock, vars, profiles; struct dlg_cell *dlg = NULL; - struct socket_info *caller_sock, *callee_sock; + const struct socket_info *caller_sock, *callee_sock; struct dlg_entry *d_entry; int_str tag_name; unsigned int h_id; diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 2abd57e2a89..89e13c7975e 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -57,7 +57,7 @@ extern ds_partition_t *partitions; -extern struct socket_info *probing_sock; +extern const struct socket_info *probing_sock; extern event_id_t dispatch_evi_id; extern ds_partition_t *default_partition; @@ -174,7 +174,7 @@ void ds_destroy_data(ds_partition_t *partition) } -int add_dest2list(int id, str uri, struct socket_info *sock, str *comsock, int state, +int add_dest2list(int id, str uri, const struct socket_info *sock, str *comsock, int state, int weight, int prio, int probe_mode, str attrs, str description, ds_data_t *d_data) { ds_dest_p dp = NULL; @@ -1010,7 +1010,7 @@ static ds_data_t* ds_load_data(ds_partition_t *partition) int weight; int prio; int probe_mode; - struct socket_info *sock; + const struct socket_info *sock; str uri; str attrs, weight_st; str description; @@ -1597,7 +1597,7 @@ static inline int ds_get_index(int group, ds_set_p *index, } -int ds_update_dst(struct sip_msg *msg, str *uri, struct socket_info *sock, +int ds_update_dst(struct sip_msg *msg, str *uri, const struct socket_info *sock, int mode) { uri_type utype; @@ -2099,7 +2099,7 @@ int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, int ds_next_dst(struct sip_msg *msg, int mode, ds_partition_t *partition) { - struct socket_info *sock; + const struct socket_info *sock; struct usr_avp *avp; struct usr_avp *tmp_avp; struct usr_avp *attr_avp; @@ -2662,7 +2662,7 @@ void ds_check_timer(unsigned int ticks, void* param) * to free the whole structure here */ ds_options_callback_param_t params; - struct socket_info *sock; + const struct socket_info *sock; struct usr_avp *avps; struct gw_prob_pack *next; diff --git a/modules/dispatcher/dispatch.h b/modules/dispatcher/dispatch.h index 531d637e2b5..7e746921ce2 100644 --- a/modules/dispatcher/dispatch.h +++ b/modules/dispatcher/dispatch.h @@ -73,7 +73,7 @@ typedef struct _ds_dest unsigned short running_weight; unsigned short active_running_weight; unsigned short priority; - struct socket_info *sock; + const struct socket_info *sock; struct ip_addr ips[DS_MAX_IPS]; /* IP-Address of the entry */ unsigned short int ports[DS_MAX_IPS]; /* Port of the request URI */ unsigned short int protos[DS_MAX_IPS]; /* Protocol of the request URI */ @@ -171,7 +171,7 @@ typedef struct typedef struct _ds_selected_dst { str uri; - struct socket_info *socket; + const struct socket_info *socket; } ds_selected_dst, *ds_selected_dst_p; extern str ds_set_id_col; @@ -216,7 +216,7 @@ int ds_reload_db(ds_partition_t *partition, int initial, int is_inherit_state); int init_ds_data(ds_partition_t *partition); void ds_destroy_data(ds_partition_t *partition); -int ds_update_dst(struct sip_msg *msg, str *uri, struct socket_info *sock, int mode); +int ds_update_dst(struct sip_msg *msg, str *uri, const struct socket_info *sock, int mode); int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, ds_selected_dst_p selected_dst, int ds_flags); int ds_next_dst(struct sip_msg *msg, int mode, ds_partition_t *partition); int ds_set_state(int group, str *address, int state, int type, diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 5e49d27ef19..789ff837c21 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -162,7 +162,7 @@ static str options_reply_codes_str= {0, 0}; static int* options_reply_codes = NULL; static int options_codes_no; static str probing_sock_s; -struct socket_info *probing_sock = NULL; +const struct socket_info *probing_sock = NULL; ds_partition_t *partitions = NULL, *default_partition = NULL; diff --git a/modules/domainpolicy/domainpolicy.c b/modules/domainpolicy/domainpolicy.c index 6f59c58019f..8d0261df39d 100644 --- a/modules/domainpolicy/domainpolicy.c +++ b/modules/domainpolicy/domainpolicy.c @@ -712,7 +712,7 @@ int dp_apply_policy(struct sip_msg* _msg, char* _s1, char* _s2) { int len, didsomething; char *at; /* pointer to current location inside duri */ - struct socket_info* si; + const struct socket_info* si; if (route_type != REQUEST_ROUTE) { LM_ERR("unsupported route type\n"); diff --git a/modules/drouting/dr_load.c b/modules/drouting/dr_load.c index 946f06b92c6..a4adf349be3 100644 --- a/modules/drouting/dr_load.c +++ b/modules/drouting/dr_load.c @@ -170,7 +170,7 @@ static int add_rule(rt_data_t *rdata, char *grplst, str *prefix, } static struct head_cache_socket *get_cache_sock_info(struct head_cache *cache, - struct socket_info *old_sock) + const struct socket_info *old_sock) { struct head_cache_socket *hsock; for (hsock = cache->sockets; hsock; hsock = hsock->next) @@ -180,7 +180,7 @@ static struct head_cache_socket *get_cache_sock_info(struct head_cache *cache, } -static int add_cache_sock_info(struct head_cache *cache, struct socket_info *sock, +static int add_cache_sock_info(struct head_cache *cache, const struct socket_info *sock, str *host, int port, int proto) { struct head_cache_socket *hsock; @@ -303,7 +303,7 @@ rt_data_t* dr_load_routing_info(struct head_db *part, int discarded_gw = 0, discarded_cr = 0, discarded_rl = 0; int no_rows = 10; int db_cols; - struct socket_info *sock; + const struct socket_info *sock; str s_sock, host; int proto, port; char id_buf[INT2STR_MAX_LEN]; diff --git a/modules/drouting/drouting.c b/modules/drouting/drouting.c index 61539d2ded7..20f39d6b935 100644 --- a/modules/drouting/drouting.c +++ b/modules/drouting/drouting.c @@ -74,7 +74,7 @@ struct tm_binds dr_tmb; str dr_probe_method = str_init("OPTIONS"); str dr_probe_from = str_init("sip:prober@localhost"); static str dr_probe_sock_s; -struct socket_info *dr_probe_sock = NULL; +const struct socket_info *dr_probe_sock = NULL; static int* probing_reply_codes = NULL; static int probing_codes_no = 0; @@ -851,7 +851,7 @@ static void dr_prob_handler(unsigned int ticks, void* param) * to free the whole structure here */ param_prob_callback_t params; - struct socket_info *sock; + const struct socket_info *sock; str uri; struct gw_prob_pack *next; @@ -1584,7 +1584,7 @@ struct head_cache *get_head_cache(str *part) void fix_cache_sockets(struct head_cache *cache) { struct head_cache_socket *prev, *csock, *free; - struct socket_info *sock; + const struct socket_info *sock; prev = NULL; csock = cache->sockets; @@ -2549,7 +2549,7 @@ static int use_next_gw(struct sip_msg* msg, str ruri; int ok = 0; pgw_t * dst; - struct socket_info *sock; + const struct socket_info *sock; if(part==NULL) { LM_ERR("Partition is mandatory for use_next_gw.\n"); diff --git a/modules/drouting/prefix_tree.h b/modules/drouting/prefix_tree.h index 0d9ae98c0cb..40ccf7b78e2 100644 --- a/modules/drouting/prefix_tree.h +++ b/modules/drouting/prefix_tree.h @@ -70,7 +70,7 @@ typedef struct pgw_ { /* type of gateway */ int type; str ip_str; - struct socket_info *sock; + const struct socket_info *sock; /* strip / pri and attrs */ str pri; int strip; diff --git a/modules/drouting/routing.c b/modules/drouting/routing.c index 5a66c4fe33d..259951e5ef0 100644 --- a/modules/drouting/routing.c +++ b/modules/drouting/routing.c @@ -522,7 +522,7 @@ add_dst( /* probe_mode */ int probing, /* socket */ - struct socket_info *sock, + const struct socket_info *sock, /* state */ int state, osips_malloc_f mf, diff --git a/modules/drouting/routing.h b/modules/drouting/routing.h index 8aba1f3ca00..d4dcdd86f8c 100644 --- a/modules/drouting/routing.h +++ b/modules/drouting/routing.h @@ -70,8 +70,8 @@ struct head_cache_socket { str host; int port; int proto; - struct socket_info *old_sock; - struct socket_info *new_sock; + const struct socket_info *old_sock; + const struct socket_info *new_sock; struct head_cache_socket *next; }; @@ -120,7 +120,7 @@ add_dst( /* probe_mode */ int, /* socket */ - struct socket_info*, + const struct socket_info*, /* state */ int, osips_malloc_f mf, diff --git a/modules/emergency/sip_emergency.c b/modules/emergency/sip_emergency.c index b2bd895a9c2..8a5b64b1905 100644 --- a/modules/emergency/sip_emergency.c +++ b/modules/emergency/sip_emergency.c @@ -512,7 +512,7 @@ int check_event_header(struct sip_msg *msg) { int get_ip_socket(struct sip_msg *msg, char** saddr){ char *socket; - struct socket_info* si; + const struct socket_info* si; si = msg->rcv.bind_address; diff --git a/modules/lua/sipapi.c b/modules/lua/sipapi.c index 406b02e30fe..e9f471ffb3b 100644 --- a/modules/lua/sipapi.c +++ b/modules/lua/sipapi.c @@ -395,7 +395,7 @@ static int l_siplua_grepSockInfo(lua_State *L) { struct sip_uri puri; size_t len; - struct socket_info *si; + const struct socket_info *si; memset(&puri, '\0', sizeof(puri)); puri.host.s = (char *)luaL_checklstring(L, 1, &len); diff --git a/modules/media_exchange/media_exchange.c b/modules/media_exchange/media_exchange.c index f372b5edcfb..108a1d53f84 100644 --- a/modules/media_exchange/media_exchange.c +++ b/modules/media_exchange/media_exchange.c @@ -271,7 +271,7 @@ static int fixup_media_leg_both(void **param) return 0; } -static inline client_info_t *media_get_client_info(struct socket_info *si, +static inline client_info_t *media_get_client_info(const struct socket_info *si, str *uri, str *hdrs, str *body) { static client_info_t ci; @@ -291,7 +291,7 @@ static inline client_info_t *media_get_client_info(struct socket_info *si, return &ci; } -static int handle_media_fork_to_uri(struct media_session_leg *msl, struct socket_info *si, +static int handle_media_fork_to_uri(struct media_session_leg *msl, const struct socket_info *si, str *uri, str *headers, int medianum) { static client_info_t *ci; @@ -342,7 +342,7 @@ static int handle_media_fork_to_uri(struct media_session_leg *msl, struct socket struct media_fork_params { struct media_session_leg *msl; - struct socket_info *si; + const struct socket_info *si; str uri; str headers; int medianum; @@ -371,7 +371,7 @@ static int media_fork_to_uri(struct sip_msg *msg, str *uri, int leg, str *headers, int *medianum) { struct dlg_cell *dlg; - struct socket_info *si; + const struct socket_info *si; struct media_session_leg *msl; struct media_fork_params *mp; @@ -585,7 +585,7 @@ static void media_session_tm_free(struct media_session_tm_param *p) shm_free(p); } -static int handle_media_exchange_from_uri(struct socket_info *si, struct dlg_cell *dlg, +static int handle_media_exchange_from_uri(const struct socket_info *si, struct dlg_cell *dlg, str *uri, int leg, str *body, str *headers, int nohold, rtp_ctx ctx, struct media_session_tm_param *p) { @@ -641,7 +641,7 @@ static int media_exchange_from_uri(struct sip_msg *msg, str *uri, int leg, struct cell *t = NULL; struct dlg_cell *dlg; int req_leg; - struct socket_info *si; + const struct socket_info *si; struct media_session_tm_param *p = NULL; rtp_ctx ctx = NULL; int release = 0; @@ -1506,7 +1506,7 @@ static mi_response_t *mi_media_fork_from_call_to_uri(const mi_params_t *params, str shdrs, *hdrs; str callid, leg, uri; struct dlg_cell *dlg; - struct socket_info *si; + const struct socket_info *si; union sockaddr_union tmp; struct media_session_leg *msl; rtp_ctx ctx = NULL; @@ -1572,7 +1572,7 @@ static mi_response_t *mi_media_exchange_from_call_to_uri(const mi_params_t *para str callid, leg, uri; str body, shdrs, *hdrs, *pbody; struct dlg_cell *dlg; - struct socket_info *si; + const struct socket_info *si; union sockaddr_union tmp; rtp_ctx ctx = NULL; int release = 0; diff --git a/modules/mi_script/mi_script.c b/modules/mi_script/mi_script.c index 741502dd914..83f6f6f19f2 100644 --- a/modules/mi_script/mi_script.c +++ b/modules/mi_script/mi_script.c @@ -307,7 +307,7 @@ static mi_request_t *mi_script_parse_request(str *method, str *params, } static void trace_script_su(struct sip_msg *msg, - union sockaddr_union **src, union sockaddr_union **dst) + const union sockaddr_union **src, const union sockaddr_union **dst) { static union sockaddr_union dummy_su; if (msg) { @@ -325,7 +325,7 @@ static void trace_script_err(struct sip_msg *msg, str *method, const char *error) { str message; - union sockaddr_union *src, *dst; + const union sockaddr_union *src, *dst; trace_script_su(msg, &src, &dst); mi_trace_request(src, dst, method->s, method->len, NULL, &backend, t_dst); @@ -336,7 +336,7 @@ static void trace_script_err(struct sip_msg *msg, str *method, static void trace_script_request(struct sip_msg *msg, str *method, mi_item_t *params) { - union sockaddr_union *src, *dst; + const union sockaddr_union *src, *dst; trace_script_su(msg, &src, &dst); mi_trace_request(src, dst, method->s, method->len, params, &backend, t_dst); @@ -344,7 +344,7 @@ static void trace_script_request(struct sip_msg *msg, str *method, static void trace_script_reply(struct sip_msg *msg, str *message) { - union sockaddr_union *src, *dst; + const union sockaddr_union *src, *dst; trace_script_su(msg, &src, &dst); mi_trace_reply(src, dst, message, t_dst); } diff --git a/modules/mid_registrar/save.c b/modules/mid_registrar/save.c index 37acbf081cf..dbfe0743a11 100644 --- a/modules/mid_registrar/save.c +++ b/modules/mid_registrar/save.c @@ -121,13 +121,14 @@ void calc_ob_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, static int trim_to_single_contact(struct sip_msg *msg, str *aor, int expires) { contact_t *c = NULL; - struct socket_info *send_sock; + const struct socket_info *send_sock; struct lump *anchor = NULL; char *buf; int e, is_dereg = 1, len, len1; struct hdr_field *ct; union sockaddr_union _; - str extra_ct_params, esc_aor, *adv_host, *adv_port; + str extra_ct_params, esc_aor; + const str *adv_host, *adv_port; /* get the source socket on the way to the next hop */ send_sock = uri2sock(msg, GET_NEXT_HOP(msg), &_, PROTO_NONE); @@ -272,7 +273,7 @@ static int overwrite_req_contacts(struct sip_msg *req, urecord_t *r; ucontact_t *uc; struct sip_uri puri; - struct socket_info *send_sock; + const struct socket_info *send_sock; struct lump *anchor; str new_username; char *lump_buf; @@ -282,7 +283,8 @@ static int overwrite_req_contacts(struct sip_msg *req, struct ct_mapping *ctmap; struct list_head *_; union sockaddr_union __; - str extra_ct_params, ctid_str, *adv_host, *adv_port; + str extra_ct_params, ctid_str; + const str *adv_host, *adv_port; ul.lock_udomain(mri->dom, &mri->aor); ul.get_urecord(mri->dom, &mri->aor, &r); @@ -738,7 +740,7 @@ static inline unsigned int calc_buf_len(ucontact_t* c,int build_gruu, { unsigned int len; int qlen; - struct socket_info *sock; + const struct socket_info *sock; len = 0; while(c) { @@ -803,7 +805,7 @@ int build_contact(ucontact_t* c,struct sip_msg *_m) char *p, *cp, *tmpgr; int fl, len,grlen; int build_gruu = 0; - struct socket_info *sock; + const struct socket_info *sock; LM_DBG("building contact ...\n"); diff --git a/modules/msrp_relay/msrp_relay.c b/modules/msrp_relay/msrp_relay.c index 699dd797fe2..92935789afd 100644 --- a/modules/msrp_relay/msrp_relay.c +++ b/modules/msrp_relay/msrp_relay.c @@ -348,7 +348,7 @@ static inline int msrp_uri_cmp(struct msrp_url *a, struct msrp_url *b) static int run_msrp_socket_route(struct receive_info *rcv, char *d_schema_s, - str *d_host, struct socket_info **si) + str *d_host, const struct socket_info **si) { pv_value_t pval; struct sip_msg *dummy_msg; @@ -404,7 +404,7 @@ int handle_msrp_request(struct msrp_msg *req, void *param) int from_peer = 0; struct msrp_url *my_url; int report = 0; - struct socket_info *si; + const struct socket_info *si; LM_DBG("Received MSRP request [%.*s]\n", req->fl.u.request.method.len, req->fl.u.request.method.s); diff --git a/modules/msrp_ua/msrp_ua.c b/modules/msrp_ua/msrp_ua.c index 864127b5aeb..34fc27dd69d 100644 --- a/modules/msrp_ua/msrp_ua.c +++ b/modules/msrp_ua/msrp_ua.c @@ -68,7 +68,7 @@ b2b_api_t b2b_api; str my_msrp_uri_str; struct msrp_url my_msrp_uri; -struct socket_info *msrp_sock; +const struct socket_info *msrp_sock; str adv_contact; diff --git a/modules/nat_traversal/nat_traversal.c b/modules/nat_traversal/nat_traversal.c index 6ee94a7de87..244027ee634 100644 --- a/modules/nat_traversal/nat_traversal.c +++ b/modules/nat_traversal/nat_traversal.c @@ -113,7 +113,7 @@ typedef struct SIP_Dialog { typedef struct NAT_Contact { char *uri; - struct socket_info *socket; + const struct socket_info *socket; time_t registration_expire; time_t subscription_expire; @@ -410,7 +410,7 @@ SIP_Subscription_expire(NAT_Contact *contact, time_t now) // static NAT_Contact* -NAT_Contact_new(char *uri, struct socket_info *socket) +NAT_Contact_new(char *uri, const struct socket_info *socket) { NAT_Contact *contact; @@ -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 union sockaddr_union *dst, const struct socket_info *sock, int proto) { struct sip_msg reply; time_t expire; @@ -1545,7 +1545,7 @@ send_keepalive(NAT_Contact *contact) char buffer[8192], *from_uri, *ptr; static char from[64] = FROM_PREFIX; static char *from_ip = from + sizeof(FROM_PREFIX) - 1; - static struct socket_info *last_socket = NULL; + static const struct socket_info *last_socket = NULL; struct hostent* hostent; union sockaddr_union to; int nat_port, len, tolen; @@ -1698,7 +1698,7 @@ restore_keepalive_state(void) char uri[64], socket[64]; time_t rtime, stime, now; NAT_Contact *contact; - struct socket_info *sock; + const struct socket_info *sock; int port, proto, res; unsigned h; str host; diff --git a/modules/nathelper/nathelper.c b/modules/nathelper/nathelper.c index d41ad2e23b1..796c14d0543 100644 --- a/modules/nathelper/nathelper.c +++ b/modules/nathelper/nathelper.c @@ -138,7 +138,7 @@ usrloc_api_t ul; static int cblen = 0; static str nortpproxy_str = str_init("a=nortpproxy:yes"); static int natping_interval = 0; -struct socket_info* force_socket = 0; +const struct socket_info* force_socket = 0; /* */ int ping_checker_interval = 1; @@ -1311,7 +1311,7 @@ nh_timer(unsigned int ticks, void *timer_idx) str received; union sockaddr_union to; struct hostent *he; - struct socket_info* send_sock; + const struct socket_info* send_sock; unsigned int flags; struct proxy_l next_hop; ucontact_coords ct_coords = 0; diff --git a/modules/nathelper/sip_pinger.h b/modules/nathelper/sip_pinger.h index 89fcc5b1bd1..09cf89aa0ee 100644 --- a/modules/nathelper/sip_pinger.h +++ b/modules/nathelper/sip_pinger.h @@ -346,13 +346,13 @@ build_branch(char *branch, int *size, /* build the buffer of a SIP ping request */ static inline char* -build_sipping(udomain_t *d, str *curi, struct socket_info* s,str *path, +build_sipping(udomain_t *d, str *curi, const struct socket_info* s,str *path, int *len_p, ucontact_coords ct_coords, int ct_flags) { #define s_len(_s) (sizeof(_s)-1) static char buf[MAX_SIPPING_SIZE]; char *p, proto_str[PROTO_NAME_MAX_SIZE+1]; - str *address, *port; + const str *address, *port; str st; int len; diff --git a/modules/presence/subscribe.h b/modules/presence/subscribe.h index e64043c5e47..643fa0c8109 100644 --- a/modules/presence/subscribe.h +++ b/modules/presence/subscribe.h @@ -56,7 +56,7 @@ struct subscription str to_tag; str from_tag; str callid; - struct socket_info* sockinfo; + const struct socket_info* sockinfo; unsigned int remote_cseq; unsigned int local_cseq; str contact; diff --git a/modules/presence/utils_func.h b/modules/presence/utils_func.h index f3363116be1..3ebca2cc1e5 100644 --- a/modules/presence/utils_func.h +++ b/modules/presence/utils_func.h @@ -75,7 +75,7 @@ static inline int uandd_to_uri(str user, str domain, str *out) /* Build a contact URI using the provided username and the socket's ip:port:protocol */ -static inline int get_local_contact(struct socket_info *sock, str *username, str *contact) +static inline int get_local_contact(const struct socket_info *sock, str *username, str *contact) { static char buf[MAX_URI_SIZE]; char *ptr = buf; diff --git a/modules/proto_bin/proto_bin.c b/modules/proto_bin/proto_bin.c index 312696f4421..5a96891aad8 100644 --- a/modules/proto_bin/proto_bin.c +++ b/modules/proto_bin/proto_bin.c @@ -46,8 +46,8 @@ 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, +static int proto_bin_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id); static int bin_read_req(struct tcp_connection* con, int* bytes_read); @@ -116,11 +116,11 @@ static int proto_bin_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)bin_read_req; - pi->net.write = (proto_net_write_f)tcp_async_write; + pi->net.stream.read = bin_read_req; + pi->net.stream.write = tcp_async_write; if (bin_async != 0) - pi->net.async_chunks= bin_async_max_postponed_chunks; + pi->net.stream.async_chunks= bin_async_max_postponed_chunks; return 0; } @@ -141,8 +141,8 @@ static int proto_bin_init_listener(struct socket_info *si) return tcp_init_listener(si); } -static int proto_bin_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, +static int proto_bin_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; @@ -200,8 +200,8 @@ static int proto_bin_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* connect is still in progress, break the sending * flow now (the actual write will be done when @@ -241,8 +241,8 @@ static int proto_bin_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* we successfully added our write chunk - success */ tcp_conn_release(c, 0); @@ -281,8 +281,8 @@ static int proto_bin_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, (ntran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)bins_read_req; - pi->net.write = (proto_net_write_f)bins_async_write; - pi->net.conn_init = proto_bins_conn_init; - pi->net.conn_clean = proto_bins_conn_clean; + pi->net.stream.read = bins_read_req; + pi->net.stream.write = bins_async_write; + pi->net.stream.conn.init = proto_bins_conn_init; + pi->net.stream.conn.clean = proto_bins_conn_clean; pi->net.report = bins_report; if (bins_async && !tcp_has_async_write()) { @@ -175,7 +175,7 @@ static int proto_bins_init(struct proto_info *pi) } if (bins_async != 0) - pi->net.async_chunks= bins_async_max_postponed_chunks; + pi->net.stream.async_chunks= bins_async_max_postponed_chunks; return 0; } @@ -336,8 +336,8 @@ static int bins_write_on_socket(struct tcp_connection* c, int fd, return n; } -static int proto_bins_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, +static int proto_bins_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; @@ -398,8 +398,8 @@ static int proto_bins_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; LM_DBG("Successfully started async connection\n"); tcp_conn_release(c, 0); @@ -469,8 +469,8 @@ static int proto_bins_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* we successfully added our write chunk - success */ tcp_conn_release(c, 0); @@ -508,8 +508,8 @@ static int proto_bins_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, (ntran.send = hep_udp_send; pi->net.flags = PROTO_NET_USE_UDP; - pi->net.read = (proto_net_read_f)hep_udp_read_req; + pi->net.dgram.read = hep_udp_read_req; return 0; } @@ -290,13 +290,13 @@ static int proto_hep_init_tcp(struct proto_info* pi) pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)hep_tcp_read_req; - pi->net.write = (proto_net_write_f)tcp_async_write; + pi->net.stream.read = hep_tcp_read_req; + pi->net.stream.write = tcp_async_write; pi->tran.send = hep_tcp_send; if (hep_async) { - pi->net.async_chunks= hep_async_max_postponed_chunks; + pi->net.stream.async_chunks= hep_async_max_postponed_chunks; } return 0; @@ -318,13 +318,13 @@ static int proto_hep_init_tls(struct proto_info* pi) pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)hep_tls_read_req; - pi->net.write = (proto_net_write_f)hep_tls_async_write; + pi->net.stream.read = hep_tls_read_req; + pi->net.stream.write = hep_tls_async_write; pi->tran.send = hep_tls_send; - pi->net.conn_init = proto_hep_tls_conn_init; - pi->net.conn_clean = proto_hep_tls_conn_clean; + pi->net.stream.conn.init = proto_hep_tls_conn_init; + pi->net.stream.conn.clean = proto_hep_tls_conn_clean; if (hep_async && !tcp_has_async_write()) { LM_WARN("TCP network layer does not have support for ASYNC write, " @@ -333,7 +333,7 @@ static int proto_hep_init_tls(struct proto_info* pi) } if (hep_async != 0) { - pi->net.async_chunks= hep_async_max_postponed_chunks; + pi->net.stream.async_chunks= hep_async_max_postponed_chunks; } return 0; @@ -344,8 +344,8 @@ static int proto_hep_init_udp_listener(struct socket_info* si) return udp_init_listener(si, hep_async ? O_NONBLOCK : 0); } -static int hep_udp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, +static int hep_udp_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { int n, tolen; @@ -366,22 +366,22 @@ static int hep_udp_send(struct socket_info* send_sock, return n; } -static int hep_tcp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, +static int hep_tcp_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* 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, +static int hep_tls_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* 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, +static int hep_tcp_or_tls_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id, unsigned int is_tls) { struct tcp_connection* c; @@ -437,8 +437,8 @@ static int hep_tcp_or_tls_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* connect is still in progress, break the sending * flow now (the actual write will be done when * connect will be completed */ @@ -508,8 +508,8 @@ static int hep_tcp_or_tls_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* we successfully added our write chunk - success */ tcp_conn_release(c, 0); @@ -553,8 +553,8 @@ static int hep_tcp_or_tls_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, (n < len) ? 1 : 0 /*pending data in async mode?*/); @@ -959,7 +959,7 @@ static int hep_tcp_or_tls_read_req(struct tcp_connection* con, int* bytes_read, return -1; } -static int hep_udp_read_req(struct socket_info* si, int* bytes_read) +static int hep_udp_read_req(const struct socket_info* si, int* bytes_read) { struct receive_info ri; int len; diff --git a/modules/proto_msrp/msrp_api.h b/modules/proto_msrp/msrp_api.h index 951b8db2ab2..f50123fc7b9 100644 --- a/modules/proto_msrp/msrp_api.h +++ b/modules/proto_msrp/msrp_api.h @@ -45,7 +45,7 @@ typedef int (*send_report_f)( void *hdl, str *status, typedef int (*fwd_request_f)( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no, - struct socket_info *sock, union sockaddr_union *to_su, + const struct socket_info *sock, union sockaddr_union *to_su, void *trans_param); typedef int (*fwd_reply_f)( void *hdl, struct msrp_msg *rpl, @@ -53,7 +53,7 @@ typedef int (*fwd_reply_f)( void *hdl, struct msrp_msg *rpl, typedef int (*send_request_f)(void *hdl, enum msrp_method method_id, str *from, struct msrp_url *to, - struct socket_info *sock, union sockaddr_union *to_su, + const struct socket_info *sock, union sockaddr_union *to_su, str *mime, str *body, str *hdrs, int hdrs_no, char cont_flag, void *trans_param); diff --git a/modules/proto_msrp/msrp_common.c b/modules/proto_msrp/msrp_common.c index 1cce62e9afd..8e1d0f80f99 100644 --- a/modules/proto_msrp/msrp_common.c +++ b/modules/proto_msrp/msrp_common.c @@ -556,9 +556,9 @@ int msrp_read_req(struct tcp_connection* con, int* bytes_read) /************** SEND related functions ***************/ /*! \brief Finds a tcpconn & sends on it */ -int proto_msrp_send(struct socket_info* send_sock, +int proto_msrp_send(const struct socket_info* send_sock, char* buf, unsigned int len, - union sockaddr_union* to, unsigned int id) + const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; struct tcp_conn_profile prof; @@ -690,8 +690,8 @@ int proto_msrp_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, 0); return n; diff --git a/modules/proto_msrp/msrp_common.h b/modules/proto_msrp/msrp_common.h index db33a9625b4..c188e236319 100644 --- a/modules/proto_msrp/msrp_common.h +++ b/modules/proto_msrp/msrp_common.h @@ -84,9 +84,9 @@ extern struct tls_mgm_binds tls_mgm_api; void msrp_brief_parse_msg(struct msrp_req *r); -int proto_msrp_send(struct socket_info* send_sock, +int proto_msrp_send(const struct socket_info* send_sock, char* buf, unsigned int len, - union sockaddr_union* to, unsigned int id); + const union sockaddr_union* 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..3ae17e9f4ec 100644 --- a/modules/proto_msrp/msrp_signaling.c +++ b/modules/proto_msrp/msrp_signaling.c @@ -214,7 +214,7 @@ int msrp_send_reply( void *hdl, struct msrp_msg *req, int code, str* reason, * -3 - internal error */ int msrp_fwd_request( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no, - struct socket_info *sock, union sockaddr_union *to_su, void *trans_param) + const struct socket_info *sock, union sockaddr_union *to_su, void *trans_param) { char *buf, *p, *s, bk; struct msrp_url *to, *from; @@ -284,13 +284,14 @@ int msrp_fwd_request( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no, (to->next->secured?1:0)^(req->rcv.bind_address->proto==PROTO_MSRPS?1:0)) { /* IN and OUT are different from the "secured" perspective, so * pick the first socket matching the outbound proto */ - sock = protos[to->next->secured?PROTO_MSRPS:PROTO_MSRP].listeners; - if (sock==NULL) { + struct socket_info_full **_s = get_sock_info_list(to->next->secured?PROTO_MSRPS:PROTO_MSRP); + if (_s==NULL || _s[0]==NULL) { LM_ERR("cannot find outbound interface - the URL requires %s, but" " not such sockets are defined\n", to->next->secured?"MSRPS":"MSRP"); return -2; } + sock = &_s[0]->socket_info; } else { sock = req->rcv.bind_address; } @@ -810,7 +811,7 @@ int msrp_send_report(void *hdl, str *status, int msrp_send_request(void *hdl, enum msrp_method method_id, str *from, struct msrp_url *to, - struct socket_info *sock, union sockaddr_union *to_su, + const struct socket_info *sock, union sockaddr_union *to_su, str *mime, str *body, str *hdrs, int hdrs_no, char cont_flag, void *trans_param) @@ -889,13 +890,14 @@ int msrp_send_request(void *hdl, enum msrp_method method_id, } } else { /* just pick the first socket matching the outbound proto */ - sock = protos[to->secured?PROTO_MSRPS:PROTO_MSRP].listeners; - if (sock==NULL) { + struct socket_info_full **_s = get_sock_info_list(to->secured?PROTO_MSRPS:PROTO_MSRP); + if (_s==NULL || _s[0]==NULL) { LM_ERR("cannot find outbound interface - the URL requires %s, but" " not such sockets are defined\n", to->secured?"MSRPS":"MSRP"); return -2; } + sock = &_s[0]->socket_info; } diff --git a/modules/proto_msrp/msrp_signaling.h b/modules/proto_msrp/msrp_signaling.h index b4bd4630f28..e03d34a8ee8 100644 --- a/modules/proto_msrp/msrp_signaling.h +++ b/modules/proto_msrp/msrp_signaling.h @@ -82,14 +82,14 @@ int msrp_send_report(void *hdl, str *status, int msrp_fwd_request( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no, - struct socket_info *sock, union sockaddr_union *to_su, + const struct socket_info *sock, union sockaddr_union *to_su, void *trans_param); int msrp_fwd_reply( void *hdl, struct msrp_msg *rpl, struct msrp_cell *cell); int msrp_send_request(void *hdl, enum msrp_method method_id, str *from, struct msrp_url *to, - struct socket_info *sock, union sockaddr_union *to_su, + const struct socket_info *sock, union sockaddr_union *to_su, str *mime, str *body, str *hdrs, int hdrs_no, char cont_flag, void *trans_param); diff --git a/modules/proto_msrp/proto_msrp.c b/modules/proto_msrp/proto_msrp.c index 2608da5aa86..d7e7f135a9a 100644 --- a/modules/proto_msrp/proto_msrp.c +++ b/modules/proto_msrp/proto_msrp.c @@ -141,8 +141,8 @@ static int proto_msrp_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)msrp_read_req; - pi->net.conn_init = NULL; + pi->net.stream.read = msrp_read_req; + pi->net.stream.conn.init = NULL; pi->net.report = msrp_report; return 0; @@ -158,13 +158,13 @@ static int proto_msrps_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)msrp_read_req; - pi->net.conn_init = proto_msrps_conn_init; - pi->net.conn_clean = proto_msrps_conn_clean; + pi->net.stream.read = msrp_read_req; + pi->net.stream.conn.init = proto_msrps_conn_init; + pi->net.stream.conn.clean = proto_msrps_conn_clean; if (msrp_check_cert_on_reusage) - pi->net.conn_match = msrps_conn_extra_match; + pi->net.stream.conn.match = msrps_conn_extra_match; else - pi->net.conn_match = NULL; + pi->net.stream.conn.match = NULL; pi->net.report = msrps_report; return 0; diff --git a/modules/proto_sctp/proto_sctp.c b/modules/proto_sctp/proto_sctp.c index 4877fc1bd73..ed1f9ded721 100644 --- a/modules/proto_sctp/proto_sctp.c +++ b/modules/proto_sctp/proto_sctp.c @@ -81,7 +81,7 @@ static int proto_sctp_init(struct proto_info *pi) pi->tran.send = proto_sctp_send; pi->net.flags = PROTO_NET_USE_UDP; - pi->net.read = (proto_net_read_f)proto_sctp_read; + pi->net.dgram.read = proto_sctp_read; return 0; } diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index e48f4d56be7..2b4c0fbc436 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -140,7 +140,7 @@ int proto_sctp_init_listener(struct socket_info* sock_info) } -int proto_sctp_read(struct socket_info *si, int* bytes_read) +int proto_sctp_read(const struct socket_info *si, int* bytes_read) { struct receive_info ri; int len; @@ -189,15 +189,16 @@ 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) +int proto_sctp_send(const struct socket_info *source, char *buf, unsigned len, + const union sockaddr_union* to, unsigned int id) { int n; int tolen; + union sockaddr_union _to = *to; /* XXX Linux defines sctp_sendmsg without const */ tolen=sockaddru_len(*to); again: - n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, 0, 0, 0, 0); + n=sctp_sendmsg(source->socket, buf, len, &_to.s, tolen, 0, 0, 0, 0, 0); #ifdef XL_DEBUG LM_INFO("send status: %d\n", n); #endif diff --git a/modules/proto_sctp/sctp_server.h b/modules/proto_sctp/sctp_server.h index 57700703f4f..ff4a48e02b2 100644 --- a/modules/proto_sctp/sctp_server.h +++ b/modules/proto_sctp/sctp_server.h @@ -36,9 +36,9 @@ 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); +int proto_sctp_send(const struct socket_info *source, char *buf, unsigned len, + const union sockaddr_union* to, unsigned int id); -int proto_sctp_read(struct socket_info *si, int* bytes_read); +int proto_sctp_read(const struct socket_info *si, int* bytes_read); #endif diff --git a/modules/proto_smpp/proto_smpp.c b/modules/proto_smpp/proto_smpp.c index a43776f91c0..7b1be30e2a8 100644 --- a/modules/proto_smpp/proto_smpp.c +++ b/modules/proto_smpp/proto_smpp.c @@ -59,8 +59,8 @@ static int mod_init(void); 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, +static int smpp_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* 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); @@ -144,11 +144,11 @@ static int smpp_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)smpp_read_req; - pi->net.write = (proto_net_write_f)smpp_write_async_req; + pi->net.stream.read = smpp_read_req; + pi->net.stream.write = smpp_write_async_req; - pi->net.conn_init = smpp_conn_init; - pi->net.conn_clean = smpp_conn_clean; + pi->net.stream.conn.init = smpp_conn_init; + pi->net.stream.conn.clean = smpp_conn_clean; return 0; } @@ -229,8 +229,8 @@ static int smpp_init_listener(struct socket_info *si) return tcp_init_listener(si); } -static int smpp_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, +static int smpp_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* 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..43185650592 100644 --- a/modules/proto_smpp/smpp.c +++ b/modules/proto_smpp/smpp.c @@ -792,7 +792,7 @@ static struct tcp_connection *smpp_connect(smpp_session_t *session, int *fd) { union sockaddr_union to; union sockaddr_union server; - struct socket_info *send_socket; + const struct socket_info *send_socket; struct tcp_conn_profile prof; if (init_su(&to, &session->ip, session->port)) { diff --git a/modules/proto_tls/proto_tls.c b/modules/proto_tls/proto_tls.c index 17af9a0f5b9..db1f1ff3c9a 100644 --- a/modules/proto_tls/proto_tls.c +++ b/modules/proto_tls/proto_tls.c @@ -122,8 +122,8 @@ static int tls_send_tout = 100; 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, union sockaddr_union* to, +static int proto_tls_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id); static void tls_report(int type, unsigned long long conn_id, int conn_flags, void *extra); @@ -343,14 +343,14 @@ static int proto_tls_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)tls_read_req; - pi->net.write = (proto_net_write_f)tls_async_write; - pi->net.conn_init = proto_tls_conn_init; - pi->net.conn_clean = proto_tls_conn_clean; + pi->net.stream.read = tls_read_req; + pi->net.stream.write = tls_async_write; + pi->net.stream.conn.init = proto_tls_conn_init; + pi->net.stream.conn.clean = proto_tls_conn_clean; if (cert_check_on_conn_reusage) - pi->net.conn_match = tls_conn_extra_match; + pi->net.stream.conn.match = tls_conn_extra_match; else - pi->net.conn_match = NULL; + pi->net.stream.conn.match = NULL; pi->net.report = tls_report; if (tls_async && !tcp_has_async_write()) { @@ -360,7 +360,7 @@ static int proto_tls_init(struct proto_info *pi) } if (tls_async!=0) - pi->net.async_chunks= tls_async_max_postponed_chunks; + pi->net.stream.async_chunks= tls_async_max_postponed_chunks; return 0; } @@ -473,8 +473,8 @@ static void tls_report(int type, unsigned long long conn_id, int conn_flags, return; } -static int proto_tls_send(struct socket_info* send_sock, - char* buf, unsigned int len, union sockaddr_union* to, +static int proto_tls_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; @@ -615,8 +615,8 @@ static int proto_tls_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, 0); return rlen; diff --git a/modules/proto_ws/proto_ws.c b/modules/proto_ws/proto_ws.c index ee73bbfc16d..17465e33133 100644 --- a/modules/proto_ws/proto_ws.c +++ b/modules/proto_ws/proto_ws.c @@ -94,8 +94,8 @@ static struct script_route_ref *trace_filter_route_ref = NULL; 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, +static int proto_ws_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* 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); @@ -186,10 +186,10 @@ static int proto_ws_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)ws_read_req; + pi->net.stream.read = ws_read_req; - pi->net.conn_init = ws_conn_init; - pi->net.conn_clean = ws_conn_clean; + pi->net.stream.conn.init = ws_conn_init; + pi->net.stream.conn.clean = ws_conn_clean; pi->net.report = ws_report; return 0; @@ -327,8 +327,8 @@ 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, +static int proto_ws_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; @@ -428,8 +428,8 @@ static int proto_ws_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, 0); return n; diff --git a/modules/proto_ws/ws_common.h b/modules/proto_ws/ws_common.h index 201e0ccb7e8..14274ed910c 100644 --- a/modules/proto_ws/ws_common.h +++ b/modules/proto_ws/ws_common.h @@ -635,8 +635,8 @@ static void ws_close(struct tcp_connection *c) ws_send_close(c); } -static struct tcp_connection* ws_sync_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof) +static struct tcp_connection* ws_sync_connect(const struct socket_info* send_sock, + const union sockaddr_union* server, struct tcp_conn_profile *prof) { int s; union sockaddr_union my_name; @@ -683,8 +683,8 @@ 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) +static struct tcp_connection* ws_connect(const struct socket_info* send_sock, + const union sockaddr_union* 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 aeb572a5701..25838194f02 100644 --- a/modules/proto_wss/proto_wss.c +++ b/modules/proto_wss/proto_wss.c @@ -107,8 +107,8 @@ static struct script_route_ref *trace_filter_route_ref = NULL; 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, union sockaddr_union* to, +static int proto_wss_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* 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); @@ -202,14 +202,14 @@ static int proto_wss_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)wss_read_req; + pi->net.stream.read = wss_read_req; - pi->net.conn_init = wss_conn_init; - pi->net.conn_clean = ws_conn_clean; + pi->net.stream.conn.init = wss_conn_init; + pi->net.stream.conn.clean = ws_conn_clean; if (cert_check_on_conn_reusage) - pi->net.conn_match = tls_conn_extra_match; + pi->net.stream.conn.match = tls_conn_extra_match; else - pi->net.conn_match = NULL; + pi->net.stream.conn.match = NULL; pi->net.report = wss_report; return 0; @@ -388,8 +388,8 @@ 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, union sockaddr_union* to, +static int proto_wss_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; @@ -495,8 +495,8 @@ static int proto_wss_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; tcp_conn_release(c, 0); return n; diff --git a/modules/registrar/reg_mod.c b/modules/registrar/reg_mod.c index 644a6432b90..338f31878ae 100644 --- a/modules/registrar/reg_mod.c +++ b/modules/registrar/reg_mod.c @@ -469,7 +469,7 @@ static void mod_destroy(void) static int add_sock_hdr(struct sip_msg* msg, str *hdr_name) { - struct socket_info* si; + const struct socket_info* si; struct lump* anchor; str hdr; char *p; diff --git a/modules/registrar/reply.c b/modules/registrar/reply.c index 55d1bf05673..fc726afdadd 100644 --- a/modules/registrar/reply.c +++ b/modules/registrar/reply.c @@ -116,7 +116,7 @@ static inline unsigned int calc_buf_len(ucontact_t* c,int build_gruu, { unsigned int len; int qlen; - struct socket_info *sock; + const struct socket_info *sock; len = 0; while(c) { @@ -223,7 +223,7 @@ int build_contact(ucontact_t* c,struct sip_msg *_m) char *p, *cp, *tmpgr; int fl, len,grlen; int build_gruu = 0; - struct socket_info *sock; + const struct socket_info *sock; if (!disable_gruu && _m->supported && parse_supported(_m) == 0 && (get_supported(_m) & F_SUPPORTED_GRUU)) diff --git a/modules/registrar/save.c b/modules/registrar/save.c index 963ed193af5..80c25478a17 100644 --- a/modules/registrar/save.c +++ b/modules/registrar/save.c @@ -156,7 +156,7 @@ static inline int no_contacts(udomain_t* _d, struct save_ctx *_sctx, static int set_sock_hdr(struct sip_msg *msg, ucontact_info_t *ci, unsigned int reg_flags) { - struct socket_info *sock; + const struct socket_info *sock; struct hdr_field *hf; str socks; str hosts; diff --git a/modules/rls/subscribe.c b/modules/rls/subscribe.c index 54ed1dcaa43..190f557cbd8 100644 --- a/modules/rls/subscribe.c +++ b/modules/rls/subscribe.c @@ -795,7 +795,7 @@ int send_resource_subs(char* uri, void* param) str *dest_uri, *tmp_str; subs_info_t *s = (subs_info_t *) ((void**)param)[0]; list_entry_t **rls_contact_list = (list_entry_t **) ((void**)param)[1]; - struct socket_info *send_sock; + const struct socket_info *send_sock; union sockaddr_union dummy_su; static str contact; diff --git a/modules/rr/loose.c b/modules/rr/loose.c index 8203b2d4358..88d33303f7f 100644 --- a/modules/rr/loose.c +++ b/modules/rr/loose.c @@ -501,7 +501,7 @@ static inline int after_strict(struct sip_msg* _m) rr_t* rt, *prev, *del_rt; char* rem_off; str uri; - struct socket_info *si; + const struct socket_info *si; unsigned short port, proto; hdr = _m->route; @@ -713,7 +713,7 @@ static inline int after_loose(struct sip_msg* _m, int preloaded) int ret; #endif str uri; - struct socket_info *si; + const struct socket_info *si; int force_ss = 0; hdr = _m->route; diff --git a/modules/sipcapture/sipcapture.c b/modules/sipcapture/sipcapture.c index a07f26e7a6f..58a142ff0fa 100644 --- a/modules/sipcapture/sipcapture.c +++ b/modules/sipcapture/sipcapture.c @@ -4250,7 +4250,7 @@ static int w_hep_relay(struct sip_msg *msg) struct proxy_l* proxy; struct sip_uri uri; - struct socket_info* send_sock; + const struct socket_info* send_sock; union sockaddr_union to; diff --git a/modules/siprec/siprec_sess.c b/modules/siprec/siprec_sess.c index a07d050da16..fa9f112d628 100644 --- a/modules/siprec/siprec_sess.c +++ b/modules/siprec/siprec_sess.c @@ -34,7 +34,7 @@ struct dlg_binds srec_dlg; static str srec_dlg_name = str_init("siprecX_ctx"); static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp, - struct socket_info *si, int version, time_t ts, str *hdrs, siprec_uuid *uuid, + const struct socket_info *si, int version, time_t ts, str *hdrs, siprec_uuid *uuid, str* group_custom_extension, str* session_custom_extension) { struct src_sess *ss = shm_malloc(sizeof *ss + (m_ip ? m_ip->len : 0) + @@ -282,7 +282,7 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type, str group_custom_extension, session_custom_extension; str aor, name, xml_val, *xml; siprec_uuid uuid; - struct socket_info *si; + const struct socket_info *si; int p, c, label, medianum; rtp_ctx rtp; int p_type; diff --git a/modules/siprec/siprec_sess.h b/modules/siprec/siprec_sess.h index 77941eb47f0..47aa99fc9cc 100644 --- a/modules/siprec/siprec_sess.h +++ b/modules/siprec/siprec_sess.h @@ -93,7 +93,7 @@ struct src_sess { /* SRS */ struct list_head srs; str group; - struct socket_info *socket; /* socket used towards SRS */ + const struct socket_info *socket; /* socket used towards SRS */ str group_custom_extension; str session_custom_extension; diff --git a/modules/siprec/siprec_var.c b/modules/siprec/siprec_var.c index 32cc9af332c..6089367b7a8 100644 --- a/modules/siprec/siprec_var.c +++ b/modules/siprec/siprec_var.c @@ -166,7 +166,7 @@ int pv_parse_siprec(pv_spec_p sp, const str *in) int pv_get_siprec(struct sip_msg *msg, pv_param_t *param, pv_value_t *val) { - str *field = NULL; + const str *field = NULL; struct srec_var *sv = SIPREC_GET_VAR(); if (!sv) return pv_get_null(msg, param, val); diff --git a/modules/siprec/siprec_var.h b/modules/siprec/siprec_var.h index 9a2f0e80b46..2dd392da4a5 100644 --- a/modules/siprec/siprec_var.h +++ b/modules/siprec/siprec_var.h @@ -27,7 +27,7 @@ struct srec_var { str group, caller, callee, media, headers, group_custom_extension, session_custom_extension; - struct socket_info *si; + const struct socket_info *si; }; int init_srec_var(void); diff --git a/modules/stun/stun.c b/modules/stun/stun.c index e0da49a7b3f..ba476b9cc89 100644 --- a/modules/stun/stun.c +++ b/modules/stun/stun.c @@ -35,10 +35,10 @@ #include "stun.h" /* Globals */ -struct socket_info* grep1 = NULL; -struct socket_info* grep2 = NULL; -struct socket_info* grep3 = NULL; -struct socket_info* grep4 = NULL; +const struct socket_info* grep1 = NULL; +const struct socket_info* grep2 = NULL; +const struct socket_info* grep3 = NULL; +const struct socket_info* grep4 = NULL; int assign_once = FALSE; int sockfd4=-1; /* ip2 port2 */ @@ -162,8 +162,8 @@ static struct stun_socket *add_sock_to_set(struct stun_socket_set *set, static int stun_mod_init(void) { str s; - struct socket_info *si; - struct socket_info **si_list; + struct socket_info_full *sif; + struct socket_info_full **si_list; int i = 0; int ip; struct stun_socket *sock; @@ -171,8 +171,8 @@ static int stun_mod_init(void) if (use_listeners_as_primary) { si_list = get_sock_info_list(PROTO_UDP); - for (si = si_list ? *si_list : 0; si; si = si->next) - if (si->address.af == AF_INET) + for (sif = si_list ? *si_list : 0; sif; sif = sif->next) + if (sif->socket_info.address.af == AF_INET) no_socket_sets++; } else { if (!primary_ip || primary_ip[0] == '\0') { @@ -212,7 +212,8 @@ static int stun_mod_init(void) } si_list = get_sock_info_list(PROTO_UDP); - for (si = si_list ? *si_list : 0; si; si = si->next) { + for (sif = si_list ? *si_list : 0; sif; sif = sif->next) { + const struct socket_info *si = &sif->socket_info; if (si->address.af != AF_INET || si == grep4) continue; else diff --git a/modules/stun/stun.h b/modules/stun/stun.h index 61885bee8d2..59390ea351c 100644 --- a/modules/stun/stun.h +++ b/modules/stun/stun.h @@ -208,7 +208,7 @@ struct stun_socket_set { struct stun_socket *sock2; /* ip1 port2 */ struct stun_socket *sock3; /* ip2 port1 */ - struct socket_info *si; + const struct socket_info *si; int ip1; int port1; diff --git a/modules/tcp_mgm/tcp_path.c b/modules/tcp_mgm/tcp_path.c index 721be6b623a..973abd27f0f 100644 --- a/modules/tcp_mgm/tcp_path.c +++ b/modules/tcp_mgm/tcp_path.c @@ -52,8 +52,8 @@ int tcp_path_init(void) } -int tcp_mgm_get_profile(union sockaddr_union *remote, - union sockaddr_union *local, enum sip_protos proto, +int tcp_mgm_get_profile(const union sockaddr_union *remote, + const union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile) { struct tcp_path *path, *lim; @@ -103,7 +103,7 @@ int tcp_mgm_get_profile(union sockaddr_union *remote, int tcp_store_path(int *int_vals, char **str_vals, struct tcp_path *path) { - struct socket_info *sock; + const struct socket_info *sock; str st; int _proto; diff --git a/modules/tcp_mgm/tcp_path.h b/modules/tcp_mgm/tcp_path.h index ce3e215c636..646d701eb37 100644 --- a/modules/tcp_mgm/tcp_path.h +++ b/modules/tcp_mgm/tcp_path.h @@ -54,8 +54,8 @@ 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, - union sockaddr_union *local, enum sip_protos proto, +int tcp_mgm_get_profile(const union sockaddr_union *remote, + const union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile); #endif /* TCP_PATH_H */ diff --git a/modules/tm/async.c b/modules/tm/async.c index 8453d91e73a..c9b03b88bc7 100644 --- a/modules/tm/async.c +++ b/modules/tm/async.c @@ -80,7 +80,7 @@ int t_resume_async(int fd, void *param, int was_timeout) struct cell *backup_cancelled_t; struct cell *backup_e2eack_t; struct usr_avp **backup_list; - struct socket_info* backup_si; + const struct socket_info* backup_si; struct cell *t= ctx->t; int route; diff --git a/modules/tm/callid.c b/modules/tm/callid.c index 30faceac33f..a44880d6ce2 100644 --- a/modules/tm/callid.c +++ b/modules/tm/callid.c @@ -101,7 +101,7 @@ int init_callid(void) */ int child_init_callid(int rank) { - struct socket_info *si; + const struct socket_info *si; /* on tcp/tls bind_address is 0 so try to get the first address we listen * on no matter the protocol */ diff --git a/modules/tm/dlg.c b/modules/tm/dlg.c index a505805f849..f2e5ca87d60 100644 --- a/modules/tm/dlg.c +++ b/modules/tm/dlg.c @@ -138,7 +138,7 @@ int w_calculate_hooks(dlg_t* _d) /* * Create a new dialog - internal function */ -static int _internal_new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _turi, str* _ruri, struct socket_info* sock, dlg_t** _d) +static int _internal_new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _turi, str* _ruri, const struct socket_info* sock, dlg_t** _d) { dlg_t* res; @@ -198,7 +198,7 @@ int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _tur /* * Create a new dialog (auto mode) */ -int new_auto_dlg_uac( str* _luri, str* _turi, str* _ruri, str *callid, struct socket_info* _sock, dlg_t** _d) +int new_auto_dlg_uac( str* _luri, str* _turi, str* _ruri, str *callid, const struct socket_info* _sock, dlg_t** _d) { str fromtag, clid; diff --git a/modules/tm/dlg.h b/modules/tm/dlg.h index 71d0531a5fd..5389b750561 100644 --- a/modules/tm/dlg.h +++ b/modules/tm/dlg.h @@ -108,8 +108,8 @@ typedef struct dlg { * can be reused when building a message (to * prevent repeated analyzing of the dialog data */ - struct socket_info* send_sock; /* forced sock, overrides dst proto */ - struct socket_info* pref_sock; /* preffered sock, if no proto conflict */ + const struct socket_info* send_sock; /* forced sock, overrides dst proto */ + const struct socket_info* pref_sock; /* preffered sock, if no proto conflict */ unsigned short mf_enforced; /* if Max-Forward is to be enforced */ unsigned short mf_value; /* the Mx-Forward values, if enforced */ void *dialog_ctx; /* backpointer to dialog ctx */ @@ -128,8 +128,8 @@ typedef int (*new_dlg_uac_f)(str* _cid, str* _ltag, unsigned int _lseq, str* _lu /* * Create a auto new dialog (callid, from tag and CSEQ are auto generated) */ -int new_auto_dlg_uac( str* _luri, str* _turi, str* _ruri, str* callid, struct socket_info* sock, dlg_t** _d); -typedef int (*new_auto_dlg_uac_f)(str* _luri, str* _turi, str* _ruri, str* callid, struct socket_info *sock, dlg_t** _d); +int new_auto_dlg_uac( str* _luri, str* _turi, str* _ruri, str* callid, const struct socket_info* sock, dlg_t** _d); +typedef int (*new_auto_dlg_uac_f)(str* _luri, str* _turi, str* _ruri, str* callid, const struct socket_info *sock, dlg_t** _d); /* * Function which adds Display Names to an existing dialog diff --git a/modules/tm/mi.c b/modules/tm/mi.c index 0e2a43bb3d5..38e958d40b5 100644 --- a/modules/tm/mi.c +++ b/modules/tm/mi.c @@ -118,12 +118,12 @@ static inline str_list *new_str(char *s, int len, str_list **last, int *total) static inline char *get_hfblock( str *uri, struct hdr_field *hf, int *l, - struct socket_info** send_sock) + const struct socket_info** send_sock) { str_list sl, *last, *new, *i, *foo; int hf_avail, frag_len, total_len; char *begin, *needle, *dst, *ret, *d; - str *sock_name, *portname; + const str *sock_name, *portname; union sockaddr_union to_su; ret=0; /* pessimist: assume failure */ @@ -374,7 +374,7 @@ static mi_response_t *mi_tm_uac_dlg(const mi_params_t *params, str *nexthop, static dlg_t dlg; struct sip_uri pruri; struct sip_uri pnexthop; - struct socket_info* sock; + const struct socket_info* sock; str method; str ruri; str hdrs; diff --git a/modules/tm/t_fwd.c b/modules/tm/t_fwd.c index 6d9029a7d68..0d5f4275d54 100644 --- a/modules/tm/t_fwd.c +++ b/modules/tm/t_fwd.c @@ -235,7 +235,7 @@ static inline int pre_print_uac_request( struct cell *t, int branch, /* be aware and use it *all* the time between pre_* and post_* functions! */ static inline char *print_uac_request(struct sip_msg *i_req, unsigned int *len, - struct socket_info *send_sock, enum sip_protos proto ) + const struct socket_info *send_sock, enum sip_protos proto ) { char *buf; str *cid = NULL; @@ -325,7 +325,7 @@ int add_blind_uac(void) /*struct cell *t*/ static inline int update_uac_dst( struct sip_msg *request, struct ua_client *uac ) { - struct socket_info* send_sock; + const struct socket_info* send_sock; char *shbuf; unsigned int len; @@ -697,7 +697,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg , struct cell *t_invite; int success_branch; str dst_uri; - struct socket_info *bk_sock; + const struct socket_info *bk_sock; unsigned int br_flags, bk_bflags; int idx; str path; diff --git a/modules/tm/t_msgbuilder.c b/modules/tm/t_msgbuilder.c index 6c1efcc3c7b..dae09fcc6fe 100644 --- a/modules/tm/t_msgbuilder.c +++ b/modules/tm/t_msgbuilder.c @@ -454,7 +454,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, struct hostport hp; struct rte* list; str contact, ruri, *cont; - struct socket_info* send_sock; + const struct socket_info* send_sock; str next_hop; @@ -608,7 +608,7 @@ static inline int print_cseq_num(str* _s, dlg_t* _d) /* * Create Via header */ -static inline int assemble_via(str* dest, struct cell* t, struct socket_info* sock, int branch, str *extra) +static inline int assemble_via(str* dest, struct cell* t, const struct socket_info* sock, int branch, str *extra) { static char branch_buf[MAX_BRANCH_PARAM_LEN]; char* via; diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c index db2775ae9f8..aa74e54c3bd 100644 --- a/modules/tm/t_reply.c +++ b/modules/tm/t_reply.c @@ -544,7 +544,7 @@ static inline void faked_env( struct cell *t,struct sip_msg *msg) { static struct cell *backup_t; static struct usr_avp **backup_list; - static struct socket_info* backup_si; + static const struct socket_info* backup_si; static int backup_route_type; if (msg) { diff --git a/modules/tm/uac.c b/modules/tm/uac.c index a82ee564cb1..4220feca78a 100644 --- a/modules/tm/uac.c +++ b/modules/tm/uac.c @@ -84,7 +84,7 @@ struct cell** last_localT; int uac_init(void) { str src[3]; - struct socket_info *si; + const struct socket_info *si; if (RAND_MAX < TM_TABLE_ENTRIES) { LM_WARN("uac does not spread across the whole hash table\n"); @@ -171,7 +171,7 @@ static int run_local_route( struct cell *new_cell, char **buf, int *buf_len, struct retr_buf *request; struct proxy_l *new_proxy = NULL; union sockaddr_union new_to_su; - struct socket_info *new_send_sock; + const struct socket_info *new_send_sock; unsigned short dst_changed; char *buf1=NULL, *sipmsg_buf; int buf_len1, sip_msg_len; diff --git a/modules/tm/ut.h b/modules/tm/ut.h index 5bf3521000f..f0da8484f3a 100644 --- a/modules/tm/ut.h +++ b/modules/tm/ut.h @@ -127,10 +127,10 @@ static inline int uri2su(str *uri, union sockaddr_union *to_su, int proto) /* * Convert a URI into socket_info */ -static inline struct socket_info *uri2sock(struct sip_msg* msg, str *uri, +static inline const struct socket_info *uri2sock(struct sip_msg* msg, str *uri, union sockaddr_union *to_su, int proto) { - struct socket_info* send_sock; + const struct socket_info* send_sock; if ( (proto=uri2su(uri, to_su, proto))==-1 ) return 0; diff --git a/modules/topology_hiding/topo_hiding_logic.c b/modules/topology_hiding/topo_hiding_logic.c index ea63dc5cbf3..22cc2aa94e0 100644 --- a/modules/topology_hiding/topo_hiding_logic.c +++ b/modules/topology_hiding/topo_hiding_logic.c @@ -1821,7 +1821,7 @@ static int topo_no_dlg_seq_handling(struct sip_msg *msg,str *info) struct lump* lmp = NULL; str host; int port,proto; - struct socket_info *sock; + const struct socket_info *sock; /* parse all headers to be sure that all RR and Contact hdrs are found */ if (parse_headers(msg, HDR_EOH_F, 0)< 0) { diff --git a/modules/tracer/tracer.c b/modules/tracer/tracer.c index b69ea870615..09c86fc74c9 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, + const 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,13 +163,13 @@ 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 union sockaddr_union *to, const 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 union sockaddr_union *dst, const struct socket_info *sock, int proto); #if 0 static void trace_slack_in(struct sip_msg* req, str *buffer,int rpl_code, - union sockaddr_union *dst, struct socket_info *sock, int proto); + union sockaddr_union *dst, const struct socket_info *sock, int proto); #endif static mi_response_t *sip_trace_mi(const mi_params_t *params, @@ -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, - union sockaddr_union *to, struct socket_info *sock, int proto) + const union sockaddr_union *to, const struct socket_info *sock, int proto) { trace_info_p info; @@ -2317,7 +2317,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 union sockaddr_union *dst, const 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]; @@ -2408,7 +2408,7 @@ static void trace_slreply_out(struct sip_msg* req, str *buffer,int rpl_code, /* FIXME can't get the trace info here */ #if 0 static void trace_slack_in(struct sip_msg* req, str *buffer,int rpl_code, - union sockaddr_union *dst, struct socket_info *sock, int proto) + union sockaddr_union *dst, const struct socket_info *sock, int proto) { /* FIXME How can we pass the trace info structure here ???? */ // sip_trace(req, NULL); @@ -2456,7 +2456,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, + const 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]; @@ -2520,8 +2520,8 @@ static void trace_msg_out(struct sip_msg* msg, str *sbuf, db_vals[4].val.str_val.s = fromip_buff; db_vals[4].val.str_val.len = nbuff - fromip_buff; db_vals[5].val.str_val = send_sock->address_str; - db_vals[6].val.int_val = send_sock->last_local_real_port? - send_sock->last_local_real_port:send_sock->port_no; + db_vals[6].val.int_val = send_sock->last_real_ports->local? + send_sock->last_real_ports->local:send_sock->port_no; } } @@ -2532,8 +2532,8 @@ static void trace_msg_out(struct sip_msg* msg, str *sbuf, su2ip_addr(&to_ip, to); set_sock_columns( db_vals[7], db_vals[8], db_vals[9], toip_buff, &to_ip, - (unsigned long)(send_sock && send_sock->last_remote_real_port? - send_sock->last_remote_real_port:su_getport(to)), + (unsigned long)(send_sock && send_sock->last_real_ports->remote? + send_sock->last_real_ports->remote:su_getport(to)), proto); } @@ -2808,8 +2808,8 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps, db_vals[4].val.str_val.s = fromip_buff; db_vals[4].val.str_val.len = nbuff - fromip_buff; db_vals[5].val.str_val = dst->send_sock->address_str; - db_vals[6].val.int_val = dst->send_sock->last_local_real_port? - dst->send_sock->last_local_real_port:dst->send_sock->port_no; + db_vals[6].val.int_val = dst->send_sock->last_real_ports->local? + dst->send_sock->last_real_ports->local:dst->send_sock->port_no; } } @@ -2821,8 +2821,8 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps, su2ip_addr(&to_ip, &dst->to); 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)), + (unsigned long)(dst->send_sock && dst->send_sock->last_real_ports->remote? + dst->send_sock->last_real_ports->remote:su_getport(&dst->to)), dst->proto); } @@ -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) { union sockaddr_union* to; - struct socket_info* send_sock; + const struct socket_info* send_sock; struct proxy_l * p; int proto; int ret; diff --git a/modules/uac_registrant/reg_records.h b/modules/uac_registrant/reg_records.h index 739b2baabcd..a7b35cf3af4 100644 --- a/modules/uac_registrant/reg_records.h +++ b/modules/uac_registrant/reg_records.h @@ -67,7 +67,7 @@ typedef struct uac_reg_map { str auth_user; /* authentication user */ str auth_password; /* authentication password */ unsigned int expires; /* expiration interval */ - struct socket_info *send_sock; /* socket */ + const struct socket_info *send_sock; /* socket */ str cluster_shtag; /* clustering sharing tag */ int cluster_id; unsigned int flags; /* record flags */ diff --git a/modules/usrloc/dlist.c b/modules/usrloc/dlist.c index a5789869093..73e7b92f7cc 100644 --- a/modules/usrloc/dlist.c +++ b/modules/usrloc/dlist.c @@ -117,7 +117,7 @@ static int get_domain_db_ucontacts(udomain_t *d, void *buf, int *len, static str query_str; static struct sip_uri puri; - struct socket_info *sock; + const struct socket_info *sock; struct proxy_l next_hop; db_res_t *res = NULL; db_row_t *row; @@ -407,7 +407,7 @@ cdb_pack_ping_data(const str *aor, const cdb_pair_t *contact, struct sip_uri puri; struct list_head *_; unsigned int cflags = 0; - struct socket_info *sock = NULL; + const struct socket_info *sock = NULL; struct proxy_l next_hop; str ct_uri, received = STR_NULL, path = STR_NULL; int needed; diff --git a/modules/usrloc/ucontact.h b/modules/usrloc/ucontact.h index c39e0d56656..2e7e185d58e 100644 --- a/modules/usrloc/ucontact.h +++ b/modules/usrloc/ucontact.h @@ -122,7 +122,7 @@ typedef struct ucontact { ucontact_flags_t flags; /*!< Usrloc-specific internal contact flags */ unsigned int cflags; /*!< Custom branch flags (NAT, RTO, etc.) */ str user_agent; /*!< User-Agent header field */ - struct socket_info *sock; /*!< received socket */ + const struct socket_info *sock; /*!< received socket */ time_t last_modified; /*!< When the record was last modified */ unsigned int methods; /*!< Supported methods */ str attr; /*!< Additional registration info */ @@ -162,7 +162,7 @@ typedef struct ucontact_info { ucontact_flags_t flags; unsigned int cflags; str *user_agent; - struct socket_info *sock; + const struct socket_info *sock; unsigned int methods; time_t last_modified; str *packed_kv_storage; diff --git a/modules/usrloc/ul_evi.c b/modules/usrloc/ul_evi.c index 4e4b16d0d89..ea142265f89 100644 --- a/modules/usrloc/ul_evi.c +++ b/modules/usrloc/ul_evi.c @@ -677,10 +677,11 @@ void ul_raise_ct_refresh_event(const ucontact_t *c, const str *reason, if (!c->sock) { buf->ct.sock = NULL; } else { - buf->ct.sock = &buf->sock[0]; + struct socket_info *sock = &buf->sock[0]; - buf->ct.sock->sock_str.s = p; - str_cpy(&buf->ct.sock->sock_str, &c->sock->sock_str); + sock->sock_str.s = p; + str_cpy(&sock->sock_str, &c->sock->sock_str); + buf->ct.sock = sock; p += c->sock->sock_str.len; } diff --git a/msg_translator.c b/msg_translator.c index f6ee3757819..64a6ac8feed 100644 --- a/msg_translator.c +++ b/msg_translator.c @@ -353,10 +353,10 @@ char* clen_builder(struct sip_msg* msg, int *clen_len, int diff) * returns 1 if cond is true, 0 if false */ static inline int lump_check_opt( struct lump *l, struct sip_msg* msg, - struct socket_info* snd_s + const struct socket_info* snd_s ) { - struct ip_addr* ip; + const struct ip_addr* ip; unsigned short port; int proto; @@ -443,15 +443,15 @@ static inline int lump_check_opt( struct lump *l, /*! \brief computes the "unpacked" len of a lump list, code moved from build_req_from_req */ -int lumps_len(struct sip_msg* msg, struct lump* lumps, - struct socket_info* send_sock, int max_offset) +static int lumps_len(struct sip_msg* msg, struct lump* lumps, + const struct socket_info* send_sock, int max_offset) { unsigned int s_offset, new_len; unsigned int last_del; struct lump *t, *r; - str *send_address_str, *send_port_str; - str *rcv_address_str=NULL; - str *rcv_port_str=NULL; + const str *send_address_str, *send_port_str; + const str *rcv_address_str=NULL; + const str *rcv_port_str=NULL; #define SUBST_LUMP_LEN(subst_l) \ switch((subst_l)->u.subst){ \ @@ -751,16 +751,16 @@ void process_lumps( struct sip_msg* msg, char* new_buf, unsigned int* new_buf_offs, unsigned int* orig_offs, - struct socket_info* send_sock, + const struct socket_info* send_sock, int max_offset) { struct lump *t, *r; char* orig; unsigned int size, offset, s_offset; unsigned int last_del; - str *send_address_str, *send_port_str; - str *rcv_address_str=NULL; - str *rcv_port_str=NULL; + const str *send_address_str, *send_port_str; + const str *rcv_address_str=NULL; + const str *rcv_port_str=NULL; #define SUBST_LUMP(subst_l) \ switch((subst_l)->u.subst){ \ @@ -1250,7 +1250,7 @@ void process_lumps( struct sip_msg* msg, * result (as len). */ unsigned int prep_reassemble_body_parts( struct sip_msg* msg, - struct socket_info* send_sock) + const struct socket_info* send_sock) { struct body_part *part; struct lump* lump; @@ -1585,7 +1585,7 @@ unsigned int prep_reassemble_body_parts( struct sip_msg* msg, void reassemble_body_parts( struct sip_msg* msg, char* new_buf, unsigned int* new_offs, unsigned int* orig_offs, - struct socket_info* send_sock) + const struct socket_info* send_sock) { struct body_part *part; struct lump* lump; @@ -1881,7 +1881,7 @@ void reassemble_body_parts( struct sip_msg* msg, char* new_buf, * lump-based changes and body_part-based changes. */ static inline int calculate_body_diff(struct sip_msg *msg, - struct socket_info *sock ) + const struct socket_info *sock ) { if (msg->body==NULL) { /* no body parsed, no advanced ops done, just dummy lumps over body */ @@ -1899,7 +1899,7 @@ static inline int calculate_body_diff(struct sip_msg *msg, */ static inline void apply_msg_changes(struct sip_msg *msg, char *new_buf, unsigned int *new_offs, - unsigned int *orig_offs, struct socket_info *sock, + unsigned int *orig_offs, const struct socket_info *sock, unsigned int max_offset) { unsigned int size; @@ -2101,7 +2101,7 @@ int is_del_via1_lump(struct sip_msg* msg) char * build_req_buf_from_sip_req( struct sip_msg* msg, unsigned int *returned_len, - struct socket_info* send_sock, int proto, + const struct socket_info* send_sock, int proto, str *via_params, unsigned int flags) { unsigned int len, new_len, received_len, rport_len, uri_len, via_len, body_delta; @@ -2359,7 +2359,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg, char * build_res_buf_from_sip_res( struct sip_msg* msg, - unsigned int *returned_len, struct socket_info *sock,int flags) + unsigned int *returned_len, const struct socket_info *sock,int flags) { unsigned int new_len, body_delta, len; char *new_buf, *buf; @@ -2776,14 +2776,14 @@ int branch_builder( unsigned int hash_index, char* via_builder( unsigned int *len, - struct socket_info* send_sock, + const struct socket_info* send_sock, str* branch, str* extra_params, int proto, struct hostport* hp) { unsigned int via_len, extra_len; char *line_buf; int max_len, local_via_len=MY_VIA_LEN; - str* address_str; /* address displayed in via */ - str* port_str; /* port no displayed in via */ + const str* address_str; /* address displayed in via */ + const str* port_str; /* port no displayed in via */ /* use pre-set address in via or the outbound socket one */ if (hp && hp->host && hp->host->len) @@ -2918,12 +2918,12 @@ char *construct_uri(str *protocol,str *username,str *domain,str *port, } /* uses uri_buff above, since contact is still an uri */ -char *contact_builder(struct socket_info* send_sock, int *ct_len) +char *contact_builder(const struct socket_info* send_sock, int *ct_len) { char *p; int proto_len = 0; - str* address_str = get_adv_host(send_sock); - str* port_str = get_adv_port(send_sock); + const str* address_str = get_adv_host(send_sock); + const str* port_str = get_adv_port(send_sock); /* sip: */ p = uri_buff; diff --git a/msg_translator.h b/msg_translator.h index b7c24215f1b..db06fc61224 100644 --- a/msg_translator.h +++ b/msg_translator.h @@ -88,7 +88,7 @@ struct hostport { } \ } while (0) -static inline str *get_adv_host(struct socket_info *send_sock) +static inline const str *get_adv_host(const struct socket_info *send_sock) { if(send_sock->adv_name_str.len) return &(send_sock->adv_name_str); @@ -98,7 +98,7 @@ static inline str *get_adv_host(struct socket_info *send_sock) return &(send_sock->address_str); } -static inline str *get_adv_port(struct socket_info *send_sock) +static inline const str *get_adv_port(const struct socket_info *send_sock) { if(send_sock->adv_port_str.len) return &(send_sock->adv_port_str); @@ -108,7 +108,7 @@ static inline str *get_adv_port(struct socket_info *send_sock) return &(send_sock->port_no_str); } -static inline str *_get_adv_host(struct socket_info *send_sock, +static inline const str *_get_adv_host(const struct socket_info *send_sock, struct sip_msg *msg) { if (send_sock->adv_name_str.len) @@ -121,7 +121,7 @@ static inline str *_get_adv_host(struct socket_info *send_sock, return &send_sock->address_str; } -static inline str *_get_adv_port(struct socket_info *send_sock, +static inline const str *_get_adv_port(const struct socket_info *send_sock, struct sip_msg *msg) { if (send_sock->adv_port_str.len) @@ -135,11 +135,11 @@ static inline str *_get_adv_port(struct socket_info *send_sock, } char * build_req_buf_from_sip_req ( struct sip_msg* msg, - unsigned int *returned_len, struct socket_info* send_sock, + unsigned int *returned_len, const struct socket_info* send_sock, int proto, str *via_params, unsigned int flags); char * build_res_buf_from_sip_res( struct sip_msg* msg, - unsigned int *returned_len, struct socket_info *sock,int flags); + unsigned int *returned_len, const struct socket_info *sock,int flags); char * build_res_buf_from_sip_req( unsigned int code, @@ -150,7 +150,7 @@ char * build_res_buf_from_sip_req( unsigned int code, struct bookmark *bmark); char* via_builder( unsigned int *len, - struct socket_info* send_sock, + const struct socket_info* send_sock, str *branch, str* extra_params, int proto, struct hostport *hp ); @@ -161,7 +161,7 @@ int branch_builder( unsigned int hash_index, /* output value: string and actual length */ char *branch_str, int *len ); -char *contact_builder(struct socket_info* send_sock, int *ct_len); +char *contact_builder(const struct socket_info* send_sock, int *ct_len); /* check if IP address in Via != source IP address of signaling */ int received_test( struct sip_msg *msg ); @@ -171,7 +171,7 @@ char *construct_uri(str *protocol,str *username,str *domain,str *port, void process_lumps( struct sip_msg* msg, struct lump* lumps, char* new_buf, unsigned int* new_buf_offs, unsigned int* orig_offs, - struct socket_info* send_sock, int max_offset); + const struct socket_info* send_sock, int max_offset); int is_del_via1_lump(struct sip_msg* msg); @@ -180,10 +180,10 @@ char* received_builder(struct sip_msg *msg, unsigned int *received_len); char* rport_builder(struct sip_msg *msg, unsigned int *rport_len); unsigned int prep_reassemble_body_parts( struct sip_msg* msg, - struct socket_info* send_sock); + const struct socket_info* send_sock); void reassemble_body_parts( struct sip_msg* msg, char* new_buf, unsigned int* new_offs, unsigned int* orig_offs, - struct socket_info* send_sock); + const struct socket_info* send_sock); #endif diff --git a/net/api_proto.h b/net/api_proto.h index 39f708f2a2d..37af16493a9 100644 --- a/net/api_proto.h +++ b/net/api_proto.h @@ -31,8 +31,8 @@ #define PROTO_PREFIX "proto_" 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); +typedef int (*proto_send_f)(const struct socket_info *si, char* buf,unsigned int len, + const union sockaddr_union* 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 7f570f4efaa..30ed4540a19 100644 --- a/net/api_proto_net.h +++ b/net/api_proto_net.h @@ -33,8 +33,9 @@ #define PROTO_NET_USE_UDP (1<<1) /* set by proto's that are based on UDP */ -typedef int (*proto_net_write_f)(void *src, int fd); -typedef int (*proto_net_read_f)(void *src, int *len); +typedef int (*proto_net_write_tcp_f)(struct tcp_connection *c, int fd); +typedef int (*proto_net_read_udp_f)(const struct socket_info *si, int *len); +typedef int (*proto_net_read_tcp_f)(struct tcp_connection *c, int *len); typedef int (*proto_net_conn_init_f)(struct tcp_connection *c); typedef void (*proto_net_conn_clean_f)(struct tcp_connection *c); typedef int (*proto_net_extra_match_f)(struct tcp_connection *c, void *id); @@ -43,12 +44,21 @@ typedef void (*proto_net_report_f)( int type, unsigned long long conn_id, struct api_proto_net { int flags; - unsigned async_chunks; - proto_net_write_f write; - proto_net_read_f read; - proto_net_conn_init_f conn_init; - proto_net_conn_clean_f conn_clean; - proto_net_extra_match_f conn_match; + union { + struct { + proto_net_read_udp_f read; + } dgram; + struct { + unsigned async_chunks; + proto_net_read_tcp_f read; + proto_net_write_tcp_f write; + struct { + proto_net_conn_init_f init; + proto_net_conn_clean_f clean; + proto_net_extra_match_f match; + } conn; + } stream; + }; proto_net_report_f report; }; diff --git a/net/net_tcp.c b/net/net_tcp.c index d4a8100f275..48fef454ae7 100644 --- a/net/net_tcp.c +++ b/net/net_tcp.c @@ -159,7 +159,7 @@ static struct scaling_profile *s_profile = NULL; /****************************** helper functions *****************************/ extern void handle_sigs(void); -static inline int init_sock_keepalive(int s, struct tcp_conn_profile *prof) +static inline int init_sock_keepalive(int s, const struct tcp_conn_profile *prof) { int ka; #if defined(HAVE_TCP_KEEPINTVL) || defined(HAVE_TCP_KEEPIDLE) || defined(HAVE_TCP_KEEPCNT) @@ -223,7 +223,7 @@ static inline void set_sock_reuseport(int s) /*! \brief Set all socket/fd options: disable nagle, tos lowdelay, * non-blocking * \return -1 on error */ -int tcp_init_sock_opt(int s, struct tcp_conn_profile *prof, enum si_flags socketflags) +int tcp_init_sock_opt(int s, const struct tcp_conn_profile *prof, enum si_flags socketflags) { int flags; int optval; @@ -451,7 +451,7 @@ int tcp_get_correlation_id( unsigned int id, unsigned long long *cid) int tcp_conn_get(unsigned int id, struct ip_addr* ip, int port, enum sip_protos proto, void *proto_extra_id, struct tcp_connection** conn, int* conn_fd, - struct socket_info* send_sock) + const struct socket_info* send_sock) { struct tcp_connection* c; struct tcp_connection* tmp; @@ -498,8 +498,8 @@ int tcp_conn_get(unsigned int id, struct ip_addr* ip, int port, proto == c->type && ip_addr_cmp(ip, &c->rcv.src_ip) && (proto_extra_id==NULL || - protos[proto].net.conn_match==NULL || - protos[proto].net.conn_match( c, proto_extra_id)) ) + protos[proto].net.stream.conn.match==NULL || + protos[proto].net.stream.conn.match( c, proto_extra_id)) ) goto found; } TCPCONN_UNLOCK(part); @@ -741,8 +741,8 @@ static void _tcpconn_rm(struct tcp_connection* c, int no_event) if (c->con_req) shm_free(c->con_req); - if (protos[c->type].net.conn_clean) - protos[c->type].net.conn_clean(c); + if (protos[c->type].net.stream.conn.clean) + protos[c->type].net.stream.conn.clean(c); if (!no_event) tcp_disconnect_event_raise(c); @@ -772,8 +772,8 @@ static void tcpconn_rm(struct tcp_connection* c) TCPCONN_UNLOCK(c->id); lock_destroy(&c->write_lock); - if (protos[c->type].net.conn_clean) - protos[c->type].net.conn_clean(c); + if (protos[c->type].net.stream.conn.clean) + protos[c->type].net.stream.conn.clean(c); shm_free(c); } @@ -864,8 +864,8 @@ static inline void tcpconn_ref(struct tcp_connection* c) } -static struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su, - struct socket_info* si, struct tcp_conn_profile *prof, +static struct tcp_connection* tcpconn_new(int sock, const union sockaddr_union* su, + const struct socket_info* si, const struct tcp_conn_profile *prof, int state, int flags) { struct tcp_connection *c; @@ -920,12 +920,12 @@ static struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su, c->hist = sh_push(c, con_hist); #endif - if (protos[si->proto].net.async_chunks) { + if (protos[si->proto].net.stream.async_chunks) { c->async = shm_malloc(sizeof(struct tcp_async_data) + - protos[si->proto].net.async_chunks * + protos[si->proto].net.stream.async_chunks * sizeof(struct tcp_async_chunk)); if (c->async) { - c->async->allocated = protos[si->proto].net.async_chunks; + c->async->allocated = protos[si->proto].net.stream.async_chunks; c->async->oldest = 0; c->async->pending = 0; } else { @@ -951,8 +951,8 @@ 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 socket_info* si, struct tcp_conn_profile *prof, +struct tcp_connection* tcp_conn_create(int sock, const union sockaddr_union* su, + const struct socket_info* si, struct tcp_conn_profile *prof, int state, int send2main) { struct tcp_connection *c; @@ -967,8 +967,8 @@ struct tcp_connection* tcp_conn_create(int sock, union sockaddr_union* su, return NULL; } - if (protos[c->type].net.conn_init && - protos[c->type].net.conn_init(c) < 0) { + if (protos[c->type].net.stream.conn.init && + protos[c->type].net.stream.conn.init(c) < 0) { LM_ERR("failed to do proto %d specific init for conn %p\n", c->type, c); tcp_conn_destroy(c); @@ -1072,7 +1072,7 @@ void tcp_conn_destroy(struct tcp_connection* tcpconn) * io events queued), >0 on success. success/error refer only to * the accept. */ -static inline int handle_new_connect(struct socket_info* si) +static inline int handle_new_connect(const struct socket_info* si) { union sockaddr_union su; struct tcp_connection* tcpconn; @@ -1545,7 +1545,7 @@ inline static int handle_io(struct fd_map* fm, int idx,int event_type) pt_become_active(); switch(fm->type){ case F_TCP_LISTENER: - ret = handle_new_connect((struct socket_info*)fm->data); + ret = handle_new_connect((const struct socket_info*)fm->data); break; case F_TCPCONN: ret = handle_tcpconn_ev((struct tcp_connection*)fm->data, idx, @@ -1651,7 +1651,7 @@ static void tcp_main_server(void) { static unsigned int last_sec = 0; int flags; - struct socket_info* si; + struct socket_info_full* sif; int n; /* we run in a separate, dedicated process, with its own reactor @@ -1664,7 +1664,8 @@ static void tcp_main_server(void) /* add all the sockets we listens on for connections */ for( n=PROTO_FIRST ; nnext ) { + for( sif=protos[n].listeners ; sif ; sif=sif->next ) { + struct socket_info* si = &sif->socket_info; if ( (si->socket!=-1) && reactor_add_reader( si->socket, F_TCP_LISTENER, RCT_PRIO_NET, si)<0 ) { @@ -2042,7 +2043,7 @@ int tcp_start_processes(int *chd_rank, int *startup_done) { int r, n, p_id; int reader_fd[2]; /* for comm. with the tcp workers read */ - struct socket_info *si; + struct socket_info_full *sif; const struct internal_fork_params ifp_sr_tcp = { .proc_desc = "SIP receiver TCP", .flags = OSS_PROC_NEEDS_SCRIPT, @@ -2058,7 +2059,7 @@ int tcp_start_processes(int *chd_rank, int *startup_done) * + no_listen_tcp */ for( r=0,n=PROTO_FIRST ; nnext,r++ ); + for(sif=protos[n].listeners; sif ; sif=sif->next,r++ ); /* create the socket pairs for ALL potential processes */ for(r=0; rflags & F_CONN_INIT)) { - if (protos[con->type].net.conn_init && - protos[con->type].net.conn_init(con) < 0) { + if (protos[con->type].net.stream.conn.init && + protos[con->type].net.stream.conn.init(con) < 0) { LM_ERR("failed to do proto %d specific init for conn %p\n", con->type, con); goto con_error; @@ -294,7 +294,7 @@ inline static int handle_io(struct fd_map* fm, int idx,int event_type) LM_DBG("Received con for async write %p ref = %d\n", con, con->refcnt); lock_get(&con->write_lock); - resp = protos[con->type].net.write( (void*)con, s ); + resp = protos[con->type].net.stream.write( con, s ); lock_release(&con->write_lock); if (resp<0) { ret=-1; /* some error occurred */ @@ -327,7 +327,7 @@ inline static int handle_io(struct fd_map* fm, int idx,int event_type) if (event_type & IO_WATCH_READ) { con=(struct tcp_connection*)fm->data; _tcp_done_reading_marker = 0; - resp = protos[con->type].net.read( (void*)con, &ret ); + resp = protos[con->type].net.stream.read( con, &ret ); if (resp<0) { ret=-1; /* some error occurred */ con->state=S_CONN_BAD; diff --git a/net/net_udp.c b/net/net_udp.c index ad10e076129..bd61aadddb5 100644 --- a/net/net_udp.c +++ b/net/net_udp.c @@ -65,7 +65,7 @@ void udp_destroy(void) /* tells how many processes the UDP layer will create */ int udp_count_processes(unsigned int *extra) { - struct socket_info *si; + struct socket_info_full *sif; unsigned int n, e, i; if (udp_disabled) { @@ -75,7 +75,8 @@ int udp_count_processes(unsigned int *extra) for( i=0,n=0,e=0 ; inext) { + for( sif=protos[i].listeners ; sif; sif=sif->next) { + const struct socket_info *si = &sif->socket_info; n+=si->workers; if (si->s_profile) if (si->s_profile->max_procs > si->workers) @@ -293,7 +294,7 @@ inline static int handle_io(struct fd_map* fm, int idx,int event_type) switch(fm->type){ case F_UDP_READ: n = protos[((struct socket_info*)fm->data)->proto].net. - read( fm->data /*si*/, &read); + dgram.read( fm->data /*si*/, &read); break; case F_TIMER_JOB: handle_timer_job(); @@ -455,7 +456,7 @@ static void udp_process_graceful_terminate(int sender, void *param) /* starts all UDP related processes */ int udp_start_processes(int *chd_rank, int *startup_done) { - struct socket_info *si; + struct socket_info_full *sif; int p_id; int i,p; const struct internal_fork_params ifp_udp_rcv = { @@ -471,7 +472,8 @@ int udp_start_processes(int *chd_rank, int *startup_done) if ( !is_udp_based_proto(p) ) continue; - for(si=protos[p].listeners; si ; si=si->next ) { + for( sif=protos[p].listeners; sif ; sif=sif->next ) { + struct socket_info* si = &sif->socket_info; if ( auto_scaling_enabled && si->s_profile && create_process_group( TYPE_UDP, si, si->s_profile, diff --git a/net/proto_tcp/proto_tcp.c b/net/proto_tcp/proto_tcp.c index ce4e67263c4..a2c06966f35 100644 --- a/net/proto_tcp/proto_tcp.c +++ b/net/proto_tcp/proto_tcp.c @@ -52,8 +52,8 @@ 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, +static int proto_tcp_send(const struct socket_info* send_sock, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id); inline static int _tcp_write_on_socket(struct tcp_connection *c, int fd, char *buf, int len); @@ -207,8 +207,8 @@ static int proto_tcp_init(struct proto_info *pi) pi->tran.dst_attr = tcp_conn_fcntl; pi->net.flags = PROTO_NET_USE_TCP; - pi->net.read = (proto_net_read_f)tcp_read_req; - pi->net.write = (proto_net_write_f)tcp_async_write; + pi->net.stream.read = tcp_read_req; + pi->net.stream.write = tcp_async_write; pi->net.report = tcp_report; if (tcp_async && !tcp_has_async_write()) { @@ -223,7 +223,7 @@ static int proto_tcp_init(struct proto_info *pi) * if the tcp_async is enbled */ if (tcp_async_max_postponed_chunks<=1) tcp_async_max_postponed_chunks = 2; - pi->net.async_chunks= tcp_async_max_postponed_chunks; + pi->net.stream.async_chunks= tcp_async_max_postponed_chunks; } return 0; @@ -360,9 +360,9 @@ 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, +static int proto_tcp_send(const struct socket_info* send_sock, char* buf, unsigned int len, - union sockaddr_union* to, unsigned int id) + const union sockaddr_union* to, unsigned int id) { struct tcp_connection *c; struct tcp_conn_profile prof; @@ -442,8 +442,8 @@ static int proto_tcp_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* connect is still in progress, break the sending * flow now (the actual write will be done when @@ -532,8 +532,8 @@ static int proto_tcp_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; /* we successfully added our write chunk - success */ sh_log(c->hist, TCP_SEND2MAIN, "send 3, (%d)", c->refcnt); @@ -581,8 +581,8 @@ static int proto_tcp_send(struct socket_info* send_sock, /* mark the ID of the used connection (tracing purposes) */ last_outgoing_tcp_id = c->id; - send_sock->last_local_real_port = c->rcv.dst_port; - send_sock->last_remote_real_port = c->rcv.src_port; + send_sock->last_real_ports->local = c->rcv.dst_port; + send_sock->last_real_ports->remote = c->rcv.src_port; sh_log(c->hist, TCP_SEND2MAIN, "send 6, (%d, async: %d)", c->refcnt, n < len); tcp_conn_release(c, (ntran.send = proto_udp_send; pi->net.flags = PROTO_NET_USE_UDP; - pi->net.read = (proto_net_read_f)udp_read_req; + pi->net.dgram.read = udp_read_req; return 0; } @@ -121,7 +121,7 @@ static int proto_udp_init_listener(struct socket_info *si) } -static int udp_read_req(struct socket_info *si, int* bytes_read) +static int udp_read_req(const struct socket_info *si, int* bytes_read) { struct receive_info ri; int len; @@ -198,8 +198,8 @@ static int udp_read_req(struct socket_info *si, int* bytes_read) * \param to destination address * \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, +static int proto_udp_send(const struct socket_info* source, + char* buf, unsigned int len, const union sockaddr_union* to, unsigned int id) { int n, tolen; diff --git a/net/tcp_common.c b/net/tcp_common.c index 76ffeec1c30..830500c3b70 100644 --- a/net/tcp_common.c +++ b/net/tcp_common.c @@ -140,8 +140,8 @@ 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, - enum sip_protos proto, struct tcp_conn_profile *prof, enum si_flags flags) +int tcp_sync_connect_fd(const union sockaddr_union* src, const union sockaddr_union* dst, + enum sip_protos proto, const struct tcp_conn_profile *prof, enum si_flags flags) { int s; union sockaddr_union my_name; @@ -181,8 +181,8 @@ int tcp_sync_connect_fd(union sockaddr_union* src, union sockaddr_union* dst, return -1; } -struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, +struct tcp_connection* tcp_sync_connect(const struct socket_info* send_sock, + const union sockaddr_union* server, struct tcp_conn_profile *prof, int *fd, int send2main) { struct tcp_connection* con; @@ -202,8 +202,8 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, return con; } -int tcp_async_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, +int tcp_async_connect(const struct socket_info* send_sock, + const union sockaddr_union* server, 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 5d95b2c5e94..035637b64d7 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, - enum sip_protos proto, struct tcp_conn_profile *prof, enum si_flags flags); +int tcp_sync_connect_fd(const union sockaddr_union* src, const union sockaddr_union* dst, + enum sip_protos proto, const 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, +struct tcp_connection* tcp_sync_connect(const struct socket_info* send_sock, + const union sockaddr_union* server, struct tcp_conn_profile *prof, int *fd, int send2main); /* Attempts do a connect to the given destination. It returns: @@ -42,8 +42,8 @@ struct tcp_connection* tcp_sync_connect(struct socket_info* send_sock, * 0 - connect launched as async (in progress) * -1 - error */ -int tcp_async_connect(struct socket_info* send_sock, - union sockaddr_union* server, struct tcp_conn_profile *prof, +int tcp_async_connect(const struct socket_info* send_sock, + const union sockaddr_union* 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..e1b6bc830a9 100644 --- a/net/tcp_conn_profile.c +++ b/net/tcp_conn_profile.c @@ -26,8 +26,8 @@ * 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 *_, - union sockaddr_union *__, enum sip_protos ___, +static int tcp_con_get_df_profile(const union sockaddr_union *_, + const union sockaddr_union *__, enum sip_protos ___, struct tcp_conn_profile *out_profile) { *out_profile = tcp_con_df_profile; @@ -36,8 +36,8 @@ 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, - union sockaddr_union *local, enum sip_protos proto, +int (*tcp_con_get_profile)(const union sockaddr_union *remote, + const union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile) = tcp_con_get_df_profile; struct tcp_conn_attr_key tcp_con_attr[] = { diff --git a/net/tcp_conn_profile.h b/net/tcp_conn_profile.h index 3061e12e352..4ddafbb9934 100644 --- a/net/tcp_conn_profile.h +++ b/net/tcp_conn_profile.h @@ -44,8 +44,8 @@ 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, - union sockaddr_union *local, enum sip_protos proto, +extern int (*tcp_con_get_profile)(const union sockaddr_union *remote, + const union sockaddr_union *local, enum sip_protos proto, struct tcp_conn_profile *out_profile); /* initialize the support for customized, per-path TCP connection profiles */ diff --git a/net/trans.c b/net/trans.c index d9f3e0f767a..5e23e5bc2fe 100644 --- a/net/trans.c +++ b/net/trans.c @@ -229,12 +229,13 @@ int fix_all_socket_lists(void) int trans_init_all_listeners(void) { - struct socket_info *si; + struct socket_info_full *sif; int i; for (i = PROTO_FIRST; i < PROTO_LAST; i++) if (protos[i].id != PROTO_NONE) - for( si=protos[i].listeners ; si ; si=si->next ) { + for( sif=protos[i].listeners ; sif ; sif=sif->next ) { + struct socket_info *si = &sif->socket_info; if (protos[i].tran.init_listener(si)<0) { LM_ERR("failed to init listener [%.*s], proto %s\n", si->name.len, si->name.s, @@ -255,7 +256,7 @@ int trans_init_all_listeners(void) void print_all_socket_lists(void) { - struct socket_info *si; + struct socket_info_full *sif; int i; @@ -263,11 +264,13 @@ void print_all_socket_lists(void) if (protos[i].id == PROTO_NONE) continue; - for (si = protos[i].listeners; si; si = si->next) + for ( sif = protos[i].listeners; sif; sif = sif->next ) { + const struct socket_info *si = &sif->socket_info; printf(" %s: %s [%s]:%s%s%s%s\n", protos[i].name, si->name.s, si->address_str.s, si->port_no_str.s, si->flags & SI_IS_MCAST ? " mcast" : "", si->flags & SI_FRAG ? " allow_fragments" : "", is_anycast(si)? " anycast" : ""); + } } } diff --git a/net/trans.h b/net/trans.h index 8d56dc6dd24..2ee2d9b23d3 100644 --- a/net/trans.h +++ b/net/trans.h @@ -50,7 +50,7 @@ struct proto_info { struct api_proto_net net; /* listeners on this proto */ - struct socket_info *listeners; + struct socket_info_full *listeners; /* default sending interfaces */ struct socket_info *sendipv4; diff --git a/parser/msg_parser.h b/parser/msg_parser.h index ac317abed53..e3cdd5e7b2e 100644 --- a/parser/msg_parser.h +++ b/parser/msg_parser.h @@ -296,7 +296,7 @@ struct sip_msg { unsigned int ruri_bflags; /* per-branch flags for RURI*/ /* force sending on this socket */ - struct socket_info* force_send_socket; + const struct socket_info* force_send_socket; /* path vector to generate Route hdrs */ str path_vec; diff --git a/pvar.c b/pvar.c index 61ae6e3d3e8..1f8511c2fce 100644 --- a/pvar.c +++ b/pvar.c @@ -1970,7 +1970,7 @@ static inline int get_branch_field( int idx, pv_name_t *pvn, pv_value_t *res) str duri; str path; unsigned int flags; - struct socket_info *si; + const struct socket_info *si; uri.s = get_branch(idx, &uri.len, &q, &duri, &path, &flags, &si); if (!uri.s) @@ -2160,7 +2160,7 @@ static int pv_parse_socket_name(pv_spec_p sp, const str *in) } -static inline int get_socket_field( struct socket_info *si, +static inline int get_socket_field( const struct socket_info *si, pv_name_t *pvn, pv_value_t *res) { if (si==NULL) @@ -2256,7 +2256,7 @@ static int pv_get_socket_in_fields(struct sip_msg *msg, pv_param_t *param, static int pv_get_socket_out_fields(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { - struct socket_info *si; + const struct socket_info *si; if(msg==NULL || res==NULL) return -1; @@ -3162,7 +3162,7 @@ static int pv_set_branch_fields(struct sip_msg* msg, pv_param_t *param, str *s; qvalue_t q; unsigned int flags; - struct socket_info *si; + const struct socket_info *si; if (msg==NULL || param==NULL) { LM_ERR("bad parameters\n"); @@ -3259,7 +3259,7 @@ static int pv_set_branch_fields(struct sip_msg* msg, pv_param_t *param, static int pv_set_force_sock(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val) { - struct socket_info *si; + const struct socket_info *si; if(msg==NULL || param==NULL) { diff --git a/serialize.c b/serialize.c index 608e48c7885..2d2e2509c51 100644 --- a/serialize.c +++ b/serialize.c @@ -94,7 +94,7 @@ int serialize_branches(struct sip_msg *msg, int clean_before, int keep_order) char *p; str dst_uri, path, enc_info; unsigned int flags; - struct socket_info *sock_info; + const struct socket_info *sock_info; int_str val; int idx; diff --git a/sl_cb.c b/sl_cb.c index 7c91e27fbdf..5118856b196 100644 --- a/sl_cb.c +++ b/sl_cb.c @@ -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 union sockaddr_union *dst, const struct socket_info *sock, int proto) { struct sl_callback *cbp; diff --git a/sl_cb.h b/sl_cb.h index 27005d48246..f724303f053 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 union sockaddr_union *dst, const 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); @@ -54,7 +54,7 @@ void slcb_run_reply_out(struct sip_msg *req, str *buffer, union sockaddr_union *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 union sockaddr_union *dst, const struct socket_info *sock, int proto); #endif diff --git a/socket_info.c b/socket_info.c index b27a4e83bee..93a7983ff90 100644 --- a/socket_info.c +++ b/socket_info.c @@ -113,14 +113,17 @@ /* another helper function, it just creates a socket_info struct */ -static struct socket_info* new_sock_info( struct socket_id *sid) +static struct socket_info_full* new_sock_info( struct socket_id *sid) { - struct socket_info* si; + struct socket_info_full *sif; + struct socket_info *si; - si=(struct socket_info*) pkg_malloc(sizeof(struct socket_info)); - if (si==0) goto error; - memset(si, 0, sizeof(struct socket_info)); + sif=(struct socket_info_full*) pkg_malloc(sizeof(*sif)); + if (sif==NULL) goto error; + memset(sif, 0, sizeof(*sif)); + si = &sif->socket_info; si->socket=-1; + si->last_real_ports = &sif->last_real_ports; if (sid->name) { si->name.len=strlen(sid->name); @@ -192,19 +195,20 @@ static struct socket_info* new_sock_info( struct socket_id *sid) } } } - return si; + return sif; error: LM_ERR("pkg memory allocation error\n"); - if (si) pkg_free(si); + if (sif) pkg_free(sif); return 0; } /* delete a socket_info struct */ -static void free_sock_info(struct socket_info* si) +static void free_sock_info(struct socket_info_full* sif) { - if(si){ + if(sif){ + struct socket_info *si = &sif->socket_info; if(si->name.s) pkg_free(si->name.s); if(si->tag.s) pkg_free(si->tag.s); if(si->sock_str.s) pkg_free(si->sock_str.s); @@ -226,13 +230,14 @@ static void free_sock_info(struct socket_info* si) * WARNING: uses str2ip6 so it will overwrite any previous * unsaved result of this function (static buffer) */ -struct socket_info* grep_sock_info_ext(str* host, unsigned short port, +const struct socket_info* grep_sock_info_ext(str* host, unsigned short port, unsigned short proto, int check_tags) { char* hname; int h_len; - struct socket_info* si; - struct socket_info** list; + const struct socket_info* si = NULL; + struct socket_info_full* sif; + struct socket_info_full ** list; unsigned short c_proto; struct ip_addr* ip6; @@ -254,7 +259,8 @@ struct socket_info* grep_sock_info_ext(str* host, unsigned short port, LM_WARN("unknown proto %d\n", c_proto); goto not_found; /* false */ } - for (si=*list; si; si=si->next){ + for (sif=*list; sif; sif=sif->next){ + si = &sif->socket_info; LM_DBG("checking if host==us: %d==%d && " " [%.*s] == [%.*s]\n", h_len, @@ -342,11 +348,12 @@ struct socket_info* grep_sock_info_ext(str* host, unsigned short port, * WARNING: uses str2ip6 so it will overwrite any previous * unsaved result of this function (static buffer) */ -struct socket_info* find_si(struct ip_addr* ip, unsigned short port, +const struct socket_info* find_si(const struct ip_addr* ip, unsigned short port, unsigned short proto) { - struct socket_info* si; - struct socket_info** list; + const struct socket_info* si = NULL; + struct socket_info_full* sif; + struct socket_info_full** list; unsigned short c_proto; c_proto=proto?proto:PROTO_UDP; @@ -358,7 +365,8 @@ struct socket_info* find_si(struct ip_addr* ip, unsigned short port, LM_WARN("unknown proto %d\n", c_proto); goto not_found; /* false */ } - for (si=*list; si; si=si->next){ + for (sif=*list; sif; sif=sif->next){ + si = &sif->socket_info; if (port) { if (si->port_no!=port) { continue; @@ -377,7 +385,7 @@ struct socket_info* find_si(struct ip_addr* ip, unsigned short port, /* parses the specified `spec` and returns an associated * socket_info*, if it could be found */ -struct socket_info* parse_sock_info(str *addr) +const struct socket_info* parse_sock_info(str *addr) { int port, proto; str host; @@ -397,9 +405,9 @@ struct socket_info* parse_sock_info(str *addr) /* adds a new sock_info structure to the corresponding list * return 0 on success, -1 on error */ -int new_sock2list(struct socket_id *sid, struct socket_info** list) +int new_sock2list(struct socket_id *sid, struct socket_info_full** list) { - struct socket_info* si; + struct socket_info_full* si; si=new_sock_info(sid); if (si==0){ @@ -418,7 +426,7 @@ int new_sock2list(struct socket_id *sid, struct socket_info** list) * WARNING: it only works with ipv6 addresses on FreeBSD * return: -1 on error, 0 on success */ -int expand_interface(struct socket_info *si, struct socket_info** list) +static int expand_interface(const struct socket_info *si, struct socket_info_full** list) { int ret = -1; struct ip_addr addr; @@ -591,11 +599,12 @@ int expand_interface(struct socket_info *si, struct socket_info** list) /* fixes a socket list => resolve addresses, * interface names, fills missing members, remove duplicates */ -int fix_socket_list(struct socket_info **list) +int fix_socket_list(struct socket_info_full **list) { + struct socket_info_full* sif; struct socket_info* si; - struct socket_info* l; - struct socket_info* next; + struct socket_info_full* l; + struct socket_info_full* next; char* tmp; int len; struct hostent* he; @@ -604,8 +613,9 @@ int fix_socket_list(struct socket_info **list) /* try to change all the interface names into addresses * --ugly hack */ - for (si=*list;si;){ - next=si->next; + for (sif=*list;sif;){ + next=sif->next; + si = &sif->socket_info; // fix the SI_IS_LO flag for sockets specified by IP/hostname as expand_interface // below will only do it for sockets specified using the network interface name if (STR_IMATCH(si->name, "localhost") || @@ -615,16 +625,17 @@ int fix_socket_list(struct socket_info **list) } if (expand_interface(si, list)!=-1){ /* success => remove current entry (shift the entire array)*/ - sock_listrm(list, si); - free_sock_info(si); + sock_listrm(list, sif); + free_sock_info(sif); } - si=next; + sif=next; } /* get ips & fill the port numbers*/ #ifdef EXTRA_DEBUG LM_DBG("listening on \n"); #endif - for (si=*list;si;si=si->next){ + for (sif=*list;sif;sif=sif->next){ + si = &sif->socket_info; /* fix the number of processes per interface */ if (!si->workers && is_udp_based_proto(si->proto)) si->workers = udp_workers_no; @@ -823,25 +834,27 @@ int fix_socket_list(struct socket_info **list) #endif } /* removing duplicate addresses*/ - for (si=*list;si; si=si->next){ - for (l=si->next;l;){ + for (sif=*list;sif; sif=sif->next){ + for (l=sif->next;l;){ next=l->next; - if ((si->port_no==l->port_no) && - (si->address.af==l->address.af) && - (memcmp(si->address.u.addr, l->address.u.addr, si->address.len) + si = &sif->socket_info; + const struct socket_info *sl = &l->socket_info; + if ((si->port_no==sl->port_no) && + (si->address.af==sl->address.af) && + (memcmp(si->address.u.addr, sl->address.u.addr, si->address.len) == 0) ){ #ifdef EXTRA_DEBUG printf("removing duplicate %s [%s] == %s [%s]\n", si->name.s, si->address_str.s, - l->name.s, l->address_str.s); + sl->name.s, sl->address_str.s); #endif /* add the name to the alias list*/ - if ((!(l->flags& SI_IS_IP)) && ( - (l->name.len!=si->name.len)|| - (strncmp(l->name.s, si->name.s, si->name.len)!=0)) + if ((!(sl->flags& SI_IS_IP)) && ( + (sl->name.len!=si->name.len)|| + (strncmp(sl->name.s, si->name.s, si->name.len)!=0)) ) - if (add_alias(l->name.s,l->name.len,l->port_no,l->proto)<0) + if (add_alias(sl->name.s,sl->name.len,sl->port_no,sl->proto)<0) LM_ERR(" add_alias failed\n"); /* remove l*/ @@ -854,20 +867,21 @@ int fix_socket_list(struct socket_info **list) #ifdef USE_MCAST /* Remove invalid multicast entries */ - si=*list; - while(si){ + sif=*list; + while(sif){ + si = &sif->socket_info; if ((si->flags & SI_IS_MCAST) && (si->proto != PROTO_UDP) ){ LM_WARN("removing entry %s:%s [%s]:%s\n", get_proto_name(si->proto), si->name.s, si->address_str.s, si->port_no_str.s); - l = si; - si=si->next; + l = sif; + sif=sif->next; sock_listrm(list, l); free_sock_info(l); } else { - si=si->next; + sif=sif->next; } } #endif /* USE_MCAST */ @@ -914,8 +928,8 @@ int fix_socket_list(struct socket_info **list) */ int get_socket_list_from_proto(unsigned int **ipList, int protocol) { - struct socket_info *si; - struct socket_info** list; + struct socket_info_full *sif; + struct socket_info_full ** list; int num_ip_octets = 4; int numberOfSockets = 0; @@ -938,9 +952,9 @@ int get_socket_list_from_proto(unsigned int **ipList, int protocol) { /* Find out how many sockets are in the list. We need to know this so * we can malloc an array to assign to ipList. */ - for(si=list?*list:0; si; si=si->next){ + for(sif=list?*list:0; sif; sif=sif->next){ /* We only support IPV4 at this point. */ - if (si->address.af == AF_INET) { + if (sif->socket_info.address.af == AF_INET) { numberOfSockets++; } } @@ -966,7 +980,8 @@ int get_socket_list_from_proto(unsigned int **ipList, int protocol) { list=get_sock_info_list(protocol); /* Extract out the IP Addresses and ports. */ - for(si=list?*list:0; si; si=si->next){ + for(sif=list?*list:0; sif; sif=sif->next){ + const struct socket_info *si = &sif->socket_info; /* We currently only support IPV4. */ if (si->address.af != AF_INET) { diff --git a/socket_info.h b/socket_info.h index 75604de515c..1ed6df50e54 100644 --- a/socket_info.h +++ b/socket_info.h @@ -37,6 +37,11 @@ #include "net/trans.h" #include "ut.h" +struct last_real_ports { + unsigned short local; + unsigned short remote; +}; + struct socket_info { int socket; str name; /*!< name - eg.: foo.bar or 10.0.0.1 */ @@ -65,13 +70,15 @@ struct socket_info { * they are simply overwritten by the next write op on this socket/conn. * IMPORTANT: when reading them, be sure you are just after a write ops, * otherwise you may read old data here */ - unsigned short last_local_real_port; - unsigned short last_remote_real_port; - - struct socket_info* next; - struct socket_info* prev; + struct last_real_ports *last_real_ports; }; +struct socket_info_full { + struct socket_info socket_info; + struct last_real_ports last_real_ports; + struct socket_info_full* next; + struct socket_info_full* prev; +}; #define get_socket_real_name(_s) \ (&(_s)->sock_str) @@ -86,9 +93,9 @@ struct socket_info { #define PROTO_NAME_MAX_SIZE 8 /* CHANGEME if you define a bigger protocol name * currently hep_tcp - biggest proto */ -int new_sock2list(struct socket_id *sid, struct socket_info** list); +int new_sock2list(struct socket_id *sid, struct socket_info_full** list); -int fix_socket_list(struct socket_info **); +int fix_socket_list(struct socket_info_full **); /* * This function will retrieve a list of all ip addresses and ports that @@ -142,20 +149,20 @@ void print_aliases(); #define grep_internal_sock_info(_host, _port, _proto) \ grep_sock_info_ext(_host, _port, _proto, 1) -struct socket_info* grep_sock_info_ext(str* host, unsigned short port, +const struct socket_info* grep_sock_info_ext(str* host, unsigned short port, unsigned short proto, int check_tag); -struct socket_info* parse_sock_info(str *spec); +const struct socket_info* parse_sock_info(str *spec); -struct socket_info* find_si(struct ip_addr* ip, unsigned short port, +const struct socket_info* find_si(const struct ip_addr* ip, unsigned short port, unsigned short proto); #define set_sip_defaults( _port, _proto) \ do { \ - if (_proto==PROTO_NONE) _proto = PROTO_UDP; \ - if (_port==0) { \ - if (_proto==PROTO_TLS) _port = SIPS_PORT; else\ - _port = SIP_PORT; \ + if ((_proto)==PROTO_NONE) (_proto) = PROTO_UDP; \ + if ((_port)==0) { \ + if ((_proto)==PROTO_TLS) (_port) = SIPS_PORT; else\ + (_port) = SIP_PORT; \ } \ } while(0) @@ -177,13 +184,13 @@ static inline int next_proto(unsigned short proto) /*! \brief gets first non-null socket_info structure * (useful if for. e.g we are not listening on any udp sockets ) */ -inline static struct socket_info* get_first_socket(void) +inline static const struct socket_info* get_first_socket(void) { int p; for( p=0 ; psocket_info; return NULL; } @@ -548,7 +555,7 @@ static inline char *proto2a(int proto) 1 - advertised name 2 - tagged name */ -static inline char* socket2str(struct socket_info *sock, char *s, int *len, int type) +static inline char* socket2str(const struct socket_info *sock, char *s, int *len, int type) { static char buf[MAX_SOCKET_STR]; char *p,*p1; @@ -598,7 +605,7 @@ static inline char* socket2str(struct socket_info *sock, char *s, int *len, int #define get_sock_info_list(_proto) \ - ((_proto>=PROTO_FIRST && _proto=PROTO_FIRST && (_proto)