int main (int argc, char *argv []) { int i ; struct node *n ; struct eq *eq ; ip_t cidr ; int c, err ; char *prog, *errstr ; prog = argv [0] ; err = 0 ; sel_init () ; while ((c = getopt (argc, argv, "an:e:E:tv:m")) != -1) { switch (c) { case 'a' : case 'n' : case 'e' : case 'E' : case 't' : case 'v' : case 'm' : if ((errstr = sel_register (c, optarg)) != NULL) { fprintf (stderr, "%s: %s\n", prog, errstr) ; err = 1 ; } break ; case '?' : default : usage (prog) ; } } if (err) exit (1) ; argc -= optind ; argv += optind ; if (argc == 0) usage (prog) ; /* * Read the graph and select subgraph */ bin_read (stdin, mobjlist) ; sel_mark () ; /* * First pass : mark all L3 nodes matching CIDR arguments */ for (i = 0 ; i < argc ; i++) { if (! ip_pton (argv [i], &cidr)) { fprintf (stderr, "%s: Invalid cidr '%s'\n", prog, argv [i]) ; exit (1) ; } for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) if (n->nodetype == NT_L3 && ip_match (&n->u.l3.addr, &cidr, 0)) MK_SET (n, MK_IPMATCH) ; } /* * Output selection arguments */ fprintf (stdout, "selection") ; for (i = 0 ; i < argc ; i++) fprintf (stdout, " %s", argv [i]) ; fprintf (stdout, "\n") ; /* * Second pass : identify all routing instances connected to those * L3 nodes we have marked before, and print equipements which are * routing instances. */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (n->nodetype == NT_L3 && MK_ISSET (n, MK_IPMATCH)) { struct node *r ; MK_SET (n->eq, MK_IPMATCH) ; r = get_neighbour (n, NT_ROUTER) ; if (r != NULL && ! MK_ISSET (r, MK_ISROUTER)) { MK_SET (n, MK_ISROUTER) ; MK_SET (r, MK_ISROUTER) ; MK_SET (n->eq, MK_ISROUTER) ; if (MK_ISSELECTED (n)) fprintf (stdout, "eq %s:%s router\n", n->eq->name, r->u.router.name) ; } } } /* * Third pass : print equipements which are not routing instances */ for (eq = mobj_head (eqmobj) ; eq != NULL ; eq = eq->next) if (MK_ISSET (eq, MK_IPMATCH) && ! MK_ISSET (eq, MK_ISROUTER)) if (MK_ISSELECTED (eq)) fprintf (stdout, "eq %s host\n", eq->name) ; /* * Fourth pass : identify broadcast domain for each L3 */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (n->nodetype == NT_L3 && MK_ISSET (n, MK_IPMATCH) && ! MK_ISSET (n, MK_PROCESSED)) walkl3 (stdout, n) ; } sel_end () ; exit (0) ; }
int main (int argc, char *argv []) { int termif, backif ; int c, err ; char *prog, *errstr ; prog = argv [0] ; err = 0 ; termif = backif = 0 ; sel_init () ; while ((c = getopt (argc, argv, "an:e:E:tv:mBb")) != -1) { switch (c) { case 'a' : case 'n' : case 'e' : case 'E' : case 't' : case 'v' : case 'm' : if ((errstr = sel_register (c, optarg)) != NULL) { fprintf (stderr, "%s: %s\n", prog, errstr) ; err = 1 ; } break ; case 'B' : termif = 1 ; break ; case 'b' : backif = 1 ; break ; case '?' : default : usage (prog) ; } } if (err) exit (1) ; argc -= optind ; argv += optind ; if (argc != 0) usage (prog) ; if (termif == 0 && backif == 0) { termif = 1 ; backif = 1 ; } /* * Read the graph and select a subgraph */ bin_read (stdin, mobjlist) ; sel_mark () ; /* * Grep interface type */ if (! termif) /* we don't want terminal interfaces */ mark_ifaces (TERMINAL) ; if (! backif) /* we don't want backbone interfaces */ mark_ifaces (! TERMINAL) ; /* * Output graph */ output_eq_ifaces (stdout) ; sel_end () ; exit (0) ; }
int main (void) { int s, s2, t, len; struct sockaddr_un local, remote; pthread_t tid; int *p_s2; int rc = 0; daemon(1, 1); openlog("ipmid", LOG_CONS, LOG_DAEMON); plat_fruid_init(); plat_sensor_init(); plat_lan_init(&g_lan_config); sdr_init(); sel_init(); pthread_mutex_init(&m_chassis, NULL); pthread_mutex_init(&m_sensor, NULL); pthread_mutex_init(&m_app, NULL); pthread_mutex_init(&m_storage, NULL); pthread_mutex_init(&m_transport, NULL); pthread_mutex_init(&m_oem, NULL); pthread_mutex_init(&m_oem_1s, NULL); if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) { syslog(LOG_WARNING, "ipmid: socket() failed\n"); exit (1); } local.sun_family = AF_UNIX; strcpy (local.sun_path, SOCK_PATH_IPMI); unlink (local.sun_path); len = strlen (local.sun_path) + sizeof (local.sun_family); if (bind (s, (struct sockaddr *) &local, len) == -1) { syslog(LOG_WARNING, "ipmid: bind() failed\n"); exit (1); } if (listen (s, 5) == -1) { syslog(LOG_WARNING, "ipmid: listen() failed\n"); exit (1); } while(1) { int n; t = sizeof (remote); // TODO: seen accept() call fails and need further debug if ((s2 = accept (s, (struct sockaddr *) &remote, &t)) < 0) { rc = errno; syslog(LOG_WARNING, "ipmid: accept() failed with ret: %x, errno: %x\n", s2, rc); sleep(5); continue; } // Creating a worker thread to handle the request // TODO: Need to monitor the server performance with higher load and // see if we need to create pre-defined number of workers and schedule // the requests among them. p_s2 = malloc(sizeof(int)); *p_s2 = s2; if (pthread_create(&tid, NULL, conn_handler, (void*) p_s2) < 0) { syslog(LOG_WARNING, "ipmid: pthread_create failed\n"); close(s2); continue; } pthread_detach(tid); } close(s); pthread_mutex_destroy(&m_chassis); pthread_mutex_destroy(&m_sensor); pthread_mutex_destroy(&m_app); pthread_mutex_destroy(&m_storage); pthread_mutex_destroy(&m_transport); pthread_mutex_destroy(&m_oem); pthread_mutex_destroy(&m_oem_1s); return 0; }
int main (int argc, char *argv []) { char *prog, *errstr ; int c, err ; char *eqname ; struct eq *eq, *neq ; struct node *n ; int dumpstat, dumpwifi, dumppmac, dumpipmac ; /* * Analyzes arguments */ prog = argv [0] ; err = 0 ; dumpstat = 0 ; dumpwifi = 0 ; dumppmac = 0 ; dumpipmac = 0 ; sel_init () ; while ((c = getopt (argc, argv, "an:e:E:tv:impsw")) != -1) { switch (c) { case 'a' : case 'n' : case 'e' : case 'E' : case 't' : case 'm' : case 'v' : if ((errstr = sel_register (c, optarg)) != NULL) { fprintf (stderr, "%s: %s\n", prog, errstr) ; err = 1 ; } break ; case 's' : dumpstat = 1 ; break ; case 'w' : dumpwifi = 1 ; break ; case 'p' : dumppmac = 1 ; break ; case 'i' : dumpipmac = 1 ; break ; case '?' : default : usage (prog) ; } } if (err) exit (1) ; if (dumpstat == 0 && dumpwifi == 0 && dumppmac == 0 && dumpipmac == 0) { dumpstat = 1 ; dumpwifi = 1 ; dumppmac = 1 ; dumpipmac = 1 ; } argc -= optind ; argv += optind ; switch (argc) { case 0 : eqname = NULL ; break ; case 1 : eqname = argv [0] ; break ; default : usage (prog) ; break ; } /* * Read the graph and process selection */ bin_read (stdin, mobjlist) ; for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { n->mark = 0 ; vlan_zero (n->vlanset) ; } sel_mark () ; /* * Lookup the equipment, if any */ if (eqname != NULL) { eq = eq_lookup (eqname) ; if (eq == NULL) { fprintf (stderr, "%s : equipement '%s' not found\n", prog, eqname) ; exit (1) ; } } else eq = NULL ; /* * Output the wifi probes first, since stat dump will reset marks */ if (dumpwifi) { struct ssidprobe *sp ; for (sp = mobj_head (ssidprobemobj) ; sp != NULL ; sp = sp->next) { if (eq == NULL || sp->eq == eq) if (MK_ISSELECTED (sp->l1)) output_ssidprobe (stdout, sp) ; } } if (dumppmac) { for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if ((eq == NULL || n->eq == eq) && n->nodetype == NT_BRIDGE && n->eq->portmac && MK_ISSELECTED (n->eq)) output_portmac (stdout, n) ; } } if (dumpipmac) { if (eq == NULL) { for (neq = mobj_head (eqmobj) ; neq != NULL ; neq = neq->next) { if(neq->ipmac && MK_ISSELECTED (neq)) output_ipmac (stdout, neq) ; } } else { if(eq->ipmac && MK_ISSELECTED (eq)) output_ipmac (stdout, eq) ; } } if (dumpstat) { for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (eq == NULL || n->eq == eq) { if (n->nodetype == NT_L2 && MK_ISSELECTED (n)) output_collect_L2 (stdout, n) ; if (n->nodetype == NT_L1 && MK_ISSELECTED (n)) output_collect_L1 (stdout, n) ; } } } sel_end () ; exit (0) ; }