version 1.1, 2012/02/21 17:26:12
|
version 1.1.1.3, 2016/11/02 10:09:10
|
Line 23
|
Line 23
|
|
|
#include "command.h" |
#include "command.h" |
#include "prefix.h" |
#include "prefix.h" |
|
#include "table.h" |
#include "stream.h" |
#include "stream.h" |
|
#include "memory.h" |
#include "routemap.h" |
#include "routemap.h" |
#include "zclient.h" |
#include "zclient.h" |
#include "log.h" |
#include "log.h" |
|
#include "vrf.h" |
#include "ripd/ripd.h" |
#include "ripd/ripd.h" |
#include "ripd/rip_debug.h" |
#include "ripd/rip_debug.h" |
#include "ripd/rip_interface.h" |
#include "ripd/rip_interface.h" |
|
|
/* All information about zebra. */ |
/* All information about zebra. */ |
struct zclient *zclient = NULL; |
struct zclient *zclient = NULL; |
| |
/* RIPd to zebra command interface. */ | /* Send ECMP routes to zebra. */ |
void | static void |
rip_zebra_ipv4_add (struct prefix_ipv4 *p, struct in_addr *nexthop, | rip_zebra_ipv4_send (struct route_node *rp, u_char cmd) |
u_int32_t metric, u_char distance) | |
{ |
{ |
|
static struct in_addr **nexthops = NULL; |
|
static unsigned int nexthops_len = 0; |
|
|
|
struct list *list = (struct list *)rp->info; |
struct zapi_ipv4 api; |
struct zapi_ipv4 api; |
|
struct listnode *listnode = NULL; |
|
struct rip_info *rinfo = NULL; |
|
int count = 0; |
|
|
if (zclient->redist[ZEBRA_ROUTE_RIP]) | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT)) |
{ |
{ |
|
api.vrf_id = VRF_DEFAULT; |
api.type = ZEBRA_ROUTE_RIP; |
api.type = ZEBRA_ROUTE_RIP; |
api.flags = 0; |
api.flags = 0; |
api.message = 0; |
api.message = 0; |
|
api.safi = SAFI_UNICAST; |
|
|
|
if (nexthops_len < listcount (list)) |
|
{ |
|
nexthops_len = listcount (list); |
|
nexthops = XREALLOC (MTYPE_TMP, nexthops, |
|
nexthops_len * sizeof (struct in_addr *)); |
|
} |
|
|
SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
api.nexthop_num = 1; | for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo)) |
api.nexthop = &nexthop; | { |
| nexthops[count++] = &rinfo->nexthop; |
| if (cmd == ZEBRA_IPV4_ROUTE_ADD) |
| SET_FLAG (rinfo->flags, RIP_RTF_FIB); |
| else |
| UNSET_FLAG (rinfo->flags, RIP_RTF_FIB); |
| } |
| |
| api.nexthop = nexthops; |
| api.nexthop_num = count; |
api.ifindex_num = 0; |
api.ifindex_num = 0; |
|
|
|
rinfo = listgetdata (listhead (list)); |
|
|
SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
api.metric = metric; | api.metric = rinfo->metric; |
|
|
if (distance && distance != ZEBRA_RIP_DISTANCE_DEFAULT) | if (rinfo->distance && rinfo->distance != ZEBRA_RIP_DISTANCE_DEFAULT) |
{ | { |
SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
api.distance = distance; | api.distance = rinfo->distance; |
} | } |
|
|
zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api); | zapi_ipv4_route (cmd, zclient, |
| (struct prefix_ipv4 *)&rp->p, &api); |
|
|
|
if (IS_RIP_DEBUG_ZEBRA) |
|
{ |
|
if (rip->ecmp) |
|
zlog_debug ("%s: %s/%d nexthops %d", |
|
(cmd == ZEBRA_IPV4_ROUTE_ADD) ? \ |
|
"Install into zebra" : "Delete from zebra", |
|
inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen, count); |
|
else |
|
zlog_debug ("%s: %s/%d", |
|
(cmd == ZEBRA_IPV4_ROUTE_ADD) ? \ |
|
"Install into zebra" : "Delete from zebra", |
|
inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen); |
|
} |
|
|
rip_global_route_changes++; |
rip_global_route_changes++; |
} |
} |
} |
} |
|
|
|
/* Add/update ECMP routes to zebra. */ |
void |
void |
rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop, | rip_zebra_ipv4_add (struct route_node *rp) |
u_int32_t metric) | |
{ |
{ |
struct zapi_ipv4 api; | rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_ADD); |
| } |
|
|
if (zclient->redist[ZEBRA_ROUTE_RIP]) | /* Delete ECMP routes from zebra. */ |
{ | void |
api.type = ZEBRA_ROUTE_RIP; | rip_zebra_ipv4_delete (struct route_node *rp) |
api.flags = 0; | { |
api.message = 0; | rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_DELETE); |
SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); | |
api.nexthop_num = 1; | |
api.nexthop = &nexthop; | |
api.ifindex_num = 0; | |
SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); | |
api.metric = metric; | |
| |
zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api); | |
| |
rip_global_route_changes++; | |
} | |
} |
} |
|
|
/* Zebra route add and delete treatment. */ |
/* Zebra route add and delete treatment. */ |
static int |
static int |
rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length) | rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, |
| vrf_id_t vrf_id) |
{ |
{ |
struct stream *s; |
struct stream *s; |
struct zapi_ipv4 api; |
struct zapi_ipv4 api; |
unsigned long ifindex; |
unsigned long ifindex; |
struct in_addr nexthop; |
struct in_addr nexthop; |
struct prefix_ipv4 p; |
struct prefix_ipv4 p; |
| unsigned char plength = 0; |
| |
s = zclient->ibuf; |
s = zclient->ibuf; |
ifindex = 0; |
ifindex = 0; |
nexthop.s_addr = 0; |
nexthop.s_addr = 0; |
Line 111 rip_zebra_read_ipv4 (int command, struct zclient *zcli
|
Line 149 rip_zebra_read_ipv4 (int command, struct zclient *zcli
|
/* IPv4 prefix. */ |
/* IPv4 prefix. */ |
memset (&p, 0, sizeof (struct prefix_ipv4)); |
memset (&p, 0, sizeof (struct prefix_ipv4)); |
p.family = AF_INET; |
p.family = AF_INET; |
p.prefixlen = stream_getc (s); | plength = stream_getc (s); |
| p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength); |
stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
|
|
/* Nexthop, ifindex, distance, metric. */ |
/* Nexthop, ifindex, distance, metric. */ |
Line 194 rip_routemap_unset (int type, const char *name)
|
Line 233 rip_routemap_unset (int type, const char *name)
|
|
|
return 0; |
return 0; |
} |
} |
| |
/* Redistribution types */ |
/* Redistribution types */ |
static struct { |
static struct { |
int type; |
int type; |
Line 205 static struct {
|
Line 244 static struct {
|
{ZEBRA_ROUTE_CONNECT, 1, "connected"}, |
{ZEBRA_ROUTE_CONNECT, 1, "connected"}, |
{ZEBRA_ROUTE_STATIC, 1, "static"}, |
{ZEBRA_ROUTE_STATIC, 1, "static"}, |
{ZEBRA_ROUTE_OSPF, 1, "ospf"}, |
{ZEBRA_ROUTE_OSPF, 1, "ospf"}, |
{ZEBRA_ROUTE_BGP, 1, "bgp"}, | {ZEBRA_ROUTE_BGP, 2, "bgp"}, |
| {ZEBRA_ROUTE_BABEL, 2, "babel"}, |
{0, 0, NULL} |
{0, 0, NULL} |
}; |
}; |
|
|
Line 237 DEFUN (no_router_zebra,
|
Line 277 DEFUN (no_router_zebra,
|
static int |
static int |
rip_redistribute_set (int type) |
rip_redistribute_set (int type) |
{ |
{ |
if (zclient->redist[type]) | if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)) |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
|
|
zclient->redist[type] = 1; | vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT); |
|
|
if (zclient->sock > 0) |
if (zclient->sock > 0) |
zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type); |
zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type); |
Line 252 rip_redistribute_set (int type)
|
Line 292 rip_redistribute_set (int type)
|
static int |
static int |
rip_redistribute_unset (int type) |
rip_redistribute_unset (int type) |
{ |
{ |
if (! zclient->redist[type]) | if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)) |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
|
|
zclient->redist[type] = 0; | vrf_bitmap_unset (zclient->redist[type], VRF_DEFAULT); |
|
|
if (zclient->sock > 0) |
if (zclient->sock > 0) |
zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type); | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type, |
| VRF_DEFAULT); |
|
|
/* Remove the routes from RIP table. */ |
/* Remove the routes from RIP table. */ |
rip_redistribute_withdraw (type); |
rip_redistribute_withdraw (type); |
Line 269 rip_redistribute_unset (int type)
|
Line 310 rip_redistribute_unset (int type)
|
int |
int |
rip_redistribute_check (int type) |
rip_redistribute_check (int type) |
{ |
{ |
return (zclient->redist[type]); | return vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT); |
} |
} |
|
|
void |
void |
Line 279 rip_redistribute_clean (void)
|
Line 320 rip_redistribute_clean (void)
|
|
|
for (i = 0; redist_type[i].str; i++) |
for (i = 0; redist_type[i].str; i++) |
{ |
{ |
if (zclient->redist[redist_type[i].type]) | if (vrf_bitmap_check (zclient->redist[redist_type[i].type], VRF_DEFAULT)) |
{ |
{ |
if (zclient->sock > 0) |
if (zclient->sock > 0) |
zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, |
zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, |
zclient, redist_type[i].type); | zclient, redist_type[i].type, |
| VRF_DEFAULT); |
|
|
zclient->redist[redist_type[i].type] = 0; | vrf_bitmap_unset (zclient->redist[redist_type[i].type], VRF_DEFAULT); |
|
|
/* Remove the routes from RIP table. */ |
/* Remove the routes from RIP table. */ |
rip_redistribute_withdraw (redist_type[i].type); |
rip_redistribute_withdraw (redist_type[i].type); |
Line 299 DEFUN (rip_redistribute_rip,
|
Line 341 DEFUN (rip_redistribute_rip,
|
"Redistribute information from another routing protocol\n" |
"Redistribute information from another routing protocol\n" |
"Routing Information Protocol (RIP)\n") |
"Routing Information Protocol (RIP)\n") |
{ |
{ |
zclient->redist[ZEBRA_ROUTE_RIP] = 1; | vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT); |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
|
|
Line 310 DEFUN (no_rip_redistribute_rip,
|
Line 352 DEFUN (no_rip_redistribute_rip,
|
"Redistribute information from another routing protocol\n" |
"Redistribute information from another routing protocol\n" |
"Routing Information Protocol (RIP)\n") |
"Routing Information Protocol (RIP)\n") |
{ |
{ |
zclient->redist[ZEBRA_ROUTE_RIP] = 0; | vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT); |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
|
|
Line 328 DEFUN (rip_redistribute_type,
|
Line 370 DEFUN (rip_redistribute_type,
|
redist_type[i].str_min_len) == 0) |
redist_type[i].str_min_len) == 0) |
{ |
{ |
zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, |
zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, |
redist_type[i].type); | redist_type[i].type, VRF_DEFAULT); |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
} |
} |
Line 381 DEFUN (rip_redistribute_type_routemap,
|
Line 423 DEFUN (rip_redistribute_type_routemap,
|
redist_type[i].str_min_len) == 0) |
redist_type[i].str_min_len) == 0) |
{ |
{ |
rip_routemap_set (redist_type[i].type, argv[1]); |
rip_routemap_set (redist_type[i].type, argv[1]); |
zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type, |
| VRF_DEFAULT); |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
} |
} |
Line 439 DEFUN (rip_redistribute_type_metric,
|
Line 482 DEFUN (rip_redistribute_type_metric,
|
redist_type[i].str_min_len) == 0) |
redist_type[i].str_min_len) == 0) |
{ |
{ |
rip_redistribute_metric_set (redist_type[i].type, metric); |
rip_redistribute_metric_set (redist_type[i].type, metric); |
zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type, |
| VRF_DEFAULT); |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
} |
} |
Line 500 DEFUN (rip_redistribute_type_metric_routemap,
|
Line 544 DEFUN (rip_redistribute_type_metric_routemap,
|
{ |
{ |
rip_redistribute_metric_set (redist_type[i].type, metric); |
rip_redistribute_metric_set (redist_type[i].type, metric); |
rip_routemap_set (redist_type[i].type, argv[2]); |
rip_routemap_set (redist_type[i].type, argv[2]); |
zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type, |
| VRF_DEFAULT); |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
} |
} |
Line 548 DEFUN (no_rip_redistribute_type_metric_routemap,
|
Line 593 DEFUN (no_rip_redistribute_type_metric_routemap,
|
|
|
return CMD_WARNING; |
return CMD_WARNING; |
} |
} |
| |
/* Default information originate. */ |
/* Default information originate. */ |
|
|
DEFUN (rip_default_information_originate, |
DEFUN (rip_default_information_originate, |
Line 594 DEFUN (no_rip_default_information_originate,
|
Line 639 DEFUN (no_rip_default_information_originate,
|
|
|
return CMD_SUCCESS; |
return CMD_SUCCESS; |
} |
} |
| |
/* RIP configuration write function. */ |
/* RIP configuration write function. */ |
static int |
static int |
config_write_zebra (struct vty *vty) |
config_write_zebra (struct vty *vty) |
Line 604 config_write_zebra (struct vty *vty)
|
Line 649 config_write_zebra (struct vty *vty)
|
vty_out (vty, "no router zebra%s", VTY_NEWLINE); |
vty_out (vty, "no router zebra%s", VTY_NEWLINE); |
return 1; |
return 1; |
} |
} |
else if (! zclient->redist[ZEBRA_ROUTE_RIP]) | else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT)) |
{ |
{ |
vty_out (vty, "router zebra%s", VTY_NEWLINE); |
vty_out (vty, "router zebra%s", VTY_NEWLINE); |
vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); |
vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); |
Line 619 config_write_rip_redistribute (struct vty *vty, int co
|
Line 664 config_write_rip_redistribute (struct vty *vty, int co
|
int i; |
int i; |
|
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
if (i != zclient->redist_default && zclient->redist[i]) | if (i != zclient->redist_default && |
| vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT)) |
{ |
{ |
if (config_mode) |
if (config_mode) |
{ |
{ |
Line 659 static struct cmd_node zebra_node =
|
Line 705 static struct cmd_node zebra_node =
|
"%s(config-router)# ", |
"%s(config-router)# ", |
}; |
}; |
|
|
|
static void |
|
rip_zebra_connected (struct zclient *zclient) |
|
{ |
|
zclient_send_requests (zclient, VRF_DEFAULT); |
|
} |
|
|
void |
void |
rip_zclient_init () | rip_zclient_init (struct thread_master *master) |
{ |
{ |
/* Set default value to the zebra client structure. */ |
/* Set default value to the zebra client structure. */ |
zclient = zclient_new (); | zclient = zclient_new (master); |
zclient_init (zclient, ZEBRA_ROUTE_RIP); |
zclient_init (zclient, ZEBRA_ROUTE_RIP); |
|
zclient->zebra_connected = rip_zebra_connected; |
zclient->interface_add = rip_interface_add; |
zclient->interface_add = rip_interface_add; |
zclient->interface_delete = rip_interface_delete; |
zclient->interface_delete = rip_interface_delete; |
zclient->interface_address_add = rip_interface_address_add; |
zclient->interface_address_add = rip_interface_address_add; |