diff options
Diffstat (limited to 'lib/zclient.c')
| -rw-r--r-- | lib/zclient.c | 183 |
1 files changed, 141 insertions, 42 deletions
diff --git a/lib/zclient.c b/lib/zclient.c index a4fa0966a7..0c29b523bf 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -389,25 +389,28 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) vrf_id); /* Flush all redistribute request. */ - if (vrf_id == VRF_DEFAULT) - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (zclient->mi_redist[afi][i].enabled) { - struct listnode *node; - u_short *id; - - for (ALL_LIST_ELEMENTS_RO( - zclient->mi_redist[afi][i] - .instances, - node, id)) - if (!(i == zclient->redist_default - && *id == zclient->instance)) - zebra_redistribute_send( - ZEBRA_REDISTRIBUTE_ADD, - zclient, afi, i, - *id, - VRF_DEFAULT); - } + if (vrf_id == VRF_DEFAULT) { + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { + if (!zclient->mi_redist[afi][i].enabled) + continue; + + struct listnode *node; + u_short *id; + + for (ALL_LIST_ELEMENTS_RO( + zclient->mi_redist[afi][i] + .instances, node, id)) + if (!(i == zclient->redist_default + && *id == zclient->instance)) + zebra_redistribute_send( + ZEBRA_REDISTRIBUTE_ADD, + zclient, afi, i, + *id, + VRF_DEFAULT); + } + } + } /* Flush all redistribute request. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) @@ -447,29 +450,32 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) /* Set unwanted redistribute route. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - vrf_bitmap_set(zclient->redist[afi][zclient->redist_default], - vrf_id); + vrf_bitmap_unset(zclient->redist[afi][zclient->redist_default], + vrf_id); /* Flush all redistribute request. */ - if (vrf_id == VRF_DEFAULT) - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (zclient->mi_redist[afi][i].enabled) { - struct listnode *node; - u_short *id; - - for (ALL_LIST_ELEMENTS_RO( - zclient->mi_redist[afi][i] - .instances, - node, id)) - if (!(i == zclient->redist_default - && *id == zclient->instance)) - zebra_redistribute_send( - ZEBRA_REDISTRIBUTE_DELETE, - zclient, afi, i, - *id, - VRF_DEFAULT); - } + if (vrf_id == VRF_DEFAULT) { + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { + if (!zclient->mi_redist[afi][i].enabled) + continue; + + struct listnode *node; + u_short *id; + + for (ALL_LIST_ELEMENTS_RO( + zclient->mi_redist[afi][i] + .instances, node, id)) + if (!(i == zclient->redist_default + && *id == zclient->instance)) + zebra_redistribute_send( + ZEBRA_REDISTRIBUTE_DELETE, + zclient, afi, i, + *id, + VRF_DEFAULT); + } + } + } /* Flush all redistribute request. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) @@ -608,6 +614,33 @@ static int zclient_connect(struct thread *t) return zclient_start(zclient); } +int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p, + bool exact_match, vrf_id_t vrf_id) +{ + struct stream *s; + + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, command, vrf_id); + stream_putc(s, (exact_match) ? 1 : 0); + + stream_putw(s, PREFIX_FAMILY(p)); + stream_putc(s, p->prefixlen); + switch (PREFIX_FAMILY(p)) { + case AF_INET: + stream_put_in_addr(s, &p->u.prefix4); + break; + case AF_INET6: + stream_put(s, &(p->u.prefix6), 16); + break; + default: + break; + } + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + /* * "xdr_encode"-like interface that allows daemon (client) to send * a message to zebra server for a route that needs to be @@ -943,7 +976,7 @@ int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api) stream_putw(s, api->nexthop_num); if (api->nexthop_num) - stream_putw(s, api->nh_vrf_id); + stream_putl(s, api->nh_vrf_id); for (i = 0; i < api->nexthop_num; i++) { api_nh = &api->nexthops[i]; @@ -1094,7 +1127,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) } if (api->nexthop_num) - STREAM_GETW(s, api->nh_vrf_id); + STREAM_GETL(s, api->nh_vrf_id); for (i = 0; i < api->nexthop_num; i++) { api_nh = &api->nexthops[i]; @@ -1179,6 +1212,72 @@ stream_failure: return false; } +struct nexthop *nexthop_from_zapi_nexthop(struct zapi_nexthop *znh) +{ + struct nexthop *n = nexthop_new(); + + n->type = znh->type; + n->ifindex = znh->ifindex; + n->gate = znh->gate; + + /* + * This function does not currently handle labels + */ + + return n; +} + +bool zapi_nexthop_update_decode(struct stream *s, struct zapi_route *nhr) +{ + uint32_t i; + + memset(nhr, 0, sizeof(*nhr)); + + STREAM_GETW(s, nhr->prefix.family); + STREAM_GETC(s, nhr->prefix.prefixlen); + switch(nhr->prefix.family) { + case AF_INET: + STREAM_GET(&nhr->prefix.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN); + break; + case AF_INET6: + STREAM_GET(&nhr->prefix.u.prefix6, s, IPV6_MAX_BYTELEN); + break; + default: + break; + } + + STREAM_GETC(s, nhr->distance); + STREAM_GETL(s, nhr->metric); + STREAM_GETC(s, nhr->nexthop_num); + + for (i = 0; i < nhr->nexthop_num ; i++) { + STREAM_GETC(s, nhr->nexthops[i].type); + switch (nhr->nexthops[i].type) { + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + STREAM_GET(&nhr->nexthops[i].gate.ipv4.s_addr, + s, IPV4_MAX_BYTELEN); + STREAM_GETL(s, nhr->nexthops[i].ifindex); + break; + case NEXTHOP_TYPE_IFINDEX: + STREAM_GETL(s, nhr->nexthops[i].ifindex); + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + STREAM_GET(&nhr->nexthops[i].gate.ipv6, + s, IPV6_MAX_BYTELEN); + STREAM_GETL(s, nhr->nexthops[i].ifindex); + break; + case NEXTHOP_TYPE_BLACKHOLE: + break; + } + } + + return true; +stream_failure: + return false; +} + /* * send a ZEBRA_REDISTRIBUTE_ADD or ZEBRA_REDISTRIBUTE_DELETE * for the route type (ZEBRA_ROUTE_KERNEL etc.). The zebra server will |
