aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/ip_tunnels.h
diff options
context:
space:
mode:
authorTom Herbert <tom@herbertland.com>2016-05-18 12:06:13 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-20 18:03:16 -0400
commit55c2bc1432241e7be39b11339bd00e85f878ebd6 (patch)
tree33b4dfd243b3164041732dbbb2366fd05e4274a7 /include/net/ip_tunnels.h
parent1da44f9c15e6389d45e034d5fd0b937e2928b412 (diff)
net: Cleanup encap items in ip_tunnels.h
Consolidate all the ip_tunnel_encap definitions in one spot in the header file. Also, move ip_encap_hlen and ip_tunnel_encap from ip_tunnel.c to ip_tunnels.h so they call be called without a dependency on ip_tunnel module. Similarly, move iptun_encaps to ip_tunnel_core.c. Signed-off-by: Tom Herbert <tom@herbertland.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/ip_tunnels.h')
-rw-r--r--include/net/ip_tunnels.h76
1 files changed, 58 insertions, 18 deletions
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index d916b4315903..dbf444428437 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -171,22 +171,6 @@ struct ip_tunnel_net {
171 struct ip_tunnel __rcu *collect_md_tun; 171 struct ip_tunnel __rcu *collect_md_tun;
172}; 172};
173 173
174struct ip_tunnel_encap_ops {
175 size_t (*encap_hlen)(struct ip_tunnel_encap *e);
176 int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
177 u8 *protocol, struct flowi4 *fl4);
178};
179
180#define MAX_IPTUN_ENCAP_OPS 8
181
182extern const struct ip_tunnel_encap_ops __rcu *
183 iptun_encaps[MAX_IPTUN_ENCAP_OPS];
184
185int ip_tunnel_encap_add_ops(const struct ip_tunnel_encap_ops *op,
186 unsigned int num);
187int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
188 unsigned int num);
189
190static inline void ip_tunnel_key_init(struct ip_tunnel_key *key, 174static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
191 __be32 saddr, __be32 daddr, 175 __be32 saddr, __be32 daddr,
192 u8 tos, u8 ttl, __be32 label, 176 u8 tos, u8 ttl, __be32 label,
@@ -251,8 +235,6 @@ void ip_tunnel_delete_net(struct ip_tunnel_net *itn, struct rtnl_link_ops *ops);
251void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, 235void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
252 const struct iphdr *tnl_params, const u8 protocol); 236 const struct iphdr *tnl_params, const u8 protocol);
253int ip_tunnel_ioctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd); 237int ip_tunnel_ioctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd);
254int ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel *t,
255 u8 *protocol, struct flowi4 *fl4);
256int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict); 238int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict);
257int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu); 239int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu);
258 240
@@ -271,9 +253,67 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
271int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], 253int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
272 struct ip_tunnel_parm *p); 254 struct ip_tunnel_parm *p);
273void ip_tunnel_setup(struct net_device *dev, int net_id); 255void ip_tunnel_setup(struct net_device *dev, int net_id);
256
257struct ip_tunnel_encap_ops {
258 size_t (*encap_hlen)(struct ip_tunnel_encap *e);
259 int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
260 u8 *protocol, struct flowi4 *fl4);
261};
262
263#define MAX_IPTUN_ENCAP_OPS 8
264
265extern const struct ip_tunnel_encap_ops __rcu *
266 iptun_encaps[MAX_IPTUN_ENCAP_OPS];
267
268int ip_tunnel_encap_add_ops(const struct ip_tunnel_encap_ops *op,
269 unsigned int num);
270int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
271 unsigned int num);
272
274int ip_tunnel_encap_setup(struct ip_tunnel *t, 273int ip_tunnel_encap_setup(struct ip_tunnel *t,
275 struct ip_tunnel_encap *ipencap); 274 struct ip_tunnel_encap *ipencap);
276 275
276static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
277{
278 const struct ip_tunnel_encap_ops *ops;
279 int hlen = -EINVAL;
280
281 if (e->type == TUNNEL_ENCAP_NONE)
282 return 0;
283
284 if (e->type >= MAX_IPTUN_ENCAP_OPS)
285 return -EINVAL;
286
287 rcu_read_lock();
288 ops = rcu_dereference(iptun_encaps[e->type]);
289 if (likely(ops && ops->encap_hlen))
290 hlen = ops->encap_hlen(e);
291 rcu_read_unlock();
292
293 return hlen;
294}
295
296static inline int ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel *t,
297 u8 *protocol, struct flowi4 *fl4)
298{
299 const struct ip_tunnel_encap_ops *ops;
300 int ret = -EINVAL;
301
302 if (t->encap.type == TUNNEL_ENCAP_NONE)
303 return 0;
304
305 if (t->encap.type >= MAX_IPTUN_ENCAP_OPS)
306 return -EINVAL;
307
308 rcu_read_lock();
309 ops = rcu_dereference(iptun_encaps[t->encap.type]);
310 if (likely(ops && ops->build_header))
311 ret = ops->build_header(skb, &t->encap, protocol, fl4);
312 rcu_read_unlock();
313
314 return ret;
315}
316
277/* Extract dsfield from inner protocol */ 317/* Extract dsfield from inner protocol */
278static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph, 318static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
279 const struct sk_buff *skb) 319 const struct sk_buff *skb)