Communitygithub.com

网络BGP诊断

用于BGP邻居状态、路由交换、前缀策略、AS路径检查和安全证据收集的仅诊断模式故障排查。当BGP邻居断开、路由缺失或需要检查前缀策略和AS路径时使用。

网络BGP诊断 是什么?

该技能提供了一套严格的只读BGP诊断工作流,专为网络工程师和AI代理设计,用于在不影响生产路由的情况下排查BGP会话问题。它涵盖了从邻居状态解释(包括Idle、Active、Established等)到传输层可达性验证、路由策略检查以及AS路径审查的完整流程。支持的平台包括运行标准BGP实现的路由器(如Cisco IOS、类似系统),并提供了跨平台通用的show命令模板。技能的核心价值在于强制使用只读命令收集证据,避免因故障排查操作而引入新的网络中断。此外,它还包含一个Python正则解析器示例,用于解析BGP摘要输出,并明确列出了需要变更窗口批准的操作(如重置会话、修改策略),以及常见的反模式,帮助用户避免错误假设。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/network-bgp-diagnostics

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

网络BGP诊断 是做什么的?

当BGP会话断开、振荡、已建立但路由缺失,或通告了意外前缀时,请使用此技能。默认工作流为只读证据收集;策略和重置操作应属于经过审核的变更窗口。

何时使用

  • BGP邻居卡在Idle、Connect、Active、OpenSent或OpenConfirm状态。
  • 会话处于Established状态,但预期的前缀缺失。
  • route-map、prefix-list、max-prefix限制或AS路径策略可能正在过滤路由。
  • 需要对BGP变更进行前后证据对比。
  • 正在审查解析BGP摘要输出的自动化脚本。

只读故障排查流程

  1. 确定确切的邻居、地址族、VRF以及本地/远端ASN。
  2. 捕获摘要状态和上次重置原因。
  3. 验证对等体源地址的可达性。
  4. 在假设传输故障之前,检查路由策略引用。
  5. 在平台支持的命令范围内,比较通告、接收和安装的路由。
show bgp summary
show bgp neighbors <peer>
show ip route <peer>
show tcp brief | include <peer>|:179
show logging | include BGP|<peer>
show running-config | section router bgp
show ip prefix-list
show route-map

当设备使用VRF、IPv6、VPNv4或EVPN时,请使用特定于平台的地址族命令。不要假设全局IPv4单播。

状态解读

状态首要检查项
Established 且 prefix count > 0路由交换正常;检查策略和表选择
Established 且 prefix count = 0检查入站策略、max-prefix、通告路由及AFI/SAFI
ActiveTCP会话未完成;检查路由、源地址、ACL和对等体可达性
ConnectTCP连接正在进行;检查路径和远程监听器
OpenSent/OpenConfirmTCP工作正常;检查ASN、认证、定时器、能力和日志
Idle邻居可能被禁用、配置缺失、被策略阻止或处于退避定时器状态

传输层检查

ping <peer> source <local-source>
traceroute <peer> source <local-source>
show ip route <peer>
show bgp neighbors <peer> | include BGP state|Last reset|Local host|Foreign host

如果对等体源地址来自loopback,请确认两个方向的路由都指向loopback地址,并且邻居配置使用了预期的更新源。

避免以诊断捷径为由禁用ACL或防火墙策略。请先读取命中计数器、日志和路径状态。

路由策略检查

show bgp neighbors <peer> advertised-routes
show bgp neighbors <peer> routes
show ip prefix-list <name>
show route-map <name>
show bgp <prefix>

某些平台需要额外配置才能使用received-routes。除非操作员批准变更,否则不要在事件排查期间添加该配置。

AS路径和前缀审查

show bgp regexp _65001_
show bgp regexp ^65001$
show bgp <prefix>
show bgp neighbors <peer> advertised-routes | include Network|Path|<prefix>

谨慎使用AS路径正则。_65001_将AS 65001匹配为一个令牌。纯文本65001可能匹配更长的ASN或不相关的文本。

解析器模式

import re
from typing import Any

BGP_SUMMARY_RE = re.compile(
    r"^(?P<neighbor>\d{1,3}(?:\.\d{1,3}){3})\s+"
    r"(?P<version>\d+)\s+"
    r"(?P<remote_as>\d+)\s+"
    r"(?P<msg_rcvd>\d+)\s+"
    r"(?P<msg_sent>\d+)\s+"
    r"(?P<table_version>\d+)\s+"
    r"(?P<input_queue>\d+)\s+"
    r"(?P<output_queue>\d+)\s+"
    r"(?P<uptime>\S+)\s+"
    r"(?P<state_or_prefixes>\S+)$",
    re.M,
)

def parse_bgp_summary(raw: str) -> list[dict[str, Any]]:
    rows = []
    for match in BGP_SUMMARY_RE.finditer(raw):
        state_or_prefixes = match.group("state_or_prefixes")
        if state_or_prefixes.isdigit():
            state = "Established"
            prefixes_received = int(state_or_prefixes)
        else:
            state = state_or_prefixes
            prefixes_received = None
        rows.append({
            "neighbor": match.group("neighbor"),
            "remote_as": int(match.group("remote_as")),
            "state": state,
            "prefixes_received": prefixes_received,
            "uptime": match.group("uptime"),
        })
    return rows

优先使用结构化解析器输出(如有),但同时需将原始输出保存到事件记录中,因为BGP摘要格式因平台和地址族而异。

仅限变更窗口

以下操作可能影响路由,不应作为自动诊断建议:

  • 清除BGP会话。
  • 更改邻居认证、定时器、更新源、route-map或prefix-list。
  • 启用额外的received-route存储。
  • 放宽防火墙、ACL或控制平面策略。

如果重置获得批准,请优先选择平台支持的最小破坏性软重置或路由刷新选项,并记录其安全原因。

反模式

  • 假设Active状态总是意味着远端故障。
  • 忽略VRF、地址族或更新源差异。
  • 使用不带令牌边界的宽泛AS路径正则。
  • 在读取上次重置原因和日志之前,对对等体进行硬重置。
  • 将缺失的received-routes输出视为没有路由到达的证据。

参见

  • 技能:cisco-ios-patterns
  • 技能:network-config-validation
  • 技能:network-interface-health

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能