Communitygithub.com

網路 BGP 診斷

僅供診斷的 BGP 故障排除模式,涵蓋鄰居狀態、路由交換、前綴政策、AS 路徑檢查以及安全證據收集。當 BGP 鄰居中斷、路由遺失,或需要檢查前綴政策與 AS 路徑時使用。

網路 BGP 診斷 是什麼?

這是一個專為網路工程師和 AI 代理設計的 BGP 診斷技能,專注於**唯讀**的故障排查,確保在不影響生產路由的情況下收集關鍵證據。支援的平台包括任何使用標準 CLI (如 Cisco IOS/IOS-XE、NX-OS、Juniper JunOS 等) 的網路設備。其核心工作流程引導使用者依序檢查 BGP 鄰居狀態、傳輸層連通性、路由政策 (route-map、prefix-list)、以及 AS 路徑與前綴通告。技能內含一個 Python 解析器模板,用於從 `show bgp summary` 輸出中提取鄰居狀態和前綴計數,適合自動化腳本或日誌分析。特別強調**變更窗口限制**,明確指出清除 BGP 會話、修改認證、計時器或政策等動作不應作為自動診斷步驟,僅能在經過審查的變更窗口中執行。對於常見的狀態如 Active、Connect、Idle 提供了直接的檢查清單,並提醒了典型的反模式,例如忽略 VRF 或地址族、未檢查錯誤原因就硬重置鄰居等。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/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 且前綴計數正常路由交換正常;檢查政策與路由表選擇
Established 但前綴為零檢查入站政策、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-path 正則表達式。_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-maps 或 prefix-lists。
  • 啟用額外的 received-route 儲存空間。
  • 放寬防火牆、ACL 或控制平面政策。

如果重置獲得核准,請優先選擇平台支援的、破壞性最小的軟重置或 route-refresh 選項,並記錄其安全原因。

反模式

  • 假設 Active 總是代表遠端已中斷。
  • 忽略 VRF、地址族或更新來源的差異。
  • 使用不帶記號邊界的寬泛 AS-path 正則表達式。
  • 在讀取最後重置原因和日誌之前硬重置對等體。
  • 將缺少 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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能