]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/ip6_tunnel.h
net: core: limit nested device depth
[mirror_ubuntu-bionic-kernel.git] / include / net / ip6_tunnel.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _NET_IP6_TUNNEL_H
3#define _NET_IP6_TUNNEL_H
4
5#include <linux/ipv6.h>
6#include <linux/netdevice.h>
c5441932 7#include <linux/if_tunnel.h>
1da177e4 8#include <linux/ip6_tunnel.h>
039f5062 9#include <net/ip_tunnels.h>
607f725f 10#include <net/dst_cache.h>
1da177e4 11
c12b395a 12#define IP6TUNNEL_ERR_TIMEO (30*HZ)
13
1da177e4
LT
14/* capable of sending packets */
15#define IP6_TNL_F_CAP_XMIT 0x10000
16/* capable of receiving packets */
17#define IP6_TNL_F_CAP_RCV 0x20000
d0087b29
VN
18/* determine capability on a per-packet basis */
19#define IP6_TNL_F_CAP_PER_PACKET 0x40000
1da177e4 20
c12b395a 21struct __ip6_tnl_parm {
22 char name[IFNAMSIZ]; /* name of tunnel device */
23 int link; /* ifindex of underlying L2 interface */
24 __u8 proto; /* tunnel protocol */
25 __u8 encap_limit; /* encapsulation limit for tunnel */
26 __u8 hop_limit; /* hop limit for tunnel */
8d79266b 27 bool collect_md;
c12b395a 28 __be32 flowinfo; /* traffic class and flowlabel for tunnel */
29 __u32 flags; /* tunnel flags */
30 struct in6_addr laddr; /* local tunnel end-point address */
31 struct in6_addr raddr; /* remote tunnel end-point address */
32
33 __be16 i_flags;
34 __be16 o_flags;
35 __be32 i_key;
36 __be32 o_key;
0a473b82
CG
37
38 __u32 fwmark;
c12b395a 39};
1da177e4 40
c12b395a 41/* IPv6 tunnel */
1da177e4 42struct ip6_tnl {
6f0bcf15 43 struct ip6_tnl __rcu *next; /* next tunnel in list */
1da177e4 44 struct net_device *dev; /* virtual device associated with tunnel */
0bd87628 45 struct net *net; /* netns for packet i/o */
c12b395a 46 struct __ip6_tnl_parm parms; /* tunnel configuration parameters */
1da177e4 47 struct flowi fl; /* flowi template for xmit */
607f725f 48 struct dst_cache dst_cache; /* cached dst */
0d3c703a 49 struct gro_cells gro_cells;
c12b395a 50
51 int err_count;
52 unsigned long err_time;
53
54 /* These fields used only by GRE */
55 __u32 i_seqno; /* The last seen seqno */
56 __u32 o_seqno; /* The last output seqno */
79ecb90e
TH
57 int hlen; /* tun_hlen + encap_hlen */
58 int tun_hlen; /* Precalculated header length */
058214a4
TH
59 int encap_hlen; /* Encap header length (FOU,GUE) */
60 struct ip_tunnel_encap encap;
c12b395a 61 int mlink;
058214a4 62};
79ecb90e 63
058214a4
TH
64struct ip6_tnl_encap_ops {
65 size_t (*encap_hlen)(struct ip_tunnel_encap *e);
66 int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
67 u8 *protocol, struct flowi6 *fl6);
1da177e4
LT
68};
69
9791d8e7
AB
70#ifdef CONFIG_INET
71
058214a4
TH
72extern const struct ip6_tnl_encap_ops __rcu *
73 ip6tun_encaps[MAX_IPTUN_ENCAP_OPS];
74
75int ip6_tnl_encap_add_ops(const struct ip6_tnl_encap_ops *ops,
76 unsigned int num);
77int ip6_tnl_encap_del_ops(const struct ip6_tnl_encap_ops *ops,
78 unsigned int num);
79int ip6_tnl_encap_setup(struct ip6_tnl *t,
80 struct ip_tunnel_encap *ipencap);
81
82static inline int ip6_encap_hlen(struct ip_tunnel_encap *e)
83{
84 const struct ip6_tnl_encap_ops *ops;
85 int hlen = -EINVAL;
86
87 if (e->type == TUNNEL_ENCAP_NONE)
88 return 0;
89
90 if (e->type >= MAX_IPTUN_ENCAP_OPS)
91 return -EINVAL;
92
93 rcu_read_lock();
94 ops = rcu_dereference(ip6tun_encaps[e->type]);
95 if (likely(ops && ops->encap_hlen))
96 hlen = ops->encap_hlen(e);
97 rcu_read_unlock();
98
99 return hlen;
100}
101
102static inline int ip6_tnl_encap(struct sk_buff *skb, struct ip6_tnl *t,
103 u8 *protocol, struct flowi6 *fl6)
104{
105 const struct ip6_tnl_encap_ops *ops;
106 int ret = -EINVAL;
107
108 if (t->encap.type == TUNNEL_ENCAP_NONE)
109 return 0;
110
111 if (t->encap.type >= MAX_IPTUN_ENCAP_OPS)
112 return -EINVAL;
113
114 rcu_read_lock();
115 ops = rcu_dereference(ip6tun_encaps[t->encap.type]);
116 if (likely(ops && ops->build_header))
117 ret = ops->build_header(skb, &t->encap, protocol, fl6);
118 rcu_read_unlock();
119
120 return ret;
121}
122
1da177e4
LT
123/* Tunnel encapsulation limit destination sub-option */
124
125struct ipv6_tlv_tnl_enc_lim {
126 __u8 type; /* type-code for option */
127 __u8 length; /* option length */
128 __u8 encap_limit; /* tunnel encapsulation limit */
bc10502d 129} __packed;
1da177e4 130
c12b395a 131int ip6_tnl_rcv_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
132 const struct in6_addr *raddr);
0d3c703a
TH
133int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
134 const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst,
135 bool log_ecn_error);
d5005140
SK
136int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
137 const struct in6_addr *raddr);
8eb30be0
TH
138int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
139 struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto);
c12b395a 140__u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);
141__u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,
142 const struct in6_addr *raddr);
1728d4fa 143struct net *ip6_tnl_get_link_net(const struct net_device *dev);
ecf2c06a 144int ip6_tnl_get_iflink(const struct net_device *dev);
79ecb90e 145int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu);
c12b395a 146
79b16aad
DM
147static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,
148 struct net_device *dev)
e8f72ea4 149{
e8f72ea4
CW
150 int pkt_len, err;
151
23f4ffed 152 memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
83cf9a25 153 pkt_len = skb->len - skb_inner_network_offset(skb);
33224b16 154 err = ip6_local_out(dev_net(skb_dst(skb)->dev), sk, skb);
7bac9a76
XL
155
156 if (dev) {
157 if (unlikely(net_xmit_eval(err)))
158 pkt_len = -1;
159 iptunnel_xmit_stats(dev, pkt_len);
160 }
e8f72ea4 161}
1da177e4 162#endif
0efeff29 163#endif