Quagga添加自己的命令
参考了王斌的文档: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 2609
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 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 Verification Password:
ospfd> en
ospfd> enable
ospfd# con
ospfd# configure
% Command incomplete.
ospfd# configure te
ospfd# configure terminal
ospfd(config)# int
ospfd(config)# interface eth1
ospfd(config-if)# ip os
ospfd(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 delay
ospfd(config-if)# ip ospf en
ospfd(config-if)# ip ospf enable
% GO GO Sven
ospfd(config-if)#
可以看到"ip ospf enable"命令已经加入进去,并且有提示信息,执行完毕后,会输出字符串。
Quagga添加自己的命令的更多相关文章
- nodejs 编写(添加时间戳)命令行工具 timestamp
Nodejs除了编写服务器端程序还可以编写命令行工具,如gulp.js就是Nodejs编写的. 接下来我们来实现一个添加时间戳的命令: $ timestamp action https://www.n ...
- 添加右键菜单命令 在此处打开命令窗口(E)(带图标)
@color 0A @title 添加右键菜单命令 在此处打开命令窗口(^&E)(带图标) by wjshan0808 @echo off reg add HKCR\Directory\Bac ...
- win7下给右键菜单添加启动cmd命令
win7下给右键菜单添加启动cmd命令 (2013-07-20 19:20:56) 转载▼ 标签: it 右键 cmd 分类: 小软件操作技巧 最近编辑器在用windows下的gvim,但进入 ...
- 给Linux添加google搜索命令
一次面试时,面试官问怎么在终端直接做到在百度搜索自己的名字,当时没回答出来,面试官给了提示,问http协议.答案是说telnet连接www.baidu.com之后GET 昨天偶然看到一篇博客,http ...
- uboot中添加自己的命令【转】
本文转载自:http://blog.csdn.net/huanghai381/article/details/51206646 每个命令都是通过U_BOOT_CMD宏来定义的.这个宏定义了一个相关的结 ...
- Linux添加开机启动命令
1.vi /etc/rc.d/rc.local 添加要启动的命令 如: service php-fpm start //这样,开机就自动启动了php扩展 2. crontab -e //是写定时 ...
- windows系统添加删除用户命令!
参考:net help usernet help group Net user添加或修改用户帐户或者显示用户帐户信息. 语法net user [UserName [Pa ...
- 为自己的git添加alias,命令缩写
在多人协作开发时,一般用git来进行代码管理.git有一些命令如:git pull . git push等等,这些命令可以设置alias,也就是缩写.如:git pull 是 git pl, git ...
- CentOS -- 添加开机自启动 命令 脚本
如果只是添加一条开机启动的命令: 1. chmod +x /etc/rc.d/rc.local 2. 将命令写到 /etc/rc.d/rc.local 这个文件中 3. reboot
随机推荐
- 多线程学习之BlockingQueue
前言: 在新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列 类,为我们快速搭建高质量的多线程程序带来极大的 ...
- C语言库函数大全及应用实例一
原文:C语言库函数大全及应用实例一 [编程资料]C语言库函数大全及应用实例一 函数名: abort 功 能: 异常终止一个进程 用 法: ...
- C#映射网络驱动器
using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] public class NetResource ...
- Mac OSX操作系统安装和配置Zend Server 6教程(3)
Zend Server安装好以后,在php.ini文件中,没有默认时区.就是导致很多警告信息出现的根本. 接下来,我们看看如果修改这个文件. 首先,进入php.ini文件.此文件在目录zend/etc ...
- IIS 5.x/6.0/7.0 和 ASP.NET
原文:IIS 5.x/6.0/7.0 和 ASP.NET 本文主要介绍 3 个主要的 IIS 版本各自对 Web 请求的不同处理方式. 本文内容 IIS 5.x 和 ASP.NET IIS 6.0 和 ...
- HTML表单元素
HTML表单元素 表单元素同意的形式向用户(例:文本字段,下拉列表,单箱,检查盒等)输入元素信息 表单标签 文本域(Text Fields) 当用户要在表单中键入字母,数字等内容时,就会用到文本域 单 ...
- 设置checkbox为只读(readOnly)
方式一: checkbox没有readOnly属性,如果使用disabled=“disabled”属性的话,会让checkbox变成灰色的,用户很反感这种样式可以这样让它保持只读:设置它的onclic ...
- c/c++中typedef详解
1. typedef 最简单使用 typedef long byte_4; // 给已知数据类型long起个新名字,叫byte_4 你可以在任何需要 long 的上下文中使用 byte_4.注意 ty ...
- [Usaco2008 Nov]Guarding the Farm 保卫牧场[DFS]
Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...
- vijos1053 用spfa判断是否存在负环
MARK 用spfa判断是否存在负环 判断是否存在负环的方法有很多, 其中用spfa判断的方法是:如果存在一个点入栈两次,那么就存在负环. 细节想想确实是这样,按理来说是不存在入栈两次的如果边权值为正 ...