int main() { // (void)smart_link_log_type_set(0xff); sl_master = thread_master_create (); if (0 != smart_link_db_init()) { smart_link_log_error("Smart-link data-base init failed.\n"); return -1; } if (0 != smart_link_app_event_init()) { smart_link_log_error("Smart-link app event init failed.\n"); return -1; } if (0 != smart_link_app_msg_sock_init()) { smart_link_log_error("Smart-link msg socket init failed.\n"); return -1; } if (0 != smart_link_packet_socket_init()) { smart_link_log_error("Smart-link socket init failed.\n"); return -1; } if (0 != smart_link_dbus_sock_init()) { smart_link_log_error("Smart-link socket init failed.\n"); return -1; } if (0 != smart_link_sysmac_init()) { smart_link_log_error("Smart-link get system MAC failed.\n"); } app_module_inst_set("smart-link", getpid()); // (void)smart_link_log_type_unset(0xff); smart_link_master(); smart_link_log_error("Game Over!\n"); thread_master_free(sl_master); return 0; }
int main (int argc, char **argv) { (void) argv; (void) argc; int32_t ret = ERROR_SUCCESS; cfc_show_status_info_t cfc_flux_info; struct thread thread; master = thread_master_create (); cmd_init (1); vty_init (); cfc_vty_init (); daemon (0,1); vty_set_vrf_info(); vty_serv_sock (0, 0, CFC_VTYSH_PATH); if(ERR_FILE_OPEN == cfc_get_config(&cfc_flux_info)) { ret = ERR_FILE_OPEN; goto label_ret; } if(CFC_MODULE_ACTIVE == cfc_flux_info.module_stat) { cfc_cf_set_tot_flux(cfc_flux_info.tot_flux); } if(ERR_FILE_OPEN == cfc_get_limit_config()) { ret = ERR_FILE_OPEN; } cfc_cf_set_privatenet(); while(thread_fetch (master, &thread)) { thread_call (&thread); } label_ret: return ret; }
int main (void) { struct peer *peer; int i, j; conf_bgp_debug_fsm = -1UL; conf_bgp_debug_events = -1UL; conf_bgp_debug_packet = -1UL; conf_bgp_debug_normal = -1UL; conf_bgp_debug_as4 = -1UL; term_bgp_debug_fsm = -1UL; term_bgp_debug_events = -1UL; term_bgp_debug_packet = -1UL; term_bgp_debug_normal = -1UL; term_bgp_debug_as4 = -1UL; master = thread_master_create (); bgp_master_init (); if (fileno (stdout) >= 0) tty = isatty (fileno (stdout)); if (bgp_get (&bgp, &asn, NULL)) return -1; peer = peer_create_accept (bgp); peer->host = "foo"; for (i = AFI_IP; i < AFI_MAX; i++) for (j = SAFI_UNICAST; j < SAFI_MAX; j++) { peer->afc[i][j] = 1; peer->afc_adv[i][j] = 1; } i = 0; while (mp_reach_segments[i].name) parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI); i = 0; while (mp_unreach_segments[i].name) parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI); printf ("failures: %d\n", failed); return failed; }
int main (void) { master = thread_master_create (); signal_init (master, array_size(sigs), sigs); zlog_default = openzlog("testsig", ZLOG_NONE, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); while (thread_fetch (master, &t)) thread_call (&t); exit (0); }
/* basic parsing test */ static void parse_test (struct peer *peer, struct test_segment *t, int type) { int parse_ret = 0, nlri_ret = 0; struct attr attr = { }; struct bgp_nlri nlri = { }; struct bgp_attr_parser_args attr_args = { .peer = peer, .length = t->len, .total = 1, .attr = &attr, .type = type, .flags = BGP_ATTR_FLAG_OPTIONAL, .startp = BGP_INPUT_PNT (peer), }; #define RANDOM_FUZZ 35 stream_reset (peer->ibuf); stream_put (peer->ibuf, NULL, RANDOM_FUZZ); stream_set_getp (peer->ibuf, RANDOM_FUZZ); stream_write (peer->ibuf, t->data, t->len); printf ("%s: %s\n", t->name, t->desc); if (type == BGP_ATTR_MP_REACH_NLRI) parse_ret = bgp_mp_reach_parse (&attr_args, &nlri); else parse_ret = bgp_mp_unreach_parse (&attr_args, &nlri); if (parse_ret == 0 && t->afi_valid == VALID_AFI) assert (nlri.afi == t->afi && nlri.safi == t->safi); if (!parse_ret) { if (type == BGP_ATTR_MP_REACH_NLRI) nlri_ret = bgp_nlri_parse (peer, &attr, &nlri); else nlri_ret = bgp_nlri_parse (peer, NULL, &nlri); } handle_result (peer, t, parse_ret, nlri_ret); } static struct bgp *bgp; static as_t asn = 100; int main (void) { struct peer *peer; int i, j; conf_bgp_debug_fsm = -1UL; conf_bgp_debug_events = -1UL; conf_bgp_debug_packet = -1UL; conf_bgp_debug_normal = -1UL; conf_bgp_debug_as4 = -1UL; term_bgp_debug_fsm = -1UL; term_bgp_debug_events = -1UL; term_bgp_debug_packet = -1UL; term_bgp_debug_normal = -1UL; term_bgp_debug_as4 = -1UL; master = thread_master_create (); bgp_master_init (); bgp_option_set (BGP_OPT_NO_LISTEN); bgp_attr_init (); bgp_address_init (); if (fileno (stdout) >= 0) tty = isatty (fileno (stdout)); if (bgp_get (&bgp, &asn, NULL)) return -1; peer = peer_create_accept (bgp); peer->host = (char *)"foo"; peer->status = Established; for (i = AFI_IP; i < AFI_MAX; i++) for (j = SAFI_UNICAST; j < SAFI_MAX; j++) { peer->afc[i][j] = 1; peer->afc_adv[i][j] = 1; } i = 0; while (mp_reach_segments[i].name) parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI); i = 0; while (mp_unreach_segments[i].name) parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI); printf ("failures: %d\n", failed); return failed; }
int main(void) { int ret=0; struct thread thread; int sock; pthread_t packet_thread_id; rte_backtrace_init(); if(!access(SHOW_PACKET_FLILE, F_OK)){ // file exist, will show packet vsecplat_show_packet = 1; } if(!access(SHOW_RECORD_FLILE, F_OK)){ // file exist, will show packet vsecplat_show_record = 1; } ret = nm_log_init(); if(ret<0){ printf("failed to init log.\n"); return -1; } ret = init_disp_type(); if(ret<0){ printf("failed to init disp type array.\n"); return -1; } // parse configfile and init global descriptor: global_vsecplat_config ret = parse_vsecplat_config(); if(ret<0){ printf("Failed to parse vsecplat config.\n"); return -1; } ret = init_recurs_dst_mac_list(); if(ret<0){ printf("Failed to init recursive dstmac list.\n"); return -1; } // Init forward policy desc: fw_policy_list ret = init_policy_list(); if(ret<0){ printf("Failed to init policy descriptor.\n"); return -1; } // init global interface list: vsecplat_interface_list ret = init_vsecplat_interface_list(); if(ret<0){ printf("Failed to get interface.\n"); return -1; } #if 1 // Disable to test function on host // setup mgt interface ip address and set it to up ret = setup_mgt_interface(); if(ret<0){ printf("Failed to setup mgt interface.\n"); return -1; } #endif // set dataplane interface to netmap mode ret = setup_dp_interfaces(); if(ret<0){ printf("Failed to setup dataplane interface.\n"); return -1; } // init connection descriptor: conn_desc ret = init_conn_desc(); if(ret<0){ printf("Failed to init vsecplat status.\n"); return -1; } // init record bucket: record_bucket_hash ret = vsecplat_init_record_bucket(); if(ret<0){ printf("Failed to init record bucket.\n"); return -1; } ret = vsecplat_load_duplicate_rule(); if(ret<0){ printf("Failed to load duplicate rules.\n"); return -1; } ret = vsecplat_load_policy(); if(ret<0){ printf("Failed to load policy.\n"); return -1; } #if 0// For test test_packet_match_policy(); vsecplat_test_record(); packet_handle_thread(NULL); #endif #if 1 /* 创建处理数据包的线程 */ ret = pthread_create(&packet_thread_id, NULL, &packet_handle_thread, NULL); if(ret<0){ nm_log("failed to create packet thread.\n"); return -1; } #endif #if 1 // manage thread master = thread_master_create(); if(NULL==master){ nm_log("failed to alloc master.\n"); return -1; } /* 报告统计数据的线程 */ nm_log("Add report stats thread.\n"); thread_add_timer(master, vsecplat_report_stats, NULL, global_vsecplat_config->time_interval); sock = create_listen_socket(); if(sock<0){ nm_log("failed to create socket.\n"); return -1; } thread_add_read(master, vsecplat_listen_func, NULL, sock); memset(&thread, 0, sizeof(struct thread)); while(thread_fetch(master, &thread)){ thread_call(&thread); } #endif return 0; }
/* Main startup routine. */ int main (int argc, char **argv) { char *p; char *vty_addr = NULL; int vty_port = ZEBRA_VTY_PORT; int dryrun = 0; int batch_mode = 0; int daemon_mode = 0; char *config_file = NULL; char *progname; struct thread thread; char *zserv_path = NULL; /* Set umask before anything for security */ umask (0027); /* preserve my name */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); zlog_default = openzlog (progname, ZLOG_ZEBRA, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); while (1) { int opt; #ifdef HAVE_NETLINK opt = getopt_long (argc, argv, "bdkf:i:z:hA:P:ru:g:vs:C", longopts, 0); #else opt = getopt_long (argc, argv, "bdkf:i:z:hA:P:ru:g:vC", longopts, 0); #endif /* HAVE_NETLINK */ if (opt == EOF) break; switch (opt) { case 0: break; case 'b': batch_mode = 1; case 'd': daemon_mode = 1; break; case 'k': keep_kernel_mode = 1; break; case 'C': dryrun = 1; break; case 'f': config_file = optarg; break; case 'A': vty_addr = optarg; break; case 'i': pid_file = optarg; break; case 'z': zserv_path = optarg; break; case 'P': /* Deal with atoi() returning 0 on failure, and zebra not listening on zebra port... */ if (strcmp(optarg, "0") == 0) { vty_port = 0; break; } vty_port = atoi (optarg); if (vty_port <= 0 || vty_port > 0xffff) vty_port = ZEBRA_VTY_PORT; break; case 'r': retain_mode = 1; break; #ifdef HAVE_NETLINK case 's': nl_rcvbufsize = atoi (optarg); break; #endif /* HAVE_NETLINK */ case 'u': zserv_privs.user = optarg; break; case 'g': zserv_privs.group = optarg; break; case 'v': print_version (progname); exit (0); break; case 'h': usage (progname, 0); break; default: usage (progname, 1); break; } } /* Make master thread emulator. */ zebrad.master = thread_master_create (); /* privs initialise */ zprivs_init (&zserv_privs); /* Vty related initialize. */ signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals); cmd_init (1); vty_init (zebrad.master); memory_init (); /* Zebra related initialize. */ zebra_init (); rib_init (); zebra_if_init (); zebra_debug_init (); router_id_init(); zebra_vty_init (); access_list_init (); prefix_list_init (); rtadv_init (); #ifdef HAVE_IRDP irdp_init(); #endif /* For debug purpose. */ /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ /* Make kernel routing socket. */ kernel_init (); interface_list (); route_read (); /* Sort VTY commands. */ sort_node (); #ifdef HAVE_SNMP zebra_snmp_init (); #endif /* HAVE_SNMP */ /* Process the configuration file. Among other configuration * directives we can meet those installing static routes. Such * requests will not be executed immediately, but queued in * zebra->ribq structure until we enter the main execution loop. * The notifications from kernel will show originating PID equal * to that after daemon() completes (if ever called). */ vty_read_config (config_file, config_default); /* Don't start execution if we are in dry-run mode */ if (dryrun) return(0); /* Clean up rib. */ rib_weed_tables (); /* Exit when zebra is working in batch mode. */ if (batch_mode) exit (0); /* Daemonize. */ if (daemon_mode && daemon (0, 0) < 0) { zlog_err("Zebra daemon failed: %s", strerror(errno)); exit (1); } /* Output pid of zebra. */ pid_output (pid_file); /* After we have successfully acquired the pidfile, we can be sure * about being the only copy of zebra process, which is submitting * changes to the FIB. * Clean up zebra-originated routes. The requests will be sent to OS * immediately, so originating PID in notifications from kernel * will be equal to the current getpid(). To know about such routes, * we have to have route_read() called before. */ if (! keep_kernel_mode) rib_sweep_route (); /* Needed for BSD routing socket. */ pid = getpid (); /* This must be done only after locking pidfile (bug #403). */ zebra_zserv_socket_init (zserv_path); /* Make vty server socket. */ vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH); /* Print banner. */ zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION, vty_port); while (thread_fetch (zebrad.master, &thread)) thread_call (&thread); /* Not reached... */ return 0; }
int main (int argc, char *argv[]) { struct thread thread; args = argv; /* ospfclient should be started with the following arguments: * * (1) host (2) lsa_type (3) opaque_type (4) opaque_id (5) if_addr * (6) area_id * * host: name or IP of host where ospfd is running * lsa_type: 9, 10, or 11 * opaque_type: 0-255 (e.g., experimental applications use > 128) * opaque_id: arbitrary application instance (24 bits) * if_addr: interface IP address (for type 9) otherwise ignored * area_id: area in IP address format (for type 10) otherwise ignored */ if (argc != 7) { usage(); } /* Initialization */ zprivs_init (&ospfd_privs); master = thread_master_create (); /* Open connection to OSPF daemon */ oclient = ospf_apiclient_connect (args[1], ASYNCPORT); if (!oclient) { printf ("Connecting to OSPF daemon on %s failed!\n", args[1]); exit (1); } /* Register callback functions. */ ospf_apiclient_register_callback (oclient, ready_callback, new_if_callback, del_if_callback, ism_change_callback, nsm_change_callback, lsa_update_callback, lsa_delete_callback); /* Register LSA type and opaque type. */ ospf_apiclient_register_opaque_type (oclient, atoi (args[2]), atoi (args[3])); /* Synchronize database with OSPF daemon. */ ospf_apiclient_sync_lsdb (oclient); /* Schedule thread that handles asynchronous messages */ thread_add_read (master, lsa_read, oclient, oclient->fd_async); /* Now connection is established, run loop */ while (1) { thread_fetch (master, &thread); thread_call (&thread); } /* Never reached */ return 0; }
void skinny_isis_daemon() { char errbuf[PCAP_ERRBUF_SIZE]; struct pcap_device device; struct pcap_isis_callback_data cb_data; struct host_addr addr; struct prefix_ipv4 *ipv4; int index, ret; char area_tag[] = "default"; struct isis_area *area; struct isis_circuit *circuit; struct interface interface; memset(&device, 0, sizeof(struct pcap_device)); memset(&cb_data, 0, sizeof(cb_data)); memset(&interface, 0, sizeof(interface)); memset(&isis_spf_deadline, 0, sizeof(isis_spf_deadline)); /* initializing IS-IS structures */ isis_init(); dyn_cache_init(); /* thread master */ master = thread_master_create(); if (!config.nfacctd_isis_iface) { Log(LOG_ERR, "ERROR ( default/core/ISIS ): 'isis_daemon_iface' value is not specified. Terminating thread.\n"); exit(1); } if ((device.dev_desc = pcap_open_live(config.nfacctd_isis_iface, 65535, 0, 1000, errbuf)) == NULL) { Log(LOG_ERR, "ERROR ( default/core/ISIS ): pcap_open_live(): %s\n", errbuf); exit(1); } device.link_type = pcap_datalink(device.dev_desc); for (index = 0; _isis_devices[index].link_type != -1; index++) { if (device.link_type == _isis_devices[index].link_type) device.data = &_isis_devices[index]; } if (device.data == NULL) { Log(LOG_ERR, "ERROR ( default/core/ISIS ): data link not supported: %d\n", device.link_type); return; } else { Log(LOG_INFO, "OK ( default/core/ISIS ): link type is: %d\n", device.link_type); cb_data.device = &device; } area = isis_area_create(); area->area_tag = area_tag; area->is_type = IS_LEVEL_2; area->newmetric = TRUE; listnode_add(isis->area_list, area); Log(LOG_DEBUG, "DEBUG ( default/core/ISIS ): New IS-IS area instance %s\n", area->area_tag); if (config.nfacctd_isis_net) area_net_title(area, config.nfacctd_isis_net); else { Log(LOG_ERR, "ERROR ( default/core/ISIS ): 'isis_daemon_net' value is not specified. Terminating thread.\n"); exit_all(1); } circuit = isis_circuit_new(); circuit->circ_type = CIRCUIT_T_P2P; circuit->fd = pcap_fileno(device.dev_desc); circuit->tx = isis_send_pdu_p2p; circuit->interface = &interface; circuit->state = C_STATE_UP; if (config.nfacctd_isis_ip) { trim_spaces(config.nfacctd_isis_ip); ret = str_to_addr(config.nfacctd_isis_ip, &addr); if (!ret) { Log(LOG_ERR, "ERROR ( default/core/ISIS ): 'isis_daemon_ip' value is not a valid IPv4/IPv6 address. Terminating thread.\n"); exit_all(1); } } else { Log(LOG_ERR, "ERROR ( default/core/ISIS ): 'isis_daemon_ip' value is not specified. Terminating thread.\n"); exit_all(1); } circuit->ip_router = addr.address.ipv4.s_addr; ipv4 = isis_prefix_ipv4_new(); ipv4->prefixlen = 32; ipv4->prefix.s_addr = addr.address.ipv4.s_addr; circuit->ip_addrs = list_new(); listnode_add(circuit->ip_addrs, ipv4); circuit_update_nlpids(circuit); isis_circuit_configure(circuit, area); cb_data.circuit = circuit; area->ip_circuits = 1; memcpy(circuit->interface->name, config.nfacctd_isis_iface, strlen(config.nfacctd_isis_iface)); circuit->interface->ifindex = if_nametoindex(config.nfacctd_isis_iface); if (!config.nfacctd_isis_mtu) config.nfacctd_isis_mtu = SNAPLEN_ISIS_DEFAULT; for (;;) { /* XXX: should get a select() here at some stage? */ pcap_loop(device.dev_desc, -1, isis_pdu_runner, (u_char *) &cb_data); break; } pcap_close(device.dev_desc); }
/* Main startup routine. */ int rtm_init (int argc, char **argv) { char *p; char *vty_addr = NULL; int vty_port = ZEBRA_VTY_PORT; int dryrun = 0; int batch_mode = 0; int daemon_mode = 0; char *config_file = NULL; char *progname; struct thread thread; char *zserv_path = NULL; /* Set umask before anything for security */ umask (0027); /* preserve my name */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); zlog_default = openzlog (progname, ZLOG_ZEBRA, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); /* Make master thread emulator. */ zebrad.master = thread_master_create (); /* privs initialise */ zprivs_init (&zserv_privs); /* Vty related initialize. */ signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals); #if 0 /* * All CLI command registrations commented out */ cmd_init (1); vty_init (zebrad.master); memory_init (); zebra_init (); zebra_if_init (); zebra_vty_init (); /* Sort VTY commands. */ sort_node (); #endif /* Zebra related initialize. */ rib_init (); zebra_debug_init (); router_id_init(); access_list_init (); prefix_list_init (); rtadv_init (); #ifdef HAVE_IRDP irdp_init(); #endif /* For debug purpose. */ /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ #if 0 /* * The Kernel FIB Interface is no longer needed */ /* Make kernel routing socket. */ kernel_init (); interface_list (); route_read (); #endif #ifdef HAVE_SNMP zebra_snmp_init (); #endif /* HAVE_SNMP */ /* Process the configuration file. Among other configuration * directives we can meet those installing static routes. Such * requests will not be executed immediately, but queued in * zebra->ribq structure until we enter the main execution loop. * The notifications from kernel will show originating PID equal * to that after daemon() completes (if ever called). */ vty_read_config (config_file, config_default); /* Don't start execution if we are in dry-run mode */ if (dryrun) return(0); /* Clean up rib. */ rib_weed_tables (); /* Exit when zebra is working in batch mode. */ if (batch_mode) exit (0); #if 0 /* Daemonize. */ if (daemon_mode && daemon (0, 0) < 0) { zlog_err("Zebra daemon failed: %s", strerror(errno)); exit (1); } /* Output pid of zebra. */ pid_output (pid_file); #endif /* After we have successfully acquired the pidfile, we can be sure * about being the only copy of zebra process, which is submitting * changes to the FIB. * Clean up zebra-originated routes. The requests will be sent to OS * immediately, so originating PID in notifications from kernel * will be equal to the current getpid(). To know about such routes, * we have to have route_read() called before. */ if (! keep_kernel_mode) rib_sweep_route (); #if 0 /* Needed for BSD routing socket. */ pid = getpid (); /* This must be done only after locking pidfile (bug #403). */ zebra_zserv_socket_init (zserv_path); /* Make vty server socket. */ vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH); #endif /* Print banner. */ zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION, vty_port); while (thread_fetch (zebrad.master, &thread)) thread_call (&thread); /* Not reached... */ return 0; }
int main(int argc, char *argv[]) { int opt; char * config_file = "/etc/zebralite/ospf6_sibling.conf"; char * sisis_addr; struct in6_addr * sibling_addr; struct list * replicas; struct vconn * vconn; int retval; struct rfpbuf * buffer; struct thread thread; struct in6_addr * ctrl_addr; int sisis_fd; uint64_t host_num = 1; bool restart_mode = false; struct sigaction sa; /* Command line argument treatment. */ while(1) { opt = getopt_long(argc, argv, "rf:", longopts, 0); if(opt == EOF) break; switch(opt) { case 'f': config_file = optarg; break; case 'r': restart_mode = true; break; } } zlog_default = openzlog(argv[0], ZLOG_OSPF6_SIBLING, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); cmd_init(1); vty_init(master); ospf6_sibling_debug_init(); // signal_init - use sigaction sa.sa_handler = terminate; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGABRT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); /* thread master */ master = thread_master_create(); /* initialize ospf6 */ ospf6_top_init(restart_mode); ospf6_area_init(); sisis_addr = calloc(INET6_ADDRSTRLEN, sizeof(char)); if((sisis_fd = sisis_init(sisis_addr, host_num, SISIS_PTYPE_OSPF6_SBLING) < 0)) { printf("sisis_init error\n"); exit(1); } sibling_addr = calloc(1, sizeof(struct in6_addr)); inet_pton(AF_INET6, sisis_addr, sibling_addr); replicas = get_ospf6_sibling_addrs(); ospf6_replicas_init(sibling_addr, replicas); // init ctrl clients and restart msg queue sibling_ctrl_init(); // this is where the command actually gets executed vty_read_config(config_file, config_default); if(restart_mode) { zlog_notice("<---- OSPF6 Sibling starting in restart mode: %d ---->", getpid()); } else { zlog_notice("<---- OSPF6 Sibling starting in normal mode: %d ---->", getpid()); } zlog_debug("sibling sisis addr: %s", sisis_addr); free(sisis_addr); unsigned int num_of_controllers = number_of_sisis_addrs_for_process_type(SISIS_PTYPE_CTRL); if(IS_OSPF6_SIBLING_DEBUG_SISIS) { zlog_debug("num of controllers: %d", num_of_controllers); } sibling_ctrl_set_addresses(sibling_addr); // Monitor rib changes in the case that we need to restart it struct subscribe_to_rib_changes_info info; info.rib_add_ipv4_route = rib_monitor_add_ipv4_route; info.rib_remove_ipv4_route = rib_monitor_remove_ipv4_route; info.rib_add_ipv6_route = rib_monitor_add_ipv6_route; info.rib_remove_ipv6_route = rib_monitor_remove_ipv6_route; subscribe_to_rib_changes(&info); /* Start finite state machine, here we go! */ while(thread_fetch(master, &thread)) thread_call(&thread); }
int main(int argc, char **argv) { int i, j; struct thread t; struct timeval **alarms; master = thread_master_create(); log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; log_buf_pos = 0; log_buf = XMALLOC(MTYPE_TMP, log_buf_len); expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; expected_buf_pos = 0; expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len); prng = prng_new(0); timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers)); for (i = 0; i < SCHEDULE_TIMERS; i++) { long interval_msec; int ret; char *arg; /* Schedule timers to expire in 0..5 seconds */ interval_msec = prng_rand(prng) % 5000; arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1); timers[i] = thread_add_timer_msec(master, timer_func, arg, interval_msec); ret = snprintf(arg, TIMESTR_LEN + 1, "%ld.%06ld", timers[i]->u.sands.tv_sec, timers[i]->u.sands.tv_usec); assert(ret > 0); assert((size_t)ret < TIMESTR_LEN + 1); timers_pending++; } for (i = 0; i < REMOVE_TIMERS; i++) { int index; index = prng_rand(prng) % SCHEDULE_TIMERS; if (!timers[index]) continue; XFREE(MTYPE_TMP, timers[index]->arg); thread_cancel(timers[index]); timers[index] = NULL; timers_pending--; } /* We create an array of pointers to the alarm times and sort * that array. That sorted array is used to generate a string * representing the expected "output" of the timers when they * are run. */ j = 0; alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms)); for (i = 0; i < SCHEDULE_TIMERS; i++) { if (!timers[i]) continue; alarms[j++] = &timers[i]->u.sands; } qsort(alarms, j, sizeof(*alarms), cmp_timeval); for (i = 0; i < j; i++) { int ret; ret = snprintf(expected_buf + expected_buf_pos, expected_buf_len - expected_buf_pos, "%ld.%06ld\n", alarms[i]->tv_sec, alarms[i]->tv_usec); assert(ret > 0); expected_buf_pos += ret; assert(expected_buf_pos < expected_buf_len); } XFREE(MTYPE_TMP, alarms); while (thread_fetch(master, &t)) thread_call(&t); return 0; }
int main (void) { struct peer *peer; int i, j; conf_bgp_debug_fsm = -1UL; conf_bgp_debug_events = -1UL; conf_bgp_debug_packet = -1UL; conf_bgp_debug_normal = -1UL; conf_bgp_debug_as4 = -1UL; term_bgp_debug_fsm = -1UL; term_bgp_debug_events = -1UL; term_bgp_debug_packet = -1UL; term_bgp_debug_normal = -1UL; term_bgp_debug_as4 = -1UL; master = thread_master_create (); bgp_master_init (); if (fileno (stdout) >= 0) tty = isatty (fileno (stdout)); if (bgp_get (&bgp, &asn, NULL)) return -1; peer = peer_create_accept (bgp); peer->host = (char *) "foo"; for (i = AFI_IP; i < AFI_MAX; i++) for (j = SAFI_UNICAST; j < SAFI_MAX; j++) { peer->afc[i][j] = 1; peer->afc_adv[i][j] = 1; } i = 0; while (mp_segments[i].name) parse_test (peer, &mp_segments[i++], CAPABILITY); /* These tests assume mp_segments tests set at least * one of the afc_nego's */ i = 0; while (test_segments[i].name) parse_test (peer, &test_segments[i++], CAPABILITY); i = 0; while (misc_segments[i].name) parse_test (peer, &misc_segments[i++], CAPABILITY); i = 0; while (opt_params[i].name) parse_test (peer, &opt_params[i++], OPT_PARAM); SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_ADV); peer->status = Established; i = 0; while (dynamic_cap_msgs[i].name) parse_test (peer, &dynamic_cap_msgs[i++], DYNCAP); printf ("failures: %d\n", failed); return failed; }
int main(int argc, char **argv) { struct prng *prng; int i; struct thread **timers; struct timeval tv_start, tv_lap, tv_stop; unsigned long t_schedule, t_remove; master = thread_master_create(); prng = prng_new(0); timers = calloc(SCHEDULE_TIMERS, sizeof(*timers)); /* create thread structures so they won't be allocated during the * time measurement */ for (i = 0; i < SCHEDULE_TIMERS; i++) timers[i] = thread_add_timer_msec(master, dummy_func, NULL, 0); for (i = 0; i < SCHEDULE_TIMERS; i++) thread_cancel(timers[i]); quagga_gettime(QUAGGA_CLK_MONOTONIC, &tv_start); for (i = 0; i < SCHEDULE_TIMERS; i++) { long interval_msec; interval_msec = prng_rand(prng) % (100 * SCHEDULE_TIMERS); timers[i] = thread_add_timer_msec(master, dummy_func, NULL, interval_msec); } quagga_gettime(QUAGGA_CLK_MONOTONIC, &tv_lap); for (i = 0; i < REMOVE_TIMERS; i++) { int index; index = prng_rand(prng) % SCHEDULE_TIMERS; if (timers[index]) thread_cancel(timers[index]); timers[index] = NULL; } quagga_gettime(QUAGGA_CLK_MONOTONIC, &tv_stop); t_schedule = 1000 * (tv_lap.tv_sec - tv_start.tv_sec); t_schedule += (tv_lap.tv_usec - tv_start.tv_usec) / 1000; t_remove = 1000 * (tv_stop.tv_sec - tv_lap.tv_sec); t_remove += (tv_stop.tv_usec - tv_lap.tv_usec) / 1000; printf("Scheduling %d random timers took %ld.%03ld seconds.\n", SCHEDULE_TIMERS, t_schedule/1000, t_schedule%1000); printf("Removing %d random timers took %ld.%03ld seconds.\n", REMOVE_TIMERS, t_remove/1000, t_remove%1000); fflush(stdout); free(timers); thread_master_free(master); prng_free(prng); return 0; }
/* Main startup routine. */ int main (int argc, char **argv) { char *p; char *vty_addr = NULL; int vty_port = ZEBRA_VTY_PORT; int batch_mode = 0; int daemon_mode = 0; char *config_file = NULL; char *progname; struct thread thread; void rib_weed_tables (); void zebra_vty_init (); /* Set umask before anything for security */ umask (0027); /* preserve my name */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); zlog_default = openzlog (progname, ZLOG_ZEBRA, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); while (1) { int opt; #ifdef HAVE_NETLINK opt = getopt_long (argc, argv, "bdklf:i:hA:P:ru:g:vs:", longopts, 0); #else opt = getopt_long (argc, argv, "bdklf:i:hA:P:ru:g:v", longopts, 0); #endif /* HAVE_NETLINK */ if (opt == EOF) break; switch (opt) { case 0: break; case 'b': batch_mode = 1; case 'd': daemon_mode = 1; break; case 'k': keep_kernel_mode = 1; break; case 'l': /* log_mode = 1; */ break; case 'f': config_file = optarg; break; case 'A': vty_addr = optarg; break; case 'i': pid_file = optarg; break; case 'P': /* Deal with atoi() returning 0 on failure, and zebra not listening on zebra port... */ if (strcmp(optarg, "0") == 0) { vty_port = 0; break; } vty_port = atoi (optarg); vty_port = (vty_port ? vty_port : ZEBRA_VTY_PORT); break; case 'r': retain_mode = 1; break; #ifdef HAVE_NETLINK case 's': nl_rcvbufsize = atoi (optarg); break; #endif /* HAVE_NETLINK */ case 'u': zserv_privs.user = optarg; break; case 'g': zserv_privs.group = optarg; break; case 'v': print_version (progname); exit (0); break; case 'h': usage (progname, 0); break; default: usage (progname, 1); break; } } /* Make master thread emulator. */ zebrad.master = thread_master_create (); /* privs initialise */ zprivs_init (&zserv_privs); /* Vty related initialize. */ signal_init (zebrad.master, Q_SIGC(zebra_signals), zebra_signals); cmd_init (1); vty_init (zebrad.master); memory_init (); /* Zebra related initialize. */ zebra_init (); rib_init (); zebra_if_init (); zebra_debug_init (); router_id_init(); zebra_vty_init (); access_list_init (); rtadv_init (); #ifdef HAVE_IRDP irdp_init(); #endif /* For debug purpose. */ /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ /* Make kernel routing socket. */ kernel_init (); interface_list (); route_read (); /* Sort VTY commands. */ sort_node (); #ifdef HAVE_SNMP zebra_snmp_init (); #endif /* HAVE_SNMP */ /* Clean up self inserted route. */ if (! keep_kernel_mode) rib_sweep_route (); /* Configuration file read*/ vty_read_config (config_file, config_default); /* Clean up rib. */ rib_weed_tables (); /* Exit when zebra is working in batch mode. */ if (batch_mode) exit (0); /* Needed for BSD routing socket. */ old_pid = getpid (); /* Daemonize. */ if (daemon_mode) daemon (0, 0); /* Output pid of zebra. */ pid_output (pid_file); /* Needed for BSD routing socket. */ pid = getpid (); /* Make vty server socket. */ vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH); /* Print banner. */ zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION, vty_port); while (thread_fetch (zebrad.master, &thread)) thread_call (&thread); /* Not reached... */ exit (0); }