Blame view

include/net/lwtunnel.h 6.38 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
499a24256   Roopa Prabhu   lwtunnel: infrast...
2
3
4
5
6
7
8
9
10
11
12
13
14
  #ifndef __NET_LWTUNNEL_H
  #define __NET_LWTUNNEL_H 1
  
  #include <linux/lwtunnel.h>
  #include <linux/netdevice.h>
  #include <linux/skbuff.h>
  #include <linux/types.h>
  #include <net/route.h>
  
  #define LWTUNNEL_HASH_BITS   7
  #define LWTUNNEL_HASH_SIZE   (1 << LWTUNNEL_HASH_BITS)
  
  /* lw tunnel state flags */
253686231   Tom Herbert   lwt: Add support ...
15
16
  #define LWTUNNEL_STATE_OUTPUT_REDIRECT	BIT(0)
  #define LWTUNNEL_STATE_INPUT_REDIRECT	BIT(1)
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
17
18
19
20
21
22
  #define LWTUNNEL_STATE_XMIT_REDIRECT	BIT(2)
  
  enum {
  	LWTUNNEL_XMIT_DONE,
  	LWTUNNEL_XMIT_CONTINUE,
  };
499a24256   Roopa Prabhu   lwtunnel: infrast...
23
24
25
26
  
  struct lwtunnel_state {
  	__u16		type;
  	__u16		flags;
f76a9db35   Thomas Graf   lwt: Remove unuse...
27
  	__u16		headroom;
499a24256   Roopa Prabhu   lwtunnel: infrast...
28
  	atomic_t	refcnt;
ede2059db   Eric W. Biederman   dst: Pass net int...
29
  	int		(*orig_output)(struct net *net, struct sock *sk, struct sk_buff *skb);
253686231   Tom Herbert   lwt: Add support ...
30
  	int		(*orig_input)(struct sk_buff *);
1104d9ba4   Tom Herbert   lwtunnel: Add des...
31
  	struct		rcu_head rcu;
499a24256   Roopa Prabhu   lwtunnel: infrast...
32
33
34
35
  	__u8            data[0];
  };
  
  struct lwtunnel_encap_ops {
30357d7d8   David Ahern   lwtunnel: remove ...
36
  	int (*build_state)(struct nlattr *encap,
127eb7cd3   Tom Herbert   lwt: Add cfg argu...
37
  			   unsigned int family, const void *cfg,
9ae287274   David Ahern   net: add extack a...
38
39
  			   struct lwtunnel_state **ts,
  			   struct netlink_ext_ack *extack);
1104d9ba4   Tom Herbert   lwtunnel: Add des...
40
  	void (*destroy_state)(struct lwtunnel_state *lws);
ede2059db   Eric W. Biederman   dst: Pass net int...
41
  	int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
253686231   Tom Herbert   lwt: Add support ...
42
  	int (*input)(struct sk_buff *skb);
499a24256   Roopa Prabhu   lwtunnel: infrast...
43
44
45
46
  	int (*fill_encap)(struct sk_buff *skb,
  			  struct lwtunnel_state *lwtstate);
  	int (*get_encap_size)(struct lwtunnel_state *lwtstate);
  	int (*cmp_encap)(struct lwtunnel_state *a, struct lwtunnel_state *b);
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
47
  	int (*xmit)(struct sk_buff *skb);
88ff7334f   Robert Shearman   net: Specify the ...
48
49
  
  	struct module *owner;
499a24256   Roopa Prabhu   lwtunnel: infrast...
50
  };
499a24256   Roopa Prabhu   lwtunnel: infrast...
51
  #ifdef CONFIG_LWTUNNEL
1104d9ba4   Tom Herbert   lwtunnel: Add des...
52
  void lwtstate_free(struct lwtunnel_state *lws);
df383e624   Jiri Benc   lwtunnel: fix mem...
53

5a6228a0b   Nicolas Dichtel   lwtunnel: change ...
54
55
  static inline struct lwtunnel_state *
  lwtstate_get(struct lwtunnel_state *lws)
499a24256   Roopa Prabhu   lwtunnel: infrast...
56
  {
5a6228a0b   Nicolas Dichtel   lwtunnel: change ...
57
58
59
60
  	if (lws)
  		atomic_inc(&lws->refcnt);
  
  	return lws;
499a24256   Roopa Prabhu   lwtunnel: infrast...
61
  }
5a6228a0b   Nicolas Dichtel   lwtunnel: change ...
62
  static inline void lwtstate_put(struct lwtunnel_state *lws)
499a24256   Roopa Prabhu   lwtunnel: infrast...
63
64
65
66
67
  {
  	if (!lws)
  		return;
  
  	if (atomic_dec_and_test(&lws->refcnt))
df383e624   Jiri Benc   lwtunnel: fix mem...
68
  		lwtstate_free(lws);
499a24256   Roopa Prabhu   lwtunnel: infrast...
69
70
71
72
73
74
75
76
77
  }
  
  static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
  {
  	if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_OUTPUT_REDIRECT))
  		return true;
  
  	return false;
  }
253686231   Tom Herbert   lwt: Add support ...
78
79
80
81
82
83
84
  static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate)
  {
  	if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_INPUT_REDIRECT))
  		return true;
  
  	return false;
  }
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
85
86
87
88
89
90
91
92
93
94
95
96
  
  static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate)
  {
  	if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_XMIT_REDIRECT))
  		return true;
  
  	return false;
  }
  
  static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate,
  					     unsigned int mtu)
  {
a23a8f5bc   David Lebrun   lwtunnel: subtrac...
97
98
  	if ((lwtunnel_xmit_redirect(lwtstate) ||
  	     lwtunnel_output_redirect(lwtstate)) && lwtstate->headroom < mtu)
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
99
100
101
102
  		return lwtstate->headroom;
  
  	return 0;
  }
499a24256   Roopa Prabhu   lwtunnel: infrast...
103
104
105
106
  int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
  			   unsigned int num);
  int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
  			   unsigned int num);
c255bd681   David Ahern   net: lwtunnel: Ad...
107
108
109
110
  int lwtunnel_valid_encap_type(u16 encap_type,
  			      struct netlink_ext_ack *extack);
  int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len,
  				   struct netlink_ext_ack *extack);
30357d7d8   David Ahern   lwtunnel: remove ...
111
  int lwtunnel_build_state(u16 encap_type,
499a24256   Roopa Prabhu   lwtunnel: infrast...
112
  			 struct nlattr *encap,
127eb7cd3   Tom Herbert   lwt: Add cfg argu...
113
  			 unsigned int family, const void *cfg,
9ae287274   David Ahern   net: add extack a...
114
115
  			 struct lwtunnel_state **lws,
  			 struct netlink_ext_ack *extack);
ffa8ce54b   David Ahern   lwtunnel: Pass en...
116
117
  int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate,
  			int encap_attr, int encap_type_attr);
499a24256   Roopa Prabhu   lwtunnel: infrast...
118
119
120
  int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate);
  struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len);
  int lwtunnel_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b);
ede2059db   Eric W. Biederman   dst: Pass net int...
121
  int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb);
253686231   Tom Herbert   lwt: Add support ...
122
  int lwtunnel_input(struct sk_buff *skb);
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
123
  int lwtunnel_xmit(struct sk_buff *skb);
52f278774   Peter Oskolkov   bpf: implement BP...
124
125
  int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len,
  			  bool ingress);
499a24256   Roopa Prabhu   lwtunnel: infrast...
126

9942895b5   David Ahern   net: Move ipv4 se...
127
128
129
130
131
132
133
134
135
136
137
  static inline void lwtunnel_set_redirect(struct dst_entry *dst)
  {
  	if (lwtunnel_output_redirect(dst->lwtstate)) {
  		dst->lwtstate->orig_output = dst->output;
  		dst->output = lwtunnel_output;
  	}
  	if (lwtunnel_input_redirect(dst->lwtstate)) {
  		dst->lwtstate->orig_input = dst->input;
  		dst->input = lwtunnel_input;
  	}
  }
499a24256   Roopa Prabhu   lwtunnel: infrast...
138
  #else
824e7383e   Ying Xue   lwtunnel: Fix the...
139
140
141
  static inline void lwtstate_free(struct lwtunnel_state *lws)
  {
  }
5a6228a0b   Nicolas Dichtel   lwtunnel: change ...
142
143
  static inline struct lwtunnel_state *
  lwtstate_get(struct lwtunnel_state *lws)
499a24256   Roopa Prabhu   lwtunnel: infrast...
144
  {
5a6228a0b   Nicolas Dichtel   lwtunnel: change ...
145
  	return lws;
499a24256   Roopa Prabhu   lwtunnel: infrast...
146
  }
5a6228a0b   Nicolas Dichtel   lwtunnel: change ...
147
  static inline void lwtstate_put(struct lwtunnel_state *lws)
499a24256   Roopa Prabhu   lwtunnel: infrast...
148
149
150
151
152
153
154
  {
  }
  
  static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
  {
  	return false;
  }
253686231   Tom Herbert   lwt: Add support ...
155
156
157
158
  static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate)
  {
  	return false;
  }
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
159
160
161
162
  static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate)
  {
  	return false;
  }
9942895b5   David Ahern   net: Move ipv4 se...
163
164
165
  static inline void lwtunnel_set_redirect(struct dst_entry *dst)
  {
  }
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
166
167
168
169
170
  static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate,
  					     unsigned int mtu)
  {
  	return 0;
  }
499a24256   Roopa Prabhu   lwtunnel: infrast...
171
172
173
174
175
176
177
178
179
180
181
182
  static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
  					 unsigned int num)
  {
  	return -EOPNOTSUPP;
  
  }
  
  static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
  					 unsigned int num)
  {
  	return -EOPNOTSUPP;
  }
c255bd681   David Ahern   net: lwtunnel: Ad...
183
184
  static inline int lwtunnel_valid_encap_type(u16 encap_type,
  					    struct netlink_ext_ack *extack)
9ed59592e   David Ahern   lwtunnel: fix aut...
185
  {
c255bd681   David Ahern   net: lwtunnel: Ad...
186
  	NL_SET_ERR_MSG(extack, "CONFIG_LWTUNNEL is not enabled in this kernel");
9ed59592e   David Ahern   lwtunnel: fix aut...
187
188
  	return -EOPNOTSUPP;
  }
c255bd681   David Ahern   net: lwtunnel: Ad...
189
190
  static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len,
  						 struct netlink_ext_ack *extack)
9ed59592e   David Ahern   lwtunnel: fix aut...
191
  {
2bd137de5   David Ahern   lwtunnel: valid e...
192
193
194
195
  	/* return 0 since we are not walking attr looking for
  	 * RTA_ENCAP_TYPE attribute on nexthops.
  	 */
  	return 0;
9ed59592e   David Ahern   lwtunnel: fix aut...
196
  }
30357d7d8   David Ahern   lwtunnel: remove ...
197
  static inline int lwtunnel_build_state(u16 encap_type,
499a24256   Roopa Prabhu   lwtunnel: infrast...
198
  				       struct nlattr *encap,
127eb7cd3   Tom Herbert   lwt: Add cfg argu...
199
  				       unsigned int family, const void *cfg,
9ae287274   David Ahern   net: add extack a...
200
201
  				       struct lwtunnel_state **lws,
  				       struct netlink_ext_ack *extack)
499a24256   Roopa Prabhu   lwtunnel: infrast...
202
203
204
205
206
  {
  	return -EOPNOTSUPP;
  }
  
  static inline int lwtunnel_fill_encap(struct sk_buff *skb,
ffa8ce54b   David Ahern   lwtunnel: Pass en...
207
208
  				      struct lwtunnel_state *lwtstate,
  				      int encap_attr, int encap_type_attr)
499a24256   Roopa Prabhu   lwtunnel: infrast...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  {
  	return 0;
  }
  
  static inline int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate)
  {
  	return 0;
  }
  
  static inline struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len)
  {
  	return NULL;
  }
  
  static inline int lwtunnel_cmp_encap(struct lwtunnel_state *a,
  				     struct lwtunnel_state *b)
  {
  	return 0;
  }
ede2059db   Eric W. Biederman   dst: Pass net int...
228
  static inline int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb)
ffce41962   Roopa Prabhu   lwtunnel: support...
229
230
231
  {
  	return -EOPNOTSUPP;
  }
253686231   Tom Herbert   lwt: Add support ...
232
233
234
235
  static inline int lwtunnel_input(struct sk_buff *skb)
  {
  	return -EOPNOTSUPP;
  }
14972cbd3   Roopa Prabhu   net: lwtunnel: Ha...
236
237
238
239
  static inline int lwtunnel_xmit(struct sk_buff *skb)
  {
  	return -EOPNOTSUPP;
  }
745041e2a   Robert Shearman   lwtunnel: autoloa...
240
241
242
  #endif /* CONFIG_LWTUNNEL */
  
  #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type))
499a24256   Roopa Prabhu   lwtunnel: infrast...
243
244
  
  #endif /* __NET_LWTUNNEL_H */