?? dump.c
字號:
/* * Copyright (C) 1998 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#include <time.h>#include "include.h"#include "bgp.h"#include "router.h"#include "task.h"#include "rt_table.h"#include "aspath.h"#include "bgp_var.h"#include "in6.h"#include "ripng.h"extern struct ifinfo *ifentry;extern struct ripif *ripifs; /* defined in ripng.c */extern task *taskhead;extern time_t bgpd_start_time;char *dumpfile;static time_t tloc_now;static char *aspath2str(struct aspath *);static char *cll2str(struct clstrlist *);/* structures to show all BGP route */struct bgproute_entry { struct bgproute_entry *next; struct bgproute_list *head; /* back pointer to the list */ struct rpcb *bnp; struct rt_entry *rte;};struct bgproute_list { struct bgproute_list *next; struct bgproute_list *prev; struct bgproute_entry *entry;};#define bgp_route_head(l) ((l)->next)#define bgp_route_isend(e,b) ((e) == (b))#define bgp_route_next(l) ((l)->next)#define bgp_route_prev(l) ((l)->prev)#define bgp_route_insert(new,post) insque((new), (post)->prev)#ifdef __FreeBSD__ /* XXX: see PORTABILITY */#define LONGLONG "%qu"#else#define LONGLONG "%llu"#endifstatic char *sec2str(total) time_t total;{ static char result[256]; int days, hours, mins, secs; int first = 1; char *p = result; days = total / 3600 / 24; hours = (total / 3600) % 24; mins = (total / 60) % 60; secs = total % 60; if (days) { first = 0; p += sprintf(p, "%dd", days); } if (!first || hours) { first = 0; p += sprintf(p, "%dh", hours); } if (!first || mins) { first = 0; p += sprintf(p, "%dm", mins); } sprintf(p, "%ds", secs); return(result);}static voiddump_if_rtable(FILE *fp, struct rt_entry *base){ struct rt_entry *rte = base; while(rte) { fprintf(fp, " "); /* indentation */ fprintf(fp, "%s/%d(%d)", ip6str(&rte->rt_ripinfo.rip6_dest, 0), rte->rt_ripinfo.rip6_plen, rte->rt_ripinfo.rip6_metric); if (rte->rt_flags & RTF_BGPDGWSTATIC) { fprintf(fp, " gateway=%s", ip6str(&rte->rt_gw, rte->rt_proto.rtp_if->ifi_ifn->if_index)); } fprintf(fp, " Flags:"); if ((rte->rt_flags & (RTF_BGPDIFSTATIC | RTF_BGPDGWSTATIC))) fprintf(fp, " BGPDSTATIC"); if ((rte->rt_flags & RTF_REJECT)) fprintf(fp, " REJECT"); if ((rte->rt_flags & RTF_STATIC)) fprintf(fp, " STATIC"); if ((rte->rt_flags & RTF_BLACKHOLE)) fprintf(fp, " BLACKHOLE"); fputc('\n', fp); if ((rte = rte->rt_next) == base) break; }}static voiddump_rip_rtable(FILE *fp, struct rt_entry *base){ struct rt_entry *rte = base; rte = base; while(rte) { fprintf(fp, " "); /* indentation */ fprintf(fp, "%s/%d(%d) [%d] gw = %s", ip6str(&rte->rt_ripinfo.rip6_dest, 0), rte->rt_ripinfo.rip6_plen, rte->rt_ripinfo.rip6_metric, rte->rt_ripinfo.rip6_tag, ip6str(&rte->rt_gw, 0)); if (rte->rt_riptime) { fprintf(fp, " timeout=%d:%02d", (int)(rte->rt_riptime->tsk_timeval.tv_sec / 60), (int)(rte->rt_riptime->tsk_timeval.tv_sec % 60)); } fputc('\n', fp); if ((rte = rte->rt_next) == base) break; }}#define FILTERTYPE_FILTER 0#define FILTERTYPE_RESTRICTION 1static voidprint_filterinfo(FILE *fp, struct filtinfo *top, int type){ struct filtinfo *filter = top; /* must not be NULL */ while(filter) { fprintf(fp, " "); /* indentation */ if (type == FILTERTYPE_FILTER) fprintf(fp, "%s/%d: filtered %d routes\n", ip6str(&filter->filtinfo_addr, 0), filter->filtinfo_plen, filter->filtinfo_stat); if (type == FILTERTYPE_RESTRICTION) fprintf(fp, "%s/%d: passed %d routes\n", ip6str(&filter->filtinfo_addr, 0), filter->filtinfo_plen, filter->filtinfo_stat); if ((filter = filter->filtinfo_next) == top) break; }}static voiddump_filterinfo(FILE *fp, char *indent, struct filterset *filterset){ struct filtinfo *filter; if ((filter = filterset->filterin) != NULL) { fprintf(fp, "%s Input filter:\n", indent); print_filterinfo(fp, filter, FILTERTYPE_FILTER); } if ((filter = filterset->filterout) != NULL) { fprintf(fp, "%s Output filter:\n", indent); print_filterinfo(fp, filter, FILTERTYPE_FILTER); } if ((filter = filterset->restrictin) != NULL) { fprintf(fp, "%s Input restriction:\n", indent); print_filterinfo(fp, filter, FILTERTYPE_RESTRICTION); } if ((filter = filterset->restrictout) != NULL) { fprintf(fp, "%s Output restriction:\n", indent); print_filterinfo(fp, filter, FILTERTYPE_RESTRICTION); } if (filterset->deffilterflags & DEFAULT_FILTERIN) fprintf(fp, "%s %d incoming default routes were filtered\n", indent, filterset->filtered_indef); if (filterset->deffilterflags & DEFAULT_FILTEROUT) fprintf(fp, "%s %d outgoing default routes were filtered\n", indent, filterset->filtered_outdef); if ((filterset->deffilterflags & DEFAULT_RESTRICTIN) || filterset->restrictin) fprintf(fp, "%s %d incoming routes were filtered by " "restriction\n", indent, filterset->input_restrected); if ((filterset->deffilterflags & DEFAULT_RESTRICTOUT) || filterset->restrictout) fprintf(fp, "%s %d outgoing routes were filtered by " "restriction\n", indent, filterset->output_restrected);}static voiddump_bgp_rtentry(FILE *fp, struct rt_entry *rte, char *indent){ struct aspath *ap; extern char *origin_str[]; struct optatr *optatr; char inetaddrstr[INET_ADDRSTRLEN]; ap = rte->rt_aspath; fprintf(fp, "%s", indent); /* indentation */ fprintf(fp, "%s%s/%d\n", (rte->rt_flags & RTF_INSTALLED) ? "*" : " ", ip6str(&rte->rt_ripinfo.rip6_dest, 0), rte->rt_ripinfo.rip6_plen); fprintf(fp, "%s Nexthop: %s\n", indent, ip6str(&rte->rt_bgw, 0)); if (rte->rt_aspath && !IN6_IS_ADDR_UNSPECIFIED(&rte->rt_aspath->asp_nexthop_local)) fprintf(fp, "%s Nexhop(local): %s\n", indent, ip6str(&rte->rt_aspath->asp_nexthop_local, 0)); fprintf(fp, "%s ", indent); /* more indent */ fprintf(fp, "Gateway: %s ", ip6str(&rte->rt_gw, rte->rt_gwif ? rte->rt_gwif->ifi_ifn->if_index : 0)); fprintf(fp, "Flags:"); if (rte->rt_flags & RTF_UP) fprintf(fp, " UP"); if (rte->rt_flags & RTF_GATEWAY) fprintf(fp, " GW"); if (rte->rt_flags & RTF_HOST) fprintf(fp, " HOST"); if (rte->rt_flags & RTF_IGP_EGP_SYNC) fprintf(fp, " IESYNC"); if (rte->rt_flags & RTF_NH_NOT_LLADDR) fprintf(fp, " NONLOCAL"); if (rte->rt_flags & RTF_INSTALLED) fprintf(fp, " INSTALLED"); fputc('\n', fp); if (!IN6_IS_ADDR_UNSPECIFIED(&rte->rt_gw)) { fprintf(fp, "%s ", indent); /* more^2 indent */ switch(rte->rt_gwsrc_type) { case RTPROTO_IF: fprintf(fp, "gwsrc: ifroute(%s/%d on %s)", ip6str(&rte->rt_gwsrc_entry->rt_ripinfo.rip6_dest, 0), rte->rt_gwsrc_entry->rt_ripinfo.rip6_plen, rte->rt_gwif->ifi_ifn->if_name); break; case RTPROTO_RIP: fprintf(fp, "gwsrc: ripng(%s/%d on %s,\n", ip6str(&rte->rt_gwsrc_entry->rt_ripinfo.rip6_dest, 0), rte->rt_gwsrc_entry->rt_ripinfo.rip6_plen, rte->rt_gwif->ifi_ifn->if_name); fprintf(fp, "%s ", indent); /* more^2 indent */ fprintf(fp, " %s)", ip6str(&rte->rt_gwsrc_entry->rt_gw, rte->rt_gwif->ifi_ifn->if_index)); break; case RTPROTO_BGP: fprintf(fp, "gwsrc: bgp (link %s)\n", rte->rt_proto.rtp_bgp->rp_ife ? rte->rt_proto.rtp_bgp->rp_ife->ifi_ifn->if_name : "??"); break; default: fprintf(fp, "gwsrc: unknown(%d)", rte->rt_gwsrc_type); break; } fputc('\n', fp); } fprintf(fp, "%s ", indent); /* more indent */ fprintf(fp, "MED: %d localpref: %d origin: %s\n", (int)ntohl(ap->asp_med), (int)ntohl(ap->asp_localpref), origin_str[ap->asp_origin]); fprintf(fp, "%s ", indent); /* more indent */ fprintf(fp, "ASPATH: %s\n", aspath2str(ap)); /* Route Reflection Origin ID and Cluster list*/ if (ap->asp_origid) { fprintf(fp, "%s ", indent); /* more indent */ fprintf(fp, "Originator ID: %s\n", inet_ntop(AF_INET, &ap->asp_origid, inetaddrstr, INET_ADDRSTRLEN)); } if (ap->asp_clstr) { fprintf(fp, "%s ", indent); /* more indent */ fprintf(fp, "Cluster list: %s\n", cll2str(ap->asp_clstr)); } /* unrecognized attributes */ if ((optatr = ap->asp_optatr) != NULL) fprintf(fp, "%s Unrecognized Attributes:\n", indent); for (optatr = ap->asp_optatr; optatr; optatr = optatr->next) { int c = 0; fprintf(fp, "%s ", indent); for (c = 0; c < optatr->len && c < 20; c++) fprintf(fp, "%02x ", (unsigned char)optatr->data[c]); if (optatr->len > 20) fprintf(fp, "..."); fputc('\n', fp); }}static voiddump_bgp_exportlist(FILE *fp, struct rt_entry *rte, char *indent){ char inetaddrstr[INET_ADDRSTRLEN]; extern struct rpcb *bgb; struct rpcb *srcbnp = rte->rt_proto.rtp_bgp, *obnp; int first = 1; obnp = bgb; while(obnp) { struct rtproto *rtp = obnp->rp_adj_ribs_out; struct rpcb *ebnp; if (obnp != srcbnp && obnp->rp_state == BGPSTATE_ESTABLISHED) { while(rtp) { if (rtp->rtp_type == RTPROTO_BGP && (ebnp = find_epeer_by_rpcb(rtp->rtp_bgp)) != NULL && ebnp == srcbnp) { if (first == 1) { fprintf(fp, "%s Exported to:\n", indent); first = 0; } fprintf(fp, "%s %s(%s), ID=%s\n", indent, bgp_peerstr(obnp), (obnp->rp_mode & BGPO_IGP) ? "IBGP" : "EBGP", inet_ntop(AF_INET, &obnp->rp_id, inetaddrstr, INET_ADDRSTRLEN)); } if ((rtp = rtp->rtp_next) == obnp->rp_adj_ribs_out) break; } } if ((obnp = obnp->rp_next) == bgb) break; } if (first == 1) fprintf(fp, "%s Not exported\n", indent);}#if 0static voiddump_bgp_rtable(FILE *fp, struct rt_entry *base){ struct rt_entry *rte = base; while(rte) { dump_bgp_rtentry(fp, rte, " "); if ((rte = rte->rt_next) == base) break; }}#endif#if notusedstatic voiddump_exports(FILE *fp, struct rtproto *base){ struct rtproto *rtp = base; struct rpcb *ebnp; char inetaddrstr[INET_ADDRSTRLEN]; while(rtp) { switch(rtp->rtp_type) { case RTPROTO_IF: fprintf(fp, " Interface routes:\n"); dump_rip_rtable(fp, rtp->rtp_if->ifi_rte); break; case RTPROTO_BGP: fprintf(fp, " BGP routes: "); ebnp = find_epeer_by_rpcb(rtp->rtp_bgp); if (rtp->rtp_bgp->rp_mode & BGPO_IGP) { /* IBGP */ u_int32_t peerid = ebnp ? ebnp->rp_id : rtp->rtp_bgp->rp_id; fprintf(fp, "from an IBGP peer, ID = %s\n", inet_ntop(AF_INET, &peerid, inetaddrstr, INET_ADDRSTRLEN)); } else /* EBGP */ fprintf(fp, "from an EBGP peer, AS = %d\n", rtp->rtp_bgp->rp_as); if (ebnp) dump_bgp_rtable(fp, ebnp->rp_adj_ribs_in); else fprintf(fp, " No established peer\n"); break; case RTPROTO_RIP: fprintf(fp, " RIPng routes\n"); dump_rip_rtable(fp, rtp->rtp_rip->rip_adj_ribs_in); break; } if ((rtp = rtp->rtp_next) == base) break; }}#endifstatic voidprint_if_dump(FILE *fp){ struct ifinfo *ife = ifentry; fprintf(fp, "=== Direct Interfaces Information ===\n"); while(ife) { fprintf(fp, " Interface: %s\n", ife->ifi_ifn->if_name); fprintf(fp, " Link-local Address: %s\n", ip6str(&ife->ifi_laddr, ife->ifi_ifn->if_index)); fprintf(fp, " Global Address: %s\n", IN6_IS_ADDR_UNSPECIFIED(&ife->ifi_gaddr) ? "NONE" : ip6str(&ife->ifi_gaddr, 0)); fprintf(fp, " Routes to the interface\n" ); dump_if_rtable(fp, ife->ifi_rte); if ((ife = ife->ifi_next) == ifentry) break; }}static voidprint_rip_dump(FILE *fp){ struct ripif *ripif = ripifs; task *t = taskhead; extern time_t last_rip_dump; fprintf(fp, "\n=== RIPng generic information ===\n"); while (t) { if (t->tsk_timename == RIP_DUMP_TIMER) { fprintf(fp, " Dump timer=%d:%02d\n", (int)(t->tsk_timeval.tv_sec / 60), (int)(t->tsk_timeval.tv_usec % 60)); break; } if ((t = t->tsk_next) == taskhead) break; } fprintf(fp, " Last dump: %s", ctime(&last_rip_dump)); fprintf(fp, " (%s before)\n", sec2str(tloc_now - last_rip_dump)); fprintf(fp, "\n=== RIPng per interface information ===\n"); while(ripif) { fprintf(fp, " Interface: %s", ripif->rip_ife->ifi_ifn->if_name); if (ripif->rip_desc) fprintf(fp, " Description: %s", ripif->rip_desc); fputc('\n', fp); /* RIPng related flags */ fprintf(fp, " Flags:"); if (ripif->rip_mode & IFS_NORIPIN) fprintf(fp, " NORIPIN"); if (ripif->rip_mode & IFS_NORIPOUT) fprintf(fp, " NORIPOUT"); if (ripif->rip_filterset.deffilterflags & DEFAULT_FILTERIN) fprintf(fp, " FILTERIN_DEFAULT"); if (ripif->rip_filterset.deffilterflags & DEFAULT_FILTEROUT) fprintf(fp, " FILTEROUT_DEFAULT"); if (ripif->rip_filterset.deffilterflags & DEFAULT_RESTRICTIN) fprintf(fp, " RESTRICTIN_DEFAULT"); if (ripif->rip_filterset.deffilterflags & DEFAULT_RESTRICTOUT) fprintf(fp, " RESTRICTOUT_DEFAULT"); if (ripif->rip_mode & IFS_DEFAULTORIGINATE) fprintf(fp, " DEFRT_ORIGINATE");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -