struct ospf_interface * ospf_if_new (struct ospf *ospf, struct interface_FOO *ifp, struct prefix *p) { struct ospf_interface *oi; if ((oi = ospf_if_table_lookup (ifp, p)) == NULL) { oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface)); memset (oi, 0, sizeof (struct ospf_interface)); } else return oi; /* Set zebra interface pointer. */ oi->ifp = ifp; oi->address = p; ospf_add_to_if (ifp, oi); listnode_add (ospf->oiflist, oi); /* Clear self-originated network-LSA. */ oi->network_lsa_self = NULL; /* Initialize neighbor list. */ oi->nbrs = route_table_init (); /* Initialize static neighbor list. */ oi->nbr_nbma = list_new (); /* Initialize Link State Acknowledgment list. */ oi->ls_ack = list_new (); oi->ls_ack_direct.ls_ack = list_new (); /* Set default values. */ ospf_if_reset_variables (oi); /* Add pseudo neighbor. */ oi->nbr_self = ospf_nbr_new (oi); oi->nbr_self->state = NSM_TwoWay; oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority); oi->nbr_self->options = OSPF_OPTION_E; oi->ls_upd_queue = route_table_init (); oi->t_ls_upd_event = NULL; oi->t_ls_ack_direct = NULL; oi->crypt_seqnum = time (NULL); #ifdef HAVE_OPAQUE_LSA ospf_opaque_type9_lsa_init (oi); #endif /* HAVE_OPAQUE_LSA */ oi->ospf = ospf; return oi; }
struct isis_area * isis_area_create () { struct isis_area *area; area = calloc(1, sizeof (struct isis_area)); /* * The first instance is level-1-2 rest are level-1, unless otherwise * configured */ if (listcount (isis->area_list) > 0) area->is_type = IS_LEVEL_1; else area->is_type = IS_LEVEL_1_AND_2; /* * intialize the databases */ area->lspdb[0] = lsp_db_init (); area->lspdb[1] = lsp_db_init (); spftree_area_init (area); area->route_table[0] = route_table_init (); area->route_table[1] = route_table_init (); #ifdef ENABLE_IPV6 area->route_table6[0] = route_table_init (); area->route_table6[1] = route_table_init (); #endif /* ENABLE_IPV6 */ area->circuit_list = isis_list_new (); area->area_addrs = isis_list_new (); flags_initialize (&area->flags); /* * Default values */ area->max_lsp_lifetime[0] = MAX_AGE; /* 1200 */ area->max_lsp_lifetime[1] = MAX_AGE; /* 1200 */ area->lsp_gen_interval[0] = LSP_GEN_INTERVAL_DEFAULT; area->lsp_gen_interval[1] = LSP_GEN_INTERVAL_DEFAULT; area->lsp_refresh[0] = MAX_LSP_GEN_INTERVAL; /* 900 */ area->lsp_refresh[1] = MAX_LSP_GEN_INTERVAL; /* 900 */ area->min_spf_interval[0] = MINIMUM_SPF_INTERVAL; area->min_spf_interval[1] = MINIMUM_SPF_INTERVAL; area->dynhostname = 1; area->oldmetric = 1; area->lsp_frag_threshold = 90; /* FIXME: Think of a better way... */ area->min_bcast_mtu = 1497; return area; }
static struct ospf6 *ospf6_create(void) { struct ospf6 *o; o = XCALLOC(MTYPE_OSPF6_TOP, sizeof(struct ospf6)); /* initialize */ monotime(&o->starttime); o->area_list = list_new(); o->area_list->cmp = ospf6_area_cmp; o->lsdb = ospf6_lsdb_create(o); o->lsdb_self = ospf6_lsdb_create(o); o->lsdb->hook_add = ospf6_top_lsdb_hook_add; o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove; o->spf_delay = OSPF_SPF_DELAY_DEFAULT; o->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT; o->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT; o->spf_hold_multiplier = 1; /* LSA timers value init */ o->lsa_minarrival = OSPF_MIN_LS_ARRIVAL; o->route_table = OSPF6_ROUTE_TABLE_CREATE(GLOBAL, ROUTES); o->route_table->scope = o; o->route_table->hook_add = ospf6_top_route_hook_add; o->route_table->hook_remove = ospf6_top_route_hook_remove; o->brouter_table = OSPF6_ROUTE_TABLE_CREATE(GLOBAL, BORDER_ROUTERS); o->brouter_table->scope = o; o->brouter_table->hook_add = ospf6_top_brouter_hook_add; o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove; o->external_table = OSPF6_ROUTE_TABLE_CREATE(GLOBAL, EXTERNAL_ROUTES); o->external_table->scope = o; o->external_id_table = route_table_init(); o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH; o->distance_table = route_table_init(); /* Enable "log-adjacency-changes" */ #if DFLT_OSPF6_LOG_ADJACENCY_CHANGES SET_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES); #endif QOBJ_REG(o, ospf6); return o; }
struct ospf_interface * ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p) { struct ospf_interface *oi; if ((oi = ospf_if_table_lookup (ifp, p)) == NULL) { oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface)); memset (oi, 0, sizeof (struct ospf_interface)); } else return oi; /* Set zebra interface pointer. */ oi->ifp = ifp; oi->address = p; ospf_add_to_if (ifp, oi); listnode_add (ospf->oiflist, oi); /* Initialize neighbor list. */ oi->nbrs = route_table_init (); /* Initialize static neighbor list. */ oi->nbr_nbma = list_new (); /* Initialize Link State Acknowledgment list. */ oi->ls_ack = list_new (); oi->ls_ack_direct.ls_ack = list_new (); /* Set default values. */ ospf_if_reset_variables (oi); /* Add pseudo neighbor. */ oi->nbr_self = ospf_nbr_new (oi); oi->ls_upd_queue = route_table_init (); oi->t_ls_upd_event = NULL; oi->t_ls_ack_direct = NULL; oi->crypt_seqnum = time (NULL); ospf_opaque_type9_lsa_init (oi); oi->ospf = ospf; return oi; }
static struct ospf6 * ospf6_create (void) { struct ospf6 *o; o = XCALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6)); /* initialize */ quagga_gettime (QUAGGA_CLK_MONOTONIC, &o->starttime); o->area_list = list_new (); o->area_list->cmp = ospf6_area_cmp; o->lsdb = ospf6_lsdb_create (o); o->lsdb_self = ospf6_lsdb_create (o); o->lsdb->hook_add = ospf6_top_lsdb_hook_add; o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove; o->route_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, ROUTES); o->route_table->scope = o; o->route_table->hook_add = ospf6_top_route_hook_add; o->route_table->hook_remove = ospf6_top_route_hook_remove; o->brouter_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, BORDER_ROUTERS); o->brouter_table->scope = o; o->brouter_table->hook_add = ospf6_top_brouter_hook_add; o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove; o->external_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, EXTERNAL_ROUTES); o->external_table->scope = o; o->external_id_table = route_table_init (); return o; }
int ospf_if_new_hook (struct interface *ifp) { int rc = 0; ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info)); memset (ifp->info, 0, sizeof (struct ospf_if_info)); IF_OIFS (ifp) = route_table_init (); IF_OIFS_PARAMS (ifp) = route_table_init (); IF_DEF_PARAMS (ifp) = ospf_new_if_params (); SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay); IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval); IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority); IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT; IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT; SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface); IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE; SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello); IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello); IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT; SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait); IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple); memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type); IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET; #ifdef HAVE_OPAQUE_LSA rc = ospf_opaque_new_if (ifp); #endif /* HAVE_OPAQUE_LSA */ return rc; }
/* Register RIPv2-MIB. */ void rip_snmp_init () { rip_ifaddr_table = route_table_init (); smux_init (master); REGISTER_MIB("mibII/rip", rip_variables, variable, rip_oid); }
/* Register RIPv2-MIB. */ void rip_snmp_init () { rip_ifaddr_table = route_table_init (); smux_init (ripd_oid, sizeof (ripd_oid) / sizeof (oid)); REGISTER_MIB("mibII/rip", rip_variables, variable, rip_oid); smux_start (); }
void nhrp_zebra_init(void) { zebra_rib[AFI_IP] = route_table_init(); zebra_rib[AFI_IP6] = route_table_init(); zclient = zclient_new(master, &zclient_options_default); zclient->zebra_connected = nhrp_zebra_connected; zclient->interface_add = nhrp_interface_add; zclient->interface_delete = nhrp_interface_delete; zclient->interface_up = nhrp_interface_up; zclient->interface_down = nhrp_interface_down; zclient->interface_address_add = nhrp_interface_address_add; zclient->interface_address_delete = nhrp_interface_address_delete; zclient->redistribute_route_add = nhrp_route_read; zclient->redistribute_route_del = nhrp_route_read; zclient_init(zclient, ZEBRA_ROUTE_NHRP, 0, &nhrpd_privs); }
int ip4_module_shared_init(struct ip4_module_shared *pms, struct in_addr *network, struct in_addr *netmask, struct in_addr *default_route) { int rv; pms->rt = route_table_new(ROUTE_TABLE_CAPACITY_MIN); if (!pms->rt) return -1; rv = route_table_init(pms->rt, network, netmask, default_route); if (rv < 0) return -1; return 1; }
struct ospf6_lsdb * ospf6_lsdb_create (void *data) { struct ospf6_lsdb *lsdb; lsdb = XCALLOC (MTYPE_OSPF6_LSDB, sizeof (struct ospf6_lsdb)); if (lsdb == NULL) { zlog_warn ("Can't malloc lsdb"); return NULL; } memset (lsdb, 0, sizeof (struct ospf6_lsdb)); lsdb->data = data; lsdb->table = route_table_init (); return lsdb; }
/* Called when new interface is added. */ static int if_zebra_new_hook (struct interface *ifp) { struct zebra_if *zebra_if; zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if)); zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC; zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_UNSPEC; #ifdef RTADV { /* Set default router advertise values. */ struct rtadvconf *rtadv; rtadv = &zebra_if->rtadv; rtadv->AdvSendAdvertisements = 0; rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL; rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL; rtadv->AdvIntervalTimer = 0; rtadv->AdvManagedFlag = 0; rtadv->AdvOtherConfigFlag = 0; rtadv->AdvHomeAgentFlag = 0; rtadv->AdvLinkMTU = 0; rtadv->AdvReachableTime = 0; rtadv->AdvRetransTimer = 0; rtadv->AdvCurHopLimit = 0; rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */ rtadv->HomeAgentPreference = 0; rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */ rtadv->AdvIntervalOption = 0; rtadv->DefaultPreference = RTADV_PREF_MEDIUM; rtadv->AdvPrefixList = list_new (); } #endif /* RTADV */ /* Initialize installed address chains tree. */ zebra_if->ipv4_subnets = route_table_init (); ifp->info = zebra_if; return 0; }
/* Make new area structure */ struct ospf6_area * ospf6_area_create (u_int32_t area_id) { struct ospf6_area *o6a; /* allocate memory */ o6a = (struct ospf6_area *) XMALLOC (MTYPE_OSPF6_AREA, sizeof (struct ospf6_area)); if (!o6a) { char str[16]; inet_ntop (AF_INET, &area_id, str, sizeof (str)); zlog_err ("can't allocate memory for Area %s", str); return NULL; } /* initialize */ memset (o6a, 0, sizeof (struct ospf6_area)); inet_ntop (AF_INET, &area_id, o6a->str, sizeof (o6a->str)); o6a->area_id = area_id; o6a->if_list = list_new (); #if 0 o6a->lsdb = list_new (); #endif o6a->lsdb = ospf6_lsdb_create (); o6a->spf_tree = ospf6_spftree_create (); o6a->table_topology = route_table_init (); /* xxx, set options */ OSPF6_OPT_SET (o6a->options, OSPF6_OPT_V6); OSPF6_OPT_SET (o6a->options, OSPF6_OPT_E); OSPF6_OPT_SET (o6a->options, OSPF6_OPT_R); o6a->foreach_if = ospf6_area_foreach_interface; o6a->foreach_nei = ospf6_area_foreach_neighbor; return o6a; }
static struct ospf6 * ospf6_create (void) { struct ospf6 *o; o = XCALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6)); /* initialize */ quagga_gettime (QUAGGA_CLK_MONOTONIC, &o->starttime); o->area_list = list_new (); o->area_list->cmp = ospf6_area_cmp; o->lsdb = ospf6_lsdb_create (o); o->lsdb_self = ospf6_lsdb_create (o); o->lsdb->hook_add = ospf6_top_lsdb_hook_add; o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove; o->spf_delay = OSPF_SPF_DELAY_DEFAULT; o->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT; o->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT; o->spf_hold_multiplier = 1; o->route_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, ROUTES); o->route_table->scope = o; o->route_table->hook_add = ospf6_top_route_hook_add; o->route_table->hook_remove = ospf6_top_route_hook_remove; o->brouter_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, BORDER_ROUTERS); o->brouter_table->scope = o; o->brouter_table->hook_add = ospf6_top_brouter_hook_add; o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove; o->external_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, EXTERNAL_ROUTES); o->external_table->scope = o; o->external_id_table = route_table_init (); o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH; return o; }
struct ospf_interface * ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p) { struct ospf_interface *oi; struct ifreq ifreq; int liteid; if ((oi = ospf_if_table_lookup (ifp, p)) == NULL) { oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface)); memset (oi, 0, sizeof (struct ospf_interface)); } else return oi; /* Set zebra interface pointer. */ oi->ifp = ifp; oi->address = p; ospf_add_to_if (ifp, oi); listnode_add (ospf->oiflist, oi); /* Clear self-originated network-LSA. */ oi->network_lsa_self = NULL; /* Initialize neighbor list. */ oi->nbrs = route_table_init (); /* Initialize static neighbor list. */ oi->nbr_nbma = list_new (); /* Initialize Link State Acknowledgment list. */ oi->ls_ack = list_new (); oi->ls_ack_direct.ls_ack = list_new (); /* Set default values. */ ospf_if_reset_variables (oi); /* Add pseudo neighbor. */ oi->nbr_self = ospf_nbr_new (oi); oi->ls_upd_queue = route_table_init (); oi->t_ls_upd_event = NULL; oi->t_ls_ack_direct = NULL; oi->crypt_seqnum = time (NULL); #ifdef HAVE_OPAQUE_LSA ospf_opaque_type9_lsa_init (oi); #ifdef HAVE_GRACEFUL_RESTART oi->gr_helping_list= list_new(); oi->gr_lsa = NULL; oi->t_opaque_lsa_refresh = NULL; #endif #endif /* HAVE_OPAQUE_LSA */ oi->ospf = ospf; if((oi->packet_fd = ospf_sock_init(OSPF_IP_OTHER_PACKET))<0) { exit(1); } liteid = oi->ospf->litevrfid; setsockopt (oi->packet_fd, SOL_SOCKET, SO_SET_LITEVRFID, (char *) &liteid, sizeof (int)); strncpy ((char *)&ifreq.ifr_name,ifp->name,sizeof(ifreq.ifr_name)); setsockopt (oi->packet_fd, SOL_SOCKET, SO_BINDTODEVICE, &ifreq, sizeof (ifreq)); if(oi->t_packet_read == NULL) oi->t_packet_read = thread_add_read (master, ospf_read_oisock, oi, oi->packet_fd); return oi; }
int main() { int rv; struct in_addr network, netmask, default_route, next_hop; struct route_table *rt; char src[32]; char dst[32]; rt = route_table_new(32); assert(rt); inet_pton(AF_INET, "192.168.37.0", &network); inet_pton(AF_INET, "255.255.255.0", &netmask); inet_pton(AF_INET, "192.168.37.1", &default_route); rv = route_table_init(rt, &network, &netmask, &default_route); if (rv < 0) { printf("init error\n"); return -1; } inet_pton(AF_INET, "6.6.6.4", &network); inet_pton(AF_INET, "255.255.255.252", &netmask); inet_pton(AF_INET, "192.168.37.2", &next_hop); rv = route_table_add(rt, 0, &network, &netmask, &next_hop); if (rv < 0) { printf("add error\n"); return -1; } printf("route table:\n"); route_table_print(rt); printf("*************\n"); inet_pton(AF_INET, "192.168.37.1", &network); rv = route_table_get_route(rt, &network, &next_hop); if (rv > 0) { inet_ntop(AF_INET, &network, src, 32); inet_ntop(AF_INET, &next_hop, dst, 32); printf("%s -> %s\n", src, dst); } inet_pton(AF_INET, "192.168.37.11", &network); rv = route_table_get_route(rt, &network, &next_hop); if (rv > 0) { inet_ntop(AF_INET, &network, src, 32); inet_ntop(AF_INET, &next_hop, dst, 32); printf("%s -> %s\n", src, dst); } inet_pton(AF_INET, "127.0.0.1", &network); rv = route_table_get_route(rt, &network, &next_hop); if (rv > 0) { inet_ntop(AF_INET, &network, src, 32); inet_ntop(AF_INET, &next_hop, dst, 32); printf("%s -> %s\n", src, dst); } inet_pton(AF_INET, "6.6.6.3", &network); rv = route_table_get_route(rt, &network, &next_hop); if (rv > 0) { inet_ntop(AF_INET, &network, src, 32); inet_ntop(AF_INET, &next_hop, dst, 32); printf("%s -> %s\n", src, dst); } inet_pton(AF_INET, "6.6.6.6", &network); rv = route_table_get_route(rt, &network, &next_hop); if (rv > 0) { inet_ntop(AF_INET, &network, src, 32); inet_ntop(AF_INET, &next_hop, dst, 32); printf("%s -> %s\n", src, dst); } inet_pton(AF_INET, "6.6.6.8", &network); rv = route_table_get_route(rt, &network, &next_hop); if (rv > 0) { inet_ntop(AF_INET, &network, src, 32); inet_ntop(AF_INET, &next_hop, dst, 32); printf("%s -> %s\n", src, dst); } route_table_delete(rt); return 0; }