From patchwork Fri Feb 14 14:37:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andrzej Ostruszka [C]" X-Patchwork-Id: 65814 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CB659A0547; Fri, 14 Feb 2020 15:38:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DAE36F72; Fri, 14 Feb 2020 15:38:07 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 88090374 for ; Fri, 14 Feb 2020 15:38:05 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01EEPIEu004882; Fri, 14 Feb 2020 06:38:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=seWpeSu6Su/wiTPttxajwIfzhmmQ1KCVFeM0ALorunU=; b=MQPsx2RFmhmt7fpGt9bNcbqovbV30Km8IGf5q6uMYRYPBmcrnMIrS2XVs5tk0izrGqHq WQ79pvIt3d7Ata6hojVqFznAV9QYhH2ulg9eH6/ZcyAqmq2Jzj80NX/v88T0UDZTNQyj xyZxcnDTjEFTpyCLzzv1sQvUZW5U4PPcDArSF0F831hvkzukuGq9qwOs5F6qZm55PgZa +d2x5uL+hZay26Fw25pXhqO4u0tjD/RzElljlWxhhu2Iuwb/7wUBSNBS0I5BCVhPl/RU nXjsOMnpJq9GmuhZcdGgH/tbgo5KKq7CqWyxnEotbrwPzK0AYhXbohTf3hwPoJ7pJLqM +Q== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2y4j5k3dpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 14 Feb 2020 06:38:04 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 14 Feb 2020 06:38:02 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 14 Feb 2020 06:38:02 -0800 Received: from amok.marvell.com (unknown [10.95.130.22]) by maili.marvell.com (Postfix) with ESMTP id 314053F7040; Fri, 14 Feb 2020 06:38:00 -0800 (PST) From: Andrzej Ostruszka To: , Bruce Richardson , Vladimir Medvedkin Date: Fri, 14 Feb 2020 15:37:59 +0100 Message-ID: <20200214143800.27230-1-aostruszka@marvell.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-02-14_04:2020-02-12, 2020-02-14 signatures=0 Subject: [dpdk-dev] [PATCH] lpm6: add const to IPv6 addresses X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 }