/* Inbound message handling ------------------------------------------------ */
-const int cmd2type[] = {
- [ZEBRA_NEXTHOP_REGISTER] = RNH_NEXTHOP_TYPE,
- [ZEBRA_NEXTHOP_UNREGISTER] = RNH_NEXTHOP_TYPE,
-};
-
/* Nexthop register */
static void zread_rnh_register(ZAPI_HANDLER_ARGS)
{
unsigned short l = 0;
uint8_t flags = 0;
uint8_t resolve_via_default;
- uint16_t type = cmd2type[hdr->command];
bool exist;
bool flag_changed = false;
uint8_t orig_flags;
if (IS_ZEBRA_DEBUG_NHT)
zlog_debug(
- "rnh_register msg from client %s: hdr->length=%d, type=%s vrf=%u",
+ "rnh_register msg from client %s: hdr->length=%d vrf=%u",
zebra_route_string(client->proto), hdr->length,
- (type == RNH_NEXTHOP_TYPE) ? "nexthop" : "route",
zvrf->vrf->vrf_id);
s = msg;
p.family);
return;
}
- rnh = zebra_add_rnh(&p, zvrf_id(zvrf), type, &exist);
+ rnh = zebra_add_rnh(&p, zvrf_id(zvrf), &exist);
if (!rnh)
return;
orig_flags = rnh->flags;
- if (type == RNH_NEXTHOP_TYPE) {
- if (flags
- && !CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
- SET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
- else if (!flags
- && CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
- UNSET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
- }
+ if (flags && !CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
+ SET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
+ else if (!flags && CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
+ UNSET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
if (resolve_via_default)
SET_FLAG(rnh->flags, ZEBRA_NHT_RESOLVE_VIA_DEFAULT);
/* Anything not AF_INET/INET6 has been filtered out above */
if (!exist || flag_changed)
- zebra_evaluate_rnh(zvrf, family2afi(p.family), 1, type,
- &p);
+ zebra_evaluate_rnh(zvrf, family2afi(p.family), 1, &p);
- zebra_add_rnh_client(rnh, client, type, zvrf_id(zvrf));
+ zebra_add_rnh_client(rnh, client, zvrf_id(zvrf));
}
stream_failure:
struct stream *s;
struct prefix p;
unsigned short l = 0;
- uint16_t type = cmd2type[hdr->command];
if (IS_ZEBRA_DEBUG_NHT)
zlog_debug(
p.family);
return;
}
- rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf), type);
+ rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf));
if (rnh) {
client->nh_dereg_time = monotime(NULL);
- zebra_remove_rnh_client(rnh, client, type);
+ zebra_remove_rnh_client(rnh, client);
}
}
stream_failure:
hook_register(zserv_client_close, zebra_client_cleanup_rnh);
}
-static inline struct route_table *get_rnh_table(vrf_id_t vrfid, afi_t afi,
- enum rnh_type type)
+static inline struct route_table *get_rnh_table(vrf_id_t vrfid, afi_t afi)
{
struct zebra_vrf *zvrf;
struct route_table *t = NULL;
zvrf = zebra_vrf_lookup_by_id(vrfid);
if (zvrf)
- switch (type) {
- case RNH_NEXTHOP_TYPE:
- t = zvrf->rnh_table[afi];
- break;
- }
+ t = zvrf->rnh_table[afi];
return t;
}
route_unlock_node(rn);
}
-struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, enum rnh_type type,
- bool *exists)
+struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, bool *exists)
{
struct route_table *table;
struct route_node *rn;
if (IS_ZEBRA_DEBUG_NHT) {
struct vrf *vrf = vrf_lookup_by_id(vrfid);
- zlog_debug("%s(%u): Add RNH %pFX type %s", VRF_LOGNAME(vrf),
- vrfid, p, rnh_type2str(type));
+ zlog_debug("%s(%u): Add RNH %pFX", VRF_LOGNAME(vrf), vrfid, p);
}
- table = get_rnh_table(vrfid, afi, type);
+ table = get_rnh_table(vrfid, afi);
if (!table) {
struct vrf *vrf = vrf_lookup_by_id(vrfid);
flog_warn(EC_ZEBRA_RNH_NO_TABLE,
- "%s(%u): Add RNH %pFX type %s - table not found",
- VRF_LOGNAME(vrf), vrfid, p, rnh_type2str(type));
+ "%s(%u): Add RNH %pFX - table not found",
+ VRF_LOGNAME(vrf), vrfid, p);
*exists = false;
return NULL;
}
rnh->resolved_route.family = p->family;
rnh->client_list = list_new();
rnh->vrf_id = vrfid;
- rnh->type = type;
rnh->seqno = 0;
rnh->afi = afi;
rnh->zebra_pseudowire_list = list_new();
return (rn->info);
}
-struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid,
- enum rnh_type type)
+struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid)
{
struct route_table *table;
struct route_node *rn;
- table = get_rnh_table(vrfid, family2afi(PREFIX_FAMILY(p)), type);
+ table = get_rnh_table(vrfid, family2afi(PREFIX_FAMILY(p)));
if (!table)
return NULL;
XFREE(MTYPE_RNH, rnh);
}
-static void zebra_delete_rnh(struct rnh *rnh, enum rnh_type type)
+static void zebra_delete_rnh(struct rnh *rnh)
{
struct route_node *rn;
if (IS_ZEBRA_DEBUG_NHT) {
struct vrf *vrf = vrf_lookup_by_id(rnh->vrf_id);
- zlog_debug("%s(%u): Del RNH %pRN type %s", VRF_LOGNAME(vrf),
- rnh->vrf_id, rnh->node, rnh_type2str(type));
+ zlog_debug("%s(%u): Del RNH %pRN", VRF_LOGNAME(vrf),
+ rnh->vrf_id, rnh->node);
}
zebra_free_rnh(rnh);
* and as such it will have a resolved rnh.
*/
void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client,
- enum rnh_type type, vrf_id_t vrf_id)
+ vrf_id_t vrf_id)
{
if (IS_ZEBRA_DEBUG_NHT) {
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
- zlog_debug("%s(%u): Client %s registers for RNH %pRN type %s",
+ zlog_debug("%s(%u): Client %s registers for RNH %pRN",
VRF_LOGNAME(vrf), vrf_id,
- zebra_route_string(client->proto), rnh->node,
- rnh_type2str(type));
+ zebra_route_string(client->proto), rnh->node);
}
if (!listnode_lookup(rnh->client_list, client))
listnode_add(rnh->client_list, client);
* We always need to respond with known information,
* currently multiple daemons expect this behavior
*/
- zebra_send_rnh_update(rnh, client, type, vrf_id, 0);
+ zebra_send_rnh_update(rnh, client, vrf_id, 0);
}
-void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client,
- enum rnh_type type)
+void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client)
{
if (IS_ZEBRA_DEBUG_NHT) {
struct vrf *vrf = vrf_lookup_by_id(rnh->vrf_id);
- zlog_debug("Client %s unregisters for RNH %s(%u)%pRN type %s",
+ zlog_debug("Client %s unregisters for RNH %s(%u)%pRN",
zebra_route_string(client->proto), VRF_LOGNAME(vrf),
- vrf->vrf_id, rnh->node, rnh_type2str(type));
+ vrf->vrf_id, rnh->node);
}
listnode_delete(rnh->client_list, client);
- zebra_delete_rnh(rnh, type);
+ zebra_delete_rnh(rnh);
}
/* XXX move this utility function elsewhere? */
return;
addr2hostprefix(pw->af, &pw->nexthop, &nh);
- rnh = zebra_add_rnh(&nh, vrf_id, RNH_NEXTHOP_TYPE, &exists);
+ rnh = zebra_add_rnh(&nh, vrf_id, &exists);
if (!rnh)
return;
if (!listnode_lookup(rnh->zebra_pseudowire_list, pw)) {
listnode_add(rnh->zebra_pseudowire_list, pw);
pw->rnh = rnh;
- zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1,
- RNH_NEXTHOP_TYPE, &nh);
+ zebra_evaluate_rnh(zvrf, family2afi(pw->af), 1, &nh);
} else
*nht_exists = true;
}
listnode_delete(rnh->zebra_pseudowire_list, pw);
pw->rnh = NULL;
- zebra_delete_rnh(rnh, RNH_NEXTHOP_TYPE);
+ zebra_delete_rnh(rnh);
}
/* Clear the NEXTHOP_FLAG_RNH_FILTERED flags on all nexthops
zebra_route_string(client->proto));
}
- zebra_send_rnh_update(rnh, client, RNH_NEXTHOP_TYPE,
- zvrf->vrf->vrf_id, 0);
+ zebra_send_rnh_update(rnh, client, zvrf->vrf->vrf_id, 0);
}
if (re)
/* Evaluate one tracked entry */
static void zebra_rnh_evaluate_entry(struct zebra_vrf *zvrf, afi_t afi,
- int force, enum rnh_type type,
- struct route_node *nrn)
+ int force, struct route_node *nrn)
{
struct rnh *rnh;
struct route_entry *re;
struct route_node *prn;
if (IS_ZEBRA_DEBUG_NHT) {
- zlog_debug("%s(%u):%pRN: Evaluate RNH, type %s %s",
+ zlog_debug("%s(%u):%pRN: Evaluate RNH, %s",
VRF_LOGNAME(zvrf->vrf), zvrf->vrf->vrf_id, nrn,
- rnh_type2str(type), force ? "(force)" : "");
+ force ? "(force)" : "");
}
rnh = nrn->info;
* covers multiple nexthops we are interested in.
*/
static void zebra_rnh_clear_nhc_flag(struct zebra_vrf *zvrf, afi_t afi,
- enum rnh_type type, struct route_node *nrn)
+ struct route_node *nrn)
{
struct rnh *rnh;
struct route_entry *re;
* of a particular VRF and address-family or a specific prefix.
*/
void zebra_evaluate_rnh(struct zebra_vrf *zvrf, afi_t afi, int force,
- enum rnh_type type, struct prefix *p)
+ struct prefix *p)
{
struct route_table *rnh_table;
struct route_node *nrn;
- rnh_table = get_rnh_table(zvrf->vrf->vrf_id, afi, type);
+ rnh_table = get_rnh_table(zvrf->vrf->vrf_id, afi);
if (!rnh_table) // unexpected
return;
/* Evaluating a specific entry, make sure it exists. */
nrn = route_node_lookup(rnh_table, p);
if (nrn && nrn->info)
- zebra_rnh_evaluate_entry(zvrf, afi, force, type, nrn);
+ zebra_rnh_evaluate_entry(zvrf, afi, force, nrn);
if (nrn)
route_unlock_node(nrn);
nrn = route_top(rnh_table);
while (nrn) {
if (nrn->info)
- zebra_rnh_evaluate_entry(zvrf, afi, force, type,
- nrn);
+ zebra_rnh_evaluate_entry(zvrf, afi, force, nrn);
nrn = route_next(nrn); /* this will also unlock nrn */
}
nrn = route_top(rnh_table);
while (nrn) {
if (nrn->info)
- zebra_rnh_clear_nhc_flag(zvrf, afi, type, nrn);
+ zebra_rnh_clear_nhc_flag(zvrf, afi, nrn);
nrn = route_next(nrn); /* this will also unlock nrn */
}
}
}
void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty,
- enum rnh_type type, struct prefix *p)
+ struct prefix *p)
{
struct route_table *table;
struct route_node *rn;
- table = get_rnh_table(vrfid, afi, type);
+ table = get_rnh_table(vrfid, afi);
if (!table) {
if (IS_ZEBRA_DEBUG_NHT)
zlog_debug("print_rnhs: rnh table not found");
}
int zebra_send_rnh_update(struct rnh *rnh, struct zserv *client,
- enum rnh_type type, vrf_id_t vrf_id,
- uint32_t srte_color)
+ vrf_id_t vrf_id, uint32_t srte_color)
{
struct stream *s = NULL;
struct route_entry *re;
}
static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, afi_t afi,
- struct zserv *client, enum rnh_type type)
+ struct zserv *client)
{
struct route_table *ntable;
struct route_node *nrn;
if (IS_ZEBRA_DEBUG_NHT) {
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
- zlog_debug(
- "%s(%u): Client %s RNH cleanup for family %s type %s",
- VRF_LOGNAME(vrf), vrf_id,
- zebra_route_string(client->proto), afi2str(afi),
- rnh_type2str(type));
+ zlog_debug("%s(%u): Client %s RNH cleanup for family %s",
+ VRF_LOGNAME(vrf), vrf_id,
+ zebra_route_string(client->proto), afi2str(afi));
}
- ntable = get_rnh_table(vrf_id, afi, type);
+ ntable = get_rnh_table(vrf_id, afi);
if (!ntable) {
zlog_debug("cleanup_rnh_client: rnh table not found");
return -1;
continue;
rnh = nrn->info;
- zebra_remove_rnh_client(rnh, client, type);
+ zebra_remove_rnh_client(rnh, client);
}
return 1;
}
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
zvrf = vrf->info;
if (zvrf) {
- zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, client,
- RNH_NEXTHOP_TYPE);
- zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP6, client,
- RNH_NEXTHOP_TYPE);
+ zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP, client);
+ zebra_cleanup_rnh_client(zvrf_id(zvrf), AFI_IP6,
+ client);
}
}