本篇博客转载自奎爷 👀
背景
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调试:
- 容器调用显示器
在外部终端执行 xhost +
之后就可以 在容器内显示图形化界面。
core容器节点想进行图形化的调试 推荐使用 vscode (死忠粉)
- root用户下使用vscode
使用 sudo code --user-data-dir="/home/ling/.vscode/root_config/" --no-sandbox
进入管理员状态的vscode
修改launch文件就可以进行 配置 gdb调试 的参数。
- vtysh shell 读取当前配置文件发现不生效 查看 boot_quagga 脚本才明白 需要使用
vtysh -b
命令读取配置。
vtysh 命令介绍
命令 | 解释 |
---|---|
clear | Reset functions |
configure | Configuration from vty interface |
copy | Copy from one file to another |
debug | Enable debug messages for specific or all part. |
disable | Turn off privileged mode command |
end | End current mode and change to enable mode |
exit | Exit current mode and down to previous mode |
list | Print command list |
no | Negate a command or set its defaults |
ping | Send echo messages |
quit | Exit current mode and down to previous mode |
show | Show running system information |
ssh | Open an ssh connection |
start-shell | Start UNIX shell |
telnet | Open a telnet connection |
terminal | Set terminal line parameters |
traceroute | Trace route to destination |
undebug | Disable debugging functions (see also ‘debug’) |
write | Write running configuration to memory, network, or terminal |
babel | IP information |
bgp | BGP information |
daemons | Show list of running daemons |
debugging | State of each debugging option |
interface | Interface status and configuration |
ip | IP information |
ipv6 | IPv6 information |
isis | IS-IS information |
logging | Show current logging configuration |
memory | Memory statistics |
mpls-te | MPLS-TE information |
route-map | route-map information |
running-config | Current operating configuration |
startup-config | Contentes of startup configuration |
table | default routing table to use for all clients |
version | Displays zebra version |
zebra | Zebra information |
access-list | Add an access list entry |
bgp | BGP information |
debug | Enable debug messages for specific or all part. |
dump | Dump packet |
enable | Modify enable password parameters |
end | End current mode and change to enable mode |
exit | Exit current mode and down to previous mode |
hostname | Set system’s network name |
interface | Select an interface to configure |
ip | IP information |
ipv6 | IPv6 information |
key | Authentication key management |
line | Configure a terminal line |
list | Print command list |
log | Logging control |
no | Negate a command or set its defaults |
password | Assign the terminal connection password |
route-map | Create route-map or enter route-map command mode |
router | Enable a routing process |
router-id | Manually set the router-id |
service | Set up miscellaneous service |
table | Configure target kernel routing table |