/* * Initialize our routing tree. */ int in_inithead(void **head, int off) { struct radix_node_head *rnh; /* XXX MRT * This can be called from vfs_export.c too in which case 'off' * will be 0. We know the correct value so just use that and * return directly if it was 0. * This is a hack that replaces an even worse hack on a bad hack * on a bad design. After RELENG_7 this should be fixed but that * will change the ABI, so for now do it this way. */ if (!rn_inithead(head, 32)) return 0; if (off == 0) /* XXX MRT see above */ return 1; /* only do the rest for a real routing table */ rnh = *head; rnh->rnh_addaddr = in_addroute; in_setmatchfunc(rnh, V_drop_redirect); rnh->rnh_close = in_clsroute; if (_in_rt_was_here == 0 ) { callout_init(&V_rtq_timer, CALLOUT_MPSAFE); callout_reset(&V_rtq_timer, 1, in_rtqtimo, curvnet); _in_rt_was_here = 1; } return 1; }
static void maptables_init(void) /* * This init both maptables for IPv4 and IPv6 EIDs */ { mapzone = uma_zcreate("mapentry", sizeof(struct mapentry), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); if (rn_inithead((void**)(void *) &map_tables[IPv4_EIDs_TABLE], 0) == 0){ log(LOG_INFO,"WARNING!!! IPv4 MapTable Init KO \n"); } else { /* Initialize Expunge Timer */ callout_init(&maptable_xpg_timer[IPv4_EIDs_TABLE], CALLOUT_MPSAFE); maptable_xpgto_args[IPv4_EIDs_TABLE].rnh = map_tables[IPv4_EIDs_TABLE]; maptable_xpgto_args[IPv4_EIDs_TABLE].af_family = AF_INET; lisp_cache_xpg_to((void *) &maptable_xpgto_args[IPv4_EIDs_TABLE]); log(LOG_INFO,"IPv4 MapTable Init OK \n"); }; if (rn_inithead((void**)(void *)&map_tables[IPv6_EIDs_TABLE], 0) == 0){ log(LOG_INFO,"WARNING!!! IPv6 MapTable Init KO \n"); } else { /* Initialize Expunge Timer */ callout_init(&maptable_xpg_timer[IPv6_EIDs_TABLE], CALLOUT_MPSAFE); maptable_xpgto_args[IPv6_EIDs_TABLE].rnh = map_tables[IPv6_EIDs_TABLE]; maptable_xpgto_args[IPv6_EIDs_TABLE].af_family = AF_INET6; lisp_cache_xpg_to((void *) &maptable_xpgto_args[IPv6_EIDs_TABLE]); log(LOG_INFO,"IPv6 MapTable Init OK \n"); }; } /* maptables_init() */
int rn_mpath_inithead(void **head, int off) { struct radix_node_head *rnh; hashjitter = arc4random(); if (rn_inithead(head, off) == 1) { rnh = (struct radix_node_head *)*head; rnh->rnh_multipath = 1; return 1; } else return 0; }
/* * Initialize our routing tree with debugging hooks. */ int at_inithead(void **head, int off) { struct radix_node_head *rnh; if (!rn_inithead(head, off)) return 0; rnh = *head; rnh->rnh_addaddr = at_addroute; rnh->rnh_deladdr = at_delroute; rnh->rnh_matchaddr = at_matroute; rnh->rnh_lookup = at_lookup; return 1; }
int ipfw_init_tables(struct ip_fw_chain *ch) { int i; uint16_t j; for (i = 0; i < IPFW_TABLES_MAX; i++) { if (!rn_inithead((void **)&ch->tables[i], KEY_OFS)) { for (j = 0; j < i; j++) { (void) ipfw_flush_table(ch, j); } return (ENOMEM); } } return (0); }
/* * Initialize our routing tree. */ int in_inithead(void **head, int off) { struct radix_node_head *rnh; if (!rn_inithead(head, 32)) return 0; rnh = *head; RADIX_NODE_HEAD_LOCK_INIT(rnh); rnh->rnh_addaddr = in_addroute; if (_in_rt_was_here == 0 ) { _in_rt_was_here = 1; } return 1; }
void rn_init(void) { char *cp, *cplim; if (max_keylen == 0) { printf("rn_init: radix functions require max_keylen be set\n"); return; } rn_zeros = (char *)rtmalloc(3 * max_keylen, "rn_init"); Bzero(rn_zeros, 3 * max_keylen); rn_ones = cp = rn_zeros + max_keylen; addmask_key = cplim = rn_ones + max_keylen; while (cp < cplim) *cp++ = -1; if (rn_inithead(&mask_rnhead, 0) == 0) panic("rn_init 2"); }
/* * Initialize our routing tree. */ int in_inithead(void **head, int off) { struct radix_node_head *rnh; if(!rn_inithead(head, off)) return 0; if(head != (void **)&rt_tables[AF_INET]) /* BOGUS! */ return 1; /* only do this for the real routing table */ rnh = *head; rnh->rnh_addaddr = in_addroute; rnh->rnh_matchaddr = in_matroute; rnh->rnh_close = in_clsroute; in_rtqtimo(rnh); /* kick off timeout first time */ return 1; }
/* * Initialize tree. */ int mpls_rn_inithead(void **rnh0, int off) { int error; struct radix_node_head *rnh; if ((error = rn_inithead(rnh0, off)) != 0) { rnh = *rnh0; rnh->rnh_close = mpls_rn_clsroute; rnh->rnh_deladdr = mpls_rn_delroute; rnh->rnh_matchaddr = mpls_rn_match; rnh->rnh_addaddr = mpls_rn_addroute; rnh->rnh_lookup = mpls_rn_lookup; } return (error); }
/* * Initialize our routing tree. */ int in6_inithead(void **head, int off) { struct radix_node_head *rnh; if (!rn_inithead(head, off)) return 0; if (head != (void **)&rt_tables[AF_INET6]) /* BOGUS! */ return 1; /* only do this for the real routing table */ rnh = *head; rnh->rnh_addaddr = in6_addroute; rnh->rnh_matchaddr = in6_matroute; rnh->rnh_close = in6_clsroute; callout_init(&rtq_timer, CALLOUT_MPSAFE); in6_rtqtimo(rnh); /* kick off timeout first time */ callout_init(&rtq_mtutimer, CALLOUT_MPSAFE); in6_mtutimo(rnh); /* kick off timeout first time */ return 1; }
/* * Initialize our routing tree. */ int in6_inithead(void **head, int off) { struct radix_node_head *rnh; if (!rn_inithead(head, rn_cpumaskhead(mycpuid), off)) return 0; if (head != (void **)&rt_tables[mycpuid][AF_INET6]) /* BOGUS! */ return 1; /* only do this for the real routing table */ rnh = *head; rnh->rnh_addaddr = in6_addroute; rnh->rnh_matchaddr = in6_matchroute; rnh->rnh_close = in6_clsroute; callout_init(&in6_mtutimo_ch[mycpuid]); callout_init(&in6_rtqtimo_ch[mycpuid]); in6_rtqtimo(rnh); /* kick off timeout first time */ in6_mtutimo(rnh); /* kick off timeout first time */ return 1; }
/* shim to adapt arguments */ int ipx_inithead(void **head, int offset) { return rn_inithead(head, offset); }
int ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr, uint8_t plen, uint8_t mlen, uint8_t type, uint32_t value) { struct radix_node_head *rnh, **rnh_ptr; struct table_entry *ent; struct table_xentry *xent; struct radix_node *rn; in_addr_t addr; int offset; void *ent_ptr; struct sockaddr *addr_ptr, *mask_ptr; char c; if (tbl >= V_fw_tables_max) return (EINVAL); switch (type) { case IPFW_TABLE_CIDR: if (plen == sizeof(in_addr_t)) { #ifdef INET /* IPv4 case */ if (mlen > 32) return (EINVAL); ent = malloc(sizeof(*ent), M_IPFW_TBL, M_WAITOK | M_ZERO); ent->value = value; /* Set 'total' structure length */ KEY_LEN(ent->addr) = KEY_LEN_INET; KEY_LEN(ent->mask) = KEY_LEN_INET; /* Set offset of IPv4 address in bits */ offset = OFF_LEN_INET; ent->mask.sin_addr.s_addr = htonl(mlen ? ~((1 << (32 - mlen)) - 1) : 0); addr = *((in_addr_t *)paddr); ent->addr.sin_addr.s_addr = addr & ent->mask.sin_addr.s_addr; /* Set pointers */ rnh_ptr = &ch->tables[tbl]; ent_ptr = ent; addr_ptr = (struct sockaddr *)&ent->addr; mask_ptr = (struct sockaddr *)&ent->mask; #endif #ifdef INET6 } else if (plen == sizeof(struct in6_addr)) { /* IPv6 case */ if (mlen > 128) return (EINVAL); xent = malloc(sizeof(*xent), M_IPFW_TBL, M_WAITOK | M_ZERO); xent->value = value; /* Set 'total' structure length */ KEY_LEN(xent->a.addr6) = KEY_LEN_INET6; KEY_LEN(xent->m.mask6) = KEY_LEN_INET6; /* Set offset of IPv6 address in bits */ offset = OFF_LEN_INET6; ipv6_writemask(&xent->m.mask6.sin6_addr, mlen); memcpy(&xent->a.addr6.sin6_addr, paddr, sizeof(struct in6_addr)); APPLY_MASK(&xent->a.addr6.sin6_addr, &xent->m.mask6.sin6_addr); /* Set pointers */ rnh_ptr = &ch->xtables[tbl]; ent_ptr = xent; addr_ptr = (struct sockaddr *)&xent->a.addr6; mask_ptr = (struct sockaddr *)&xent->m.mask6; #endif } else { /* Unknown CIDR type */ return (EINVAL); } break; case IPFW_TABLE_INTERFACE: /* Check if string is terminated */ c = ((char *)paddr)[IF_NAMESIZE - 1]; ((char *)paddr)[IF_NAMESIZE - 1] = '\0'; if (((mlen = strlen((char *)paddr)) == IF_NAMESIZE - 1) && (c != '\0')) return (EINVAL); /* Include last \0 into comparison */ mlen++; xent = malloc(sizeof(*xent), M_IPFW_TBL, M_WAITOK | M_ZERO); xent->value = value; /* Set 'total' structure length */ KEY_LEN(xent->a.iface) = KEY_LEN_IFACE + mlen; KEY_LEN(xent->m.ifmask) = KEY_LEN_IFACE + mlen; /* Set offset of interface name in bits */ offset = OFF_LEN_IFACE; memcpy(xent->a.iface.ifname, paddr, mlen); /* Assume direct match */ /* TODO: Add interface pattern matching */ #if 0 memset(xent->m.ifmask.ifname, 0xFF, IF_NAMESIZE); mask_ptr = (struct sockaddr *)&xent->m.ifmask; #endif /* Set pointers */ rnh_ptr = &ch->xtables[tbl]; ent_ptr = xent; addr_ptr = (struct sockaddr *)&xent->a.iface; mask_ptr = NULL; break; default: return (EINVAL); } IPFW_WLOCK(ch); /* Check if tabletype is valid */ if ((ch->tabletype[tbl] != 0) && (ch->tabletype[tbl] != type)) { IPFW_WUNLOCK(ch); free(ent_ptr, M_IPFW_TBL); return (EINVAL); } /* Check if radix tree exists */ if ((rnh = *rnh_ptr) == NULL) { IPFW_WUNLOCK(ch); /* Create radix for a new table */ if (!rn_inithead((void **)&rnh, offset)) { free(ent_ptr, M_IPFW_TBL); return (ENOMEM); } IPFW_WLOCK(ch); if (*rnh_ptr != NULL) { /* Tree is already attached by other thread */ rn_detachhead((void **)&rnh); rnh = *rnh_ptr; /* Check table type another time */ if (ch->tabletype[tbl] != type) { IPFW_WUNLOCK(ch); free(ent_ptr, M_IPFW_TBL); return (EINVAL); } } else { *rnh_ptr = rnh; /* * Set table type. It can be set already * (if we have IPv6-only table) but setting * it another time does not hurt */ ch->tabletype[tbl] = type; } } rn = rnh->rnh_addaddr(addr_ptr, mask_ptr, rnh, ent_ptr); IPFW_WUNLOCK(ch); if (rn == NULL) { free(ent_ptr, M_IPFW_TBL); return (EEXIST); } return (0); }
tuba_table_init() { rn_inithead((void **)&tuba_tree, 0); timeout(tuba_timer, (caddr_t)0, arpt_prune * hz); }
int main(int argc, char **argv) { /* 32 таблицы ип локальных адресов */ struct t_ip_groups groups; char ch; struct sockaddr_in tmp; const struct { char *local_ips_name; char *logfile_name; double bw; int print_report1; int print_report2; int print_report3; } defaults = {"locals.txt", "-", 4*1000000, 0, 0, 0}; struct { const char *local_ips_name; FILE *local_ips; const char *logfile_name; FILE *logfile; double bw; int print_report1; int print_report2; int print_report3; }params; params.local_ips_name = strdup(defaults.local_ips_name); params.logfile_name = strdup(defaults.logfile_name); params.bw = defaults.bw; params.print_report1 = defaults.print_report1; params.print_report2 = defaults.print_report2; params.print_report3 = defaults.print_report3; while ((ch = getopt(argc, argv, "123c:f:m:")) != -1) { switch (ch) { case '1': params.print_report1 = 1; break; case '2': params.print_report2 = 1; break; case '3': params.print_report3 = 1; break; case 'c': free((void *)params.local_ips_name); params.local_ips_name=strdup(optarg); break; case 'f': free((void *)params.logfile_name); params.logfile_name = strdup(optarg); break; case 'm': sscanf(optarg, "%lf", ¶ms.bw); params.bw = params.bw*1000000; break; case 'h': case '?': default: usage(); return 0; break; } } argc -= optind; argv += optind; params.local_ips = my_fopen(params.local_ips_name); if ( params.local_ips == NULL) { char buf[80]; snprintf(buf, sizeof(buf), "cannot open config file %s", params.local_ips_name); perror (buf); return -1; } rn_init(); if ( !rn_inithead((void **)&groups.ips, ((uint8_t *)&tmp.sin_addr - (uint8_t *)&tmp) * 8)) { fprintf(stderr, "cannot init group"); return -1; } if ( load_ip_config(params.local_ips, &groups) < 0) { fprintf(stderr, "can not load config file\n"); return -2; } params.logfile = my_fopen(params.logfile_name); if ( params.logfile == NULL) { char buf[80]; snprintf(buf, sizeof(buf), "cannot open log file %s", params.logfile_name); perror (buf); return -3; } if ( load_ip_stats(params.logfile, &groups) < 0) { fprintf(stderr, "cannot load stats file\n"); return -4; } groups.bw = params.bw; if (params.print_report1) print_full_time_log(stdout, &groups); if (params.print_report2) calc_n_print_hour_log(stdout, &groups); if (params.print_report3) print_unformatted_time_log(stdout, &groups); fclose(params.local_ips); fclose(params.logfile); return 0; }
static int ipx_inithead(void **head, int off) { return rn_inithead(head, rn_cpumaskhead(mycpuid), off); }