diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-17 20:32:09 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-22 21:05:59 +0100 |
commit | cfe9d718e27b812da4b90c5bda2fea8c9ce4ff7b (patch) | |
tree | 1c025dbed694d0332648f2d440597d47373a0227 | |
parent | 4cee7c09018609332e057359cf8533624d64b918 (diff) |
vty: Remove more globals from the bsc data.
This is a interim solution until we have the new and all mighty
new config file format. This should work for now, makes the init
abit harder to understand though.
-rw-r--r-- | include/bsc_data.h | 15 | ||||
-rw-r--r-- | include/ss7_application.h | 6 | ||||
-rw-r--r-- | src/bsc.c | 8 | ||||
-rw-r--r-- | src/links.c | 35 | ||||
-rw-r--r-- | src/main.c | 24 | ||||
-rw-r--r-- | src/main_stp.c | 50 | ||||
-rw-r--r-- | src/ss7_application.c | 25 | ||||
-rw-r--r-- | src/vty_interface.c | 43 |
8 files changed, 117 insertions, 89 deletions
diff --git a/include/bsc_data.h b/include/bsc_data.h index 83061e2..12e8e93 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -69,22 +69,10 @@ struct bsc_data { /* udp code */ struct mtp_udp_data udp_data; - int dpc; - int opc; - int sccp_opc; - int isup_opc; int src_port; int udp_port; char *udp_ip; int udp_nr_links; - int once; - - /* the network header to use */ - int ni_ni; - int ni_spare; - - /* isup handling */ - int isup_pass; /* MTP Links */ struct llist_head linksets; @@ -115,9 +103,10 @@ void mtp_linkset_up(struct mtp_link_set *); /* connection tracking and action */ /* udp init */ +struct mtp_link_set *link_set_create(struct bsc_data *bsc); int link_global_init(struct mtp_udp_data *data, int src_port); int link_udp_init(struct mtp_udp_link *data, char *dest_ip, int port); -struct mtp_link_set *link_init(struct bsc_data *bsc); +int link_init(struct bsc_data *bsc, struct mtp_link_set *set); int link_shutdown_all(struct mtp_link_set *); int link_reset_all(struct mtp_link_set *); int link_clear_all(struct mtp_link_set *); diff --git a/include/ss7_application.h b/include/ss7_application.h index 51426b5..66ddd87 100644 --- a/include/ss7_application.h +++ b/include/ss7_application.h @@ -64,6 +64,9 @@ struct ss7_application { struct bsc_data *bsc; + /* isup handling */ + int isup_pass; + /* handling for the NAT/State handling */ struct llist_head sccp_connections; struct timer_list reset_timeout; @@ -81,4 +84,7 @@ int ss7_application_setup(struct ss7_application *, int type, int ss7_application_start(struct ss7_application *); +/* config changes */ +void ss7_application_pass_isup(struct ss7_application *, int pass); + #endif @@ -22,7 +22,6 @@ #include <bsc_data.h> #include <cellmgr_debug.h> #include <msc_connection.h> -#include <mtp_level3.h> #include <mtp_pcap.h> #include <osmocore/talloc.h> @@ -68,16 +67,11 @@ struct bsc_data *bsc_data_create() INIT_LLIST_HEAD(&bsc->mscs); INIT_LLIST_HEAD(&bsc->apps); - bsc->dpc = 1; - bsc->opc = 0; - bsc->sccp_opc = -1; - bsc->isup_opc = -1; bsc->udp_port = 3456; bsc->udp_ip = NULL; bsc->udp_nr_links = 1; + bsc->src_port = 1313; - bsc->ni_ni = MTP_NI_NATION_NET; - bsc->ni_spare = 0; bsc->pcap_fd = -1; bsc->udp_reset_timeout = 180; diff --git a/src/links.c b/src/links.c index 236d190..a756a68 100644 --- a/src/links.c +++ b/src/links.c @@ -24,6 +24,7 @@ #include <cellmgr_debug.h> #include <msc_connection.h> #include <mtp_data.h> +#include <mtp_level3.h> #include <mtp_pcap.h> #include <snmp_mtp.h> @@ -87,39 +88,43 @@ void mtp_link_restart(struct mtp_link *link) link->reset(link); } -struct mtp_link_set *link_init(struct bsc_data *bsc) +struct mtp_link_set *link_set_create(struct bsc_data *bsc) { - int i; - struct mtp_udp_link *lnk; - struct mtp_link *blnk; struct mtp_link_set *set; set = mtp_link_set_alloc(bsc); set->name = talloc_strdup(set, "MTP"); - set->dpc = bsc->dpc; - set->opc = bsc->opc; - set->sccp_opc = bsc->sccp_opc > -1 ? bsc->sccp_opc : bsc->opc; - set->isup_opc = bsc->isup_opc > -1 ? bsc->isup_opc : bsc->opc; - set->sltm_once = bsc->once; - set->ni = bsc->ni_ni; - set->spare = bsc->ni_spare; + set->sccp_opc = set->isup_opc = -1; set->pcap_fd = bsc->pcap_fd; + set->ni = MTP_NI_NATION_NET; + set->spare = 0; + set->supported_ssn[1] = 1; set->supported_ssn[7] = 1; set->supported_ssn[8] = 1; set->supported_ssn[146] = 1; set->supported_ssn[254] = 1; + return set; +} + +int link_init(struct bsc_data *bsc, struct mtp_link_set *set) +{ + int i; + struct mtp_udp_link *lnk; + struct mtp_link *blnk; + + if (!bsc->src_port) { LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n"); - return NULL; + return -1; } LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); if (link_global_init(&bsc->udp_data, bsc->src_port) != 0) - return NULL; + return -1; for (i = 1; i <= bsc->udp_nr_links; ++i) { @@ -135,10 +140,10 @@ struct mtp_link_set *link_init(struct bsc_data *bsc) /* now connect to the transport */ if (link_udp_init(lnk, bsc->udp_ip, bsc->udp_port) != 0) - return NULL; + return -1; } - return set; + return 0; } int link_shutdown_all(struct mtp_link_set *set) @@ -95,6 +95,20 @@ int main(int argc, char **argv) srand(time(NULL)); cell_vty_init(); + + set = link_set_create(bsc); + if (!set) { + LOGP(DINP, LOGL_ERROR, "Failed to allocate the link.\n"); + return -1; + } + + app = ss7_application_alloc(bsc); + if (!app) { + LOGP(DINP, LOGL_ERROR, "Failed to create the SS7 application.\n"); + return -1; + } + + /* Now parse the configuration file */ if (vty_read_config_file(config, NULL) < 0) { fprintf(stderr, "Failed to read the VTY config.\n"); return -1; @@ -104,15 +118,9 @@ int main(int argc, char **argv) if (rc < 0) return rc; - set = link_init(bsc); - if (!set) - return -1; - - app = ss7_application_alloc(bsc); - if (!app) { - LOGP(DINP, LOGL_ERROR, "Failed to create the SS7 application.\n"); + /* create the links and start */ + if (link_init(bsc, set) != 0) return -1; - } ss7_application_setup(app, APP_CELLMGR, SS7_SET_LINKSET, 0, diff --git a/src/main_stp.c b/src/main_stp.c index ba204a7..35ec2ed 100644 --- a/src/main_stp.c +++ b/src/main_stp.c @@ -227,6 +227,32 @@ int main(int argc, char **argv) srand(time(NULL)); + set = link_set_create(bsc); + if (!set) { + LOGP(DINP, LOGL_ERROR, "Failed to allocate the link.\n"); + return -1; + } + + app = ss7_application_alloc(bsc); + if (!app) { + LOGP(DINP, LOGL_ERROR, "Failed to create the SS7 application.\n"); + return -1; + } + + m2ua_set = mtp_link_set_alloc(bsc); + m2ua_set->dpc = 92; + m2ua_set->opc = 9; + m2ua_set->sccp_opc = 9; + m2ua_set->isup_opc = 9; + m2ua_set->ni = 3; + m2ua_set->pcap_fd = bsc->pcap_fd; + m2ua_set->name = talloc_strdup(m2ua_set, "M2UA"); + m2ua_set->supported_ssn[1] = 1; + m2ua_set->supported_ssn[7] = 1; + m2ua_set->supported_ssn[8] = 1; + m2ua_set->supported_ssn[146] = 1; + m2ua_set->supported_ssn[254] = 1; + cell_vty_init(); if (vty_read_config_file(config, NULL) < 0) { fprintf(stderr, "Failed to read the VTY config.\n"); @@ -242,12 +268,7 @@ int main(int argc, char **argv) return -1; } - app = ss7_application_alloc(bsc); - if (!app) - return -1; - - set = link_init(bsc); - if (!set) + if (link_init(bsc, set) != 0) return -1; bsc->m2ua_trans = sctp_m2ua_transp_create("0.0.0.0", 2904); @@ -256,24 +277,7 @@ int main(int argc, char **argv) return -1; } - m2ua_set = mtp_link_set_alloc(bsc); - m2ua_set->dpc = 92; - m2ua_set->opc = 9; - m2ua_set->sccp_opc = 9; - m2ua_set->isup_opc = 9; - m2ua_set->ni = 3; - m2ua_set->pcap_fd = bsc->pcap_fd; - m2ua_set->name = talloc_strdup(m2ua_set, "M2UA"); - m2ua_set->supported_ssn[1] = 1; - m2ua_set->supported_ssn[7] = 1; - m2ua_set->supported_ssn[8] = 1; - m2ua_set->supported_ssn[146] = 1; - m2ua_set->supported_ssn[254] = 1; - /* setup things */ - set->pass_all_isup = bsc->isup_pass; - m2ua_set->pass_all_isup = bsc->isup_pass; - lnk = mtp_m2ua_link_create(bsc->m2ua_trans, m2ua_set); ss7_application_setup(app, APP_STP, diff --git a/src/ss7_application.c b/src/ss7_application.c index 1756bf2..906e7aa 100644 --- a/src/ss7_application.c +++ b/src/ss7_application.c @@ -325,12 +325,21 @@ static void start_msc(struct msc_connection *msc) msc_connection_start(msc); } +static void start_set(struct ss7_application *app, struct mtp_link_set *set) +{ + if (!set) + return; + + set->isup_opc = set->isup_opc >= 0 ? set->isup_opc : set->opc; + set->sccp_opc = set->sccp_opc >= 0 ? set->sccp_opc : set->opc; + set->pass_all_isup = app->isup_pass; + start_mtp(set); +} + int ss7_application_start(struct ss7_application *app) { - if (app->route_src.set) - start_mtp(app->route_src.set); - if (app->route_dst.set) - start_mtp(app->route_dst.set); + start_set(app, app->route_src.set); + start_set(app, app->route_dst.set); if (app->route_src.msc) start_msc(app->route_src.msc); @@ -341,3 +350,11 @@ int ss7_application_start(struct ss7_application *app) app->nr, app->name); return 0; } + +void ss7_application_pass_isup(struct ss7_application *app, int pass) +{ + if (app->route_src.set) + app->route_src.set->pass_all_isup = pass; + if (app->route_dst.set) + app->route_dst.set->pass_all_isup = pass; +} diff --git a/src/vty_interface.c b/src/vty_interface.c index 7bee8f7..3bf2b15 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -22,6 +22,7 @@ #include <bsc_data.h> #include <mtp_pcap.h> #include <msc_connection.h> +#include <ss7_application.h> #include <osmocore/talloc.h> #include <osmocore/gsm48.h> @@ -65,22 +66,24 @@ static struct cmd_node cell_node = { static int config_write_cell(struct vty *vty) { + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); struct msc_connection *msc = msc_connection_num(bsc, 0); + struct ss7_application *app = ss7_application_num(bsc, 0); vty_out(vty, "cellmgr%s", VTY_NEWLINE); - vty_out(vty, " mtp dpc %d%s", bsc->dpc, VTY_NEWLINE); - vty_out(vty, " mtp opc %d%s", bsc->opc, VTY_NEWLINE); - vty_out(vty, " mtp sccp-opc %d%s", bsc->sccp_opc, VTY_NEWLINE); - vty_out(vty, " mtp ni %d%s", bsc->ni_ni, VTY_NEWLINE); - vty_out(vty, " mtp spare %d%s", bsc->ni_spare, VTY_NEWLINE); - vty_out(vty, " mtp sltm once %d%s", bsc->once, VTY_NEWLINE); + vty_out(vty, " mtp dpc %d%s", set->dpc, VTY_NEWLINE); + vty_out(vty, " mtp opc %d%s", set->opc, VTY_NEWLINE); + vty_out(vty, " mtp sccp-opc %d%s", set->sccp_opc, VTY_NEWLINE); + vty_out(vty, " mtp ni %d%s", set->ni, VTY_NEWLINE); + vty_out(vty, " mtp spare %d%s", set->spare, VTY_NEWLINE); + vty_out(vty, " mtp sltm once %d%s", set->sltm_once, VTY_NEWLINE); if (bsc->udp_ip) vty_out(vty, " udp dest ip %s%s", bsc->udp_ip, VTY_NEWLINE); vty_out(vty, " udp dest port %d%s", bsc->udp_port, VTY_NEWLINE); vty_out(vty, " udp src port %d%s", bsc->src_port, VTY_NEWLINE); vty_out(vty, " udp reset %d%s", bsc->udp_reset_timeout, VTY_NEWLINE); vty_out(vty, " udp number-links %d%s", bsc->udp_nr_links, VTY_NEWLINE); - vty_out(vty, " isup pass-through %d%s", bsc->isup_pass, VTY_NEWLINE); + vty_out(vty, " isup pass-through %d%s", app->isup_pass, VTY_NEWLINE); if (msc) { vty_out(vty, " msc ip %s%s", msc->ip, VTY_NEWLINE); @@ -103,7 +106,8 @@ DEFUN(cfg_net_dpc, cfg_net_dpc_cmd, "mtp dpc DPC_NR", "Set the DPC to be used.") { - bsc->dpc = atoi(argv[0]); + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); + set->dpc = atoi(argv[0]); return CMD_SUCCESS; } @@ -111,7 +115,8 @@ DEFUN(cfg_net_opc, cfg_net_opc_cmd, "mtp opc OPC_NR", "Set the OPC to be used.") { - bsc->opc = atoi(argv[0]); + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); + set->opc = atoi(argv[0]); return CMD_SUCCESS; } @@ -119,7 +124,8 @@ DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd, "mtp sccp-opc OPC_NR", "Set the SCCP OPC to be used.") { - bsc->sccp_opc = atoi(argv[0]); + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); + set->sccp_opc = atoi(argv[0]); return CMD_SUCCESS; } @@ -127,7 +133,8 @@ DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd, "mtp ni NR", "Set the MTP NI to be used.\n" "NR") { - bsc->ni_ni = atoi(argv[0]); + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); + set->ni = atoi(argv[0]); return CMD_SUCCESS; } @@ -135,7 +142,8 @@ DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd, "mtp spare NR", "Set the MTP Spare to be used.\n" "NR") { - bsc->ni_spare = atoi(argv[0]); + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); + set->spare = atoi(argv[0]); return CMD_SUCCESS; } @@ -194,7 +202,8 @@ DEFUN(cfg_sltm_once, cfg_sltm_once_cmd, "mtp sltm once (0|1)", "Send SLTMs until the link is established.") { - bsc->once = !!atoi(argv[0]); + struct mtp_link_set *set = mtp_link_set_num(bsc, 0); + set->sltm_once = !!atoi(argv[0]); return CMD_SUCCESS; } @@ -314,12 +323,8 @@ DEFUN(cfg_isup_pass, cfg_isup_pass_cmd, "Pass through all ISUP messages directly\n" "Handle some messages locally\n" "Pass through everything\n") { - struct mtp_link_set *set; - - bsc->isup_pass = atoi(argv[0]); - - llist_for_each_entry(set, &bsc->linksets, entry) - set->pass_all_isup = bsc->isup_pass; + struct ss7_application *app = ss7_application_num(bsc, 0); + ss7_application_pass_isup(app, atoi(argv[0])); return CMD_SUCCESS; } |