Пример #1
0
/* freeDiameter starting point */
int main(int argc, char * argv[])
{
	int ret;
	sigset_t sig_all;
	
	/* Block all signals from the current thread and all its future children -- we will catch everything in catch_signals */
	sigfillset(&sig_all);
	ret = pthread_sigmask(SIG_BLOCK, &sig_all, NULL);
	ASSERT(ret == 0);
	
	/* Parse the command-line */
	ret = main_cmdline(argc, argv);
	if (ret != 0) {
		return ret;
	}
	
	/* Initialize the core library */
	ret = fd_core_initialize();
	if (ret != 0) {
		fprintf(stderr, "An error occurred during freeDiameter core library initialization.\n");
		return ret;
	}
	
	/* Set gnutls debug level ? */
	if (gnutls_debug) {
		gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
		gnutls_global_set_log_level (gnutls_debug);
		TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", gnutls_debug);
	}
	
	/* Parse the configuration file */
	CHECK_FCT_DO( fd_core_parseconf(conffile), goto error );
	
	/* Start the servers */
	CHECK_FCT_DO( fd_core_start(), goto error );
	
	/* Allow SIGINT and SIGTERM from this point to terminate the application */
	CHECK_POSIX_DO( pthread_create(&signals_thr, NULL, catch_signals, NULL), goto error );
	
	TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");

	/* Now, just wait for termination */
	CHECK_FCT( fd_core_wait_shutdown_complete() );
	
	/* Just in case it was not the result of a signal, we cancel signals_thr */
	fd_thr_term(&signals_thr);
	
	return 0;
error:	
	CHECK_FCT_DO( fd_core_shutdown(),  );
	CHECK_FCT( fd_core_wait_shutdown_complete() );
	fd_thr_term(&signals_thr);
	return -1;
}
Пример #2
0
int s6a_init(const mme_config_t *mme_config_p)
{
    int ret;

    S6A_DEBUG("Initializing S6a interface\n");

    memset(&s6a_fd_cnf, 0, sizeof(s6a_fd_cnf_t));

    /*if (strcmp(fd_core_version(), FREE_DIAMETER_MINIMUM_VERSION) != 0) {
        S6A_ERROR("Freediameter version %s found, expecting %s\n", fd_core_version(),
                  FREE_DIAMETER_MINIMUM_VERSION);
        return -1;
    } else {
        S6A_DEBUG("Freediameter version %s\n", fd_core_version());
    }*/


    /* Initializing freeDiameter core */
    S6A_DEBUG("Initializing freeDiameter core...\n");
    ret = fd_core_initialize();
    if (ret != 0) {
        S6A_ERROR("An error occurred during freeDiameter core library initialization: %d\n",ret);
        return ret;
    } else {
        S6A_DEBUG("Initializing freeDiameter core done\n");
    }



    S6A_DEBUG("Default ext path: %s\n", DEFAULT_EXTENSIONS_PATH);

    ret = fd_core_parseconf(mme_config_p->s6a_config.conf_file);
    if (ret != 0) {
        S6A_ERROR("An error occurred during fd_core_parseconf file :%s.\n", mme_config_p->s6a_config.conf_file);
        return ret;
    }
    
    /* Set gnutls debug level ? */
    if (gnutls_debug) {
        gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
        gnutls_global_set_log_level (gnutls_debug);
        S6A_DEBUG("Enabled GNUTLS debug at level %d", gnutls_debug);
    }

    /* Starting freeDiameter core */
    ret = fd_core_start();
    if (ret != 0) {
        S6A_ERROR("An error occurred during freeDiameter core library start\n");
        return ret;
    }



    ret = fd_core_waitstartcomplete();
    if (ret != 0) {
        S6A_ERROR("An error occurred during fd_core_waitstartcomplete.\n");
        return ret;
    }

    ret = s6a_fd_init_dict_objs();
    if (ret != 0) {
        S6A_ERROR("An error occurred during s6a_fd_init_dict_objs.\n");
        return ret;
    }

    /* Trying to connect to peers */
    CHECK_FCT(s6a_fd_new_peer());

    if (itti_create_task(TASK_S6A, &s6a_thread, NULL) < 0) {
        S6A_ERROR("s6a create task\n");
        return -1;
    }
    S6A_DEBUG("Initializing S6a interface: DONE\n");

    return 0;
}
Пример #3
0
int s6a_init(hss_config_t *hss_config_p)
{
  int ret = 0;
  struct disp_when when;
  char why[100];

  fprintf(stdout, "Initializing s6a layer\n");

  ret = fd_core_initialize();

  if (ret != 0) {
    strcpy(why, "fd_core_initialize");
    goto err;
  }

  /* Parse the external configuration file */
  ret = fd_core_parseconf(hss_config_p->freediameter_config);

  if (ret != 0) {
    strcpy(why, "fd_core_parseconf");
    goto err;
  }


  ret = fd_core_start();

  if (ret != 0) {
    strcpy(why, "fd_core_start");
    goto err;
  }


  /* We wait till freediameter has completed loading extensions */
  fd_core_waitstartcomplete();

  /* Register the peer acceptor/rejector */
  fd_peer_validate_register(s6a_peer_validate);

  /* Initialize useful objects */
  ret = s6a_init_objs();

  if (ret != 0) {
    strcpy(why, "s6a_init_objs");
    goto err;
  }

  /* Create handler for sessions */
#if FREEDIAMETER_VERSION < 120
  CHECK_FCT(fd_sess_handler_create(&s6a_reg, s6a_cli_sess_cleanup, NULL));
#else
  session_state_dump dumper;
  CHECK_FCT(fd_sess_handler_create(&s6a_reg, s6a_cli_sess_cleanup, dumper, NULL));
#endif

  /* Register the callback */
  memset(&when, 0, sizeof(when));
  when.command = s6a_cnf.dataobj_s6a_auth_cmd;
  when.app     = s6a_cnf.dataobj_s6a_app;

  /* Register the callbacks for S6A Application */
  CHECK_FCT(fd_disp_register(s6a_auth_info_cb, DISP_HOW_CC, &when, NULL,
                             &handle));

  if (handle == NULL) {
    strcpy(why, "cannot register authentication info req cb");
    goto err;
  }

  when.command = s6a_cnf.dataobj_s6a_loc_up;
  when.app     = s6a_cnf.dataobj_s6a_app;

  /* Register the callbacks for S6A Application */
  CHECK_FCT(fd_disp_register(s6a_up_loc_cb, DISP_HOW_CC, &when, NULL,
                             &handle));

  if (handle == NULL) {
    strcpy(why, "cannot register update location req cb");
    goto err;
  }

  when.command = s6a_cnf.dataobj_s6a_purge_ue;
  when.app     = s6a_cnf.dataobj_s6a_app;

  /* Register the callbacks for S6A Application */
  CHECK_FCT(fd_disp_register(s6a_purge_ue_cb, DISP_HOW_CC, &when, NULL,
                             &handle));

  if (handle == NULL) {
    strcpy(why, "cannot register purge ue req cb");
    goto err;
  }

  fprintf(stdout, "Initializing s6a layer: DONE\n");

  return 0;

err:
  fprintf(stdout, "Initializing s6a layer: FAILED (%s)\n", why);
  return -1;
}