enum pim_msdp_err pim_msdp_mg_src_add(struct pim_instance *pim, const char *mesh_group_name, struct in_addr src_ip) { int rc; struct pim_msdp_mg_mbr *mbr; struct listnode *mbr_node; struct pim_msdp_mg *mg; if (src_ip.s_addr == INADDR_ANY) { pim_msdp_mg_src_del(pim, mesh_group_name); return PIM_MSDP_ERR_NONE; } rc = pim_msdp_mg_add(pim, mesh_group_name); if (rc != PIM_MSDP_ERR_NONE) { return rc; } mg = pim->msdp.mg; if (mg->src_ip.s_addr != INADDR_ANY) { pim_msdp_mg_src_do_del(pim); } mg->src_ip = src_ip; for (ALL_LIST_ELEMENTS_RO(mg->mbr_list, mbr_node, mbr)) { pim_msdp_peer_add(pim, mbr->mbr_ip, mg->src_ip, mesh_group_name, &mbr->mp); } if (PIM_DEBUG_MSDP_EVENTS) { char ip_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", mg->src_ip, ip_str, sizeof(ip_str)); zlog_debug("MSDP mesh-group %s src %s set", mg->mesh_group_name, ip_str); } return PIM_MSDP_ERR_NONE; }
static void dump_if_address(struct interface *ifp) { struct connected *ifc; struct listnode *node; zlog_debug("%s %s: interface %s addresses:", __FILE__, __PRETTY_FUNCTION__, ifp->name); for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { struct prefix *p = ifc->address; if (p->family != AF_INET) continue; zlog_debug("%s %s: interface %s address %s %s", __FILE__, __PRETTY_FUNCTION__, ifp->name, inet_ntoa(p->u.prefix4), CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); } }
static void dr_election_by_addr(struct interface *ifp) { struct pim_interface *pim_ifp; struct listnode *node; struct pim_neighbor *neigh; pim_ifp = ifp->info; zassert(pim_ifp); pim_ifp->pim_dr_addr = pim_ifp->primary_address; if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: on interface %s", __PRETTY_FUNCTION__, ifp->name); } for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { if (ntohl(neigh->source_addr.s_addr) > ntohl(pim_ifp->pim_dr_addr.s_addr)) { pim_ifp->pim_dr_addr = neigh->source_addr; } } }
/* Find the IPv4 address on our side that will be used when packets are sent to dst. */ struct connected * connected_lookup_address (struct interface *ifp, struct in_addr dst) { struct prefix addr; struct listnode *cnode; struct connected *c; struct connected *match; addr.family = AF_INET; addr.u.prefix4 = dst; addr.prefixlen = IPV4_MAX_BITLEN; match = NULL; for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { if (c->address && (c->address->family == AF_INET) && prefix_match(CONNECTED_PREFIX(c), &addr) && (!match || (c->address->prefixlen > match->address->prefixlen))) match = c; } return match; }
/** * @fn eigrp_nbr_lookup_by_addr_process * * @param[in] eigrp EIGRP process * @param[in] nbr_addr Address of neighbor * * @return void * * @par * Function is used for neighbor lookup by address * in whole EIGRP process. */ struct eigrp_neighbor * eigrp_nbr_lookup_by_addr_process (struct eigrp *eigrp, struct in_addr nbr_addr) { struct eigrp_interface *ei; struct listnode *node, *node2, *nnode2; struct eigrp_neighbor *nbr; /* iterate over all eigrp interfaces */ for (ALL_LIST_ELEMENTS_RO (eigrp->eiflist, node, ei)) { /* iterate over all neighbors on eigrp interface */ for (ALL_LIST_ELEMENTS (ei->nbrs, node2, nnode2, nbr)) { /* compare if neighbor address is same as arg address */ if (nbr->src.s_addr == nbr_addr.s_addr) { return nbr; } } } return NULL; }
static uint16_t find_neighbors_next_highest_override_interval_msec(struct interface *ifp, struct pim_neighbor *highest_neigh) { struct pim_interface *pim_ifp; struct listnode *neigh_node; struct pim_neighbor *neigh; uint16_t next_highest_interval_msec; pim_ifp = ifp->info; zassert(pim_ifp); next_highest_interval_msec = pim_ifp->pim_override_interval_msec; for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neigh_node, neigh)) { if (neigh == highest_neigh) continue; if (neigh->override_interval_msec > next_highest_interval_msec) next_highest_interval_msec = neigh->override_interval_msec; } return next_highest_interval_msec; }
struct key * key_lookup_for_accept (const struct keychain *keychain, u_int32_t index) { struct listnode *node; struct key *key; time_t now; now = time (NULL); for (ALL_LIST_ELEMENTS_RO (keychain->key, node, key)) { if (key->index >= index) { if (key->accept.start == 0) return key; if (key->accept.start <= now) if (key->accept.end >= now || key->accept.end == -1) return key; } } return NULL; }
/* Lookup interface by IPv4 address. */ struct interface * if_lookup_exact_address (struct in_addr src) { struct listnode *cnode; struct interface *ifp = NULL; struct prefix *p; struct connected *c; int idx = 0; while (idx < get_max_port ()) { for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { p = c->address; if (p && p->family == AF_INET) { if (IPV4_ADDR_SAME (&p->u.prefix4, &src)) return ifp; } } idx++; } return NULL; }
static void pim_msdp_up_xg_del(struct pim_instance *pim, struct prefix_sg *sg) { struct listnode *sanode; struct pim_msdp_sa *sa; if (PIM_DEBUG_MSDP_INTERNAL) { zlog_debug("MSDP %s del", pim_str_sg_dump(sg)); } /* If this is not really an XG entry just move on */ if ((sg->src.s_addr != INADDR_ANY) || (sg->grp.s_addr == INADDR_ANY)) { return; } /* XXX: Need to maintain SAs per-group to avoid all this unnecessary * walking */ for (ALL_LIST_ELEMENTS_RO(pim->msdp.sa_list, sanode, sa)) { if (sa->sg.grp.s_addr != sg->grp.s_addr) { continue; } pim_msdp_sa_upstream_update(sa, NULL /* xg */, "up-jp-change"); } }
static struct ospf_neighbor * ospf_elect_dr (struct ospf_interface *oi, struct list *el_list) { struct list *dr_list; struct listnode *node; struct ospf_neighbor *nbr, *dr = NULL, *bdr = NULL; dr_list = list_new (); /* Add neighbors to the list. */ for (ALL_LIST_ELEMENTS_RO (el_list, node, nbr)) { /* neighbor declared to be DR. */ if (NBR_IS_DR (nbr)) listnode_add (dr_list, nbr); /* Preserve neighbor BDR. */ if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4)) bdr = nbr; } /* Elect Designated Router. */ if (listcount (dr_list) > 0) dr = ospf_dr_election_sub (dr_list); else dr = bdr; /* Set DR to interface. */ if (dr) DR (oi) = dr->address.u.prefix4; else DR (oi).s_addr = 0; list_delete (dr_list); return dr; }
static void delete_prefix_list(struct pim_neighbor *neigh) { if (neigh->prefix_list) { #ifdef DUMP_PREFIX_LIST struct listnode *p_node; struct prefix *p; char addr_str[10]; int list_size = neigh->prefix_list ? (int) listcount(neigh->prefix_list) : -1; int i = 0; for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, p_node, p)) { pim_inet4_dump("<addr?>", p->u.prefix4, addr_str, sizeof(addr_str)); zlog_debug("%s: DUMP_PREFIX_LIST neigh=%x prefix_list=%x prefix=%x addr=%s [%d/%d]", __PRETTY_FUNCTION__, (unsigned) neigh, (unsigned) neigh->prefix_list, (unsigned) p, addr_str, i, list_size); ++i; } #endif list_delete(neigh->prefix_list); neigh->prefix_list = 0; } }
static void router_id_set (struct prefix *p, vrf_id_t vrf_id) { struct prefix p2; struct listnode *node; struct zserv *client; struct zebra_vrf *zvrf; if (p->u.prefix4.s_addr == 0) /* unset */ { zvrf = vrf_info_lookup (vrf_id); if (! zvrf) return; } else /* set */ zvrf = vrf_info_get (vrf_id); zvrf->rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr; router_id_get (&p2, vrf_id); for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client)) zsend_router_id_update (client, &p2, vrf_id); }
//extern void rw_finalString(Rewriter*_this,FILE * out) extern void finalString(struct list * tokens,u8 * ori, u32 len, FILE *out) { u32 pos = 0 ; u32 act = 0 ; struct listnode * node; RwRecord * rec ; u32 cnt = 0 ; for(ALL_LIST_ELEMENTS_RO(tokens,node,rec) ) { act = rec->position ; cnt ++ ; if( cnt >= listcount(tokens) - 2 ) cnt = 0 ; if( act > pos ) { fwrite(ori+pos,1,act-pos,out); pos=act; } // delete if( rec->insert == NULL ) { pos+=rec->length; } // insert else { fwrite(rec->insert,1,rec->length,out); } } if( pos < len ) { fwrite(ori+pos,1,len-pos,out); } }
static void ospf6_spf_log_database (struct ospf6_area *oa) { char *p, *end, buffer[256]; struct listnode *node; struct ospf6_interface *oi; p = buffer; end = buffer + sizeof (buffer); snprintf (p, end - p, "SPF on DB (#LSAs):"); p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); snprintf (p, end - p, " Area %s: %d", oa->name, oa->lsdb->count); p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); for (ALL_LIST_ELEMENTS_RO (oa->if_list, node, oi)) { snprintf (p, end - p, " I/F %s: %d", oi->interface->name, oi->lsdb->count); p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); } zlog_debug ("%s", buffer); }
/* elect DR and BDR. Refer to RFC2319 section 9.4 */ static struct ospf_neighbor * ospf_dr_election_sub (struct list *routers) { struct listnode *node; struct ospf_neighbor *nbr, *max = NULL; /* Choose highest router priority. In case of tie, choose highest Router ID. */ for (ALL_LIST_ELEMENTS_RO (routers, node, nbr)) { if (max == NULL) max = nbr; else { if (max->priority < nbr->priority) max = nbr; else if (max->priority == nbr->priority) if (IPV4_ADDR_CMP (&max->router_id, &nbr->router_id) < 0) max = nbr; } } return max; }
int pim_global_config_write(struct vty *vty) { int writes = 0; if (PIM_MROUTE_IS_ENABLED) { vty_out(vty, "%s%s", PIM_CMD_IP_MULTICAST_ROUTING, VTY_NEWLINE); ++writes; } if (qpim_ssmpingd_list) { struct listnode *node; struct ssmpingd_sock *ss; vty_out(vty, "!%s", VTY_NEWLINE); ++writes; for (ALL_LIST_ELEMENTS_RO(qpim_ssmpingd_list, node, ss)) { char source_str[100]; pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str)); vty_out(vty, "ip ssmpingd %s%s", source_str, VTY_NEWLINE); ++writes; } } return writes; }
RwConfig * OWXmlLookup(struct list ** _OWJ, u8 * name, u32 flg, u32 len ) { RwConfig * conf; struct listnode * node; if( len >= 60 ) { return NULL; } if( len >= KEY_NAME_MAX_LEN || _OWJ[len] == NULL ) return NULL; for( ALL_LIST_ELEMENTS_RO(_OWJ[len],node,conf) ) { /*if( strncmp((const char*)conf->name,(const char*)name,len)) continue;*/ if( (conf->flg & flg) != flg ) continue; if( conf->flg & _const_is_property ) { if( 0==strncasecmp((const char*)conf->name,(const char*)name,len)) { return conf ; } } else { if( 0==strncasecmp( (const char*)conf->lowerCase, (const char*)name,len)) { return conf ; } } } return NULL; }
static void bgp_dump_routes_index_table(struct bgp *bgp) { struct peer *peer; struct listnode *node; uint16_t peerno = 0; struct stream *obuf; obuf = bgp_dump_obuf; stream_reset (obuf); /* MRT header */ bgp_dump_header (obuf, MSG_TABLE_DUMP_V2, TABLE_DUMP_V2_PEER_INDEX_TABLE, BGP_DUMP_ROUTES); /* Collector BGP ID */ stream_put_in_addr (obuf, &bgp->router_id); /* View name */ if(bgp->name) { stream_putw (obuf, strlen(bgp->name)); stream_put(obuf, bgp->name, strlen(bgp->name)); } else { stream_putw(obuf, 0); } /* Peer count */ stream_putw (obuf, listcount(bgp->peer)); /* Walk down all peers */ for(ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer)) { /* Peer's type */ if (sockunion_family(&peer->su) == AF_INET) { stream_putc (obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4+TABLE_DUMP_V2_PEER_INDEX_TABLE_IP); } else if (sockunion_family(&peer->su) == AF_INET6) { stream_putc (obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4+TABLE_DUMP_V2_PEER_INDEX_TABLE_IP6); } /* Peer's BGP ID */ stream_put_in_addr (obuf, &peer->remote_id); /* Peer's IP address */ if (sockunion_family(&peer->su) == AF_INET) { stream_put_in_addr (obuf, &peer->su.sin.sin_addr); } else if (sockunion_family(&peer->su) == AF_INET6) { stream_write (obuf, (u_char *)&peer->su.sin6.sin6_addr, IPV6_MAX_BYTELEN); } /* Peer's AS number. */ /* Note that, as this is an AS4 compliant quagga, the RIB is always AS4 */ stream_putl (obuf, peer->as); /* Store the peer number for this peer */ peer->table_dump_index = peerno; peerno++; } bgp_dump_set_size(obuf, MSG_TABLE_DUMP_V2); fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_routes.fp); fflush (bgp_dump_routes.fp); }
static u_char * ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_lsa *lsa = NULL; struct in_addr area_id; u_int16_t type; struct in_addr id; struct in_addr adv_router; int len; oid *offset; int offsetlen; char a[16], b[16], c[16]; struct ospf6_area *oa; struct listnode *node; memset (&area_id, 0, sizeof (struct in_addr)); type = 0; memset (&id, 0, sizeof (struct in_addr)); memset (&adv_router, 0, sizeof (struct in_addr)); /* Check OSPFv3 instance. */ if (ospf6 == NULL) return NULL; /* Get variable length. */ offset = name + v->namelen; offsetlen = *length - v->namelen; #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \ (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE) if (exact && offsetlen != OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET) return NULL; /* Parse area-id */ len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); if (len) oid2in_addr (offset, len, &area_id); offset += len; offsetlen -= len; /* Parse type */ len = (offsetlen < 1 ? offsetlen : 1); if (len) type = htons (*offset); offset += len; offsetlen -= len; /* Parse Router-ID */ len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); if (len) oid2in_addr (offset, len, &adv_router); offset += len; offsetlen -= len; /* Parse LS-ID */ len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); if (len) oid2in_addr (offset, len, &id); offset += len; offsetlen -= len; ospf6_id2str (area_id.s_addr, a, sizeof (a)); ospf6_id2str (adv_router.s_addr, b, sizeof (b)); ospf6_id2str (id.s_addr, c, sizeof (c)); zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%lu magic=%d" " type=%#x adv_router=%s id=%s", a, exact, (u_long)*length, v->magic, ntohs (type), b, c); if (exact) { oa = ospf6_area_lookup (area_id.s_addr, ospf6); lsa = ospf6_lsdb_lookup (type, id.s_addr, adv_router.s_addr, oa->lsdb); } else { for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { if (lsa) continue; if (ntohl (oa->area_id) < ntohl (area_id.s_addr)) continue; lsa = ospf6_lsdb_lookup_next (type, id.s_addr, adv_router.s_addr, oa->lsdb); if (! lsa) { type = 0; memset (&id, 0, sizeof (struct in_addr)); memset (&adv_router, 0, sizeof (struct in_addr)); } } } if (! lsa) { zlog_debug ("SNMP respond: No LSA to return"); return NULL; } oa = OSPF6_AREA (lsa->lsdb->data); zlog_debug ("SNMP respond: area: %s lsa: %s", oa->name, lsa->name); /* Add Index (AreaId, Type, RouterId, Lsid) */ *length = v->namelen + OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET; offset = name + v->namelen; oid_copy_addr (offset, (struct in_addr *) &oa->area_id, IN_ADDR_SIZE); offset += IN_ADDR_SIZE; *offset = ntohs (lsa->header->type); offset++; oid_copy_addr (offset, (struct in_addr *) &lsa->header->adv_router, IN_ADDR_SIZE); offset += IN_ADDR_SIZE; oid_copy_addr (offset, (struct in_addr *) &lsa->header->id, IN_ADDR_SIZE); offset += IN_ADDR_SIZE; /* Return the current value of the variable */ switch (v->magic) { case OSPFv3AREALSDBAREAID: /* 1 */ area_id.s_addr = OSPF6_AREA (lsa->lsdb->data)->area_id; return SNMP_IPADDRESS (area_id); break; case OSPFv3AREALSDBTYPE: /* 2 */ return SNMP_INTEGER (ntohs (lsa->header->type)); break; case OSPFv3AREALSDBROUTERID: /* 3 */ adv_router.s_addr = lsa->header->adv_router; return SNMP_IPADDRESS (adv_router); break; case OSPFv3AREALSDBLSID: /* 4 */ id.s_addr = lsa->header->id; return SNMP_IPADDRESS (id); break; case OSPFv3AREALSDBSEQUENCE: /* 5 */ return SNMP_INTEGER (lsa->header->seqnum); break; case OSPFv3AREALSDBAGE: /* 6 */ ospf6_lsa_age_current (lsa); return SNMP_INTEGER (lsa->header->age); break; case OSPFv3AREALSDBCHECKSUM: /* 7 */ return SNMP_INTEGER (lsa->header->checksum); break; case OSPFv3AREALSDBADVERTISEMENT: /* 8 */ *var_len = ntohs (lsa->header->length); return (u_char *) lsa->header; break; case OSPFv3AREALSDBTYPEKNOWN: /* 9 */ return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ? SNMP_TRUE : SNMP_FALSE); break; default: return NULL; break; } return NULL; }
static u_char * ospfv3AreaEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_area *oa, *area = NULL; u_int32_t area_id = 0; struct listnode *node; unsigned int len; if (ospf6 == NULL) return NULL; len = *length - v->namelen; len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0); if (exact && len != sizeof (u_int32_t)) return NULL; if (len) oid2in_addr (name + v->namelen, len, (struct in_addr *) &area_id); zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu", inet_ntoa (* (struct in_addr *) &area_id), exact, len, (u_long)*length); for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { if (area == NULL) { if (len == 0) /* return first area entry */ area = oa; else if (exact && ntohl (oa->area_id) == ntohl (area_id)) area = oa; else if (ntohl (oa->area_id) > ntohl (area_id)) area = oa; } } if (area == NULL) return NULL; *length = v->namelen + sizeof (u_int32_t); oid_copy_addr (name + v->namelen, (struct in_addr *) &area->area_id, sizeof (u_int32_t)); zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu", inet_ntoa (* (struct in_addr *) &area->area_id), exact, len, (u_long)*length); switch (v->magic) { case OSPFv3AREAID: /* 1*/ return SNMP_IPADDRESS (INT32_INADDR (area->area_id)); break; case OSPFv3IMPORTASEXTERN: /* 2*/ return SNMP_INTEGER (ospf6->external_table->count); break; default: return NULL; break; } return NULL; }
/* Send router advertisement packet. */ static void rtadv_send_packet (int sock, struct interface *ifp) { struct msghdr msg; struct iovec iov; struct cmsghdr *cmsgptr; struct in6_pktinfo *pkt; struct sockaddr_in6 addr; #ifdef HAVE_STRUCT_SOCKADDR_DL struct sockaddr_dl *sdl; #endif /* HAVE_STRUCT_SOCKADDR_DL */ static void *adata = NULL; unsigned char buf[RTADV_MSG_SIZE]; struct nd_router_advert *rtadv; int ret; int len = 0; struct zebra_if *zif; struct rtadv_prefix *rprefix; u_char all_nodes_addr[] = {0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; struct listnode *node; /* * Allocate control message bufffer. This is dynamic because * CMSG_SPACE is not guaranteed not to call a function. Note that * the size will be different on different architectures due to * differing alignment rules. */ if (adata == NULL) { /* XXX Free on shutdown. */ adata = malloc(CMSG_SPACE(sizeof(struct in6_pktinfo))); if (adata == NULL) zlog_err("rtadv_send_packet: can't malloc control data\n"); } /* Logging of packet. */ if (IS_ZEBRA_DEBUG_PACKET) zlog_debug ("Router advertisement send to %s", ifp->name); /* Fill in sockaddr_in6. */ memset (&addr, 0, sizeof (struct sockaddr_in6)); addr.sin6_family = AF_INET6; #ifdef SIN6_LEN addr.sin6_len = sizeof (struct sockaddr_in6); #endif /* SIN6_LEN */ addr.sin6_port = htons (IPPROTO_ICMPV6); memcpy (&addr.sin6_addr, all_nodes_addr, sizeof (struct in6_addr)); /* Fetch interface information. */ zif = ifp->info; /* Make router advertisement message. */ rtadv = (struct nd_router_advert *) buf; rtadv->nd_ra_type = ND_ROUTER_ADVERT; rtadv->nd_ra_code = 0; rtadv->nd_ra_cksum = 0; rtadv->nd_ra_curhoplimit = 64; /* RFC4191: Default Router Preference is 0 if Router Lifetime is 0. */ rtadv->nd_ra_flags_reserved = zif->rtadv.AdvDefaultLifetime == 0 ? 0 : zif->rtadv.DefaultPreference; rtadv->nd_ra_flags_reserved <<= 3; if (zif->rtadv.AdvManagedFlag) rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_MANAGED; if (zif->rtadv.AdvOtherConfigFlag) rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_OTHER; if (zif->rtadv.AdvHomeAgentFlag) rtadv->nd_ra_flags_reserved |= ND_RA_FLAG_HOME_AGENT; rtadv->nd_ra_router_lifetime = htons (zif->rtadv.AdvDefaultLifetime); rtadv->nd_ra_reachable = htonl (zif->rtadv.AdvReachableTime); rtadv->nd_ra_retransmit = htonl (0); len = sizeof (struct nd_router_advert); if (zif->rtadv.AdvHomeAgentFlag) { struct nd_opt_homeagent_info *ndopt_hai = (struct nd_opt_homeagent_info *)(buf + len); ndopt_hai->nd_opt_hai_type = ND_OPT_HA_INFORMATION; ndopt_hai->nd_opt_hai_len = 1; ndopt_hai->nd_opt_hai_reserved = 0; ndopt_hai->nd_opt_hai_preference = htons(zif->rtadv.HomeAgentPreference); ndopt_hai->nd_opt_hai_lifetime = htons(zif->rtadv.HomeAgentLifetime); len += sizeof(struct nd_opt_homeagent_info); } if (zif->rtadv.AdvIntervalOption) { struct nd_opt_adv_interval *ndopt_adv = (struct nd_opt_adv_interval *)(buf + len); ndopt_adv->nd_opt_ai_type = ND_OPT_ADV_INTERVAL; ndopt_adv->nd_opt_ai_len = 1; ndopt_adv->nd_opt_ai_reserved = 0; ndopt_adv->nd_opt_ai_interval = htonl(zif->rtadv.MaxRtrAdvInterval); len += sizeof(struct nd_opt_adv_interval); } /* Fill in prefix. */ for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvPrefixList, node, rprefix)) { struct nd_opt_prefix_info *pinfo; pinfo = (struct nd_opt_prefix_info *) (buf + len); pinfo->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION; pinfo->nd_opt_pi_len = 4; pinfo->nd_opt_pi_prefix_len = rprefix->prefix.prefixlen; pinfo->nd_opt_pi_flags_reserved = 0; if (rprefix->AdvOnLinkFlag) pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_ONLINK; if (rprefix->AdvAutonomousFlag) pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO; if (rprefix->AdvRouterAddressFlag) pinfo->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR; pinfo->nd_opt_pi_valid_time = htonl (rprefix->AdvValidLifetime); pinfo->nd_opt_pi_preferred_time = htonl (rprefix->AdvPreferredLifetime); pinfo->nd_opt_pi_reserved2 = 0; memcpy (&pinfo->nd_opt_pi_prefix, &rprefix->prefix.u.prefix6, sizeof (struct in6_addr)); #ifdef DEBUG { u_char buf[INET6_ADDRSTRLEN]; zlog_debug ("DEBUG %s", inet_ntop (AF_INET6, &pinfo->nd_opt_pi_prefix, buf, INET6_ADDRSTRLEN)); } #endif /* DEBUG */ len += sizeof (struct nd_opt_prefix_info); } /* Hardware address. */ #ifdef HAVE_STRUCT_SOCKADDR_DL sdl = &ifp->sdl; if (sdl != NULL && sdl->sdl_alen != 0) { buf[len++] = ND_OPT_SOURCE_LINKADDR; /* Option length should be rounded up to next octet if the link address does not end on an octet boundary. */ buf[len++] = (sdl->sdl_alen + 9) >> 3; memcpy (buf + len, LLADDR (sdl), sdl->sdl_alen); len += sdl->sdl_alen; /* Pad option to end on an octet boundary. */ memset (buf + len, 0, -(sdl->sdl_alen + 2) & 0x7); len += -(sdl->sdl_alen + 2) & 0x7; }
void ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or) { u_char message; u_char distance; u_char flags; int psize; struct stream *s; struct ospf_path *path; struct listnode *node; if (zclient->redist[ZEBRA_ROUTE_OSPF]) { message = 0; flags = 0; /* OSPF pass nexthop and metric */ SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); SET_FLAG (message, ZAPI_MESSAGE_METRIC); /* Distance value. */ distance = ospf_distance_apply (p, or); if (distance) SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); /* Make packet. */ s = zclient->obuf; stream_reset (s); /* Put command, type, flags, message. */ zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD); stream_putc (s, ZEBRA_ROUTE_OSPF); stream_putc (s, flags); stream_putc (s, message); stream_putw (s, SAFI_UNICAST); /* Put prefix information. */ psize = PSIZE (p->prefixlen); stream_putc (s, p->prefixlen); stream_write (s, (u_char *) & p->prefix, psize); /* Nexthop count. */ stream_putc (s, or->paths->count); /* Nexthop, ifindex, distance and metric information. */ for (ALL_LIST_ELEMENTS_RO (or->paths, node, path)) { if (path->nexthop.s_addr != INADDR_ANY && path->ifindex != 0) { stream_putc (s, ZEBRA_NEXTHOP_IPV4_IFINDEX); stream_put_in_addr (s, &path->nexthop); stream_putl (s, path->ifindex); } else if (path->nexthop.s_addr != INADDR_ANY) { stream_putc (s, ZEBRA_NEXTHOP_IPV4); stream_put_in_addr (s, &path->nexthop); } else { stream_putc (s, ZEBRA_NEXTHOP_IFINDEX); if (path->ifindex) stream_putl (s, path->ifindex); else stream_putl (s, 0); } if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) { char buf[2][INET_ADDRSTRLEN]; zlog_debug("Zebra: Route add %s/%d nexthop %s", inet_ntop(AF_INET, &p->prefix, buf[0], sizeof(buf[0])), p->prefixlen, inet_ntop(AF_INET, &path->nexthop, buf[1], sizeof(buf[1]))); } } if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) stream_putc (s, distance); if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) { if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL) stream_putl (s, or->cost + or->u.ext.type2_cost); else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL) stream_putl (s, or->u.ext.type2_cost); else stream_putl (s, or->cost); } stream_putw_at (s, 0, stream_get_endp (s)); zclient_send_message(zclient); }
static u_char dr_election (struct ospf6_interface *oi) { struct listnode *node, *nnode; struct ospf6_neighbor *on, *drouter, *bdrouter, myself; struct ospf6_neighbor *best_drouter, *best_bdrouter; u_char next_state = 0; drouter = bdrouter = NULL; best_drouter = best_bdrouter = NULL; /* pseudo neighbor myself, including noting current DR/BDR (1) */ memset (&myself, 0, sizeof (myself)); inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name, sizeof (myself.name)); myself.state = OSPF6_NEIGHBOR_TWOWAY; myself.drouter = oi->drouter; myself.bdrouter = oi->bdrouter; myself.priority = oi->priority; myself.router_id = oi->area->ospf6->router_id; /* Electing BDR (2) */ for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) bdrouter = better_bdrouter (bdrouter, on); best_bdrouter = bdrouter; bdrouter = better_bdrouter (best_bdrouter, &myself); /* Electing DR (3) */ for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) drouter = better_drouter (drouter, on); best_drouter = drouter; drouter = better_drouter (best_drouter, &myself); if (drouter == NULL) drouter = bdrouter; /* the router itself is newly/no longer DR/BDR (4) */ if ((drouter == &myself && myself.drouter != myself.router_id) || (drouter != &myself && myself.drouter == myself.router_id) || (bdrouter == &myself && myself.bdrouter != myself.router_id) || (bdrouter != &myself && myself.bdrouter == myself.router_id)) { myself.drouter = (drouter ? drouter->router_id : htonl (0)); myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0)); /* compatible to Electing BDR (2) */ bdrouter = better_bdrouter (best_bdrouter, &myself); /* compatible to Electing DR (3) */ drouter = better_drouter (best_drouter, &myself); if (drouter == NULL) drouter = bdrouter; } /* Set interface state accordingly (5) */ if (drouter && drouter == &myself) next_state = OSPF6_INTERFACE_DR; else if (bdrouter && bdrouter == &myself) next_state = OSPF6_INTERFACE_BDR; else next_state = OSPF6_INTERFACE_DROTHER; /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */ /* XXX */ /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */ /* RFC 2328 section 12.4. Originating LSAs (3) will be handled accordingly after AdjOK */ if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) || oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0))) { if (IS_OSPF6_DEBUG_INTERFACE) zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name, (drouter ? drouter->name : "0.0.0.0"), (bdrouter ? bdrouter->name : "0.0.0.0")); for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on)) { if (on->state < OSPF6_NEIGHBOR_TWOWAY) continue; /* Schedule AdjOK. */ thread_add_event (master, adj_ok, on, 0); } } oi->drouter = (drouter ? drouter->router_id : htonl (0)); oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0)); return next_state; }
/* * C.2.6 Step 1 */ static int isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp, uint32_t cost, uint16_t depth, int family) { struct listnode *node, *fragnode = NULL; u_int16_t dist; struct is_neigh *is_neigh; struct te_is_neigh *te_is_neigh; struct ipv4_reachability *ipreach; struct te_ipv4_reachability *te_ipv4_reach; enum vertextype vtype; struct prefix prefix; #ifdef HAVE_IPV6 struct ipv6_reachability *ip6reach; #endif /* HAVE_IPV6 */ if (!lsp->adj) return ISIS_WARNING; if (lsp->tlv_data.nlpids == NULL || !speaks (lsp->tlv_data.nlpids, family)) return ISIS_OK; lspfragloop: if (lsp->lsp_header->seq_num == 0) { zlog_warn ("isis_spf_process_lsp(): lsp with 0 seq_num" " - do not process"); return ISIS_WARNING; } if (!ISIS_MASK_LSP_OL_BIT (lsp->lsp_header->lsp_bits)) { if (lsp->tlv_data.is_neighs) { for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, node, is_neigh)) { /* C.2.6 a) */ /* Two way connectivity */ if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) continue; dist = cost + is_neigh->metrics.metric_default; vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS : VTYPE_NONPSEUDO_IS; process_N (spftree, vtype, (void *) is_neigh->neigh_id, dist, depth + 1, lsp->adj, family); } } if (lsp->tlv_data.te_is_neighs) { for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, node, te_is_neigh)) { uint32_t metric; if (!memcmp (te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) continue; memcpy (&metric, te_is_neigh->te_metric, 3); dist = cost + ntohl (metric << 8); vtype = LSP_PSEUDO_ID (te_is_neigh->neigh_id) ? VTYPE_PSEUDO_TE_IS : VTYPE_NONPSEUDO_TE_IS; process_N (spftree, vtype, (void *) te_is_neigh->neigh_id, dist, depth + 1, lsp->adj, family); } } if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs) { prefix.family = AF_INET; for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, node, ipreach)) { dist = cost + ipreach->metrics.metric_default; vtype = VTYPE_IPREACH_INTERNAL; prefix.u.prefix4 = ipreach->prefix; prefix.prefixlen = ip_masklen (ipreach->mask); process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, lsp->adj, family); } } if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs) { prefix.family = AF_INET; for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, node, ipreach)) { dist = cost + ipreach->metrics.metric_default; vtype = VTYPE_IPREACH_EXTERNAL; prefix.u.prefix4 = ipreach->prefix; prefix.prefixlen = ip_masklen (ipreach->mask); process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, lsp->adj, family); } }
static int ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v) { int changed = 0; struct ospf_interface *voi; struct listnode *node; struct vertex_parent *vp = NULL; int i; struct router_lsa *rl; voi = vl_data->vl_oi; if (voi->output_cost != v->distance) { voi->output_cost = v->distance; changed = 1; } for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp)) { vl_data->nexthop.oi = vp->nexthop->oi; vl_data->nexthop.router = vp->nexthop->router; if (!IPV4_ADDR_SAME(&voi->address->u.prefix4, &vl_data->nexthop.oi->address->u.prefix4)) changed = 1; voi->address->u.prefix4 = vl_data->nexthop.oi->address->u.prefix4; voi->address->prefixlen = vl_data->nexthop.oi->address->prefixlen; break; /* We take the first interface. */ } rl = (struct router_lsa *)v->lsa; /* use SPF determined backlink index in struct vertex * for virtual link destination address */ if (vp && vp->backlink >= 0) { if (!IPV4_ADDR_SAME (&vl_data->peer_addr, &rl->link[vp->backlink].link_data)) changed = 1; vl_data->peer_addr = rl->link[vp->backlink].link_data; } else { /* This is highly odd, there is no backlink index * there should be due to the ospf_spf_has_link() check * in SPF. Lets warn and try pick a link anyway. */ zlog_warn ("ospf_vl_set_params: No backlink for %s!", vl_data->vl_oi->ifp->name); for (i = 0; i < ntohs (rl->links); i++) { switch (rl->link[i].type) { case LSA_LINK_TYPE_VIRTUALLINK: if (IS_DEBUG_OSPF_EVENT) zlog_debug ("found back link through VL"); case LSA_LINK_TYPE_TRANSIT: case LSA_LINK_TYPE_POINTOPOINT: if (!IPV4_ADDR_SAME (&vl_data->peer_addr, &rl->link[i].link_data)) changed = 1; vl_data->peer_addr = rl->link[i].link_data; } } } if (IS_DEBUG_OSPF_EVENT) zlog_debug ("%s: %s peer address: %s, cost: %d,%schanged", __func__, vl_data->vl_oi->ifp->name, inet_ntoa(vl_data->peer_addr), voi->output_cost, (changed ? " " : " un")); return changed; }
static int rpki_config_write(struct vty * vty) { struct listnode *cache_group_node; cache_group* cache_group; if (listcount(cache_group_list)) { if (rpki_debug) { vty_out(vty, "debug rpki%s", VTY_NEWLINE); } vty_out(vty, "! %s", VTY_NEWLINE); vty_out(vty, "enable-rpki%s", VTY_NEWLINE); vty_out(vty, " rpki polling_period %d %s", polling_period, VTY_NEWLINE); vty_out(vty, " rpki timeout %d %s", timeout, VTY_NEWLINE); vty_out(vty, " rpki initial-synchronisation-timeout %d %s", initial_synchronisation_timeout, VTY_NEWLINE); vty_out(vty, "! %s", VTY_NEWLINE); for (ALL_LIST_ELEMENTS_RO(cache_group_list, cache_group_node, cache_group) ) { struct list* cache_list = cache_group->cache_config_list; struct listnode* cache_node; cache* cache; vty_out(vty, " rpki group %d %s", cache_group->preference_value, VTY_NEWLINE); if (listcount(cache_list) == 0) { vty_out(vty, "! %s", VTY_NEWLINE); continue; } for (ALL_LIST_ELEMENTS_RO(cache_list, cache_node, cache)) { switch (cache->type) { struct tr_tcp_config* tcp_config; struct tr_ssh_config* ssh_config; case TCP: tcp_config = cache->tr_config.tcp_config; vty_out(vty, " rpki cache %s %s %s", tcp_config->host, tcp_config->port, VTY_NEWLINE); break; case SSH: #if defined(FOUND_SSH) ssh_config = cache->tr_config.ssh_config; vty_out(vty, " rpki cache %s %u %s %s %s %s", ssh_config->host, ssh_config->port, ssh_config->username, ssh_config->client_privkey_path, ssh_config->server_hostkey_path != NULL ? ssh_config->server_hostkey_path : " ", VTY_NEWLINE); #endif break; default: break; } } vty_out(vty, "! %s", VTY_NEWLINE); } return 1; } else { return 0;
void ospf_ia_routing (struct ospf *ospf, struct route_table *rt, struct route_table *rtrs) { struct ospf_area * area; if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing():start"); if (IS_OSPF_ABR (ospf)) { struct listnode *node; struct ospf_area *area; switch (ospf->abr_type) { case OSPF_ABR_STAND: if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing():Standard ABR"); if ((area = ospf->backbone)) { struct listnode *node; if (IS_DEBUG_OSPF_EVENT) { zlog_debug ("ospf_ia_routing():backbone area found"); zlog_debug ("ospf_ia_routing():examining summaries"); } OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) if (area != ospf->backbone) if (ospf_area_is_transit (area)) OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); } else if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing():backbone area NOT found"); break; case OSPF_ABR_IBM: case OSPF_ABR_CISCO: if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing():Alternative Cisco/IBM ABR"); area = ospf->backbone; /* Find the BB */ /* If we have an active BB connection */ if (area && ospf_act_bb_connection (ospf)) { if (IS_DEBUG_OSPF_EVENT) { zlog_debug ("ospf_ia_routing(): backbone area found"); zlog_debug ("ospf_ia_routing(): examining BB summaries"); } OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) if (area != ospf->backbone) if (ospf_area_is_transit (area)) OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); } else { /* No active BB connection--consider all areas */ if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing(): " "Active BB connection not found"); for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); } break; case OSPF_ABR_SHORTCUT: if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing():Alternative Shortcut"); area = ospf->backbone; /* Find the BB */ /* If we have an active BB connection */ if (area && ospf_act_bb_connection (ospf)) { if (IS_DEBUG_OSPF_EVENT) { zlog_debug ("ospf_ia_routing(): backbone area found"); zlog_debug ("ospf_ia_routing(): examining BB summaries"); } OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); } for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) if (area != ospf->backbone) if (ospf_area_is_transit (area) || ((area->shortcut_configured != OSPF_SHORTCUT_DISABLE) && ((ospf->backbone == NULL) || ((area->shortcut_configured == OSPF_SHORTCUT_ENABLE) && area->shortcut_capability)))) OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); break; default: break; }
/* show specified interface structure */ static int ospf6_interface_show (struct vty *vty, struct interface *ifp) { struct ospf6_interface *oi; struct connected *c; struct prefix *p; struct listnode *i; char strbuf[64], drouter[32], bdrouter[32]; const char *updown[3] = {"down", "up", NULL}; const char *type; struct timeval res, now; char duration[32]; struct ospf6_lsa *lsa; /* check physical interface type */ if (if_is_loopback (ifp)) type = "LOOPBACK"; else if (if_is_broadcast (ifp)) type = "BROADCAST"; else if (if_is_pointopoint (ifp)) type = "POINTOPOINT"; else type = "UNKNOWN"; vty_out (vty, "%s is %s, type %s%s", ifp->name, updown[if_is_up (ifp)], type, VNL); vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL); if (ifp->info == NULL) { vty_out (vty, " OSPF not enabled on this interface%s", VNL); return 0; } else oi = (struct ospf6_interface *) ifp->info; vty_out (vty, " Internet Address:%s", VNL); for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c)) { p = c->address; prefix2str (p, strbuf, sizeof (strbuf)); switch (p->family) { case AF_INET: vty_out (vty, " inet : %s%s", strbuf, VNL); break; case AF_INET6: vty_out (vty, " inet6: %s%s", strbuf, VNL); break; default: vty_out (vty, " ??? : %s%s", strbuf, VNL); break; } } if (oi->area) { vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s", oi->instance_id, oi->ifmtu, ifp->mtu6, VNL); vty_out (vty, " MTU mismatch detection: %s%s", oi->mtu_ignore ? "disabled" : "enabled", VNL); inet_ntop (AF_INET, &oi->area->area_id, strbuf, sizeof (strbuf)); vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost, VNL); } else vty_out (vty, " Not Attached to Area%s", VNL); vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s", ospf6_interface_state_str[oi->state], oi->transdelay, oi->priority, VNL); vty_out (vty, " Timer intervals configured:%s", VNL); vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s", oi->hello_interval, oi->dead_interval, oi->rxmt_interval, VNL); inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter)); inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter)); vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL); vty_out (vty, " Number of I/F scoped LSAs is %u%s", oi->lsdb->count, VNL); bane_gettime (BANE_CLK_MONOTONIC, &now); timerclear (&res); if (oi->thread_send_lsupdate) timersub (&oi->thread_send_lsupdate->u.sands, &now, &res); timerstring (&res, duration, sizeof (duration)); vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s", oi->lsupdate_list->count, duration, (oi->thread_send_lsupdate ? "on" : "off"), VNL); for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa; lsa = ospf6_lsdb_next (lsa)) vty_out (vty, " %s%s", lsa->name, VNL); timerclear (&res); if (oi->thread_send_lsack) timersub (&oi->thread_send_lsack->u.sands, &now, &res); timerstring (&res, duration, sizeof (duration)); vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s", oi->lsack_list->count, duration, (oi->thread_send_lsack ? "on" : "off"), VNL); for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa; lsa = ospf6_lsdb_next (lsa)) vty_out (vty, " %s%s", lsa->name, VNL); return 0; }
/* Interface's information print out to vty interface. */ static void if_dump_vty (struct vty *vty, struct interface *ifp) { #ifdef HAVE_STRUCT_SOCKADDR_DL struct sockaddr_dl *sdl; #endif /* HAVE_STRUCT_SOCKADDR_DL */ struct connected *connected; struct listnode *node; struct route_node *rn; struct zebra_if *zebra_if; zebra_if = ifp->info; vty_out (vty, "Interface %s is ", ifp->name); if (if_is_up(ifp)) { vty_out (vty, "up, line protocol "); if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) { if (if_is_running(ifp)) vty_out (vty, "is up%s", VTY_NEWLINE); else vty_out (vty, "is down%s", VTY_NEWLINE); } else { vty_out (vty, "detection is disabled%s", VTY_NEWLINE); } } else { vty_out (vty, "down%s", VTY_NEWLINE); } if (ifp->desc) vty_out (vty, " Description: %s%s", ifp->desc, VTY_NEWLINE); if (ifp->ifindex == IFINDEX_INTERNAL) { vty_out(vty, " pseudo interface%s", VTY_NEWLINE); return; } else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) { vty_out(vty, " index %d inactive interface%s", ifp->ifindex, VTY_NEWLINE); return; } vty_out (vty, " index %d metric %d mtu %d ", ifp->ifindex, ifp->metric, ifp->mtu); #ifdef HAVE_IPV6 if (ifp->mtu6 != ifp->mtu) vty_out (vty, "mtu6 %d ", ifp->mtu6); #endif vty_out (vty, "%s flags: %s%s", VTY_NEWLINE, if_flag_dump (ifp->flags), VTY_NEWLINE); /* Hardware address. */ #ifdef HAVE_STRUCT_SOCKADDR_DL sdl = &ifp->sdl; if (sdl != NULL && sdl->sdl_alen != 0) { int i; u_char *ptr; vty_out (vty, " HWaddr: "); for (i = 0, ptr = (u_char *)LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++) vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr); vty_out (vty, "%s", VTY_NEWLINE); } #else if (ifp->hw_addr_len != 0) { int i; vty_out (vty, " HWaddr: "); for (i = 0; i < ifp->hw_addr_len; i++) vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]); vty_out (vty, "%s", VTY_NEWLINE); } #endif /* HAVE_STRUCT_SOCKADDR_DL */ /* Bandwidth in kbps */ if (ifp->bandwidth != 0) { vty_out(vty, " bandwidth %u kbps", ifp->bandwidth); vty_out(vty, "%s", VTY_NEWLINE); } for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn)) { if (! rn->info) continue; for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected)) connected_dump_vty (vty, connected); } for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) { if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6)) connected_dump_vty (vty, connected); } #ifdef RTADV nd_dump_vty (vty, ifp); #endif /* RTADV */ #ifdef HAVE_PROC_NET_DEV /* Statistics print out using proc file system. */ vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, " "%lu dropped%s", ifp->stats.rx_packets, ifp->stats.rx_multicast, ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE); vty_out (vty, " %lu input errors, %lu length, %lu overrun," " %lu CRC, %lu frame%s", ifp->stats.rx_errors, ifp->stats.rx_length_errors, ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors, ifp->stats.rx_frame_errors, VTY_NEWLINE); vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors, ifp->stats.rx_missed_errors, VTY_NEWLINE); vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s", ifp->stats.tx_packets, ifp->stats.tx_bytes, ifp->stats.tx_dropped, VTY_NEWLINE); vty_out (vty, " %lu output errors, %lu aborted, %lu carrier," " %lu fifo, %lu heartbeat%s", ifp->stats.tx_errors, ifp->stats.tx_aborted_errors, ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors, ifp->stats.tx_heartbeat_errors, VTY_NEWLINE); vty_out (vty, " %lu window, %lu collisions%s", ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE); #endif /* HAVE_PROC_NET_DEV */ #ifdef HAVE_NET_RT_IFLIST #if defined (__bsdi__) || defined (__NetBSD__) /* Statistics print out using sysctl (). */ vty_out (vty, " input packets %qu, bytes %qu, dropped %qu," " multicast packets %qu%s", ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, VTY_NEWLINE); vty_out (vty, " input errors %qu%s", ifp->stats.ifi_ierrors, VTY_NEWLINE); vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s", ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, ifp->stats.ifi_omcasts, VTY_NEWLINE); vty_out (vty, " output errors %qu%s", ifp->stats.ifi_oerrors, VTY_NEWLINE); vty_out (vty, " collisions %qu%s", ifp->stats.ifi_collisions, VTY_NEWLINE); #else /* Statistics print out using sysctl (). */ vty_out (vty, " input packets %lu, bytes %lu, dropped %lu," " multicast packets %lu%s", ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, VTY_NEWLINE); vty_out (vty, " input errors %lu%s", ifp->stats.ifi_ierrors, VTY_NEWLINE); vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s", ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, ifp->stats.ifi_omcasts, VTY_NEWLINE); vty_out (vty, " output errors %lu%s", ifp->stats.ifi_oerrors, VTY_NEWLINE); vty_out (vty, " collisions %lu%s", ifp->stats.ifi_collisions, VTY_NEWLINE); #endif /* __bsdi__ || __NetBSD__ */ #endif /* HAVE_NET_RT_IFLIST */ }
static void isis_zebra_route_add_ipv4 (struct prefix *prefix, struct isis_route_info *route_info) { u_char message, flags; int psize; struct stream *stream; struct isis_nexthop *nexthop; struct listnode *node; if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) return; if (zclient->redist[ZEBRA_ROUTE_ISIS]) { message = 0; flags = 0; SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); SET_FLAG (message, ZAPI_MESSAGE_METRIC); #if 0 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); #endif stream = zclient->obuf; stream_reset (stream); zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD); /* type */ stream_putc (stream, ZEBRA_ROUTE_ISIS); /* flags */ stream_putc (stream, flags); /* message */ stream_putc (stream, message); /* prefix information */ psize = PSIZE (prefix->prefixlen); stream_putc (stream, prefix->prefixlen); stream_write (stream, (u_char *) & prefix->u.prefix4, psize); stream_putc (stream, listcount (route_info->nexthops)); /* Nexthop, ifindex, distance and metric information */ for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop)) { /* FIXME: can it be ? */ if (nexthop->ip.s_addr != INADDR_ANY) { stream_putc (stream, ZEBRA_NEXTHOP_IPV4); stream_put_in_addr (stream, &nexthop->ip); } else { stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX); stream_putl (stream, nexthop->ifindex); } } #if 0 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) stream_putc (stream, route_info->depth); #endif if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) stream_putl (stream, route_info->cost); stream_putw_at (stream, 0, stream_get_endp (stream)); zclient_send_message(zclient); SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); }