From c8405692b381e4079eeaf52f38610a6a24f64773 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 2 Jan 2011 20:24:08 +0100 Subject: [PATCH] mtp: Propagate link and linkset failures in two stages Handle a single link failure in links.c and if all the links have failed propagate it up. This is preparing the multiple links support. --- include/bsc_data.h | 11 +++++++---- include/mtp_data.h | 9 +++++++-- src/link_udp.c | 10 +++++----- src/links.c | 12 ++++++++++++ src/main.c | 34 ++++++++++++++-------------------- src/main_udt.c | 24 +++++++++--------------- 6 files changed, 54 insertions(+), 46 deletions(-) diff --git a/include/bsc_data.h b/include/bsc_data.h index 48ce137..76e6b44 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -1,7 +1,7 @@ /* Everything related to the BSC connection */ /* - * (C) 2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves + * (C) 2010-2011 by Holger Hans Peter Freyther + * (C) 2010-2011 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -126,8 +126,11 @@ struct bsc_data { /* bsc related functions */ void release_bsc_resources(struct bsc_data *bsc); -void bsc_link_down(struct link_data *data); -void bsc_link_up(struct link_data *data); +void mtp_link_down(struct link_data *data); +void mtp_link_up(struct link_data *data); + +void mtp_linkset_down(struct mtp_link_set *); +void mtp_linkset_up(struct mtp_link_set *); /* msc related functions */ int msc_init(struct bsc_data *bsc, int mgcp); diff --git a/include/mtp_data.h b/include/mtp_data.h index c2bf841..5afcb92 100644 --- a/include/mtp_data.h +++ b/include/mtp_data.h @@ -1,6 +1,6 @@ /* - * (C) 2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves + * (C) 2010-2011 by Holger Hans Peter Freyther + * (C) 2010-2011 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -24,6 +24,8 @@ #include #include +struct bsc_data; + /* MTP Level3 timers */ /* Timers for SS7 */ @@ -60,6 +62,9 @@ struct mtp_link_set { struct timer_list t2_timer; struct timer_list delay_timer; + + /* custom data */ + struct bsc_data *bsc; }; diff --git a/src/link_udp.c b/src/link_udp.c index e5e476c..3fbc726 100644 --- a/src/link_udp.c +++ b/src/link_udp.c @@ -91,12 +91,12 @@ static int udp_read_cb(struct bsc_fd *fd) if (hdr->data_type == UDP_DATA_RETR_COMPL || hdr->data_type == UDP_DATA_RETR_IMPOS) { LOGP(DINP, LOGL_ERROR, "Link retrieval done. Restarting the link.\n"); - bsc_link_down(link); - bsc_link_up(link); + mtp_link_down(link); + mtp_link_up(link); goto exit; } else if (hdr->data_type > UDP_DATA_MSU_PRIO_3) { LOGP(DINP, LOGL_ERROR, "Link failure. retrieved message.\n"); - bsc_link_down(link); + mtp_link_down(link); goto exit; } @@ -132,7 +132,7 @@ static void do_start(void *_data) link->forced_down = 0; snmp_mtp_activate(link->udp.session, link->udp.link_index); - bsc_link_up(link); + mtp_link_up(link); } static int udp_link_reset(struct link_data *link) @@ -140,7 +140,7 @@ static int udp_link_reset(struct link_data *link) LOGP(DINP, LOGL_NOTICE, "Will restart SLTM transmission in %d seconds.\n", link->udp.reset_timeout); snmp_mtp_deactivate(link->udp.session, link->udp.link_index); - bsc_link_down(link); + mtp_link_down(link); /* restart the link in 90 seconds... to force a timeout on the BSC */ link->link_activate.cb = do_start; diff --git a/src/links.c b/src/links.c index adc74d1..233f323 100644 --- a/src/links.c +++ b/src/links.c @@ -27,6 +27,17 @@ extern struct bsc_data bsc; +void mtp_link_down(struct link_data *link) +{ + mtp_linkset_down(link->the_link); + link->clear_queue(link); +} + +void mtp_link_up(struct link_data *link) +{ + mtp_linkset_up(link->the_link); +} + void mtp_link_set_sccp_down(struct mtp_link_set *link) { } @@ -63,6 +74,7 @@ int link_init(struct bsc_data *bsc) 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; diff --git a/src/main.c b/src/main.c index c764cc2..7a66cd8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ /* Bloated main routine, refactor */ /* - * (C) 2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves + * (C) 2010-2011 by Holger Hans Peter Freyther + * (C) 2010-2011 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -284,34 +284,28 @@ void release_bsc_resources(struct bsc_data *bsc) } } -void bsc_link_down(struct link_data *data) +void mtp_linkset_down(struct mtp_link_set *set) { - int was_up; - struct mtp_link_set *link = data->the_link; - - link->available = 0; - was_up = link->sccp_up; - mtp_link_set_stop(link); - clear_connections(data->bsc); - mgcp_reset(data->bsc); - - data->clear_queue(data); + set->available = 0; + mtp_link_set_stop(set); + clear_connections(set->bsc); + mgcp_reset(set->bsc); /* If we have an A link send a reset to the MSC */ - msc_send_reset(data->bsc); + msc_send_reset(set->bsc); } -void bsc_link_up(struct link_data *data) +void mtp_linkset_up(struct mtp_link_set *set) { - data->the_link->available = 1; + set->available = 1; /* we have not gone through link down */ - if (data->bsc->msc_link_down) { - clear_connections(data->bsc); - bsc_resources_released(data->bsc); + if (set->bsc->msc_link_down) { + clear_connections(set->bsc); + bsc_resources_released(set->bsc); } - mtp_link_set_reset(data->the_link); + mtp_link_set_reset(set); } /** diff --git a/src/main_udt.c b/src/main_udt.c index 1536301..40fe616 100644 --- a/src/main_udt.c +++ b/src/main_udt.c @@ -1,7 +1,7 @@ /* Relay UDT/all SCCP messages */ /* - * (C) 2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves + * (C) 2010-2011 by Holger Hans Peter Freyther + * (C) 2010-2011 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -70,25 +70,19 @@ void mtp_link_set_forward_sccp(struct mtp_link_set *link, struct msgb *_msg, int msc_send_direct(&bsc, _msg); } -void bsc_link_down(struct link_data *data) +void mtp_linkset_down(struct mtp_link_set *set) { - int was_up; - struct mtp_link_set *link = data->the_link; - - link->available = 0; - was_up = link->sccp_up; - mtp_link_set_stop(link); - - data->clear_queue(data); + set->available = 0; + mtp_link_set_stop(set); /* If we have an A link send a reset to the MSC */ - msc_send_reset(data->bsc); + msc_send_reset(set->bsc); } -void bsc_link_up(struct link_data *data) +void mtp_linkset_up(struct mtp_link_set *set) { - data->the_link->available = 1; - mtp_link_set_reset(data->the_link); + set->available = 1; + mtp_link_set_reset(set); } static void print_usage()