1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
From 8113b8d3ba0646715a3b922a2a2afc5bc25375d7 Mon Sep 17 00:00:00 2001
From: Zhiyuan Wan <h@iloli.bid>
Date: Wed, 29 Mar 2023 23:05:20 +0800
Subject: [PATCH 1/3] ospfd: Support show advertise router in 'show ip ospf
route' command
Users can now use 'show ip ospf route [detail]' command to show the
originator of each OSPF route item.
Signed-off-by: Zhiyuan Wan <h@iloli.bid>
---
doc/user/ospfd.rst | 7 +++---
ospfd/ospf_vty.c | 56 ++++++++++++++++++++++++++++++++++++----------
2 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/doc/user/ospfd.rst b/doc/user/ospfd.rst
index b69230b99..419928d9f 100644
--- a/doc/user/ospfd.rst
+++ b/doc/user/ospfd.rst
@@ -826,10 +826,11 @@ Showing Information
Show the OSPF database summary.
-.. clicmd:: show ip ospf route [json]
+.. clicmd:: show ip ospf route [detail] [json]
Show the OSPF routing table, as determined by the most recent SPF
- calculation.
+ calculation. If detail is specified, each routing item's
+ advertiser will be show up.
.. clicmd:: show ip ospf [vrf <NAME|all>] border-routers [json]
@@ -840,7 +841,7 @@ Showing Information
.. clicmd:: show ip ospf graceful-restart helper [detail] [json]
- Displays the Grcaeful Restart Helper details including helper
+ Displays the Graceful Restart Helper details including helper
config changes.
.. _opaque-lsa:
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 469e9955e..40b38e18b 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -10553,7 +10553,7 @@ static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
struct route_table *rt,
- json_object *json)
+ json_object *json, bool detail)
{
struct route_node *rn;
struct ospf_route * or ;
@@ -10678,6 +10678,10 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
ifindex2ifname(
path->ifindex,
ospf->vrf_id));
+ json_object_string_addf(
+ json_nexthop,
+ "adv", "%pI4",
+ &path->adv_router);
} else {
vty_out(vty,
"%24s via %pI4, %s\n",
@@ -10687,6 +10691,11 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
path->ifindex,
ospf->vrf_id));
}
+ if (detail && !json)
+ vty_out(vty,
+ "%24s adv %pI4\n",
+ "",
+ &path->adv_router);
}
}
}
@@ -10841,7 +10850,7 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
struct route_table *rt,
- json_object *json)
+ json_object *json, bool detail)
{
struct route_node *rn;
struct ospf_route *er;
@@ -10945,6 +10954,10 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
ifindex2ifname(
path->ifindex,
ospf->vrf_id));
+ json_object_string_addf(
+ json_nexthop, "adv",
+ "%pI4",
+ &path->adv_router);
} else {
vty_out(vty,
"%24s via %pI4, %s\n",
@@ -10954,6 +10967,10 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
path->ifindex,
ospf->vrf_id));
}
+ if (detail && !json)
+ vty_out(vty,
+ "%24s adv %pI4\n", "",
+ &path->adv_router);
}
}
}
@@ -11240,7 +11257,8 @@ DEFUN (show_ip_ospf_instance_border_routers,
}
static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
- json_object *json, uint8_t use_vrf)
+ json_object *json, uint8_t use_vrf,
+ bool detail)
{
json_object *json_vrf = NULL;
@@ -11268,7 +11286,8 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
}
/* Show Network routes. */
- show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
+ show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf,
+ detail);
/* Show Router routes. */
show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
@@ -11279,7 +11298,7 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
/* Show AS External routes. */
show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
- json_vrf);
+ json_vrf, detail);
if (json) {
if (use_vrf) {
@@ -11297,13 +11316,14 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
DEFUN (show_ip_ospf_route,
show_ip_ospf_route_cmd,
- "show ip ospf [vrf <NAME|all>] route [json]",
+ "show ip ospf [vrf <NAME|all>] route [detail] [json]",
SHOW_STR
IP_STR
"OSPF information\n"
VRF_CMD_HELP_STR
"All VRFs\n"
"OSPF routing table\n"
+ "Detailed information\n"
JSON_STR)
{
struct ospf *ospf = NULL;
@@ -11312,14 +11332,19 @@ DEFUN (show_ip_ospf_route,
bool all_vrf = false;
int ret = CMD_SUCCESS;
int inst = 0;
+ int idx = 0;
int idx_vrf = 0;
uint8_t use_vrf = 0;
bool uj = use_json(argc, argv);
+ bool detail = false;
json_object *json = NULL;
if (uj)
json = json_object_new_object();
+ if (argv_find(argv, argc, "detail", &idx))
+ detail = true;
+
OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
/* vrf input is provided could be all or specific vrf*/
@@ -11333,8 +11358,8 @@ DEFUN (show_ip_ospf_route,
if (!ospf->oi_running)
continue;
ospf_output = true;
- ret = show_ip_ospf_route_common(vty, ospf, json,
- use_vrf);
+ ret = show_ip_ospf_route_common(
+ vty, ospf, json, use_vrf, detail);
}
if (uj) {
@@ -11371,7 +11396,8 @@ DEFUN (show_ip_ospf_route,
}
if (ospf) {
- ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
+ ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf,
+ detail);
/* Keep Non-pretty format */
if (uj)
vty_out(vty, "%s\n",
@@ -11387,16 +11413,22 @@ DEFUN (show_ip_ospf_route,
DEFUN (show_ip_ospf_instance_route,
show_ip_ospf_instance_route_cmd,
- "show ip ospf (1-65535) route",
+ "show ip ospf (1-65535) route [detail]",
SHOW_STR
IP_STR
"OSPF information\n"
"Instance ID\n"
- "OSPF routing table\n")
+ "OSPF routing table\n"
+ "Detailed information\n")
{
int idx_number = 3;
+ int idx = 0;
struct ospf *ospf;
unsigned short instance = 0;
+ bool detail = false;
+
+ if (argv_find(argv, argc, "detail", &idx))
+ detail = true;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (instance != ospf_instance)
@@ -11406,7 +11438,7 @@ DEFUN (show_ip_ospf_instance_route,
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
- return show_ip_ospf_route_common(vty, ospf, NULL, 0);
+ return show_ip_ospf_route_common(vty, ospf, NULL, 0, detail);
}
--
2.30.2
|