Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 1 | /* main application for hnb-gw part of osmo-iuh */ |
| 2 | |
| 3 | /* (C) 2015 by Harald Welte <laforge@gnumonks.org> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <getopt.h> |
| 26 | #include <errno.h> |
| 27 | #include <signal.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 28 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | #include <sys/socket.h> |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 31 | #include <netinet/in.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 32 | #include <netinet/sctp.h> |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 33 | #include <arpa/inet.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 34 | |
| 35 | #include <osmocom/core/application.h> |
| 36 | #include <osmocom/core/talloc.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 37 | #include <osmocom/core/select.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 38 | #include <osmocom/core/logging.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 39 | #include <osmocom/core/socket.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 40 | #include <osmocom/core/msgb.h> |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 41 | #include <osmocom/core/write_queue.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 42 | |
| 43 | #include <osmocom/vty/telnet_interface.h> |
| 44 | #include <osmocom/vty/logging.h> |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 45 | #include <osmocom/vty/command.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 46 | |
| 47 | #include "hnbgw.h" |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 48 | #include "hnbgw_hnbap.h" |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 49 | #include "hnbgw_rua.h" |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 50 | |
| 51 | static void *tall_hnb_ctx; |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 52 | static void *tall_ue_ctx; |
Harald Welte | 08de638 | 2015-08-31 09:54:45 +0200 | [diff] [blame] | 53 | void *talloc_asn1_ctx; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 54 | |
| 55 | struct hnb_gw g_hnb_gw = { |
| 56 | .config = { |
| 57 | .iuh_listen_port = IUH_DEFAULT_SCTP_PORT, |
| 58 | }, |
| 59 | }; |
| 60 | |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 61 | struct ue_context *ue_context_by_id(uint32_t id) |
| 62 | { |
| 63 | struct ue_context *ue; |
| 64 | |
| 65 | llist_for_each_entry(ue, &g_hnb_gw.ue_list, list) { |
| 66 | if (ue->context_id == id) |
| 67 | return ue; |
| 68 | } |
| 69 | return NULL; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | struct ue_context *ue_context_by_imsi(const char *imsi) |
| 74 | { |
| 75 | struct ue_context *ue; |
| 76 | |
| 77 | llist_for_each_entry(ue, &g_hnb_gw.ue_list, list) { |
| 78 | if (!strcmp(ue->imsi, imsi)) |
| 79 | return ue; |
| 80 | } |
| 81 | return NULL; |
| 82 | } |
| 83 | |
| 84 | static uint32_t get_next_ue_ctx_id(void) |
| 85 | { |
| 86 | uint32_t id; |
| 87 | |
| 88 | do { |
| 89 | id = g_hnb_gw.next_ue_ctx_id++; |
| 90 | } while (ue_context_by_id(id)); |
| 91 | |
| 92 | return id; |
| 93 | } |
| 94 | |
| 95 | struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi) |
| 96 | { |
| 97 | struct ue_context *ue; |
| 98 | |
| 99 | ue = talloc_zero(tall_hnb_ctx, struct ue_context); |
| 100 | if (!ue) |
| 101 | return NULL; |
| 102 | |
| 103 | ue->hnb = hnb; |
| 104 | strncpy(ue->imsi, imsi, sizeof(ue->imsi)); |
| 105 | ue->context_id = get_next_ue_ctx_id(); |
Harald Welte | 256c67a | 2015-09-11 01:22:29 +0200 | [diff] [blame] | 106 | llist_add_tail(&ue->list, &g_hnb_gw.ue_list); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 107 | |
| 108 | return ue; |
| 109 | } |
| 110 | |
| 111 | void ue_context_free(struct ue_context *ue) |
| 112 | { |
| 113 | llist_del(&ue->list); |
| 114 | talloc_free(ue); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 119 | static int hnb_read_cb(struct osmo_fd *fd) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 120 | { |
| 121 | struct hnb_context *hnb = fd->data; |
| 122 | struct sctp_sndrcvinfo sinfo; |
| 123 | struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx"); |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 124 | int flags = 0; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 125 | int rc; |
| 126 | |
| 127 | if (!msg) |
| 128 | return -ENOMEM; |
| 129 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 130 | /* we store a reference to the HomeNodeB in the msg->dest for the |
| 131 | * benefit of varoius downstream processing functions */ |
| 132 | msg->dst = hnb; |
| 133 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 134 | rc = sctp_recvmsg(fd->fd, msgb_data(msg), msgb_tailroom(msg), |
| 135 | NULL, NULL, &sinfo, &flags); |
| 136 | if (rc < 0) { |
| 137 | LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 138 | /* FIXME: clean up after disappeared HNB */ |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 139 | close(fd->fd); |
| 140 | osmo_fd_unregister(fd); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 141 | return rc; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 142 | } else if (rc == 0) { |
| 143 | LOGP(DMAIN, LOGL_ERROR, "Connection to HNB closed\n"); |
| 144 | /* TODO: Remove all UEs from that connection */ |
| 145 | close(fd->fd); |
| 146 | osmo_fd_unregister(fd); |
| 147 | fd->fd = -1; |
| 148 | |
| 149 | return -1; |
| 150 | } else { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 151 | msgb_put(msg, rc); |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 152 | } |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 153 | |
Harald Welte | 17878e2 | 2015-09-08 00:09:13 +0200 | [diff] [blame] | 154 | if (flags & MSG_NOTIFICATION) { |
Daniel Willmann | 7c27f7b | 2015-12-15 17:41:41 +0100 | [diff] [blame] | 155 | LOGP(DMAIN, LOGL_DEBUG, "Ignoring SCTP notification\n"); |
Harald Welte | 17878e2 | 2015-09-08 00:09:13 +0200 | [diff] [blame] | 156 | msgb_free(msg); |
| 157 | return 0; |
| 158 | } |
| 159 | |
Harald Welte | 5c11c94 | 2015-09-07 19:54:49 +0200 | [diff] [blame] | 160 | sinfo.sinfo_ppid = ntohl(sinfo.sinfo_ppid); |
| 161 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 162 | switch (sinfo.sinfo_ppid) { |
| 163 | case IUH_PPI_HNBAP: |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 164 | hnb->hnbap_stream = sinfo.sinfo_stream; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 165 | rc = hnbgw_hnbap_rx(hnb, msg); |
| 166 | break; |
| 167 | case IUH_PPI_RUA: |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 168 | hnb->rua_stream = sinfo.sinfo_stream; |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 169 | rc = hnbgw_rua_rx(hnb, msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 170 | break; |
| 171 | case IUH_PPI_SABP: |
| 172 | case IUH_PPI_RNA: |
| 173 | case IUH_PPI_PUA: |
| 174 | LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n", |
| 175 | sinfo.sinfo_ppid); |
| 176 | rc = 0; |
| 177 | break; |
| 178 | default: |
| 179 | LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n", |
| 180 | sinfo.sinfo_ppid); |
| 181 | rc = 0; |
| 182 | break; |
| 183 | } |
| 184 | |
Harald Welte | f2f3000 | 2015-09-08 00:09:23 +0200 | [diff] [blame] | 185 | msgb_free(msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 186 | return rc; |
| 187 | } |
| 188 | |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 189 | static int hnb_write_cb(struct osmo_fd *fd, struct msgb *msg) |
| 190 | { |
| 191 | struct hnb_context *ctx = fd->data; |
| 192 | struct sctp_sndrcvinfo sinfo = { |
Harald Welte | cfcc1e6 | 2015-09-07 22:39:56 +0200 | [diff] [blame] | 193 | .sinfo_ppid = htonl(msgb_ppid(msg)), |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 194 | .sinfo_stream = ctx->hnbap_stream, |
| 195 | }; |
| 196 | int rc; |
| 197 | |
| 198 | rc = sctp_send(fd->fd, msgb_data(msg), msgb_length(msg), |
| 199 | &sinfo, 0); |
Harald Welte | 9e270b4 | 2015-09-07 22:41:26 +0200 | [diff] [blame] | 200 | /* we don't need to msgb_free(), write_queue does this for us */ |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 201 | return rc; |
| 202 | } |
| 203 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 204 | /*! call-back when the listen FD has something to read */ |
| 205 | static int listen_fd_cb(struct osmo_fd *fd, unsigned int what) |
| 206 | { |
| 207 | struct hnb_gw *gw = fd->data; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 208 | struct hnb_context *ctx; |
| 209 | struct sockaddr_storage sockaddr; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 210 | socklen_t len = sizeof(sockaddr); |
| 211 | |
| 212 | int new_fd = accept(fd->fd, (struct sockaddr *)&sockaddr, &len); |
| 213 | if (new_fd < 0) { |
| 214 | LOGP(DMAIN, LOGL_ERROR, "Iuh accept() failed\n"); |
| 215 | return new_fd; |
| 216 | } |
| 217 | |
| 218 | LOGP(DMAIN, LOGL_INFO, "SCTP Connection accept()ed\n"); |
| 219 | |
| 220 | ctx = talloc_zero(tall_hnb_ctx, struct hnb_context); |
| 221 | if (!ctx) |
| 222 | return -ENOMEM; |
| 223 | |
| 224 | ctx->gw = gw; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 225 | osmo_wqueue_init(&ctx->wqueue, 16); |
| 226 | ctx->wqueue.bfd.data = ctx; |
| 227 | ctx->wqueue.bfd.fd = new_fd; |
| 228 | ctx->wqueue.bfd.when = BSC_FD_READ; |
| 229 | ctx->wqueue.read_cb = hnb_read_cb; |
| 230 | ctx->wqueue.write_cb = hnb_write_cb; |
| 231 | osmo_fd_register(&ctx->wqueue.bfd); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 232 | |
| 233 | llist_add_tail(&ctx->list, &gw->hnb_list); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 238 | static const struct log_info_cat log_cat[] = { |
| 239 | [DMAIN] = { |
Daniel Willmann | 7c27f7b | 2015-12-15 17:41:41 +0100 | [diff] [blame] | 240 | .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 241 | .color = "", |
| 242 | .description = "Main program", |
| 243 | }, |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 244 | [DHNBAP] = { |
| 245 | .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 246 | .color = "", |
| 247 | .description = "Home Node B Application Part", |
| 248 | }, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 249 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 250 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 251 | static const struct log_info hnbgw_log_info = { |
| 252 | .cat = log_cat, |
| 253 | .num_cat = ARRAY_SIZE(log_cat), |
| 254 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 255 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 256 | static struct vty_app_info vty_info = { |
| 257 | .name = "OsmoHNBGW", |
| 258 | .version = "0", |
| 259 | }; |
| 260 | |
| 261 | static int daemonize = 0; |
| 262 | |
Harald Welte | 5c11c94 | 2015-09-07 19:54:49 +0200 | [diff] [blame] | 263 | static int sctp_sock_init(int fd) |
| 264 | { |
| 265 | struct sctp_event_subscribe event; |
| 266 | int rc; |
| 267 | |
| 268 | /* subscribe for all events */ |
| 269 | memset((uint8_t *)&event, 1, sizeof(event)); |
| 270 | rc = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, |
| 271 | &event, sizeof(event)); |
| 272 | |
| 273 | return rc; |
| 274 | } |
| 275 | |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 276 | static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb) |
| 277 | { |
| 278 | vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info, |
| 279 | hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid, |
| 280 | VTY_NEWLINE); |
| 281 | vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE); |
| 282 | } |
| 283 | |
| 284 | static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue) |
| 285 | { |
| 286 | vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE); |
| 287 | } |
| 288 | |
| 289 | DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB") |
| 290 | { |
| 291 | struct hnb_context *hnb; |
| 292 | |
| 293 | llist_for_each_entry(hnb, &g_hnb_gw.hnb_list, list) { |
| 294 | vty_dump_hnb_info(vty, hnb); |
| 295 | } |
| 296 | |
| 297 | return CMD_SUCCESS; |
| 298 | } |
| 299 | |
| 300 | DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE") |
| 301 | { |
| 302 | struct ue_context *ue; |
| 303 | |
| 304 | llist_for_each_entry(ue, &g_hnb_gw.ue_list, list) { |
| 305 | vty_dump_ue_info(vty, ue); |
| 306 | } |
| 307 | |
| 308 | return CMD_SUCCESS; |
| 309 | } |
| 310 | |
| 311 | static void hnbgw_vty_init(void) |
| 312 | { |
| 313 | install_element_ve(&show_hnb_cmd); |
| 314 | install_element_ve(&show_ue_cmd); |
| 315 | } |
| 316 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 317 | int main(int argc, char **argv) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 318 | { |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 319 | int rc; |
| 320 | |
| 321 | tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context"); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 322 | tall_ue_ctx = talloc_named_const(NULL, 0, "ue_context"); |
Harald Welte | 08de638 | 2015-08-31 09:54:45 +0200 | [diff] [blame] | 323 | talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context"); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 324 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 325 | g_hnb_gw.listen_fd.cb = listen_fd_cb; |
| 326 | g_hnb_gw.listen_fd.when = BSC_FD_READ; |
| 327 | g_hnb_gw.listen_fd.data = &g_hnb_gw; |
Harald Welte | 10dfc5a | 2015-09-11 01:34:45 +0200 | [diff] [blame] | 328 | g_hnb_gw.next_ue_ctx_id = 23; |
Harald Welte | 08a793b | 2015-09-07 19:53:46 +0200 | [diff] [blame] | 329 | INIT_LLIST_HEAD(&g_hnb_gw.hnb_list); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 330 | INIT_LLIST_HEAD(&g_hnb_gw.ue_list); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 331 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 332 | rc = osmo_init_logging(&hnbgw_log_info); |
| 333 | if (rc < 0) |
| 334 | exit(1); |
| 335 | |
| 336 | vty_init(&vty_info); |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 337 | hnbgw_vty_init(); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 338 | |
| 339 | rc = telnet_init(NULL, &g_hnb_gw, 2323); |
| 340 | if (rc < 0) { |
| 341 | perror("Error binding VTY port"); |
| 342 | exit(1); |
| 343 | } |
| 344 | |
| 345 | rc = osmo_sock_init_ofd(&g_hnb_gw.listen_fd, AF_INET, SOCK_STREAM, |
Harald Welte | 1c0f538 | 2015-09-07 18:46:58 +0200 | [diff] [blame] | 346 | IPPROTO_SCTP, NULL, |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 347 | g_hnb_gw.config.iuh_listen_port, OSMO_SOCK_F_BIND); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 348 | if (rc < 0) { |
| 349 | perror("Error binding Iuh port"); |
| 350 | exit(1); |
| 351 | } |
Harald Welte | 5c11c94 | 2015-09-07 19:54:49 +0200 | [diff] [blame] | 352 | sctp_sock_init(g_hnb_gw.listen_fd.fd); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 353 | |
| 354 | if (daemonize) { |
| 355 | rc = osmo_daemonize(); |
| 356 | if (rc < 0) { |
| 357 | perror("Error during daemonize"); |
| 358 | exit(1); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | while (1) { |
| 363 | rc = osmo_select_main(0); |
| 364 | if (rc < 0) |
| 365 | exit(3); |
| 366 | } |
| 367 | |
| 368 | /* not reached */ |
| 369 | exit(0); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 370 | } |