DPDK patches and discussions
 help / color / Atom feed
* [dpdk-dev] [PATCH] lpm6: add const to IPv6 addresses
@ 2020-02-14 14:37 Andrzej Ostruszka
  2020-02-14 15:47 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Andrzej Ostruszka @ 2020-02-14 14:37 UTC (permalink / raw)
  To: dev, Bruce Richardson, Vladimir Medvedkin

LPM6 does not modify input IPv6 addresses so mark them as 'const'.

The real need is to add those annotations to the API but in addition
they were added also to internal functions and slight formatting changes
were performed (aligning of input args).

Signed-off-by: Andrzej Ostruszka <aostruszka@marvell.com>
---
 lib/librte_lpm/rte_lpm6.c | 71 ++++++++++++++++++++-------------------
 lib/librte_lpm/rte_lpm6.h | 20 ++++++-----
 2 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c
index c46e557e2..0e6b5ab19 100644
--- a/lib/librte_lpm/rte_lpm6.c
+++ b/lib/librte_lpm/rte_lpm6.c
@@ -156,7 +156,7 @@ ip6_copy_addr(uint8_t *dst, const uint8_t *src)
  */
 static inline uint32_t
 rule_hash(const void *data, __rte_unused uint32_t data_len,
-		  uint32_t init_val)
+	  uint32_t init_val)
 {
 	return rte_jhash(data, sizeof(struct rte_lpm6_rule_key), init_val);
 }
@@ -219,7 +219,7 @@ tbl8_available(struct rte_lpm6 *lpm)
  *	  note that ip must be already masked
  */
 static inline void
-rule_key_init(struct rte_lpm6_rule_key *key, uint8_t *ip, uint8_t depth)
+rule_key_init(struct rte_lpm6_rule_key *key, const uint8_t *ip, uint8_t depth)
 {
 	ip6_copy_addr(key->ip, ip);
 	key->depth = depth;
@@ -445,8 +445,8 @@ rte_lpm6_free(struct rte_lpm6 *lpm)
 /* Find a rule */
 static inline int
 rule_find_with_key(struct rte_lpm6 *lpm,
-		  const struct rte_lpm6_rule_key *rule_key,
-		  uint32_t *next_hop)
+		   const struct rte_lpm6_rule_key *rule_key,
+		   uint32_t *next_hop)
 {
 	uint64_t hash_val;
 	int ret;
@@ -464,8 +464,8 @@ rule_find_with_key(struct rte_lpm6 *lpm,
 
 /* Find a rule */
 static int
-rule_find(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
-		  uint32_t *next_hop)
+rule_find(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+	  uint32_t *next_hop)
 {
 	struct rte_lpm6_rule_key rule_key;
 
@@ -485,7 +485,8 @@ rule_find(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
  *   <0 - error
  */
 static inline int
-rule_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint32_t next_hop)
+rule_add(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+	 uint32_t next_hop)
 {
 	int ret, rule_exist;
 	struct rte_lpm6_rule_key rule_key;
@@ -526,7 +527,7 @@ rule_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint32_t next_hop)
  */
 static void
 expand_rule(struct rte_lpm6 *lpm, uint32_t tbl8_gindex, uint8_t old_depth,
-		uint8_t new_depth, uint32_t next_hop, uint8_t valid)
+	    uint8_t new_depth, uint32_t next_hop, uint8_t valid)
 {
 	uint32_t tbl8_group_end, tbl8_gindex_next, j;
 
@@ -561,7 +562,7 @@ expand_rule(struct rte_lpm6 *lpm, uint32_t tbl8_gindex, uint8_t old_depth,
  */
 static inline void
 init_tbl8_header(struct rte_lpm6 *lpm, uint32_t tbl_ind,
-		uint32_t owner_tbl_ind, uint32_t owner_entry_ind)
+		 uint32_t owner_tbl_ind, uint32_t owner_entry_ind)
 {
 	struct rte_lpm_tbl8_hdr *tbl_hdr = &lpm->tbl8_hdrs[tbl_ind];
 	tbl_hdr->owner_tbl_ind = owner_tbl_ind;
@@ -600,9 +601,9 @@ get_bitshift(const uint8_t *ip, uint8_t first_byte, uint8_t bytes)
  */
 static inline int
 simulate_add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
-		struct rte_lpm6_tbl_entry **next_tbl, const uint8_t *ip,
-		uint8_t bytes, uint8_t first_byte, uint8_t depth,
-		uint32_t *need_tbl_nb)
+		  struct rte_lpm6_tbl_entry **next_tbl, const uint8_t *ip,
+		  uint8_t bytes, uint8_t first_byte, uint8_t depth,
+		  uint32_t *need_tbl_nb)
 {
 	uint32_t entry_ind;
 	uint8_t bits_covered;
@@ -652,10 +653,10 @@ simulate_add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
  */
 static inline int
 add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl,
-		uint32_t tbl_ind, struct rte_lpm6_tbl_entry **next_tbl,
-		uint32_t *next_tbl_ind, uint8_t *ip, uint8_t bytes,
-		uint8_t first_byte, uint8_t depth, uint32_t next_hop,
-		uint8_t is_new_rule)
+	 uint32_t tbl_ind, struct rte_lpm6_tbl_entry **next_tbl,
+	 uint32_t *next_tbl_ind, const uint8_t *ip, uint8_t bytes,
+	 uint8_t first_byte, uint8_t depth, uint32_t next_hop,
+	 uint8_t is_new_rule)
 {
 	uint32_t entry_ind, tbl_range, tbl8_group_start, tbl8_group_end, i;
 	uint32_t tbl8_gindex;
@@ -854,8 +855,8 @@ simulate_add(struct rte_lpm6 *lpm, const uint8_t *masked_ip, uint8_t depth)
  * Add a route
  */
 int
-rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
-	uint32_t next_hop)
+rte_lpm6_add(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+	     uint32_t next_hop)
 {
 	struct rte_lpm6_tbl_entry *tbl;
 	struct rte_lpm6_tbl_entry *tbl_next = NULL;
@@ -913,8 +914,8 @@ rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
  */
 static inline int
 lookup_step(const struct rte_lpm6 *lpm, const struct rte_lpm6_tbl_entry *tbl,
-		const struct rte_lpm6_tbl_entry **tbl_next, uint8_t *ip,
-		uint8_t first_byte, uint32_t *next_hop)
+	    const struct rte_lpm6_tbl_entry **tbl_next, const uint8_t *ip,
+	    uint8_t first_byte, uint32_t *next_hop)
 {
 	uint32_t tbl8_index, tbl_entry;
 
@@ -943,7 +944,7 @@ lookup_step(const struct rte_lpm6 *lpm, const struct rte_lpm6_tbl_entry *tbl,
  * Looks up an IP
  */
 int
-rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip,
+rte_lpm6_lookup(const struct rte_lpm6 *lpm, const uint8_t *ip,
 		uint32_t *next_hop)
 {
 	const struct rte_lpm6_tbl_entry *tbl;
@@ -976,8 +977,8 @@ rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip,
  */
 int
 rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
-		uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
-		int32_t *next_hops, unsigned int n)
+			  const uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
+			  int32_t *next_hops, unsigned int n)
 {
 	unsigned int i;
 	const struct rte_lpm6_tbl_entry *tbl;
@@ -1020,8 +1021,8 @@ rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
  * Look for a rule in the high-level rules table
  */
 int
-rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
-		uint32_t *next_hop)
+rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+			 uint32_t *next_hop)
 {
 	uint8_t masked_ip[RTE_LPM6_IPV6_ADDR_SIZE];
 
@@ -1045,7 +1046,7 @@ rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
  *   <0 on failure
  */
 static inline int
-rule_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth)
+rule_delete(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth)
 {
 	int ret;
 	struct rte_lpm6_rule_key rule_key;
@@ -1070,8 +1071,8 @@ rule_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth)
  */
 int
 rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
-		uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths,
-		unsigned n)
+			  const uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
+			  uint8_t *depths, unsigned n)
 {
 	uint8_t masked_ip[RTE_LPM6_IPV6_ADDR_SIZE];
 	unsigned i;
@@ -1144,8 +1145,8 @@ depth_to_mask_1b(uint8_t depth)
  * Find a less specific rule
  */
 static int
-rule_find_less_specific(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
-	struct rte_lpm6_rule *rule)
+rule_find_less_specific(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+			struct rte_lpm6_rule *rule)
 {
 	int ret;
 	uint32_t next_hop;
@@ -1185,9 +1186,9 @@ rule_find_less_specific(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
  */
 static void
 rule_find_range(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
-		  struct rte_lpm6_tbl_entry **from,
-		  struct rte_lpm6_tbl_entry **to,
-		  uint32_t *out_tbl_ind)
+		struct rte_lpm6_tbl_entry **from,
+		struct rte_lpm6_tbl_entry **to,
+		uint32_t *out_tbl_ind)
 {
 	uint32_t ind;
 	uint32_t first_3bytes = (uint32_t)ip[0] << 16 | ip[1] << 8 | ip[2];
@@ -1240,7 +1241,7 @@ rule_find_range(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
  */
 static void
 remove_tbl(struct rte_lpm6 *lpm, struct rte_lpm_tbl8_hdr *tbl_hdr,
-		  uint32_t tbl_ind, struct rte_lpm6_rule *lsp_rule)
+	   uint32_t tbl_ind, struct rte_lpm6_rule *lsp_rule)
 {
 	struct rte_lpm6_tbl_entry *owner_entry;
 
@@ -1291,7 +1292,7 @@ remove_tbl(struct rte_lpm6 *lpm, struct rte_lpm_tbl8_hdr *tbl_hdr,
  * Deletes a rule
  */
 int
-rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth)
+rte_lpm6_delete(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth)
 {
 	uint8_t masked_ip[RTE_LPM6_IPV6_ADDR_SIZE];
 	struct rte_lpm6_rule lsp_rule_obj;
diff --git a/lib/librte_lpm/rte_lpm6.h b/lib/librte_lpm/rte_lpm6.h
index 37dfb2024..855324f15 100644
--- a/lib/librte_lpm/rte_lpm6.h
+++ b/lib/librte_lpm/rte_lpm6.h
@@ -94,8 +94,8 @@ rte_lpm6_free(struct rte_lpm6 *lpm);
  *   0 on success, negative value otherwise
  */
 int
-rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
-		uint32_t next_hop);
+rte_lpm6_add(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+	     uint32_t next_hop);
 
 /**
  * Check if a rule is present in the LPM table,
@@ -113,8 +113,8 @@ rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
  *   1 if the rule exists, 0 if it does not, a negative value on failure
  */
 int
-rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
-		uint32_t *next_hop);
+rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
+			 uint32_t *next_hop);
 
 /**
  * Delete a rule from the LPM table.
@@ -129,7 +129,7 @@ rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth,
  *   0 on success, negative value otherwise
  */
 int
-rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth);
+rte_lpm6_delete(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth);
 
 /**
  * Delete a rule from the LPM table.
@@ -147,7 +147,8 @@ rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth);
  */
 int
 rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
-		uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths, unsigned n);
+			  const uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
+			  uint8_t *depths, unsigned n);
 
 /**
  * Delete all rules from the LPM table.
@@ -171,7 +172,8 @@ rte_lpm6_delete_all(struct rte_lpm6 *lpm);
  *   -EINVAL for incorrect arguments, -ENOENT on lookup miss, 0 on lookup hit
  */
 int
-rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint32_t *next_hop);
+rte_lpm6_lookup(const struct rte_lpm6 *lpm, const uint8_t *ip,
+		uint32_t *next_hop);
 
 /**
  * Lookup multiple IP addresses in an LPM table.
@@ -191,8 +193,8 @@ rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint32_t *next_hop);
  */
 int
 rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
-		uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
-		int32_t *next_hops, unsigned int n);
+			  const uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE],
+			  int32_t *next_hops, unsigned int n);
 
 #ifdef __cplusplus
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] lpm6: add const to IPv6 addresses
  2020-02-14 14:37 [dpdk-dev] [PATCH] lpm6: add const to IPv6 addresses Andrzej Ostruszka
@ 2020-02-14 15:47 ` Stephen Hemminger
  2020-02-14 16:06   ` Andrzej Ostruszka
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2020-02-14 15:47 UTC (permalink / raw)
  To: Andrzej Ostruszka; +Cc: dev, Bruce Richardson, Vladimir Medvedkin

On Fri, 14 Feb 2020 15:37:59 +0100
Andrzej Ostruszka <aostruszka@marvell.com> wrote:

> LPM6 does not modify input IPv6 addresses so mark them as 'const'.
> 
> The real need is to add those annotations to the API but in addition
> they were added also to internal functions and slight formatting changes
> were performed (aligning of input args).
> 
> Signed-off-by: Andrzej Ostruszka <aostruszka@marvell.com>

This is a duplicate of: 
https://patchwork.dpdk.org/patch/65126/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] lpm6: add const to IPv6 addresses
  2020-02-14 15:47 ` Stephen Hemminger
@ 2020-02-14 16:06   ` Andrzej Ostruszka
  0 siblings, 0 replies; 3+ messages in thread
From: Andrzej Ostruszka @ 2020-02-14 16:06 UTC (permalink / raw)
  To: Stephen Hemminger, Andrzej Ostruszka
  Cc: dev, Bruce Richardson, Vladimir Medvedkin

On 2/14/20 4:47 PM, Stephen Hemminger wrote:
> On Fri, 14 Feb 2020 15:37:59 +0100
> Andrzej Ostruszka <aostruszka@marvell.com> wrote:
> 
>> LPM6 does not modify input IPv6 addresses so mark them as 'const'.
>>
>> The real need is to add those annotations to the API but in addition
>> they were added also to internal functions and slight formatting changes
>> were performed (aligning of input args).
>>
>> Signed-off-by: Andrzej Ostruszka <aostruszka@marvell.com>
> 
> This is a duplicate of: 
> https://patchwork.dpdk.org/patch/65126/

Yes indeed.  Thank you for pointing out, will drop it.

With regards
Andrzej Ostruszka

PS. Did you remember this patch, or is there some neat way to search for
relevant outstanding patches?  I'm pretty sure I've seen it but there
are so many changes being sent and at the time had no need for this
change that it escaped from my memory.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 14:37 [dpdk-dev] [PATCH] lpm6: add const to IPv6 addresses Andrzej Ostruszka
2020-02-14 15:47 ` Stephen Hemminger
2020-02-14 16:06   ` Andrzej Ostruszka

DPDK patches and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox