199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson #ifndef _RTE_LPM6_H_ 599a2dd95SBruce Richardson #define _RTE_LPM6_H_ 699a2dd95SBruce Richardson 799a2dd95SBruce Richardson /** 899a2dd95SBruce Richardson * @file 999a2dd95SBruce Richardson * RTE Longest Prefix Match for IPv6 (LPM6) 1099a2dd95SBruce Richardson */ 1199a2dd95SBruce Richardson 1299a2dd95SBruce Richardson #include <stdint.h> 1399a2dd95SBruce Richardson 14*e1a06e39SRobin Jarry #include <rte_common.h> 15*e1a06e39SRobin Jarry #include <rte_ip6.h> 16*e1a06e39SRobin Jarry 1799a2dd95SBruce Richardson #ifdef __cplusplus 1899a2dd95SBruce Richardson extern "C" { 1999a2dd95SBruce Richardson #endif 2099a2dd95SBruce Richardson 2199a2dd95SBruce Richardson 22*e1a06e39SRobin Jarry #define RTE_LPM6_MAX_DEPTH (RTE_DEPRECATED(RTE_LPM6_MAX_DEPTH) RTE_IPV6_MAX_DEPTH) 23*e1a06e39SRobin Jarry #define RTE_LPM6_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_LPM6_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE) 2499a2dd95SBruce Richardson /** Max number of characters in LPM name. */ 2599a2dd95SBruce Richardson #define RTE_LPM6_NAMESIZE 32 2699a2dd95SBruce Richardson 2799a2dd95SBruce Richardson /** LPM structure. */ 2899a2dd95SBruce Richardson struct rte_lpm6; 2999a2dd95SBruce Richardson 3099a2dd95SBruce Richardson /** LPM configuration structure. */ 3199a2dd95SBruce Richardson struct rte_lpm6_config { 3299a2dd95SBruce Richardson uint32_t max_rules; /**< Max number of rules. */ 3399a2dd95SBruce Richardson uint32_t number_tbl8s; /**< Number of tbl8s to allocate. */ 3499a2dd95SBruce Richardson int flags; /**< This field is currently unused. */ 3599a2dd95SBruce Richardson }; 3699a2dd95SBruce Richardson 3799a2dd95SBruce Richardson /** 3899a2dd95SBruce Richardson * Create an LPM object. 3999a2dd95SBruce Richardson * 4099a2dd95SBruce Richardson * @param name 4199a2dd95SBruce Richardson * LPM object name 4299a2dd95SBruce Richardson * @param socket_id 4399a2dd95SBruce Richardson * NUMA socket ID for LPM table memory allocation 4499a2dd95SBruce Richardson * @param config 4599a2dd95SBruce Richardson * Structure containing the configuration 4699a2dd95SBruce Richardson * @return 4799a2dd95SBruce Richardson * Handle to LPM object on success, NULL otherwise with rte_errno set 4899a2dd95SBruce Richardson * to an appropriate values. Possible rte_errno values include: 4999a2dd95SBruce Richardson * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure 5099a2dd95SBruce Richardson * - E_RTE_SECONDARY - function was called from a secondary process instance 5199a2dd95SBruce Richardson * - EINVAL - invalid parameter passed to function 5299a2dd95SBruce Richardson * - ENOSPC - the maximum number of memzones has already been allocated 5399a2dd95SBruce Richardson * - EEXIST - a memzone with the same name already exists 5499a2dd95SBruce Richardson * - ENOMEM - no appropriate memory area found in which to create memzone 5599a2dd95SBruce Richardson */ 5699a2dd95SBruce Richardson struct rte_lpm6 * 5799a2dd95SBruce Richardson rte_lpm6_create(const char *name, int socket_id, 5899a2dd95SBruce Richardson const struct rte_lpm6_config *config); 5999a2dd95SBruce Richardson 6099a2dd95SBruce Richardson /** 6199a2dd95SBruce Richardson * Find an existing LPM object and return a pointer to it. 6299a2dd95SBruce Richardson * 6399a2dd95SBruce Richardson * @param name 6499a2dd95SBruce Richardson * Name of the lpm object as passed to rte_lpm6_create() 6599a2dd95SBruce Richardson * @return 6699a2dd95SBruce Richardson * Pointer to lpm object or NULL if object not found with rte_errno 6799a2dd95SBruce Richardson * set appropriately. Possible rte_errno values include: 6899a2dd95SBruce Richardson * - ENOENT - required entry not available to return. 6999a2dd95SBruce Richardson */ 7099a2dd95SBruce Richardson struct rte_lpm6 * 7199a2dd95SBruce Richardson rte_lpm6_find_existing(const char *name); 7299a2dd95SBruce Richardson 7399a2dd95SBruce Richardson /** 7499a2dd95SBruce Richardson * Free an LPM object. 7599a2dd95SBruce Richardson * 7699a2dd95SBruce Richardson * @param lpm 7799a2dd95SBruce Richardson * LPM object handle 78448e01f1SStephen Hemminger * If lpm is NULL, no operation is performed. 7999a2dd95SBruce Richardson */ 8099a2dd95SBruce Richardson void 8199a2dd95SBruce Richardson rte_lpm6_free(struct rte_lpm6 *lpm); 8299a2dd95SBruce Richardson 8399a2dd95SBruce Richardson /** 8499a2dd95SBruce Richardson * Add a rule to the LPM table. 8599a2dd95SBruce Richardson * 8699a2dd95SBruce Richardson * @param lpm 8799a2dd95SBruce Richardson * LPM object handle 8899a2dd95SBruce Richardson * @param ip 8999a2dd95SBruce Richardson * IP of the rule to be added to the LPM table 9099a2dd95SBruce Richardson * @param depth 9199a2dd95SBruce Richardson * Depth of the rule to be added to the LPM table 9299a2dd95SBruce Richardson * @param next_hop 9399a2dd95SBruce Richardson * Next hop of the rule to be added to the LPM table 9499a2dd95SBruce Richardson * @return 9599a2dd95SBruce Richardson * 0 on success, negative value otherwise 9699a2dd95SBruce Richardson */ 9799a2dd95SBruce Richardson int 98*e1a06e39SRobin Jarry rte_lpm6_add(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth, 9999a2dd95SBruce Richardson uint32_t next_hop); 10099a2dd95SBruce Richardson 10199a2dd95SBruce Richardson /** 10299a2dd95SBruce Richardson * Check if a rule is present in the LPM table, 10399a2dd95SBruce Richardson * and provide its next hop if it is. 10499a2dd95SBruce Richardson * 10599a2dd95SBruce Richardson * @param lpm 10699a2dd95SBruce Richardson * LPM object handle 10799a2dd95SBruce Richardson * @param ip 10899a2dd95SBruce Richardson * IP of the rule to be searched 10999a2dd95SBruce Richardson * @param depth 11099a2dd95SBruce Richardson * Depth of the rule to searched 11199a2dd95SBruce Richardson * @param next_hop 11299a2dd95SBruce Richardson * Next hop of the rule (valid only if it is found) 11399a2dd95SBruce Richardson * @return 11499a2dd95SBruce Richardson * 1 if the rule exists, 0 if it does not, a negative value on failure 11599a2dd95SBruce Richardson */ 11699a2dd95SBruce Richardson int 117*e1a06e39SRobin Jarry rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth, 11899a2dd95SBruce Richardson uint32_t *next_hop); 11999a2dd95SBruce Richardson 12099a2dd95SBruce Richardson /** 12199a2dd95SBruce Richardson * Delete a rule from the LPM table. 12299a2dd95SBruce Richardson * 12399a2dd95SBruce Richardson * @param lpm 12499a2dd95SBruce Richardson * LPM object handle 12599a2dd95SBruce Richardson * @param ip 12699a2dd95SBruce Richardson * IP of the rule to be deleted from the LPM table 12799a2dd95SBruce Richardson * @param depth 12899a2dd95SBruce Richardson * Depth of the rule to be deleted from the LPM table 12999a2dd95SBruce Richardson * @return 13099a2dd95SBruce Richardson * 0 on success, negative value otherwise 13199a2dd95SBruce Richardson */ 13299a2dd95SBruce Richardson int 133*e1a06e39SRobin Jarry rte_lpm6_delete(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth); 13499a2dd95SBruce Richardson 13599a2dd95SBruce Richardson /** 13699a2dd95SBruce Richardson * Delete a rule from the LPM table. 13799a2dd95SBruce Richardson * 13899a2dd95SBruce Richardson * @param lpm 13999a2dd95SBruce Richardson * LPM object handle 14099a2dd95SBruce Richardson * @param ips 14199a2dd95SBruce Richardson * Array of IPs to be deleted from the LPM table 14299a2dd95SBruce Richardson * @param depths 14399a2dd95SBruce Richardson * Array of depths of the rules to be deleted from the LPM table 14499a2dd95SBruce Richardson * @param n 14599a2dd95SBruce Richardson * Number of rules to be deleted from the LPM table 14699a2dd95SBruce Richardson * @return 14799a2dd95SBruce Richardson * 0 on success, negative value otherwise. 14899a2dd95SBruce Richardson */ 14999a2dd95SBruce Richardson int 15099a2dd95SBruce Richardson rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm, 151*e1a06e39SRobin Jarry struct rte_ipv6_addr *ips, uint8_t *depths, unsigned int n); 15299a2dd95SBruce Richardson 15399a2dd95SBruce Richardson /** 15499a2dd95SBruce Richardson * Delete all rules from the LPM table. 15599a2dd95SBruce Richardson * 15699a2dd95SBruce Richardson * @param lpm 15799a2dd95SBruce Richardson * LPM object handle 15899a2dd95SBruce Richardson */ 15999a2dd95SBruce Richardson void 16099a2dd95SBruce Richardson rte_lpm6_delete_all(struct rte_lpm6 *lpm); 16199a2dd95SBruce Richardson 16299a2dd95SBruce Richardson /** 16399a2dd95SBruce Richardson * Lookup an IP into the LPM table. 16499a2dd95SBruce Richardson * 16599a2dd95SBruce Richardson * @param lpm 16699a2dd95SBruce Richardson * LPM object handle 16799a2dd95SBruce Richardson * @param ip 16899a2dd95SBruce Richardson * IP to be looked up in the LPM table 16999a2dd95SBruce Richardson * @param next_hop 17099a2dd95SBruce Richardson * Next hop of the most specific rule found for IP (valid on lookup hit only) 17199a2dd95SBruce Richardson * @return 17299a2dd95SBruce Richardson * -EINVAL for incorrect arguments, -ENOENT on lookup miss, 0 on lookup hit 17399a2dd95SBruce Richardson */ 17499a2dd95SBruce Richardson int 175*e1a06e39SRobin Jarry rte_lpm6_lookup(const struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint32_t *next_hop); 17699a2dd95SBruce Richardson 17799a2dd95SBruce Richardson /** 17899a2dd95SBruce Richardson * Lookup multiple IP addresses in an LPM table. 17999a2dd95SBruce Richardson * 18099a2dd95SBruce Richardson * @param lpm 18199a2dd95SBruce Richardson * LPM object handle 18299a2dd95SBruce Richardson * @param ips 18399a2dd95SBruce Richardson * Array of IPs to be looked up in the LPM table 18499a2dd95SBruce Richardson * @param next_hops 18599a2dd95SBruce Richardson * Next hop of the most specific rule found for IP (valid on lookup hit only). 18699a2dd95SBruce Richardson * This is an array of two byte values. The next hop will be stored on 18799a2dd95SBruce Richardson * each position on success; otherwise the position will be set to -1. 18899a2dd95SBruce Richardson * @param n 18999a2dd95SBruce Richardson * Number of elements in ips (and next_hops) array to lookup. 19099a2dd95SBruce Richardson * @return 19199a2dd95SBruce Richardson * -EINVAL for incorrect arguments, otherwise 0 19299a2dd95SBruce Richardson */ 19399a2dd95SBruce Richardson int 19499a2dd95SBruce Richardson rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm, 195*e1a06e39SRobin Jarry struct rte_ipv6_addr *ips, 19699a2dd95SBruce Richardson int32_t *next_hops, unsigned int n); 19799a2dd95SBruce Richardson 19899a2dd95SBruce Richardson #ifdef __cplusplus 19999a2dd95SBruce Richardson } 20099a2dd95SBruce Richardson #endif 20199a2dd95SBruce Richardson 20299a2dd95SBruce Richardson #endif 203