The IPv4 addresses of a lookup file (-t) are parsed with inet_pton()
and kept in network byte order, while the lookup takes them in host
byte order, like the addresses generated by the tool and the routes
read from a file. On a little endian machine every address of the
file is looked up byte-swapped, and a file written with -u is not
read back as it was written.

Convert the IPv4 addresses to host byte order when they are read.

Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
Cc: [email protected]

Signed-off-by: Maxime Leroy <[email protected]>
---
 app/test-fib/main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index dd1a6d7297..05f9b9a1c7 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -525,6 +525,7 @@ parse_lookup(FILE *f, int af)
 {
        int ret, i = 0;
        uint8_t *tbl = (uint8_t *)config.lookup_tbl;
+       uint32_t *tbl4 = config.lookup_tbl;
        int step = (af == AF_INET) ? 4 : 16;
        char *s;
 
@@ -535,6 +536,8 @@ parse_lookup(FILE *f, int af)
                ret = inet_pton(af, s, &tbl[i]);
                if (ret != 1)
                        return -EINVAL;
+               if (af == AF_INET)
+                       tbl4[i / step] = rte_be_to_cpu_32(tbl4[i / step]);
                i += step;
        }
        return 0;
-- 
2.43.0

Reply via email to