Simplify dom_<rtattach|rtdetach>.

Remove unused arguments from dom_rtattach/dom_rtdetach functions and make
  them return/accept 'struct rib_head' instead of 'void **'.
Declare inet/inet6 implementations in the relevant _var.h headers similar
  to domifattach / domifdetach.
Add rib_subscribe_internal() function to accept subscriptions to the rnh
  directly.

Differential Revision:	https://reviews.freebsd.org/D26053
This commit is contained in:
Alexander V. Chernikov 2020-08-14 21:29:56 +00:00
parent ea7b737a6f
commit 2f23f45b20
10 changed files with 71 additions and 55 deletions

View File

@ -227,7 +227,7 @@ vnet_route_init(const void *unused __unused)
rnh = rt_tables_get_rnh_ptr(table, fam);
if (rnh == NULL)
panic("%s: rnh NULL", __func__);
dom->dom_rtattach((void **)rnh, 0, table);
*rnh = dom->dom_rtattach(table);
}
}
}
@ -256,7 +256,7 @@ vnet_route_uninit(const void *unused __unused)
rnh = rt_tables_get_rnh_ptr(table, fam);
if (rnh == NULL)
panic("%s: rnh NULL", __func__);
dom->dom_rtdetach((void **)rnh, 0);
dom->dom_rtdetach(*rnh);
}
}

View File

@ -817,6 +817,25 @@ rib_notify(struct rib_head *rnh, enum rib_subscription_type type,
}
}
static struct rib_subscription *
allocate_subscription(rib_subscription_cb_t *f, void *arg,
enum rib_subscription_type type, bool waitok)
{
struct rib_subscription *rs;
int flags = M_ZERO | (waitok ? M_WAITOK : 0);
rs = malloc(sizeof(struct rib_subscription), M_RTABLE, flags);
if (rs == NULL)
return (NULL);
rs->func = f;
rs->arg = arg;
rs->type = type;
return (rs);
}
/*
* Subscribe for the changes in the routing table specified by @fibnum and
* @family.
@ -830,20 +849,33 @@ rib_subscribe(uint32_t fibnum, int family, rib_subscription_cb_t *f, void *arg,
struct rib_head *rnh;
struct rib_subscription *rs;
struct epoch_tracker et;
int flags = M_ZERO | (waitok ? M_WAITOK : 0);
rs = malloc(sizeof(struct rib_subscription), M_RTABLE, flags);
if (rs == NULL)
if ((rs = allocate_subscription(f, arg, type, waitok)) == NULL)
return (NULL);
NET_EPOCH_ENTER(et);
KASSERT((fibnum < rt_numfibs), ("%s: bad fibnum", __func__));
rnh = rt_tables_get_rnh(fibnum, family);
rs->func = f;
rs->arg = arg;
rs->type = type;
RIB_WLOCK(rnh);
CK_STAILQ_INSERT_TAIL(&rnh->rnh_subscribers, rs, next);
RIB_WUNLOCK(rnh);
NET_EPOCH_EXIT(et);
return (rs);
}
struct rib_subscription *
rib_subscribe_internal(struct rib_head *rnh, rib_subscription_cb_t *f, void *arg,
enum rib_subscription_type type, bool waitok)
{
struct rib_subscription *rs;
struct epoch_tracker et;
if ((rs = allocate_subscription(f, arg, type, waitok)) == NULL)
return (NULL);
NET_EPOCH_ENTER(et);
RIB_WLOCK(rnh);
CK_STAILQ_INSERT_TAIL(&rnh->rnh_subscribers, rs, next);
RIB_WUNLOCK(rnh);

View File

@ -79,6 +79,9 @@ typedef void rib_subscription_cb_t(struct rib_head *rnh, struct rib_cmd_info *rc
struct rib_subscription *rib_subscribe(uint32_t fibnum, int family,
rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type,
bool waitok);
struct rib_subscription *rib_subscribe_internal(struct rib_head *rnh,
rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type,
bool waitok);
int rib_unsibscribe(uint32_t fibnum, int family, struct rib_subscription *rs);
#endif

View File

@ -294,9 +294,6 @@ IPPROTOSPACER,
},
};
extern int in_inithead(void **, int, u_int);
extern int in_detachhead(void **, int);
struct domain inetdomain = {
.dom_family = AF_INET,
.dom_name = "internet",

View File

@ -54,10 +54,6 @@ __FBSDID("$FreeBSD$");
#include <netinet/ip_icmp.h>
#include <netinet/ip_var.h>
extern int in_inithead(void **head, int off, u_int fibnum);
#ifdef VIMAGE
extern int in_detachhead(void **head, int off);
#endif
static int
rib4_preadd(u_int fibnum, const struct sockaddr *addr, const struct sockaddr *mask,
@ -121,38 +117,32 @@ rib4_preadd(u_int fibnum, const struct sockaddr *addr, const struct sockaddr *ma
return (0);
}
static int _in_rt_was_here;
/*
* Initialize our routing tree.
*/
int
in_inithead(void **head, int off, u_int fibnum)
struct rib_head *
in_inithead(uint32_t fibnum)
{
struct rib_head *rh;
rh = rt_table_init(32, AF_INET, fibnum);
if (rh == NULL)
return (0);
return (NULL);
rh->rnh_preadd = rib4_preadd;
#ifdef RADIX_MPATH
rt_mpath_init_rnh(rh);
#endif
*head = (void *)rh;
if (_in_rt_was_here == 0 ) {
_in_rt_was_here = 1;
}
return 1;
return (rh);
}
#ifdef VIMAGE
int
in_detachhead(void **head, int off)
void
in_detachhead(struct rib_head *rh)
{
rt_table_destroy((struct rib_head *)(*head));
return (1);
rt_table_destroy(rh);
}
#endif

View File

@ -436,8 +436,7 @@ inm_rele_locked(struct in_multi_head *inmh, struct in_multi *inm)
#define MCAST_NOTSMEMBER 2 /* This host excluded source */
#define MCAST_MUTED 3 /* [deprecated] */
struct rtentry;
struct route;
struct rib_head;
struct ip_moptions;
struct in_multi *inm_lookup_locked(struct ifnet *, const struct in_addr);
@ -471,6 +470,10 @@ void in_ifadown(struct ifaddr *ifa, int);
struct mbuf *ip_tryforward(struct mbuf *);
void *in_domifattach(struct ifnet *);
void in_domifdetach(struct ifnet *, void *);
struct rib_head *in_inithead(uint32_t fibnum);
#ifdef VIMAGE
void in_detachhead(struct rib_head *rh);
#endif
#endif /* _KERNEL */

View File

@ -333,11 +333,6 @@ IP6PROTOSPACER,
},
};
extern int in6_inithead(void **, int, u_int);
#ifdef VIMAGE
extern int in6_detachhead(void **, int);
#endif
struct domain inet6domain = {
.dom_family = AF_INET6,
.dom_name = "internet6",

View File

@ -101,11 +101,6 @@ __FBSDID("$FreeBSD$");
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
extern int in6_inithead(void **head, int off, u_int fibnum);
#ifdef VIMAGE
extern int in6_detachhead(void **head, int off);
#endif
static int
rib6_preadd(u_int fibnum, const struct sockaddr *addr, const struct sockaddr *mask,
struct nhop_object *nh)
@ -147,8 +142,8 @@ rib6_preadd(u_int fibnum, const struct sockaddr *addr, const struct sockaddr *ma
* Initialize our routing tree.
*/
int
in6_inithead(void **head, int off, u_int fibnum)
struct rib_head *
in6_inithead(uint32_t fibnum)
{
struct rib_head *rh;
struct rib_subscription *rs;
@ -156,29 +151,26 @@ in6_inithead(void **head, int off, u_int fibnum)
rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3,
AF_INET6, fibnum);
if (rh == NULL)
return (0);
return (NULL);
rh->rnh_preadd = rib6_preadd;
#ifdef RADIX_MPATH
rt_mpath_init_rnh(rh);
#endif
*head = (void *)rh;
rs = rib_subscribe(fibnum, AF_INET6, nd6_subscription_cb, NULL,
rs = rib_subscribe_internal(rh, nd6_subscription_cb, NULL,
RIB_NOTIFY_IMMEDIATE, true);
KASSERT(rs != NULL, ("Unable to subscribe to fib %u\n", fibnum));
return (1);
return (rh);
}
#ifdef VIMAGE
int
in6_detachhead(void **head, int off)
void
in6_detachhead(struct rib_head *rh)
{
rt_table_destroy((struct rib_head *)(*head));
return (1);
rt_table_destroy(rh);
}
#endif

View File

@ -857,6 +857,7 @@ in6m_rele_locked(struct in6_multi_head *inmh, struct in6_multi *inm)
struct ip6_moptions;
struct sockopt;
struct inpcbinfo;
struct rib_head;
/* Multicast KPIs. */
int im6o_mc_filter(const struct ip6_moptions *, const struct ifnet *,
@ -891,6 +892,8 @@ void in6_savemkludge(struct in6_ifaddr *);
void *in6_domifattach(struct ifnet *);
void in6_domifdetach(struct ifnet *, void *);
int in6_domifmtu(struct ifnet *);
struct rib_head *in6_inithead(uint32_t fibnum);
void in6_detachhead(struct rib_head *rh);
void in6_setmaxmtu(void);
int in6_if2idlen(struct ifnet *);
struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int);

View File

@ -45,6 +45,7 @@
struct mbuf;
struct ifnet;
struct socket;
struct rib_head;
struct domain {
int dom_family; /* AF_xxx */
@ -59,10 +60,10 @@ struct domain {
(struct socket *);
struct protosw *dom_protosw, *dom_protoswNPROTOSW;
struct domain *dom_next;
int (*dom_rtattach) /* initialize routing table */
(void **, int, u_int);
int (*dom_rtdetach) /* clean up routing table */
(void **, int);
struct rib_head *(*dom_rtattach) /* initialize routing table */
(uint32_t);
void (*dom_rtdetach) /* clean up routing table */
(struct rib_head *);
void *(*dom_ifattach)(struct ifnet *);
void (*dom_ifdetach)(struct ifnet *, void *);
int (*dom_ifmtu)(struct ifnet *);