|WARNING| lib: fix mempool name prefixes

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Wed Aug 12 13:30:43 CEST 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/167553

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-08-12

# DPDK Patch Review

## Summary

This patch fixes mempool naming issues in the RIB and FIB libraries and adds length validation to prevent silent failures from oversized names. The changes are correct and improve error handling. A few minor issues were found.

---

## Errors

### 1. Missing error check on snprintf return value

**File:** `lib/fib/rte_fib.c:180`

```c
snprintf(mem_name, sizeof(mem_name), FIB_MEM_PREFIX "%s", name);
```

**Issue:** The `snprintf` return value is not checked. If the composed name exceeds `RTE_RIB_NAMESIZE`, it will be silently truncated, and the subsequent `rte_rib_create()` call may fail with an unclear error or create a RIB with a truncated name.

**Fix:** Check the return value and return `ENAMETOOLONG` if truncation occurs, matching the pattern used in `rte_rib.c`:

```c
int ret;
ret = snprintf(mem_name, sizeof(mem_name), FIB_MEM_PREFIX "%s", name);
if (unlikely(ret < 0 || ret >= (int)sizeof(mem_name))) {
	FIB_LOG(ERR, "FIB name %s is too long, limit is %zu characters",
		name, sizeof(mem_name) - sizeof(FIB_MEM_PREFIX));
	rte_errno = ENAMETOOLONG;
	return NULL;
}
```

### 2. Missing error check on snprintf return value

**File:** `lib/fib/rte_fib6.c:179`

```c
snprintf(mem_name, sizeof(mem_name), FIB6_MEM_PREFIX "%s", name);
```

**Issue:** Same as above for FIB6.

**Fix:** Add the same check:

```c
int ret;
ret = snprintf(mem_name, sizeof(mem_name), FIB6_MEM_PREFIX "%s", name);
if (unlikely(ret < 0 || ret >= (int)sizeof(mem_name))) {
	FIB_LOG(ERR, "FIB6 name %s is too long, limit is %zu characters",
		name, sizeof(mem_name) - sizeof(FIB6_MEM_PREFIX));
	rte_errno = ENAMETOOLONG;
	return NULL;
}
```

---

## Warnings

### 1. Hardcoded limit calculation in error message

**Files:** `lib/rib/rte_rib.c:433`, `lib/rib/rte_rib6.c:496`

```c
RIB_LOG(ERR, "RIB name %s is too long, limit is %zu characters",
	name, RTE_MEMPOOL_NAMESIZE - sizeof(RIB_MEM_PREFIX));
```

**Issue:** `sizeof(RIB_MEM_PREFIX)` includes the null terminator (5 bytes for "RIB_\0"). The actual character limit should subtract `strlen(RIB_MEM_PREFIX)` (4 bytes) instead. This makes the error message report 27 characters when the limit is actually 28.

**Fix:**

```c
RIB_LOG(ERR, "RIB name %s is too long, limit is %zu characters",
	name, RTE_MEMPOOL_NAMESIZE - strlen(RIB_MEM_PREFIX) - 1);
```

Or define the prefix length separately to avoid repeated `strlen()` calls:

```c
#define RIB_MEM_PREFIX "RIB_"
#define RIB_MEM_PREFIX_LEN (sizeof(RIB_MEM_PREFIX) - 1)
```

Then use:

```c
RIB_LOG(ERR, "RIB name %s is too long, limit is %zu characters",
	name, RTE_MEMPOOL_NAMESIZE - RIB_MEM_PREFIX_LEN - 1);
```

Same issue in `rte_rib6.c` with `RIB6_MEM_PREFIX`.

### 2. Missing validation in FIB create functions

**Files:** `lib/fib/rte_fib.c`, `lib/fib/rte_fib6.c`

While the RIB layer now validates name length against `RTE_MEMPOOL_NAMESIZE`, the FIB layer should also validate against `RTE_RIB_NAMESIZE` or `RTE_RIB6_NAMESIZE` to provide clearer error messages. Currently, if a FIB name is too long after adding the prefix, the error comes from deep in the RIB layer.

Consider adding early validation in `rte_fib_create()` and `rte_fib6_create()` before calling `rte_rib_create()`.

---

## Info

### Documentation completeness

The release notes document the user-visible naming change but do not mention the new `ENAMETOOLONG` error return or the practical name length limits. Applications that currently use long names (e.g., the 32-character `__func__` names in tests) will start failing. Consider documenting:

- Maximum name lengths for each object type (RIB: 21, RIB6: 20, FIB: 17, FIB6: 15)
- The new error code `ENAMETOOLONG`

---

## Positive Observations

1. **Correct error handling:** The patch properly uses `rte_errno = ENAMETOOLONG` and returns `NULL`, matching DPDK error conventions.
2. **Comprehensive test updates:** All test functions and examples updated to use shorter names within the new limits.
3. **Consistent naming pattern:** The hierarchical prefixes (RIB_ / RIB6_ / FIB_ / FIB6_) make ownership clear.
4. **Atomic documentation:** Release notes updated in the same patch.

---

## Conclusion

The patch correctly addresses the double-prefixing bug and adds proper name length validation. The two missing `snprintf` checks in FIB create functions are **errors** that must be fixed. The error message calculation issue is a **warning**-level inaccuracy.


More information about the test-report mailing list