]>
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 | |
bce8e868 LF |
94 | zapi_ipv4_route (cmd, zclient, |
95 | (struct prefix_ipv4 *)&rp->p, &api); | |
718e3744 | 96 | |
bce8e868 | 97 | if (IS_RIP_DEBUG_ZEBRA) |
8478ae7e LF |
98 | { |
99 | if (rip->ecmp) | |
100 | zlog_debug ("%s: %s/%d nexthops %d", | |
101 | (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \ | |
102 | "Install into zebra" : "Delete from zebra", | |
103 | inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen, count); | |
104 | else | |
105 | zlog_debug ("%s: %s/%d", | |
106 | (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \ | |
107 | "Install into zebra" : "Delete from zebra", | |
108 | inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen); | |
109 | } | |
718e3744 | 110 | |
111 | rip_global_route_changes++; | |
112 | } | |
113 | } | |
114 | ||
bce8e868 | 115 | /* Add/update ECMP routes to zebra. */ |
718e3744 | 116 | void |
bce8e868 | 117 | rip_zebra_ipv4_add (struct route_node *rp) |
718e3744 | 118 | { |
bce8e868 LF |
119 | rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_ADD); |
120 | } | |
718e3744 | 121 | |
bce8e868 LF |
122 | /* Delete ECMP routes from zebra. */ |
123 | void | |
124 | rip_zebra_ipv4_delete (struct route_node *rp) | |
125 | { | |
126 | rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_DELETE); | |
718e3744 | 127 | } |
128 | ||
129 | /* Zebra route add and delete treatment. */ | |
dc63bfd4 | 130 | static int |
7076bb2f FL |
131 | rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, |
132 | vrf_id_t vrf_id) | |
718e3744 | 133 | { |
134 | struct stream *s; | |
135 | struct zapi_ipv4 api; | |
136 | unsigned long ifindex; | |
137 | struct in_addr nexthop; | |
138 | struct prefix_ipv4 p; | |
b3556ea3 DS |
139 | |
140 | if (!rip) | |
141 | return 0; | |
142 | ||
718e3744 | 143 | s = zclient->ibuf; |
144 | ifindex = 0; | |
145 | nexthop.s_addr = 0; | |
146 | ||
147 | /* Type, flags, message. */ | |
148 | api.type = stream_getc (s); | |
7c8ff89e | 149 | api.instance = stream_getw (s); |
0fc452dc | 150 | api.flags = stream_getl (s); |
718e3744 | 151 | api.message = stream_getc (s); |
152 | ||
153 | /* IPv4 prefix. */ | |
154 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
155 | p.family = AF_INET; | |
d9178828 | 156 | p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, stream_getc (s)); |
718e3744 | 157 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
158 | ||
159 | /* Nexthop, ifindex, distance, metric. */ | |
160 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) | |
161 | { | |
162 | api.nexthop_num = stream_getc (s); | |
163 | nexthop.s_addr = stream_get_ipv4 (s); | |
164 | } | |
165 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) | |
166 | { | |
167 | api.ifindex_num = stream_getc (s); | |
168 | ifindex = stream_getl (s); | |
169 | } | |
170 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) | |
171 | api.distance = stream_getc (s); | |
fbf5d033 | 172 | else |
173 | api.distance = 255; | |
718e3744 | 174 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
175 | api.metric = stream_getl (s); | |
fbf5d033 | 176 | else |
177 | api.metric = 0; | |
718e3744 | 178 | |
179 | /* Then fetch IPv4 prefixes. */ | |
5048fe14 | 180 | if (command == ZEBRA_REDISTRIBUTE_IPV4_ADD) |
fbf5d033 | 181 | rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex, |
182 | &nexthop, api.metric, api.distance); | |
5048fe14 | 183 | else if (command == ZEBRA_REDISTRIBUTE_IPV4_DEL) |
718e3744 | 184 | rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex); |
185 | ||
186 | return 0; | |
187 | } | |
188 | ||
189 | void | |
dc63bfd4 | 190 | rip_zclient_reset (void) |
718e3744 | 191 | { |
192 | zclient_reset (zclient); | |
193 | } | |
194 | ||
195 | /* RIP route-map set for redistribution */ | |
dc63bfd4 | 196 | static void |
98b718a9 | 197 | rip_routemap_set (int type, const char *name) |
718e3744 | 198 | { |
199 | if (rip->route_map[type].name) | |
200 | free(rip->route_map[type].name); | |
201 | ||
202 | rip->route_map[type].name = strdup (name); | |
203 | rip->route_map[type].map = route_map_lookup_by_name (name); | |
204 | } | |
205 | ||
dc63bfd4 | 206 | static void |
8a676be3 | 207 | rip_redistribute_metric_set (int type, unsigned int metric) |
718e3744 | 208 | { |
209 | rip->route_map[type].metric_config = 1; | |
210 | rip->route_map[type].metric = metric; | |
211 | } | |
212 | ||
dc63bfd4 | 213 | static int |
8a676be3 | 214 | rip_metric_unset (int type, unsigned int metric) |
718e3744 | 215 | { |
216 | #define DONT_CARE_METRIC_RIP 17 | |
217 | if (metric != DONT_CARE_METRIC_RIP && | |
218 | rip->route_map[type].metric != metric) | |
219 | return 1; | |
220 | rip->route_map[type].metric_config = 0; | |
221 | rip->route_map[type].metric = 0; | |
222 | return 0; | |
223 | } | |
224 | ||
225 | /* RIP route-map unset for redistribution */ | |
dc63bfd4 | 226 | static int |
98b718a9 | 227 | rip_routemap_unset (int type, const char *name) |
718e3744 | 228 | { |
229 | if (! rip->route_map[type].name || | |
230 | (name != NULL && strcmp(rip->route_map[type].name,name))) | |
231 | return 1; | |
232 | ||
233 | free (rip->route_map[type].name); | |
234 | rip->route_map[type].name = NULL; | |
235 | rip->route_map[type].map = NULL; | |
236 | ||
237 | return 0; | |
238 | } | |
6b0655a2 | 239 | |
718e3744 | 240 | /* Redistribution types */ |
241 | static struct { | |
242 | int type; | |
243 | int str_min_len; | |
8a676be3 | 244 | const char *str; |
718e3744 | 245 | } redist_type[] = { |
246 | {ZEBRA_ROUTE_KERNEL, 1, "kernel"}, | |
247 | {ZEBRA_ROUTE_CONNECT, 1, "connected"}, | |
248 | {ZEBRA_ROUTE_STATIC, 1, "static"}, | |
249 | {ZEBRA_ROUTE_OSPF, 1, "ospf"}, | |
9c58fbd7 | 250 | {ZEBRA_ROUTE_BGP, 2, "bgp"}, |
65efcfce | 251 | {ZEBRA_ROUTE_VNC, 1, "vnc"}, |
718e3744 | 252 | {0, 0, NULL} |
253 | }; | |
254 | ||
255 | DEFUN (router_zebra, | |
256 | router_zebra_cmd, | |
257 | "router zebra", | |
258 | "Enable a routing process\n" | |
259 | "Make connection to zebra daemon\n") | |
260 | { | |
261 | vty->node = ZEBRA_NODE; | |
262 | zclient->enable = 1; | |
263 | zclient_start (zclient); | |
264 | return CMD_SUCCESS; | |
265 | } | |
266 | ||
267 | DEFUN (no_router_zebra, | |
268 | no_router_zebra_cmd, | |
269 | "no router zebra", | |
270 | NO_STR | |
271 | "Enable a routing process\n" | |
272 | "Make connection to zebra daemon\n") | |
273 | { | |
274 | zclient->enable = 0; | |
275 | zclient_stop (zclient); | |
276 | return CMD_SUCCESS; | |
277 | } | |
278 | ||
2c239705 | 279 | #if 0 |
dc63bfd4 | 280 | static int |
718e3744 | 281 | rip_redistribute_set (int type) |
282 | { | |
7076bb2f | 283 | if (vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT)) |
718e3744 | 284 | return CMD_SUCCESS; |
285 | ||
7076bb2f | 286 | vrf_bitmap_set (zclient->redist[AFI_IP][type], VRF_DEFAULT); |
718e3744 | 287 | |
288 | if (zclient->sock > 0) | |
8bb0831e | 289 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, API_IP, type); |
718e3744 | 290 | |
291 | return CMD_SUCCESS; | |
292 | } | |
2c239705 | 293 | #endif |
718e3744 | 294 | |
dc63bfd4 | 295 | static int |
718e3744 | 296 | rip_redistribute_unset (int type) |
297 | { | |
7076bb2f | 298 | if (! vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT)) |
718e3744 | 299 | return CMD_SUCCESS; |
300 | ||
7076bb2f | 301 | vrf_bitmap_unset (zclient->redist[AFI_IP][type], VRF_DEFAULT); |
718e3744 | 302 | |
303 | if (zclient->sock > 0) | |
7076bb2f | 304 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT); |
718e3744 | 305 | |
306 | /* Remove the routes from RIP table. */ | |
307 | rip_redistribute_withdraw (type); | |
308 | ||
309 | return CMD_SUCCESS; | |
310 | } | |
311 | ||
312 | int | |
313 | rip_redistribute_check (int type) | |
314 | { | |
7076bb2f | 315 | return vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT); |
718e3744 | 316 | } |
317 | ||
318 | void | |
dc63bfd4 | 319 | rip_redistribute_clean (void) |
718e3744 | 320 | { |
321 | int i; | |
322 | ||
323 | for (i = 0; redist_type[i].str; i++) | |
324 | { | |
7076bb2f | 325 | if (vrf_bitmap_check (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT)) |
718e3744 | 326 | { |
327 | if (zclient->sock > 0) | |
328 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, | |
7076bb2f FL |
329 | zclient, AFI_IP, redist_type[i].type, 0, |
330 | VRF_DEFAULT); | |
718e3744 | 331 | |
7076bb2f | 332 | vrf_bitmap_unset (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT); |
718e3744 | 333 | |
334 | /* Remove the routes from RIP table. */ | |
335 | rip_redistribute_withdraw (redist_type[i].type); | |
336 | } | |
337 | } | |
338 | } | |
339 | ||
340 | DEFUN (rip_redistribute_rip, | |
341 | rip_redistribute_rip_cmd, | |
342 | "redistribute rip", | |
343 | "Redistribute information from another routing protocol\n" | |
344 | "Routing Information Protocol (RIP)\n") | |
345 | { | |
7076bb2f | 346 | vrf_bitmap_set (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT); |
718e3744 | 347 | return CMD_SUCCESS; |
348 | } | |
349 | ||
350 | DEFUN (no_rip_redistribute_rip, | |
351 | no_rip_redistribute_rip_cmd, | |
352 | "no redistribute rip", | |
353 | NO_STR | |
354 | "Redistribute information from another routing protocol\n" | |
355 | "Routing Information Protocol (RIP)\n") | |
356 | { | |
7076bb2f | 357 | vrf_bitmap_unset (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT); |
718e3744 | 358 | return CMD_SUCCESS; |
359 | } | |
360 | ||
361 | DEFUN (rip_redistribute_type, | |
362 | rip_redistribute_type_cmd, | |
9a57dc69 PJ |
363 | "redistribute " QUAGGA_REDIST_STR_RIPD, |
364 | REDIST_STR | |
365 | QUAGGA_REDIST_HELP_STR_RIPD) | |
718e3744 | 366 | { |
367 | int i; | |
368 | ||
369 | for(i = 0; redist_type[i].str; i++) | |
370 | { | |
371 | if (strncmp (redist_type[i].str, argv[0], | |
372 | redist_type[i].str_min_len) == 0) | |
373 | { | |
0a589359 | 374 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, |
7076bb2f | 375 | AFI_IP, redist_type[i].type, 0, VRF_DEFAULT); |
718e3744 | 376 | return CMD_SUCCESS; |
377 | } | |
378 | } | |
379 | ||
380 | vty_out(vty, "Invalid type %s%s", argv[0], | |
381 | VTY_NEWLINE); | |
382 | ||
383 | return CMD_WARNING; | |
384 | } | |
385 | ||
386 | DEFUN (no_rip_redistribute_type, | |
387 | no_rip_redistribute_type_cmd, | |
9a57dc69 | 388 | "no redistribute " QUAGGA_REDIST_STR_RIPD, |
718e3744 | 389 | NO_STR |
9a57dc69 PJ |
390 | REDIST_STR |
391 | QUAGGA_REDIST_HELP_STR_RIPD) | |
718e3744 | 392 | { |
393 | int i; | |
394 | ||
395 | for (i = 0; redist_type[i].str; i++) | |
396 | { | |
397 | if (strncmp(redist_type[i].str, argv[0], | |
398 | redist_type[i].str_min_len) == 0) | |
399 | { | |
400 | rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP); | |
401 | rip_routemap_unset (redist_type[i].type,NULL); | |
402 | rip_redistribute_unset (redist_type[i].type); | |
403 | return CMD_SUCCESS; | |
404 | } | |
405 | } | |
406 | ||
407 | vty_out(vty, "Invalid type %s%s", argv[0], | |
408 | VTY_NEWLINE); | |
409 | ||
410 | return CMD_WARNING; | |
411 | } | |
412 | ||
413 | DEFUN (rip_redistribute_type_routemap, | |
414 | rip_redistribute_type_routemap_cmd, | |
9a57dc69 PJ |
415 | "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD", |
416 | REDIST_STR | |
417 | QUAGGA_REDIST_HELP_STR_RIPD | |
718e3744 | 418 | "Route map reference\n" |
419 | "Pointer to route-map entries\n") | |
420 | { | |
421 | int i; | |
422 | ||
423 | for (i = 0; redist_type[i].str; i++) { | |
424 | if (strncmp(redist_type[i].str, argv[0], | |
425 | redist_type[i].str_min_len) == 0) | |
426 | { | |
427 | rip_routemap_set (redist_type[i].type, argv[1]); | |
8bb0831e | 428 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, |
7076bb2f | 429 | redist_type[i].type, 0, VRF_DEFAULT); |
718e3744 | 430 | return CMD_SUCCESS; |
431 | } | |
432 | } | |
433 | ||
434 | vty_out(vty, "Invalid type %s%s", argv[0], | |
435 | VTY_NEWLINE); | |
436 | ||
437 | return CMD_WARNING; | |
438 | } | |
439 | ||
440 | DEFUN (no_rip_redistribute_type_routemap, | |
441 | no_rip_redistribute_type_routemap_cmd, | |
9a57dc69 | 442 | "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD", |
718e3744 | 443 | NO_STR |
9a57dc69 PJ |
444 | REDIST_STR |
445 | QUAGGA_REDIST_HELP_STR_RIPD | |
718e3744 | 446 | "Route map reference\n" |
447 | "Pointer to route-map entries\n") | |
448 | { | |
449 | int i; | |
450 | ||
451 | for (i = 0; redist_type[i].str; i++) | |
452 | { | |
453 | if (strncmp(redist_type[i].str, argv[0], | |
454 | redist_type[i].str_min_len) == 0) | |
455 | { | |
456 | if (rip_routemap_unset (redist_type[i].type,argv[1])) | |
457 | return CMD_WARNING; | |
458 | rip_redistribute_unset (redist_type[i].type); | |
459 | return CMD_SUCCESS; | |
460 | } | |
461 | } | |
462 | ||
463 | vty_out(vty, "Invalid type %s%s", argv[0], | |
464 | VTY_NEWLINE); | |
465 | ||
466 | return CMD_WARNING; | |
467 | } | |
468 | ||
469 | DEFUN (rip_redistribute_type_metric, | |
470 | rip_redistribute_type_metric_cmd, | |
9a57dc69 PJ |
471 | "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>", |
472 | REDIST_STR | |
473 | QUAGGA_REDIST_HELP_STR_RIPD | |
718e3744 | 474 | "Metric\n" |
475 | "Metric value\n") | |
476 | { | |
477 | int i; | |
478 | int metric; | |
479 | ||
480 | metric = atoi (argv[1]); | |
481 | ||
482 | for (i = 0; redist_type[i].str; i++) { | |
483 | if (strncmp(redist_type[i].str, argv[0], | |
484 | redist_type[i].str_min_len) == 0) | |
485 | { | |
486 | rip_redistribute_metric_set (redist_type[i].type, metric); | |
8bb0831e | 487 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, |
7076bb2f | 488 | redist_type[i].type, 0, VRF_DEFAULT); |
718e3744 | 489 | return CMD_SUCCESS; |
490 | } | |
491 | } | |
492 | ||
493 | vty_out(vty, "Invalid type %s%s", argv[0], | |
494 | VTY_NEWLINE); | |
495 | ||
496 | return CMD_WARNING; | |
497 | } | |
498 | ||
499 | DEFUN (no_rip_redistribute_type_metric, | |
500 | no_rip_redistribute_type_metric_cmd, | |
9a57dc69 | 501 | "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>", |
718e3744 | 502 | NO_STR |
9a57dc69 PJ |
503 | REDIST_STR |
504 | QUAGGA_REDIST_HELP_STR_RIPD | |
718e3744 | 505 | "Metric\n" |
506 | "Metric value\n") | |
507 | { | |
508 | int i; | |
509 | ||
510 | for (i = 0; redist_type[i].str; i++) | |
511 | { | |
512 | if (strncmp(redist_type[i].str, argv[0], | |
513 | redist_type[i].str_min_len) == 0) | |
514 | { | |
515 | if (rip_metric_unset (redist_type[i].type, atoi(argv[1]))) | |
516 | return CMD_WARNING; | |
517 | rip_redistribute_unset (redist_type[i].type); | |
518 | return CMD_SUCCESS; | |
519 | } | |
520 | } | |
521 | ||
522 | vty_out(vty, "Invalid type %s%s", argv[0], | |
523 | VTY_NEWLINE); | |
524 | ||
525 | return CMD_WARNING; | |
526 | } | |
527 | ||
16705130 | 528 | DEFUN (rip_redistribute_type_metric_routemap, |
529 | rip_redistribute_type_metric_routemap_cmd, | |
9a57dc69 PJ |
530 | "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD", |
531 | REDIST_STR | |
532 | QUAGGA_REDIST_HELP_STR_RIPD | |
16705130 | 533 | "Metric\n" |
534 | "Metric value\n" | |
535 | "Route map reference\n" | |
536 | "Pointer to route-map entries\n") | |
537 | { | |
538 | int i; | |
539 | int metric; | |
540 | ||
541 | metric = atoi (argv[1]); | |
542 | ||
543 | for (i = 0; redist_type[i].str; i++) { | |
544 | if (strncmp(redist_type[i].str, argv[0], | |
545 | redist_type[i].str_min_len) == 0) | |
546 | { | |
547 | rip_redistribute_metric_set (redist_type[i].type, metric); | |
548 | rip_routemap_set (redist_type[i].type, argv[2]); | |
8bb0831e | 549 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, |
7076bb2f | 550 | redist_type[i].type, 0, VRF_DEFAULT); |
16705130 | 551 | return CMD_SUCCESS; |
552 | } | |
553 | } | |
554 | ||
555 | vty_out(vty, "Invalid type %s%s", argv[0], | |
556 | VTY_NEWLINE); | |
557 | ||
558 | return CMD_WARNING; | |
559 | } | |
560 | ||
561 | ||
718e3744 | 562 | DEFUN (no_rip_redistribute_type_metric_routemap, |
563 | no_rip_redistribute_type_metric_routemap_cmd, | |
9a57dc69 PJ |
564 | "no redistribute " QUAGGA_REDIST_STR_RIPD |
565 | " metric <0-16> route-map WORD", | |
718e3744 | 566 | NO_STR |
9a57dc69 PJ |
567 | REDIST_STR |
568 | QUAGGA_REDIST_HELP_STR_RIPD | |
718e3744 | 569 | "Metric\n" |
570 | "Metric value\n" | |
571 | "Route map reference\n" | |
572 | "Pointer to route-map entries\n") | |
573 | { | |
574 | int i; | |
575 | ||
576 | for (i = 0; redist_type[i].str; i++) | |
577 | { | |
578 | if (strncmp(redist_type[i].str, argv[0], | |
579 | redist_type[i].str_min_len) == 0) | |
580 | { | |
581 | if (rip_metric_unset (redist_type[i].type, atoi(argv[1]))) | |
582 | return CMD_WARNING; | |
583 | if (rip_routemap_unset (redist_type[i].type, argv[2])) | |
584 | { | |
585 | rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1])); | |
586 | return CMD_WARNING; | |
587 | } | |
588 | rip_redistribute_unset (redist_type[i].type); | |
589 | return CMD_SUCCESS; | |
590 | } | |
591 | } | |
592 | ||
593 | vty_out(vty, "Invalid type %s%s", argv[0], | |
594 | VTY_NEWLINE); | |
595 | ||
596 | return CMD_WARNING; | |
597 | } | |
6b0655a2 | 598 | |
718e3744 | 599 | /* Default information originate. */ |
600 | ||
601 | DEFUN (rip_default_information_originate, | |
602 | rip_default_information_originate_cmd, | |
603 | "default-information originate", | |
604 | "Control distribution of default route\n" | |
605 | "Distribute a default route\n") | |
606 | { | |
607 | struct prefix_ipv4 p; | |
608 | ||
609 | if (! rip->default_information) | |
610 | { | |
611 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
612 | p.family = AF_INET; | |
613 | ||
614 | rip->default_information = 1; | |
615 | ||
fbf5d033 | 616 | rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0, |
617 | NULL, 0, 0); | |
718e3744 | 618 | } |
619 | ||
620 | return CMD_SUCCESS; | |
621 | } | |
622 | ||
623 | DEFUN (no_rip_default_information_originate, | |
624 | no_rip_default_information_originate_cmd, | |
625 | "no default-information originate", | |
626 | NO_STR | |
627 | "Control distribution of default route\n" | |
628 | "Distribute a default route\n") | |
629 | { | |
630 | struct prefix_ipv4 p; | |
631 | ||
632 | if (rip->default_information) | |
633 | { | |
634 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
635 | p.family = AF_INET; | |
636 | ||
637 | rip->default_information = 0; | |
638 | ||
16705130 | 639 | rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0); |
718e3744 | 640 | } |
641 | ||
642 | return CMD_SUCCESS; | |
643 | } | |
6b0655a2 | 644 | |
718e3744 | 645 | /* RIP configuration write function. */ |
dc63bfd4 | 646 | static int |
718e3744 | 647 | config_write_zebra (struct vty *vty) |
648 | { | |
649 | if (! zclient->enable) | |
650 | { | |
651 | vty_out (vty, "no router zebra%s", VTY_NEWLINE); | |
652 | return 1; | |
653 | } | |
7076bb2f | 654 | else if (! vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT)) |
718e3744 | 655 | { |
656 | vty_out (vty, "router zebra%s", VTY_NEWLINE); | |
657 | vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); | |
658 | return 1; | |
659 | } | |
660 | return 0; | |
661 | } | |
662 | ||
663 | int | |
664 | config_write_rip_redistribute (struct vty *vty, int config_mode) | |
665 | { | |
666 | int i; | |
718e3744 | 667 | |
668 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) | |
7c8ff89e | 669 | if (i != zclient->redist_default && |
7076bb2f | 670 | vrf_bitmap_check (zclient->redist[AFI_IP][i], VRF_DEFAULT)) |
718e3744 | 671 | { |
672 | if (config_mode) | |
673 | { | |
674 | if (rip->route_map[i].metric_config) | |
675 | { | |
676 | if (rip->route_map[i].name) | |
677 | vty_out (vty, " redistribute %s metric %d route-map %s%s", | |
f52d13cb | 678 | zebra_route_string(i), rip->route_map[i].metric, |
718e3744 | 679 | rip->route_map[i].name, |
680 | VTY_NEWLINE); | |
681 | else | |
682 | vty_out (vty, " redistribute %s metric %d%s", | |
f52d13cb | 683 | zebra_route_string(i), rip->route_map[i].metric, |
718e3744 | 684 | VTY_NEWLINE); |
685 | } | |
686 | else | |
687 | { | |
688 | if (rip->route_map[i].name) | |
689 | vty_out (vty, " redistribute %s route-map %s%s", | |
f52d13cb | 690 | zebra_route_string(i), rip->route_map[i].name, |
718e3744 | 691 | VTY_NEWLINE); |
692 | else | |
f52d13cb | 693 | vty_out (vty, " redistribute %s%s", zebra_route_string(i), |
718e3744 | 694 | VTY_NEWLINE); |
695 | } | |
696 | } | |
697 | else | |
f52d13cb | 698 | vty_out (vty, " %s", zebra_route_string(i)); |
718e3744 | 699 | } |
700 | return 0; | |
701 | } | |
702 | ||
703 | /* Zebra node structure. */ | |
7fc626de | 704 | static struct cmd_node zebra_node = |
718e3744 | 705 | { |
706 | ZEBRA_NODE, | |
707 | "%s(config-router)# ", | |
708 | }; | |
709 | ||
7076bb2f FL |
710 | static void |
711 | rip_zebra_connected (struct zclient *zclient) | |
712 | { | |
0e5223e7 | 713 | zclient_send_reg_requests (zclient, VRF_DEFAULT); |
7076bb2f FL |
714 | } |
715 | ||
718e3744 | 716 | void |
4140ca4d | 717 | rip_zclient_init (struct thread_master *master) |
718e3744 | 718 | { |
719 | /* Set default value to the zebra client structure. */ | |
4140ca4d | 720 | zclient = zclient_new(master); |
7c8ff89e | 721 | zclient_init (zclient, ZEBRA_ROUTE_RIP, 0); |
7076bb2f | 722 | zclient->zebra_connected = rip_zebra_connected; |
718e3744 | 723 | zclient->interface_add = rip_interface_add; |
724 | zclient->interface_delete = rip_interface_delete; | |
725 | zclient->interface_address_add = rip_interface_address_add; | |
726 | zclient->interface_address_delete = rip_interface_address_delete; | |
718e3744 | 727 | zclient->interface_up = rip_interface_up; |
728 | zclient->interface_down = rip_interface_down; | |
5048fe14 | 729 | zclient->redistribute_route_ipv4_add = rip_zebra_read_ipv4; |
730 | zclient->redistribute_route_ipv4_del = rip_zebra_read_ipv4; | |
718e3744 | 731 | |
732 | /* Install zebra node. */ | |
733 | install_node (&zebra_node, config_write_zebra); | |
734 | ||
735 | /* Install command elements to zebra node. */ | |
736 | install_element (CONFIG_NODE, &router_zebra_cmd); | |
737 | install_element (CONFIG_NODE, &no_router_zebra_cmd); | |
738 | install_default (ZEBRA_NODE); | |
739 | install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd); | |
740 | install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd); | |
741 | ||
742 | /* Install command elements to rip node. */ | |
743 | install_element (RIP_NODE, &rip_redistribute_type_cmd); | |
744 | install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd); | |
745 | install_element (RIP_NODE, &rip_redistribute_type_metric_cmd); | |
16705130 | 746 | install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd); |
718e3744 | 747 | install_element (RIP_NODE, &no_rip_redistribute_type_cmd); |
748 | install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd); | |
749 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd); | |
750 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd); | |
751 | install_element (RIP_NODE, &rip_default_information_originate_cmd); | |
752 | install_element (RIP_NODE, &no_rip_default_information_originate_cmd); | |
753 | } |