diff --git a/main.c b/main.c index d37a9b85739..4ce3ec162d2 100644 --- a/main.c +++ b/main.c @@ -955,15 +955,6 @@ int main(int argc, char** argv) yydebug = 1; #endif - /* - * initializes transport interfaces - we initialize them here because we - * can have listening interfaces declared in the command line - */ - if (trans_init() < 0) { - LM_ERR("cannot initialize transport interface\n"); - goto error; - } - /* get uid/gid */ if (user){ if (user2uid(&uid, &gid, user)<0){ diff --git a/net/trans.c b/net/trans.c index 0b14cadf80f..cbb17e5a630 100644 --- a/net/trans.c +++ b/net/trans.c @@ -33,38 +33,25 @@ #include "proto_udp/proto_udp_handler.h" -/* we alocate this dynamically because we don't know how when new protocols - * are developed. Since this is done only once, it's not that bad */ -struct proto_info *protos; +/* + * we need to always populate this structure at startup, at least the SIP + * protocols, because we never know what kind of traffic we receive and have + * to print its name + */ +struct proto_info protos[PROTO_LAST - PROTO_NONE] = { + + { }, /* PROTO_NONE */ + { .name = "udp", .port = 5060 }, /* PROTO_UDP */ + { .name = "tcp", .port = 5060 }, /* PROTO_TCP */ + { .name = "tls", .port = 5061 }, /* PROTO_TLS */ + { .name = "sctp", .port = 5060 }, /* PROTO_SCTP */ + { .name = "ws", .port = 80 }, /* PROTO_WS */ + { .name = "wss", .port = 443 }, /* PROTO_WSS */ + /* populate here for other protos - not necessary right now */ +}; static struct socket_id *cmd_listeners; - -int trans_init(void) -{ - unsigned int proto_nr; - - proto_nr = PROTO_LAST - PROTO_NONE; - protos = pkg_malloc(proto_nr * sizeof(struct proto_info)); - if (!protos) { - LM_ERR("no more memory to allocate protocols\n"); - return -1; - } - - memset(protos, 0, proto_nr * sizeof(struct proto_info)); - - return 0; -} - -void trans_destroy(void) -{ - int i; - for (i = PROTO_FIRST; i < PROTO_LAST; i++) - if (protos[i].id != PROTO_NONE) - pkg_free(protos[i].name); - pkg_free(protos); -} - #define PROTO_PREFIX_LEN (sizeof(PROTO_PREFIX) - 1) int trans_load(void) @@ -117,10 +104,13 @@ int trans_load(void) found_proto = 1; /* copy necessary info */ protos[pi.id].id = pi.id; - protos[pi.id].name = pi.name; protos[pi.id].default_port = pi.default_port; protos[pi.id].tran = pi.tran; protos[pi.id].net = pi.net; + /* + * XXX: make sure you never overwrite port or name + * should we put it in a separate structure? + */ } } if (found_proto) diff --git a/net/trans.h b/net/trans.h index e9f948665f5..8862d145884 100644 --- a/net/trans.h +++ b/net/trans.h @@ -31,13 +31,16 @@ #include "api_proto_net.h" struct proto_info { - /* proto as ID */ - enum sip_protos id; - /* the name of the protocol */ char *name; - /* the default protocol */ + /* the default port according to RFC */ + unsigned short port; + + /* proto as ID */ + enum sip_protos id; + + /* the default port, in case it is missing in the listener */ unsigned short default_port; /* bindings for the transport interface */ @@ -59,7 +62,7 @@ struct proto_info { * listeners */ typedef int (*api_proto_init)(struct proto_info *pi); -extern struct proto_info *protos; +extern struct proto_info protos[]; #define is_tcp_based_proto(_p) \ (protos[_p].net.flags&PROTO_NET_USE_TCP) @@ -75,16 +78,6 @@ extern struct proto_info *protos; protos[(_rcv)->proto].tran.dst_attr(_rcv,_attr,_val);\ }while(0) -/* - * initializes transport interface structures - */ -int trans_init(void); - -/* - * destroys the transport interface structures - */ -void trans_destroy(void); - /* * loads the transport protocol */