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 | |
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')
-rw-r--r-- | sys/net/route.c | 11 | ||||
-rw-r--r-- | sys/net/route.h | 23 | ||||
-rw-r--r-- | sys/net/route_var.h | 2 |
3 files changed, 35 insertions, 1 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index 45f479c..77c775d 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -201,6 +201,16 @@ rt_tables_get_rnh(int table, int fam) return (*rt_tables_get_rnh_ptr(table, fam)); } +rt_gen_t +rt_tables_get_gen(int table, int fam) +{ + struct rib_head *rnh; + + rnh = *rt_tables_get_rnh_ptr(table, fam); + return (rnh->rnh_gen); +} + + /* * route initialization must occur before ip6_init2(), which happenas at * SI_ORDER_MIDDLE. @@ -1754,6 +1764,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt, *ret_nrt = rt; RT_ADDREF(rt); } + rnh->rnh_gen++; /* Routing table updated */ RT_UNLOCK(rt); break; case RTM_CHANGE: 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); diff --git a/sys/net/route_var.h b/sys/net/route_var.h index 86fc8a9..a8ef56a 100644 --- a/sys/net/route_var.h +++ b/sys/net/route_var.h @@ -41,7 +41,7 @@ struct rib_head { rn_walktree_t *rnh_walktree; /* traverse tree */ rn_walktree_from_t *rnh_walktree_from; /* traverse tree below a */ rn_close_t *rnh_close; /*do something when the last ref drops*/ - u_int rnh_gen; /* generation counter */ + rt_gen_t rnh_gen; /* generation counter */ int rnh_multipath; /* multipath capable ? */ struct radix_node rnh_nodes[3]; /* empty tree for common case */ struct rwlock rib_lock; /* config/data path lock */ |