Quagga 调试记录

本篇博客转载自奎爷 👀

背景

Quagga是一个开源的、基 于Zebra的、实现了RIP, OSPF, BGP的动态路由软件。它提供的CL命令和Cisco IOS类似,可以使用quagga将linux机器打造成一台功能完备的路由器。

最近由于项目需要计算路由协议收敛时间,因此不得不看Quagga源码实现,但苦于不知道开发者是如何使用日志对代码进行调试的,所以更改代码、编译后也不知道怎么查看结果。为了今后需要的时候有个参考,因此对该调试方法进行记录。

vtysh debug 调试

Quagga提供了一个类Cisco命令行的分级多用户命令解析引擎–VTY(Virtual Terminal)。它是类似于Linux Shell的虚拟终端接口,负责对访问的安全验证、数据缓冲、命令解析、模式切换和命令调用。

vtysh 使用 ? 可以类似 tab 补齐命令

启动vtysh命令行 为Quagga配置日志文件 日志后也可设置打印等级

$ vtysh
n1# configure terminal        				#进入vtysh全局配置模式
n1(config)# log file /var/log/quagga.log   #指定日志文件位置  指定其他位置会显示无法打开
n1(config)# exit
n1# write					  			#永久保存到配置文件中
Building Configuration...
Integrated configuration saved to /usr/local/etc/quagga/Quagga.conf
[OK]
n1# 

当然我这里使用 core 来做,直接将log file 写入config配置文件中,这些配置文件 和日志文件会单独挂载不用担心影响物理主机配置。例如

log file /var/log/quagga.log
interface eth0
  ip address 10.0.0.1/24
  ip ospf network point-to-point
  ip ospf hello-interval 2
  ip ospf dead-interval 6
  ip ospf retransmit-interval 5
  ipv6 address 2001::1/64
!
interface eth1
  ip address 10.0.1.2/24
  ip ospf network point-to-point
  ip ospf hello-interval 2
  ip ospf dead-interval 6
  ip ospf retransmit-interval 5
  ipv6 address 2001:1::2/64
!
router ospf
  router-id 10.0.0.1
  network 10.0.0.1/24 area 0
  network 10.0.1.2/24 area 0
!

打开需要调试的接口

n1# debug ospf event 
n1# debug ospf packet ls-update 
n1# show debugging 
bgp    ospf   rip    ripng  zebra  
n1# show debugging ospf
OSPF debugging status:
  OSPF event debugging is on
  OSPF packet Link State Update debugging is on
n1# undebug # 关闭debug接口

​ 查看日志信息

root@n1:/var/log# tail -f var.log/quagga.log

使用gdb调试:

  1. 容器调用显示器

在外部终端执行 xhost + 之后就可以 在容器内显示图形化界面。

core容器节点想进行图形化的调试 推荐使用 vscode (死忠粉)

  1. root用户下使用vscode

使用 sudo code --user-data-dir="/home/ling/.vscode/root_config/" --no-sandbox 进入管理员状态的vscode 修改launch文件就可以进行 配置 gdb调试 的参数。

  1. vtysh shell 读取当前配置文件发现不生效 查看 boot_quagga 脚本才明白 需要使用 vtysh -b 命令读取配置。

vtysh 命令介绍

以下是vtysh的一些命令

命令解释
clearReset functions
configureConfiguration from vty interface
copyCopy from one file to another
debugEnable debug messages for specific or all part.
disableTurn off privileged mode command
endEnd current mode and change to enable mode
exitExit current mode and down to previous mode
listPrint command list
noNegate a command or set its defaults
pingSend echo messages
quitExit current mode and down to previous mode
showShow running system information
sshOpen an ssh connection
start-shellStart UNIX shell
telnetOpen a telnet connection
terminalSet terminal line parameters
tracerouteTrace route to destination
undebugDisable debugging functions (see also ‘debug’)
writeWrite running configuration to memory, network, or terminal
babelIP information
bgpBGP information
daemonsShow list of running daemons
debuggingState of each debugging option
interfaceInterface status and configuration
ipIP information
ipv6IPv6 information
isisIS-IS information
loggingShow current logging configuration
memoryMemory statistics
mpls-teMPLS-TE information
route-maproute-map information
running-configCurrent operating configuration
startup-configContentes of startup configuration
tabledefault routing table to use for all clients
versionDisplays zebra version
zebraZebra information
access-listAdd an access list entry
bgpBGP information
debugEnable debug messages for specific or all part.
dumpDump packet
enableModify enable password parameters
endEnd current mode and change to enable mode
exitExit current mode and down to previous mode
hostnameSet system’s network name
interfaceSelect an interface to configure
ipIP information
ipv6IPv6 information
keyAuthentication key management
lineConfigure a terminal line
listPrint command list
logLogging control
noNegate a command or set its defaults
passwordAssign the terminal connection password
route-mapCreate route-map or enter route-map command mode
routerEnable a routing process
router-idManually set the router-id
serviceSet up miscellaneous service
tableConfigure target kernel routing table