Skip to contentSkip to conversation

rib: minor fixes

PATCH Applied Stephen Hemminger 3 participants 8 messages Jun 25, 2020 – Jul 7, 2020

lore
Share & tools
lore
#0 lore raw

cover rib: minor fixes

Some minor updates to the RIB library to fix issues found while reviewing and trying it out.

Stephen Hemminger (3):
rib: constify arguments
rib: check for invalid max_nodes
rib: add C++ include guard

 lib/librte_rib/rte_rib.c  | 11 +++++------
 lib/librte_rib/rte_rib.h  | 17 +++++++++++++----
 lib/librte_rib/rte_rib6.c | 13 +++++++------
 lib/librte_rib/rte_rib6.h | 23 ++++++++++++++++-------
 4 files changed, 41 insertions(+), 23 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/3 rib: constify arguments

The getter functions should take a constant pointer to make it clear that node is not modified.

The rib create functions do not modify their config structure. Mark the config as constant so that programs can pass simple constant data.

---
 lib/librte_rib/rte_rib.c  |  8 ++++----
 lib/librte_rib/rte_rib.h  |  9 +++++----
 lib/librte_rib/rte_rib6.c | 10 ++++++----
 lib/librte_rib/rte_rib6.h | 13 +++++++------
 4 files changed, 22 insertions(+), 18 deletions(-)
lib/librte_rib/rte_rib.c +4 -4
index 55d612dc2e27..e40cf715c099 100644
@@ -342,7 +342,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth)
 }
 
 int
-rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip)
+rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip)
 {
 	if ((node == NULL) || (ip == NULL)) {
 		rte_errno = EINVAL;
@@ -353,7 +353,7 @@ rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip)
 }
 
 int
-rte_rib_get_depth(struct rte_rib_node *node, uint8_t *depth)
+rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth)
 {
 	if ((node == NULL) || (depth == NULL)) {
 		rte_errno = EINVAL;
@@ -370,7 +370,7 @@ rte_rib_get_ext(struct rte_rib_node *node)
 }
 
 int
-rte_rib_get_nh(struct rte_rib_node *node, uint64_t *nh)
+rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh)
 {
 	if ((node == NULL) || (nh == NULL)) {
 		rte_errno = EINVAL;
@@ -392,7 +392,7 @@ rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh)
 }
 
 struct rte_rib *
-rte_rib_create(const char *name, int socket_id, struct rte_rib_conf *conf)
+rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
 {
 	char mem_name[RTE_RIB_NAMESIZE];
 	struct rte_rib *rib = NULL;
lib/librte_rib/rte_rib.h +5 -4
index 6b70de980a2c..a7daa9d8a76e 100644
@@ -171,7 +171,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
  */
 __rte_experimental
 int
-rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip);
+rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip);
 
 /**
  * Get a depth from rte_rib_node
@@ -186,7 +186,7 @@ rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip);
  */
 __rte_experimental
 int
-rte_rib_get_depth(struct rte_rib_node *node, uint8_t *depth);
+rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth);
 
 /**
  * Get ext field from the rib node
@@ -215,7 +215,7 @@ rte_rib_get_ext(struct rte_rib_node *node);
  */
 __rte_experimental
 int
-rte_rib_get_nh(struct rte_rib_node *node, uint64_t *nh);
+rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
 
 /**
  * Set nexthop into the rib node
@@ -247,7 +247,8 @@ rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
  */
 __rte_experimental
 struct rte_rib *
-rte_rib_create(const char *name, int socket_id, struct rte_rib_conf *conf);
+rte_rib_create(const char *name, int socket_id,
+	       const struct rte_rib_conf *conf);
 
 /**
  * Find an existing RIB object and return a pointer to it.
lib/librte_rib/rte_rib6.c +6 -4
index 78b8dcfd94a9..02563b951620 100644
@@ -399,7 +399,8 @@ rte_rib6_insert(struct rte_rib6 *rib,
 }
 
 int
-rte_rib6_get_ip(struct rte_rib6_node *node, uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
+rte_rib6_get_ip(const struct rte_rib6_node *node,
+		uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
 {
 	if ((node == NULL) || (ip == NULL)) {
 		rte_errno = EINVAL;
@@ -410,7 +411,7 @@ rte_rib6_get_ip(struct rte_rib6_node *node, uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
 }
 
 int
-rte_rib6_get_depth(struct rte_rib6_node *node, uint8_t *depth)
+rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth)
 {
 	if ((node == NULL) || (depth == NULL)) {
 		rte_errno = EINVAL;
@@ -427,7 +428,7 @@ rte_rib6_get_ext(struct rte_rib6_node *node)
 }
 
 int
-rte_rib6_get_nh(struct rte_rib6_node *node, uint64_t *nh)
+rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
 {
 	if ((node == NULL) || (nh == NULL)) {
 		rte_errno = EINVAL;
@@ -449,7 +450,8 @@ rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh)
 }
 
 struct rte_rib6 *
-rte_rib6_create(const char *name, int socket_id, struct rte_rib6_conf *conf)
+rte_rib6_create(const char *name, int socket_id,
+		const struct rte_rib6_conf *conf)
 {
 	char mem_name[RTE_RIB6_NAMESIZE];
 	struct rte_rib6 *rib = NULL;
lib/librte_rib/rte_rib6.h +7 -6
index 871457138d7b..e6b4b7fff98c 100644
@@ -70,7 +70,7 @@ rte_rib6_copy_addr(uint8_t *dst, const uint8_t *src)
  *  0 otherwise
  */
 static inline int
-rte_rib6_is_equal(uint8_t *ip1, uint8_t *ip2) {
+rte_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2) {
 	int i;
 
 	if ((ip1 == NULL) || (ip2 == NULL))
@@ -227,8 +227,8 @@ rte_rib6_insert(struct rte_rib6 *rib,
  */
 __rte_experimental
 int
-rte_rib6_get_ip(struct rte_rib6_node *node,
-	uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]);
+rte_rib6_get_ip(const struct rte_rib6_node *node,
+		uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]);
 
 /**
  * Get a depth from rte_rib6_node
@@ -243,7 +243,7 @@ rte_rib6_get_ip(struct rte_rib6_node *node,
  */
 __rte_experimental
 int
-rte_rib6_get_depth(struct rte_rib6_node *node, uint8_t *depth);
+rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth);
 
 /**
  * Get ext field from the rte_rib6_node
@@ -272,7 +272,7 @@ rte_rib6_get_ext(struct rte_rib6_node *node);
  */
 __rte_experimental
 int
-rte_rib6_get_nh(struct rte_rib6_node *node, uint64_t *nh);
+rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh);
 
 /**
  * Set nexthop into the rte_rib6_node
@@ -304,7 +304,8 @@ rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh);
  */
 __rte_experimental
 struct rte_rib6 *
-rte_rib6_create(const char *name, int socket_id, struct rte_rib6_conf *conf);
+rte_rib6_create(const char *name, int socket_id,
+		const struct rte_rib6_conf *conf);
 
 /**
  * Find an existing RIB object and return a pointer to it.
Signature · 1 line
2.26.2
Acked-by on v1 1/3
#2 lore raw

Re: [dpdk-dev] [PATCH 1/3] rib: constify arguments

Quoted 181 lines · Stephen Hemminger

The getter functions should take a constant pointer to make it clear that node is not modified.

The rib create functions do not modify their config structure. Mark the config as constant so that programs can pass simple constant data.

---
  lib/librte_rib/rte_rib.c  |  8 ++++----
  lib/librte_rib/rte_rib.h  |  9 +++++----
  lib/librte_rib/rte_rib6.c | 10 ++++++----
  lib/librte_rib/rte_rib6.h | 13 +++++++------
  4 files changed, 22 insertions(+), 18 deletions(-)
lib/librte_rib/rte_rib.c +4 -4
index 55d612dc2e27..e40cf715c099 100644
@@ -342,7 +342,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth)
  }
 
  int
-rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip)
+rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip)
  {
  	if ((node == NULL) || (ip == NULL)) {
  		rte_errno = EINVAL;
@@ -353,7 +353,7 @@ rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip)
  }
 
  int
-rte_rib_get_depth(struct rte_rib_node *node, uint8_t *depth)
+rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth)
  {
  	if ((node == NULL) || (depth == NULL)) {
  		rte_errno = EINVAL;
@@ -370,7 +370,7 @@ rte_rib_get_ext(struct rte_rib_node *node)
  }
 
  int
-rte_rib_get_nh(struct rte_rib_node *node, uint64_t *nh)
+rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh)
  {
  	if ((node == NULL) || (nh == NULL)) {
  		rte_errno = EINVAL;
@@ -392,7 +392,7 @@ rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh)
  }
 
  struct rte_rib *
-rte_rib_create(const char *name, int socket_id, struct rte_rib_conf *conf)
+rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
  {
  	char mem_name[RTE_RIB_NAMESIZE];
  	struct rte_rib *rib = NULL;
lib/librte_rib/rte_rib.h +5 -4
index 6b70de980a2c..a7daa9d8a76e 100644
@@ -171,7 +171,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth);
   */
  __rte_experimental
  int
-rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip);
+rte_rib_get_ip(const struct rte_rib_node *node, uint32_t *ip);
 
  /**
   * Get a depth from rte_rib_node
@@ -186,7 +186,7 @@ rte_rib_get_ip(struct rte_rib_node *node, uint32_t *ip);
   */
  __rte_experimental
  int
-rte_rib_get_depth(struct rte_rib_node *node, uint8_t *depth);
+rte_rib_get_depth(const struct rte_rib_node *node, uint8_t *depth);
 
  /**
   * Get ext field from the rib node
@@ -215,7 +215,7 @@ rte_rib_get_ext(struct rte_rib_node *node);
   */
  __rte_experimental
  int
-rte_rib_get_nh(struct rte_rib_node *node, uint64_t *nh);
+rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
 
  /**
   * Set nexthop into the rib node
@@ -247,7 +247,8 @@ rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
   */
  __rte_experimental
  struct rte_rib *
-rte_rib_create(const char *name, int socket_id, struct rte_rib_conf *conf);
+rte_rib_create(const char *name, int socket_id,
+	       const struct rte_rib_conf *conf);
 
  /**
   * Find an existing RIB object and return a pointer to it.
lib/librte_rib/rte_rib6.c +6 -4
index 78b8dcfd94a9..02563b951620 100644
@@ -399,7 +399,8 @@ rte_rib6_insert(struct rte_rib6 *rib,
  }
 
  int
-rte_rib6_get_ip(struct rte_rib6_node *node, uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
+rte_rib6_get_ip(const struct rte_rib6_node *node,
+		uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
  {
  	if ((node == NULL) || (ip == NULL)) {
  		rte_errno = EINVAL;
@@ -410,7 +411,7 @@ rte_rib6_get_ip(struct rte_rib6_node *node, uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE])
  }
 
  int
-rte_rib6_get_depth(struct rte_rib6_node *node, uint8_t *depth)
+rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth)
  {
  	if ((node == NULL) || (depth == NULL)) {
  		rte_errno = EINVAL;
@@ -427,7 +428,7 @@ rte_rib6_get_ext(struct rte_rib6_node *node)
  }
 
  int
-rte_rib6_get_nh(struct rte_rib6_node *node, uint64_t *nh)
+rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh)
  {
  	if ((node == NULL) || (nh == NULL)) {
  		rte_errno = EINVAL;
@@ -449,7 +450,8 @@ rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh)
  }
 
  struct rte_rib6 *
-rte_rib6_create(const char *name, int socket_id, struct rte_rib6_conf *conf)
+rte_rib6_create(const char *name, int socket_id,
+		const struct rte_rib6_conf *conf)
  {
  	char mem_name[RTE_RIB6_NAMESIZE];
  	struct rte_rib6 *rib = NULL;
lib/librte_rib/rte_rib6.h +5 -5
index 871457138d7b..e6b4b7fff98c 100644
@@ -70,7 +70,7 @@ rte_rib6_copy_addr(uint8_t *dst, const uint8_t *src)
   *  0 otherwise
   */
  static inline int
-rte_rib6_is_equal(uint8_t *ip1, uint8_t *ip2) {
+rte_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2) {
  	int i;
 
  	if ((ip1 == NULL) || (ip2 == NULL))
@@ -227,8 +227,8 @@ rte_rib6_insert(struct rte_rib6 *rib,
   */
  __rte_experimental
  int
-rte_rib6_get_ip(struct rte_rib6_node *node,
-	uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]);
+rte_rib6_get_ip(const struct rte_rib6_node *node,
+		uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]);
 
  /**
   * Get a depth from rte_rib6_node
@@ -243,7 +243,7 @@ rte_rib6_get_ip(struct rte_rib6_node *node,
   */
  __rte_experimental
  int
-rte_rib6_get_depth(struct rte_rib6_node *node, uint8_t *depth);
+rte_rib6_get_depth(const struct rte_rib6_node *node, uint8_t *depth);
 
  /**
   * Get ext field from the rte_rib6_node
@@ -272,7 +272,7 @@ rte_rib6_get_ext(struct rte_rib6_node *node);
   */
  __rte_experimental
  int
-rte_rib6_get_nh(struct rte_rib6_node *node, uint64_t *nh);
+rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh);
 
  /**
   * Set nexthop into the rte_rib6_node

lib/librte_rib/rte_rib6.h rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh); · line 311

Quoted 9 lines
lib/librte_rib/rte_rib6.h +2 -1
@@ -304,7 +304,8 @@ rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh);
   */
  __rte_experimental
  struct rte_rib6 *
-rte_rib6_create(const char *name, int socket_id, struct rte_rib6_conf *conf);
+rte_rib6_create(const char *name, int socket_id,
+		const struct rte_rib6_conf *conf);
 
  /**
   * Find an existing RIB object and return a pointer to it.
Signature · 2 lines
Regards,
Vladimir
#3 lore raw

PATCH 2/3 rib: check for invalid max_nodes

In reply to Stephen Hemminger

Max_nodes in config is signed, but a negative value makes no sense. Get rid of extra BSD style parens.

---
 lib/librte_rib/rte_rib.c  | 3 +--
 lib/librte_rib/rte_rib6.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
lib/librte_rib/rte_rib.c +1 -2
index e40cf715c099..2a370d7f8439 100644
@@ -401,8 +401,7 @@ rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
 	struct rte_mempool *node_pool;
 
 	/* Check user arguments. */
-	if ((name == NULL) || (conf == NULL) ||
-			(conf->max_nodes == 0)) {
+	if (name == NULL || conf == NULL || conf->max_nodes <= 0) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
lib/librte_rib/rte_rib6.c +1 -2
index 02563b951620..f6c55ee454be 100644
@@ -460,8 +460,7 @@ rte_rib6_create(const char *name, int socket_id,
 	struct rte_mempool *node_pool;
 
 	/* Check user arguments. */
-	if ((name == NULL) || (conf == NULL) ||
-			(conf->max_nodes == 0)) {
+	if (name == NULL || conf == NULL || conf->max_nodes <= 0) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
Signature · 1 line
2.26.2
Acked-by on v1 2/3
#4 lore raw

Re: [dpdk-dev] [PATCH 2/3] rib: check for invalid max_nodes

Quoted 28 lines · Stephen Hemminger

Max_nodes in config is signed, but a negative value makes no sense. Get rid of extra BSD style parens.

---
  lib/librte_rib/rte_rib.c  | 3 +--
  lib/librte_rib/rte_rib6.c | 3 +--
  2 files changed, 2 insertions(+), 4 deletions(-)
lib/librte_rib/rte_rib.c +1 -2
index e40cf715c099..2a370d7f8439 100644
@@ -401,8 +401,7 @@ rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
  	struct rte_mempool *node_pool;
 
  	/* Check user arguments. */
-	if ((name == NULL) || (conf == NULL) ||
-			(conf->max_nodes == 0)) {
+	if (name == NULL || conf == NULL || conf->max_nodes <= 0) {
  		rte_errno = EINVAL;
  		return NULL;
  	}
lib/librte_rib/rte_rib6.c +0 -0
index 02563b951620..f6c55ee454be 100644

lib/librte_rib/rte_rib6.c rte_rib6_create(const char *name, int socket_id, · line 466

Quoted 9 lines
lib/librte_rib/rte_rib6.c +1 -2
@@ -460,8 +460,7 @@ rte_rib6_create(const char *name, int socket_id,
  	struct rte_mempool *node_pool;
 
  	/* Check user arguments. */
-	if ((name == NULL) || (conf == NULL) ||
-			(conf->max_nodes == 0)) {
+	if (name == NULL || conf == NULL || conf->max_nodes <= 0) {
  		rte_errno = EINVAL;
  		return NULL;
  	}
Signature · 2 lines
Regards,
Vladimir
#5 lore raw

PATCH 3/3 rib: add C++ include guard

In reply to Stephen Hemminger

All include files should be safe from C++

Fixes 5a5793a5ffa2 ("rib: add RIB library")
Fixes f7e861e21c46 ("rib: support IPv6")
---
 lib/librte_rib/rte_rib.h  |  8 ++++++++
 lib/librte_rib/rte_rib6.h | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
lib/librte_rib/rte_rib.h +8 -0
index a7daa9d8a76e..e9ffefce6edd 100644
@@ -13,6 +13,10 @@
 
 #include <rte_compat.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * rte_rib_get_nxt() flags
  */
@@ -275,4 +279,8 @@ __rte_experimental
 void
 rte_rib_free(struct rte_rib *rib);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _RTE_RIB_H_ */
lib/librte_rib/rte_rib6.h +9 -1
index e6b4b7fff98c..68eaa8aa4812 100644
@@ -14,6 +14,10 @@
 #include <rte_memcpy.h>
 #include <rte_compat.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define RTE_RIB6_IPV6_ADDR_SIZE	16
 
 /**
@@ -332,4 +336,8 @@ __rte_experimental
 void
 rte_rib6_free(struct rte_rib6 *rib);
 
-#endif /* _RTE_RIB_H_ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_RIB6_H_ */
Signature · 1 line
2.26.2
Acked-by on v1 3/3
#6 lore raw

Re: [dpdk-dev] [PATCH 3/3] rib: add C++ include guard

Quoted 50 lines · Stephen Hemminger

All include files should be safe from C++

Fixes 5a5793a5ffa2 ("rib: add RIB library")
Fixes f7e861e21c46 ("rib: support IPv6")
---
  lib/librte_rib/rte_rib.h  |  8 ++++++++
  lib/librte_rib/rte_rib6.h | 10 +++++++++-
  2 files changed, 17 insertions(+), 1 deletion(-)
lib/librte_rib/rte_rib.h +8 -0
index a7daa9d8a76e..e9ffefce6edd 100644
@@ -13,6 +13,10 @@
 
  #include <rte_compat.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
  /**
   * rte_rib_get_nxt() flags
   */
@@ -275,4 +279,8 @@ __rte_experimental
  void
  rte_rib_free(struct rte_rib *rib);
 
+#ifdef __cplusplus
+}
+#endif
+
  #endif /* _RTE_RIB_H_ */
lib/librte_rib/rte_rib6.h +4 -0
index e6b4b7fff98c..68eaa8aa4812 100644
@@ -14,6 +14,10 @@
  #include <rte_memcpy.h>
  #include <rte_compat.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
  #define RTE_RIB6_IPV6_ADDR_SIZE	16
 
  /**

lib/librte_rib/rte_rib6.h __rte_experimental · line 343

Quoted 9 lines
lib/librte_rib/rte_rib6.h +5 -1
@@ -332,4 +336,8 @@ __rte_experimental
  void
  rte_rib6_free(struct rte_rib6 *rib);
 
-#endif /* _RTE_RIB_H_ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_RIB6_H_ */
Signature · 2 lines
Regards,
Vladimir
#7 lore raw
In reply to Stephen Hemminger

25/06/2020 22:32, Stephen Hemminger:

Quoted 7 lines

Some minor updates to the RIB library to fix issues found while reviewing and trying it out.

Stephen Hemminger (3):
rib: constify arguments
rib: check for invalid max_nodes
rib: add C++ include guard

Applied, thanks