int find_networks (ip_t tabnet [], int maxtab) { struct node *n ; int ntab, i ; int match ; ntab = 0 ; for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (n->nodetype == NT_L3 && MK_ISSET (n, MK_VLANTRAVERSAL)) { if (ntab < maxtab) { ip_netof (&n->u.l3.addr, &tabnet [ntab]) ; match = 0 ; for (i = 0 ; i < ntab ; i++) { if (ip_match (&tabnet [ntab], &tabnet [i], 1)) { match = 1 ; break ; } } if (! match) ntab++ ; } else break ; } } return ntab ; }
static void sel_mark_net (ip_t *addr) { struct node *n, *l2node ; struct network *net ; for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (n->nodetype == NT_L3 && ip_match (&n->u.l3.addr, addr, 1)) { MK_SELECT (n) ; l2node = get_neighbour (n, NT_L2) ; if (l2node != NULL) transport_vlan_on_L2 (l2node, l2node->u.l2.vlan) ; } } for (net = mobj_head (netmobj) ; net != NULL ; net = net->next) if (ip_match (&net->addr, addr, 1)) MK_SELECT (net) ; for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) if (MK_ISSET (n, MK_L2TRANSPORT)) MK_SELECT (n) ; }
/* ip inquiries. * ip is little endian 4-byte int. * note that location encoding is not converted, which will most likely be gb2312. */ int seeker_lookup(QQWrySeeker *seeker, unsigned int ip, char location[], int loc_size) { if (loc_size <= 0) return -1; int low = 0, up = (seeker->idx_end - seeker->idx_beg) / 7; while (low <= up) { int mid = (low + up) / 2; int compare = ip_match(seeker->fp, ip, seeker->idx_beg + mid * 7); if (compare == 0) /* we found the record */ return read_location(seeker->fp, location, loc_size); if (compare < 0) up = mid - 1; else low = mid + 1; } location[0] = 0; return 0; }
int main (int argc, const char *argv []) { int i, j; unsigned d; IpFilter_t f; unsigned ip [4]; unsigned char ipa [4]; for (i = 1; i < argc; i++) { f = ip_filter_new (argv [i], 3, 1); if (!f) { printf ("Invalid filter spec: %s\n", argv [i]); break; } ip_filter_dump (f); i++; if (i >= argc - 1) { printf ("Missing <domain> <address>!\n"); return (1); } d = atoi (argv [i]); i++; sscanf (argv [i], "%d.%d.%d.%d", &ip [0], &ip [1], &ip [2], &ip [3]); for (j = 0; j < 4; j++) { if (ip [j] > 255) printf ("Incorrect IP address!\n"); ipa [j] = ip [j]; } i++; if (ip_match (f, d, ipa)) printf (" -> match!\n"); else printf (" -> no match\n"); ip_filter_free (f); } return (0); }
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) ; }