static void __r_insert_node (struct rtree_node *node, const BoxType * query, int manage, bool force) { #ifdef SLOW_ASSERTS assert (__r_node_is_good (node)); #endif /* Ok, at this point we must already enclose the query or we're forcing * this node to expand to enclose it, so if we're a leaf, simply store * the query here */ if (node->flags.is_leaf) { register int i; if (UNLIKELY (manage)) { register int flag = 1; for (i = 0; i < M_SIZE; i++) { if (!node->u.rects[i].bptr) break; flag <<= 1; } node->flags.manage |= flag; } else { for (i = 0; i < M_SIZE; i++) if (!node->u.rects[i].bptr) break; } /* the node always has an extra space available */ node->u.rects[i].bptr = query; node->u.rects[i].bounds = *query; /* first entry in node determines initial bounding box */ if (i == 0) node->box = *query; else if (force) { MAKEMIN (node->box.X1, query->X1); MAKEMAX (node->box.X2, query->X2); MAKEMIN (node->box.Y1, query->Y1); MAKEMAX (node->box.Y2, query->Y2); } if (i < M_SIZE) { sort_node (node); return; } /* we must split the node */ split_node (node); return; } else { int i; struct rtree_node *best_node; double score, best_score; if (force) { MAKEMIN (node->box.X1, query->X1); MAKEMAX (node->box.X2, query->X2); MAKEMIN (node->box.Y1, query->Y1); MAKEMAX (node->box.Y2, query->Y2); } /* this node encloses it, but it's not a leaf, so descend the tree */ /* First check if any children actually encloses it */ assert (node->u.kids[0]); for (i = 0; i < M_SIZE; i++) { if (!node->u.kids[i]) break; if (contained (node->u.kids[i], query)) { __r_insert_node (node->u.kids[i], query, manage, false); sort_node (node); return; } } /* see if there is room for a new leaf node */ if (node->u.kids[0]->flags.is_leaf && i < M_SIZE) { struct rtree_node *new_node; new_node = (struct rtree_node *)calloc (1, sizeof (*new_node)); new_node->parent = node; new_node->flags.is_leaf = true; node->u.kids[i] = new_node; new_node->u.rects[0].bptr = query; new_node->u.rects[0].bounds = *query; new_node->box = *query; if (UNLIKELY (manage)) new_node->flags.manage = 1; sort_node (node); return; } /* Ok, so we're still here - look for the best child to push it into */ best_score = penalty (node->u.kids[0], query); best_node = node->u.kids[0]; for (i = 1; i < M_SIZE; i++) { if (!node->u.kids[i]) break; score = penalty (node->u.kids[i], query); if (score < best_score) { best_score = score; best_node = node->u.kids[i]; } } __r_insert_node (best_node, query, manage, true); sort_node (node); return; } }
/* Main startup routine. */ int zebra_main_entry (int argc, char **argv) { char *p; #undef vty_addr char *vty_addr = NULL; #undef vty_port int vty_port = ZEBRA_VTY_PORT; int dryrun = 0; int batch_mode = 0; int daemon_mode = 0; #undef config_file char *config_file = NULL; char *progname; struct thread thread; /* 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:C", longopts, 0); #else opt = getopt_long (argc, argv, "bdklf:i: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 '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); 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__item = thread_master_create (); /* privs initialise */ zprivs_init (&zserv_privs); /* Vty related initialize. */ signal_init (zebrad.master__item, Q_SIGC(zebra_signals), zebra_signals); cmd_init (1); vty_init (zebrad.master__item); 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); /* 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 (); /* 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__item, &thread)) thread_call (&thread); /* Not reached... */ return 0; }
/*! * \brief Split the node into two nodes putting clusters in each use the * k-means clustering algorithm. */ struct rtree_node * find_clusters (struct rtree_node *node) { float total_a, total_b; float a_X, a_Y, b_X, b_Y; bool belong[M_SIZE + 1]; struct centroid center[M_SIZE + 1]; int clust_a, clust_b, tries; int a_manage = 0, b_manage = 0; int i, old_ax, old_ay, old_bx, old_by; struct rtree_node *new_node; BoxType *b; for (i = 0; i < M_SIZE + 1; i++) { if (node->flags.is_leaf) b = &(node->u.rects[i].bounds); else b = &(node->u.kids[i]->box); center[i].x = 0.5 * (b->X1 + b->X2); center[i].y = 0.5 * (b->Y1 + b->Y2); /* adding 1 prevents zero area */ center[i].area = 1. + (float) (b->X2 - b->X1) * (float) (b->Y2 - b->Y1); } /* starting 'A' cluster center */ a_X = center[0].x; a_Y = center[0].y; /* starting 'B' cluster center */ b_X = center[M_SIZE].x; b_Y = center[M_SIZE].y; /* don't allow the same cluster centers */ if (b_X == a_X && b_Y == a_Y) { b_X += 10000; a_Y -= 10000; } for (tries = 0; tries < M_SIZE; tries++) { old_ax = (int) a_X; old_ay = (int) a_Y; old_bx = (int) b_X; old_by = (int) b_Y; clust_a = clust_b = 0; for (i = 0; i < M_SIZE + 1; i++) { float dist1, dist2; dist1 = SQUARE (a_X - center[i].x) + SQUARE (a_Y - center[i].y); dist2 = SQUARE (b_X - center[i].x) + SQUARE (b_Y - center[i].y); if (dist1 * (clust_a + M_SIZE / 2) < dist2 * (clust_b + M_SIZE / 2)) { belong[i] = true; clust_a++; } else { belong[i] = false; clust_b++; } } /* kludge to fix degenerate cases */ if (clust_a == M_SIZE + 1) belong[M_SIZE / 2] = false; else if (clust_b == M_SIZE + 1) belong[M_SIZE / 2] = true; /* compute new center of gravity of clusters */ total_a = total_b = 0; a_X = a_Y = b_X = b_Y = 0; for (i = 0; i < M_SIZE + 1; i++) { if (belong[i]) { a_X += center[i].x * center[i].area; a_Y += center[i].y * center[i].area; total_a += center[i].area; } else { b_X += center[i].x * center[i].area; b_Y += center[i].y * center[i].area; total_b += center[i].area; } } a_X /= total_a; a_Y /= total_a; b_X /= total_b; b_Y /= total_b; if (old_ax == (int) a_X && old_ay == (int) a_Y && old_bx == (int) b_X && old_by == (int) b_Y) break; } /* Now 'belong' has the partition map */ new_node = (struct rtree_node *)calloc (1, sizeof (*new_node)); new_node->parent = node->parent; new_node->flags.is_leaf = node->flags.is_leaf; clust_a = clust_b = 0; if (node->flags.is_leaf) { int flag, a_flag, b_flag; flag = a_flag = b_flag = 1; for (i = 0; i < M_SIZE + 1; i++) { if (belong[i]) { node->u.rects[clust_a++] = node->u.rects[i]; if (node->flags.manage & flag) a_manage |= a_flag; a_flag <<= 1; } else { new_node->u.rects[clust_b++] = node->u.rects[i]; if (node->flags.manage & flag) b_manage |= b_flag; b_flag <<= 1; } flag <<= 1; } } else { for (i = 0; i < M_SIZE + 1; i++) { if (belong[i]) node->u.kids[clust_a++] = node->u.kids[i]; else { node->u.kids[i]->parent = new_node; new_node->u.kids[clust_b++] = node->u.kids[i]; } } } node->flags.manage = a_manage; new_node->flags.manage = b_manage; assert (clust_a != 0); assert (clust_b != 0); if (node->flags.is_leaf) for (; clust_a < M_SIZE + 1; clust_a++) node->u.rects[clust_a].bptr = NULL; else for (; clust_a < M_SIZE + 1; clust_a++) node->u.kids[clust_a] = NULL; adjust_bounds (node); sort_node (node); adjust_bounds (new_node); sort_node (new_node); return (new_node); }
/* VTY shell main routine. */ int main (int argc, char **argv, char **env) { char *p; int opt; int eval_flag = 0; int boot_flag = 0; char *eval_line = NULL; system("nvram set wk_mode=\"ospf bgp rip router\""); system("nvram set zebra_copt=1"); system("nvram set ospfd_copt=1"); system("nvram set ripd_copt=1"); system("nvram set bgpd_copt=1"); system("stopservice zebra"); system("startservice zebra"); /* Preserve name of myself. */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); /* Option handling. */ while (1) { opt = getopt_long (argc, argv, "be:c:h", longopts, 0); if (opt == EOF) break; switch (opt) { case 0: break; case 'b': boot_flag = 1; break; case 'e': case 'c': eval_flag = 1; eval_line = optarg; break; case 'h': usage (0); break; default: usage (1); break; } } /* Initialize user input buffer. */ line_read = NULL; /* Signal and others. */ vtysh_signal_init (); /* Make vty structure and register commands. */ vtysh_init_vty (); vtysh_init_cmd (); vtysh_user_init (); vtysh_config_init (); vty_init_vtysh (); sort_node (); vtysh_connect_all (); /* Read vtysh configuration file. */ vtysh_read_config (config_default); /* If eval mode. */ if (eval_flag) { vtysh_execute_no_pager (eval_line); exit (0); } /* Boot startup configuration file. */ if (boot_flag) { if (vtysh_read_config (integrate_default)) { fprintf (stderr, "Can't open configuration file [%s]\n", integrate_default); exit (1); } else exit (0); } vtysh_pager_init (); vtysh_readline_init (); vty_hello (vty); vtysh_auth (); /* Enter into enable node. */ vtysh_execute ("enable"); /* Preparation for longjmp() in sigtstp(). */ sigsetjmp (jmpbuf, 1); jmpflag = 1; /* Main command loop. */ while (vtysh_rl_gets ()) vtysh_execute (line_read); printf ("\n"); /* Rest in peace. */ exit (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); }
/**fetch board type**/ fd = fopen(IS_MASTER_FILE,"r"); if(NULL == fd) { zlog_notice("open file /dbm/local_board/is_master failed\n"); return -1; } if(1!=fscanf(fd,"%d",&is_master)) { fclose(fd); zlog_notice("Get product is_master error\n"); return -1; } fclose(fd); fd = fopen(IS_ACTIVE_MASTER_FILE,"r"); if(NULL == fd) { zlog_notice("open file /dbm/local_board/is_active_master failed\n"); return -1; } if(1!=fscanf(fd,"%d",&is_active_master)) { fclose(fd); zlog_notice("Get product is_active_master error\n"); return -1; } fclose(fd); if(is_master == 1 && is_active_master == 1)/*Distribute System : active master board */ return 1; else return 0; /*Distribute System : not active master board */ } //extern int set_cli_syslog; /*dongshu for del cli_syslog cmd*/ int main (int argc, char **argv, char **env) { char *p; int opt; const char *daemon_name = NULL; struct cmd_rec { const char *line; struct cmd_rec *next; } *cmd = NULL; struct cmd_rec *tail = NULL; int echo_command = 0; struct termios savetty; char* loginname=NULL; char *rhost = NULL; int ret=CMD_SUCCESS; loginname = getenv("USER"); rhost = getenv("REMOTEHOST"); /* loginname = getlogin(); if(!loginname) { loginname = "TTYS0"; } */ /*added by scx*/ get_default_config(); if(integrate_default==NULL) { integrate_default= malloc(128); if(!integrate_default) { fprintf(stderr,"can't get config file,return\n"); exit(0); } sprintf(integrate_default,"%s",integrate_default_bak); } configfile = integrate_default; /*end added by scx*/ /* Preserve name of myself. */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); //openlog(progname,0,LOG_DAEMON); openlog("CLI",LOG_PID,LOG_DAEMON); /* Option handling. */ while (1) { opt = getopt_long (argc, argv, "bef:c:d:Eh", longopts, 0); if (opt == EOF) break; switch (opt) { case 0: break; case 'b': #ifdef DISTRIBUT { boot_flag =1; tipc_dbus_flag =0; } #else boot_flag = 1; #endif break; case 'e': case 'c': { /* start - added by zhengbo 2011-12-23 */ cmd_flag = 1; /* end - added by zhengbo 2011-12-23 */ struct cmd_rec *cr; cr = XMALLOC(0, sizeof(*cr)); cr->line = optarg; cr->next = NULL; if (tail) tail->next = cr; else cmd = cr; tail = cr; #ifdef DISTRIBUT tipc_dbus_flag =0; #endif vtysh_config_flag=1; } break; case 'd': { daemon_name = optarg; #ifdef DISTRIBUT tipc_dbus_flag =1; #endif } break; case 'E': { echo_command = 1; #ifdef DISTRIBUT tipc_dbus_flag =1; #endif } break; case 'h': usage (0); #ifdef DISTRIBUT tipc_dbus_flag =1; #endif break; case 'f': configfile = optarg; #ifdef DISTRIBUT tipc_dbus_flag =1; #endif break; default: usage (1); #ifdef DISTRIBUT tipc_dbus_flag =1; #endif break; } } /* Initialize user input buffer. */ line_read = NULL; /* Signal and others. */ syslog(LOG_NOTICE,"Vtysh start\n"); vtysh_signal_init (); syslog(LOG_NOTICE,"Vtysh vtysh_signal_init\n"); /* Make vty structure and register commands. */ vtysh_init_vty (); syslog(LOG_NOTICE,"Vtysh vtysh_init_vty\n"); vtysh_init_cmd (); syslog(LOG_NOTICE,"Vtysh vtysh_init_cmd\n"); /* deleted by scx for deleted user manage vtysh_user_init (); */ vtysh_config_init (); syslog(LOG_NOTICE,"Vtysh vtysh_config_init\n"); //printf("Loading dcli init...\n"); /* add device commandline interface */ #ifdef DISTRIBUT dl_dcli_init(tipc_dbus_flag); #else dl_dcli_init(); #endif syslog(LOG_NOTICE,"Vtysh dl_dcli_init\n"); //printf("Initing vtysh ...\n"); vty_init_vtysh (); syslog(LOG_NOTICE,"Vtysh vty_init_vtysh\n"); //printf("Sorting command nodes ...\n"); sort_node (); syslog(LOG_NOTICE,"Vtysh sort_node\n"); //printf("Loading startup config ...\n"); /* Read vtysh configuration file before connecting to daemons. */ /* deleted by scx vtysh_read_config (config_default); */ /* Make sure we pass authentication before proceeding. */ //printf("Preparing for authentication ..."); /* deleted by scx vtysh_auth (); */ /* Do not connect until we have passed authentication. */ if (vtysh_connect_all (daemon_name) <= 0) { /* fprintf(stderr, "Exiting: failed to connect to any daemons.\n"); exit(1); */ } syslog(LOG_NOTICE,"Vtysh vtysh_connect_all\n"); /* If eval mode. */ if (cmd) { /* Enter into enable node. */ vtysh_execute ("enable"); while (cmd != NULL) { char *eol; while ((eol = strchr(cmd->line, '\n')) != NULL) { *eol = '\0'; if (echo_command) printf("%s%s\n", vtysh_prompt(), cmd->line); syslog(LOG_NOTICE|LOG_LOCAL7,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read); ret=vtysh_execute_func_4ret(cmd->line); cmd->line = eol+1; if(ret != CMD_SUCCESS) break; } if(ret == CMD_SUCCESS) { if (echo_command) printf("%s%s\n", vtysh_prompt(), cmd->line); syslog(LOG_NOTICE|LOG_LOCAL7,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read); ret=vtysh_execute_func_4ret (cmd->line); } { struct cmd_rec *cr; cr = cmd; cmd = cmd->next; XFREE(0, cr); } } return(ret); } #ifdef DISTRIBUT vtysh_get_every_board_hostname_list_init(); #endif /* Boot startup configuration file. */ if (boot_flag) { if (vtysh_read_config (configfile)) { fprintf (stderr, "Can't open configuration file [%s]\n", configfile); exit (1); } else exit (0); } // printf("."); vtysh_pager_init (); syslog(LOG_NOTICE,"Vtysh vtysh_pager_init\n"); // printf("."); vtysh_readline_init (); tcgetattr(fileno(stdout),&savetty); savetty.c_cc[VSUSP]=3; savetty.c_cc[VEOF]=3; memcpy(&bktty,&savetty,sizeof(savetty)); tcsetattr(fileno(stdout),TCSANOW,&savetty); init_idel_time(); syslog(LOG_NOTICE,"Vtysh init_idel_time\n"); // printf(".\n"); vty_hello (vty); vty_set_init_passwd(); #if 0 /*deleted by scx*/ /* Enter into enable node. */ vtysh_execute ("enable"); #endif /* Preparation for longjmp() in sigtstp(). */ sigsetjmp (jmpbuf, 1); sigsetjmp(jmpbuffer,1); jmpflag = 1; /* Main command loop. */ while (vtysh_rl_gets ()) { #if 0/*dongshu for del cli_syslog cmd*/ set_cli_syslog=get_cli_syslog_str(); if(set_cli_syslog) { syslog(LOG_DEBUG,"CLI: user:%s vty->node is %d exec %s\n",loginname,vty->node,line_read); } #else /*CID 11025 (#1 of 1):. var_deref_model: Passing null pointer "line_read" to function "strcmp(char const *, char const *)", which dereferences it. */ if(!line_read) continue; if(strcmp(line_read,QPMZ) && vty->node != HIDDENDEBUG_NODE) { syslog(LOG_NOTICE|LOG_LOCAL5,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read); } else if(strcmp(line_read,QPMZ)== 0) { syslog(LOG_NOTICE,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#","Enter debug model\n"); } else if(vty->node == HIDDENDEBUG_NODE) { syslog(LOG_NOTICE,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read); } #endif idle_time=0; vtysh_execute (line_read); set_idle_time_init(); /* idle_time_rem = idle_time; idle_time = tmp_idle_time; */ tcsetattr(fileno(stdout),TCSANOW,&bktty); } printf ("\n"); /* Close dcli lib handle before exit,*/ dlclose(dcli_dl_handle); dlclose(dcli_dl_handle_sem); /* Rest in peace. */ exit (0); }
/* VTY shell main routine. */ int main (int argc, char **argv, char **env) { char *p; int opt; int dryrun = 0; int boot_flag = 0; const char *daemon_name = NULL; struct cmd_rec { const char *line; struct cmd_rec *next; } *cmd = NULL; struct cmd_rec *tail = NULL; int echo_command = 0; int no_error = 0; /* Preserve name of myself. */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); /* if logging open now */ if ((p = getenv("VTYSH_LOG")) != NULL) logfile = fopen(p, "a"); /* Option handling. */ while (1) { opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0); if (opt == EOF) break; switch (opt) { case 0: break; case 'b': boot_flag = 1; break; case 'e': case 'c': { struct cmd_rec *cr; cr = XMALLOC(0, sizeof(*cr)); cr->line = optarg; cr->next = NULL; if (tail) tail->next = cr; else cmd = cr; tail = cr; } break; case 'd': daemon_name = optarg; break; case 'n': no_error = 1; break; case 'E': echo_command = 1; break; case 'C': dryrun = 1; break; case 'h': usage (0); break; default: usage (1); break; } } /* Initialize user input buffer. */ line_read = NULL; setlinebuf(stdout); /* Signal and others. */ vtysh_signal_init (); /* Make vty structure and register commands. */ vtysh_init_vty (); vtysh_init_cmd (); vtysh_user_init (); vtysh_config_init (); vty_init_vtysh (); sort_node (); /* Read vtysh configuration file before connecting to daemons. */ vtysh_read_config (config_default); /* Start execution only if not in dry-run mode */ if(dryrun) return(0); /* Ignore error messages */ if (no_error) freopen("/dev/null", "w", stdout); /* Make sure we pass authentication before proceeding. */ vtysh_auth (); /* Do not connect until we have passed authentication. */ if (vtysh_connect_all (daemon_name) <= 0) { fprintf(stderr, "Exiting: failed to connect to any daemons.\n"); exit(1); } /* If eval mode. */ if (cmd) { /* Enter into enable node. */ vtysh_execute ("enable"); while (cmd != NULL) { int ret; char *eol; while ((eol = strchr(cmd->line, '\n')) != NULL) { *eol = '\0'; if (echo_command) printf("%s%s\n", vtysh_prompt(), cmd->line); if (logfile) log_it(cmd->line); ret = vtysh_execute_no_pager(cmd->line); if (!no_error && ! (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)) exit(1); cmd->line = eol+1; } if (echo_command) printf("%s%s\n", vtysh_prompt(), cmd->line); if (logfile) log_it(cmd->line); ret = vtysh_execute_no_pager(cmd->line); if (!no_error && ! (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)) exit(1); { struct cmd_rec *cr; cr = cmd; cmd = cmd->next; XFREE(0, cr); } } exit (0); } /* Boot startup configuration file. */ if (boot_flag) { if (vtysh_read_config (integrate_default)) { fprintf (stderr, "Can't open configuration file [%s]\n", integrate_default); exit (1); } else exit (0); } vtysh_pager_init (); vtysh_readline_init (); vty_hello (vty); /* Enter into enable node. */ vtysh_execute ("enable"); /* Preparation for longjmp() in sigtstp(). */ sigsetjmp (jmpbuf, 1); jmpflag = 1; snprintf(history_file, sizeof(history_file), "%s/.history_quagga", getenv("HOME")); read_history(history_file); /* Main command loop. */ while (vtysh_rl_gets ()) vtysh_execute (line_read); history_truncate_file(history_file,1000); printf ("\n"); /* Rest in peace. */ exit (0); }