aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc_nat/bsc_nat.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-07-13 14:43:37 +0200
committerHarald Welte <laforge@gnumonks.org>2011-07-13 14:53:16 +0200
commitf8e49dd187ec9ad55b133dcd15f4b1b4343da1a5 (patch)
tree4bf98b3ab4a7ad262304a2653b7cbeb7b29ff49d /openbsc/src/osmo-bsc_nat/bsc_nat.c
parent1b5e5c372781731d63dbefb01898e790236c354f (diff)
bsc-nat: ctrlif: split out handle_ctrlif_msg() from ipaccess_bsc_read_cb()
We want to avoid spaghetti code by creating smaller functions, which also helps with the line lengths / indentation levels.
Diffstat (limited to 'openbsc/src/osmo-bsc_nat/bsc_nat.c')
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat.c137
1 files changed, 71 insertions, 66 deletions
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index 2335e2412..2cbb7dc0f 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -1181,6 +1181,75 @@ static void bsc_del_pending(struct bsc_cmd_list *pending)
talloc_free(pending);
}
+
+static int handle_ctrlif_msg(struct bsc_connection *bsc, struct msgb *msg)
+{
+ struct ctrl_cmd *cmd;
+ struct bsc_cmd_list *pending;
+ char *var, *id;
+
+ cmd = ctrl_cmd_parse(bsc, msg);
+ msgb_free(msg);
+
+ if (!cmd) {
+ cmd = talloc_zero(bsc, struct ctrl_cmd);
+ if (!cmd) {
+ LOGP(DNAT, LOGL_ERROR, "OOM!\n");
+ return 0;
+ }
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->id = "err";
+ cmd->reply = "Failed to parse command.";
+ ctrl_cmd_send(&bsc->write_queue, cmd);
+ talloc_free(cmd);
+ return 0;
+ }
+
+ if (bsc->cfg) {
+ if (!llist_empty(&bsc->cfg->lac_list)) {
+ if (cmd->variable) {
+ var = talloc_asprintf(cmd, "bsc.%i.%s", ((struct bsc_lac_entry *)bsc->cfg->lac_list.next)->lac,
+ cmd->variable);
+ if (!var) {
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "OOM";
+ goto err;
+ }
+ talloc_free(cmd->variable);
+ cmd->variable = var;
+ }
+
+ /* Find the pending command */
+ pending = bsc_get_pending(bsc, cmd->id);
+ if (pending) {
+ id = talloc_strdup(cmd, pending->cmd->id);
+ if (!id) {
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "OOM";
+ goto err;
+ }
+ cmd->id = id;
+ ctrl_cmd_send(&pending->ccon->write_queue, cmd);
+ bsc_del_pending(pending);
+ } else {
+ /* We need to handle TRAPS here */
+ if ((cmd->type != CTRL_TYPE_ERROR) && (cmd->type != CTRL_TYPE_TRAP)) {
+ LOGP(DNAT, LOGL_NOTICE, "Got control message from BSC without pending entry\n");
+ cmd->type = CTRL_TYPE_ERROR;
+ cmd->reply = "No request outstanding";
+ goto err;
+ }
+ }
+ }
+ }
+ talloc_free(cmd);
+ return 0;
+err:
+ ctrl_cmd_send(&bsc->write_queue, cmd);
+ talloc_free(cmd);
+ return 0;
+}
+
static int ipaccess_bsc_read_cb(struct osmo_fd *bfd)
{
int error;
@@ -1228,72 +1297,8 @@ static int ipaccess_bsc_read_cb(struct osmo_fd *bfd)
/* l2h is where the actual command data is expected */
msg->l2h = hh_ext->data;
- if (hh_ext->proto == IPAC_PROTO_EXT_CTRL) {
- struct ctrl_cmd *cmd;
- struct bsc_cmd_list *pending;
- char *var, *id;
-
- cmd = ctrl_cmd_parse(bsc, msg);
- msgb_free(msg);
-
- if (!cmd) {
- cmd = talloc_zero(bsc, struct ctrl_cmd);
- if (!cmd) {
- LOGP(DNAT, LOGL_ERROR, "OOM!\n");
- return 0;
- }
- cmd->type = CTRL_TYPE_ERROR;
- cmd->id = "err";
- cmd->reply = "Failed to parse command.";
- ctrl_cmd_send(&bsc->write_queue, cmd);
- talloc_free(cmd);
- return 0;
- }
-
- if (bsc->cfg) {
- if (!llist_empty(&bsc->cfg->lac_list)) {
- if (cmd->variable) {
- var = talloc_asprintf(cmd, "bsc.%i.%s", ((struct bsc_lac_entry *)bsc->cfg->lac_list.next)->lac,
- cmd->variable);
- if (!var) {
- cmd->type = CTRL_TYPE_ERROR;
- cmd->reply = "OOM";
- goto err;
- }
- talloc_free(cmd->variable);
- cmd->variable = var;
- }
-
- /* Find the pending command */
- pending = bsc_get_pending(bsc, cmd->id);
- if (pending) {
- id = talloc_strdup(cmd, pending->cmd->id);
- if (!id) {
- cmd->type = CTRL_TYPE_ERROR;
- cmd->reply = "OOM";
- goto err;
- }
- cmd->id = id;
- ctrl_cmd_send(&pending->ccon->write_queue, cmd);
- bsc_del_pending(pending);
- } else {
- /* We need to handle TRAPS here */
- if ((cmd->type != CTRL_TYPE_ERROR) && (cmd->type != CTRL_TYPE_TRAP)) {
- LOGP(DNAT, LOGL_NOTICE, "Got control message from BSC without pending entry\n");
- cmd->type = CTRL_TYPE_ERROR;
- cmd->reply = "No request outstanding";
- goto err;
- }
- }
- }
- }
- talloc_free(cmd);
- return 0;
-err:
- ctrl_cmd_send(&bsc->write_queue, cmd);
- talloc_free(cmd);
- return 0;
- }
+ if (hh_ext->proto == IPAC_PROTO_EXT_CTRL)
+ return handle_ctrlif_msg(bsc, msg);
}
/* FIXME: Currently no PONG is sent to the BSC */