]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #8180 from kuldeepkash/topojson_framework
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Mon, 8 Mar 2021 07:32:09 +0000 (09:32 +0200)
committerGitHub <noreply@github.com>
Mon, 8 Mar 2021 07:32:09 +0000 (09:32 +0200)
tests: Improve error/assert message logging

15 files changed:
bgpd/bgp_io.c
bgpd/bgp_route.c
bgpd/bgp_rpki.c
bgpd/bgpd.h
isisd/isis_redist.c
isisd/isis_redist.h
isisd/isis_routemap.c
isisd/isis_zebra.c
lib/ringbuf.c
lib/ringbuf.h
ospf6d/ospf6_area.c
ospf6d/ospf6_asbr.c
ospf6d/ospf6_asbr.h
ospf6d/ospf6_message.c
tests/topotests/lib/common_config.py

index 644f9633f336ba880488bce11ee2deaabe8b2145..9a178395b83832da8beca3a8961ea5315fa255e9 100644 (file)
@@ -451,13 +451,10 @@ done : {
  */
 static uint16_t bgp_read(struct peer *peer)
 {
-       size_t readsize; // how many bytes we want to read
        ssize_t nbytes;  // how many bytes we actually read
        uint16_t status = 0;
-       uint8_t ibw[peer->max_packet_size * BGP_READ_PACKET_MAX];
 
-       readsize = MIN(ringbuf_space(peer->ibuf_work), sizeof(ibw));
-       nbytes = read(peer->fd, ibw, readsize);
+       nbytes = ringbuf_read(peer->ibuf_work, peer->fd);
 
        /* EAGAIN or EWOULDBLOCK; come back later */
        if (nbytes < 0 && ERRNO_IO_RETRY(errno)) {
@@ -500,9 +497,6 @@ static uint16_t bgp_read(struct peer *peer)
 
                BGP_EVENT_ADD(peer, TCP_connection_closed);
                SET_FLAG(status, BGP_IO_FATAL_ERR);
-       } else {
-               assert(ringbuf_put(peer->ibuf_work, ibw, nbytes)
-                      == (size_t)nbytes);
        }
 
        return status;
index ea6bf95d1413af45eb81ff0cea4af502ce141fc7..a753b7ef60b473c74edc0637bc57a9dfec5aaf82 100644 (file)
@@ -97,6 +97,11 @@ DEFINE_HOOK(bgp_snmp_update_stats,
            (struct bgp_node *rn, struct bgp_path_info *pi, bool added),
            (rn, pi, added))
 
+DEFINE_HOOK(bgp_rpki_prefix_status,
+           (struct peer *peer, struct attr *attr,
+            const struct prefix *prefix),
+           (peer, attr, prefix))
+
 /* Extern from bgp_dump.c */
 extern const char *bgp_origin_str[];
 extern const char *bgp_origin_long_str[];
@@ -7554,6 +7559,21 @@ static const char *bgp_origin2str(uint8_t origin)
        return "n/a";
 }
 
+static const char *bgp_rpki_validation2str(int v_state)
+{
+       switch (v_state) {
+       case 1:
+               return "valid";
+       case 2:
+               return "not found";
+       case 3:
+               return "invalid";
+       default:
+               break;
+       }
+       return "ERROR";
+}
+
 int bgp_aggregate_unset(struct bgp *bgp, struct prefix *prefix, afi_t afi,
                        safi_t safi, char *errmsg, size_t errmsg_len)
 {
@@ -9568,6 +9588,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
        int i;
        char *nexthop_hostname =
                bgp_nexthop_hostname(path->peer, path->nexthop);
+       int rpki_validation_state = 0;
 
        if (json_paths) {
                json_path = json_object_new_object();
@@ -10166,6 +10187,20 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
                }
        }
 
+       const struct prefix *p = bgp_dest_get_prefix(bn);
+       if (p->family == AF_INET || p->family == AF_INET6)
+               rpki_validation_state = hook_call(bgp_rpki_prefix_status,
+                                                 path->peer, path->attr, p);
+       if (rpki_validation_state) {
+               if (json_paths)
+                       json_object_string_add(
+                               json_path, "rpkiValidationState",
+                               bgp_rpki_validation2str(rpki_validation_state));
+               else
+                       vty_out(vty, ", validation-state: %s",
+                               bgp_rpki_validation2str(rpki_validation_state));
+       }
+
        if (json_bestpath)
                json_object_object_add(json_path, "bestpath", json_bestpath);
 
index 6bb33ff859d777bc1b76744bf7dfb30dac4248ac..42951efb0164e23464d428c16c3395d4e08821bc 100644 (file)
@@ -562,6 +562,7 @@ static int bgp_rpki_module_init(void)
 {
        lrtr_set_alloc_functions(malloc_wrapper, realloc_wrapper, free_wrapper);
 
+       hook_register(bgp_rpki_prefix_status, rpki_validate_prefix);
        hook_register(frr_late_init, bgp_rpki_init);
        hook_register(frr_early_fini, &bgp_rpki_fini);
 
index 23d0e9dfb1ef517362925b3d98de6a41d5ad9371..3f5ec0779676f6d2c809d9f841c057ed61888d10 100644 (file)
@@ -2371,6 +2371,11 @@ DECLARE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp))
 DECLARE_HOOK(bgp_snmp_update_stats,
             (struct bgp_node *rn, struct bgp_path_info *pi, bool added),
             (rn, pi, added))
+DECLARE_HOOK(bgp_rpki_prefix_status,
+            (struct peer * peer, struct attr *attr,
+             const struct prefix *prefix),
+            (peer, attr, prefix))
+
 void peer_nsf_stop(struct peer *peer);
 
 #endif /* _QUAGGA_BGPD_H */
index 240be27cf35f34bdf936b2fd25c1817214493ef9..856c47b9b74906dbd89604fe179ec891a3be7237 100644 (file)
@@ -219,7 +219,7 @@ static void isis_redist_ensure_default(struct isis *isis, int family)
 /* Handle notification about route being added */
 void isis_redist_add(struct isis *isis, int type, struct prefix *p,
                     struct prefix_ipv6 *src_p, uint8_t distance,
-                    uint32_t metric)
+                    uint32_t metric, const route_tag_t tag)
 {
        int family = p->family;
        struct route_table *ei_table = get_ext_info(isis, family);
@@ -250,6 +250,7 @@ void isis_redist_add(struct isis *isis, int type, struct prefix *p,
        info->origin = type;
        info->distance = distance;
        info->metric = metric;
+       info->tag = tag;
 
        if (is_default_prefix(p)
            && (!src_p || !src_p->prefixlen)) {
@@ -288,7 +289,7 @@ void isis_redist_delete(struct isis *isis, int type, struct prefix *p,
                 * "always" setting will ignore routes with origin
                 * DEFAULT_ROUTE. */
                isis_redist_add(isis, DEFAULT_ROUTE, p, NULL, 254,
-                               MAX_WIDE_PATH_METRIC);
+                               MAX_WIDE_PATH_METRIC, 0);
                return;
        }
 
index afce922240e3e4cbb423c1d745b6b900acf5b1ba..fcc4ceadf49b92e170182855a5c1c44bf490617e 100644 (file)
@@ -31,6 +31,7 @@ struct isis_ext_info {
        int origin;
        uint32_t metric;
        uint8_t distance;
+       route_tag_t tag;
 };
 
 struct isis_redist {
@@ -50,7 +51,7 @@ struct route_table *get_ext_reach(struct isis_area *area, int family,
                                  int level);
 void isis_redist_add(struct isis *isis, int type, struct prefix *p,
                     struct prefix_ipv6 *src_p, uint8_t distance,
-                    uint32_t metric);
+                    uint32_t metric, route_tag_t tag);
 void isis_redist_delete(struct isis *isis, int type, struct prefix *p,
                        struct prefix_ipv6 *src_p);
 int isis_redist_config_write(struct vty *vty, struct isis_area *area,
index db0f2fd8be3fd996fb3a80fa4cf3ed266f45c7a9..626e399e1591f5d6ed931b7a24a9d06b2cb5881b 100644 (file)
@@ -112,6 +112,35 @@ static const struct route_map_rule_cmd
 
 /* ------------------------------------------------------------*/
 
+/* `match tag TAG' */
+/* Match function return 1 if match is success else return zero. */
+static enum route_map_cmd_result_t
+route_match_tag(void *rule, const struct prefix *p, void *object)
+{
+       route_tag_t *tag;
+       struct isis_ext_info *info;
+       route_tag_t info_tag;
+
+       tag = rule;
+       info = object;
+
+       info_tag = info->tag;
+       if (info_tag == *tag)
+               return RMAP_MATCH;
+       else
+               return RMAP_NOMATCH;
+}
+
+/* Route map commands for tag matching. */
+static const struct route_map_rule_cmd route_match_tag_cmd = {
+       "tag",
+       route_match_tag,
+       route_map_rule_tag_compile,
+       route_map_rule_tag_free,
+};
+
+/* ------------------------------------------------------------*/
+
 static enum route_map_cmd_result_t
 route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object)
 {
@@ -234,6 +263,9 @@ void isis_route_map_init(void)
        route_map_match_ipv6_address_prefix_list_hook(generic_match_add);
        route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete);
 
+       route_map_match_tag_hook(generic_match_add);
+       route_map_no_match_tag_hook(generic_match_delete);
+
        route_map_set_metric_hook(generic_set_add);
        route_map_no_set_metric_hook(generic_set_delete);
 
@@ -241,5 +273,6 @@ void isis_route_map_init(void)
        route_map_install_match(&route_match_ip_address_prefix_list_cmd);
        route_map_install_match(&route_match_ipv6_address_cmd);
        route_map_install_match(&route_match_ipv6_address_prefix_list_cmd);
+       route_map_install_match(&route_match_tag_cmd);
        route_map_install_set(&route_set_metric_cmd);
 }
index 703532234ab55a0ffc1a7da93347e1a484b144d9..cb4dd2569d14f869b5bbee50cde99277b856a708 100644 (file)
@@ -509,7 +509,7 @@ static int isis_zebra_read(ZAPI_CALLBACK_ARGS)
 
        if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
                isis_redist_add(isis, api.type, &api.prefix, &api.src_prefix,
-                               api.distance, api.metric);
+                               api.distance, api.metric, api.tag);
        else
                isis_redist_delete(isis, api.type, &api.prefix,
                                   &api.src_prefix);
index 1c3c3e9753653282478e7880d83c3a853b5ef5e3..26c4e744b4973c85c9aac52a1c83a0f022c5516b 100644 (file)
@@ -131,3 +131,38 @@ void ringbuf_wipe(struct ringbuf *buf)
        memset(buf->data, 0x00, buf->size);
        ringbuf_reset(buf);
 }
+
+ssize_t ringbuf_read(struct ringbuf *buf, int sock)
+{
+       size_t to_read = ringbuf_space(buf);
+       size_t bytes_to_end = buf->size - buf->end;
+       ssize_t bytes_read;
+       struct iovec iov[2] = {};
+
+       /* Calculate amount of read blocks. */
+       if (to_read > bytes_to_end) {
+               iov[0].iov_base = buf->data + buf->end;
+               iov[0].iov_len = bytes_to_end;
+               iov[1].iov_base = buf->data;
+               iov[1].iov_len = to_read - bytes_to_end;
+       } else {
+               iov[0].iov_base = buf->data + buf->end;
+               iov[0].iov_len = to_read;
+       }
+
+       /* Do the system call. */
+       bytes_read = readv(sock, iov, 2);
+       if (bytes_read <= 0)
+               return bytes_read;
+
+       /* Calculate the new end. */
+       if ((size_t)bytes_read > bytes_to_end)
+               buf->end = bytes_read - bytes_to_end;
+       else
+               buf->end += bytes_read;
+
+       /* Set emptiness state. */
+       buf->empty = (buf->start == buf->end) && (buf->empty && !bytes_read);
+
+       return bytes_read;
+}
index b8f4d9798dc97f2391c6358271111bf30758328e..209687512bed8f2bd71bb15be7d27ae30981acca 100644 (file)
@@ -126,6 +126,17 @@ void ringbuf_reset(struct ringbuf *buf);
  */
 void ringbuf_wipe(struct ringbuf *buf);
 
+/**
+ * Perform a socket/file `read()` in to the ring buffer.
+ *
+ * \param buf the ring buffer pointer.
+ * \param sock the file descriptor.
+ * \returns the number of bytes read, `0` on connection close or `-1` with
+ *          `errno` pointing the error (see `readv()` man page for more
+ *          information.)
+ */
+ssize_t ringbuf_read(struct ringbuf *buf, int sock);
+
 #ifdef __cplusplus
 }
 #endif
index 898567b4f089ccb903e13d352ed8654c27c53ea0..cf33069c9f42c28db0e3f3139ddc69bb24a801df 100644 (file)
@@ -142,11 +142,12 @@ static void ospf6_area_stub_update(struct ospf6_area *area)
 
        if (IS_AREA_STUB(area)) {
                if (IS_OSPF6_DEBUG_ORIGINATE(ROUTER))
-                       zlog_debug("Stubbing out area for if %s", area->name);
+                       zlog_debug("Stubbing out area for area %s", area->name);
                OSPF6_OPT_CLEAR(area->options, OSPF6_OPT_E);
+               ospf6_asbr_remove_externals_from_area(area);
        } else if (IS_AREA_ENABLED(area)) {
                if (IS_OSPF6_DEBUG_ORIGINATE(ROUTER))
-                       zlog_debug("Normal area for if %s", area->name);
+                       zlog_debug("Normal area for area %s", area->name);
                OSPF6_OPT_SET(area->options, OSPF6_OPT_E);
                ospf6_asbr_send_externals_to_area(area);
        }
index d0c93dd5773e94d5042b6dba612be6f988b374dc..beca6b9690838984b551a43ba10e3f2671efc6cc 100644 (file)
@@ -1099,6 +1099,27 @@ void ospf6_asbr_send_externals_to_area(struct ospf6_area *oa)
        }
 }
 
+/* When an area is stubified, remove all the external LSAs in the area */
+void ospf6_asbr_remove_externals_from_area(struct ospf6_area *oa)
+{
+       struct ospf6_lsa *lsa, *lsanext;
+       struct listnode *node, *nnode;
+       struct ospf6_area *area;
+       struct ospf6 *ospf6 = oa->ospf6;
+
+
+       /* skip if router is in other non-stub areas */
+       for (ALL_LIST_ELEMENTS(ospf6->area_list, node, nnode, area))
+               if (!IS_AREA_STUB(area))
+                       return;
+
+       /* if router is only in a stub area then purge AS-External LSAs */
+       for (ALL_LSDB(oa->ospf6->lsdb, lsa, lsanext)) {
+               if (ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL)
+                       ospf6_lsdb_remove(lsa, ospf6->lsdb);
+       }
+}
+
 void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
                                 struct prefix *prefix,
                                 unsigned int nexthop_num,
index fd14610042471991f3c38bbffdd180df62dc84a4..e4a4455a5c4ae326febb693634b0dc1bee4e0aed 100644 (file)
@@ -95,6 +95,7 @@ extern void ospf6_asbr_init(void);
 extern void ospf6_asbr_redistribute_reset(struct ospf6 *ospf6);
 extern void ospf6_asbr_terminate(void);
 extern void ospf6_asbr_send_externals_to_area(struct ospf6_area *);
+extern void ospf6_asbr_remove_externals_from_area(struct ospf6_area *oa);
 
 extern int config_write_ospf6_debug_asbr(struct vty *vty);
 extern void install_element_ospf6_debug_asbr(void);
index bd180a9f55e8e04508b301f020f503268d5d1a75..349dc50b8ce336f4e48b4495c164c9e4fd0598c4 100644 (file)
@@ -1893,6 +1893,13 @@ int ospf6_dbdesc_send_newone(struct thread *thread)
           so that ospf6_send_dbdesc () can send those LSAs */
        size = sizeof(struct ospf6_lsa_header) + sizeof(struct ospf6_dbdesc);
        for (ALL_LSDB(on->summary_list, lsa, lsanext)) {
+               /* if stub area then don't advertise AS-External LSAs */
+               if (IS_AREA_STUB(on->ospf6_if->area)
+                   && ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL) {
+                       ospf6_lsdb_remove(lsa, on->summary_list);
+                       continue;
+               }
+
                if (size + sizeof(struct ospf6_lsa_header)
                    > ospf6_packet_max(on->ospf6_if)) {
                        ospf6_lsdb_lsa_unlock(lsa);
index fd480aba731fb24258c5fb103fef4e5042c72c98..9174389bea5232ec06bc8be8514782d5ff4997d2 100644 (file)
@@ -2391,14 +2391,7 @@ def create_bgp_community_lists(tgen, input_dict, build=False):
                     logger.error(errormsg)
                     return False
 
-                try:
-                    community_type = int(community_type)
-                    cmd = "{} {} {} {}".format(cmd, community_type, action, value)
-                except ValueError:
-
-                    cmd = "{} {} {} {} {}".format(
-                        cmd, community_type, name, action, value
-                    )
+                cmd = "{} {} {} {} {}".format(cmd, community_type, name, action, value)
 
                 if del_action:
                     cmd = "no {}".format(cmd)