r8152: fix tx packets accounting
[linux/fpc-iii.git] / include / net / lwtunnel.h
blob3f40132e2129e0430715b0db762a8e7761cadccf
1 #ifndef __NET_LWTUNNEL_H
2 #define __NET_LWTUNNEL_H 1
4 #include <linux/lwtunnel.h>
5 #include <linux/netdevice.h>
6 #include <linux/skbuff.h>
7 #include <linux/types.h>
8 #include <net/route.h>
10 #define LWTUNNEL_HASH_BITS 7
11 #define LWTUNNEL_HASH_SIZE (1 << LWTUNNEL_HASH_BITS)
13 /* lw tunnel state flags */
14 #define LWTUNNEL_STATE_OUTPUT_REDIRECT BIT(0)
15 #define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1)
16 #define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2)
18 enum {
19 LWTUNNEL_XMIT_DONE,
20 LWTUNNEL_XMIT_CONTINUE,
24 struct lwtunnel_state {
25 __u16 type;
26 __u16 flags;
27 atomic_t refcnt;
28 int (*orig_output)(struct net *net, struct sock *sk, struct sk_buff *skb);
29 int (*orig_input)(struct sk_buff *);
30 int len;
31 __u16 headroom;
32 __u8 data[0];
35 struct lwtunnel_encap_ops {
36 int (*build_state)(struct net_device *dev, struct nlattr *encap,
37 unsigned int family, const void *cfg,
38 struct lwtunnel_state **ts);
39 int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
40 int (*input)(struct sk_buff *skb);
41 int (*fill_encap)(struct sk_buff *skb,
42 struct lwtunnel_state *lwtstate);
43 int (*get_encap_size)(struct lwtunnel_state *lwtstate);
44 int (*cmp_encap)(struct lwtunnel_state *a, struct lwtunnel_state *b);
45 int (*xmit)(struct sk_buff *skb);
47 struct module *owner;
50 #ifdef CONFIG_LWTUNNEL
51 void lwtstate_free(struct lwtunnel_state *lws);
53 static inline struct lwtunnel_state *
54 lwtstate_get(struct lwtunnel_state *lws)
56 if (lws)
57 atomic_inc(&lws->refcnt);
59 return lws;
62 static inline void lwtstate_put(struct lwtunnel_state *lws)
64 if (!lws)
65 return;
67 if (atomic_dec_and_test(&lws->refcnt))
68 lwtstate_free(lws);
71 static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
73 if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_OUTPUT_REDIRECT))
74 return true;
76 return false;
79 static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate)
81 if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_INPUT_REDIRECT))
82 return true;
84 return false;
87 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate)
89 if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_XMIT_REDIRECT))
90 return true;
92 return false;
95 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate,
96 unsigned int mtu)
98 if (lwtunnel_xmit_redirect(lwtstate) && lwtstate->headroom < mtu)
99 return lwtstate->headroom;
101 return 0;
104 int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
105 unsigned int num);
106 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
107 unsigned int num);
108 int lwtunnel_valid_encap_type(u16 encap_type);
109 int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len);
110 int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
111 struct nlattr *encap,
112 unsigned int family, const void *cfg,
113 struct lwtunnel_state **lws);
114 int lwtunnel_fill_encap(struct sk_buff *skb,
115 struct lwtunnel_state *lwtstate);
116 int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate);
117 struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len);
118 int lwtunnel_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b);
119 int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb);
120 int lwtunnel_input(struct sk_buff *skb);
121 int lwtunnel_xmit(struct sk_buff *skb);
123 #else
125 static inline void lwtstate_free(struct lwtunnel_state *lws)
129 static inline struct lwtunnel_state *
130 lwtstate_get(struct lwtunnel_state *lws)
132 return lws;
135 static inline void lwtstate_put(struct lwtunnel_state *lws)
139 static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
141 return false;
144 static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate)
146 return false;
149 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate)
151 return false;
154 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate,
155 unsigned int mtu)
157 return 0;
160 static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
161 unsigned int num)
163 return -EOPNOTSUPP;
167 static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
168 unsigned int num)
170 return -EOPNOTSUPP;
173 static inline int lwtunnel_valid_encap_type(u16 encap_type)
175 return -EOPNOTSUPP;
177 static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len)
179 /* return 0 since we are not walking attr looking for
180 * RTA_ENCAP_TYPE attribute on nexthops.
182 return 0;
185 static inline int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
186 struct nlattr *encap,
187 unsigned int family, const void *cfg,
188 struct lwtunnel_state **lws)
190 return -EOPNOTSUPP;
193 static inline int lwtunnel_fill_encap(struct sk_buff *skb,
194 struct lwtunnel_state *lwtstate)
196 return 0;
199 static inline int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate)
201 return 0;
204 static inline struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len)
206 return NULL;
209 static inline int lwtunnel_cmp_encap(struct lwtunnel_state *a,
210 struct lwtunnel_state *b)
212 return 0;
215 static inline int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb)
217 return -EOPNOTSUPP;
220 static inline int lwtunnel_input(struct sk_buff *skb)
222 return -EOPNOTSUPP;
225 static inline int lwtunnel_xmit(struct sk_buff *skb)
227 return -EOPNOTSUPP;
230 #endif /* CONFIG_LWTUNNEL */
232 #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type))
234 #endif /* __NET_LWTUNNEL_H */