From 644aafbc94a2c2bfb49b2352fe31452a1cddab27 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 3 Jan 2011 23:51:07 +0100 Subject: mtp: Make the link_data be a child of the link_set Change the order of the link and linkset. The link will be below the linkset. This change should make it more easy to introduce multiple linksets. --- include/bsc_data.h | 4 +++- include/mtp_data.h | 3 +++ src/links.c | 49 ++++++++++++++++++++++++++++--------------------- src/main.c | 30 +++++++++++++++--------------- src/main_udt.c | 16 ++++++++-------- src/msc_conn.c | 2 +- src/vty_interface.c | 4 ++-- 7 files changed, 60 insertions(+), 48 deletions(-) diff --git a/include/bsc_data.h b/include/bsc_data.h index 76e6b44..d734177 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -96,7 +96,9 @@ struct bsc_data { int setup; - struct link_data link; + int pcap_fd; + int udp_reset_timeout; + struct mtp_link_set *link_set; const char *token; diff --git a/include/mtp_data.h b/include/mtp_data.h index 5afcb92..f2aeaec 100644 --- a/include/mtp_data.h +++ b/include/mtp_data.h @@ -25,6 +25,7 @@ #include struct bsc_data; +struct link_data; /* MTP Level3 timers */ @@ -63,6 +64,8 @@ struct mtp_link_set { struct timer_list delay_timer; + struct link_data *link; + /* custom data */ struct bsc_data *bsc; }; diff --git a/src/links.c b/src/links.c index 233f323..1102ee6 100644 --- a/src/links.c +++ b/src/links.c @@ -25,6 +25,8 @@ #include #include +#include + extern struct bsc_data bsc; void mtp_link_down(struct link_data *link) @@ -42,15 +44,15 @@ void mtp_link_set_sccp_down(struct mtp_link_set *link) { } -void mtp_link_set_submit(struct mtp_link_set *link, struct msgb *msg) +void mtp_link_set_submit(struct mtp_link_set *set, struct msgb *msg) { - bsc.link.write(&bsc.link, msg); + set->link->write(set->link, msg); } -void mtp_link_set_restart(struct mtp_link_set *link) +void mtp_link_set_restart(struct mtp_link_set *set) { LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n"); - bsc.link.reset(&bsc.link); + set->link->reset(set->link); } static void start_rest(void *start) @@ -62,21 +64,26 @@ static void start_rest(void *start) exit(3); } - bsc.link.start(&bsc.link); + bsc.link_set->link->start(bsc.link_set->link); } int link_init(struct bsc_data *bsc) { - bsc->link.the_link = mtp_link_set_alloc(); - bsc->link.the_link->dpc = bsc->dpc; - bsc->link.the_link->opc = bsc->opc; - bsc->link.the_link->sccp_opc = bsc->sccp_opc > -1 ? bsc->sccp_opc : bsc->opc; - bsc->link.the_link->sltm_once = bsc->once; - bsc->link.the_link->ni = bsc->ni_ni; - bsc->link.the_link->spare = bsc->ni_spare; - bsc->link.the_link->bsc = bsc; - bsc->link.bsc = bsc; - bsc->link.udp.link_index = 1; + bsc->link_set = mtp_link_set_alloc(); + 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->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->link = talloc_zero(bsc->link_set, struct link_data); + bsc->link_set->link->bsc = bsc; + bsc->link_set->link->udp.link_index = 1; + bsc->link_set->link->pcap_fd = bsc->pcap_fd; + bsc->link_set->link->udp.reset_timeout = bsc->udp_reset_timeout; + bsc->link_set->link->the_link = bsc->link_set; if (!bsc->src_port) { LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n"); @@ -86,12 +93,12 @@ int link_init(struct bsc_data *bsc) LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); /* setup SNMP first, it is blocking */ - bsc->link.udp.session = snmp_mtp_session_create(bsc->udp_ip); - if (!bsc->link.udp.session) + bsc->link_set->link->udp.session = snmp_mtp_session_create(bsc->udp_ip); + if (!bsc->link_set->link->udp.session) return -1; /* now connect to the transport */ - if (link_udp_init(&bsc->link, bsc->src_port, bsc->udp_ip, bsc->udp_port) != 0) + if (link_udp_init(bsc->link_set->link, bsc->src_port, bsc->udp_ip, bsc->udp_port) != 0) return -1; /* @@ -100,11 +107,11 @@ int link_init(struct bsc_data *bsc) * SLTM and it begins a reset. Then we will take it up * again and do the usual business. */ - snmp_mtp_deactivate(bsc->link.udp.session, - bsc->link.udp.link_index); + snmp_mtp_deactivate(bsc->link_set->link->udp.session, + bsc->link_set->link->udp.link_index); bsc->start_timer.cb = start_rest; bsc->start_timer.data = &bsc; - bsc_schedule_timer(&bsc->start_timer, bsc->link.udp.reset_timeout, 0); + bsc_schedule_timer(&bsc->start_timer, bsc->link_set->link->udp.reset_timeout, 0); LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n"); return 0; diff --git a/src/main.c b/src/main.c index 7a66cd8..a8edb97 100644 --- a/src/main.c +++ b/src/main.c @@ -194,7 +194,7 @@ static void clear_connections(struct bsc_data *bsc) free_con(con); } - bsc->link.clear_queue(&bsc->link); + bsc->link_set->link->clear_queue(bsc->link_set->link); } void bsc_resources_released(struct bsc_data *bsc) @@ -210,9 +210,9 @@ static void bsc_reset_timeout(void *_data) /* no reset */ if (bsc->reset_count > 0) { LOGP(DINP, LOGL_ERROR, "The BSC did not answer the GSM08.08 reset. Restart MTP\n"); - mtp_link_set_stop(bsc->link.the_link); + mtp_link_set_stop(bsc->link_set); clear_connections(bsc); - bsc->link.reset(&bsc->link); + bsc->link_set->link->reset(bsc->link_set->link); bsc_resources_released(bsc); return; } @@ -224,7 +224,7 @@ static void bsc_reset_timeout(void *_data) } ++bsc->reset_count; - mtp_link_set_submit_sccp_data(bsc->link.the_link, -1, msg->l2h, msgb_l2len(msg)); + mtp_link_set_submit_sccp_data(bsc->link_set, -1, msg->l2h, msgb_l2len(msg)); msgb_free(msg); bsc_schedule_timer(&bsc->reset_timeout, 20, 0); } @@ -269,7 +269,7 @@ void release_bsc_resources(struct bsc_data *bsc) continue; /* wait for the clear commands */ - mtp_link_set_submit_sccp_data(bsc->link.the_link, con->sls, msg->l2h, msgb_l2len(msg)); + mtp_link_set_submit_sccp_data(bsc->link_set, con->sls, msg->l2h, msgb_l2len(msg)); msgb_free(msg); } @@ -319,7 +319,7 @@ static void send_rlc_to_bsc(unsigned int sls, struct sccp_source_reference *src, if (!msg) return; - mtp_link_set_submit_sccp_data(bsc.link.the_link, sls, msg->l2h, msgb_l2len(msg)); + mtp_link_set_submit_sccp_data(bsc.link_set, sls, msg->l2h, msgb_l2len(msg)); msgb_free(msg); } @@ -500,7 +500,7 @@ static void send_local_rlsd_for_con(void *data) ++con->rls_tries; LOGP(DINP, LOGL_DEBUG, "Sending RLSD for 0x%x the %d time.\n", sccp_src_ref_to_int(&con->src_ref), con->rls_tries); - mtp_link_set_submit_sccp_data(bsc.link.the_link, con->sls, rlsd->l2h, msgb_l2len(rlsd)); + mtp_link_set_submit_sccp_data(bsc.link_set, con->sls, rlsd->l2h, msgb_l2len(rlsd)); msgb_free(rlsd); } @@ -547,7 +547,7 @@ static void sigint() printf("Terminating.\n"); handled = 1; if (bsc.setup) - bsc.link.shutdown(&bsc.link); + bsc.link_set->link->shutdown(bsc.link_set->link); exit(0); out: @@ -593,14 +593,14 @@ static void handle_options(int argc, char **argv) print_help(); exit(0); case 'p': - if (bsc.link.pcap_fd >= 0) - close(bsc.link.pcap_fd); - bsc.link.pcap_fd = open(optarg, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); - if (bsc.link.pcap_fd < 0) { + if (bsc.pcap_fd >= 0) + close(bsc.pcap_fd); + bsc.pcap_fd = open(optarg, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); + if (bsc.pcap_fd < 0) { fprintf(stderr, "Failed to open PCAP file.\n"); exit(0); } - mtp_pcap_write_header(bsc.link.pcap_fd); + mtp_pcap_write_header(bsc.pcap_fd); break; case 'c': config = optarg; @@ -650,8 +650,8 @@ int main(int argc, char **argv) bsc.setup = 0; bsc.msc_address = "127.0.0.1"; - bsc.link.pcap_fd = -1; - bsc.link.udp.reset_timeout = 180; + bsc.pcap_fd = -1; + bsc.udp_reset_timeout = 180; bsc.ping_time = 20; bsc.pong_time = 5; bsc.msc_time = 20; diff --git a/src/main_udt.c b/src/main_udt.c index 40fe616..b8d754e 100644 --- a/src/main_udt.c +++ b/src/main_udt.c @@ -104,7 +104,7 @@ static void sigint() printf("Terminating.\n"); handled = 1; if (bsc.setup) - bsc.link.shutdown(&bsc.link); + bsc.link_set->link->shutdown(bsc.link_set->link); exit(0); out: @@ -150,14 +150,14 @@ static void handle_options(int argc, char **argv) print_help(); exit(0); case 'p': - if (bsc.link.pcap_fd >= 0) - close(bsc.link.pcap_fd); - bsc.link.pcap_fd = open(optarg, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); - if (bsc.link.pcap_fd < 0) { + if (bsc.pcap_fd >= 0) + close(bsc.pcap_fd); + bsc.pcap_fd = open(optarg, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); + if (bsc.pcap_fd < 0) { fprintf(stderr, "Failed to open PCAP file.\n"); exit(0); } - mtp_pcap_write_header(bsc.link.pcap_fd); + mtp_pcap_write_header(bsc.pcap_fd); break; case 'c': config = optarg; @@ -207,8 +207,8 @@ int main(int argc, char **argv) bsc.setup = 0; bsc.msc_address = "127.0.0.1"; - bsc.link.pcap_fd = -1; - bsc.link.udp.reset_timeout = 180; + bsc.pcap_fd = -1; + bsc.udp_reset_timeout = 180; bsc.ping_time = 20; bsc.pong_time = 5; bsc.msc_time = 20; diff --git a/src/msc_conn.c b/src/msc_conn.c index 89b39c7..bc05744 100644 --- a/src/msc_conn.c +++ b/src/msc_conn.c @@ -146,7 +146,7 @@ static int ipaccess_a_fd_cb(struct bsc_fd *bfd) hh = (struct ipaccess_head *) msg->data; ipaccess_rcvmsg_base(msg, bfd); - link = bsc->link.the_link; + link = bsc->link_set; /* initialize the networking. This includes sending a GSM08.08 message */ if (hh->proto == IPAC_PROTO_IPACCESS) { diff --git a/src/vty_interface.c b/src/vty_interface.c index 6ddf549..0cf5929 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -72,7 +72,7 @@ static int config_write_cell(struct vty *vty) 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.link.udp.reset_timeout, VTY_NEWLINE); + vty_out(vty, " udp reset %d%s", bsc.udp_reset_timeout, VTY_NEWLINE); vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE); vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE); vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE); @@ -166,7 +166,7 @@ DEFUN(cfg_udp_reset, cfg_udp_reset_cmd, "udp reset TIMEOUT", "Set the timeout to take the link down") { - bsc.link.udp.reset_timeout = atoi(argv[0]); + bsc.udp_reset_timeout = atoi(argv[0]); return CMD_SUCCESS; } -- cgit v1.2.3