routing: add rt_tables_get_rnh_safe() that doesn't panic when af/fib is

incorrect.

MFC after:	2 weeks
This commit is contained in:
Alexander V. Chernikov 2023-04-25 10:53:51 +00:00
parent 6f96b5487f
commit fd1aa866eb
2 changed files with 13 additions and 0 deletions

View File

@ -35,6 +35,8 @@
#ifndef _NET_ROUTE_ROUTE_CTL_H_
#define _NET_ROUTE_ROUTE_CTL_H_
struct rib_head *rt_tables_get_rnh_safe(uint32_t table, sa_family_t family);
struct rib_cmd_info {
uint8_t rc_cmd; /* RTM_ADD|RTM_DEL|RTM_CHANGE */
uint8_t spare[3];

View File

@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
#include <net/vnet.h>
#include <net/route.h>
#include <net/route/route_ctl.h>
#include <net/route/route_var.h>
/* Kernel config default option. */
@ -387,6 +388,16 @@ rt_tables_get_rnh(uint32_t table, sa_family_t family)
return (rt_tables_get_rnh_ptr(table, family));
}
struct rib_head *
rt_tables_get_rnh_safe(uint32_t table, sa_family_t family)
{
if (__predict_false(table >= V_rt_numfibs))
return (NULL);
if (__predict_false(family >= (AF_MAX + 1)))
return (NULL);
return (rt_tables_get_rnh_ptr(table, family));
}
u_int
rt_tables_get_gen(uint32_t table, sa_family_t family)
{