Harald Welte | f736559 | 2020-04-15 21:48:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #include <unistd.h> |
| 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <stdio.h> |
| 8 | #include <assert.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <signal.h> |
| 11 | #include <errno.h> |
| 12 | |
| 13 | #include <pthread.h> |
| 14 | |
| 15 | #include <osmocom/core/linuxlist.h> |
| 16 | #include <osmocom/core/talloc.h> |
| 17 | #include <osmocom/core/select.h> |
| 18 | #include <osmocom/core/application.h> |
| 19 | #include <osmocom/core/logging.h> |
| 20 | #include <osmocom/core/stats.h> |
| 21 | #include <osmocom/core/rate_ctr.h> |
| 22 | #include <osmocom/core/socket.h> |
| 23 | #include <osmocom/vty/telnet_interface.h> |
| 24 | #include <osmocom/vty/logging.h> |
| 25 | #include <osmocom/vty/stats.h> |
| 26 | #include <osmocom/vty/ports.h> |
| 27 | #include <osmocom/vty/command.h> |
| 28 | #include <osmocom/vty/misc.h> |
| 29 | |
| 30 | #include <osmocom/netif/stream.h> |
| 31 | #include <netinet/sctp.h> |
| 32 | |
| 33 | #include <jansson.h> |
| 34 | |
| 35 | #include "internal.h" |
| 36 | #include "netns.h" |
| 37 | #include "gtp.h" |
| 38 | |
| 39 | /*********************************************************************** |
| 40 | * Client (Contol/User Plane Separation) Socket |
| 41 | ***********************************************************************/ |
| 42 | |
| 43 | #define CUPS_MSGB_SIZE 1024 |
| 44 | |
| 45 | #define LOGCC(cc, lvl, fmt, args ...) \ |
| 46 | LOGP(DUECUPS, lvl, "%s: " fmt, (cc)->sockname, ## args) |
| 47 | |
| 48 | struct cups_client { |
| 49 | /* member in daemon->cups_clients */ |
| 50 | struct llist_head list; |
| 51 | /* back-pointer to daemon */ |
| 52 | struct gtp_daemon *d; |
| 53 | /* client socket */ |
| 54 | struct osmo_stream_srv *srv; |
| 55 | char sockname[OSMO_SOCK_NAME_MAXLEN]; |
| 56 | }; |
| 57 | |
| 58 | /* Send JSON to a given client/connection */ |
| 59 | static int cups_client_tx_json(struct cups_client *cc, json_t *jtx) |
| 60 | { |
| 61 | struct msgb *msg = msgb_alloc(CUPS_MSGB_SIZE, "Tx JSON"); |
| 62 | char *json_str = json_dumps(jtx, JSON_SORT_KEYS); |
| 63 | char *out; |
| 64 | int json_strlen; |
| 65 | |
| 66 | json_decref(jtx); |
| 67 | if (!json_str) { |
| 68 | LOGCC(cc, LOGL_ERROR, "Error encoding JSON\n"); |
| 69 | return 0; |
| 70 | } |
| 71 | json_strlen = strlen(json_str); |
| 72 | |
| 73 | LOGCC(cc, LOGL_DEBUG, "JSON Tx '%s'\n", json_str); |
| 74 | |
| 75 | if (json_strlen > msgb_tailroom(msg)) { |
| 76 | LOGCC(cc, LOGL_ERROR, "Not enough room for JSON in msgb\n"); |
| 77 | free(json_str); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | out = (char *)msgb_put(msg, json_strlen); |
| 82 | memcpy(out, json_str, json_strlen); |
| 83 | free(json_str); |
| 84 | osmo_stream_srv_send(cc->srv, msg); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static json_t *gen_uecups_result(const char *name, const char *res) |
| 90 | { |
| 91 | json_t *jres = json_object(); |
| 92 | json_t *jret = json_object(); |
| 93 | |
| 94 | json_object_set_new(jres, "result", json_string(res)); |
| 95 | json_object_set_new(jret, name, jres); |
| 96 | |
| 97 | return jret; |
| 98 | } |
| 99 | |
| 100 | static int parse_ep(struct sockaddr_storage *out, json_t *in) |
| 101 | { |
| 102 | json_t *jaddr_type, *jport, *jip; |
| 103 | const char *addr_type, *ip; |
| 104 | uint8_t buf[16]; |
| 105 | |
| 106 | /* {"addr_type":"IPV4","ip":"31323334","Port":2152} */ |
| 107 | |
| 108 | if (!json_is_object(in)) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | jaddr_type = json_object_get(in, "addr_type"); |
| 112 | jport = json_object_get(in, "Port"); |
| 113 | jip = json_object_get(in, "ip"); |
| 114 | |
| 115 | if (!jaddr_type || !jport || !jip) |
| 116 | return -EINVAL; |
| 117 | |
| 118 | if (!json_is_string(jaddr_type) || !json_is_integer(jport) || !json_is_string(jip)) |
| 119 | return -EINVAL; |
| 120 | |
| 121 | addr_type = json_string_value(jaddr_type); |
| 122 | ip = json_string_value(jip); |
| 123 | |
| 124 | memset(out, 0, sizeof(*out)); |
| 125 | |
| 126 | if (!strcmp(addr_type, "IPV4")) { |
| 127 | struct sockaddr_in *sin = (struct sockaddr_in *) out; |
| 128 | if (osmo_hexparse(ip, buf, sizeof(buf)) != 4) |
| 129 | return -EINVAL; |
| 130 | memcpy(&sin->sin_addr, buf, 4); |
| 131 | sin->sin_family = AF_INET; |
| 132 | sin->sin_port = htons(json_integer_value(jport)); |
| 133 | } else if (!strcmp(addr_type, "IPV6")) { |
| 134 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) out; |
| 135 | if (osmo_hexparse(ip, buf, sizeof(buf)) != 16) |
| 136 | return -EINVAL; |
| 137 | memcpy(&sin6->sin6_addr, buf, 16); |
| 138 | sin6->sin6_family = AF_INET6; |
| 139 | sin6->sin6_port = htons(json_integer_value(jport)); |
| 140 | } else |
| 141 | return -EINVAL; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | static int parse_eua(struct sockaddr_storage *out, json_t *jip, json_t *jaddr_type) |
| 147 | { |
| 148 | const char *addr_type, *ip; |
| 149 | uint8_t buf[16]; |
| 150 | |
| 151 | if (!json_is_string(jip) || !json_is_string(jaddr_type)) |
| 152 | return -EINVAL; |
| 153 | |
| 154 | addr_type = json_string_value(jaddr_type); |
| 155 | ip = json_string_value(jip); |
| 156 | |
| 157 | memset(out, 0, sizeof(*out)); |
| 158 | |
| 159 | if (!strcmp(addr_type, "IPV4")) { |
| 160 | struct sockaddr_in *sin = (struct sockaddr_in *) out; |
| 161 | if (osmo_hexparse(ip, buf, sizeof(buf)) != 4) |
| 162 | return -EINVAL; |
| 163 | memcpy(&sin->sin_addr, buf, 4); |
| 164 | sin->sin_family = AF_INET; |
| 165 | } else if (!strcmp(addr_type, "IPV6")) { |
| 166 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) out; |
| 167 | if (osmo_hexparse(ip, buf, sizeof(buf)) != 16) |
| 168 | return -EINVAL; |
| 169 | memcpy(&sin6->sin6_addr, buf, 16); |
| 170 | sin6->sin6_family = AF_INET6; |
| 171 | } else |
| 172 | return -EINVAL; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | |
| 178 | static int parse_create_tun(struct gtp_tunnel_params *out, json_t *ctun) |
| 179 | { |
| 180 | json_t *jlocal_gtp_ep, *jremote_gtp_ep; |
| 181 | json_t *jrx_teid, *jtx_teid; |
| 182 | json_t *jtun_dev_name, *jtun_netns_name; |
| 183 | json_t *juser_addr, *juser_addr_type; |
| 184 | int rc; |
| 185 | |
| 186 | /* '{"create_tun":{"tx_teid":1234,"rx_teid":5678,"user_addr_type":"IPV4","user_addr":"21222324","local_gtp_ep":{"addr_type":"IPV4","ip":"31323334","Port":2152},"remote_gtp_ep":{"addr_type":"IPV4","ip":"41424344","Port":2152},"tun_dev_name":"tun23","tun_netns_name":"foo"}}' */ |
| 187 | |
| 188 | if (!json_is_object(ctun)) |
| 189 | return -EINVAL; |
| 190 | |
| 191 | /* mandatory IEs */ |
| 192 | jlocal_gtp_ep = json_object_get(ctun, "local_gtp_ep"); |
| 193 | jremote_gtp_ep = json_object_get(ctun, "remote_gtp_ep"); |
| 194 | jrx_teid = json_object_get(ctun, "rx_teid"); |
| 195 | jtx_teid = json_object_get(ctun, "tx_teid"); |
| 196 | jtun_dev_name = json_object_get(ctun, "tun_dev_name"); |
| 197 | juser_addr = json_object_get(ctun, "user_addr"); |
| 198 | juser_addr_type = json_object_get(ctun, "user_addr_type"); |
| 199 | |
| 200 | if (!jlocal_gtp_ep || !jremote_gtp_ep || !jrx_teid || !jtx_teid || !jtun_dev_name || |
| 201 | !juser_addr || !juser_addr_type) |
| 202 | return -EINVAL; |
| 203 | if (!json_is_object(jlocal_gtp_ep) || !json_is_object(jremote_gtp_ep) || |
| 204 | !json_is_integer(jrx_teid) || !json_is_integer(jtx_teid) || |
| 205 | !json_is_string(jtun_dev_name) || |
| 206 | !json_is_string(juser_addr) || !json_is_string(juser_addr_type)) |
| 207 | return -EINVAL; |
| 208 | |
| 209 | memset(out, 0, sizeof(*out)); |
| 210 | |
| 211 | rc = parse_ep(&out->local_udp, jlocal_gtp_ep); |
| 212 | if (rc < 0) |
| 213 | return rc; |
| 214 | rc = parse_ep(&out->remote_udp, jremote_gtp_ep); |
| 215 | if (rc < 0) |
| 216 | return rc; |
| 217 | rc = parse_eua(&out->user_addr, juser_addr, juser_addr_type); |
| 218 | if (rc < 0) |
| 219 | return rc; |
| 220 | out->rx_teid = json_integer_value(jrx_teid); |
| 221 | out->tx_teid = json_integer_value(jtx_teid); |
| 222 | out->tun_name = talloc_strdup(out, json_string_value(jtun_dev_name)); |
| 223 | |
| 224 | /* optional IEs */ |
| 225 | jtun_netns_name = json_object_get(ctun, "tun_netns_name"); |
| 226 | if (jtun_netns_name) { |
| 227 | if (!json_is_string(jtun_netns_name)) |
| 228 | return -EINVAL; |
| 229 | out->tun_netns_name = talloc_strdup(out, json_string_value(jtun_netns_name)); |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | static int cups_client_handle_create_tun(struct cups_client *cc, json_t *ctun) |
| 237 | { |
| 238 | int rc; |
| 239 | struct gtp_tunnel_params *tpars = talloc_zero(cc, struct gtp_tunnel_params); |
| 240 | struct gtp_tunnel *t; |
| 241 | |
| 242 | rc = parse_create_tun(tpars, ctun); |
| 243 | if (rc < 0) { |
| 244 | talloc_free(tpars); |
| 245 | return rc; |
| 246 | } |
| 247 | |
| 248 | t = gtp_tunnel_alloc(g_daemon, tpars); |
| 249 | if (!t) { |
| 250 | LOGCC(cc, LOGL_NOTICE, "Failed to allocate tunnel\n"); |
| 251 | cups_client_tx_json(cc, gen_uecups_result("create_tun_res", "ERR_NOT_FOUND")); |
| 252 | } else { |
| 253 | cups_client_tx_json(cc, gen_uecups_result("create_tun_res", "OK")); |
| 254 | } |
| 255 | |
| 256 | talloc_free(tpars); |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int cups_client_handle_destroy_tun(struct cups_client *cc, json_t *dtun) |
| 261 | { |
| 262 | struct sockaddr_storage local_ep_addr; |
| 263 | json_t *jlocal_gtp_ep, *jrx_teid; |
| 264 | uint32_t rx_teid; |
| 265 | int rc; |
| 266 | |
| 267 | jlocal_gtp_ep = json_object_get(dtun, "local_gtp_ep"); |
| 268 | jrx_teid = json_object_get(dtun, "rx_teid"); |
| 269 | |
| 270 | if (!jlocal_gtp_ep || !jrx_teid) |
| 271 | return -EINVAL; |
| 272 | |
| 273 | if (!json_is_object(jlocal_gtp_ep) || !json_is_integer(jrx_teid)) |
| 274 | return -EINVAL; |
| 275 | |
| 276 | rc = parse_ep(&local_ep_addr, jlocal_gtp_ep); |
| 277 | if (rc < 0) |
| 278 | return rc; |
| 279 | rx_teid = json_integer_value(jrx_teid); |
| 280 | |
| 281 | rc = gtp_tunnel_destroy(g_daemon, &local_ep_addr, rx_teid); |
| 282 | if (rc < 0) { |
| 283 | LOGCC(cc, LOGL_NOTICE, "Failed to destroy tunnel\n"); |
| 284 | cups_client_tx_json(cc, gen_uecups_result("destroy_tun_res", "ERR_NOT_FOUND")); |
| 285 | } else { |
| 286 | cups_client_tx_json(cc, gen_uecups_result("destroy_tun_res", "OK")); |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int cups_client_handle_json(struct cups_client *cc, json_t *jroot) |
| 293 | { |
| 294 | void *iter; |
| 295 | const char *key; |
| 296 | json_t *cmd; |
| 297 | int rc; |
| 298 | |
| 299 | if (!json_is_object(jroot)) |
| 300 | return -EINVAL; |
| 301 | |
| 302 | iter = json_object_iter(jroot); |
| 303 | key = json_object_iter_key(iter); |
| 304 | cmd = json_object_iter_value(iter); |
| 305 | if (!iter || !key || !cmd) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | if (!strcmp(key, "create_tun")) { |
| 309 | rc = cups_client_handle_create_tun(cc, cmd); |
| 310 | } else if (!strcmp(key, "destroy_tun")) { |
| 311 | rc = cups_client_handle_destroy_tun(cc, cmd); |
| 312 | } else { |
| 313 | LOGCC(cc, LOGL_NOTICE, "Unknown command '%s' received\n", key); |
| 314 | return -EINVAL; |
| 315 | } |
| 316 | |
| 317 | if (rc < 0) { |
| 318 | LOGCC(cc, LOGL_NOTICE, "Error %d handling '%s' command\n", rc, key); |
| 319 | char buf[64]; |
| 320 | snprintf(buf, sizeof(buf), "%s_res", key); |
| 321 | cups_client_tx_json(cc, gen_uecups_result(buf, "ERR_INVALID_DATA")); |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | /* control/user plane separation per-client read cb */ |
| 329 | static int cups_client_read_cb(struct osmo_stream_srv *conn) |
| 330 | { |
| 331 | struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn); |
| 332 | struct cups_client *cc = osmo_stream_srv_get_data(conn); |
| 333 | struct msgb *msg = msgb_alloc(CUPS_MSGB_SIZE, "Rx JSON"); |
| 334 | struct sctp_sndrcvinfo sinfo; |
| 335 | json_error_t jerr; |
| 336 | json_t *jroot; |
| 337 | int flags = 0; |
| 338 | int rc = 0; |
| 339 | |
| 340 | /* Read message from socket */ |
| 341 | /* we cannot use osmo_stream_srv_recv() here, as we might get some out-of-band info from |
| 342 | * SCTP. FIXME: add something like osmo_stream_srv_recv_sctp() to libosmo-netif and use |
| 343 | * it here as well as in libosmo-sigtran and osmo-msc */ |
| 344 | rc = sctp_recvmsg(ofd->fd, msg->tail, msgb_tailroom(msg), NULL, NULL, &sinfo,&flags); |
| 345 | if (rc <= 0) { |
| 346 | osmo_stream_srv_destroy(conn); |
| 347 | rc = -1; |
| 348 | goto out; |
| 349 | } else |
| 350 | msgb_put(msg, rc); |
| 351 | |
| 352 | if (flags & MSG_NOTIFICATION) { |
| 353 | union sctp_notification *notif = (union sctp_notification *) msgb_data(msg); |
| 354 | switch (notif->sn_header.sn_type) { |
| 355 | case SCTP_SHUTDOWN_EVENT: |
| 356 | osmo_stream_srv_destroy(conn); |
| 357 | rc = -EBADF; |
| 358 | goto out; |
| 359 | default: |
| 360 | break; |
| 361 | } |
| 362 | goto out; |
| 363 | } |
| 364 | |
| 365 | LOGCC(cc, LOGL_DEBUG, "Rx '%s'\n", msgb_data(msg)); |
| 366 | |
| 367 | /* Parse the JSON */ |
| 368 | jroot = json_loadb((const char *) msgb_data(msg), msgb_length(msg), 0, &jerr); |
| 369 | if (!jroot) { |
| 370 | LOGCC(cc, LOGL_ERROR, "Error decoding JSON (%s)", jerr.text); |
| 371 | rc = -1; |
| 372 | goto out; |
| 373 | } |
| 374 | |
| 375 | /* Dispatch */ |
| 376 | rc = cups_client_handle_json(cc, jroot); |
| 377 | |
| 378 | json_decref(jroot); |
| 379 | msgb_free(msg); |
| 380 | |
| 381 | return 0; |
| 382 | out: |
| 383 | msgb_free(msg); |
| 384 | return rc; |
| 385 | } |
| 386 | |
| 387 | static int cups_client_closed_cb(struct osmo_stream_srv *conn) |
| 388 | { |
| 389 | struct cups_client *cc = osmo_stream_srv_get_data(conn); |
| 390 | |
| 391 | LOGCC(cc, LOGL_INFO, "UECUPS connection lost\n"); |
| 392 | llist_del(&cc->list); |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | |
| 397 | /* the control/user plane separation server bind/accept fd */ |
| 398 | static int cups_accept_cb(struct osmo_stream_srv_link *link, int fd) |
| 399 | { |
| 400 | struct gtp_daemon *d = osmo_stream_srv_link_get_data(link); |
| 401 | struct cups_client *cc; |
| 402 | |
| 403 | cc = talloc_zero(d, struct cups_client); |
| 404 | if (!cc) |
| 405 | return -1; |
| 406 | |
| 407 | osmo_sock_get_name_buf(cc->sockname, sizeof(cc->sockname), fd); |
| 408 | cc->srv = osmo_stream_srv_create(cc, link, fd, cups_client_read_cb, cups_client_closed_cb, cc); |
| 409 | if (!cc->srv) { |
| 410 | talloc_free(cc); |
| 411 | return -1; |
| 412 | } |
| 413 | LOGCC(cc, LOGL_INFO, "Accepted new UECUPS connection\n"); |
| 414 | |
| 415 | llist_add_tail(&cc->list, &d->cups_clients); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | /*********************************************************************** |
| 421 | * GTP Daemon |
| 422 | ***********************************************************************/ |
| 423 | |
Harald Welte | 432a130 | 2020-04-17 12:52:40 +0200 | [diff] [blame^] | 424 | #ifndef OSMO_VTY_PORT_UECUPS |
| 425 | #define OSMO_VTY_PORT_UECUPS 4268 |
| 426 | #endif |
| 427 | |
Harald Welte | f736559 | 2020-04-15 21:48:45 +0200 | [diff] [blame] | 428 | struct gtp_daemon *g_daemon; |
| 429 | static int g_daemonize; |
| 430 | static char *g_config_file = "osmo-gtpu-daemon.cfg"; |
| 431 | extern struct vty_app_info g_vty_info; |
| 432 | |
| 433 | static struct gtp_daemon *gtp_daemon_alloc(void *ctx) |
| 434 | { |
| 435 | struct gtp_daemon *d = talloc_zero(ctx, struct gtp_daemon); |
| 436 | if (!d) |
| 437 | return NULL; |
| 438 | |
| 439 | INIT_LLIST_HEAD(&d->gtp_endpoints); |
| 440 | INIT_LLIST_HEAD(&d->tun_devices); |
| 441 | INIT_LLIST_HEAD(&d->gtp_tunnels); |
| 442 | pthread_rwlock_init(&d->rwlock, NULL); |
| 443 | d->main_thread = pthread_self(); |
| 444 | |
| 445 | INIT_LLIST_HEAD(&d->cups_clients); |
| 446 | |
| 447 | d->cfg.cups_local_ip = talloc_strdup(d, "localhost"); |
Harald Welte | 432a130 | 2020-04-17 12:52:40 +0200 | [diff] [blame^] | 448 | d->cfg.cups_local_port = UECUPS_SCTP_PORT; |
Harald Welte | f736559 | 2020-04-15 21:48:45 +0200 | [diff] [blame] | 449 | |
| 450 | return d; |
| 451 | } |
| 452 | |
| 453 | static const struct log_info_cat log_categories[] = { |
| 454 | [DTUN] = { |
| 455 | .name ="DTUN", |
| 456 | .description = "Tunnel interface (tun device)", |
| 457 | .enabled = 1, .loglevel = LOGL_INFO, |
| 458 | }, |
| 459 | [DEP] = { |
| 460 | .name = "DEP", |
| 461 | .description = "GTP endpoint (UDP socket)", |
| 462 | .enabled = 1, .loglevel = LOGL_INFO, |
| 463 | }, |
| 464 | [DGT] = { |
| 465 | .name = "DGT", |
| 466 | .description = "GTP tunnel (session)", |
| 467 | .enabled = 1, .loglevel = LOGL_INFO, |
| 468 | }, |
| 469 | [DUECUPS] = { |
| 470 | .name = "DUECUPS", |
| 471 | .description = "UE Control User Plane Separation", |
| 472 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 473 | }, |
| 474 | |
| 475 | }; |
| 476 | |
| 477 | static const struct log_info log_info = { |
| 478 | .cat = log_categories, |
| 479 | .num_cat = ARRAY_SIZE(log_categories), |
| 480 | }; |
| 481 | |
| 482 | int main(int argc, char **argv) |
| 483 | { |
| 484 | void *ctx = talloc_named_const(NULL, 0, "root"); |
| 485 | int rc; |
| 486 | |
| 487 | g_vty_info.tall_ctx = ctx; |
| 488 | |
| 489 | osmo_init_ignore_signals(); |
| 490 | osmo_init_logging2(ctx, &log_info); |
| 491 | |
| 492 | g_daemon = gtp_daemon_alloc(ctx); |
| 493 | OSMO_ASSERT(g_daemon); |
| 494 | |
| 495 | osmo_stats_init(ctx); |
| 496 | vty_init(&g_vty_info); |
| 497 | logging_vty_add_cmds(); |
| 498 | osmo_talloc_vty_add_cmds(); |
| 499 | osmo_stats_vty_add_cmds(); |
| 500 | rate_ctr_init(ctx); |
| 501 | gtpud_vty_init(); |
| 502 | |
| 503 | init_netns(); |
| 504 | |
| 505 | rc = vty_read_config_file(g_config_file, NULL); |
| 506 | if (rc < 0) { |
| 507 | fprintf(stderr, "Failed to open config file: '%s'\n", g_config_file); |
| 508 | exit(2); |
| 509 | } |
| 510 | |
Harald Welte | 432a130 | 2020-04-17 12:52:40 +0200 | [diff] [blame^] | 511 | rc = telnet_init_dynif(ctx, NULL, vty_get_bind_addr(), OSMO_VTY_PORT_UECUPS); |
Harald Welte | f736559 | 2020-04-15 21:48:45 +0200 | [diff] [blame] | 512 | if (rc < 0) |
| 513 | exit(1); |
| 514 | |
| 515 | g_daemon->cups_link = osmo_stream_srv_link_create(g_daemon); |
| 516 | if (!g_daemon->cups_link) { |
| 517 | fprintf(stderr, "Failed to create CUPS socket %s:%u (%s)\n", |
| 518 | g_daemon->cfg.cups_local_ip, g_daemon->cfg.cups_local_port, strerror(errno)); |
| 519 | exit(1); |
| 520 | } |
| 521 | |
| 522 | /* UECUPS socket for control from control plane side */ |
| 523 | osmo_stream_srv_link_set_nodelay(g_daemon->cups_link, true); |
| 524 | osmo_stream_srv_link_set_addr(g_daemon->cups_link, g_daemon->cfg.cups_local_ip); |
| 525 | osmo_stream_srv_link_set_port(g_daemon->cups_link, g_daemon->cfg.cups_local_port); |
| 526 | osmo_stream_srv_link_set_proto(g_daemon->cups_link, IPPROTO_SCTP); |
| 527 | osmo_stream_srv_link_set_data(g_daemon->cups_link, g_daemon); |
| 528 | osmo_stream_srv_link_set_accept_cb(g_daemon->cups_link, cups_accept_cb); |
| 529 | osmo_stream_srv_link_open(g_daemon->cups_link); |
| 530 | |
| 531 | if (g_daemonize) { |
| 532 | rc = osmo_daemonize(); |
| 533 | if (rc < 0) { |
| 534 | perror("Error during daemonize"); |
| 535 | exit(1); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | while (1) { |
| 540 | osmo_select_main(0); |
| 541 | } |
| 542 | } |