CNDP  22.08.0
cne_rib6.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3  * Copyright (c) 2019-2022 Intel Corporation
4  */
5 
6 #ifndef _CNE_RIB6_H_
7 #define _CNE_RIB6_H_
8 
17 #include <cne_common.h> // for CNDP_API, CNE_MAX, CNE_MIN
18 #include <stdint.h> // for uint8_t, int16_t, uint64_t, UINT8_MAX, uint16_t
19 #include <string.h> // for NULL, memcpy, size_t
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define CNE_RIB6_IPV6_ADDR_SIZE 16
26 
30 enum {
35 };
36 
37 struct cne_rib6;
38 struct cne_rib6_node;
39 
41 struct cne_rib6_conf {
47  size_t ext_sz; /* size of cne_rib_node's pool */
48  int max_nodes;
49 };
50 
59 static inline void
60 cne_rib6_copy_addr(uint8_t *dst, const uint8_t *src)
61 {
62  if ((dst == NULL) || (src == NULL))
63  return;
64  memcpy(dst, src, CNE_RIB6_IPV6_ADDR_SIZE);
65 }
66 
79 static inline int
80 cne_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2)
81 {
82  int i;
83 
84  if ((ip1 == NULL) || (ip2 == NULL))
85  return 0;
86  for (i = 0; i < CNE_RIB6_IPV6_ADDR_SIZE; i++) {
87  if (ip1[i] != ip2[i])
88  return 0;
89  }
90  return 1;
91 }
92 
104 static inline uint8_t
105 get_msk_part(uint8_t depth, int byte)
106 {
107  uint8_t part;
108 
109  byte &= 0xf;
110  depth = CNE_MIN(depth, 128);
111  part = CNE_MAX((int16_t)depth - (byte * 8), 0);
112  part = (part > 8) ? 8 : part;
113  return (uint16_t)(~UINT8_MAX) >> part;
114 }
115 
127 CNDP_API struct cne_rib6_node *cne_rib6_lookup(struct cne_rib6 *rib,
128  const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE]);
129 
140 CNDP_API struct cne_rib6_node *cne_rib6_lookup_parent(struct cne_rib6_node *ent);
141 
155 CNDP_API struct cne_rib6_node *cne_rib6_lookup_exact(struct cne_rib6 *rib,
156  const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE],
157  uint8_t depth);
158 
182 CNDP_API struct cne_rib6_node *cne_rib6_get_nxt(struct cne_rib6 *rib,
183  const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE],
184  uint8_t depth, struct cne_rib6_node *last,
185  int flag);
186 
197 CNDP_API void cne_rib6_remove(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE],
198  uint8_t depth);
199 
213 CNDP_API struct cne_rib6_node *
214 cne_rib6_insert(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE], uint8_t depth);
215 
227 CNDP_API int cne_rib6_get_ip(const struct cne_rib6_node *node, uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE]);
228 
240 CNDP_API int cne_rib6_get_depth(const struct cne_rib6_node *node, uint8_t *depth);
241 
252 CNDP_API void *cne_rib6_get_ext(struct cne_rib6_node *node);
253 
265 CNDP_API int cne_rib6_get_nh(const struct cne_rib6_node *node, uint64_t *nh);
266 
278 CNDP_API int cne_rib6_set_nh(struct cne_rib6_node *node, uint64_t nh);
279 
291 CNDP_API struct cne_rib6 *cne_rib6_create(const char *name, const struct cne_rib6_conf *conf);
292 
301 CNDP_API void cne_rib6_free(struct cne_rib6 *rib);
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 
307 #endif /* _CNE_RIB6_H_ */
#define CNE_MAX(a, b)
Definition: cne_common.h:560
#define CNE_MIN(a, b)
Definition: cne_common.h:550
CNDP_API struct cne_rib6_node * cne_rib6_insert(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE], uint8_t depth)
static uint8_t get_msk_part(uint8_t depth, int byte)
Definition: cne_rib6.h:105
CNDP_API int cne_rib6_get_depth(const struct cne_rib6_node *node, uint8_t *depth)
static void cne_rib6_copy_addr(uint8_t *dst, const uint8_t *src)
Definition: cne_rib6.h:60
CNDP_API void cne_rib6_free(struct cne_rib6 *rib)
CNDP_API struct cne_rib6_node * cne_rib6_lookup_exact(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE], uint8_t depth)
static int cne_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2)
Definition: cne_rib6.h:80
CNDP_API struct cne_rib6_node * cne_rib6_lookup_parent(struct cne_rib6_node *ent)
CNDP_API int cne_rib6_set_nh(struct cne_rib6_node *node, uint64_t nh)
@ CNE_RIB6_GET_NXT_ALL
Definition: cne_rib6.h:32
@ CNE_RIB6_GET_NXT_COVER
Definition: cne_rib6.h:34
CNDP_API int cne_rib6_get_nh(const struct cne_rib6_node *node, uint64_t *nh)
CNDP_API void cne_rib6_remove(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE], uint8_t depth)
CNDP_API void * cne_rib6_get_ext(struct cne_rib6_node *node)
CNDP_API struct cne_rib6 * cne_rib6_create(const char *name, const struct cne_rib6_conf *conf)
CNDP_API struct cne_rib6_node * cne_rib6_get_nxt(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE], uint8_t depth, struct cne_rib6_node *last, int flag)
CNDP_API int cne_rib6_get_ip(const struct cne_rib6_node *node, uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE])
CNDP_API struct cne_rib6_node * cne_rib6_lookup(struct cne_rib6 *rib, const uint8_t ip[CNE_RIB6_IPV6_ADDR_SIZE])
size_t ext_sz
Definition: cne_rib6.h:47