From 599c9a4b9aa3faa0b9c05dfcf6057ad9ccd4dfa6 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 15 Feb 2011 11:18:38 +0100 Subject: mtp: Allocate the MTPLinkSet as a child of the BSC In preparation of the VTY code change, make the mtp linkset a child of the bsc. --- include/bsc_data.h | 4 +++- include/mtp_data.h | 11 ++++++----- src/bsc.c | 2 +- src/links.c | 2 +- src/main.c | 4 +--- src/main_stp.c | 9 +++------ src/mtp_layer3.c | 17 ++++++----------- src/vty_interface.c | 14 +++++++------- 8 files changed, 28 insertions(+), 35 deletions(-) diff --git a/include/bsc_data.h b/include/bsc_data.h index 189ddcb..df62493 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -123,7 +123,6 @@ struct bsc_data { int setup; int pcap_fd; int udp_reset_timeout; - struct llist_head links; /* udp code */ struct mtp_udp_data udp_data; @@ -145,6 +144,9 @@ struct bsc_data { /* isup handling */ int isup_pass; + /* MTP Links */ + struct llist_head linksets; + int num_linksets; /* inject */ int allow_inject; diff --git a/include/mtp_data.h b/include/mtp_data.h index e8cb79e..3330de6 100644 --- a/include/mtp_data.h +++ b/include/mtp_data.h @@ -42,13 +42,15 @@ struct rate_ctr_group; */ struct mtp_link_set { struct llist_head entry; + int no; + char *name; + /* routing info.. */ int dpc, opc, sccp_opc, isup_opc; int ni; int spare; - const char *name; /* internal state */ /* the MTP1 link is up */ @@ -120,7 +122,6 @@ struct mtp_link { }; -struct mtp_link_set *mtp_link_set_alloc(void); void mtp_link_set_stop(struct mtp_link_set *link); void mtp_link_set_reset(struct mtp_link_set *link); int mtp_link_set_data(struct mtp_link *link, struct msgb *msg); @@ -134,9 +135,6 @@ void mtp_link_block(struct mtp_link *link); void mtp_link_unblock(struct mtp_link *link); -/* one time init function */ -void mtp_link_set_init(void); - /* to be implemented for MSU sending */ void mtp_link_submit(struct mtp_link *link, struct msgb *msg); void mtp_link_set_forward_sccp(struct mtp_link_set *link, struct msgb *msg, int sls); @@ -158,4 +156,7 @@ void mtp_link_failure(struct mtp_link *fail); /* internal routines */ struct msgb *mtp_msg_alloc(struct mtp_link_set *link); +/* link management */ +struct mtp_link_set *mtp_link_set_alloc(struct bsc_data *bsc); + #endif diff --git a/src/bsc.c b/src/bsc.c index c26c6ec..081774d 100644 --- a/src/bsc.c +++ b/src/bsc.c @@ -35,7 +35,7 @@ struct bsc_data *bsc_data_create() return NULL; } - INIT_LLIST_HEAD(&bsc->links); + INIT_LLIST_HEAD(&bsc->linksets); bsc->dpc = 1; bsc->opc = 0; bsc->sccp_opc = -1; diff --git a/src/links.c b/src/links.c index b694b8c..b74d843 100644 --- a/src/links.c +++ b/src/links.c @@ -106,7 +106,7 @@ struct mtp_link_set *link_init(struct bsc_data *bsc) struct mtp_udp_link *lnk; struct mtp_link_set *set; - set = mtp_link_set_alloc(); + set = mtp_link_set_alloc(bsc); set->name = talloc_strdup(set, "MTP"); set->dpc = bsc->dpc; set->opc = bsc->opc; diff --git a/src/main.c b/src/main.c index d23961f..93e9ee3 100644 --- a/src/main.c +++ b/src/main.c @@ -85,7 +85,7 @@ static void sigint() printf("Terminating.\n"); handled = 1; if (bsc && bsc->setup) { - llist_for_each_entry(set, &bsc->links, entry) + llist_for_each_entry(set, &bsc->linksets, entry) link_shutdown_all(set); } @@ -175,7 +175,6 @@ int main(int argc, char **argv) struct mtp_link_set *set; - mtp_link_set_init(); thread_init(); log_init(&log_info); @@ -222,7 +221,6 @@ int main(int argc, char **argv) if (!set) return -1; - llist_add(&set->entry, &bsc->links); set->fw = &bsc->msc_forward; bsc->msc_forward.bsc = set; diff --git a/src/main_stp.c b/src/main_stp.c index 43491b8..a26823d 100644 --- a/src/main_stp.c +++ b/src/main_stp.c @@ -112,7 +112,7 @@ static void sigint() printf("Terminating.\n"); handled = 1; if (bsc && bsc->setup) { - llist_for_each_entry(set, &bsc->links, entry) + llist_for_each_entry(set, &bsc->linksets, entry) link_shutdown_all(set); } exit(0); @@ -182,7 +182,7 @@ static struct mtp_link_set *find_link_set(struct bsc_data *bsc, { struct mtp_link_set *set; - llist_for_each_entry(set, &bsc->links, entry) + llist_for_each_entry(set, &bsc->linksets, entry) if (strncmp(buf, set->name, len) == 0) return set; @@ -308,7 +308,6 @@ int main(int argc, char **argv) struct mtp_link_set *m2ua_set; struct mtp_m2ua_link *lnk; - mtp_link_set_init(); thread_init(); log_init(&log_info); @@ -356,9 +355,8 @@ int main(int argc, char **argv) set = link_init(bsc); if (!set) return -1; - llist_add(&set->entry, &bsc->links); - m2ua_set = mtp_link_set_alloc(); + m2ua_set = mtp_link_set_alloc(bsc); m2ua_set->dpc = 92; m2ua_set->opc = 9; m2ua_set->sccp_opc = 9; @@ -367,7 +365,6 @@ int main(int argc, char **argv) m2ua_set->bsc = bsc; m2ua_set->pcap_fd = bsc->pcap_fd; m2ua_set->name = talloc_strdup(m2ua_set, "M2UA"); - llist_add(&m2ua_set->entry, &bsc->links); /* setup things */ set->pass_all_isup = bsc->isup_pass; diff --git a/src/mtp_layer3.c b/src/mtp_layer3.c index 71db16d..ecc1370 100644 --- a/src/mtp_layer3.c +++ b/src/mtp_layer3.c @@ -33,8 +33,6 @@ #include -static void *tall_mtp_ctx = NULL; - static int mtp_int_submit(struct mtp_link_set *link, int pc, int sls, int type, const uint8_t *data, unsigned int length); void mtp_link_submit(struct mtp_link *link, struct msgb *msg) @@ -185,23 +183,17 @@ static struct msgb *mtp_sccp_alloc_scmg(struct mtp_link_set *link, return out; } -void mtp_link_set_init(void) +struct mtp_link_set *mtp_link_set_alloc(struct bsc_data *bsc) { - tall_mtp_ctx = talloc_named_const(NULL, 1, "mtp-link"); -} - -struct mtp_link_set *mtp_link_set_alloc(void) -{ - static int linkset_no = 0; struct mtp_link_set *link; - link = talloc_zero(tall_mtp_ctx, struct mtp_link_set); + link = talloc_zero(bsc, struct mtp_link_set); if (!link) return NULL; link->ctrg = rate_ctr_group_alloc(link, mtp_link_set_rate_ctr_desc(), - linkset_no++); + bsc->num_linksets + 1); if (!link->ctrg) { LOGP(DINP, LOGL_ERROR, "Failed to allocate counter.\n"); return NULL; @@ -211,6 +203,9 @@ struct mtp_link_set *mtp_link_set_alloc(void) link->ni = MTP_NI_NATION_NET; INIT_LLIST_HEAD(&link->links); + link->no = bsc->num_linksets++; + llist_add(&link->entry, &bsc->linksets); + return link; } diff --git a/src/vty_interface.c b/src/vty_interface.c index 3d2b6a6..fbf0200 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -266,7 +266,7 @@ DEFUN(cfg_isup_pass, cfg_isup_pass_cmd, bsc->isup_pass = atoi(argv[0]); - llist_for_each_entry(set, &bsc->links, entry) + llist_for_each_entry(set, &bsc->linksets, entry) set->pass_all_isup = bsc->isup_pass; return CMD_SUCCESS; @@ -291,7 +291,7 @@ DEFUN(show_stats, show_stats_cmd, { struct mtp_link_set *set; - llist_for_each_entry(set, &bsc->links, entry) + llist_for_each_entry(set, &bsc->linksets, entry) dump_stats(vty, set); return CMD_SUCCESS; @@ -330,7 +330,7 @@ DEFUN(show_linksets, show_linksets_cmd, { struct mtp_link_set *set; - llist_for_each_entry(set, &bsc->links, entry) + llist_for_each_entry(set, &bsc->linksets, entry) dump_state(vty, set); return CMD_SUCCESS; } @@ -365,7 +365,7 @@ DEFUN(show_slc, show_slc_cmd, struct mtp_link_set *set = NULL; int i; - set = find_link_set(&bsc->links, argv[0]); + set = find_link_set(&bsc->linksets, argv[0]); if (!set) { vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); @@ -392,7 +392,7 @@ DEFUN(pcap_set, pcap_set_cmd, { struct mtp_link_set *set = NULL; - set = find_link_set(&bsc->links, argv[0]); + set = find_link_set(&bsc->linksets, argv[0]); if (!set) { vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); @@ -420,7 +420,7 @@ DEFUN(pcap_set_stop, pcap_set_stop_cmd, { struct mtp_link_set *set = NULL; - set = find_link_set(&bsc->links, argv[0]); + set = find_link_set(&bsc->linksets, argv[0]); if (!set) { vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); @@ -436,7 +436,7 @@ 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; \ - set = find_link_set(&bsc->links, type); \ + set = find_link_set(&bsc->linksets, type); \ if (!set) { \ vty_out(vty, "Unknown linkset %s.%s", type, VTY_NEWLINE); \ return CMD_WARNING; \ -- cgit v1.2.3