Exemplo n.º 1
0
Arquivo: oor.c Projeto: biels/oor
JNIEXPORT jint JNICALL Java_org_openoverlayrouter_noroot_OOR_1JNI_oor_1start
  (JNIEnv *env, jobject thisObj, jint vpn_tun_fd, jstring storage_path)
{
    oor_dev_type_e dev_type;
    jintArray fd_list;
    uint32_t iseed = 0;  /* initial random number generator */
    pid_t pid = 0;    /* child pid */
    pid_t sid = 0;
    char log_file[1024];
    const char *path = NULL;
    lisp_xtr_t *tunnel_router;
    memset (log_file,0,sizeof(char)*1024);

    initial_setup();
    jni_init(env,thisObj);

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    oor_timers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    lctrl = ctrl_create();

    /* Detect the data plane type */
    data_plane_select();

    /** parse config and create ctrl_dev **/
    /* obtain the configuration file */
    path = (*env)->GetStringUTFChars(env, storage_path, 0);
    config_file = calloc(1024, sizeof(char));
    strcat(config_file,path);
    strcat(config_file,"oor.conf");
    strcat(log_file,path);
    strcat(log_file,"oor.log");
    (*env)->ReleaseStringUTFChars(env, storage_path, path);
    open_log_file(log_file);
    if (parse_config_file()!=GOOD){
        exit_cleanup();
        close(vpn_tun_fd);
        return (BAD);
    }
    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        OOR_LOG(LDBG_2, "Configuring data plane");
        tunnel_router = CONTAINER_OF(ctrl_dev, lisp_xtr_t, super);
        data_plane->datap_init(dev_type, tr_get_encap_type(tunnel_router), vpn_tun_fd);
        OOR_LOG(LDBG_1, "Data plane initialized");

    }
    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
     if (!ctrl_dev) {
         OOR_LOG(LDBG_1, "device NULL");
         return (BAD);
     }
     return (GOOD);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int arg = -1;
	struct nl_handle *nhandle;

	while (-1 != (arg = getopt(argc, argv, "h")))
	{
		switch (arg)
		{
			case 'h':
				show_usage();
				return 0;
			default:
				printf("option %c is invalid, ignored!\n", optopt);
				return 0;
		}
	}

	nhandle = init_netlink();
	if(!nhandle)
		return 1;
	dlog("running ... \n");

	run(nhandle);
	nl_handle_destroy(nhandle);

	return 0;
}
Exemplo n.º 3
0
gint
main (void)
{
	gboolean ret;
	GSocket *gsocket = NULL;
	int socket_fd = 0;
	GSocketAddress *address = NULL;
	GError *error = NULL;
	gsize wrote;
	GSource *source;
	GMainLoop *loop;
	struct sockaddr_nl my_nla;
	struct nlmsghdr *nl_hdr;
	char buff[BUFF_SIZE];
	struct cn_msg *cn_hdr;
	enum proc_cn_mcast_op *mcop_msg;

	g_type_init ();
	loop = g_main_loop_new (NULL, FALSE);

	init_netlink(loop);

	g_debug ("running main loop");
	g_main_loop_run (loop);
out:
	if (loop != NULL)
		g_main_loop_unref (loop);
	if (socket != NULL)
		g_object_unref (socket);
	if (address != NULL)
		g_object_unref (address);
	return 0;
}
Exemplo n.º 4
0
int __init ecc_init(void) {
	// init netlink
	init_netlink();
	init_sqr_table();
	
	return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	dhcpctl_handle conn = NULL;
	char *conffile=NULL;
	char ch;
	
	name = strdup("OMAPI");
	    
	openlog("dhcparpd", LOG_PID, LOG_DAEMON);

	/* Parse Commandline Options */
	while((ch = getopt(argc, argv, "c:dh")) != -1) {
		switch(ch){
			case 'c':
				conffile = strdup(optarg);
				break;
			case 'd':
				do_daemonise=0;
				break;
			case 'h':
				usage(argv[0]);
				return 0;
			default:
				fprintf(stderr, "Unknown option '%c'!", ch);
				usage(argv[0]);
				return 1;
		}
	}

	/* Try a default configfile if non specified */
	if (conffile==NULL) {
		conffile = strdup("/etc/dhcparpd.conf");
	}
	if (parse_config(config,conffile)) {
		fprintf(stderr,"Unable to parse configfile: %s\n", 
				conffile);
		return 1;
	}
	free(conffile);

	/* Daemonise */
	if (do_daemonise) {
		daemonise(argv[0]);
		put_pid(pidfile);
	}
	
	parse_mappings();

	conn = dhcpd_connect(servername, port, name, key);

	if (!conn) {
		Log(LOG_CRIT, "failed to connect to dhcp server");
		return 1;
	}

	arp_init(interface,conn);

	init_event();
	init_netlink();

	if (pcap_init(interface))
		return 1;

        Log(LOG_NOTICE, "Ready for action! Lets Go...");
	run();

	return 0;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	pid_t pid;
	/* Reset signal handlers */
	if (daemon_reset_sigs(-1) < 0) {
		daemon_log(LOG_ERR, "Failed to reset all signal handlers: %s",
			strerror(errno));
		return 1;
	}
	/* Unblock signals */
	if (daemon_unblock_sigs(-1) < 0) {
		daemon_log(LOG_ERR, "Failed to unblock all signals: %s",
			strerror(errno));
	}
	/* Set indetification string for the daemon for both syslog and PID file */
	daemon_log_ident = daemon_ident_from_argv0(argv[0]);
	daemon_pid_file_ident = daemon_log_ident;
	//(LOG_ERR, "The log ident is %s\n",daemon_log_ident);
	daemon_pid_file_proc = get_pid_file_proc;
	sprintf (image_pid_file, "/var/run/%s.pid", daemon_pid_file_ident);
	/* Check if we are called with -k parameter */
	if (argc >= 2 && !strcmp(argv[1], "-k")) {
		int ret;
		/* Kill daemon with SIGTERM */
		/* Check if the new function daemon_pid_file_kill_wait() is available,
			if it is, use it. */
		if ((ret = daemon_pid_file_kill_wait(SIGTERM, 5)) < 0)
			daemon_log(LOG_WARNING, "Failed to kill daemon: %s",
				strerror(errno));
		return ret < 0 ? 1 : 0;
	}
	/* Check that the daemon is not rung twice a the same time */
	if ((pid = daemon_pid_file_is_running()) >= 0) {
		daemon_log(LOG_ERR, "Daemon already running on PID file %u", pid);
		return 1;
	}
	/* Prepare for return value passing from the initialization procedure
		of the daemon process */
	if (daemon_retval_init() < 0) {
		daemon_log(LOG_ERR, "Failed to create pipe.");
		return 1;
	}
	/* Do the fork */
	if ((pid = daemon_fork()) < 0) {
		/* Exit on error */
		daemon_retval_done();
		return 1;
	} else if (pid) {  /* The parent */
		int ret;
		/* Wait for 20 seconds for the return value passed from the daemon
			process */
		if ((ret = daemon_retval_wait(20)) < 0) {
			daemon_log(LOG_ERR, "Count not receive return value from daemon"
				"process: %s", strerror(errno));
		}
		//daemon_log(ret != 0 ? LOG_ERR : LOG_INFO,
		//	"Daemon returned %i as return value.", ret);
		return ret;
	} else {  /* The daemon */
		int fd, quit = 0;
		fd_set fds;
		pthread_t sock_thread;
		pthread_t nl_thread;
		/* Close FDs */
		if (daemon_close_all(-1) < 0) {
			daemon_log(LOG_ERR, "Failed to close all file descriptors: %s",
				strerror(errno));
			/* Send the error condition to the parent process */
			daemon_retval_send(1);
			goto finish;
		}
		/* Create the PID file */
		if (daemon_pid_file_create() < 0) {
			daemon_log(LOG_ERR, "Could not create PID file (%s).",
				strerror(errno));
			daemon_retval_send(2);
			goto finish;
		}
		/* Initialize signal handling */
		if (daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, 0) < 0) {
			daemon_log(LOG_ERR, "Could not register signal handlers (%s).",
				strerror(errno));
			daemon_retval_send(3);
			goto finish;
		}
		/* Init task */
		init_image_config(argc, argv);
		init_netlink();
		/* Send OK to parent process */
		daemon_retval_send(0);
		daemon_log(LOG_INFO, "Sucessfully started");
		/* Main task*/
		pthread_create(&nl_thread, NULL, (void *)netlink_loop, (void *)NULL);
		#if 0
		pthread_create(&sock_thread, NULL, (void *)socket_loop, (void *)NULL);
		#endif
		pthread_create(&sock_thread, NULL, (void *)mq_loop, (void *)NULL);
		/* Prepare for select() on the signal fd */
		FD_ZERO(&fds);
		fd = daemon_signal_fd();
		FD_SET(fd, &fds);
		while (!quit) {
			fd_set fds2 = fds;
			/* Wait for an incoming signal */
			if (select(FD_SETSIZE, &fds2, 0, 0, 0) < 0) {
				/* If we've been interrupted by an incoming signal, continue */
				if (errno == EINTR)
					continue;
				daemon_log(LOG_ERR, "select(): %s", strerror(errno));
				break;
			}
			/* Check if a signal has been recieved */
			if (FD_ISSET(fd, &fds2)) {
				int sig;
				/* Get signal */
				if ((sig = daemon_signal_next()) <= 0) {
					daemon_log(LOG_ERR, "daemon_signal_next() failed: %s",
						strerror(errno));
					break;
				}
				/* Dispatch signal */
				switch (sig) {
					case SIGINT:
					case SIGQUIT:
					case SIGTERM:
						daemon_log(LOG_WARNING, "Got SIGINT, SIGQUIT or"
							"SIGTERM.");
						if (nl_image_config.nl_connected == 1) {
							nl_image_config.nl_connected = 0;
							if (nl_send_image_session_cmd(
								IMAGE_SESSION_CMD_DISCONNECT) < 0) {
								printf("Failed to remove connection with"
									"kernel!\n");
							}
						}
						quit = 1;
						break;
					case SIGHUP:
						daemon_log(LOG_INFO, "Got a HUP");
						daemon_exec("/", NULL, "/bin/ls", "ls", (char*) NULL);
						break;
				}
			}
		}
		/* Do a cleanup */
finish:
		delete_pid_file(IMAGE_SERVER_PROC);
		daemon_log(LOG_INFO, "Exiting...");
		daemon_retval_send(255);
		daemon_signal_done();
		daemon_pid_file_remove();
		return 0;
	}
}
Exemplo n.º 7
0
int init_module()
{
	init_netlink();
	return 0;
}
Exemplo n.º 8
0
Arquivo: oor.c Projeto: biels/oor
int
main(int argc, char **argv)
{
    oor_dev_type_e dev_type;
    lisp_xtr_t *tunnel_router;

    initial_setup();

    handle_oor_command_line(argc, argv);

    /* see if we need to daemonize, and if so, do it */
    demonize_start();

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    oor_timers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    if ((lctrl = ctrl_create())==NULL){
        exit_cleanup();
    }

    /* Detect the data plane type */
    data_plane_select();

    /* parse config and create ctrl_dev */
    if (parse_config_file() != GOOD){
        exit_cleanup();
    }


    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        OOR_LOG(LDBG_2, "Configuring data plane");
        tunnel_router = CONTAINER_OF(ctrl_dev, lisp_xtr_t, super);
        if (data_plane->datap_init(dev_type,tr_get_encap_type(tunnel_router))!=GOOD){
            exit_cleanup();
        }
        OOR_LOG(LDBG_1, "Data plane initialized");
    }

    /* The control should be initialized after data plane */
    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
    if (!ctrl_dev) {
        OOR_LOG(LDBG_1, "device NULL");
        exit(0);
    }

    ctrl_dev_run(ctrl_dev);

    OOR_LOG(LINF,"\n\n Open Overlay Router (%s): started... \n\n",OOR_VERSION);

#ifndef ANDROID
    /* Initialize API for external access */
    oor_api_init_server(&oor_api_connection);

    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
        oor_api_loop(&oor_api_connection);
    }
#else
    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
    }
#endif

    /* event_loop returned: bad! */
    OOR_LOG(LINF, "Exiting...");
    exit_cleanup();
    return(0);
}
Exemplo n.º 9
0
int init_module(void)
{
	printk(KERN_INFO "Network Kernel/User communications module 0.03\n");
	return init_netlink();
}
Exemplo n.º 10
0
JNIEXPORT jint JNICALL Java_org_lispmob_noroot_LISPmob_1JNI_startLispd
  (JNIEnv *env, jobject thisObj, jint vpn_tun_fd, jstring storage_path)
{
    lisp_dev_type_e dev_type;
    jintArray fd_list;
    uint32_t iseed = 0;  /* initial random number generator */
    pid_t pid = 0;    /* child pid */
    pid_t sid = 0;
    char log_file[1024];
    const char *path = NULL;

    memset (log_file,0,sizeof(char)*1024);


    initial_setup();
    jni_init(env,thisObj);

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    lmtimers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    lctrl = ctrl_create();

    /* Detect the data plane type */
    data_plane_select();

    /** parse config and create ctrl_dev **/

    /* obtain the configuration file */
    path = (*env)->GetStringUTFChars(env, storage_path, 0);
    config_file = calloc(1024, sizeof(char));
    strcat(config_file,path);
    strcat(config_file,"lispd.conf");
    strcat(log_file,path);
    strcat(log_file,"lispd.log");
    (*env)->ReleaseStringUTFChars(env, storage_path, path);
    open_log_file(log_file);

    if (parse_config_file()!=GOOD){
        exit_cleanup();
        return (BAD);
    }

    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        data_plane->datap_init(dev_type, vpn_tun_fd);
    }

    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
     if (!ctrl_dev) {
         LMLOG(LDBG_1, "device NULL");
         return (BAD);
     }

     return (GOOD);
}
Exemplo n.º 11
0
int
main(int argc, char **argv)
{
    lisp_dev_type_e dev_type;

    initial_setup();

    handle_lispd_command_line(argc, argv);

    /* see if we need to daemonize, and if so, do it */
    demonize_start();

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    lmtimers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    if ((lctrl = ctrl_create())==NULL){
        exit_cleanup();
    }

    /* Detect the data plane type */
    data_plane_select();

    /* parse config and create ctrl_dev */
    if (parse_config_file() != GOOD){
        exit_cleanup();
    }


    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        data_plane->datap_init(dev_type);
    }

    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
    if (!ctrl_dev) {
        LMLOG(LDBG_1, "device NULL");
        exit(0);
    }
    ctrl_dev_run(ctrl_dev);

    LMLOG(LINF,"\n\n LISPmob (%s): 'lispd' started... \n\n",LISPD_VERSION);

#ifndef ANDROID
    /* Initialize API for external access */
    lmapi_init_server(&lmapi_connection);

    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
        lmapi_loop(&lmapi_connection);
    }
#else
    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
    }
#endif



    /* EVENT LOOP */
    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
#ifndef ANDROID
        lmapi_loop(&lmapi_connection);
#endif
    }

    /* event_loop returned: bad! */
    LMLOG(LINF, "Exiting...");
    exit_cleanup();
    return(0);
}