]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Abstract distance retrieving/setting from info pointer
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 30 Jul 2018 14:29:28 +0000 (10:29 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 22 Sep 2018 18:59:23 +0000 (14:59 -0400)
The bgp_distance data is stored as a void pointer in `struct bgp_node`.
Abstract retrieval of this data and setting of this data
into functions so that in the future we can move around
what is stored in bgp_node.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_route.c
bgpd/bgp_table.h

index 29c68dc6fa2e52f3aa8a75883979645a9e368b74..42028fda483936b60986e86503dc24acf4249f5f 100644 (file)
@@ -10771,12 +10771,12 @@ static int bgp_distance_set(struct vty *vty, const char *distance_str,
 
        /* Get BGP distance node. */
        rn = bgp_node_get(bgp_distance_table[afi][safi], (struct prefix *)&p);
-       if (rn->info) {
-               bdistance = rn->info;
+       bdistance = bgp_distance_get_node(rn);
+       if (bdistance)
                bgp_unlock_node(rn);
-       else {
+       else {
                bdistance = bgp_distance_new();
-               rn->info = bdistance;
+               bgp_distance_set_node(rn, bdistance);
        }
 
        /* Set distance value. */
@@ -10821,7 +10821,7 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
-       bdistance = rn->info;
+       bdistance = bgp_distance_get_node(rn);
        distance = atoi(distance_str);
 
        if (bdistance->distance != distance) {
@@ -10860,7 +10860,7 @@ uint8_t bgp_distance_apply(struct prefix *p, struct bgp_info *rinfo, afi_t afi,
        sockunion2hostprefix(&peer->su, &q);
        rn = bgp_node_match(bgp_distance_table[afi][safi], &q);
        if (rn) {
-               bdistance = rn->info;
+               bdistance = bgp_distance_get_node(rn);
                bgp_unlock_node(rn);
 
                if (bdistance->access_list) {
@@ -11511,8 +11511,9 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi,
        }
 
        for (rn = bgp_table_top(bgp_distance_table[afi][safi]); rn;
-            rn = bgp_route_next(rn))
-               if ((bdistance = rn->info) != NULL) {
+            rn = bgp_route_next(rn)) {
+               bdistance = bgp_distance_get_node(rn);
+               if (bdistance != NULL) {
                        char buf[PREFIX_STRLEN];
 
                        vty_out(vty, "  distance %d %s %s\n",
@@ -11521,6 +11522,7 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi,
                                bdistance->access_list ? bdistance->access_list
                                                       : "");
                }
+       }
 }
 
 /* Allocate routing table structure and install commands. */
index fc1942db5a95f992189b584569f23ae09b93e5f2..6c52d27a8270f3a2222cf9c86ed5cb78ef52f78e 100644 (file)
@@ -326,4 +326,15 @@ static inline void bgp_aggregate_set_node_info(struct bgp_node *node,
        node->info = aggregate;
 }
 
+static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node)
+{
+       return node->info;
+}
+
+static inline void bgp_distance_set_node(struct bgp_node *node,
+                                        struct bgp_distance *distance)
+{
+       node->info = distance;
+}
+
 #endif /* _QUAGGA_BGP_TABLE_H */