GNU Linux-libre 4.19.264-gnu1
[releases.git] / net / netfilter / nft_tunnel.c
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/seqlock.h>
6 #include <linux/netlink.h>
7 #include <linux/netfilter.h>
8 #include <linux/netfilter/nf_tables.h>
9 #include <net/netfilter/nf_tables.h>
10 #include <net/dst_metadata.h>
11 #include <net/ip_tunnels.h>
12 #include <net/vxlan.h>
13 #include <net/erspan.h>
14
15 struct nft_tunnel {
16         enum nft_tunnel_keys    key:8;
17         enum nft_registers      dreg:8;
18 };
19
20 static void nft_tunnel_get_eval(const struct nft_expr *expr,
21                                 struct nft_regs *regs,
22                                 const struct nft_pktinfo *pkt)
23 {
24         const struct nft_tunnel *priv = nft_expr_priv(expr);
25         u32 *dest = &regs->data[priv->dreg];
26         struct ip_tunnel_info *tun_info;
27
28         tun_info = skb_tunnel_info(pkt->skb);
29
30         switch (priv->key) {
31         case NFT_TUNNEL_PATH:
32                 nft_reg_store8(dest, !!tun_info);
33                 break;
34         case NFT_TUNNEL_ID:
35                 if (!tun_info) {
36                         regs->verdict.code = NFT_BREAK;
37                         return;
38                 }
39                 *dest = ntohl(tunnel_id_to_key32(tun_info->key.tun_id));
40                 break;
41         default:
42                 WARN_ON(1);
43                 regs->verdict.code = NFT_BREAK;
44         }
45 }
46
47 static const struct nla_policy nft_tunnel_policy[NFTA_TUNNEL_MAX + 1] = {
48         [NFTA_TUNNEL_KEY]       = { .type = NLA_U32 },
49         [NFTA_TUNNEL_DREG]      = { .type = NLA_U32 },
50 };
51
52 static int nft_tunnel_get_init(const struct nft_ctx *ctx,
53                                const struct nft_expr *expr,
54                                const struct nlattr * const tb[])
55 {
56         struct nft_tunnel *priv = nft_expr_priv(expr);
57         u32 len;
58
59         if (!tb[NFTA_TUNNEL_KEY] ||
60             !tb[NFTA_TUNNEL_DREG])
61                 return -EINVAL;
62
63         priv->key = ntohl(nla_get_be32(tb[NFTA_TUNNEL_KEY]));
64         switch (priv->key) {
65         case NFT_TUNNEL_PATH:
66                 len = sizeof(u8);
67                 break;
68         case NFT_TUNNEL_ID:
69                 len = sizeof(u32);
70                 break;
71         default:
72                 return -EOPNOTSUPP;
73         }
74
75         priv->dreg = nft_parse_register(tb[NFTA_TUNNEL_DREG]);
76
77         return nft_validate_register_store(ctx, priv->dreg, NULL,
78                                            NFT_DATA_VALUE, len);
79 }
80
81 static int nft_tunnel_get_dump(struct sk_buff *skb,
82                                const struct nft_expr *expr)
83 {
84         const struct nft_tunnel *priv = nft_expr_priv(expr);
85
86         if (nla_put_be32(skb, NFTA_TUNNEL_KEY, htonl(priv->key)))
87                 goto nla_put_failure;
88         if (nft_dump_register(skb, NFTA_TUNNEL_DREG, priv->dreg))
89                 goto nla_put_failure;
90         return 0;
91
92 nla_put_failure:
93         return -1;
94 }
95
96 static struct nft_expr_type nft_tunnel_type;
97 static const struct nft_expr_ops nft_tunnel_get_ops = {
98         .type           = &nft_tunnel_type,
99         .size           = NFT_EXPR_SIZE(sizeof(struct nft_tunnel)),
100         .eval           = nft_tunnel_get_eval,
101         .init           = nft_tunnel_get_init,
102         .dump           = nft_tunnel_get_dump,
103 };
104
105 static struct nft_expr_type nft_tunnel_type __read_mostly = {
106         .name           = "tunnel",
107         .family         = NFPROTO_NETDEV,
108         .ops            = &nft_tunnel_get_ops,
109         .policy         = nft_tunnel_policy,
110         .maxattr        = NFTA_TUNNEL_MAX,
111         .owner          = THIS_MODULE,
112 };
113
114 struct nft_tunnel_opts {
115         union {
116                 struct vxlan_metadata   vxlan;
117                 struct erspan_metadata  erspan;
118         } u;
119         u32     len;
120         __be16  flags;
121 };
122
123 struct nft_tunnel_obj {
124         struct metadata_dst     *md;
125         struct nft_tunnel_opts  opts;
126 };
127
128 static const struct nla_policy nft_tunnel_ip_policy[NFTA_TUNNEL_KEY_IP_MAX + 1] = {
129         [NFTA_TUNNEL_KEY_IP_SRC]        = { .type = NLA_U32 },
130         [NFTA_TUNNEL_KEY_IP_DST]        = { .type = NLA_U32 },
131 };
132
133 static int nft_tunnel_obj_ip_init(const struct nft_ctx *ctx,
134                                   const struct nlattr *attr,
135                                   struct ip_tunnel_info *info)
136 {
137         struct nlattr *tb[NFTA_TUNNEL_KEY_IP_MAX + 1];
138         int err;
139
140         err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_IP_MAX, attr,
141                                nft_tunnel_ip_policy, NULL);
142         if (err < 0)
143                 return err;
144
145         if (!tb[NFTA_TUNNEL_KEY_IP_DST])
146                 return -EINVAL;
147
148         if (tb[NFTA_TUNNEL_KEY_IP_SRC])
149                 info->key.u.ipv4.src = nla_get_be32(tb[NFTA_TUNNEL_KEY_IP_SRC]);
150         if (tb[NFTA_TUNNEL_KEY_IP_DST])
151                 info->key.u.ipv4.dst = nla_get_be32(tb[NFTA_TUNNEL_KEY_IP_DST]);
152
153         return 0;
154 }
155
156 static const struct nla_policy nft_tunnel_ip6_policy[NFTA_TUNNEL_KEY_IP6_MAX + 1] = {
157         [NFTA_TUNNEL_KEY_IP6_SRC]       = { .len = sizeof(struct in6_addr), },
158         [NFTA_TUNNEL_KEY_IP6_DST]       = { .len = sizeof(struct in6_addr), },
159         [NFTA_TUNNEL_KEY_IP6_FLOWLABEL] = { .type = NLA_U32, }
160 };
161
162 static int nft_tunnel_obj_ip6_init(const struct nft_ctx *ctx,
163                                    const struct nlattr *attr,
164                                    struct ip_tunnel_info *info)
165 {
166         struct nlattr *tb[NFTA_TUNNEL_KEY_IP6_MAX + 1];
167         int err;
168
169         err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_IP6_MAX, attr,
170                                nft_tunnel_ip6_policy, NULL);
171         if (err < 0)
172                 return err;
173
174         if (!tb[NFTA_TUNNEL_KEY_IP6_DST])
175                 return -EINVAL;
176
177         if (tb[NFTA_TUNNEL_KEY_IP6_SRC]) {
178                 memcpy(&info->key.u.ipv6.src,
179                        nla_data(tb[NFTA_TUNNEL_KEY_IP6_SRC]),
180                        sizeof(struct in6_addr));
181         }
182         if (tb[NFTA_TUNNEL_KEY_IP6_DST]) {
183                 memcpy(&info->key.u.ipv6.dst,
184                        nla_data(tb[NFTA_TUNNEL_KEY_IP6_DST]),
185                        sizeof(struct in6_addr));
186         }
187         if (tb[NFTA_TUNNEL_KEY_IP6_FLOWLABEL])
188                 info->key.label = nla_get_be32(tb[NFTA_TUNNEL_KEY_IP6_FLOWLABEL]);
189
190         info->mode |= IP_TUNNEL_INFO_IPV6;
191
192         return 0;
193 }
194
195 static const struct nla_policy nft_tunnel_opts_vxlan_policy[NFTA_TUNNEL_KEY_VXLAN_MAX + 1] = {
196         [NFTA_TUNNEL_KEY_VXLAN_GBP]     = { .type = NLA_U32 },
197 };
198
199 static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr,
200                                      struct nft_tunnel_opts *opts)
201 {
202         struct nlattr *tb[NFTA_TUNNEL_KEY_VXLAN_MAX + 1];
203         int err;
204
205         err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_VXLAN_MAX, attr,
206                                nft_tunnel_opts_vxlan_policy, NULL);
207         if (err < 0)
208                 return err;
209
210         if (!tb[NFTA_TUNNEL_KEY_VXLAN_GBP])
211                 return -EINVAL;
212
213         opts->u.vxlan.gbp = ntohl(nla_get_be32(tb[NFTA_TUNNEL_KEY_VXLAN_GBP]));
214
215         opts->len       = sizeof(struct vxlan_metadata);
216         opts->flags     = TUNNEL_VXLAN_OPT;
217
218         return 0;
219 }
220
221 static const struct nla_policy nft_tunnel_opts_erspan_policy[NFTA_TUNNEL_KEY_ERSPAN_MAX + 1] = {
222         [NFTA_TUNNEL_KEY_ERSPAN_VERSION]        = { .type = NLA_U32 },
223         [NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX]       = { .type = NLA_U32 },
224         [NFTA_TUNNEL_KEY_ERSPAN_V2_DIR]         = { .type = NLA_U8 },
225         [NFTA_TUNNEL_KEY_ERSPAN_V2_HWID]        = { .type = NLA_U8 },
226 };
227
228 static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,
229                                       struct nft_tunnel_opts *opts)
230 {
231         struct nlattr *tb[NFTA_TUNNEL_KEY_ERSPAN_MAX + 1];
232         uint8_t hwid, dir;
233         int err, version;
234
235         err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_ERSPAN_MAX, attr,
236                                nft_tunnel_opts_erspan_policy, NULL);
237         if (err < 0)
238                 return err;
239
240         if (!tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION])
241                  return -EINVAL;
242
243         version = ntohl(nla_get_be32(tb[NFTA_TUNNEL_KEY_ERSPAN_VERSION]));
244         switch (version) {
245         case ERSPAN_VERSION:
246                 if (!tb[NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX])
247                         return -EINVAL;
248
249                 opts->u.erspan.u.index =
250                         nla_get_be32(tb[NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX]);
251                 break;
252         case ERSPAN_VERSION2:
253                 if (!tb[NFTA_TUNNEL_KEY_ERSPAN_V2_DIR] ||
254                     !tb[NFTA_TUNNEL_KEY_ERSPAN_V2_HWID])
255                         return -EINVAL;
256
257                 hwid = nla_get_u8(tb[NFTA_TUNNEL_KEY_ERSPAN_V2_HWID]);
258                 dir = nla_get_u8(tb[NFTA_TUNNEL_KEY_ERSPAN_V2_DIR]);
259
260                 set_hwid(&opts->u.erspan.u.md2, hwid);
261                 opts->u.erspan.u.md2.dir = dir;
262                 break;
263         default:
264                 return -EOPNOTSUPP;
265         }
266         opts->u.erspan.version = version;
267
268         opts->len       = sizeof(struct erspan_metadata);
269         opts->flags     = TUNNEL_ERSPAN_OPT;
270
271         return 0;
272 }
273
274 static const struct nla_policy nft_tunnel_opts_policy[NFTA_TUNNEL_KEY_OPTS_MAX + 1] = {
275         [NFTA_TUNNEL_KEY_OPTS_VXLAN]    = { .type = NLA_NESTED, },
276         [NFTA_TUNNEL_KEY_OPTS_ERSPAN]   = { .type = NLA_NESTED, },
277 };
278
279 static int nft_tunnel_obj_opts_init(const struct nft_ctx *ctx,
280                                     const struct nlattr *attr,
281                                     struct ip_tunnel_info *info,
282                                     struct nft_tunnel_opts *opts)
283 {
284         struct nlattr *tb[NFTA_TUNNEL_KEY_OPTS_MAX + 1];
285         int err;
286
287         err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_OPTS_MAX, attr,
288                                nft_tunnel_opts_policy, NULL);
289         if (err < 0)
290                 return err;
291
292         if (tb[NFTA_TUNNEL_KEY_OPTS_VXLAN]) {
293                 err = nft_tunnel_obj_vxlan_init(tb[NFTA_TUNNEL_KEY_OPTS_VXLAN],
294                                                 opts);
295         } else if (tb[NFTA_TUNNEL_KEY_OPTS_ERSPAN]) {
296                 err = nft_tunnel_obj_erspan_init(tb[NFTA_TUNNEL_KEY_OPTS_ERSPAN],
297                                                  opts);
298         } else {
299                 return -EOPNOTSUPP;
300         }
301
302         return err;
303 }
304
305 static const struct nla_policy nft_tunnel_key_policy[NFTA_TUNNEL_KEY_MAX + 1] = {
306         [NFTA_TUNNEL_KEY_IP]    = { .type = NLA_NESTED, },
307         [NFTA_TUNNEL_KEY_IP6]   = { .type = NLA_NESTED, },
308         [NFTA_TUNNEL_KEY_ID]    = { .type = NLA_U32, },
309         [NFTA_TUNNEL_KEY_FLAGS] = { .type = NLA_U32, },
310         [NFTA_TUNNEL_KEY_TOS]   = { .type = NLA_U8, },
311         [NFTA_TUNNEL_KEY_TTL]   = { .type = NLA_U8, },
312         [NFTA_TUNNEL_KEY_SPORT] = { .type = NLA_U16, },
313         [NFTA_TUNNEL_KEY_DPORT] = { .type = NLA_U16, },
314         [NFTA_TUNNEL_KEY_OPTS]  = { .type = NLA_NESTED, },
315 };
316
317 static int nft_tunnel_obj_init(const struct nft_ctx *ctx,
318                                const struct nlattr * const tb[],
319                                struct nft_object *obj)
320 {
321         struct nft_tunnel_obj *priv = nft_obj_data(obj);
322         struct ip_tunnel_info info;
323         struct metadata_dst *md;
324         int err;
325
326         if (!tb[NFTA_TUNNEL_KEY_ID])
327                 return -EINVAL;
328
329         memset(&info, 0, sizeof(info));
330         info.mode               = IP_TUNNEL_INFO_TX;
331         info.key.tun_id         = key32_to_tunnel_id(nla_get_be32(tb[NFTA_TUNNEL_KEY_ID]));
332         info.key.tun_flags      = TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_NOCACHE;
333
334         if (tb[NFTA_TUNNEL_KEY_IP]) {
335                 err = nft_tunnel_obj_ip_init(ctx, tb[NFTA_TUNNEL_KEY_IP], &info);
336                 if (err < 0)
337                         return err;
338         } else if (tb[NFTA_TUNNEL_KEY_IP6]) {
339                 err = nft_tunnel_obj_ip6_init(ctx, tb[NFTA_TUNNEL_KEY_IP6], &info);
340                 if (err < 0)
341                         return err;
342         } else {
343                 return -EINVAL;
344         }
345
346         if (tb[NFTA_TUNNEL_KEY_SPORT]) {
347                 info.key.tp_src = nla_get_be16(tb[NFTA_TUNNEL_KEY_SPORT]);
348         }
349         if (tb[NFTA_TUNNEL_KEY_DPORT]) {
350                 info.key.tp_dst = nla_get_be16(tb[NFTA_TUNNEL_KEY_DPORT]);
351         }
352
353         if (tb[NFTA_TUNNEL_KEY_FLAGS]) {
354                 u32 tun_flags;
355
356                 tun_flags = ntohl(nla_get_be32(tb[NFTA_TUNNEL_KEY_FLAGS]));
357                 if (tun_flags & ~NFT_TUNNEL_F_MASK)
358                         return -EOPNOTSUPP;
359
360                 if (tun_flags & NFT_TUNNEL_F_ZERO_CSUM_TX)
361                         info.key.tun_flags &= ~TUNNEL_CSUM;
362                 if (tun_flags & NFT_TUNNEL_F_DONT_FRAGMENT)
363                         info.key.tun_flags |= TUNNEL_DONT_FRAGMENT;
364                 if (tun_flags & NFT_TUNNEL_F_SEQ_NUMBER)
365                         info.key.tun_flags |= TUNNEL_SEQ;
366         }
367         if (tb[NFTA_TUNNEL_KEY_TOS])
368                 info.key.tos = nla_get_u8(tb[NFTA_TUNNEL_KEY_TOS]);
369         if (tb[NFTA_TUNNEL_KEY_TTL])
370                 info.key.ttl = nla_get_u8(tb[NFTA_TUNNEL_KEY_TTL]);
371         else
372                 info.key.ttl = U8_MAX;
373
374         if (tb[NFTA_TUNNEL_KEY_OPTS]) {
375                 err = nft_tunnel_obj_opts_init(ctx, tb[NFTA_TUNNEL_KEY_OPTS],
376                                                &info, &priv->opts);
377                 if (err < 0)
378                         return err;
379         }
380
381         md = metadata_dst_alloc(priv->opts.len, METADATA_IP_TUNNEL, GFP_KERNEL);
382         if (!md)
383                 return -ENOMEM;
384
385         memcpy(&md->u.tun_info, &info, sizeof(info));
386         ip_tunnel_info_opts_set(&md->u.tun_info, &priv->opts.u, priv->opts.len,
387                                 priv->opts.flags);
388         priv->md = md;
389
390         return 0;
391 }
392
393 static inline void nft_tunnel_obj_eval(struct nft_object *obj,
394                                        struct nft_regs *regs,
395                                        const struct nft_pktinfo *pkt)
396 {
397         struct nft_tunnel_obj *priv = nft_obj_data(obj);
398         struct sk_buff *skb = pkt->skb;
399
400         skb_dst_drop(skb);
401         dst_hold((struct dst_entry *) priv->md);
402         skb_dst_set(skb, (struct dst_entry *) priv->md);
403 }
404
405 static int nft_tunnel_ip_dump(struct sk_buff *skb, struct ip_tunnel_info *info)
406 {
407         struct nlattr *nest;
408
409         if (info->mode & IP_TUNNEL_INFO_IPV6) {
410                 nest = nla_nest_start(skb, NFTA_TUNNEL_KEY_IP6);
411                 if (!nest)
412                         return -1;
413
414                 if (nla_put_in6_addr(skb, NFTA_TUNNEL_KEY_IP6_SRC, &info->key.u.ipv6.src) < 0 ||
415                     nla_put_in6_addr(skb, NFTA_TUNNEL_KEY_IP6_DST, &info->key.u.ipv6.dst) < 0 ||
416                     nla_put_be32(skb, NFTA_TUNNEL_KEY_IP6_FLOWLABEL, info->key.label))
417                         return -1;
418
419                 nla_nest_end(skb, nest);
420         } else {
421                 nest = nla_nest_start(skb, NFTA_TUNNEL_KEY_IP);
422                 if (!nest)
423                         return -1;
424
425                 if (nla_put_in_addr(skb, NFTA_TUNNEL_KEY_IP_SRC, info->key.u.ipv4.src) < 0 ||
426                     nla_put_in_addr(skb, NFTA_TUNNEL_KEY_IP_DST, info->key.u.ipv4.dst) < 0)
427                         return -1;
428
429                 nla_nest_end(skb, nest);
430         }
431
432         return 0;
433 }
434
435 static int nft_tunnel_opts_dump(struct sk_buff *skb,
436                                 struct nft_tunnel_obj *priv)
437 {
438         struct nft_tunnel_opts *opts = &priv->opts;
439         struct nlattr *nest;
440
441         nest = nla_nest_start(skb, NFTA_TUNNEL_KEY_OPTS);
442         if (!nest)
443                 return -1;
444
445         if (opts->flags & TUNNEL_VXLAN_OPT) {
446                 if (nla_put_be32(skb, NFTA_TUNNEL_KEY_VXLAN_GBP,
447                                  htonl(opts->u.vxlan.gbp)))
448                         return -1;
449         } else if (opts->flags & TUNNEL_ERSPAN_OPT) {
450                 switch (opts->u.erspan.version) {
451                 case ERSPAN_VERSION:
452                         if (nla_put_be32(skb, NFTA_TUNNEL_KEY_ERSPAN_V1_INDEX,
453                                          opts->u.erspan.u.index))
454                                 return -1;
455                         break;
456                 case ERSPAN_VERSION2:
457                         if (nla_put_u8(skb, NFTA_TUNNEL_KEY_ERSPAN_V2_HWID,
458                                        get_hwid(&opts->u.erspan.u.md2)) ||
459                             nla_put_u8(skb, NFTA_TUNNEL_KEY_ERSPAN_V2_DIR,
460                                        opts->u.erspan.u.md2.dir))
461                                 return -1;
462                         break;
463                 }
464         }
465         nla_nest_end(skb, nest);
466
467         return 0;
468 }
469
470 static int nft_tunnel_ports_dump(struct sk_buff *skb,
471                                  struct ip_tunnel_info *info)
472 {
473         if (nla_put_be16(skb, NFTA_TUNNEL_KEY_SPORT, info->key.tp_src) < 0 ||
474             nla_put_be16(skb, NFTA_TUNNEL_KEY_DPORT, info->key.tp_dst) < 0)
475                 return -1;
476
477         return 0;
478 }
479
480 static int nft_tunnel_flags_dump(struct sk_buff *skb,
481                                  struct ip_tunnel_info *info)
482 {
483         u32 flags = 0;
484
485         if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT)
486                 flags |= NFT_TUNNEL_F_DONT_FRAGMENT;
487         if (!(info->key.tun_flags & TUNNEL_CSUM))
488                 flags |= NFT_TUNNEL_F_ZERO_CSUM_TX;
489         if (info->key.tun_flags & TUNNEL_SEQ)
490                 flags |= NFT_TUNNEL_F_SEQ_NUMBER;
491
492         if (nla_put_be32(skb, NFTA_TUNNEL_KEY_FLAGS, htonl(flags)) < 0)
493                 return -1;
494
495         return 0;
496 }
497
498 static int nft_tunnel_obj_dump(struct sk_buff *skb,
499                                struct nft_object *obj, bool reset)
500 {
501         struct nft_tunnel_obj *priv = nft_obj_data(obj);
502         struct ip_tunnel_info *info = &priv->md->u.tun_info;
503
504         if (nla_put_be32(skb, NFTA_TUNNEL_KEY_ID,
505                          tunnel_id_to_key32(info->key.tun_id)) ||
506             nft_tunnel_ip_dump(skb, info) < 0 ||
507             nft_tunnel_ports_dump(skb, info) < 0 ||
508             nft_tunnel_flags_dump(skb, info) < 0 ||
509             nla_put_u8(skb, NFTA_TUNNEL_KEY_TOS, info->key.tos) ||
510             nla_put_u8(skb, NFTA_TUNNEL_KEY_TTL, info->key.ttl) ||
511             nft_tunnel_opts_dump(skb, priv) < 0)
512                 goto nla_put_failure;
513
514         return 0;
515
516 nla_put_failure:
517         return -1;
518 }
519
520 static void nft_tunnel_obj_destroy(const struct nft_ctx *ctx,
521                                    struct nft_object *obj)
522 {
523         struct nft_tunnel_obj *priv = nft_obj_data(obj);
524
525         metadata_dst_free(priv->md);
526 }
527
528 static struct nft_object_type nft_tunnel_obj_type;
529 static const struct nft_object_ops nft_tunnel_obj_ops = {
530         .type           = &nft_tunnel_obj_type,
531         .size           = sizeof(struct nft_tunnel_obj),
532         .eval           = nft_tunnel_obj_eval,
533         .init           = nft_tunnel_obj_init,
534         .destroy        = nft_tunnel_obj_destroy,
535         .dump           = nft_tunnel_obj_dump,
536 };
537
538 static struct nft_object_type nft_tunnel_obj_type __read_mostly = {
539         .type           = NFT_OBJECT_TUNNEL,
540         .ops            = &nft_tunnel_obj_ops,
541         .maxattr        = NFTA_TUNNEL_KEY_MAX,
542         .policy         = nft_tunnel_key_policy,
543         .owner          = THIS_MODULE,
544 };
545
546 static int __init nft_tunnel_module_init(void)
547 {
548         int err;
549
550         err = nft_register_expr(&nft_tunnel_type);
551         if (err < 0)
552                 return err;
553
554         err = nft_register_obj(&nft_tunnel_obj_type);
555         if (err < 0)
556                 nft_unregister_expr(&nft_tunnel_type);
557
558         return err;
559 }
560
561 static void __exit nft_tunnel_module_exit(void)
562 {
563         nft_unregister_obj(&nft_tunnel_obj_type);
564         nft_unregister_expr(&nft_tunnel_type);
565 }
566
567 module_init(nft_tunnel_module_init);
568 module_exit(nft_tunnel_module_exit);
569
570 MODULE_LICENSE("GPL");
571 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
572 MODULE_ALIAS_NFT_EXPR("tunnel");
573 MODULE_ALIAS_NFT_OBJ(NFT_OBJECT_TUNNEL);