参考了王斌的文档: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添加自己的命令的更多相关文章

  1. nodejs 编写(添加时间戳)命令行工具 timestamp

    Nodejs除了编写服务器端程序还可以编写命令行工具,如gulp.js就是Nodejs编写的. 接下来我们来实现一个添加时间戳的命令: $ timestamp action https://www.n ...

  2. 添加右键菜单命令 在此处打开命令窗口(E)(带图标)

    @color 0A @title 添加右键菜单命令 在此处打开命令窗口(^&E)(带图标) by wjshan0808 @echo off reg add HKCR\Directory\Bac ...

  3. win7下给右键菜单添加启动cmd命令

    win7下给右键菜单添加启动cmd命令 (2013-07-20 19:20:56) 转载▼ 标签: it 右键 cmd 分类: 小软件操作技巧     最近编辑器在用windows下的gvim,但进入 ...

  4. 给Linux添加google搜索命令

    一次面试时,面试官问怎么在终端直接做到在百度搜索自己的名字,当时没回答出来,面试官给了提示,问http协议.答案是说telnet连接www.baidu.com之后GET 昨天偶然看到一篇博客,http ...

  5. uboot中添加自己的命令【转】

    本文转载自:http://blog.csdn.net/huanghai381/article/details/51206646 每个命令都是通过U_BOOT_CMD宏来定义的.这个宏定义了一个相关的结 ...

  6. Linux添加开机启动命令

    1.vi /etc/rc.d/rc.local 添加要启动的命令 如: service php-fpm start  //这样,开机就自动启动了php扩展 2. crontab -e   //是写定时 ...

  7. windows系统添加删除用户命令!

    参考:net   help   usernet   help   group Net   user添加或修改用户帐户或者显示用户帐户信息. 语法net   user   [UserName   [Pa ...

  8. 为自己的git添加alias,命令缩写

    在多人协作开发时,一般用git来进行代码管理.git有一些命令如:git pull . git push等等,这些命令可以设置alias,也就是缩写.如:git pull 是 git pl, git ...

  9. CentOS -- 添加开机自启动 命令 脚本

    如果只是添加一条开机启动的命令: 1. chmod +x /etc/rc.d/rc.local 2. 将命令写到 /etc/rc.d/rc.local 这个文件中 3. reboot

随机推荐

  1. Github资源汇集

    Github资源汇集 突然发现申请博客园已经两年有余,没有发表过一篇文章,十分惭愧.言归正传,先分享一下两年来收集的部分编程资源,大部分为Github上的项目.虽然网上这样的分享已不在少数,但不如我理 ...

  2. LeetCode——Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  3. Installshield在安装结束时刷新系统

    原文:Installshield在安装结束时刷新系统 在OnEnd里添加代码,两种解决方案 群友kevin的解决方案 #include "ifx.h"  //Call to Win ...

  4. POJ 1284 Primitive Roots 原根

    题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...

  5. 第三记“晋IT”分享成长沙龙

    2014年8月17日下午4点-7点,第三期"晋IT"分享成长沙龙在太原大自然蒙特梭利幼儿园多功能厅成功举办. 8月17日下午两点.小编领先来到场地,提前探訪一下准备情况. &quo ...

  6. OpenGL+VS2013+WIN7(64)组态

    1.下载windows在下面glut安装文件:http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip 2. 拆开发现五个文件 ...

  7. PhotoShop CC安装抠图插件KnockOut 2

    1.KnockOut 2只有32位版本,因此需要给32位的PhotoShop CC安装. 2.下载地址:http://www.cr173.com/soft/28207.html 3.安装KnockOu ...

  8. 用一条SQL语句取出第 m 条到第 n 条记录的方法

    原文:用一条SQL语句取出第 m 条到第 n 条记录的方法   --从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)       *    FROM Table     id ...

  9. SSIS中执行SQL任务组件参数传递的问题

    原文:SSIS中执行SQL任务组件参数传递的问题 症状: 执行SQL任务,传递参数到子查询中,执行报错. 错误: 失败,错误如下:"无法从使用 sub-select 查询的 SQL 语句中派 ...

  10. 值为NULL的对象指针

    相信大家对NULL不会很陌生,NULL 是一个标准规定的宏定义,用来表示空指针常量,当一个指针变量被赋值为NULL时,表示它不再指向任何有效地址,无法在访问任何数据.在VS2012库文件stdio.h ...