summaryrefslogtreecommitdiffstats
path: root/sys/net/route.h
diff options
context:
space:
mode:
authormelifaro <melifaro@FreeBSD.org>2015-12-08 10:50:03 +0000
committermelifaro <melifaro@FreeBSD.org>2015-12-08 10:50:03 +0000
commitca13483a3ceb41301eee9d9d194676056a9b304a (patch)
tree6ca921174b94c73570e52b7776a5a84068f7a02f /sys/net/route.h
parent857f62b52e4aba63ee7b8c0eeaba0da2e8ae21e5 (diff)
downloadFreeBSD-src-ca13483a3ceb41301eee9d9d194676056a9b304a.zip
FreeBSD-src-ca13483a3ceb41301eee9d9d194676056a9b304a.tar.gz
Merge helper fib* functions used for basic lookups.
Vast majority of rtalloc(9) users require only basic info from route table (e.g. "does the rtentry interface match with the interface I have?". "what is the MTU?", "Give me the IPv4 source address to use", etc..). Instead of hand-rolling lookups, checking if rtentry is up, valid, dealing with IPv6 mtu, finding "address" ifp (almost never done right), provide easy-to-use API hiding all the complexity and returning the needed info into small on-stack structure. This change also helps hiding route subsystem internals (locking, direct rtentry accesses). Additionaly, using this API improves lookup performance since rtentry is not locked. (This is safe, since all the rtentry changes happens under both radix WLOCK and rtentry WLOCK). Sponsored by: Yandex LLC
Diffstat (limited to 'sys/net/route.h')
-rw-r--r--sys/net/route.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/sys/net/route.h b/sys/net/route.h
index ffbcb3c..c1d0997 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -171,6 +171,37 @@ struct rtentry {
RTF_REJECT | RTF_STATIC | RTF_STICKY)
/*
+ * fib_ nexthop API flags.
+ */
+
+/* Consumer-visible nexthop info flags */
+#define NHF_REJECT 0x0010 /* RTF_REJECT */
+#define NHF_BLACKHOLE 0x0020 /* RTF_BLACKHOLE */
+#define NHF_REDIRECT 0x0040 /* RTF_DYNAMIC|RTF_MODIFIED */
+#define NHF_DEFAULT 0x0080 /* Default route */
+#define NHF_BROADCAST 0x0100 /* RTF_BROADCAST */
+#define NHF_GATEWAY 0x0200 /* RTF_GATEWAY */
+
+/* Nexthop request flags */
+#define NHR_IFAIF 0x01 /* Return ifa_ifp interface */
+#define NHR_REF 0x02 /* For future use */
+
+/* rte<>nhop translation */
+static inline uint16_t
+fib_rte_to_nh_flags(int rt_flags)
+{
+ uint16_t res;
+
+ res = (rt_flags & RTF_REJECT) ? NHF_REJECT : 0;
+ res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0;
+ res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0;
+ res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0;
+ res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0;
+
+ return (res);
+}
+
+/*
* Routing statistics.
*/
struct rtstat {
OpenPOWER on IntegriCloud