Пример #1
0
Map *map_new(int ktype, enum MapValue vtype) {
    if (! t_map) { // initialize
        t_map = obj_new_type(Map,map_clear);    
        init_interfaces();
    }
    Map *m = (Map*)obj_new_from_type(t_map);
    list_init_((List*)m,ktype);
    set_vtype(m,vtype);
    return m;
}
Пример #2
0
int Init(void *_ctx) {
	int n;
	ctx = _ctx;

	moddebug("enter ts=%d\n",oesr_tstamp(ctx));

	if (!mem_ok) {
		init_memory();
		mem_ok = 1;
	}

	if (!log_ok) {
		mlog = NULL;
		if (USE_LOG) {
			if (init_log(ctx)) {
				return -1;
			}
		}
		log_ok = 1;
	}

	if (!check_ok) {
		if (check_configuration(ctx)) {
			return -1;
		}
		check_ok = 1;
	}

	if (init_variables(ctx)) {
		return -1;
	}

	if (init_counter(ctx)) {
		return -1;
	}

	moddebug("calling initialize, ts=%d\n",oesr_tstamp(ctx));

	/* this is the module initialize function */
	if (initialize()) {
		moddebug("error initializing module\n",oesr_tstamp(ctx));
		return -1;
	}

	n = init_interfaces(ctx);
	if (n == -1) {
		return -1;
	} else if (n == 0) {
		return 0;
	}

	moddebug("exit ts=%d\n",oesr_tstamp(ctx));
	return 1;
}
Пример #3
0
int
main(int argc, char **argv)
{
    bool fork_desired = TRUE;
    bool log_to_stderr_desired = FALSE;
    int lockfd;
#ifdef NAT_TRAVERSAL
    bool nat_traversal = FALSE;
    unsigned int keep_alive = 0;
#endif
#ifdef VIRTUAL_IP
    char *virtual_private = NULL;
#endif

    char *ipsec0 = NULL;
    char *ipsec1 = NULL;
    char *ipsec2 = NULL;
    char *ipsec3 = NULL;
    
    /* handle arguments */
    for (;;)
    {
	static const struct option long_opts[] = {
	    /* name, has_arg, flag, val */
	    { "help", no_argument, NULL, 'h' },
	    { "version", no_argument, NULL, 'v' },
	    { "optionsfrom", required_argument, NULL, '+' },
	    { "nofork", no_argument, NULL, 'd' },
	    { "stderrlog", no_argument, NULL, 'e' },
	    { "noklips", no_argument, NULL, 'n' },
	    { "nocrsend", no_argument, NULL, 'c' },
	    { "uniqueids", no_argument, NULL, 'u' },
	    { "interface", required_argument, NULL, 'i' },
	    { "ikeport", required_argument, NULL, 'p' },
	    { "ctlbase", required_argument, NULL, 'b' },
	    { "secretsfile", required_argument, NULL, 's' },
	    { "adns", required_argument, NULL, 'a' },
#ifdef DEBUG
	    { "debug-none", no_argument, NULL, 'N' },
	    { "debug-all]", no_argument, NULL, 'A' },
	    { "debug-raw", no_argument, NULL, 'R' },
	    { "debug-crypt", no_argument, NULL, 'X' },
	    { "debug-parsing", no_argument, NULL, 'P' },
	    { "debug-emitting", no_argument, NULL, 'E' },
	    { "debug-control", no_argument, NULL, 'C' },
	    { "debug-lifecycle", no_argument, NULL, 'L' },
	    { "debug-klips", no_argument, NULL, 'K' },
	    { "debug-dns", no_argument, NULL, 'D' },
	    { "debug-private", no_argument, NULL, 'Z' },
#endif
#ifdef NAT_TRAVERSAL
	    { "nat_traversal", no_argument, NULL, '1' },
	    { "keep_alive", required_argument, NULL, '2' },
#endif
#ifdef VIRTUAL_IP
	    { "virtual_private", required_argument, NULL, '3' },
#endif
    	    { "ipsec0", required_argument, NULL, '4' },
	    { "ipsec1", required_argument, NULL, '5' },
	    { "ipsec2", required_argument, NULL, '6' },
	    { "ipsec3", required_argument, NULL, '7' },
	    { 0,0,0,0 }
	    };
	/* Note: we don't like the way short options get parsed
	 * by getopt_long, so we simply pass an empty string as
	 * the list.  It could be "hvdenp:l:s:" "NARXPECK".
	 */
	int c = getopt_long(argc, argv, "", long_opts, NULL);

	/* Note: "breaking" from case terminates loop */
	switch (c)
	{
	case EOF:	/* end of flags */
	    break;

	case 0: /* long option already handled */
	    continue;

	case ':':	/* diagnostic already printed by getopt_long */
	case '?':	/* diagnostic already printed by getopt_long */
	    usage("");
	    break;   /* not actually reached */

	case 'h':	/* --help */
	    usage(NULL);
	    break;	/* not actually reached */

	case 'v':	/* --version */
	    {
		const char **sp = ipsec_copyright_notice();

		printf("%s\n", ipsec_version_string());
		for (; *sp != NULL; sp++)
		    puts(*sp);
	    }
	    exit_pluto(0);
	    break;	/* not actually reached */

	case '+':	/* --optionsfrom <filename> */
	    optionsfrom(optarg, &argc, &argv, optind, stderr);
	    /* does not return on error */
	    continue;

	case 'd':	/* --nofork*/
	    fork_desired = FALSE;
	    continue;

	case 'e':	/* --stderrlog */
	    log_to_stderr_desired = TRUE;
	    continue;

	case 'n':	/* --noklips */
	    no_klips = TRUE;
	    continue;

	case 'c':	/* --nocrsend */
	    no_cr_send = TRUE;
	    continue
	    ;
	case 'u':	/* --uniquids */
	    uniqueIDs = TRUE;
	    continue;

	case 'i':	/* --interface <ifname> */
	    if (!use_interface(optarg))
		usage("too many --interface specifications");
	    continue;

	case 'p':	/* --port <portnumber> */
	    if (optarg == NULL || !isdigit(optarg[0]))
		usage("missing port number");

	    {
		char *endptr;
		long port = strtol(optarg, &endptr, 0);

		if (*endptr != '\0' || endptr == optarg
		|| port <= 0 || port > 0x10000)
		    usage("<port-number> must be a number between 1 and 65535");
		pluto_port = port;
	    }
	    continue;

	case 'b':	/* --ctlbase <path> */
	    if (snprintf(ctl_addr.sun_path, sizeof(ctl_addr.sun_path)
	    , "%s%s", optarg, CTL_SUFFIX) == -1)
		usage("<path>" CTL_SUFFIX " too long for sun_path");
	    if (snprintf(pluto_lock, sizeof(pluto_lock)
	    , "%s%s", optarg, LOCK_SUFFIX) == -1)
		usage("<path>" LOCK_SUFFIX " must fit");
	    continue;

	case 's':	/* --secretsfile <secrets-file> */
	    shared_secrets_file = optarg;
	    continue;

	case 'a':	/* --adns <pathname> */
	    pluto_adns_option = optarg;
	    continue;

#ifdef DEBUG
	case 'N':	/* --debug-none */
	    base_debugging = DBG_NONE;
	    continue;

	case 'A':	/* --debug-all */
	    base_debugging = DBG_ALL;
	    continue;

	case 'R':	/* --debug-raw */
	    base_debugging |= DBG_RAW;
	    continue;

	case 'X':	/* --debug-crypt */
	    base_debugging |= DBG_CRYPT;
	    continue;

	case 'P':	/* --debug-parsing */
	    base_debugging |= DBG_PARSING;
	    continue;

	case 'E':	/* --debug-emitting */
	    base_debugging |= DBG_EMITTING;
	    continue;

	case 'C':	/* --debug-control */
	    base_debugging |= DBG_CONTROL;
	    continue;

	case 'L':	/* --debug-lifecycle */
	    base_debugging |= DBG_LIFECYCLE;
	    continue;

	case 'K':	/* --debug-klips */
	    base_debugging |= DBG_KLIPS;
	    continue;

	case 'D':	/* --debug-dns */
	    base_debugging |= DBG_DNS;
	    continue;

	case 'Z':	/* --debug-private */
	    base_debugging |= DBG_PRIVATE;
	    continue;
#endif
#ifdef NAT_TRAVERSAL
	case '1':	/* --nat_traversal */
	    nat_traversal = TRUE;
	    continue;
	case '2':	/* --keep_alive */
	    keep_alive = atoi(optarg);
	    continue;
#endif
#ifdef VIRTUAL_IP
	case '3':	/* --virtual_private */
	    virtual_private = optarg;
	    continue;
#endif
	case '4':	/* --ipsec0 */
	    ipsec0 = optarg;
	    continue;
	case '5':	/* --ipsec1 */
	    ipsec1 = optarg;
	    continue;
	case '6':	/* --ipsec2 */
	    ipsec2 = optarg;
	    continue;
	case '7':	/* --ipsec3 */
	    ipsec3 = optarg;
	    continue;

	default:
	    impossible();
	}
	break;
    }
    if (optind != argc)
	usage("unexpected argument");
    reset_debugging();
    lockfd = create_lock();

    /* select between logging methods */

    if (log_to_stderr_desired)
	log_to_syslog = FALSE;
    else
	log_to_stderr = FALSE;

    /* create control socket.
     * We must create it before the parent process returns so that
     * there will be no race condition in using it.  The easiest
     * place to do this is before the daemon fork.
     */
    {
	err_t ugh = init_ctl_socket();

	if (ugh != NULL)
	{
	    fprintf(stderr, "pluto: %s", ugh);
	    exit_pluto(1);
	}
    }

    /* If not suppressed, do daemon fork */

#ifndef EMBED
    if (fork_desired)
    {
	{
	    pid_t pid = fork();

	    if (pid < 0)
	    {
		int e = errno;

		fprintf(stderr, "pluto: fork failed (%d %s)\n",
		    errno, strerror(e));
		exit_pluto(1);
	    }

	    if (pid != 0)
	    {
		/* parent: die, after filling PID into lock file.
		 * must not use exit_pluto: lock would be removed!
		 */
		exit(fill_lock(lockfd, pid)? 0 : 1);
	    }
	}

	if (setsid() < 0)
	{
	    int e = errno;

	    fprintf(stderr, "setsid() failed in main(). Errno %d: %s\n",
		errno, strerror(e));
	    exit_pluto(1);
	}

	/* Close everything but ctl_fd and (if needed) stderr. */
	{
	    int i;

	    for (i = getdtablesize() - 1; i >= 0; i--)  /* Bad hack */
		if ((!log_to_stderr || i != 2)
		&& i != ctl_fd)
		    close(i);

	    /* make sure that stdin, stdout, stderr are reserved */
	    if (open("/dev/null", O_RDONLY) != 0)
		abort();
	    if (dup2(0, 1) != 1)
		abort();
	    if (!log_to_stderr && dup2(0, 2) != 2)
		abort();
	}
    }
    else
#endif
    {
	/* no daemon fork: we have to fill in lock file */
	(void) fill_lock(lockfd, getpid());
	fprintf(stdout, "Pluto initialized\n");
	fflush(stdout);
    }

    init_constants();
    init_log();
    /* Note: some scripts may look for this exact message -- don't change */
    log("Starting Pluto (FreeS/WAN Version %s)", ipsec_version_code());
    log("  including X.509 patch (Version %s)", x509patch_version);

#ifdef NAT_TRAVERSAL
    init_nat_traversal(nat_traversal,keep_alive);
#endif

#ifdef VIRTUAL_IP
    init_virtual_ip(virtual_private);
#endif
    init_interfaces(ipsec0, ipsec1, ipsec2, ipsec3);
    init_rnd_pool();
    init_secret();
    init_states();
    init_crypto();
    init_demux();
    init_kernel();
    init_adns();

    /* loading CA certificates */
    load_cacerts();
    /* loading CRLs */
    load_crls();
    /* loading my X.509 or OpenPGP certificate */
    load_mycert();

    call_server();
    return -1;        /* Shouldn't ever reach this */
}
Пример #4
0
status_t
init_stack()
{
	status_t status = init_domains();
	if (status != B_OK)
		return status;

	status = init_interfaces();
	if (status != B_OK)
		goto err1;

	status = init_device_interfaces();
	if (status != B_OK)
		goto err2;

	status = init_timers();
	if (status != B_OK)
		goto err3;

	status = init_notifications();
	if (status < B_OK) {
		// If this fails, it just means there won't be any notifications,
		// it's not a fatal error.
		dprintf("networking stack notifications could not be initialized: %s\n",
			strerror(status));
	}

	module_info* dummy;
	status = get_module(NET_SOCKET_MODULE_NAME, &dummy);
	if (status != B_OK)
		goto err4;

	mutex_init(&sChainLock, "net chains");
	mutex_init(&sInitializeChainLock, "net intialize chains");

	sFamilies = new(std::nothrow) FamilyTable();
	if (sFamilies == NULL || sFamilies->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err5;
	}

	sProtocolChains = new(std::nothrow) ChainTable();
	if (sProtocolChains == NULL || sProtocolChains->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err6;
	}

	sDatalinkProtocolChains = new(std::nothrow) ChainTable();
	if (sDatalinkProtocolChains == NULL
			|| sDatalinkProtocolChains->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err7;
	}

	sReceivingProtocolChains = new(std::nothrow) ChainTable();
	if (sReceivingProtocolChains == NULL
			|| sReceivingProtocolChains->Init(10) != B_OK) {
		status = B_NO_MEMORY;
		goto err8;
	}

	sInitialized = true;

	link_init();
	scan_modules("network/protocols");
	scan_modules("network/datalink_protocols");

	// TODO: for now!
	register_domain_datalink_protocols(AF_INET, IFT_LOOP,
		"network/datalink_protocols/loopback_frame/v1", NULL);
#if 0 // PPP is not (currently) included in the build
	register_domain_datalink_protocols(AF_INET, IFT_PPP,
		"network/datalink_protocols/ppp_frame/v1", NULL);
#endif
	register_domain_datalink_protocols(AF_INET6, IFT_LOOP,
		"network/datalink_protocols/loopback_frame/v1", NULL);
	register_domain_datalink_protocols(AF_INET, IFT_ETHER,
		"network/datalink_protocols/arp/v1",
		"network/datalink_protocols/ethernet_frame/v1",
		NULL);
	register_domain_datalink_protocols(AF_INET6, IFT_ETHER,
		"network/datalink_protocols/ipv6_datagram/v1",
		"network/datalink_protocols/ethernet_frame/v1",
		NULL);

	return B_OK;

err8:
	delete sDatalinkProtocolChains;
err7:
	delete sProtocolChains;
err6:
	delete sFamilies;
err5:
	mutex_destroy(&sInitializeChainLock);
	mutex_destroy(&sChainLock);
err4:
	uninit_timers();
err3:
	uninit_device_interfaces();
err2:
	uninit_interfaces();
err1:
	uninit_domains();
	return status;
}
Пример #5
0
int main(int argc, char **argv) {
	int errors = 0;
	int daemon = 0;
	int verbose = 0;
#ifdef GEN_OLD_FILES
	char *usage = "Usage: %s [-f config_file] [-g | -t | -x | -a] [-v];\n\t where g=FlapGraph, t= FlapTableDaily, x=ASExplorer, a= all three.\n";
#else 
	char *usage = "Usage: %s [-f config_file] [-p uii_port ] [-v] [-d]\n";
#endif GEN_OLD_FILES
	char *config_file = CONFIG;
	char *port = PORT;
	char c;
	int found_one = 0;

	tzset();	/* needed by my_mktime, must be before multi-thread */
	appname = strdup(argv[0]);

#ifdef GEN_OLD_FILES
       /* check if no args supplied */
       if (argc == 1) {
		fprintf (stderr, usage, appname);
		printf ("\nDerived from: DataDistiller %s (MRT %s) compiled on %s\n\n",
			DATADSTL_VERSION, MRT_VERSION, __DATE__);
		exit (1);
       }

       while ((c = getopt (argc, argv, "f:gtxav")) != -1) {
#else 
	   while ((c = getopt (argc, argv, "f:p:vd")) != -1) {
#endif GEN_OLD_FILES
		switch (c) {
		case 'f':		/* config file */
		    config_file = optarg;
		    break;
#ifdef GEN_OLD_FILES
		case 'g':               /* old FlapGraph files */
		    if (found_one) {
			errors++;
		    }
		    else {
			dump_fg = 1;
			found_one = 1;
		    }
		    break;
		case 't':               /* old FlapTableDaily files */
		    if (found_one) {
			errors++;
		    }
		    else {
			dump_ftd = 1;
			found_one = 1;
		    }
		    break;
		case 'x':
		    if (found_one) {
			errors++;
		    }
		    else {
			dump_ase = 1;       /* old ASExplorer files */
			found_one = 1;
		    }
		    break;
		case 'a':               /* all 3 above */
		    if (found_one) {
			errors++;
		    }
		    else {
			dump_fg = dump_ftd = dump_ase = 1;
			found_one = 1;
		    }
		    break;
#else 
			case 'p':		/* uii port number */
				port = optarg;
				break;
#endif GEN_OLD_FILES
			case 'v':		/* verbose */
				verbose = 1;
				break;
#ifndef GEN_OLD_FILES
			case 'd':		/* set self up as daemon */
				daemon = 1;
				break;
#endif GEN_OLD_FILES
			default:
				errors++;
				break;
		}
	   }

	if (errors) {
		fprintf (stderr, usage, appname);
		printf ("\nDataDistiller %s (MRT %s) compiled on %s\n\n",
			DATADSTL_VERSION, MRT_VERSION, __DATE__);
		exit (1);
	}

	default_trace = New_Trace2(appname);
	if (daemon)
		daemon_init();

	if (verbose)
		set_trace (default_trace, TRACE_FLAGS, NORM | TR_ERROR,
			TRACE_LOGFILE, "stdout", NULL);

/* XXX check for NULL pointers */
	init_trace(appname, 0);
	init_mrt(default_trace);
	init_mrt_reboot(argc, argv);
	init_interfaces (default_trace);

	init_uii(default_trace);
	init_mrtd_config (default_trace);
	set_prompt(strrchr(appname, '/')+1); /* after init_mrtd_config so it sticks */
	init_config(default_trace);

	init_BGP (default_trace);
	init_asExplorerPublisher(default_trace);
	start_publisher_thread(default_trace);
	register_command_handlers();
	register_config_writers();

	config_bgp_init ();
	config_from_file2 (default_trace, config_file);

#ifdef GEN_OLD_FILES
	if (dump_fg) {
	    flapGraphAndTablePublisher_FGDump();
	}

	if (dump_ftd) {
	    if (dump_fg) { /* if we are in dump all mode */
		reinitialize_ixpinfo();
	    }
	    flapGraphAndTablePublisher_FTDDump ();
	}

	if (dump_ase) {
	    asExplorerPublisher_Dump();
	}

	mrt_exit (0);
#else 
	publish_timer_fg = New_Timer (flapGraphAndTablePublisher_doFGUpdate,
		publish_interval_fg, "FlapGraph Update Timer", NULL);
	if (publish_interval_fg > 0) {
		flapGraphAndTablePublisher_doFGUpdate();
		Timer_Turn_ON (publish_timer_fg);
	}

	publish_timer_ftd = New_Timer (flapGraphAndTablePublisher_doFTDUpdate,
		publish_interval_fg, "FlapTableDaily Update Timer", NULL);
	if (publish_interval_ftd > 0) {
		flapGraphAndTablePublisher_doFTDUpdate();
		Timer_Turn_ON (publish_timer_ftd);
	}

	publish_timer_ase = New_Timer (asExplorerPublisher_doUpdate,
		publish_interval_ase, "ASExplorer Update Timer", NULL);
	if (publish_interval_ase > 0) {
		asExplorerPublisher_doUpdate();
		Timer_Turn_ON (publish_timer_ase);
	}
#endif GEN_OLD_FILES
	listen_uii2(port);

	mrt_main_loop();

	/* not reached */

	return 0;				/* just to make gcc happy */
}

void set_interval_fg(uii_connection_t *uii, int num_seconds) {
	if (num_seconds < 0) {
		uii_send_data (uii, "Publish interval must be non-negative.\n");
		return;
	}

	publish_interval_fg = num_seconds;
	
	/* reading config file at startup -- not yet initialized */
	if (publish_timer_fg == NULL)
		return;
		
	if (num_seconds == 0)
		Timer_Turn_OFF (publish_timer_fg);
	else {
		flapGraphAndTablePublisher_doFGUpdate();
		Timer_Set_Time (publish_timer_fg, publish_interval_fg);
		Timer_Reset_Time (publish_timer_fg);			/* necessary? */
		Timer_Turn_ON (publish_timer_fg);
	}
}

void set_interval_ftd(uii_connection_t *uii, int num_seconds) {
	if (num_seconds < 0) {
		uii_send_data (uii, "Publish interval must be non-negative.\n");
		return;
	}

	publish_interval_ftd = num_seconds;
	
	/* reading config file at startup -- not yet initialized */
	if (publish_timer_ftd == NULL)
		return;
		
	if (num_seconds == 0)
		Timer_Turn_OFF (publish_timer_ftd);
	else {
		flapGraphAndTablePublisher_doFTDUpdate();
		Timer_Set_Time (publish_timer_ftd, publish_interval_ftd);
		Timer_Reset_Time (publish_timer_ftd);			/* necessary? */
		Timer_Turn_ON (publish_timer_ftd);
	}
}

void set_interval_ase(uii_connection_t *uii, int num_seconds) {
	if (num_seconds < 0) {
		uii_send_data (uii, "Publish interval must be non-negative.\n");
		return;
	}

	publish_interval_ase = num_seconds;
	
	/* reading config file at startup -- not yet initialized */
	if (publish_timer_ase == NULL)
		return;

	if (num_seconds == 0)
		Timer_Turn_OFF (publish_timer_ase);
	else {
		asExplorerPublisher_doUpdate();
		Timer_Set_Time (publish_timer_ase, publish_interval_ase);
		Timer_Reset_Time (publish_timer_ase);			/* necessary? */
		Timer_Turn_ON (publish_timer_ase);
	}
}

void get_interval_fg(void *ignored) {
	config_add_output (PARAM_FG_PUBLISH_INTERVAL " %d\r\n",
		publish_interval_fg);
}
Пример #6
0
void
main (int argc, char *argv[])
{
    char c, *p, *name = argv[0];
    extern char *optarg;	/* getopt stuff */
    extern int optind;		/* getopt stuff */
    int errors = 0;
    int daemon = 0;
    char *port = "ricd";
    char *rib_file = NULL;

    int kernel_read_flag = 1;
    int kernel_install_flag4 = 1;
    int kernel_install_flag6 = 1;
    int rib_install_flag = 1;

    char *usage = "Usage: %s [-f config_file] [-p uii_port ] [-v] [-n]\n";
    char *config_file = NULL;
    trace_t *default_trace;


    if ((p = strrchr (name, '/')) != NULL) {
	name = p + 1;
    }
    if (strcasecmp (name, "ricd") == 0 ||
        strcasecmp (name, "ricd.purify") == 0) {
	config_file = "/etc/ricd.conf";		/* unix convension */
	daemon = 1;
    }
#ifdef MCHECK
    mcheck (0);
#endif
    default_trace = New_Trace2 ("RICd");
    set_trace (default_trace, TRACE_PREPEND_STRING, "RICD", 0);
    set_trace (default_trace, TRACE_MAX_ERRORS, DEFAULT_MAX_ERRORS, 0);

    /* set_trace (default_trace, TRACE_FLAGS, TR_ALL, 0); */

    while ((c = getopt (argc, argv, "46rhnkvf:p:l:i:")) != -1)
	switch (c) {
	case 'v':		/* verbose */
	    set_trace (default_trace, TRACE_FLAGS, TR_ALL,
		       TRACE_LOGFILE, "stdout",
		       0);
	    daemon = 0;
	    break;
	case 'f':		/* config file */
	    config_file = optarg;
	    break;
	case '4':
	    kernel_install_flag4 = 0;
	    break;
	case '6':
	    kernel_install_flag6 = 0;
	    break;
	case 'n':		/* no kernel installation */
	    kernel_install_flag4 = 0;
	    kernel_install_flag6 = 0;
	    daemon = 0;
	    break;
	case 'k':		/* no kernel read */
	    kernel_read_flag = 0;
	    break;
	case 'r':		/* no rib installation */
	    rib_install_flag = 0;
	    break;
	case 'p':		/* uii port number */
	    port = optarg;
	    break;
	case 'l':		/* load rib on disk (mainly for testing) */
	case 'i':		/* load rib on disk (mainly for testing) */
	    rib_file = optarg;
	    break;
	case 'h':
	default:
	    errors++;
	    break;
	}


    if (errors) {
	fprintf (stderr, usage, name);
	printf ("\nMRT %s compiled on %s\n\n",
		RICD_VERSION, __DATE__);
	exit (1);
    }

#ifdef notdef
    if (getuid ()) {
	fprintf (stderr, "must be root\n");
	exit (1);
    }
#endif

    /* init_trace (name, daemon); */
    init_trace (name, 1);	/* always syslog */
    /* no thread creates here */
    init_mrt (default_trace);
    init_uii (default_trace);
    init_uii_port (port);
    init_mrt_reboot (argc, argv);
    trace (TR_INFO, MRT->trace, "%s compiled on %s started\n",
	   MRT->version, MRT->date);

    if (daemon) {
	/*
	 * Now going into daemon mode 
	 */
	MRT->daemon_mode = 1;
	daemonize ();
    }

    /* read information on all interfaces from the kernel */
    init_interfaces (default_trace);
    init_mrtd_config (default_trace);

    ricd_init (default_trace, AF_INET);
#ifdef HAVE_IPV6
    ricd_init (default_trace, AF_INET6);
#endif /* HAVE_IPV6 */

    set_uii (UII, UII_PROMPT, UII_UNPREV, "Password: "******"RICD> ", 0);

    kernel_init ();		/* open routing socket */

    /*
     * read configuration here
     */

    ricd_init_config ();

    /* default_trace may be modified by debug statement in config file */
    if (config_from_file (default_trace, config_file) < 0) {
	config_create_default ();
    }

/* CONFIGURATION DEPENDENT INITIALIZATION PART */

    ricd_start (AF_INET);
#ifdef HAVE_IPV6
    ricd_start (AF_INET6);
#endif /* HAVE_IPV6 */
    listen_uii2 (NULL);

    if (daemon) {
 	int status = 0;
	if (write (channel[1], &status, sizeof (int)) < 0)
	    perror ("write");
    }

    /* timers never fire until going into loop */
    /* select never fire until going into loop */
    mrt_main_loop ();
    exit (0);
}
Пример #7
0
int main(int argc, char **argv)
{
	mode = IPv4;
	daemon = 1;
	err = stderr;
	portset = 0;
	srand(time(NULL));
	int i;
	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "-f") == 0) {
			daemon = 0;
		} else if (strcmp(argv[i], "-p") == 0) {
			portset = 1;
		} else if (i + 1 < argc && strcmp(argv[i], "--network-interface") == 0) {
			++i;
			strcpy(network_interface_name, argv[i]);
		} else if (i + 1 < argc && strcmp(argv[i], "--encap-mode") == 0) {
			++i;
			if (strcmp(argv[i], "ipv4") == 0) {
				mode = IPv4;
			} else if (strcmp(argv[i], "ipv6") == 0) {
				mode = IPv6;
			} else if (strcmp(argv[i], "dhcpv6") == 0) {
				mode = DHCPv6;
			} else {
				usage();
				exit(0);
			}
		} else if (i + 1 < argc && strcmp(argv[i], "--server-addr") == 0) {
			++i;
			strcpy(server_addr, argv[i]);
		} else if (i + 1 < argc && strcmp(argv[i], "--local-addr") == 0) {
			++i;
			strcpy(local_addr, argv[i]);
		} else {//config-interface
			strcpy(config_interface_name, argv[i]);
		}
	}
	
	if (mode == IPv6) {
		if (strlen(server_addr) == 0) {
			fprintf(err, "server-addr MUST be configured in DHCPv4-over-IPv6 mode!\n");
			exit(0);
		}
		memset(&dest, 0, sizeof(dest));
		dest.sin6_family = AF_INET6;
		//dest.sin6_port = htons(IPv6_SERVER_PORT);
		if (inet_pton(AF_INET6, server_addr, &dest.sin6_addr) < 0) {
			fprintf(err, "Failed to resolve server_addr : %s\n", server_addr);
			exit(1);
		}
		printf("server-addr : %s\n", server_addr);
	}

    if (mode == DHCPv6) {
		memset(&dest, 0, sizeof(dest));
		dest.sin6_family = AF_INET6;
		if (strlen(server_addr) == 0) {
			strcpy(server_addr, "ff02::1:2");
		}
		if (inet_pton(AF_INET6, server_addr, &dest.sin6_addr) < 0) {
			fprintf(err, "Failed to resolve server_addr : %s\n", server_addr);
			exit(1);
		}
	}
	
	if ((mode == IPv6 || mode == DHCPv6) && strlen(local_addr) > 0) {
		memset(&src, 0, sizeof(src));
		src.sin6_family = AF_INET6;
		if (inet_pton(AF_INET6, local_addr, &src.sin6_addr) < 0) {
			fprintf(err, "Failed to resolve local_addr : %s\n", local_addr);
			exit(1);
		}
		printf("local-addr : %s\n", local_addr);
	}

	if (portset)
		printf("port set mode\n");
//	else
//		printf("No Port Set!\n");
	
	if (config_interface_name[0] == '\0') {
		usage();
		exit(0);
	}
	if (network_interface_name[0] == '\0')
		strcpy(network_interface_name, config_interface_name);
	
	init_interfaces();
	init_dhcp();
	if (daemon)
		init_daemon();
		
	while (1) {
		handle_dhcp();
	}
	return 0;
}
Пример #8
0
status_t
init_stack()
{
    status_t status = init_domains();
    if (status != B_OK)
        return status;

    status = init_interfaces();
    if (status != B_OK)
        goto err1;

    status = init_device_interfaces();
    if (status != B_OK)
        goto err2;

    status = init_timers();
    if (status != B_OK)
        goto err3;

    status = init_notifications();
    if (status < B_OK) {
        // If this fails, it just means there won't be any notifications,
        // it's not a fatal error.
        dprintf("networking stack notifications could not be initialized: %s\n",
                strerror(status));
    }

    module_info* dummy;
    status = get_module(NET_SOCKET_MODULE_NAME, &dummy);
    if (status != B_OK)
        goto err4;

    mutex_init(&sChainLock, "net chains");
    mutex_init(&sInitializeChainLock, "net intialize chains");

    sFamilies = hash_init(10, offsetof(struct family, next),
                          &family::Compare, &family::Hash);
    if (sFamilies == NULL) {
        status = B_NO_MEMORY;
        goto err5;
    }

    sProtocolChains = hash_init(10, offsetof(struct chain, next),
                                &chain::Compare, &chain::Hash);
    if (sProtocolChains == NULL) {
        status = B_NO_MEMORY;
        goto err6;
    }

    sDatalinkProtocolChains = hash_init(10, offsetof(struct chain, next),
                                        &chain::Compare, &chain::Hash);
    if (sDatalinkProtocolChains == NULL) {
        status = B_NO_MEMORY;
        goto err7;
    }

    sReceivingProtocolChains = hash_init(10, offsetof(struct chain, next),
                                         &chain::Compare, &chain::Hash);
    if (sReceivingProtocolChains == NULL) {
        status = B_NO_MEMORY;
        goto err8;
    }

    sInitialized = true;

    link_init();
    scan_modules("network/protocols");
    scan_modules("network/datalink_protocols");

    // TODO: for now!
    register_domain_datalink_protocols(AF_INET, IFT_LOOP,
                                       "network/datalink_protocols/loopback_frame/v1", NULL);
    register_domain_datalink_protocols(AF_INET6, IFT_LOOP,
                                       "network/datalink_protocols/loopback_frame/v1", NULL);
    register_domain_datalink_protocols(AF_INET, IFT_ETHER,
                                       "network/datalink_protocols/arp/v1",
                                       "network/datalink_protocols/ethernet_frame/v1",
                                       NULL);
    register_domain_datalink_protocols(AF_INET6, IFT_ETHER,
                                       "network/datalink_protocols/ipv6_datagram/v1",
                                       "network/datalink_protocols/ethernet_frame/v1",
                                       NULL);

    return B_OK;

err8:
    hash_uninit(sDatalinkProtocolChains);
err7:
    hash_uninit(sProtocolChains);
err6:
    hash_uninit(sFamilies);
err5:
    mutex_destroy(&sInitializeChainLock);
    mutex_destroy(&sChainLock);
err4:
    uninit_timers();
err3:
    uninit_device_interfaces();
err2:
    uninit_interfaces();
err1:
    uninit_domains();
    return status;
}