Skip to content

Commit

Permalink
net: bind protocols and default port before mod_init
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Feb 19, 2015
1 parent 2a14ce8 commit 36586d6
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 146 deletions.
11 changes: 1 addition & 10 deletions cfg.y
Expand Up @@ -482,12 +482,7 @@ statements: statements statement {}
| statements error { yyerror(""); YYABORT;}
;

statement: assign_stm {
/* FIXME add the temporary listening interfaces */
if (fix_tmp_listeners() < 0) {
LM_WARN("cannot fix command line listeners\n");
}
}
statement: assign_stm
| module_stm
| {rt=REQUEST_ROUTE;} route_stm
| {rt=FAILURE_ROUTE;} failure_route_stm
Expand Down Expand Up @@ -540,10 +535,6 @@ proto: ID {
yyerrorf("cannot handle protocol <%s>\n", $1);
YYABORT;
}
if (trans_load_proto($1, i_tmp) < 0) {
yyerrorf("cannot load protocol <%s>\n", $1);
YYABORT;
}
$$ = i_tmp;
}
;
Expand Down
14 changes: 13 additions & 1 deletion main.c
Expand Up @@ -919,7 +919,7 @@ int main(int argc, char** argv)
}
tmp[tmp_len]=0; /* null terminate the host */
/* add a new addr. to our address list */
if (add_tmp_listener(tmp, port, proto)!=0){
if (add_cmd_listener(tmp, port, proto)!=0){
LM_ERR("failed to add new listen address\n");
goto error00;
}
Expand Down Expand Up @@ -1122,6 +1122,18 @@ int main(int argc, char** argv)
/* init the resolver, before fixing the config */
resolv_init();

/* fix temporary listeners added in the cmd line */
if (fix_cmd_listeners() < 0) {
LM_ERR("cannot add temproray listeners\n");
return ret;
}

/* load transport protocols */
if (trans_load() < 0) {
LM_ERR("cannot load transport protocols\n");
goto error;
}

/* fix parameters */
if (port_no<=0) port_no=SIP_PORT;

Expand Down
7 changes: 7 additions & 0 deletions modules/proto_tls/proto_tls.c
Expand Up @@ -57,6 +57,7 @@ static int tls_port_no = SIPS_PORT;
static char *tls_domain_avp = NULL;

static int mod_init(void);
static int proto_tls_init(void);
static void mod_destroy(void);
static int proto_tls_api_bind(struct api_proto *proto_binds,
struct api_proto_net *net_binds, unsigned short *port);
Expand Down Expand Up @@ -129,6 +130,7 @@ struct module_exports exports = {
};

static struct api_proto tls_proto_binds = {
.init = proto_tls_init,
.init_listener = proto_tls_init_listener,
.send = proto_tls_send,
};
Expand Down Expand Up @@ -986,6 +988,11 @@ static void mod_destroy(void)
}


static int proto_tls_init(void)
{
/* TODO - implement this */
return 0;
}
static int proto_tls_api_bind(struct api_proto *proto_api,
struct api_proto_net *net_binds, unsigned short *port)
{
Expand Down
2 changes: 2 additions & 0 deletions net/api_proto.h
Expand Up @@ -31,11 +31,13 @@

#define PROTO_PREFIX "proto_"

typedef int (*proto_init_f)(void);
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 id);

struct api_proto {
proto_init_f init;
proto_init_listener_f init_listener;
proto_send_f send;
};
Expand Down
8 changes: 8 additions & 0 deletions net/proto_tcp/proto_tcp.c
Expand Up @@ -39,6 +39,7 @@
#include "proto_tcp_handler.h"

static int mod_init(void);
static int proto_tcp_init(void);
static int proto_tcp_api_bind(struct api_proto *proto_binds,
struct api_proto_net *net_binds, unsigned short *port);
static int proto_tcp_init_listener(struct socket_info *si);
Expand Down Expand Up @@ -156,6 +157,7 @@ struct module_exports proto_tcp_exports = {
};

static struct api_proto tcp_proto_binds = {
.init = proto_tcp_init,
.init_listener = proto_tcp_init_listener,
.send = proto_tcp_send,
};
Expand Down Expand Up @@ -189,6 +191,12 @@ static int mod_init(void)
return 0;
}

static int proto_tcp_init(void)
{
/* TODO - port fixing */
return 0;
}


static int proto_tcp_api_bind(struct api_proto *proto_api,
struct api_proto_net *net_binds, unsigned short *port)
Expand Down
9 changes: 9 additions & 0 deletions net/proto_udp/proto_udp.c
Expand Up @@ -41,6 +41,7 @@


static int mod_init(void);
static int proto_udp_init(void);
static int proto_udp_api_bind(struct api_proto *proto_binds,
struct api_proto_net *net_binds, unsigned short *port);
static int proto_udp_init_listener(struct socket_info *si);
Expand Down Expand Up @@ -83,6 +84,7 @@ struct module_exports proto_udp_exports = {
};

static struct api_proto udp_proto_binds = {
.init = proto_udp_init,
.init_listener = proto_udp_init_listener,
.send = proto_udp_send,
};
Expand All @@ -103,6 +105,13 @@ static int mod_init(void)
}


static int proto_udp_init(void)
{
/* TODO - port fixing */
return 0;
}


static int proto_udp_api_bind(struct api_proto *proto_api,
struct api_proto_net *net_binds, unsigned short *port)
{
Expand Down

0 comments on commit 36586d6

Please sign in to comment.