博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Quagga添加自己的命令
阅读量:4553 次
发布时间:2019-06-08

本文共 2973 字,大约阅读时间需要 9 分钟。

参考了王斌的文档:http://down.51cto.com/data/621454

TIP:笔者使用的版本是0.99.20

需求:在接口模式下添加一条"ip ospf enable"的命令,什么也不做,只输出一些字符;

Quagga内的视图是在vtysh.h定义的,位置:“vtysh/vtysh.c”,我常接触的主要有以下:

 

/* Vty node structures. */static struct cmd_node bgp_node ={  BGP_NODE,  "%s(config-router)# ",};static struct cmd_node interface_node ={  INTERFACE_NODE,  "%s(config-if)# ",};static struct cmd_node zebra_node ={  ZEBRA_NODE,  "%s(config-router)# "};static struct cmd_node bgp_ipv4_node ={  BGP_IPV4_NODE,  "%s(config-router-af)# "};static struct cmd_node ospf_node ={  OSPF_NODE,  "%s(config-router)# "};

我主要用接口视图和OSPF视图,每个模式下会绑定该模式下可以使用的命令,比如,只有接口模式下才有“ip ospf hello-interval”,而ospf模式下没有,这就是视图和命令的关系。需要添加自己的视图可以在这里定义,这里了解下即可,无需修改;

 

定义“ip ospf enable”命令:

具体说明见王斌的笔记,这里我就直接加代码了,首先是在"ospfd/osfp_vty.c"加DEFUN,具体如下:

DEFUN (interface_ospf_enable,		interface_ospf_enable_cmd,		"ip ospf enable",		"IP Information\n"		"OSPF interface commands\n"		"enable ip ospf router in this Interface\n"){	vty_out(vty,"%% GO GO Sven%s", VTY_NEWLINE);	return CMD_SUCCESS;}

这里和王斌笔记有点不同,如果按照作者的来,可能会看不到最后的提示信息,这里需要加上另外两串字符串,ip和ospf的提示信息,如果只加上enable的提示信息的话,那么你看在敲上“ip ospf ?”的时候可能看到的就是空荡荡的,没提示信息。

 

将"ip ospf enable"和Interface视图关联起来:

需要在"ospf_vty.c"的ospf_vty_if_init函数内添加以下内容:

 

/*My commands*/  install_element(INTERFACE_NODE,&interface_ospf_enable_cmd);

表示该命令关联的是Interface视图,这样就修改完毕了,先不和ospf交互,该命令啥事也不干,只输出一个字符串

 

至此代码就修改完毕了,按照上一篇的提示编译安装,然后重启服务即可telnet 2609来查看效果了:

 

[root@sven siwen.xwd]# netstat -nta|grep 260.tcp        0      0 0.0.0.0:2601                0.0.0.0:*                   LISTEN      tcp        0      0 0.0.0.0:2609                0.0.0.0:*                   LISTEN      [root@ siwen.xwd]# telnet localhost 2609Trying ::1...telnet: connect to address ::1: Connection refusedTrying 127.0.0.1...Connected to localhost.Escape character is '^]'.Hello, this is Quagga (version 0.99.20).Copyright 1996-2005 Kunihiro Ishiguro, et al.User Access VerificationPassword: ospfd> enospfd> enable ospfd# conospfd# configure % Command incomplete.ospfd# configure teospfd# configure terminal ospfd(config)# intospfd(config)# interface eth1ospfd(config-if)# ip osospfd(config-if)# ip ospf   authentication       Enable authentication on this interface  authentication-key   Authentication password (key)  cost                 Interface cost  dead-interval        Interval after which a neighbor is declared dead  enable               enable ip ospf router in this Interface  hello-interval       Time between HELLO packets  message-digest-key   Message digest authentication password (key)  mtu-ignore           Disable mtu mismatch detection  network              Network type  priority             Router priority  retransmit-interval  Time between retransmitting lost link state advertisements  transmit-delay       Link state transmit delayospfd(config-if)# ip ospf enospfd(config-if)# ip ospf enable % GO GO Svenospfd(config-if)#

可以看到"ip ospf enable"命令已经加入进去,并且有提示信息,执行完毕后,会输出字符串。

 

 

转载于:https://www.cnblogs.com/jiangu66/p/3192312.html

你可能感兴趣的文章
hbase shell出现ERROR:Can't get master address from Zookeeper;znode data==null
查看>>
sphinx全文检索之PHP使用教程
查看>>
蜗牛讲-fabric原理之锚点
查看>>
获取字符串字节长度跟截取字符串字节长度
查看>>
电影记录管理系统 修改与注释,完整代码
查看>>
sklearn.discriminant_analysis.LinearDiscriminantAnalysis 笔记
查看>>
freebsd 断电 单用户模式恢复
查看>>
一道java笔试题
查看>>
设计师交互推荐-提高设计水平的50套精美的PSD模板
查看>>
《机器学习技法》---AdaBoost算法
查看>>
敏捷开发综述
查看>>
sed简单使用(四)选择性显示
查看>>
广告模式
查看>>
tar 的–exclude参数,实现不包括某些文件(转)
查看>>
Visual C++ 2008入门经典 第十章标准模板库(二)
查看>>
【算法笔记】B1054 求平均值
查看>>
Jmeter4.0---- 测试数据说明(17)
查看>>
大家好
查看>>
Python2与Python3用法区别
查看>>
Nagios监控ganglia的指标
查看>>