2 * Copyright (c) 2007-2012 Nicira, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <linux/in_route.h>
24 #include <linux/netlink.h>
25 #include <net/route.h>
29 #ifndef HAVE_NLA_NUL_STRING
30 static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
42 if (s[len - 1] != '\0')
48 static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
52 #endif /* !HAVE_NLA_NUL_STRING */
54 static inline void skb_clear_rxhash(struct sk_buff *skb)
56 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
61 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
62 #define GENL_SOCK(net) (genl_sock)
65 #define GENL_SOCK(net) ((net)->genl_sock)
66 #define SET_NETNSOK .netnsok = true,
69 #ifdef HAVE_PARALLEL_OPS
70 #define SET_PARALLEL_OPS .parallel_ops = true,
72 #define SET_PARALLEL_OPS
75 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
76 #define rt_dst(rt) (rt->dst)
78 #define rt_dst(rt) (rt->u.dst)
81 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
82 #define inet_sport(sk) (inet_sk(sk)->sport)
84 #define inet_sport(sk) (inet_sk(sk)->inet_sport)
87 static inline struct rtable *find_route(struct net *net,
88 __be32 *saddr, __be32 daddr,
89 u8 ipproto, u8 tos, u32 skb_mark)
92 /* Tunnel configuration keeps DSCP part of TOS bits, But Linux
93 * router expect RT_TOS bits only. */
95 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
96 struct flowi fl = { .nl_u = { .ip4_u = {
99 .tos = RT_TOS(tos) } },
103 if (unlikely(ip_route_output_key(net, &rt, &fl)))
104 return ERR_PTR(-EADDRNOTAVAIL);
105 *saddr = fl.nl_u.ip4_u.saddr;
108 struct flowi4 fl = { .daddr = daddr,
110 .flowi4_tos = RT_TOS(tos),
111 .flowi4_mark = skb_mark,
112 .flowi4_proto = ipproto };
114 rt = ip_route_output_key(net, &fl);
119 #endif /* compat.h */