src/dpdk/lib/librte_lpm/rte_lpm6.c
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)
{
	uint32_t ind;
	uint32_t first_3bytes = (uint32_t)ip[0] << 16 | ip[1] << 8 | ip[2];

	if (depth <= 24) {
		/* rule is within the top level */
		ind = first_3bytes;
		*from = &lpm->tbl24[ind];
		ind += (1 << (24 - depth)) - 1;
		*to = &lpm->tbl24[ind];
		*out_tbl_ind = TBL24_IND;
	} else {
		/* top level entry */
		struct rte_lpm6_tbl_entry *tbl = &lpm->tbl24[first_3bytes];
		assert(tbl->ext_entry == 1);
		/* first tbl8 */
		uint32_t tbl_ind = tbl->lpm6_tbl8_gindex;
		tbl = &lpm->tbl8[tbl_ind *
				RTE_LPM6_TBL8_GROUP_NUM_ENTRIES];
		/* current ip byte, the top level is already behind */
		uint8_t byte = 3;
		/* minus top level */
		depth -= 24;

		/* iterate through levels (tbl8s)
		 * until we reach the last one
		 */
		while (depth > 8) {
			tbl += ip[byte];
			assert(tbl->ext_entry == 1);
			/* go to the next level/tbl8 */
			tbl_ind = tbl->lpm6_tbl8_gindex;
			tbl = &lpm->tbl8[tbl_ind *
					RTE_LPM6_TBL8_GROUP_NUM_ENTRIES];
			byte += 1;
			depth -= 8;
		}

		/* last level/tbl8 */
		ind = ip[byte] & depth_to_mask_1b(depth);
		*from = &tbl[ind];
		ind += (1 << (8 - depth)) - 1;
		*to = &tbl[ind];
		*out_tbl_ind = tbl_ind;
	}
}
/*
 * Find range of tbl8 cells occupied by a rule
 */
Find range of tbl8 cells occupied by a rule
Find range of tbl8 cells occupied by a rule
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)
{
	uint32_t ind;
	uint32_t first_3bytes = (uint32_t)ip[0] << 16 | ip[1] << 8 | ip[2];
	if (depth <= 24) {
		ind = first_3bytes;
		*from = &lpm->tbl24[ind];
		ind += (1 << (24 - depth)) - 1;
		*to = &lpm->tbl24[ind];
		*out_tbl_ind = TBL24_IND;
	} else {
		struct rte_lpm6_tbl_entry *tbl = &lpm->tbl24[first_3bytes];
		assert(tbl->ext_entry == 1);
		uint32_t tbl_ind = tbl->lpm6_tbl8_gindex;
		tbl = &lpm->tbl8[tbl_ind *
				RTE_LPM6_TBL8_GROUP_NUM_ENTRIES];
		uint8_t byte = 3;
		depth -= 24;
		while (depth > 8) {
			tbl += ip[byte];
			assert(tbl->ext_entry == 1);
			tbl_ind = tbl->lpm6_tbl8_gindex;
			tbl = &lpm->tbl8[tbl_ind *
					RTE_LPM6_TBL8_GROUP_NUM_ENTRIES];
			byte += 1;
			depth -= 8;
		}
		ind = ip[byte] & depth_to_mask_1b(depth);
		*from = &tbl[ind];
		ind += (1 << (8 - depth)) - 1;
		*to = &tbl[ind];
		*out_tbl_ind = tbl_ind;
	}
}
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 ) { uint32_t ind ; uint32_t first_3bytes = ( uint32_t ) ip [ 0 ] << 16 | ip [ 1 ] << 8 | ip [ 2 ] ; if ( depth <= 24 ) { ind = first_3bytes ; * from = & lpm -> tbl24 [ ind ] ; ind += ( 1 << ( 24 - depth ) ) - 1 ; * to = & lpm -> tbl24 [ ind ] ; * out_tbl_ind = TBL24_IND ; } else { struct rte_lpm6_tbl_entry * tbl = & lpm -> tbl24 [ first_3bytes ] ; assert ( tbl -> ext_entry == 1 ) ; uint32_t tbl_ind = tbl -> lpm6_tbl8_gindex ; tbl = & lpm -> tbl8 [ tbl_ind * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES ] ; uint8_t byte = 3 ; depth -= 24 ; while ( depth > 8 ) { tbl += ip [ byte ] ; assert ( tbl -> ext_entry == 1 ) ; tbl_ind = tbl -> lpm6_tbl8_gindex ; tbl = & lpm -> tbl8 [ tbl_ind * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES ] ; byte += 1 ; depth -= 8 ; } ind = ip [ byte ] & depth_to_mask_1b ( depth ) ; * from = & tbl [ ind ] ; ind += ( 1 << ( 8 - depth ) ) - 1 ; * to = & tbl [ ind ] ; * out_tbl_ind = tbl_ind ; } }
Find range of tbl8 cells occupied by a rule
Find range of tbl8 cells occupied by a rule
/* rule is within the top level */ /* top level entry */ /* first tbl8 */ /* current ip byte, the top level is already behind */ /* minus top level */ /* iterate through levels (tbl8s)
		 * until we reach the last one
		 */ /* go to the next level/tbl8 */ /* last level/tbl8 */