diff options
author | gnn <gnn@FreeBSD.org> | 2016-03-24 07:54:56 +0000 |
---|---|---|
committer | gnn <gnn@FreeBSD.org> | 2016-03-24 07:54:56 +0000 |
commit | c3d5404bbe9b51c8373832a220b2568fc8b806fe (patch) | |
tree | e930aaa09aa8f724ba7ca61b6ec317d3c5bf9cee /sys/net/route.h | |
parent | a9f48f4d565cc70d5eb24a4b37b79b0f870226de (diff) | |
download | FreeBSD-src-c3d5404bbe9b51c8373832a220b2568fc8b806fe.zip FreeBSD-src-c3d5404bbe9b51c8373832a220b2568fc8b806fe.tar.gz |
FreeBSD previously provided route caching for TCP (and UDP). Re-add
route caching for TCP, with some improvements. In particular, invalidate
the route cache if a new route is added, which might be a better match.
The cache is automatically invalidated if the old route is deleted.
Submitted by: Mike Karels
Reviewed by: gnn
Differential Revision: https://reviews.freebsd.org/D4306
Diffstat (limited to 'sys/net/route.h')
-rw-r--r-- | sys/net/route.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sys/net/route.h b/sys/net/route.h index 6cc1e1c..596214e 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -98,6 +98,14 @@ struct rt_metrics { /* lle state is exported in rmx_state rt_metrics field */ #define rmx_state rmx_weight +/* + * Keep a generation count of routing table, incremented on route addition, + * so we can invalidate caches. This is accessed without a lock, as precision + * is not required. + */ +typedef volatile u_int rt_gen_t; /* tree generation (for adds) */ +#define RT_GEN(fibnum, af) rt_tables_get_gen(fibnum, af) + #define RT_DEFAULT_FIB 0 /* Explicitly mark fib=0 restricted cases */ #define RT_ALL_FIBS -1 /* Announce event for every fib */ #ifdef _KERNEL @@ -398,6 +406,20 @@ struct rt_addrinfo { } \ } while (0) +/* + * Validate a cached route based on a supplied cookie. If there is an + * out-of-date cache, simply free it. Update the generation number + * for the new allocation + */ +#define RT_VALIDATE(ro, cookiep, fibnum) do { \ + rt_gen_t cookie = RT_GEN(fibnum, (ro)->ro_dst.sa_family); \ + if (*(cookiep) != cookie && (ro)->ro_rt != NULL) { \ + RTFREE((ro)->ro_rt); \ + (ro)->ro_rt = NULL; \ + *(cookiep) = cookie; \ + } \ +} while (0) + struct ifmultiaddr; struct rib_head; @@ -415,6 +437,7 @@ int rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *); void rt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *); struct rib_head *rt_table_init(int); void rt_table_destroy(struct rib_head *); +rt_gen_t rt_tables_get_gen(int table, int fam); int rtsock_addrmsg(int, struct ifaddr *, int); int rtsock_routemsg(int, struct ifnet *ifp, int, struct rtentry *, int); |