From cd8d2e5f30afb3f7643f7983b9fb0a67da8f1acb Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 2 Jul 2011 17:05:21 +0200 Subject: input: close socket if no signal link was created If the ->sign_link_up callback does not returns (or if it's NULL) a valid new signal link, we inmediately close the socket. If no signal link is set, there is nothing we can do with this socket, so keeping it open is useless otherwise. --- src/input/hsl.c | 25 +++++++++++++++++++------ src/input/ipaccess.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/input/hsl.c b/src/input/hsl.c index dd9f17d..aa79cdf 100644 --- a/src/input/hsl.c +++ b/src/input/hsl.c @@ -79,10 +79,12 @@ static void hsl_drop(struct e1inp_line *line, struct osmo_fd *bfd) line->ops->sign_link_down(line); } -static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line) +static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line, + struct osmo_fd *bfd) { char serno_buf[16]; uint8_t serno_len; + struct e1inp_sign_link *sign_link; struct hsl_unit unit_data; switch (msg->l2h[1]) { @@ -98,12 +100,23 @@ static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line) unit_data.serno = strtoul(serno_buf, NULL, 10); if (!line->ops->sign_link_up) { - LOGP(DINP, LOGL_ERROR, "Fix your application, " - "no action set if the signalling link " - "becomes ready\n"); + LOGP(DINP, LOGL_ERROR, + "Unable to set signal link, closing socket.\n"); + osmo_fd_unregister(bfd); + close(bfd->fd); + bfd->fd = -1; + return -EINVAL; + } + sign_link = line->ops->sign_link_up(&unit_data, + line, E1INP_SIGN_NONE); + if (sign_link == NULL) { + LOGP(DINP, LOGL_ERROR, + "Unable to set signal link, closing socket.\n"); + osmo_fd_unregister(bfd); + close(bfd->fd); + bfd->fd = -1; return -EINVAL; } - line->ops->sign_link_up(&unit_data, line, E1INP_SIGN_NONE); msgb_free(msg); return 1; /* == we have taken over the msg */ case 0x82: @@ -144,7 +157,7 @@ static int handle_ts1_read(struct osmo_fd *bfd) /* HSL proprietary RSL extension */ if (hh->proto == 0 && (msg->l2h[0] == 0x81 || msg->l2h[0] == 0x80)) { - ret = process_hsl_rsl(msg, line); + ret = process_hsl_rsl(msg, line, bfd); if (ret < 0) { hsl_drop(e1i_ts->line, bfd); return ret; diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 8004760..dc25430 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -281,9 +281,11 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, ipaccess_parse_unitid(unitid, &unit_data); if (!line->ops->sign_link_up) { - LOGP(DINP, LOGL_ERROR, "Fix your application, " - "no action set if the signalling link " - "becomes ready\n"); + LOGP(DINP, LOGL_ERROR, + "Unable to set signal link, closing socket.\n"); + osmo_fd_unregister(bfd); + close(bfd->fd); + bfd->fd = -1; return -EINVAL; } /* the BSC creates the new sign links at this stage. */ @@ -293,7 +295,12 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, E1INP_SIGN_OML); if (sign_link == NULL) { LOGP(DINP, LOGL_ERROR, - "No OML signal link set by BSC\n"); + "Unable to set signal link, " + "closing socket.\n"); + osmo_fd_unregister(bfd); + close(bfd->fd); + bfd->fd = -1; + return -EINVAL; } } else if (bfd->priv_nr == E1INP_SIGN_RSL) { struct e1inp_ts *e1i_ts; @@ -303,8 +310,9 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, line->ops->sign_link_up(&unit_data, line, E1INP_SIGN_RSL); if (sign_link == NULL) { - LOGP(DINP, LOGL_ERROR, "Don't know where " - "to attach this RSL link.\n"); + LOGP(DINP, LOGL_ERROR, + "Unable to set signal link, " + "closing socket.\n"); osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; @@ -719,9 +727,12 @@ static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg) LOGP(DINP, LOGL_NOTICE, "received ID get\n"); if (!link->line->ops->sign_link_up) { - LOGP(DINP, LOGL_ERROR, "Fix your application, " - "no action set if the signalling link " - "becomes ready\n"); + LOGP(DINP, LOGL_ERROR, + "Unable to set signal link, " + "closing socket.\n"); + osmo_fd_unregister(link->ofd); + close(link->ofd->fd); + link->ofd->fd = -1; return -EINVAL; } sign_link = link->line->ops->sign_link_up(msg, @@ -729,7 +740,11 @@ static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg) link->ofd->priv_nr); if (sign_link == NULL) { LOGP(DINP, LOGL_ERROR, - "No sign link created\n"); + "Unable to set signal link, " + "closing socket.\n"); + osmo_fd_unregister(link->ofd); + close(link->ofd->fd); + link->ofd->fd = -1; return -EINVAL; } rmsg = ipa_bts_id_resp(link->line->ops->data, -- cgit v1.2.3-55-g7522