]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* RIPd and zebra interface. |
2 | * Copyright (C) 1997, 1999 Kunihiro Ishiguro <kunihiro@zebra.org> | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | * 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "command.h" | |
25 | #include "prefix.h" | |
bce8e868 | 26 | #include "table.h" |
718e3744 | 27 | #include "stream.h" |
bce8e868 | 28 | #include "memory.h" |
718e3744 | 29 | #include "routemap.h" |
30 | #include "zclient.h" | |
31 | #include "log.h" | |
7076bb2f | 32 | #include "vrf.h" |
718e3744 | 33 | #include "ripd/ripd.h" |
34 | #include "ripd/rip_debug.h" | |
dc63bfd4 | 35 | #include "ripd/rip_interface.h" |
718e3744 | 36 | |
37 | /* All information about zebra. */ | |
38 | struct zclient *zclient = NULL; | |
6b0655a2 | 39 | |
bce8e868 LF |
40 | /* Send ECMP routes to zebra. */ |
41 | static void | |
42 | rip_zebra_ipv4_send (struct route_node *rp, u_char cmd) | |
718e3744 | 43 | { |
bce8e868 LF |
44 | static struct in_addr **nexthops = NULL; |
45 | static unsigned int nexthops_len = 0; | |
46 | ||
47 | struct list *list = (struct list *)rp->info; | |
718e3744 | 48 | struct zapi_ipv4 api; |
bce8e868 LF |
49 | struct listnode *listnode = NULL; |
50 | struct rip_info *rinfo = NULL; | |
51 | int count = 0; | |
718e3744 | 52 | |
7076bb2f | 53 | if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT)) |
718e3744 | 54 | { |
7076bb2f | 55 | api.vrf_id = VRF_DEFAULT; |
718e3744 | 56 | api.type = ZEBRA_ROUTE_RIP; |
7c8ff89e | 57 | api.instance = 0; |
718e3744 | 58 | api.flags = 0; |
59 | api.message = 0; | |
b4e45f67 | 60 | api.safi = SAFI_UNICAST; |
bce8e868 LF |
61 | |
62 | if (nexthops_len < listcount (list)) | |
63 | { | |
64 | nexthops_len = listcount (list); | |
65 | nexthops = XREALLOC (MTYPE_TMP, nexthops, | |
66 | nexthops_len * sizeof (struct in_addr *)); | |
67 | } | |
68 | ||
718e3744 | 69 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
bce8e868 LF |
70 | for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo)) |
71 | { | |
72 | nexthops[count++] = &rinfo->nexthop; | |
73 | if (cmd == ZEBRA_IPV4_ROUTE_ADD) | |
74 | SET_FLAG (rinfo->flags, RIP_RTF_FIB); | |
75 | else | |
76 | UNSET_FLAG (rinfo->flags, RIP_RTF_FIB); | |
77 | } | |
78 | ||
79 | api.nexthop = nexthops; | |
80 | api.nexthop_num = count; | |
718e3744 | 81 | api.ifindex_num = 0; |
bce8e868 LF |
82 | |
83 | rinfo = listgetdata (listhead (list)); | |
84 | ||
718e3744 | 85 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
bce8e868 LF |
86 | api.metric = rinfo->metric; |
87 | ||
88 | if (rinfo->distance && rinfo->distance != ZEBRA_RIP_DISTANCE_DEFAULT) | |
89 | { | |
90 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); | |
91 | api.distance = rinfo->distance; | |
92 | } | |
718e3744 | 93 | |
9471675f CF |
94 | if (rinfo->tag) |
95 | { | |
96 | SET_FLAG (api.message, ZAPI_MESSAGE_TAG); | |
97 | api.tag = rinfo->tag; | |
98 | } | |
99 | ||
bce8e868 LF |
100 | zapi_ipv4_route (cmd, zclient, |
101 | (struct prefix_ipv4 *)&rp->p, &api); | |
718e3744 | 102 | |
bce8e868 | 103 | if (IS_RIP_DEBUG_ZEBRA) |
8478ae7e LF |
104 | { |
105 | if (rip->ecmp) | |
106 | zlog_debug ("%s: %s/%d nexthops %d", | |
107 | (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \ | |
108 | "Install into zebra" : "Delete from zebra", | |
109 | inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen, count); | |
110 | else | |
111 | zlog_debug ("%s: %s/%d", | |
112 | (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \ | |
113 | "Install into zebra" : "Delete from zebra", | |
114 | inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen); | |
115 | } | |
718e3744 | 116 | |
117 | rip_global_route_changes++; | |
118 | } | |
119 | } | |
120 | ||
bce8e868 | 121 | /* Add/update ECMP routes to zebra. */ |
718e3744 | 122 | void |
bce8e868 | 123 | rip_zebra_ipv4_add (struct route_node *rp) |
718e3744 | 124 | { |
bce8e868 LF |
125 | rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_ADD); |
126 | } | |
718e3744 | 127 | |
bce8e868 LF |
128 | /* Delete ECMP routes from zebra. */ |
129 | void | |
130 | rip_zebra_ipv4_delete (struct route_node *rp) | |
131 | { | |
132 | rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_DELETE); | |
718e3744 | 133 | } |
134 | ||
135 | /* Zebra route add and delete treatment. */ | |
dc63bfd4 | 136 | static int |
7076bb2f FL |
137 | rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, |
138 | vrf_id_t vrf_id) | |
718e3744 | 139 | { |
140 | struct stream *s; | |
141 | struct zapi_ipv4 api; | |
142 | unsigned long ifindex; | |
143 | struct in_addr nexthop; | |
144 | struct prefix_ipv4 p; | |
b3556ea3 DS |
145 | |
146 | if (!rip) | |
147 | return 0; | |
148 | ||
718e3744 | 149 | s = zclient->ibuf; |
150 | ifindex = 0; | |
151 | nexthop.s_addr = 0; | |
152 | ||
153 | /* Type, flags, message. */ | |
154 | api.type = stream_getc (s); | |
7c8ff89e | 155 | api.instance = stream_getw (s); |
0fc452dc | 156 | api.flags = stream_getl (s); |
718e3744 | 157 | api.message = stream_getc (s); |
158 | ||
159 | /* IPv4 prefix. */ | |
160 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
161 | p.family = AF_INET; | |
d9178828 | 162 | p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, stream_getc (s)); |
718e3744 | 163 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
164 | ||
165 | /* Nexthop, ifindex, distance, metric. */ | |
166 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) | |
167 | { | |
168 | api.nexthop_num = stream_getc (s); | |
169 | nexthop.s_addr = stream_get_ipv4 (s); | |
170 | } | |
171 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) | |
172 | { | |
173 | api.ifindex_num = stream_getc (s); | |
174 | ifindex = stream_getl (s); | |
175 | } | |
176 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) | |
177 | api.distance = stream_getc (s); | |
fbf5d033 | 178 | else |
179 | api.distance = 255; | |
718e3744 | 180 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
181 | api.metric = stream_getl (s); | |
fbf5d033 | 182 | else |
183 | api.metric = 0; | |
718e3744 | 184 | |
9471675f CF |
185 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG)) |
186 | api.tag = stream_getl (s); | |
187 | else | |
188 | api.tag = 0; | |
189 | ||
718e3744 | 190 | /* Then fetch IPv4 prefixes. */ |
5048fe14 | 191 | if (command == ZEBRA_REDISTRIBUTE_IPV4_ADD) |
fbf5d033 | 192 | rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex, |
9471675f | 193 | &nexthop, api.metric, api.distance, api.tag); |
5048fe14 | 194 | else if (command == ZEBRA_REDISTRIBUTE_IPV4_DEL) |
718e3744 | 195 | rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex); |
196 | ||
197 | return 0; | |
198 | } | |
199 | ||
200 | void | |
dc63bfd4 | 201 | rip_zclient_reset (void) |
718e3744 | 202 | { |
203 | zclient_reset (zclient); | |
204 | } | |
205 | ||
206 | /* RIP route-map set for redistribution */ | |
dc63bfd4 | 207 | static void |
98b718a9 | 208 | rip_routemap_set (int type, const char *name) |
718e3744 | 209 | { |
210 | if (rip->route_map[type].name) | |
211 | free(rip->route_map[type].name); | |
212 | ||
213 | rip->route_map[type].name = strdup (name); | |
214 | rip->route_map[type].map = route_map_lookup_by_name (name); | |
215 | } | |
216 | ||
dc63bfd4 | 217 | static void |
8a676be3 | 218 | rip_redistribute_metric_set (int type, unsigned int metric) |
718e3744 | 219 | { |
220 | rip->route_map[type].metric_config = 1; | |
221 | rip->route_map[type].metric = metric; | |
222 | } | |
223 | ||
dc63bfd4 | 224 | static int |
8a676be3 | 225 | rip_metric_unset (int type, unsigned int metric) |
718e3744 | 226 | { |
227 | #define DONT_CARE_METRIC_RIP 17 | |
228 | if (metric != DONT_CARE_METRIC_RIP && | |
229 | rip->route_map[type].metric != metric) | |
230 | return 1; | |
231 | rip->route_map[type].metric_config = 0; | |
232 | rip->route_map[type].metric = 0; | |
233 | return 0; | |
234 | } | |
235 | ||
236 | /* RIP route-map unset for redistribution */ | |
dc63bfd4 | 237 | static int |
98b718a9 | 238 | rip_routemap_unset (int type, const char *name) |
718e3744 | 239 | { |
240 | if (! rip->route_map[type].name || | |
241 | (name != NULL && strcmp(rip->route_map[type].name,name))) | |
242 | return 1; | |
243 | ||
244 | free (rip->route_map[type].name); | |
245 | rip->route_map[type].name = NULL; | |
246 | rip->route_map[type].map = NULL; | |
247 | ||
248 | return 0; | |
249 | } | |
6b0655a2 | 250 | |
718e3744 | 251 | /* Redistribution types */ |
252 | static struct { | |
253 | int type; | |
254 | int str_min_len; | |
8a676be3 | 255 | const char *str; |
718e3744 | 256 | } redist_type[] = { |
257 | {ZEBRA_ROUTE_KERNEL, 1, "kernel"}, | |
258 | {ZEBRA_ROUTE_CONNECT, 1, "connected"}, | |
259 | {ZEBRA_ROUTE_STATIC, 1, "static"}, | |
260 | {ZEBRA_ROUTE_OSPF, 1, "ospf"}, | |
9c58fbd7 | 261 | {ZEBRA_ROUTE_BGP, 2, "bgp"}, |
65efcfce | 262 | {ZEBRA_ROUTE_VNC, 1, "vnc"}, |
718e3744 | 263 | {0, 0, NULL} |
264 | }; | |
265 | ||
dc63bfd4 | 266 | static int |
718e3744 | 267 | rip_redistribute_unset (int type) |
268 | { | |
7076bb2f | 269 | if (! vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT)) |
718e3744 | 270 | return CMD_SUCCESS; |
271 | ||
7076bb2f | 272 | vrf_bitmap_unset (zclient->redist[AFI_IP][type], VRF_DEFAULT); |
718e3744 | 273 | |
274 | if (zclient->sock > 0) | |
7076bb2f | 275 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT); |
718e3744 | 276 | |
277 | /* Remove the routes from RIP table. */ | |
278 | rip_redistribute_withdraw (type); | |
279 | ||
280 | return CMD_SUCCESS; | |
281 | } | |
282 | ||
283 | int | |
284 | rip_redistribute_check (int type) | |
285 | { | |
7076bb2f | 286 | return vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT); |
718e3744 | 287 | } |
288 | ||
289 | void | |
dc63bfd4 | 290 | rip_redistribute_clean (void) |
718e3744 | 291 | { |
292 | int i; | |
293 | ||
294 | for (i = 0; redist_type[i].str; i++) | |
295 | { | |
7076bb2f | 296 | if (vrf_bitmap_check (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT)) |
718e3744 | 297 | { |
298 | if (zclient->sock > 0) | |
299 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, | |
7076bb2f FL |
300 | zclient, AFI_IP, redist_type[i].type, 0, |
301 | VRF_DEFAULT); | |
718e3744 | 302 | |
7076bb2f | 303 | vrf_bitmap_unset (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT); |
718e3744 | 304 | |
305 | /* Remove the routes from RIP table. */ | |
306 | rip_redistribute_withdraw (redist_type[i].type); | |
307 | } | |
308 | } | |
309 | } | |
310 | ||
311 | DEFUN (rip_redistribute_rip, | |
312 | rip_redistribute_rip_cmd, | |
313 | "redistribute rip", | |
314 | "Redistribute information from another routing protocol\n" | |
315 | "Routing Information Protocol (RIP)\n") | |
316 | { | |
7076bb2f | 317 | vrf_bitmap_set (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT); |
718e3744 | 318 | return CMD_SUCCESS; |
319 | } | |
320 | ||
321 | DEFUN (no_rip_redistribute_rip, | |
322 | no_rip_redistribute_rip_cmd, | |
323 | "no redistribute rip", | |
324 | NO_STR | |
325 | "Redistribute information from another routing protocol\n" | |
326 | "Routing Information Protocol (RIP)\n") | |
327 | { | |
7076bb2f | 328 | vrf_bitmap_unset (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT); |
718e3744 | 329 | return CMD_SUCCESS; |
330 | } | |
331 | ||
332 | DEFUN (rip_redistribute_type, | |
333 | rip_redistribute_type_cmd, | |
40d1cbfb | 334 | "redistribute " FRR_REDIST_STR_RIPD, |
9a57dc69 | 335 | REDIST_STR |
ab0181ee | 336 | FRR_REDIST_HELP_STR_RIPD) |
718e3744 | 337 | { |
338 | int i; | |
339 | ||
340 | for(i = 0; redist_type[i].str; i++) | |
341 | { | |
2caafa8c | 342 | if (strncmp (redist_type[i].str, argv[1]->arg, |
718e3744 | 343 | redist_type[i].str_min_len) == 0) |
344 | { | |
0a589359 | 345 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, |
7076bb2f | 346 | AFI_IP, redist_type[i].type, 0, VRF_DEFAULT); |
718e3744 | 347 | return CMD_SUCCESS; |
348 | } | |
349 | } | |
350 | ||
2caafa8c | 351 | vty_out(vty, "Invalid type %s%s", argv[1]->arg, |
718e3744 | 352 | VTY_NEWLINE); |
353 | ||
354 | return CMD_WARNING; | |
355 | } | |
356 | ||
357 | DEFUN (no_rip_redistribute_type, | |
358 | no_rip_redistribute_type_cmd, | |
40d1cbfb | 359 | "no redistribute " FRR_REDIST_STR_RIPD, |
718e3744 | 360 | NO_STR |
9a57dc69 | 361 | REDIST_STR |
ab0181ee | 362 | FRR_REDIST_HELP_STR_RIPD) |
718e3744 | 363 | { |
364 | int i; | |
365 | ||
366 | for (i = 0; redist_type[i].str; i++) | |
367 | { | |
2caafa8c | 368 | if (strncmp(redist_type[i].str, argv[2]->arg, |
718e3744 | 369 | redist_type[i].str_min_len) == 0) |
370 | { | |
371 | rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP); | |
372 | rip_routemap_unset (redist_type[i].type,NULL); | |
373 | rip_redistribute_unset (redist_type[i].type); | |
374 | return CMD_SUCCESS; | |
375 | } | |
376 | } | |
377 | ||
2caafa8c | 378 | vty_out(vty, "Invalid type %s%s", argv[2]->arg, |
718e3744 | 379 | VTY_NEWLINE); |
380 | ||
381 | return CMD_WARNING; | |
382 | } | |
383 | ||
384 | DEFUN (rip_redistribute_type_routemap, | |
385 | rip_redistribute_type_routemap_cmd, | |
40d1cbfb | 386 | "redistribute " FRR_REDIST_STR_RIPD " route-map WORD", |
9a57dc69 | 387 | REDIST_STR |
ab0181ee | 388 | FRR_REDIST_HELP_STR_RIPD |
718e3744 | 389 | "Route map reference\n" |
390 | "Pointer to route-map entries\n") | |
391 | { | |
80fa0c69 DW |
392 | int idx_protocol = 1; |
393 | int idx_word = 3; | |
718e3744 | 394 | int i; |
395 | ||
396 | for (i = 0; redist_type[i].str; i++) { | |
6d681bd8 | 397 | if (strmatch (redist_type[i].str, argv[idx_protocol]->text)) |
718e3744 | 398 | { |
80fa0c69 | 399 | rip_routemap_set (redist_type[i].type, argv[idx_word]->arg); |
8bb0831e | 400 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, |
7076bb2f | 401 | redist_type[i].type, 0, VRF_DEFAULT); |
718e3744 | 402 | return CMD_SUCCESS; |
403 | } | |
404 | } | |
405 | ||
6d681bd8 | 406 | vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->text, VTY_NEWLINE); |
718e3744 | 407 | |
408 | return CMD_WARNING; | |
409 | } | |
410 | ||
411 | DEFUN (no_rip_redistribute_type_routemap, | |
412 | no_rip_redistribute_type_routemap_cmd, | |
40d1cbfb | 413 | "no redistribute " FRR_REDIST_STR_RIPD " route-map WORD", |
718e3744 | 414 | NO_STR |
9a57dc69 | 415 | REDIST_STR |
ab0181ee | 416 | FRR_REDIST_HELP_STR_RIPD |
718e3744 | 417 | "Route map reference\n" |
418 | "Pointer to route-map entries\n") | |
419 | { | |
80fa0c69 DW |
420 | int idx_protocol = 2; |
421 | int idx_word = 4; | |
718e3744 | 422 | int i; |
423 | ||
6d681bd8 QY |
424 | for (i = 0; redist_type[i].str; i++) { |
425 | if (strmatch (redist_type[i].str, argv[idx_protocol]->text)) | |
426 | { | |
427 | if (rip_routemap_unset (redist_type[i].type,argv[idx_word]->arg)) | |
428 | return CMD_WARNING; | |
429 | rip_redistribute_unset (redist_type[i].type); | |
430 | return CMD_SUCCESS; | |
431 | } | |
432 | } | |
718e3744 | 433 | |
6d681bd8 | 434 | vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->text, VTY_NEWLINE); |
718e3744 | 435 | |
436 | return CMD_WARNING; | |
437 | } | |
438 | ||
439 | DEFUN (rip_redistribute_type_metric, | |
440 | rip_redistribute_type_metric_cmd, | |
40d1cbfb | 441 | "redistribute " FRR_REDIST_STR_RIPD " metric (0-16)", |
9a57dc69 | 442 | REDIST_STR |
ab0181ee | 443 | FRR_REDIST_HELP_STR_RIPD |
718e3744 | 444 | "Metric\n" |
445 | "Metric value\n") | |
446 | { | |
80fa0c69 DW |
447 | int idx_protocol = 1; |
448 | int idx_number = 3; | |
718e3744 | 449 | int i; |
450 | int metric; | |
451 | ||
80fa0c69 | 452 | metric = atoi (argv[idx_number]->arg); |
718e3744 | 453 | |
454 | for (i = 0; redist_type[i].str; i++) { | |
6d681bd8 | 455 | if (strmatch (redist_type[i].str, argv[idx_protocol]->text)) |
718e3744 | 456 | { |
457 | rip_redistribute_metric_set (redist_type[i].type, metric); | |
8bb0831e | 458 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, |
7076bb2f | 459 | redist_type[i].type, 0, VRF_DEFAULT); |
718e3744 | 460 | return CMD_SUCCESS; |
461 | } | |
462 | } | |
463 | ||
6d681bd8 | 464 | vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->text, VTY_NEWLINE); |
718e3744 | 465 | |
466 | return CMD_WARNING; | |
467 | } | |
468 | ||
469 | DEFUN (no_rip_redistribute_type_metric, | |
470 | no_rip_redistribute_type_metric_cmd, | |
40d1cbfb | 471 | "no redistribute " FRR_REDIST_STR_RIPD " metric (0-16)", |
718e3744 | 472 | NO_STR |
9a57dc69 | 473 | REDIST_STR |
ab0181ee | 474 | FRR_REDIST_HELP_STR_RIPD |
718e3744 | 475 | "Metric\n" |
476 | "Metric value\n") | |
477 | { | |
80fa0c69 DW |
478 | int idx_protocol = 2; |
479 | int idx_number = 4; | |
718e3744 | 480 | int i; |
481 | ||
6d681bd8 QY |
482 | for (i = 0; redist_type[i].str; i++) { |
483 | if (strmatch (redist_type[i].str, argv[idx_protocol]->text)) | |
484 | { | |
485 | if (rip_metric_unset (redist_type[i].type, atoi(argv[idx_number]->arg))) | |
486 | return CMD_WARNING; | |
487 | rip_redistribute_unset (redist_type[i].type); | |
488 | return CMD_SUCCESS; | |
489 | } | |
490 | } | |
718e3744 | 491 | |
6d681bd8 | 492 | vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->text, VTY_NEWLINE); |
718e3744 | 493 | |
494 | return CMD_WARNING; | |
495 | } | |
496 | ||
16705130 | 497 | DEFUN (rip_redistribute_type_metric_routemap, |
498 | rip_redistribute_type_metric_routemap_cmd, | |
40d1cbfb | 499 | "redistribute " FRR_REDIST_STR_RIPD " metric (0-16) route-map WORD", |
9a57dc69 | 500 | REDIST_STR |
ab0181ee | 501 | FRR_REDIST_HELP_STR_RIPD |
16705130 | 502 | "Metric\n" |
503 | "Metric value\n" | |
504 | "Route map reference\n" | |
505 | "Pointer to route-map entries\n") | |
506 | { | |
80fa0c69 DW |
507 | int idx_protocol = 1; |
508 | int idx_number = 3; | |
509 | int idx_word = 5; | |
16705130 | 510 | int i; |
511 | int metric; | |
512 | ||
80fa0c69 | 513 | metric = atoi (argv[idx_number]->arg); |
16705130 | 514 | |
515 | for (i = 0; redist_type[i].str; i++) { | |
6d681bd8 | 516 | if (strmatch (redist_type[i].str, argv[idx_protocol]->text)) |
16705130 | 517 | { |
518 | rip_redistribute_metric_set (redist_type[i].type, metric); | |
80fa0c69 | 519 | rip_routemap_set (redist_type[i].type, argv[idx_word]->arg); |
8bb0831e | 520 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, |
7076bb2f | 521 | redist_type[i].type, 0, VRF_DEFAULT); |
16705130 | 522 | return CMD_SUCCESS; |
523 | } | |
524 | } | |
525 | ||
6d681bd8 | 526 | vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->text, VTY_NEWLINE); |
16705130 | 527 | |
528 | return CMD_WARNING; | |
529 | } | |
530 | ||
531 | ||
718e3744 | 532 | DEFUN (no_rip_redistribute_type_metric_routemap, |
533 | no_rip_redistribute_type_metric_routemap_cmd, | |
40d1cbfb | 534 | "no redistribute " FRR_REDIST_STR_RIPD " metric (0-16) route-map WORD", |
718e3744 | 535 | NO_STR |
9a57dc69 | 536 | REDIST_STR |
ab0181ee | 537 | FRR_REDIST_HELP_STR_RIPD |
718e3744 | 538 | "Metric\n" |
539 | "Metric value\n" | |
540 | "Route map reference\n" | |
541 | "Pointer to route-map entries\n") | |
542 | { | |
80fa0c69 DW |
543 | int idx_protocol = 2; |
544 | int idx_number = 4; | |
545 | int idx_word = 6; | |
718e3744 | 546 | int i; |
547 | ||
6d681bd8 QY |
548 | for (i = 0; redist_type[i].str; i++) { |
549 | if (strmatch (redist_type[i].str, argv[idx_protocol]->text)) | |
550 | { | |
551 | if (rip_metric_unset (redist_type[i].type, atoi(argv[idx_number]->arg))) | |
552 | return CMD_WARNING; | |
553 | if (rip_routemap_unset (redist_type[i].type, argv[idx_word]->arg)) | |
554 | { | |
555 | rip_redistribute_metric_set(redist_type[i].type, atoi(argv[idx_number]->arg)); | |
556 | return CMD_WARNING; | |
557 | } | |
558 | rip_redistribute_unset (redist_type[i].type); | |
559 | return CMD_SUCCESS; | |
560 | } | |
718e3744 | 561 | } |
562 | ||
6d681bd8 | 563 | vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->text, VTY_NEWLINE); |
718e3744 | 564 | |
565 | return CMD_WARNING; | |
566 | } | |
6b0655a2 | 567 | |
718e3744 | 568 | /* Default information originate. */ |
569 | ||
570 | DEFUN (rip_default_information_originate, | |
571 | rip_default_information_originate_cmd, | |
572 | "default-information originate", | |
573 | "Control distribution of default route\n" | |
574 | "Distribute a default route\n") | |
575 | { | |
576 | struct prefix_ipv4 p; | |
577 | ||
578 | if (! rip->default_information) | |
579 | { | |
580 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
581 | p.family = AF_INET; | |
582 | ||
583 | rip->default_information = 1; | |
584 | ||
fbf5d033 | 585 | rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0, |
9471675f | 586 | NULL, 0, 0, 0); |
718e3744 | 587 | } |
588 | ||
589 | return CMD_SUCCESS; | |
590 | } | |
591 | ||
592 | DEFUN (no_rip_default_information_originate, | |
593 | no_rip_default_information_originate_cmd, | |
594 | "no default-information originate", | |
595 | NO_STR | |
596 | "Control distribution of default route\n" | |
597 | "Distribute a default route\n") | |
598 | { | |
599 | struct prefix_ipv4 p; | |
600 | ||
601 | if (rip->default_information) | |
602 | { | |
603 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
604 | p.family = AF_INET; | |
605 | ||
606 | rip->default_information = 0; | |
607 | ||
16705130 | 608 | rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0); |
718e3744 | 609 | } |
610 | ||
611 | return CMD_SUCCESS; | |
612 | } | |
6b0655a2 | 613 | |
718e3744 | 614 | /* RIP configuration write function. */ |
dc63bfd4 | 615 | static int |
718e3744 | 616 | config_write_zebra (struct vty *vty) |
617 | { | |
618 | if (! zclient->enable) | |
619 | { | |
620 | vty_out (vty, "no router zebra%s", VTY_NEWLINE); | |
621 | return 1; | |
622 | } | |
7076bb2f | 623 | else if (! vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT)) |
718e3744 | 624 | { |
625 | vty_out (vty, "router zebra%s", VTY_NEWLINE); | |
626 | vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); | |
627 | return 1; | |
628 | } | |
629 | return 0; | |
630 | } | |
631 | ||
632 | int | |
633 | config_write_rip_redistribute (struct vty *vty, int config_mode) | |
634 | { | |
635 | int i; | |
718e3744 | 636 | |
637 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) | |
7c8ff89e | 638 | if (i != zclient->redist_default && |
7076bb2f | 639 | vrf_bitmap_check (zclient->redist[AFI_IP][i], VRF_DEFAULT)) |
718e3744 | 640 | { |
641 | if (config_mode) | |
642 | { | |
643 | if (rip->route_map[i].metric_config) | |
644 | { | |
645 | if (rip->route_map[i].name) | |
646 | vty_out (vty, " redistribute %s metric %d route-map %s%s", | |
f52d13cb | 647 | zebra_route_string(i), rip->route_map[i].metric, |
718e3744 | 648 | rip->route_map[i].name, |
649 | VTY_NEWLINE); | |
650 | else | |
651 | vty_out (vty, " redistribute %s metric %d%s", | |
f52d13cb | 652 | zebra_route_string(i), rip->route_map[i].metric, |
718e3744 | 653 | VTY_NEWLINE); |
654 | } | |
655 | else | |
656 | { | |
657 | if (rip->route_map[i].name) | |
658 | vty_out (vty, " redistribute %s route-map %s%s", | |
f52d13cb | 659 | zebra_route_string(i), rip->route_map[i].name, |
718e3744 | 660 | VTY_NEWLINE); |
661 | else | |
f52d13cb | 662 | vty_out (vty, " redistribute %s%s", zebra_route_string(i), |
718e3744 | 663 | VTY_NEWLINE); |
664 | } | |
665 | } | |
666 | else | |
f52d13cb | 667 | vty_out (vty, " %s", zebra_route_string(i)); |
718e3744 | 668 | } |
669 | return 0; | |
670 | } | |
671 | ||
672 | /* Zebra node structure. */ | |
7fc626de | 673 | static struct cmd_node zebra_node = |
718e3744 | 674 | { |
675 | ZEBRA_NODE, | |
676 | "%s(config-router)# ", | |
677 | }; | |
678 | ||
7076bb2f FL |
679 | static void |
680 | rip_zebra_connected (struct zclient *zclient) | |
681 | { | |
0e5223e7 | 682 | zclient_send_reg_requests (zclient, VRF_DEFAULT); |
7076bb2f FL |
683 | } |
684 | ||
718e3744 | 685 | void |
4140ca4d | 686 | rip_zclient_init (struct thread_master *master) |
718e3744 | 687 | { |
688 | /* Set default value to the zebra client structure. */ | |
4140ca4d | 689 | zclient = zclient_new(master); |
7c8ff89e | 690 | zclient_init (zclient, ZEBRA_ROUTE_RIP, 0); |
7076bb2f | 691 | zclient->zebra_connected = rip_zebra_connected; |
718e3744 | 692 | zclient->interface_add = rip_interface_add; |
693 | zclient->interface_delete = rip_interface_delete; | |
694 | zclient->interface_address_add = rip_interface_address_add; | |
695 | zclient->interface_address_delete = rip_interface_address_delete; | |
718e3744 | 696 | zclient->interface_up = rip_interface_up; |
697 | zclient->interface_down = rip_interface_down; | |
5048fe14 | 698 | zclient->redistribute_route_ipv4_add = rip_zebra_read_ipv4; |
699 | zclient->redistribute_route_ipv4_del = rip_zebra_read_ipv4; | |
718e3744 | 700 | |
701 | /* Install zebra node. */ | |
702 | install_node (&zebra_node, config_write_zebra); | |
703 | ||
704 | /* Install command elements to zebra node. */ | |
718e3744 | 705 | install_default (ZEBRA_NODE); |
706 | install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd); | |
707 | install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd); | |
708 | ||
709 | /* Install command elements to rip node. */ | |
710 | install_element (RIP_NODE, &rip_redistribute_type_cmd); | |
711 | install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd); | |
712 | install_element (RIP_NODE, &rip_redistribute_type_metric_cmd); | |
16705130 | 713 | install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd); |
718e3744 | 714 | install_element (RIP_NODE, &no_rip_redistribute_type_cmd); |
715 | install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd); | |
716 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd); | |
717 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd); | |
718 | install_element (RIP_NODE, &rip_default_information_originate_cmd); | |
719 | install_element (RIP_NODE, &no_rip_default_information_originate_cmd); | |
720 | } |