]> git.proxmox.com Git - ovs.git/blame - datapath/compat.h
datapath: Restructure vxlan tunneling.
[ovs.git] / datapath / compat.h
CommitLineData
9cb8d24d 1/*
e0edde6f 2 * Copyright (c) 2007-2012 Nicira, Inc.
9cb8d24d 3 *
a9a29d22
JG
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.
7 *
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.
12 *
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
16 * 02110-1301, USA
9cb8d24d
JG
17 */
18
19#ifndef COMPAT_H
20#define COMPAT_H 1
21
22#include <linux/netlink.h>
23
24#ifndef HAVE_NLA_NUL_STRING
25static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
26{
27 char *s;
28 int len;
29 if (!attr)
30 return 0;
31
32 len = nla_len(attr);
33 if (len >= maxlen)
34 return -EINVAL;
35
36 s = nla_data(attr);
37 if (s[len - 1] != '\0')
38 return -EINVAL;
39
40 return 0;
41}
42#else
43static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
44{
45 return 0;
46}
47#endif /* !HAVE_NLA_NUL_STRING */
48
eba9291a
PS
49static inline void skb_clear_rxhash(struct sk_buff *skb)
50{
51#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
52 skb->rxhash = 0;
53#endif
54}
55
2a4999f3
PS
56#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
57#define GENL_SOCK(net) (genl_sock)
58#define SET_NETNSOK
59#else
60#define GENL_SOCK(net) ((net)->genl_sock)
61#define SET_NETNSOK .netnsok = true,
62#endif
63
72e8bf28
AA
64#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
65#ifdef CONFIG_NETFILTER
66static inline u32 skb_get_mark(struct sk_buff *skb)
67{
68 return skb->nfmark;
69}
70
71static inline void skb_set_mark(struct sk_buff *skb, u32 mark)
72{
73 skb->nfmark = mark;
74}
75#else /* CONFIG_NETFILTER */
76static inline u32 skb_get_mark(struct sk_buff *skb)
77{
78 return 0;
79}
80
81static inline void skb_set_mark(struct sk_buff *skb, u32 mark)
82{
83}
84#endif
85#else /* before 2.6.20 */
86static inline u32 skb_get_mark(struct sk_buff *skb)
87{
88 return skb->mark;
89}
90
91static inline void skb_set_mark(struct sk_buff *skb, u32 mark)
92{
93 skb->mark = mark;
94}
95#endif /* after 2.6.20 */
96
5ebaf571
PS
97#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
98#define rt_dst(rt) (rt->dst)
99#else
100#define rt_dst(rt) (rt->u.dst)
101#endif
102
1b7ee51f
PS
103#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
104#define inet_sport(sk) (inet_sk(sk)->sport)
105#else
106#define inet_sport(sk) (inet_sk(sk)->inet_sport)
107#endif
108
9cb8d24d 109#endif /* compat.h */