diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/links.c | 43 | ||||
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/main_stp.c | 48 | ||||
-rw-r--r-- | src/main_udt.c | 19 | ||||
-rw-r--r-- | src/vty_interface.c | 89 |
5 files changed, 123 insertions, 96 deletions
diff --git a/src/links.c b/src/links.c index a95c2d5..f300b83 100644 --- a/src/links.c +++ b/src/links.c @@ -100,47 +100,48 @@ static void start_rest(void *_set) data->start(data); } -int link_init(struct bsc_data *bsc) +struct mtp_link_set *link_init(struct bsc_data *bsc) { int i; struct mtp_udp_link *lnk; - - bsc->link_set = mtp_link_set_alloc(); - bsc->link_set->name = talloc_strdup(bsc->link_set, "MTP"); - bsc->link_set->dpc = bsc->dpc; - bsc->link_set->opc = bsc->opc; - bsc->link_set->sccp_opc = bsc->sccp_opc > -1 ? bsc->sccp_opc : bsc->opc; - bsc->link_set->isup_opc = bsc->isup_opc > -1 ? bsc->isup_opc : bsc->opc; - bsc->link_set->sltm_once = bsc->once; - bsc->link_set->ni = bsc->ni_ni; - bsc->link_set->spare = bsc->ni_spare; - bsc->link_set->bsc = bsc; - bsc->link_set->pcap_fd = bsc->pcap_fd; + struct mtp_link_set *set; + + set = mtp_link_set_alloc(); + 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->bsc = bsc; + set->pcap_fd = bsc->pcap_fd; if (!bsc->src_port) { LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n"); - return -1; + return NULL; } LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); if (link_global_init(&bsc->udp_data, bsc->src_port) != 0) - return -1; + return NULL; for (i = 1; i <= bsc->udp_nr_links; ++i) { - lnk = talloc_zero(bsc->link_set, struct mtp_udp_link); + lnk = talloc_zero(set, struct mtp_udp_link); lnk->base.pcap_fd = -1; lnk->bsc = bsc; lnk->data = &bsc->udp_data; lnk->link_index = i; lnk->reset_timeout = bsc->udp_reset_timeout; - mtp_link_set_add_link(bsc->link_set, (struct mtp_link *) lnk); + mtp_link_set_add_link(set, (struct mtp_link *) lnk); /* now connect to the transport */ if (link_udp_init(lnk, bsc->udp_ip, bsc->udp_port) != 0) - return -1; + return NULL; /* * We will ask the MTP link to be taken down for two @@ -156,10 +157,10 @@ int link_init(struct bsc_data *bsc) } bsc->start_timer.cb = start_rest; - bsc->start_timer.data = bsc->link_set; - bsc_schedule_timer(&bsc->start_timer, lnk->reset_timeout, 0); + bsc->start_timer.data = set; + bsc_schedule_timer(&bsc->start_timer, bsc->udp_reset_timeout, 0); - return 0; + return set; } int link_shutdown_all(struct mtp_link_set *set) @@ -74,6 +74,8 @@ static void sigint() static pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER; static int handled = 0; + struct mtp_link_set *set; + /* failed to lock */ if (pthread_mutex_trylock(&exit_mutex) != 0) return; @@ -82,8 +84,11 @@ static void sigint() printf("Terminating.\n"); handled = 1; - if (bsc.setup) - link_shutdown_all(bsc.link_set); + if (bsc.setup) { + llist_for_each_entry(set, &bsc.links, entry) + link_shutdown_all(set); + } + exit(0); out: @@ -167,6 +172,8 @@ static void bsc_msc_forward_init(struct bsc_data *bsc, int main(int argc, char **argv) { int rc; + struct mtp_link_set *set; + INIT_LLIST_HEAD(&bsc.links); bsc.app = APP_CELLMGR; bsc.dpc = 1; @@ -221,10 +228,13 @@ int main(int argc, char **argv) if (rc < 0) return rc; - if (link_init(&bsc) != 0) + set = link_init(&bsc); + if (!set) return -1; - bsc.link_set->fw = &bsc.msc_forward; - bsc.msc_forward.bsc = bsc.link_set; + + llist_add(&set->entry, &bsc.links); + set->fw = &bsc.msc_forward; + bsc.msc_forward.bsc = set; while (1) { bsc_select_main(0); diff --git a/src/main_stp.c b/src/main_stp.c index 5ddc10e..3e83f56 100644 --- a/src/main_stp.c +++ b/src/main_stp.c @@ -69,20 +69,14 @@ extern void cell_vty_init(void); /* * methods called from the MTP Level3 part */ -void mtp_link_set_forward_sccp(struct mtp_link_set *link, struct msgb *_msg, int sls) +void mtp_link_set_forward_sccp(struct mtp_link_set *set, struct msgb *_msg, int sls) { - struct mtp_link_set *target; - - target = bsc.m2ua_set == link ? bsc.link_set : bsc.m2ua_set; - mtp_link_set_submit_sccp_data(target, sls, _msg->l2h, msgb_l2len(_msg)); + mtp_link_set_submit_sccp_data(set->forward, sls, _msg->l2h, msgb_l2len(_msg)); } void mtp_link_set_forward_isup(struct mtp_link_set *set, struct msgb *msg, int sls) { - struct mtp_link_set *target; - - target = bsc.m2ua_set == set ? bsc.link_set : bsc.m2ua_set; - mtp_link_set_submit_isup_data(target, sls, msg->l3h, msgb_l3len(msg)); + mtp_link_set_submit_isup_data(set->forward, sls, msg->l3h, msgb_l3len(msg)); } void mtp_linkset_down(struct mtp_link_set *set) @@ -107,6 +101,8 @@ static void sigint() static pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER; static int handled = 0; + struct mtp_link_set *set; + /* failed to lock */ if (pthread_mutex_trylock(&exit_mutex) != 0) return; @@ -115,8 +111,10 @@ static void sigint() printf("Terminating.\n"); handled = 1; - if (bsc.setup) - link_shutdown_all(bsc.link_set); + if (bsc.setup) { + llist_for_each_entry(set, &bsc.links, entry) + link_shutdown_all(set); + } exit(0); out: @@ -182,10 +180,12 @@ static void handle_options(int argc, char **argv) static struct mtp_link_set *find_link_set(struct bsc_data *bsc, int len, const char *buf) { - if (strncmp(buf, "mtp", len) == 0) - return bsc->link_set; - else if (strncmp(buf, "m2ua", len) == 0) - return bsc->m2ua_set; + struct mtp_link_set *set; + + llist_for_each_entry(set, &bsc->links, entry) + if (strncmp(buf, set->name, len) == 0) + return set; + return NULL; } @@ -304,7 +304,9 @@ int main(int argc, char **argv) { int rc; struct mtp_link *data; + struct mtp_link_set *set; struct mtp_m2ua_link *lnk; + INIT_LLIST_HEAD(&bsc.links); bsc.app = APP_STP; bsc.dpc = 1; @@ -361,8 +363,10 @@ int main(int argc, char **argv) return -1; } - if (link_init(&bsc) != 0) + set = link_init(&bsc); + if (!set) return -1; + llist_add(&set->entry, &bsc.links); bsc.m2ua_set = mtp_link_set_alloc(); bsc.m2ua_set->dpc = 92; @@ -373,13 +377,13 @@ int main(int argc, char **argv) bsc.m2ua_set->bsc = &bsc; bsc.m2ua_set->pcap_fd = bsc.pcap_fd; bsc.m2ua_set->name = talloc_strdup(bsc.m2ua_set, "M2UA"); + llist_add(&bsc.m2ua_set->entry, &bsc.links); - /* for both links we want to have all isup messages */ - if (bsc.isup_pass) { - LOGP(DINP, LOGL_NOTICE, "Going to pass through all ISUP messages.\n"); - bsc.m2ua_set->pass_all_isup = 1; - bsc.link_set->pass_all_isup = 1; - } + /* setup things */ + set->pass_all_isup = bsc.isup_pass; + set->forward = bsc.m2ua_set; + bsc.m2ua_set->pass_all_isup = bsc.isup_pass; + bsc.m2ua_set->forward = set; lnk = sctp_m2ua_transp_create("0.0.0.0", 2904); lnk->base.pcap_fd = -1; diff --git a/src/main_udt.c b/src/main_udt.c index e8eb06b..fd7791a 100644 --- a/src/main_udt.c +++ b/src/main_udt.c @@ -102,6 +102,8 @@ static void sigint() static pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER; static int handled = 0; + struct mtp_link_set *set; + /* failed to lock */ if (pthread_mutex_trylock(&exit_mutex) != 0) return; @@ -110,8 +112,10 @@ static void sigint() printf("Terminating.\n"); handled = 1; - if (bsc.setup) - link_shutdown_all(bsc.link_set); + if (bsc.setup) { + llist_for_each_entry(set, &bsc.links, entry) + link_shutdown_all(set); + } exit(0); out: @@ -195,6 +199,8 @@ static void bsc_msc_forward_init(struct bsc_data *bsc, int main(int argc, char **argv) { int rc; + struct mtp_link_set *set; + INIT_LLIST_HEAD(&bsc.links); bsc.app = APP_RELAY; bsc.dpc = 1; @@ -250,10 +256,13 @@ int main(int argc, char **argv) if (rc < 0) return rc; - if (link_init(&bsc) != 0) + set = link_init(&bsc); + if (!set) return -1; - bsc.link_set->fw = &bsc.msc_forward; - bsc.msc_forward.bsc = bsc.link_set; + + llist_add(&set->entry, &bsc.links); + set->fw = &bsc.msc_forward; + bsc.msc_forward.bsc = set; while (1) { bsc_select_main(0); diff --git a/src/vty_interface.c b/src/vty_interface.c index 6d0c7b6..1d43810 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -297,20 +297,21 @@ 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]); - if (bsc.m2ua_set) - bsc.m2ua_set->pass_all_isup = bsc.isup_pass; - if (bsc.link_set) - bsc.link_set->pass_all_isup = bsc.isup_pass; + + llist_for_each_entry(set, &bsc.links, entry) + set->pass_all_isup = bsc.isup_pass; return CMD_SUCCESS; } -static void dump_stats(struct vty *vty, const char *name, struct mtp_link_set *set) +static void dump_stats(struct vty *vty, struct mtp_link_set *set) { struct mtp_link *link; - vty_out(vty, "Linkset name: %s opc: %d%s", name, set->opc, VTY_NEWLINE); + vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE); vty_out_rate_ctr_group(vty, " ", set->ctrg); llist_for_each_entry(link, &set->links, entry) { @@ -323,24 +324,25 @@ DEFUN(show_stats, show_stats_cmd, "show statistics", SHOW_STR "Display Linkset statistics\n") { - if (bsc.link_set) - dump_stats(vty, "MTP ", bsc.link_set); - if (bsc.m2ua_set && bsc.app == APP_STP) - dump_stats(vty, "M2UA", bsc.m2ua_set); + struct mtp_link_set *set; + + llist_for_each_entry(set, &bsc.links, entry) + dump_stats(vty, set); + return CMD_SUCCESS; } -static void dump_state(struct vty *vty, const char *name, struct mtp_link_set *set) +static void dump_state(struct vty *vty, struct mtp_link_set *set) { struct mtp_link *link; if (!set) { - vty_out(vty, "LinkSet for %s is not configured.%s", name, VTY_NEWLINE); + vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE); return; } vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s", - name, + set->name, set->available == 0 ? "not available" : "available", set->sccp_up == 0? "not established" : "established", VTY_NEWLINE); @@ -361,9 +363,10 @@ DEFUN(show_linksets, show_linksets_cmd, "show link-sets", SHOW_STR "Display current state of linksets\n") { - dump_state(vty, "MTP ", bsc.link_set); - if (bsc.app == APP_STP) - dump_state(vty, "M2UA", bsc.m2ua_set); + struct mtp_link_set *set; + + llist_for_each_entry(set, &bsc.links, entry) + dump_state(vty, set); return CMD_SUCCESS; } @@ -378,17 +381,26 @@ DEFUN(show_msc, show_msc_cmd, return CMD_SUCCESS; } +static struct mtp_link_set *find_link_set(struct llist_head *head, + const char *name) +{ + struct mtp_link_set *set; + + llist_for_each_entry(set, head, entry) + if (strcmp(name, set->name) == 0) + return set; + + return NULL; +} + DEFUN(show_slc, show_slc_cmd, - "show link-set (mtp|m2ua) slc", - SHOW_STR "LinkSet\n" "MTP Linkset\n" "M2UA LinkSet\n" "SLS to SLC\n") + "show link-set NAME slc", + SHOW_STR "LinkSet\n" "Linkset name\n" "SLS to SLC\n") { struct mtp_link_set *set = NULL; int i; - if (bsc.link_set && strcmp(argv[0], "mtp") == 0) - set = bsc.link_set; - else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0) - set = bsc.m2ua_set; + set = find_link_set(&bsc.links, argv[0]); if (!set) { vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); @@ -409,16 +421,13 @@ DEFUN(show_slc, show_slc_cmd, } DEFUN(pcap_set, pcap_set_cmd, - "trace-pcap set (m2ua|mtp) FILE", + "trace-pcap set NAME FILE", "Trace to a PCAP file\n" "Trace a linkset\n" - "Trace m2ua linkset\n" "Trace mtp linkset\n" "Filename to trace\n") + "Trace Linkset\n" "Filename to trace\n") { struct mtp_link_set *set = NULL; - if (bsc.link_set && strcmp(argv[0], "mtp") == 0) - set = bsc.link_set; - else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0) - set = bsc.m2ua_set; + set = find_link_set(&bsc.links, argv[0]); if (!set) { vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); @@ -440,16 +449,13 @@ DEFUN(pcap_set, pcap_set_cmd, } DEFUN(pcap_set_stop, pcap_set_stop_cmd, - "trace-pcap set (m2ua|mtp) stop", + "trace-pcap set NAME stop", "Trace to a PCAP file\n" "Trace a linkset\n" - "Trace m2ua linkset\n" "Trace mtp linkset\n" "Stop the tracing\n") + "Trace Linkset\n" "Stop the tracing\n") { struct mtp_link_set *set = NULL; - if (bsc.link_set && strcmp(argv[0], "mtp") == 0) - set = bsc.link_set; - else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0) - set = bsc.m2ua_set; + set = find_link_set(&bsc.links, argv[0]); if (!set) { vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); @@ -465,11 +471,8 @@ DEFUN(pcap_set_stop, pcap_set_stop_cmd, #define FIND_LINK(vty, type, nr) ({ \ struct mtp_link_set *set = NULL; \ struct mtp_link *link = NULL, *tmp; \ - if (strcmp(type, "mtp") == 0) \ - set = bsc.link_set; \ - else if (strcmp(type, "m2ua") == 0) \ - set = bsc.m2ua_set; \ - else { \ + set = find_link_set(&bsc.links, type); \ + if (!set) { \ vty_out(vty, "Unknown linkset %s.%s", type, VTY_NEWLINE); \ return CMD_WARNING; \ } \ @@ -486,11 +489,11 @@ DEFUN(pcap_set_stop, pcap_set_stop_cmd, link; }) #define LINK_STR "Operations on the link\n" \ - "MTP Linkset\n" "M2UA Linkset\n" \ + "Linkset name\n" \ "Link number\n" DEFUN(lnk_block, lnk_block_cmd, - "link (mtp|m2ua) <0-15> block", + "link NAME <0-15> block", LINK_STR "Block it\n") { struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1])); @@ -499,7 +502,7 @@ DEFUN(lnk_block, lnk_block_cmd, } DEFUN(lnk_unblock, lnk_unblock_cmd, - "link (mtp|m2ua) <0-15> unblock", + "link NAME <0-15> unblock", LINK_STR "Unblock it\n") { struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1])); @@ -508,7 +511,7 @@ DEFUN(lnk_unblock, lnk_unblock_cmd, } DEFUN(lnk_reset, lnk_reset_cmd, - "link (mtp|m2ua) <0-15> reset", + "link NAME <0-15> reset", LINK_STR "Reset it\n") { struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1])); |