* "xdr_encode"-like interface that allows daemon (client) to send
* a message to zebra server for a route that needs to be
* added/deleted to the kernel. Info about the route is specified
- * by the caller in a struct zapi_ipv4. zapi_ipv4_read() then writes
+ * by the caller in a struct zapi_route. zapi_route_encode() then writes
* the info down the zclient socket using the stream_* functions.
*
* The corresponding read ("xdr_decode") function on the server
- * side is zread_ipv4_add()/zread_ipv4_delete().
+ * side is zapi_route_decode().
*
* 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* is set to 1 and a nexthop of type NEXTHOP_TYPE_BLACKHOLE is the sole
* nexthop.
*
- * The original struct zapi_ipv4, zapi_ipv4_route() and zread_ipv4_*()
- * infrastructure was built around the traditional (32-bit "gate OR
- * ifindex") nexthop data unit. A special encoding can be used to feed
- * onlink (64-bit "gate AND ifindex") nexthops into zapi_ipv4_route()
- * using the same zapi_ipv4 structure. This is done by setting zapi_ipv4
- * fields as follows:
+ * The original struct zapi_route_*() infrastructure was built around
+ * the traditional (32-bit "gate OR ifindex") nexthop data unit.
+ * A special encoding can be used to feed onlink (64-bit "gate AND ifindex")
+ * nexthops into zapi_route_encode() using the same zapi_route structure.
+ * This is done by setting zapi_route fields as follows:
* - .message |= ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_ONLINK
* - .nexthop_num == .ifindex_num
* - .nexthop and .ifindex are filled with gate and ifindex parts of
* each compound nexthop, both in the same order
*
- * zapi_ipv4_route() will produce two nexthop data units for each such
- * interleaved 64-bit nexthop. On the zserv side of the socket it will be
- * mapped to a singlle NEXTHOP_TYPE_IPV4_IFINDEX_OL RIB nexthop structure.
- *
* If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1
* byte value.
*
*
* XXX: No attention paid to alignment.
*/
-int zapi_ipv4_route(uint8_t cmd, struct zclient *zclient, struct prefix_ipv4 *p,
- struct zapi_ipv4 *api)
-{
- int i;
- int psize;
- struct stream *s;
-
- /* Reset stream. */
- s = zclient->obuf;
- stream_reset(s);
-
- /* Some checks for labeled-unicast. The current expectation is that each
- * nexthop is accompanied by a label in the case of labeled-unicast.
- */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)
- && CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
- /* We expect prefixes installed with labels and the number to
- * match
- * the number of nexthops.
- */
- assert(api->label_num == api->nexthop_num);
- }
-
- zclient_create_header(s, cmd, api->vrf_id);
-
- /* Put type and nexthop. */
- stream_putc(s, api->type);
- stream_putw(s, api->instance);
- stream_putl(s, api->flags);
- stream_putc(s, api->message);
- stream_putw(s, api->safi);
-
- /* Put prefix information. */
- psize = PSIZE(p->prefixlen);
- stream_putc(s, p->prefixlen);
- stream_write(s, (uint8_t *)&p->prefix, psize);
-
- /* Nexthop, ifindex, distance and metric information. */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
- stream_putc(s, api->nexthop_num + api->ifindex_num);
-
- for (i = 0; i < api->nexthop_num; i++) {
- stream_putc(s, NEXTHOP_TYPE_IPV4);
- stream_put_in_addr(s, api->nexthop[i]);
- /* For labeled-unicast, each nexthop is followed by
- * label. */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL))
- stream_putl(s, api->label[i]);
- }
- for (i = 0; i < api->ifindex_num; i++) {
- stream_putc(s, NEXTHOP_TYPE_IFINDEX);
- stream_putl(s, api->ifindex[i]);
- }
- }
-
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_DISTANCE))
- stream_putc(s, api->distance);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_METRIC))
- stream_putl(s, api->metric);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TAG))
- stream_putl(s, api->tag);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_MTU))
- stream_putl(s, api->mtu);
-
- /* Put length at the first point of the stream. */
- stream_putw_at(s, 0, stream_get_endp(s));
-
- return zclient_send_message(zclient);
-}
-
-int zapi_ipv4_route_ipv6_nexthop(uint8_t cmd, struct zclient *zclient,
- struct prefix_ipv4 *p, struct zapi_ipv6 *api)
-{
- int i;
- int psize;
- struct stream *s;
-
- /* Reset stream. */
- s = zclient->obuf;
- stream_reset(s);
-
- /* Some checks for labeled-unicast. The current expectation is that each
- * nexthop is accompanied by a label in the case of labeled-unicast.
- */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)
- && CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
- /* We expect prefixes installed with labels and the number to
- * match
- * the number of nexthops.
- */
- assert(api->label_num == api->nexthop_num);
- }
-
- zclient_create_header(s, cmd, api->vrf_id);
-
- /* Put type and nexthop. */
- stream_putc(s, api->type);
- stream_putw(s, api->instance);
- stream_putl(s, api->flags);
- stream_putc(s, api->message);
- stream_putw(s, api->safi);
-
- /* Put prefix information. */
- psize = PSIZE(p->prefixlen);
- stream_putc(s, p->prefixlen);
- stream_write(s, (uint8_t *)&p->prefix, psize);
-
- /* Nexthop, ifindex, distance and metric information. */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
- stream_putc(s, api->nexthop_num + api->ifindex_num);
-
- for (i = 0; i < api->nexthop_num; i++) {
- stream_putc(s, NEXTHOP_TYPE_IPV6);
- stream_write(s, (uint8_t *)api->nexthop[i], 16);
- /* For labeled-unicast, each nexthop is followed by
- * label. */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL))
- stream_putl(s, api->label[i]);
- }
- for (i = 0; i < api->ifindex_num; i++) {
- stream_putc(s, NEXTHOP_TYPE_IFINDEX);
- stream_putl(s, api->ifindex[i]);
- }
- }
-
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_DISTANCE))
- stream_putc(s, api->distance);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_METRIC))
- stream_putl(s, api->metric);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TAG))
- stream_putl(s, api->tag);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_MTU))
- stream_putl(s, api->mtu);
-
- /* Put length at the first point of the stream. */
- stream_putw_at(s, 0, stream_get_endp(s));
-
- return zclient_send_message(zclient);
-}
-
-int zapi_ipv6_route(uint8_t cmd, struct zclient *zclient, struct prefix_ipv6 *p,
- struct prefix_ipv6 *src_p, struct zapi_ipv6 *api)
-{
- int i;
- int psize;
- struct stream *s;
-
- /* either we have !SRCPFX && src_p == NULL, or SRCPFX && src_p != NULL
- */
- assert(!(api->message & ZAPI_MESSAGE_SRCPFX) == !src_p);
-
- /* Reset stream. */
- s = zclient->obuf;
- stream_reset(s);
-
- /* Some checks for labeled-unicast. The current expectation is that each
- * nexthop is accompanied by a label in the case of labeled-unicast.
- */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)
- && CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
- /* We expect prefixes installed with labels and the number to
- * match
- * the number of nexthops.
- */
- assert(api->label_num == api->nexthop_num);
- }
-
- zclient_create_header(s, cmd, api->vrf_id);
-
- /* Put type and nexthop. */
- stream_putc(s, api->type);
- stream_putw(s, api->instance);
- stream_putl(s, api->flags);
- stream_putc(s, api->message);
- stream_putw(s, api->safi);
-
- /* Put prefix information. */
- psize = PSIZE(p->prefixlen);
- stream_putc(s, p->prefixlen);
- stream_write(s, (uint8_t *)&p->prefix, psize);
-
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_SRCPFX)) {
- psize = PSIZE(src_p->prefixlen);
- stream_putc(s, src_p->prefixlen);
- stream_write(s, (uint8_t *)&src_p->prefix, psize);
- }
-
- /* Nexthop, ifindex, distance and metric information. */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
- stream_putc(s, api->nexthop_num + api->ifindex_num);
-
- for (i = 0; i < api->nexthop_num; i++) {
- stream_putc(s, NEXTHOP_TYPE_IPV6);
- stream_write(s, (uint8_t *)api->nexthop[i], 16);
- /* For labeled-unicast, each nexthop is followed by
- * label. */
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL))
- stream_putl(s, api->label[i]);
- }
- for (i = 0; i < api->ifindex_num; i++) {
- stream_putc(s, NEXTHOP_TYPE_IFINDEX);
- stream_putl(s, api->ifindex[i]);
- }
- }
-
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_DISTANCE))
- stream_putc(s, api->distance);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_METRIC))
- stream_putl(s, api->metric);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TAG))
- stream_putl(s, api->tag);
- if (CHECK_FLAG(api->message, ZAPI_MESSAGE_MTU))
- stream_putl(s, api->mtu);
-
- /* Put length at the first point of the stream. */
- stream_putw_at(s, 0, stream_get_endp(s));
-
- return zclient_send_message(zclient);
-}
-
int zclient_route_send(uint8_t cmd, struct zclient *zclient,
struct zapi_route *api)
{
}
}
-/* This function support multiple nexthop. */
-/*
- * Parse the ZEBRA_IPV4_ROUTE_ADD sent from client. Update re and
- * add kernel route.
- */
-static void zread_ipv4_add(ZAPI_HANDLER_ARGS)
-{
- int i;
- struct route_entry *re;
- struct prefix p;
- uint8_t message;
- struct in_addr nhop_addr;
- uint8_t nexthop_num;
- uint8_t nexthop_type;
- struct stream *s;
- ifindex_t ifindex;
- safi_t safi;
- int ret;
- enum lsp_types_t label_type = ZEBRA_LSP_NONE;
- mpls_label_t label;
- struct nexthop *nexthop;
- enum blackhole_type bh_type = BLACKHOLE_NULL;
-
- /* Get input stream. */
- s = msg;
-
- /* Allocate new re. */
- re = XCALLOC(MTYPE_RE, sizeof(struct route_entry));
-
- /* Type, flags, message. */
- STREAM_GETC(s, re->type);
- if (re->type > ZEBRA_ROUTE_MAX) {
- zlog_warn("%s: Specified route type %d is not a legal value\n",
- __PRETTY_FUNCTION__, re->type);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GETW(s, re->instance);
- STREAM_GETL(s, re->flags);
- STREAM_GETC(s, message);
- STREAM_GETW(s, safi);
- re->uptime = time(NULL);
-
- /* IPv4 prefix. */
- memset(&p, 0, sizeof(struct prefix_ipv4));
- p.family = AF_INET;
- STREAM_GETC(s, p.prefixlen);
- if (p.prefixlen > IPV4_MAX_BITLEN) {
- zlog_warn(
- "%s: Specified prefix length %d is greater than what v4 can be",
- __PRETTY_FUNCTION__, p.prefixlen);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GET(&p.u.prefix4, s, PSIZE(p.prefixlen));
-
- /* VRF ID */
- re->vrf_id = zvrf_id(zvrf);
-
- /* Nexthop parse. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP)) {
- STREAM_GETC(s, nexthop_num);
- zserv_nexthop_num_warn(__func__, (const struct prefix *)&p,
- nexthop_num);
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_LABEL))
- label_type = lsp_type_from_re_type(client->proto);
-
- for (i = 0; i < nexthop_num; i++) {
- STREAM_GETC(s, nexthop_type);
-
- switch (nexthop_type) {
- case NEXTHOP_TYPE_IFINDEX:
- STREAM_GETL(s, ifindex);
- route_entry_nexthop_ifindex_add(re, ifindex,
- re->vrf_id);
- break;
- case NEXTHOP_TYPE_IPV4:
- STREAM_GET(&nhop_addr.s_addr, s,
- IPV4_MAX_BYTELEN);
- nexthop = route_entry_nexthop_ipv4_add(
- re, &nhop_addr, NULL, re->vrf_id);
- /*
- * For labeled-unicast, each nexthop is followed
- * by the label.
- */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_LABEL)) {
- STREAM_GETL(s, label);
- nexthop_add_labels(nexthop, label_type,
- 1, &label);
- }
- break;
- case NEXTHOP_TYPE_IPV4_IFINDEX:
- STREAM_GET(&nhop_addr.s_addr, s,
- IPV4_MAX_BYTELEN);
- STREAM_GETL(s, ifindex);
- route_entry_nexthop_ipv4_ifindex_add(
- re, &nhop_addr, NULL, ifindex,
- re->vrf_id);
- break;
- case NEXTHOP_TYPE_IPV6:
- zlog_warn(
- "%s: Please use ZEBRA_ROUTE_ADD if you want to pass v6 nexthops",
- __PRETTY_FUNCTION__);
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
- return;
- case NEXTHOP_TYPE_BLACKHOLE:
- route_entry_nexthop_blackhole_add(re, bh_type);
- break;
- default:
- zlog_warn(
- "%s: Specified nexthop type: %d does not exist",
- __PRETTY_FUNCTION__, nexthop_type);
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
- return;
- }
- }
- }
-
- /* Distance. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_DISTANCE))
- STREAM_GETC(s, re->distance);
-
- /* Metric. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_METRIC))
- STREAM_GETL(s, re->metric);
-
- /* Tag */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_TAG))
- STREAM_GETL(s, re->tag);
- else
- re->tag = 0;
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_MTU))
- STREAM_GETL(s, re->mtu);
- else
- re->mtu = 0;
-
- /* Table */
- re->table = zvrf->table_id;
-
- ret = rib_add_multipath(AFI_IP, safi, &p, NULL, re);
-
- /* Stats */
- if (ret > 0)
- client->v4_route_add_cnt++;
- else if (ret < 0)
- client->v4_route_upd8_cnt++;
-
- return;
-
-stream_failure:
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
-}
-
-/* Zebra server IPv4 prefix delete function. */
-static void zread_ipv4_delete(ZAPI_HANDLER_ARGS)
-{
- struct stream *s;
- struct zapi_ipv4 api;
- struct prefix p;
- uint32_t table_id;
-
- s = msg;
-
- /* Type, flags, message. */
- STREAM_GETC(s, api.type);
- STREAM_GETW(s, api.instance);
- STREAM_GETL(s, api.flags);
- STREAM_GETC(s, api.message);
- STREAM_GETW(s, api.safi);
-
- /* IPv4 prefix. */
- memset(&p, 0, sizeof(struct prefix));
- p.family = AF_INET;
- STREAM_GETC(s, p.prefixlen);
- if (p.prefixlen > IPV4_MAX_BITLEN) {
- zlog_warn("%s: Passed in prefixlen %d is impossible",
- __PRETTY_FUNCTION__, p.prefixlen);
- return;
- }
- STREAM_GET(&p.u.prefix4, s, PSIZE(p.prefixlen));
-
- table_id = zvrf->table_id;
-
- rib_delete(AFI_IP, api.safi, zvrf_id(zvrf), api.type, api.instance,
- api.flags, &p, NULL, NULL, table_id, 0, 0, false);
- client->v4_route_del_cnt++;
-
-stream_failure:
- return;
-}
-
/* MRIB Nexthop lookup for IPv4. */
static void zread_ipv4_nexthop_lookup_mrib(ZAPI_HANDLER_ARGS)
{
return;
}
-/* Zebra server IPv6 prefix add function. */
-static void zread_ipv4_route_ipv6_nexthop_add(ZAPI_HANDLER_ARGS)
-{
- unsigned int i;
- struct stream *s;
- struct in6_addr nhop_addr;
- struct route_entry *re;
- uint8_t message;
- uint8_t nexthop_num;
- uint8_t nexthop_type;
- struct prefix p;
- safi_t safi;
- static struct in6_addr nexthops[MULTIPATH_NUM];
- static unsigned int ifindices[MULTIPATH_NUM];
- int ret;
- static mpls_label_t labels[MULTIPATH_NUM];
- enum lsp_types_t label_type = ZEBRA_LSP_NONE;
- mpls_label_t label;
- struct nexthop *nexthop;
- enum blackhole_type bh_type = BLACKHOLE_NULL;
-
- /* Get input stream. */
- s = msg;
-
- memset(&nhop_addr, 0, sizeof(struct in6_addr));
-
- /* Allocate new re. */
- re = XCALLOC(MTYPE_RE, sizeof(struct route_entry));
-
- /* Type, flags, message. */
- STREAM_GETC(s, re->type);
- if (re->type > ZEBRA_ROUTE_MAX) {
- zlog_warn("%s: Specified route type: %d is not a legal value\n",
- __PRETTY_FUNCTION__, re->type);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GETW(s, re->instance);
- STREAM_GETL(s, re->flags);
- STREAM_GETC(s, message);
- STREAM_GETW(s, safi);
- re->uptime = time(NULL);
-
- /* IPv4 prefix. */
- memset(&p, 0, sizeof(struct prefix_ipv4));
- p.family = AF_INET;
- STREAM_GETC(s, p.prefixlen);
- if (p.prefixlen > IPV4_MAX_BITLEN) {
- zlog_warn(
- "%s: Prefix Length %d is greater than what a v4 address can use",
- __PRETTY_FUNCTION__, p.prefixlen);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GET(&p.u.prefix4, s, PSIZE(p.prefixlen));
-
- /* VRF ID */
- re->vrf_id = zvrf_id(zvrf);
-
- /*
- * We need to give nh-addr, nh-ifindex with the same next-hop object
- * to the re to ensure that IPv6 multipathing works; need to coalesce
- * these. Clients should send the same number of paired set of
- * next-hop-addr/next-hop-ifindices.
- */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP)) {
- unsigned int nh_count = 0;
- unsigned int if_count = 0;
- unsigned int max_nh_if = 0;
-
- STREAM_GETC(s, nexthop_num);
- zserv_nexthop_num_warn(__func__, (const struct prefix *)&p,
- nexthop_num);
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_LABEL))
- label_type = lsp_type_from_re_type(client->proto);
-
- for (i = 0; i < nexthop_num; i++) {
- STREAM_GETC(s, nexthop_type);
-
- switch (nexthop_type) {
- case NEXTHOP_TYPE_IPV6:
- STREAM_GET(&nhop_addr, s, 16);
- if (nh_count < MULTIPATH_NUM) {
- /*
- * For labeled-unicast, each nexthop is
- * followed by the label.
- */
- if (CHECK_FLAG(message,
- ZAPI_MESSAGE_LABEL)) {
- STREAM_GETL(s, label);
- labels[nh_count] = label;
- }
- nexthops[nh_count] = nhop_addr;
- nh_count++;
- }
- break;
- case NEXTHOP_TYPE_IFINDEX:
- if (if_count < multipath_num)
- STREAM_GETL(s, ifindices[if_count++]);
- break;
- case NEXTHOP_TYPE_BLACKHOLE:
- route_entry_nexthop_blackhole_add(re, bh_type);
- break;
- default:
- zlog_warn(
- "%s: Please use ZEBRA_ROUTE_ADD if you want to pass non v6 nexthops",
- __PRETTY_FUNCTION__);
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
- return;
- }
- }
-
- max_nh_if = (nh_count > if_count) ? nh_count : if_count;
- for (i = 0; i < max_nh_if; i++) {
- if ((i < nh_count)
- && !IN6_IS_ADDR_UNSPECIFIED(&nexthops[i])) {
- if ((i < if_count) && ifindices[i])
- nexthop =
- route_entry_nexthop_ipv6_ifindex_add(
- re, &nexthops[i],
- ifindices[i],
- re->vrf_id);
- else
- nexthop = route_entry_nexthop_ipv6_add(
- re, &nexthops[i], re->vrf_id);
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_LABEL))
- nexthop_add_labels(nexthop, label_type,
- 1, &labels[i]);
- } else {
- if ((i < if_count) && ifindices[i])
- route_entry_nexthop_ifindex_add(
- re, ifindices[i], re->vrf_id);
- }
- }
- }
-
- /* Distance. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_DISTANCE))
- STREAM_GETC(s, re->distance);
-
- /* Metric. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_METRIC))
- STREAM_GETL(s, re->metric);
-
- /* Tag */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_TAG))
- STREAM_GETL(s, re->tag);
- else
- re->tag = 0;
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_MTU))
- STREAM_GETL(s, re->mtu);
- else
- re->mtu = 0;
-
- /* Table */
- re->table = zvrf->table_id;
-
- ret = rib_add_multipath(AFI_IP6, safi, &p, NULL, re);
- /* Stats */
- if (ret > 0)
- client->v4_route_add_cnt++;
- else if (ret < 0)
- client->v4_route_upd8_cnt++;
-
- return;
-
-stream_failure:
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
-}
-
-static void zread_ipv6_add(ZAPI_HANDLER_ARGS)
-{
- unsigned int i;
- struct stream *s;
- struct in6_addr nhop_addr;
- ifindex_t ifindex;
- struct route_entry *re;
- uint8_t message;
- uint8_t nexthop_num;
- uint8_t nexthop_type;
- struct prefix p;
- struct prefix_ipv6 src_p, *src_pp;
- safi_t safi;
- static struct in6_addr nexthops[MULTIPATH_NUM];
- static unsigned int ifindices[MULTIPATH_NUM];
- int ret;
- static mpls_label_t labels[MULTIPATH_NUM];
- enum lsp_types_t label_type = ZEBRA_LSP_NONE;
- mpls_label_t label;
- struct nexthop *nexthop;
- enum blackhole_type bh_type = BLACKHOLE_NULL;
-
- /* Get input stream. */
- s = msg;
-
- memset(&nhop_addr, 0, sizeof(struct in6_addr));
-
- /* Allocate new re. */
- re = XCALLOC(MTYPE_RE, sizeof(struct route_entry));
-
- /* Type, flags, message. */
- STREAM_GETC(s, re->type);
- if (re->type > ZEBRA_ROUTE_MAX) {
- zlog_warn("%s: Specified route type: %d is not a legal value\n",
- __PRETTY_FUNCTION__, re->type);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GETW(s, re->instance);
- STREAM_GETL(s, re->flags);
- STREAM_GETC(s, message);
- STREAM_GETW(s, safi);
- re->uptime = time(NULL);
-
- /* IPv6 prefix. */
- memset(&p, 0, sizeof(p));
- p.family = AF_INET6;
- STREAM_GETC(s, p.prefixlen);
- if (p.prefixlen > IPV6_MAX_BITLEN) {
- zlog_warn(
- "%s: Specified prefix length %d is to large for v6 prefix",
- __PRETTY_FUNCTION__, p.prefixlen);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GET(&p.u.prefix6, s, PSIZE(p.prefixlen));
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_SRCPFX)) {
- memset(&src_p, 0, sizeof(src_p));
- src_p.family = AF_INET6;
- STREAM_GETC(s, src_p.prefixlen);
- if (src_p.prefixlen > IPV6_MAX_BITLEN) {
- zlog_warn(
- "%s: Specified src prefix length %d is to large for v6 prefix",
- __PRETTY_FUNCTION__, src_p.prefixlen);
- XFREE(MTYPE_RE, re);
- return;
- }
- STREAM_GET(&src_p.prefix, s, PSIZE(src_p.prefixlen));
- src_pp = &src_p;
- } else
- src_pp = NULL;
-
- /* VRF ID */
- re->vrf_id = zvrf_id(zvrf);
-
- /*
- * We need to give nh-addr, nh-ifindex with the same next-hop object
- * to the re to ensure that IPv6 multipathing works; need to coalesce
- * these. Clients should send the same number of paired set of
- * next-hop-addr/next-hop-ifindices.
- */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP)) {
- unsigned int nh_count = 0;
- unsigned int if_count = 0;
- unsigned int max_nh_if = 0;
-
- STREAM_GETC(s, nexthop_num);
- zserv_nexthop_num_warn(__func__, (const struct prefix *)&p,
- nexthop_num);
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_LABEL))
- label_type = lsp_type_from_re_type(client->proto);
-
- for (i = 0; i < nexthop_num; i++) {
- STREAM_GETC(s, nexthop_type);
-
- switch (nexthop_type) {
- case NEXTHOP_TYPE_IPV6:
- STREAM_GET(&nhop_addr, s, 16);
- if (nh_count < MULTIPATH_NUM) {
- /*
- * For labeled-unicast, each nexthop is
- * followed by label.
- */
- if (CHECK_FLAG(message,
- ZAPI_MESSAGE_LABEL)) {
- STREAM_GETL(s, label);
- labels[nh_count] = label;
- }
- nexthops[nh_count++] = nhop_addr;
- }
- break;
- case NEXTHOP_TYPE_IPV6_IFINDEX:
- STREAM_GET(&nhop_addr, s, 16);
- STREAM_GETL(s, ifindex);
- route_entry_nexthop_ipv6_ifindex_add(
- re, &nhop_addr, ifindex, re->vrf_id);
- break;
- case NEXTHOP_TYPE_IFINDEX:
- if (if_count < multipath_num)
- STREAM_GETL(s, ifindices[if_count++]);
- break;
- case NEXTHOP_TYPE_BLACKHOLE:
- route_entry_nexthop_blackhole_add(re, bh_type);
- break;
- default:
- zlog_warn(
- "%s: Please use ZEBRA_ROUTE_ADD if you want to pass non v6 nexthops",
- __PRETTY_FUNCTION__);
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
- return;
- }
- }
-
- max_nh_if = (nh_count > if_count) ? nh_count : if_count;
- for (i = 0; i < max_nh_if; i++) {
- if ((i < nh_count)
- && !IN6_IS_ADDR_UNSPECIFIED(&nexthops[i])) {
- if ((i < if_count) && ifindices[i])
- nexthop =
- route_entry_nexthop_ipv6_ifindex_add(
- re, &nexthops[i],
- ifindices[i],
- re->vrf_id);
- else
- nexthop = route_entry_nexthop_ipv6_add(
- re, &nexthops[i], re->vrf_id);
- if (CHECK_FLAG(message, ZAPI_MESSAGE_LABEL))
- nexthop_add_labels(nexthop, label_type,
- 1, &labels[i]);
- } else {
- if ((i < if_count) && ifindices[i])
- route_entry_nexthop_ifindex_add(
- re, ifindices[i], re->vrf_id);
- }
- }
- }
-
- /* Distance. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_DISTANCE))
- STREAM_GETC(s, re->distance);
-
- /* Metric. */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_METRIC))
- STREAM_GETL(s, re->metric);
-
- /* Tag */
- if (CHECK_FLAG(message, ZAPI_MESSAGE_TAG))
- STREAM_GETL(s, re->tag);
- else
- re->tag = 0;
-
- if (CHECK_FLAG(message, ZAPI_MESSAGE_MTU))
- STREAM_GETL(s, re->mtu);
- else
- re->mtu = 0;
-
- re->table = zvrf->table_id;
-
- ret = rib_add_multipath(AFI_IP6, safi, &p, src_pp, re);
- /* Stats */
- if (ret > 0)
- client->v6_route_add_cnt++;
- else if (ret < 0)
- client->v6_route_upd8_cnt++;
-
- return;
-
-stream_failure:
- nexthops_free(re->ng.nexthop);
- XFREE(MTYPE_RE, re);
-}
-
-/* Zebra server IPv6 prefix delete function. */
-static void zread_ipv6_delete(ZAPI_HANDLER_ARGS)
-{
- struct stream *s;
- struct zapi_ipv6 api;
- struct prefix p;
- struct prefix_ipv6 src_p, *src_pp;
-
- s = msg;
-
- /* Type, flags, message. */
- STREAM_GETC(s, api.type);
- STREAM_GETW(s, api.instance);
- STREAM_GETL(s, api.flags);
- STREAM_GETC(s, api.message);
- STREAM_GETW(s, api.safi);
-
- /* IPv4 prefix. */
- memset(&p, 0, sizeof(struct prefix));
- p.family = AF_INET6;
- STREAM_GETC(s, p.prefixlen);
- STREAM_GET(&p.u.prefix6, s, PSIZE(p.prefixlen));
-
- if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) {
- memset(&src_p, 0, sizeof(struct prefix_ipv6));
- src_p.family = AF_INET6;
- STREAM_GETC(s, src_p.prefixlen);
- STREAM_GET(&src_p.prefix, s, PSIZE(src_p.prefixlen));
- src_pp = &src_p;
- } else
- src_pp = NULL;
-
- rib_delete(AFI_IP6, api.safi, zvrf_id(zvrf), api.type, api.instance,
- api.flags, &p, src_pp, NULL, client->rtm_table, 0, 0, false);
-
- client->v6_route_del_cnt++;
-
-stream_failure:
- return;
-}
-
/* Register zebra server router-id information. Send current router-id */
static void zread_router_id_add(ZAPI_HANDLER_ARGS)
{
[ZEBRA_INTERFACE_DELETE] = zread_interface_delete,
[ZEBRA_ROUTE_ADD] = zread_route_add,
[ZEBRA_ROUTE_DELETE] = zread_route_del,
- [ZEBRA_IPV4_ROUTE_ADD] = zread_ipv4_add,
- [ZEBRA_IPV4_ROUTE_DELETE] = zread_ipv4_delete,
- [ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD] = zread_ipv4_route_ipv6_nexthop_add,
- [ZEBRA_IPV6_ROUTE_ADD] = zread_ipv6_add,
- [ZEBRA_IPV6_ROUTE_DELETE] = zread_ipv6_delete,
[ZEBRA_REDISTRIBUTE_ADD] = zebra_redistribute_add,
[ZEBRA_REDISTRIBUTE_DELETE] = zebra_redistribute_delete,
[ZEBRA_REDISTRIBUTE_DEFAULT_ADD] = zebra_redistribute_default_add,