version 1.1.1.1, 2012/02/21 17:26:11
|
version 1.1.1.4, 2016/11/02 10:09:10
|
Line 30
|
Line 30
|
#include "zclient.h" |
#include "zclient.h" |
#include "linklist.h" |
#include "linklist.h" |
#include "log.h" |
#include "log.h" |
|
#include "vrf.h" |
|
|
#include "zebra/rib.h" |
#include "zebra/rib.h" |
#include "zebra/zserv.h" |
#include "zebra/zserv.h" |
Line 67 zebra_check_addr (struct prefix *p)
|
Line 68 zebra_check_addr (struct prefix *p)
|
return 1; |
return 1; |
} |
} |
|
|
static int | int |
is_default (struct prefix *p) |
is_default (struct prefix *p) |
{ |
{ |
if (p->family == AF_INET) |
if (p->family == AF_INET) |
Line 85 is_default (struct prefix *p)
|
Line 86 is_default (struct prefix *p)
|
} |
} |
|
|
static void |
static void |
zebra_redistribute_default (struct zserv *client) | zebra_redistribute_default (struct zserv *client, vrf_id_t vrf_id) |
{ |
{ |
struct prefix_ipv4 p; |
struct prefix_ipv4 p; |
struct route_table *table; |
struct route_table *table; |
Line 101 zebra_redistribute_default (struct zserv *client)
|
Line 102 zebra_redistribute_default (struct zserv *client)
|
p.family = AF_INET; |
p.family = AF_INET; |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP, SAFI_UNICAST, 0); | table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); |
if (table) |
if (table) |
{ |
{ |
rn = route_node_lookup (table, (struct prefix *)&p); |
rn = route_node_lookup (table, (struct prefix *)&p); |
if (rn) |
if (rn) |
{ |
{ |
for (newrib = rn->info; newrib; newrib = newrib->next) | RNODE_FOREACH_RIB (rn, newrib) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
&& newrib->distance != DISTANCE_INFINITY) |
&& newrib->distance != DISTANCE_INFINITY) |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib); |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib); |
Line 121 zebra_redistribute_default (struct zserv *client)
|
Line 122 zebra_redistribute_default (struct zserv *client)
|
p6.family = AF_INET6; |
p6.family = AF_INET6; |
|
|
/* Lookup table. */ |
/* Lookup table. */ |
table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); | table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); |
if (table) |
if (table) |
{ |
{ |
rn = route_node_lookup (table, (struct prefix *)&p6); |
rn = route_node_lookup (table, (struct prefix *)&p6); |
if (rn) |
if (rn) |
{ |
{ |
for (newrib = rn->info; newrib; newrib = newrib->next) | RNODE_FOREACH_RIB (rn, newrib) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
&& newrib->distance != DISTANCE_INFINITY) |
&& newrib->distance != DISTANCE_INFINITY) |
zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, &rn->p, newrib); |
zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, &rn->p, newrib); |
Line 139 zebra_redistribute_default (struct zserv *client)
|
Line 140 zebra_redistribute_default (struct zserv *client)
|
|
|
/* Redistribute routes. */ |
/* Redistribute routes. */ |
static void |
static void |
zebra_redistribute (struct zserv *client, int type) | zebra_redistribute (struct zserv *client, int type, vrf_id_t vrf_id) |
{ |
{ |
struct rib *newrib; |
struct rib *newrib; |
struct route_table *table; |
struct route_table *table; |
struct route_node *rn; |
struct route_node *rn; |
|
|
table = vrf_table (AFI_IP, SAFI_UNICAST, 0); | table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); |
if (table) |
if (table) |
for (rn = route_top (table); rn; rn = route_next (rn)) |
for (rn = route_top (table); rn; rn = route_next (rn)) |
for (newrib = rn->info; newrib; newrib = newrib->next) | RNODE_FOREACH_RIB (rn, newrib) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) | { |
&& newrib->type == type | if (IS_ZEBRA_DEBUG_EVENT) |
&& newrib->distance != DISTANCE_INFINITY | zlog_debug("%s: checking: selected=%d, type=%d, distance=%d, zebra_check_addr=%d", |
&& zebra_check_addr (&rn->p)) | __func__, CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED), |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib); | newrib->type, newrib->distance, zebra_check_addr (&rn->p)); |
| if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
| && newrib->type == type |
| && newrib->distance != DISTANCE_INFINITY |
| && zebra_check_addr (&rn->p)) |
| zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib); |
| } |
| |
#ifdef HAVE_IPV6 |
#ifdef HAVE_IPV6 |
table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); | table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); |
if (table) |
if (table) |
for (rn = route_top (table); rn; rn = route_next (rn)) |
for (rn = route_top (table); rn; rn = route_next (rn)) |
for (newrib = rn->info; newrib; newrib = newrib->next) | RNODE_FOREACH_RIB (rn, newrib) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED) |
&& newrib->type == type |
&& newrib->type == type |
&& newrib->distance != DISTANCE_INFINITY |
&& newrib->distance != DISTANCE_INFINITY |
Line 176 redistribute_add (struct prefix *p, struct rib *rib)
|
Line 183 redistribute_add (struct prefix *p, struct rib *rib)
|
|
|
for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) |
for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) |
{ |
{ |
if (is_default (p)) | if ((is_default (p) && |
| vrf_bitmap_check (client->redist_default, rib->vrf_id)) |
| || vrf_bitmap_check (client->redist[rib->type], rib->vrf_id)) |
{ |
{ |
if (client->redist_default || client->redist[rib->type]) |
|
{ |
|
if (p->family == AF_INET) |
|
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); |
|
#ifdef HAVE_IPV6 |
|
if (p->family == AF_INET6) |
|
zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, p, rib); |
|
#endif /* HAVE_IPV6 */ |
|
} |
|
} |
|
else if (client->redist[rib->type]) |
|
{ |
|
if (p->family == AF_INET) |
if (p->family == AF_INET) |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); |
#ifdef HAVE_IPV6 |
#ifdef HAVE_IPV6 |
Line 212 redistribute_delete (struct prefix *p, struct rib *rib
|
Line 209 redistribute_delete (struct prefix *p, struct rib *rib
|
|
|
for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) |
for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) |
{ |
{ |
if (is_default (p)) | if ((is_default (p) && |
| vrf_bitmap_check (client->redist_default, rib->vrf_id)) |
| || vrf_bitmap_check (client->redist[rib->type], rib->vrf_id)) |
{ |
{ |
if (client->redist_default || client->redist[rib->type]) |
|
{ |
|
if (p->family == AF_INET) |
|
zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, |
|
rib); |
|
#ifdef HAVE_IPV6 |
|
if (p->family == AF_INET6) |
|
zsend_route_multipath (ZEBRA_IPV6_ROUTE_DELETE, client, p, |
|
rib); |
|
#endif /* HAVE_IPV6 */ |
|
} |
|
} |
|
else if (client->redist[rib->type]) |
|
{ |
|
if (p->family == AF_INET) |
if (p->family == AF_INET) |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib); |
zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib); |
#ifdef HAVE_IPV6 |
#ifdef HAVE_IPV6 |
Line 239 redistribute_delete (struct prefix *p, struct rib *rib
|
Line 224 redistribute_delete (struct prefix *p, struct rib *rib
|
} |
} |
|
|
void |
void |
zebra_redistribute_add (int command, struct zserv *client, int length) | zebra_redistribute_add (int command, struct zserv *client, int length, |
| vrf_id_t vrf_id) |
{ |
{ |
int type; |
int type; |
|
|
type = stream_getc (client->ibuf); |
type = stream_getc (client->ibuf); |
|
|
switch (type) | if (type == 0 || type >= ZEBRA_ROUTE_MAX) |
| return; |
| |
| if (! vrf_bitmap_check (client->redist[type], vrf_id)) |
{ |
{ |
case ZEBRA_ROUTE_KERNEL: | vrf_bitmap_set (client->redist[type], vrf_id); |
case ZEBRA_ROUTE_CONNECT: | zebra_redistribute (client, type, vrf_id); |
case ZEBRA_ROUTE_STATIC: | |
case ZEBRA_ROUTE_RIP: | |
case ZEBRA_ROUTE_RIPNG: | |
case ZEBRA_ROUTE_OSPF: | |
case ZEBRA_ROUTE_OSPF6: | |
case ZEBRA_ROUTE_BGP: | |
if (! client->redist[type]) | |
{ | |
client->redist[type] = 1; | |
zebra_redistribute (client, type); | |
} | |
break; | |
default: | |
break; | |
} |
} |
} | } |
|
|
void |
void |
zebra_redistribute_delete (int command, struct zserv *client, int length) | zebra_redistribute_delete (int command, struct zserv *client, int length, |
| vrf_id_t vrf_id) |
{ |
{ |
int type; |
int type; |
|
|
type = stream_getc (client->ibuf); |
type = stream_getc (client->ibuf); |
|
|
switch (type) | if (type == 0 || type >= ZEBRA_ROUTE_MAX) |
{ | return; |
case ZEBRA_ROUTE_KERNEL: | |
case ZEBRA_ROUTE_CONNECT: | |
case ZEBRA_ROUTE_STATIC: | |
case ZEBRA_ROUTE_RIP: | |
case ZEBRA_ROUTE_RIPNG: | |
case ZEBRA_ROUTE_OSPF: | |
case ZEBRA_ROUTE_OSPF6: | |
case ZEBRA_ROUTE_BGP: | |
client->redist[type] = 0; | |
break; | |
default: | |
break; | |
} | |
} | |
|
|
|
vrf_bitmap_unset (client->redist[type], vrf_id); |
|
} |
|
|
void |
void |
zebra_redistribute_default_add (int command, struct zserv *client, int length) | zebra_redistribute_default_add (int command, struct zserv *client, int length, |
| vrf_id_t vrf_id) |
{ |
{ |
client->redist_default = 1; | vrf_bitmap_set (client->redist_default, vrf_id); |
zebra_redistribute_default (client); | zebra_redistribute_default (client, vrf_id); |
} |
} |
|
|
void |
void |
zebra_redistribute_default_delete (int command, struct zserv *client, |
zebra_redistribute_default_delete (int command, struct zserv *client, |
int length) | int length, vrf_id_t vrf_id) |
{ |
{ |
client->redist_default = 0;; | vrf_bitmap_unset (client->redist_default, vrf_id); |
} |
} |
|
|
/* Interface up information. */ |
/* Interface up information. */ |
Line 372 zebra_interface_address_add_update (struct interface *
|
Line 338 zebra_interface_address_add_update (struct interface *
|
|
|
if (IS_ZEBRA_DEBUG_EVENT) |
if (IS_ZEBRA_DEBUG_EVENT) |
{ |
{ |
char buf[INET6_ADDRSTRLEN]; | char buf[PREFIX_STRLEN]; |
|
|
p = ifc->address; |
p = ifc->address; |
zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s/%d on %s", | zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s", |
inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN), | prefix2str (p, buf, sizeof(buf)), |
p->prefixlen, ifc->ifp->name); | ifc->ifp->name); |
} |
} |
|
|
|
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) |
|
zlog_warn("WARNING: advertising address to clients that is not yet usable."); |
|
|
router_id_add_address(ifc); |
router_id_add_address(ifc); |
|
|
for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) |
for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) |
Line 398 zebra_interface_address_delete_update (struct interfac
|
Line 367 zebra_interface_address_delete_update (struct interfac
|
|
|
if (IS_ZEBRA_DEBUG_EVENT) |
if (IS_ZEBRA_DEBUG_EVENT) |
{ |
{ |
char buf[INET6_ADDRSTRLEN]; | char buf[PREFIX_STRLEN]; |
|
|
p = ifc->address; |
p = ifc->address; |
zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s/%d on %s", | zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s", |
inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN), | prefix2str (p, buf, sizeof(buf)), |
p->prefixlen, ifc->ifp->name); | ifc->ifp->name); |
} |
} |
|
|
router_id_del_address(ifc); |
router_id_del_address(ifc); |