Exemple #1
0
int main(int argc, char **argv)
{
    struct ctrl_handle *ctrl;
    struct gsm_network dummy_network;
    int rc;

    tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
    tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb");

    signal(SIGINT, &signal_handler);
    signal(SIGABRT, &signal_handler);
    signal(SIGUSR1, &signal_handler);
    signal(SIGUSR2, &signal_handler);

    osmo_init_ignore_signals();
    osmo_init_logging(&gprs_log_info);
    osmo_stats_init(tall_bsc_ctx);

    vty_info.copyright = openbsc_copyright;
    vty_init(&vty_info);
    logging_vty_add_cmds(&gprs_log_info);
    osmo_stats_vty_add_cmds(&gprs_log_info);
    sgsn_vty_init();
    ctrl_vty_init(tall_bsc_ctx);

    handle_options(argc, argv);

    rate_ctr_init(tall_bsc_ctx);

    gprs_ns_set_log_ss(DNS);
    bssgp_set_log_ss(DBSSGP);

    sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_bsc_ctx);
    if (!sgsn_nsi) {
        LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n");
        exit(1);
    }
    bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi;

    gprs_llc_init("/usr/local/lib/osmocom/crypt/");
    sgsn_inst_init();

    gprs_ns_vty_init(bssgp_nsi);
    bssgp_vty_init();
    gprs_llc_vty_init();
    gprs_sndcp_vty_init();
    sgsn_auth_init();
    sgsn_cdr_init(&sgsn_inst);
    /* FIXME: register signal handler for SS_L_NS */

    rc = sgsn_parse_config(sgsn_inst.config_file, &sgsn_inst.cfg);
    if (rc < 0) {
        LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n");
        exit(2);
    }

    /* start telnet after reading config for vty_get_bind_addr() */
    LOGP(DGPRS, LOGL_NOTICE, "VTY at %s %d\n",
         vty_get_bind_addr(), OSMO_VTY_PORT_SGSN);
    rc = telnet_init_dynif(tall_bsc_ctx, &dummy_network,
                           vty_get_bind_addr(), OSMO_VTY_PORT_SGSN);
    if (rc < 0)
        exit(1);

    /* start control interface after reading config for
     * ctrl_vty_get_bind_addr() */
    LOGP(DGPRS, LOGL_NOTICE, "CTRL at %s %d\n",
         ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_SGSN);
    ctrl = sgsn_controlif_setup(NULL, ctrl_vty_get_bind_addr(),
                                OSMO_CTRL_PORT_SGSN);
    if (!ctrl) {
        LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
        exit(1);
    }

    if (sgsn_ctrl_cmds_install() != 0) {
        LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
        exit(1);
    }


    rc = sgsn_gtp_init(&sgsn_inst);
    if (rc) {
        LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n");
        exit(2);
    }

    rc = gprs_subscr_init(&sgsn_inst);
    if (rc < 0) {
        LOGP(DGPRS, LOGL_FATAL, "Cannot set up subscriber management\n");
        exit(2);
    }

    rc = gprs_ns_nsip_listen(sgsn_nsi);
    if (rc < 0) {
        LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n");
        exit(2);
    }

    rc = gprs_ns_frgre_listen(sgsn_nsi);
    if (rc < 0) {
        LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE "
             "socket. Do you have CAP_NET_RAW?\n");
        exit(2);
    }

    if (sgsn->cfg.dynamic_lookup) {
        if (sgsn_ares_init(sgsn) != 0) {
            LOGP(DGPRS, LOGL_FATAL,
                 "Failed to initialize c-ares(%d)\n", rc);
            exit(4);
        }
    }

    if (daemonize) {
        rc = osmo_daemonize();
        if (rc < 0) {
            perror("Error during daemonize");
            exit(1);
        }
    }

    while (1) {
        rc = osmo_select_main(0);
        if (rc < 0)
            exit(3);
    }

    /* not reached */
    exit(0);
}
Exemple #2
0
int main(int argc, char **argv)
{
	int rc;

	struct cmdline_cfg _ccfg;
	struct cmdline_cfg *ccfg = &_ccfg;
	memset(ccfg, '\0', sizeof(*ccfg));
	ccfg->config_file = "./gtphub.conf";
	ccfg->restart_counter_file = "./gtphub_restart_count";

	struct gtphub_cfg _cfg;
	struct gtphub_cfg *cfg = &_cfg;
	memset(cfg, '\0', sizeof(*cfg));

	struct gtphub _hub;
	struct gtphub *hub = &_hub;

	osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub");
	msgb_talloc_ctx_init(osmo_gtphub_ctx, 0);

	signal(SIGINT, &signal_handler);
	signal(SIGABRT, &signal_handler);
	signal(SIGUSR1, &signal_handler);
	signal(SIGUSR2, &signal_handler);
	osmo_init_ignore_signals();

	osmo_init_logging(&gtphub_log_info);

	vty_info.copyright = gtphub_copyright;
	vty_init(&vty_info);
	logging_vty_add_cmds(&gtphub_log_info);
        gtphub_vty_init(hub, cfg);

	rate_ctr_init(osmo_gtphub_ctx);

	handle_options(ccfg, argc, argv);

	rc = gtphub_cfg_read(cfg, ccfg->config_file);
	if (rc < 0) {
		LOGP(DGTPHUB, LOGL_FATAL, "Cannot parse config file '%s'\n",
		     ccfg->config_file);
		exit(2);
	}

	/* start telnet after reading config for vty_get_bind_addr() */
	rc = telnet_init_dynif(osmo_gtphub_ctx, 0, vty_get_bind_addr(),
			       OSMO_VTY_PORT_GTPHUB);
	if (rc < 0)
		exit(1);

	if (gtphub_start(hub, cfg,
			 next_restart_count(ccfg->restart_counter_file))
	    != 0)
		return -1;

	log_cfg(cfg);

	if (ccfg->daemonize) {
		rc = osmo_daemonize();
		if (rc < 0) {
			LOGP(DGTPHUB, LOGL_FATAL, "Error during daemonize");
			exit(1);
		}
	}

	while (1) {
		rc = osmo_select_main(0);
		if (rc < 0)
			exit(3);
	}

	/* not reached */
	exit(0);
}
Exemple #3
0
int main(int argc, char **argv)
{
	struct gsm_network dummy_network;
	int rc;

	tall_bsc_ctx = talloc_named_const(NULL, 0, "nsip_proxy");
	msgb_talloc_ctx_init(tall_bsc_ctx, 0);

	signal(SIGINT, &signal_handler);
	signal(SIGABRT, &signal_handler);
	signal(SIGUSR1, &signal_handler);
	signal(SIGUSR2, &signal_handler);
	osmo_init_ignore_signals();

	osmo_init_logging(&gprs_log_info);

	vty_info.copyright = openbsc_copyright;
	vty_init(&vty_info);
	logging_vty_add_cmds(&gprs_log_info);
	osmo_stats_vty_add_cmds(&gprs_log_info);
	gbproxy_vty_init();

	handle_options(argc, argv);

	rate_ctr_init(tall_bsc_ctx);
	osmo_stats_init(tall_bsc_ctx);

	bssgp_nsi = gprs_ns_instantiate(&proxy_ns_cb, tall_bsc_ctx);
	if (!bssgp_nsi) {
		LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n");
		exit(1);
	}
	gbproxy_init_config(&gbcfg);
	gbcfg.nsi = bssgp_nsi;
	gprs_ns_vty_init(bssgp_nsi);
	gprs_ns_set_log_ss(DNS);
	bssgp_set_log_ss(DBSSGP);
	osmo_signal_register_handler(SS_L_NS, &gbprox_signal, &gbcfg);

	rc = gbproxy_parse_config(config_file, &gbcfg);
	if (rc < 0) {
		LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n");
		exit(2);
	}

	/* start telnet after reading config for vty_get_bind_addr() */
	rc = telnet_init_dynif(tall_bsc_ctx, &dummy_network,
			       vty_get_bind_addr(), OSMO_VTY_PORT_GBPROXY);
	if (rc < 0)
		exit(1);

	if (!gprs_nsvc_by_nsei(gbcfg.nsi, gbcfg.nsip_sgsn_nsei)) {
		LOGP(DGPRS, LOGL_FATAL, "You cannot proxy to NSEI %u "
			"without creating that NSEI before\n",
			gbcfg.nsip_sgsn_nsei);
		exit(2);
	}

	rc = gprs_ns_nsip_listen(bssgp_nsi);
	if (rc < 0) {
		LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n");
		exit(2);
	}

	rc = gprs_ns_frgre_listen(bssgp_nsi);
	if (rc < 0) {
		LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE "
			"socket. Do you have CAP_NET_RAW?\n");
		exit(2);
	}

	if (daemonize) {
		rc = osmo_daemonize();
		if (rc < 0) {
			perror("Error during daemonize");
			exit(1);
		}
	}

	/* Reset all the persistent NS-VCs that we've read from the config */
	gbprox_reset_persistent_nsvcs(bssgp_nsi);

	while (1) {
		rc = osmo_select_main(0);
		if (rc < 0)
			exit(3);
	}

	exit(0);
}