]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_fpm_protobuf.c
isisd: implement the 'lsp-too-large' notification
[mirror_frr.git] / zebra / zebra_fpm_protobuf.c
index 1e8af19ea7f215badf95a9380c7a4403d1220f1d..be0f6a23be74224f4a83756306b5b30e784d4323 100644 (file)
 /*
  * create_delete_route_message
  */
-static Fpm__DeleteRoute *
-create_delete_route_message (qpb_allocator_t *allocator, rib_dest_t *dest,
-                            struct route_entry *re)
+static Fpm__DeleteRoute *create_delete_route_message(qpb_allocator_t *allocator,
+                                                    rib_dest_t *dest,
+                                                    struct route_entry *re)
 {
-  Fpm__DeleteRoute *msg;
-
-  msg = QPB_ALLOC(allocator, typeof(*msg));
-  if (!msg) {
-    assert(0);
-    return NULL;
-  }
-
-  fpm__delete_route__init(msg);
-  msg->vrf_id = zvrf_id(rib_dest_vrf(dest));
-
-  qpb_address_family_set(&msg->address_family, rib_dest_af(dest));
-
-  /*
-   * XXX Hardcode subaddress family for now.
-   */
-  msg->sub_address_family = QPB__SUB_ADDRESS_FAMILY__UNICAST;
-  msg->key = fpm_route_key_create (allocator, rib_dest_prefix(dest));
-  if (!msg->key) {
-    assert(0);
-    return NULL;
-  }
-
-  return msg;
+       Fpm__DeleteRoute *msg;
+
+       msg = QPB_ALLOC(allocator, typeof(*msg));
+       if (!msg) {
+               assert(0);
+               return NULL;
+       }
+
+       fpm__delete_route__init(msg);
+       msg->vrf_id = zvrf_id(rib_dest_vrf(dest));
+
+       qpb_address_family_set(&msg->address_family, rib_dest_af(dest));
+
+       /*
+        * XXX Hardcode subaddress family for now.
+        */
+       msg->sub_address_family = QPB__SUB_ADDRESS_FAMILY__UNICAST;
+       msg->key = fpm_route_key_create(allocator, rib_dest_prefix(dest));
+       if (!msg->key) {
+               assert(0);
+               return NULL;
+       }
+
+       return msg;
 }
 
 /*
  * add_nexthop
  */
-static inline int
-add_nexthop (qpb_allocator_t *allocator, Fpm__AddRoute *msg, rib_dest_t *dest,
-            struct nexthop *nexthop)
+static inline int add_nexthop(qpb_allocator_t *allocator, Fpm__AddRoute *msg,
+                             rib_dest_t *dest, struct nexthop *nexthop)
 {
-  uint32_t if_index;
-  union g_addr *gateway, *src;
-
-  gateway = src = NULL;
-
-  if_index = nexthop->ifindex;
-
-  if (nexthop->type == NEXTHOP_TYPE_IPV4
-      || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
-    {
-      gateway = &nexthop->gate;
-      if (nexthop->src.ipv4.s_addr)
-       src = &nexthop->src;
-    }
-
-  if (nexthop->type == NEXTHOP_TYPE_IPV6
-      || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
-    {
-      gateway = &nexthop->gate;
-    }
-
-  if (nexthop->type == NEXTHOP_TYPE_IFINDEX)
-    {
-      if (nexthop->src.ipv4.s_addr)
-       src = &nexthop->src;
-    }
-
-  if (!gateway && if_index == 0)
-    return 0;
-
-  /*
-   * We have a valid nexthop.
-   */
-  {
-    Fpm__Nexthop *pb_nh;
-    pb_nh = QPB_ALLOC(allocator, typeof(*pb_nh));
-    if (!pb_nh) {
-      assert(0);
-      return 0;
-    }
-
-    fpm__nexthop__init(pb_nh);
-
-    if (if_index != 0) {
-      pb_nh->if_id = qpb_if_identifier_create (allocator, if_index);
-    }
-
-    if (gateway) {
-      pb_nh->address = qpb_l3_address_create (allocator, gateway,
-                                             rib_dest_af(dest));
-    }
-
-    msg->nexthops[msg->n_nexthops++] = pb_nh;
-  }
-
-  // TODO: Use src.
-
-  return 1;
+       uint32_t if_index;
+       union g_addr *gateway, *src;
+
+       gateway = src = NULL;
+
+       if_index = nexthop->ifindex;
+
+       if (nexthop->type == NEXTHOP_TYPE_IPV4
+           || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
+               gateway = &nexthop->gate;
+               if (nexthop->src.ipv4.s_addr)
+                       src = &nexthop->src;
+       }
+
+       if (nexthop->type == NEXTHOP_TYPE_IPV6
+           || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
+               gateway = &nexthop->gate;
+       }
+
+       if (nexthop->type == NEXTHOP_TYPE_IFINDEX) {
+               if (nexthop->src.ipv4.s_addr)
+                       src = &nexthop->src;
+       }
+
+       if (!gateway && if_index == 0)
+               return 0;
+
+       /*
+        * We have a valid nexthop.
+        */
+       {
+               Fpm__Nexthop *pb_nh;
+               pb_nh = QPB_ALLOC(allocator, typeof(*pb_nh));
+               if (!pb_nh) {
+                       assert(0);
+                       return 0;
+               }
+
+               fpm__nexthop__init(pb_nh);
+
+               if (if_index != 0) {
+                       pb_nh->if_id =
+                               qpb_if_identifier_create(allocator, if_index);
+               }
+
+               if (gateway) {
+                       pb_nh->address = qpb_l3_address_create(
+                               allocator, gateway, rib_dest_af(dest));
+               }
+
+               msg->nexthops[msg->n_nexthops++] = pb_nh;
+       }
+
+       // TODO: Use src.
+       (void)src;
+
+       return 1;
 }
 
 /*
  * create_add_route_message
  */
-static Fpm__AddRoute *
-create_add_route_message (qpb_allocator_t *allocator, rib_dest_t *dest,
-                         struct route_entry *re)
+static Fpm__AddRoute *create_add_route_message(qpb_allocator_t *allocator,
+                                              rib_dest_t *dest,
+                                              struct route_entry *re)
 {
-  Fpm__AddRoute *msg;
-  int discard;
-  struct nexthop *nexthop;
-  uint num_nhs, u;
-  struct nexthop *nexthops[MULTIPATH_NUM];
-
-  msg = QPB_ALLOC(allocator, typeof(*msg));
-  if (!msg) {
-    assert(0);
-    return NULL;
-  }
-
-  fpm__add_route__init(msg);
-
-  msg->vrf_id = zvrf_id(rib_dest_vrf(dest));
-
-  qpb_address_family_set (&msg->address_family, rib_dest_af(dest));
-
-  /*
-   * XXX Hardcode subaddress family for now.
-   */
-  msg->sub_address_family = QPB__SUB_ADDRESS_FAMILY__UNICAST;
-  msg->key = fpm_route_key_create (allocator, rib_dest_prefix(dest));
-  qpb_protocol_set (&msg->protocol, re->type);
-
-  if ((re->flags & ZEBRA_FLAG_BLACKHOLE) || (re->flags & ZEBRA_FLAG_REJECT))
-    discard = 1;
-  else
-    discard = 0;
-
-  if (discard)
-    {
-      if (re->flags & ZEBRA_FLAG_BLACKHOLE) {
-       msg->route_type = FPM__ROUTE_TYPE__BLACKHOLE;
-      } else if (re->flags & ZEBRA_FLAG_REJECT) {
-       msg->route_type = FPM__ROUTE_TYPE__UNREACHABLE;
-      } else {
-       assert (0);
-      }
-      return msg;
-    }
-  else {
-    msg->route_type = FPM__ROUTE_TYPE__NORMAL;
-  }
-
-  msg->metric = re->metric;
-
-  /*
-   * Figure out the set of nexthops to be added to the message.
-   */
-  num_nhs = 0;
-  for (ALL_NEXTHOPS (re->nexthop, nexthop))
-    {
-      if (num_nhs >= multipath_num)
-        break;
-
-      if (num_nhs >= ZEBRA_NUM_OF(nexthops))
-       break;
-
-      if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
-        continue;
-
-      if (!CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
-       continue;
-
-      nexthops[num_nhs] = nexthop;
-      num_nhs++;
-    }
-
-  if (!num_nhs) {
-    zfpm_debug ("netlink_encode_route(): No useful nexthop.");
-    assert(0);
-    return NULL;
-  }
-
-  /*
-   * And add them to the message.
-   */
-  if (!(msg->nexthops = qpb_alloc_ptr_array(allocator, num_nhs))) {
-    assert(0);
-    return NULL;
-  }
-
-  msg->n_nexthops = 0;
-  for (u = 0; u < num_nhs; u++) {
-    if (!add_nexthop(allocator, msg, dest, nexthops[u])) {
-      assert(0);
-      return NULL;
-    }
-  }
-
-  assert(msg->n_nexthops == num_nhs);
-
-  return msg;
+       Fpm__AddRoute *msg;
+       struct nexthop *nexthop;
+       uint num_nhs, u;
+       struct nexthop *nexthops[MULTIPATH_NUM];
+
+       msg = QPB_ALLOC(allocator, typeof(*msg));
+       if (!msg) {
+               assert(0);
+               return NULL;
+       }
+
+       fpm__add_route__init(msg);
+
+       msg->vrf_id = zvrf_id(rib_dest_vrf(dest));
+
+       qpb_address_family_set(&msg->address_family, rib_dest_af(dest));
+
+       /*
+        * XXX Hardcode subaddress family for now.
+        */
+       msg->sub_address_family = QPB__SUB_ADDRESS_FAMILY__UNICAST;
+       msg->key = fpm_route_key_create(allocator, rib_dest_prefix(dest));
+       qpb_protocol_set(&msg->protocol, re->type);
+       msg->has_route_type = 1;
+       msg->route_type = FPM__ROUTE_TYPE__NORMAL;
+       msg->metric = re->metric;
+
+       /*
+        * Figure out the set of nexthops to be added to the message.
+        */
+       num_nhs = 0;
+       for (ALL_NEXTHOPS(re->ng, nexthop)) {
+               if (num_nhs >= multipath_num)
+                       break;
+
+               if (num_nhs >= ZEBRA_NUM_OF(nexthops))
+                       break;
+
+               if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE) {
+                       switch (nexthop->bh_type) {
+                       case BLACKHOLE_REJECT:
+                               msg->route_type = FPM__ROUTE_TYPE__UNREACHABLE;
+                               break;
+                       case BLACKHOLE_NULL:
+                       default:
+                               msg->route_type = FPM__ROUTE_TYPE__BLACKHOLE;
+                               break;
+                       }
+                       return msg;
+               }
+
+               if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
+                       continue;
+
+               if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
+                       continue;
+
+               nexthops[num_nhs] = nexthop;
+               num_nhs++;
+       }
+
+       if (!num_nhs) {
+               zfpm_debug("netlink_encode_route(): No useful nexthop.");
+               assert(0);
+               return NULL;
+       }
+
+       /*
+        * And add them to the message.
+        */
+       if (!(msg->nexthops = qpb_alloc_ptr_array(allocator, num_nhs))) {
+               assert(0);
+               return NULL;
+       }
+
+       msg->n_nexthops = 0;
+       for (u = 0; u < num_nhs; u++) {
+               if (!add_nexthop(allocator, msg, dest, nexthops[u])) {
+                       assert(0);
+                       return NULL;
+               }
+       }
+
+       assert(msg->n_nexthops == num_nhs);
+
+       return msg;
 }
 
 /*
  * create_route_message
  */
-static Fpm__Message *
-create_route_message (qpb_allocator_t *allocator, rib_dest_t *dest,
-                     struct route_entry *re)
+static Fpm__Message *create_route_message(qpb_allocator_t *allocator,
+                                         rib_dest_t *dest,
+                                         struct route_entry *re)
 {
-  Fpm__Message *msg;
-
-  msg = QPB_ALLOC(allocator, typeof(*msg));
-  if (!msg) {
-    assert(0);
-    return NULL;
-  }
-
-  fpm__message__init(msg);
-
-  if (!re) {
-    msg->type = FPM__MESSAGE__TYPE__DELETE_ROUTE;
-    msg->delete_route = create_delete_route_message(allocator, dest, re);
-    if (!msg->delete_route) {
-      assert(0);
-      return NULL;
-    }
-    return msg;
-  }
-
-  msg->type = FPM__MESSAGE__TYPE__ADD_ROUTE;
-  msg->add_route = create_add_route_message(allocator, dest, re);
-  if (!msg->add_route) {
-    assert(0);
-    return NULL;
-  }
-
-  return msg;
+       Fpm__Message *msg;
+
+       msg = QPB_ALLOC(allocator, typeof(*msg));
+       if (!msg) {
+               assert(0);
+               return NULL;
+       }
+
+       fpm__message__init(msg);
+
+       if (!re) {
+               msg->has_type = 1;
+               msg->type = FPM__MESSAGE__TYPE__DELETE_ROUTE;
+               msg->delete_route =
+                       create_delete_route_message(allocator, dest, re);
+               if (!msg->delete_route) {
+                       assert(0);
+                       return NULL;
+               }
+               return msg;
+       }
+
+       msg->has_type = 1;
+       msg->type = FPM__MESSAGE__TYPE__ADD_ROUTE;
+       msg->add_route = create_add_route_message(allocator, dest, re);
+       if (!msg->add_route) {
+               assert(0);
+               return NULL;
+       }
+
+       return msg;
 }
 
 /*
@@ -285,25 +278,24 @@ create_route_message (qpb_allocator_t *allocator, rib_dest_t *dest,
  * Returns the number of bytes written to the buffer. 0 or a negative
  * value indicates an error.
  */
-int
-zfpm_protobuf_encode_route (rib_dest_t *dest, struct route_entry *re,
-                           uint8_t *in_buf, size_t in_buf_len)
+int zfpm_protobuf_encode_route(rib_dest_t *dest, struct route_entry *re,
+                              uint8_t *in_buf, size_t in_buf_len)
 {
-  Fpm__Message *msg;
-  QPB_DECLARE_STACK_ALLOCATOR (allocator, 4096);
-  size_t len;
+       Fpm__Message *msg;
+       QPB_DECLARE_STACK_ALLOCATOR(allocator, 4096);
+       size_t len;
 
-  QPB_INIT_STACK_ALLOCATOR (allocator);
+       QPB_INIT_STACK_ALLOCATOR(allocator);
 
-  msg = create_route_message(&allocator, dest, re);
-  if (!msg) {
-    assert(0);
-    return 0;
-  }
+       msg = create_route_message(&allocator, dest, re);
+       if (!msg) {
+               assert(0);
+               return 0;
+       }
 
-  len = fpm__message__pack(msg, (uint8_t *) in_buf);
-  assert(len <= in_buf_len);
+       len = fpm__message__pack(msg, (uint8_t *)in_buf);
+       assert(len <= in_buf_len);
 
-  QPB_RESET_STACK_ALLOCATOR (allocator);
-  return len;
+       QPB_RESET_STACK_ALLOCATOR(allocator);
+       return len;
 }