Harald Welte | 936f672 | 2016-05-03 18:51:18 +0200 | [diff] [blame] | 1 | /* (C) 2016 by Harald Welte <laforge@gnumonks.org> |
| 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU Affero General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 20 | #include <signal.h> |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 21 | #include <errno.h> |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 22 | #include <stdbool.h> |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 23 | #include <getopt.h> |
| 24 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 25 | #include <osmocom/core/msgb.h> |
| 26 | #include <osmocom/core/logging.h> |
| 27 | #include <osmocom/core/application.h> |
| 28 | #include <osmocom/gsm/gsup.h> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 29 | #include <osmocom/vty/vty.h> |
| 30 | #include <osmocom/vty/command.h> |
| 31 | #include <osmocom/vty/telnet_interface.h> |
| 32 | #include <osmocom/vty/ports.h> |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 33 | #include <osmocom/ctrl/control_vty.h> |
Neels Hofmeyr | 5aeb438 | 2018-05-04 16:02:44 +0200 | [diff] [blame] | 34 | #include <osmocom/gsm/apn.h> |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 35 | |
| 36 | #include "db.h" |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 37 | #include "hlr.h" |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 38 | #include "ctrl.h" |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 39 | #include "logging.h" |
| 40 | #include "gsup_server.h" |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 41 | #include "gsup_router.h" |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 42 | #include "rand.h" |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 43 | #include "luop.h" |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 44 | #include "hlr_vty.h" |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 45 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 46 | static struct hlr *g_hlr; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 47 | |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 48 | /* Trigger 'Insert Subscriber Data' messages to all connected GSUP clients. |
| 49 | * |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 50 | * \param[in] subscr A subscriber we have new data to send for. |
| 51 | */ |
| 52 | void |
| 53 | osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr) |
| 54 | { |
Harald Welte | b85f604 | 2018-06-15 18:01:14 +0200 | [diff] [blame^] | 55 | /* FIXME: the below code can only be re-enabled after we make sure that an ISD |
| 56 | * is only sent tot the currently serving VLR and/or SGSN (if there are any). |
| 57 | * We cannot blindly flood the entire PLMN with this, as it would create subscriber |
| 58 | * state in every VLR/SGSN out there, even those that have never seen the subscriber. |
| 59 | * See https://osmocom.org/issues/3154 for details. */ |
| 60 | #if 0 |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 61 | struct osmo_gsup_conn *co; |
| 62 | |
| 63 | if (g_hlr->gs == NULL) |
| 64 | return; |
| 65 | |
| 66 | llist_for_each_entry(co, &g_hlr->gs->clients, list) { |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 67 | struct osmo_gsup_message gsup = { }; |
| 68 | uint8_t msisdn_enc[OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN]; |
| 69 | uint8_t apn[APN_MAXLEN]; |
| 70 | struct msgb *msg_out; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 71 | uint8_t *peer; |
| 72 | int peer_len; |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 73 | enum osmo_gsup_cn_domain cn_domain; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 74 | |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 75 | if (co->supports_ps) |
| 76 | cn_domain = OSMO_GSUP_CN_DOMAIN_PS; |
| 77 | else if (co->supports_cs) |
| 78 | cn_domain = OSMO_GSUP_CN_DOMAIN_CS; |
| 79 | else { |
| 80 | /* We have not yet received a location update from this subscriber .*/ |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | if (osmo_gsup_create_insert_subscriber_data_msg(&gsup, subscr->imsi, subscr->msisdn, msisdn_enc, |
| 85 | sizeof(msisdn_enc), apn, sizeof(apn), cn_domain) != 0) { |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 86 | LOGP(DMAIN, LOGL_ERROR, |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 87 | "IMSI='%s': Cannot notify GSUP client; could not create gsup message " |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 88 | "for %s:%u\n", subscr->imsi, |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 89 | co && co->conn && co->conn->server? co->conn->server->addr : "unset", |
| 90 | co && co->conn && co->conn->server? co->conn->server->port : 0); |
| 91 | continue; |
| 92 | } |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 93 | |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 94 | /* Send ISD to MSC/SGSN */ |
| 95 | msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ISD UPDATE"); |
| 96 | if (msg_out == NULL) { |
| 97 | LOGP(DMAIN, LOGL_ERROR, |
| 98 | "IMSI='%s': Cannot notify GSUP client; could not allocate msg buffer " |
| 99 | "for %s:%u\n", subscr->imsi, |
| 100 | co && co->conn && co->conn->server? co->conn->server->addr : "unset", |
| 101 | co && co->conn && co->conn->server? co->conn->server->port : 0); |
| 102 | continue; |
| 103 | } |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 104 | osmo_gsup_encode(msg_out, &gsup); |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 105 | |
| 106 | peer_len = osmo_gsup_conn_ccm_get(co, &peer, IPAC_IDTAG_SERNR); |
| 107 | if (peer_len < 0) { |
| 108 | LOGP(DMAIN, LOGL_ERROR, |
| 109 | "IMSI='%s': cannot get peer name for connection %s:%u\n", subscr->imsi, |
| 110 | co && co->conn && co->conn->server? co->conn->server->addr : "unset", |
| 111 | co && co->conn && co->conn->server? co->conn->server->port : 0); |
| 112 | continue; |
| 113 | } |
| 114 | |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 115 | if (osmo_gsup_addr_send(g_hlr->gs, peer, peer_len, msg_out) < 0) { |
| 116 | LOGP(DMAIN, LOGL_ERROR, |
| 117 | "IMSI='%s': Cannot notify GSUP client; send operation failed " |
| 118 | "for %s:%u\n", subscr->imsi, |
| 119 | co && co->conn && co->conn->server? co->conn->server->addr : "unset", |
| 120 | co && co->conn && co->conn->server? co->conn->server->port : 0); |
| 121 | continue; |
| 122 | } |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 123 | } |
Harald Welte | b85f604 | 2018-06-15 18:01:14 +0200 | [diff] [blame^] | 124 | #endif |
Stefan Sperling | f162252 | 2018-04-09 11:39:16 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 127 | /*********************************************************************** |
| 128 | * Send Auth Info handling |
| 129 | ***********************************************************************/ |
| 130 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 131 | /* process an incoming SAI request */ |
| 132 | static int rx_send_auth_info(struct osmo_gsup_conn *conn, |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 133 | const struct osmo_gsup_message *gsup, |
| 134 | struct db_context *dbc) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 135 | { |
| 136 | struct osmo_gsup_message gsup_out; |
| 137 | struct msgb *msg_out; |
| 138 | int rc; |
| 139 | |
| 140 | /* initialize return message structure */ |
| 141 | memset(&gsup_out, 0, sizeof(gsup_out)); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 142 | memcpy(&gsup_out.imsi, &gsup->imsi, sizeof(gsup_out.imsi)); |
| 143 | |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 144 | rc = db_get_auc(dbc, gsup->imsi, conn->auc_3g_ind, |
| 145 | gsup_out.auth_vectors, |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 146 | ARRAY_SIZE(gsup_out.auth_vectors), |
Harald Welte | 9be0d2f | 2016-06-10 17:34:02 +0200 | [diff] [blame] | 147 | gsup->rand, gsup->auts); |
Neels Hofmeyr | 671db90 | 2017-11-22 20:38:19 +0100 | [diff] [blame] | 148 | if (rc <= 0) { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 149 | gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR; |
Neels Hofmeyr | 671db90 | 2017-11-22 20:38:19 +0100 | [diff] [blame] | 150 | switch (rc) { |
| 151 | case 0: |
Neels Hofmeyr | bd1dca0 | 2017-11-23 15:25:30 +0100 | [diff] [blame] | 152 | /* 0 means "0 tuples generated", which shouldn't happen. |
| 153 | * Treat the same as "no auth data". */ |
| 154 | case -ENOKEY: |
Neels Hofmeyr | ab4d509 | 2017-11-23 15:31:12 +0100 | [diff] [blame] | 155 | LOGP(DAUC, LOGL_NOTICE, "%s: IMSI known, but has no auth data;" |
| 156 | " Returning slightly inaccurate cause 'IMSI Unknown' via GSUP\n", |
| 157 | gsup->imsi); |
| 158 | gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN; |
| 159 | break; |
Neels Hofmeyr | 33cbde9 | 2017-11-22 20:39:59 +0100 | [diff] [blame] | 160 | case -ENOENT: |
Neels Hofmeyr | ab4d509 | 2017-11-23 15:31:12 +0100 | [diff] [blame] | 161 | LOGP(DAUC, LOGL_NOTICE, "%s: IMSI not known\n", gsup->imsi); |
Neels Hofmeyr | 671db90 | 2017-11-22 20:38:19 +0100 | [diff] [blame] | 162 | gsup_out.cause = GMM_CAUSE_IMSI_UNKNOWN; |
| 163 | break; |
| 164 | default: |
Neels Hofmeyr | ab4d509 | 2017-11-23 15:31:12 +0100 | [diff] [blame] | 165 | LOGP(DAUC, LOGL_ERROR, "%s: failure to look up IMSI in db\n", gsup->imsi); |
Neels Hofmeyr | 671db90 | 2017-11-22 20:38:19 +0100 | [diff] [blame] | 166 | gsup_out.cause = GMM_CAUSE_NET_FAIL; |
| 167 | break; |
| 168 | } |
Harald Welte | 15db826 | 2016-05-05 16:50:39 +0200 | [diff] [blame] | 169 | } else { |
| 170 | gsup_out.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT; |
| 171 | gsup_out.num_auth_vectors = rc; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 174 | msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response"); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 175 | osmo_gsup_encode(msg_out, &gsup_out); |
| 176 | return osmo_gsup_conn_send(conn, msg_out); |
| 177 | } |
| 178 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 179 | /*********************************************************************** |
| 180 | * LU Operation State / Structure |
| 181 | ***********************************************************************/ |
| 182 | |
| 183 | static LLIST_HEAD(g_lu_ops); |
| 184 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 185 | /*! Receive Cancel Location Result from old VLR/SGSN */ |
| 186 | void lu_op_rx_cancel_old_ack(struct lu_operation *luop, |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 187 | const struct osmo_gsup_message *gsup) |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 188 | { |
| 189 | OSMO_ASSERT(luop->state == LU_S_CANCEL_SENT); |
| 190 | /* FIXME: Check for spoofing */ |
| 191 | |
| 192 | osmo_timer_del(&luop->timer); |
| 193 | |
| 194 | /* FIXME */ |
| 195 | |
| 196 | lu_op_tx_insert_subscr_data(luop); |
| 197 | } |
| 198 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 199 | /*! Receive Insert Subscriber Data Result from new VLR/SGSN */ |
| 200 | static void lu_op_rx_insert_subscr_data_ack(struct lu_operation *luop, |
| 201 | const struct osmo_gsup_message *gsup) |
| 202 | { |
| 203 | OSMO_ASSERT(luop->state == LU_S_ISD_SENT); |
| 204 | /* FIXME: Check for spoofing */ |
| 205 | |
| 206 | osmo_timer_del(&luop->timer); |
| 207 | |
| 208 | /* Subscriber_Present_HLR */ |
| 209 | /* CS only: Check_SS_required? -> MAP-FW-CHECK_SS_IND.req */ |
| 210 | |
| 211 | /* Send final ACK towards inquiring VLR/SGSN */ |
| 212 | lu_op_tx_ack(luop); |
| 213 | } |
| 214 | |
| 215 | /*! Receive GSUP message for given \ref lu_operation */ |
| 216 | void lu_op_rx_gsup(struct lu_operation *luop, |
| 217 | const struct osmo_gsup_message *gsup) |
| 218 | { |
| 219 | switch (gsup->message_type) { |
| 220 | case OSMO_GSUP_MSGT_INSERT_DATA_ERROR: |
| 221 | /* FIXME */ |
| 222 | break; |
| 223 | case OSMO_GSUP_MSGT_INSERT_DATA_RESULT: |
| 224 | lu_op_rx_insert_subscr_data_ack(luop, gsup); |
| 225 | break; |
| 226 | case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR: |
| 227 | /* FIXME */ |
| 228 | break; |
| 229 | case OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT: |
| 230 | lu_op_rx_cancel_old_ack(luop, gsup); |
| 231 | break; |
| 232 | default: |
| 233 | LOGP(DMAIN, LOGL_ERROR, "Unhandled GSUP msg_type 0x%02x\n", |
| 234 | gsup->message_type); |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 239 | /*! Receive Update Location Request, creates new \ref lu_operation */ |
| 240 | static int rx_upd_loc_req(struct osmo_gsup_conn *conn, |
| 241 | const struct osmo_gsup_message *gsup) |
| 242 | { |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 243 | struct lu_operation *luop = lu_op_alloc_conn(conn); |
| 244 | if (!luop) { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 245 | LOGP(DMAIN, LOGL_ERROR, "LU REQ from conn without addr?\n"); |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 246 | return -EINVAL; |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 249 | lu_op_statechg(luop, LU_S_LU_RECEIVED); |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 250 | |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 251 | if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_CS) |
| 252 | conn->supports_cs = true; |
| 253 | if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) { |
| 254 | conn->supports_ps = true; |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 255 | luop->is_ps = true; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 256 | } else { |
| 257 | /* The client didn't send a CN_DOMAIN IE; assume packet-switched in |
| 258 | * accordance with the GSUP spec in osmo-hlr's user manual (section |
| 259 | * 11.6.15 "CN Domain" says "if no CN Domain IE is present within |
| 260 | * a request, the PS Domain is assumed." */ |
| 261 | conn->supports_ps = true; |
Stefan Sperling | 1cb4892 | 2018-05-03 14:05:56 +0200 | [diff] [blame] | 262 | luop->is_ps = true; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 263 | } |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 264 | llist_add(&luop->list, &g_lu_ops); |
| 265 | |
| 266 | /* Roughly follwing "Process Update_Location_HLR" of TS 09.02 */ |
| 267 | |
| 268 | /* check if subscriber is known at all */ |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 269 | if (!lu_op_fill_subscr(luop, g_hlr->dbc, gsup->imsi)) { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 270 | /* Send Error back: Subscriber Unknown in HLR */ |
Harald Welte | bd0d5bf | 2017-11-06 03:55:02 +0900 | [diff] [blame] | 271 | osmo_strlcpy(luop->subscr.imsi, gsup->imsi, sizeof(luop->subscr.imsi)); |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 272 | lu_op_tx_error(luop, GMM_CAUSE_IMSI_UNKNOWN); |
| 273 | return 0; |
| 274 | } |
| 275 | |
Harald Welte | 9990927 | 2016-05-05 18:24:15 +0200 | [diff] [blame] | 276 | /* Check if subscriber is generally permitted on CS or PS |
| 277 | * service (as requested) */ |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 278 | if (!luop->is_ps && !luop->subscr.nam_cs) { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 279 | lu_op_tx_error(luop, GMM_CAUSE_PLMN_NOTALLOWED); |
| 280 | return 0; |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 281 | } else if (luop->is_ps && !luop->subscr.nam_ps) { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 282 | lu_op_tx_error(luop, GMM_CAUSE_GPRS_NOTALLOWED); |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | /* TODO: Set subscriber tracing = deactive in VLR/SGSN */ |
| 287 | |
| 288 | #if 0 |
| 289 | /* Cancel in old VLR/SGSN, if new VLR/SGSN differs from old */ |
| 290 | if (luop->is_ps == false && |
| 291 | strcmp(subscr->vlr_number, vlr_number)) { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 292 | lu_op_tx_cancel_old(luop); |
| 293 | } else if (luop->is_ps == true && |
| 294 | strcmp(subscr->sgsn_number, sgsn_number)) { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 295 | lu_op_tx_cancel_old(luop); |
| 296 | } else |
| 297 | #endif |
| 298 | { |
| 299 | /* TODO: Subscriber allowed to roam in PLMN? */ |
| 300 | /* TODO: Update RoutingInfo */ |
| 301 | /* TODO: Reset Flag MS Purged (cs/ps) */ |
| 302 | /* TODO: Control_Tracing_HLR / Control_Tracing_HLR_with_SGSN */ |
| 303 | lu_op_tx_insert_subscr_data(luop); |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 308 | static int rx_purge_ms_req(struct osmo_gsup_conn *conn, |
| 309 | const struct osmo_gsup_message *gsup) |
| 310 | { |
| 311 | struct osmo_gsup_message gsup_reply = {0}; |
| 312 | struct msgb *msg_out; |
| 313 | bool is_ps = false; |
| 314 | int rc; |
| 315 | |
| 316 | LOGP(DAUC, LOGL_INFO, "%s: Purge MS (%s)\n", gsup->imsi, |
| 317 | is_ps ? "PS" : "CS"); |
| 318 | |
| 319 | memcpy(gsup_reply.imsi, gsup->imsi, sizeof(gsup_reply.imsi)); |
| 320 | |
| 321 | if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) |
| 322 | is_ps = true; |
| 323 | |
| 324 | /* FIXME: check if the VLR that sends the purge is the same that |
| 325 | * we have on record. Only update if yes */ |
| 326 | |
| 327 | /* Perform the actual update of the DB */ |
Neels Hofmeyr | e50121e | 2017-10-09 17:48:51 +0200 | [diff] [blame] | 328 | rc = db_subscr_purge(g_hlr->dbc, gsup->imsi, true, is_ps); |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 329 | |
Harald Welte | 3f2a9a2 | 2018-03-01 23:35:35 +0100 | [diff] [blame] | 330 | if (rc == 0) |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 331 | gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT; |
Harald Welte | 3f2a9a2 | 2018-03-01 23:35:35 +0100 | [diff] [blame] | 332 | else if (rc == -ENOENT) { |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 333 | gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR; |
| 334 | gsup_reply.cause = GMM_CAUSE_IMSI_UNKNOWN; |
| 335 | } else { |
| 336 | gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_ERROR; |
| 337 | gsup_reply.cause = GMM_CAUSE_NET_FAIL; |
| 338 | } |
| 339 | |
| 340 | msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response"); |
| 341 | osmo_gsup_encode(msg_out, &gsup_reply); |
| 342 | return osmo_gsup_conn_send(conn, msg_out); |
| 343 | } |
| 344 | |
Harald Welte | a1d3b04 | 2018-06-11 20:28:35 +0200 | [diff] [blame] | 345 | static int gsup_send_err_reply(struct osmo_gsup_conn *conn, const char *imsi, |
| 346 | enum osmo_gsup_message_type type_in, uint8_t err_cause) |
| 347 | { |
| 348 | int type_err = osmo_gsup_get_err_msg_type(type_in); |
| 349 | struct osmo_gsup_message gsup_reply = {0}; |
| 350 | struct msgb *msg_out; |
| 351 | |
| 352 | if (type_err < 0) { |
| 353 | LOGP(DMAIN, LOGL_ERROR, "unable to determine error response for %s\n", |
| 354 | osmo_gsup_message_type_name(type_in)); |
| 355 | return type_err; |
| 356 | } |
| 357 | |
| 358 | OSMO_STRLCPY_ARRAY(gsup_reply.imsi, imsi); |
| 359 | gsup_reply.message_type = type_err; |
| 360 | gsup_reply.cause = err_cause; |
| 361 | msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ERR response"); |
| 362 | OSMO_ASSERT(msg_out); |
| 363 | osmo_gsup_encode(msg_out, &gsup_reply); |
| 364 | LOGP(DMAIN, LOGL_NOTICE, "Tx %s\n", osmo_gsup_message_type_name(type_err)); |
| 365 | return osmo_gsup_conn_send(conn, msg_out); |
| 366 | } |
| 367 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 368 | static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg) |
| 369 | { |
| 370 | static struct osmo_gsup_message gsup; |
| 371 | int rc; |
| 372 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 373 | rc = osmo_gsup_decode(msgb_l2(msg), msgb_l2len(msg), &gsup); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 374 | if (rc < 0) { |
| 375 | LOGP(DMAIN, LOGL_ERROR, "error in GSUP decode: %d\n", rc); |
| 376 | return rc; |
| 377 | } |
| 378 | |
Harald Welte | a1d3b04 | 2018-06-11 20:28:35 +0200 | [diff] [blame] | 379 | /* 3GPP TS 23.003 Section 2.2 clearly states that an IMSI with less than 5 |
| 380 | * digits is impossible. Even 5 digits is a highly theoretical case */ |
| 381 | if (strlen(gsup.imsi) < 5) |
| 382 | return gsup_send_err_reply(conn, gsup.imsi, gsup.message_type, GMM_CAUSE_INV_MAND_INFO); |
| 383 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 384 | switch (gsup.message_type) { |
| 385 | /* requests sent to us */ |
| 386 | case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 387 | rx_send_auth_info(conn, &gsup, g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 388 | break; |
| 389 | case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST: |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 390 | rx_upd_loc_req(conn, &gsup); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 391 | break; |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 392 | case OSMO_GSUP_MSGT_PURGE_MS_REQUEST: |
| 393 | rx_purge_ms_req(conn, &gsup); |
| 394 | break; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 395 | /* responses to requests sent by us */ |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 396 | case OSMO_GSUP_MSGT_DELETE_DATA_ERROR: |
| 397 | LOGP(DMAIN, LOGL_ERROR, "Error while deleting subscriber data " |
| 398 | "for IMSI %s\n", gsup.imsi); |
| 399 | break; |
| 400 | case OSMO_GSUP_MSGT_DELETE_DATA_RESULT: |
| 401 | LOGP(DMAIN, LOGL_ERROR, "Deleting subscriber data for IMSI %s\n", |
| 402 | gsup.imsi); |
| 403 | break; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 404 | case OSMO_GSUP_MSGT_INSERT_DATA_ERROR: |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 405 | case OSMO_GSUP_MSGT_INSERT_DATA_RESULT: |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 406 | case OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR: |
| 407 | case OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT: |
| 408 | { |
Max | ea8b0d4 | 2017-02-14 16:53:04 +0100 | [diff] [blame] | 409 | struct lu_operation *luop = lu_op_by_imsi(gsup.imsi, |
| 410 | &g_lu_ops); |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 411 | if (!luop) { |
Max | aa0fefd | 2017-02-16 12:25:22 +0100 | [diff] [blame] | 412 | LOGP(DMAIN, LOGL_ERROR, "GSUP message %s for " |
| 413 | "unknown IMSI %s\n", |
| 414 | osmo_gsup_message_type_name(gsup.message_type), |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 415 | gsup.imsi); |
| 416 | break; |
| 417 | } |
| 418 | lu_op_rx_gsup(luop, &gsup); |
| 419 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 420 | break; |
| 421 | default: |
Max | aa0fefd | 2017-02-16 12:25:22 +0100 | [diff] [blame] | 422 | LOGP(DMAIN, LOGL_DEBUG, "Unhandled GSUP message type %s\n", |
| 423 | osmo_gsup_message_type_name(gsup.message_type)); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 424 | break; |
| 425 | } |
Harald Welte | 5341b5d | 2016-04-28 12:48:39 +0200 | [diff] [blame] | 426 | msgb_free(msg); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 430 | static void print_usage() |
| 431 | { |
| 432 | printf("Usage: osmo-hlr\n"); |
| 433 | } |
| 434 | |
| 435 | static void print_help() |
| 436 | { |
| 437 | printf(" -h --help This text.\n"); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 438 | printf(" -c --config-file filename The config file to use.\n"); |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 439 | printf(" -l --database db-name The database to use.\n"); |
| 440 | printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM Enable debugging.\n"); |
| 441 | printf(" -D --daemonize Fork the process into a background daemon.\n"); |
| 442 | printf(" -s --disable-color Do not print ANSI colors in the log\n"); |
| 443 | printf(" -T --timestamp Prefix every log line with a timestamp.\n"); |
| 444 | printf(" -e --log-level number Set a global loglevel.\n"); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 445 | printf(" -V --version Print the version of OsmoHLR.\n"); |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static struct { |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 449 | const char *config_file; |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 450 | const char *db_file; |
| 451 | bool daemonize; |
| 452 | } cmdline_opts = { |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 453 | .config_file = "osmo-hlr.cfg", |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 454 | .db_file = "hlr.db", |
| 455 | .daemonize = false, |
| 456 | }; |
| 457 | |
| 458 | static void handle_options(int argc, char **argv) |
| 459 | { |
| 460 | while (1) { |
| 461 | int option_index = 0, c; |
| 462 | static struct option long_options[] = { |
| 463 | {"help", 0, 0, 'h'}, |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 464 | {"config-file", 1, 0, 'c'}, |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 465 | {"database", 1, 0, 'l'}, |
| 466 | {"debug", 1, 0, 'd'}, |
| 467 | {"daemonize", 0, 0, 'D'}, |
| 468 | {"disable-color", 0, 0, 's'}, |
| 469 | {"log-level", 1, 0, 'e'}, |
| 470 | {"timestamp", 0, 0, 'T'}, |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 471 | {"version", 0, 0, 'V' }, |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 472 | {0, 0, 0, 0} |
| 473 | }; |
| 474 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 475 | c = getopt_long(argc, argv, "hc:l:d:Dse:TV", |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 476 | long_options, &option_index); |
| 477 | if (c == -1) |
| 478 | break; |
| 479 | |
| 480 | switch (c) { |
| 481 | case 'h': |
| 482 | print_usage(); |
| 483 | print_help(); |
| 484 | exit(0); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 485 | case 'c': |
| 486 | cmdline_opts.config_file = optarg; |
| 487 | break; |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 488 | case 'l': |
| 489 | cmdline_opts.db_file = optarg; |
| 490 | break; |
| 491 | case 'd': |
| 492 | log_parse_category_mask(osmo_stderr_target, optarg); |
| 493 | break; |
| 494 | case 'D': |
| 495 | cmdline_opts.daemonize = 1; |
| 496 | break; |
| 497 | case 's': |
| 498 | log_set_use_color(osmo_stderr_target, 0); |
| 499 | break; |
| 500 | case 'e': |
| 501 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
| 502 | break; |
| 503 | case 'T': |
| 504 | log_set_print_timestamp(osmo_stderr_target, 1); |
| 505 | break; |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 506 | case 'V': |
| 507 | print_version(1); |
| 508 | exit(0); |
| 509 | break; |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 510 | default: |
| 511 | /* catch unknown options *as well as* missing arguments. */ |
| 512 | fprintf(stderr, "Error in command line options. Exiting.\n"); |
| 513 | exit(-1); |
| 514 | break; |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
Neels Hofmeyr | ca43e30 | 2017-01-30 13:18:23 +0100 | [diff] [blame] | 519 | static void *hlr_ctx = NULL; |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 520 | |
| 521 | static void signal_hdlr(int signal) |
| 522 | { |
| 523 | switch (signal) { |
| 524 | case SIGINT: |
| 525 | LOGP(DMAIN, LOGL_NOTICE, "Terminating due to SIGINT\n"); |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 526 | osmo_gsup_server_destroy(g_hlr->gs); |
| 527 | db_close(g_hlr->dbc); |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 528 | log_fini(); |
Neels Hofmeyr | ca43e30 | 2017-01-30 13:18:23 +0100 | [diff] [blame] | 529 | talloc_report_full(hlr_ctx, stderr); |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 530 | exit(0); |
| 531 | break; |
| 532 | case SIGUSR1: |
| 533 | LOGP(DMAIN, LOGL_DEBUG, "Talloc Report due to SIGUSR1\n"); |
Neels Hofmeyr | ca43e30 | 2017-01-30 13:18:23 +0100 | [diff] [blame] | 534 | talloc_report_full(hlr_ctx, stderr); |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 535 | break; |
| 536 | } |
| 537 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 538 | |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 539 | static const char vlr_copyright[] = |
| 540 | "Copyright (C) 2016, 2017 by Harald Welte, sysmocom s.f.m.c. GmbH\r\n" |
| 541 | "License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n" |
| 542 | "This is free software: you are free to change and redistribute it.\r\n" |
| 543 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
| 544 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 545 | static struct vty_app_info vty_info = { |
| 546 | .name = "OsmoHLR", |
| 547 | .version = PACKAGE_VERSION, |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 548 | .copyright = vlr_copyright, |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 549 | .is_config_node = hlr_vty_is_config_node, |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 550 | .go_parent_cb = hlr_vty_go_parent, |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 551 | }; |
| 552 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 553 | int main(int argc, char **argv) |
| 554 | { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 555 | int rc; |
| 556 | |
Neels Hofmeyr | ca43e30 | 2017-01-30 13:18:23 +0100 | [diff] [blame] | 557 | hlr_ctx = talloc_named_const(NULL, 1, "OsmoHLR"); |
| 558 | msgb_talloc_ctx_init(hlr_ctx, 0); |
Harald Welte | 7ee6e55 | 2018-02-14 00:52:05 +0100 | [diff] [blame] | 559 | vty_info.tall_ctx = hlr_ctx; |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 560 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 561 | g_hlr = talloc_zero(hlr_ctx, struct hlr); |
| 562 | |
Pau Espin Pedrol | 5153031 | 2018-04-17 15:07:06 +0200 | [diff] [blame] | 563 | rc = osmo_init_logging2(hlr_ctx, &hlr_log_info); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 564 | if (rc < 0) { |
| 565 | fprintf(stderr, "Error initializing logging\n"); |
| 566 | exit(1); |
| 567 | } |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 568 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 569 | vty_init(&vty_info); |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 570 | ctrl_vty_init(hlr_ctx); |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 571 | handle_options(argc, argv); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 572 | hlr_vty_init(g_hlr, &hlr_log_info); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 573 | |
| 574 | rc = vty_read_config_file(cmdline_opts.config_file, NULL); |
| 575 | if (rc < 0) { |
| 576 | LOGP(DMAIN, LOGL_FATAL, |
| 577 | "Failed to parse the config file: '%s'\n", |
| 578 | cmdline_opts.config_file); |
| 579 | return rc; |
| 580 | } |
| 581 | |
| 582 | /* start telnet after reading config for vty_get_bind_addr() */ |
| 583 | rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(), |
| 584 | OSMO_VTY_PORT_HLR); |
| 585 | if (rc < 0) |
| 586 | return rc; |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 587 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 588 | LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n"); |
| 589 | |
| 590 | rc = rand_init(); |
| 591 | if (rc < 0) { |
| 592 | LOGP(DMAIN, LOGL_FATAL, "Error initializing random source\n"); |
| 593 | exit(1); |
| 594 | } |
| 595 | |
Neels Hofmeyr | d3814b9 | 2017-11-21 12:28:07 +0100 | [diff] [blame] | 596 | g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true); |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 597 | if (!g_hlr->dbc) { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 598 | LOGP(DMAIN, LOGL_FATAL, "Error opening database\n"); |
| 599 | exit(1); |
| 600 | } |
| 601 | |
Neels Hofmeyr | 84201d3 | 2017-07-21 16:00:32 +0200 | [diff] [blame] | 602 | g_hlr->gs = osmo_gsup_server_create(hlr_ctx, g_hlr->gsup_bind_addr, OSMO_GSUP_PORT, |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 603 | read_cb, &g_lu_ops); |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 604 | if (!g_hlr->gs) { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 605 | LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n"); |
| 606 | exit(1); |
| 607 | } |
| 608 | |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 609 | g_hlr->ctrl_bind_addr = ctrl_vty_get_bind_addr(); |
Neels Hofmeyr | 234f9cb | 2017-10-24 17:23:04 +0200 | [diff] [blame] | 610 | g_hlr->ctrl = hlr_controlif_setup(g_hlr); |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 611 | |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 612 | osmo_init_ignore_signals(); |
| 613 | signal(SIGINT, &signal_hdlr); |
| 614 | signal(SIGUSR1, &signal_hdlr); |
| 615 | |
Neels Hofmeyr | 7f9491f | 2017-01-30 13:30:47 +0100 | [diff] [blame] | 616 | if (cmdline_opts.daemonize) { |
| 617 | rc = osmo_daemonize(); |
| 618 | if (rc < 0) { |
| 619 | perror("Error during daemonize"); |
| 620 | exit(1); |
| 621 | } |
| 622 | } |
Harald Welte | aabae9e | 2016-04-28 12:48:14 +0200 | [diff] [blame] | 623 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 624 | while (1) { |
| 625 | osmo_select_main(0); |
| 626 | } |
| 627 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 628 | db_close(g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 629 | |
| 630 | log_fini(); |
| 631 | |
| 632 | exit(0); |
| 633 | } |