1 // SPDX-License-Identifier: GPL-2.0
2 /* Bareudp: UDP tunnel encasulation for different Payload types like
4 * Copyright (c) 2019 Nokia, Inc.
5 * Authors: Martin Varghese, <martin.varghese@nokia.com>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/etherdevice.h>
13 #include <linux/hash.h>
14 #include <net/dst_metadata.h>
15 #include <net/gro_cells.h>
16 #include <net/rtnetlink.h>
17 #include <net/protocol.h>
18 #include <net/ip6_tunnel.h>
19 #include <net/ip_tunnels.h>
20 #include <net/udp_tunnel.h>
21 #include <net/bareudp.h>
23 #define BAREUDP_BASE_HLEN sizeof(struct udphdr)
24 #define BAREUDP_IPV4_HLEN (sizeof(struct iphdr) + \
25 sizeof(struct udphdr))
26 #define BAREUDP_IPV6_HLEN (sizeof(struct ipv6hdr) + \
27 sizeof(struct udphdr))
29 static bool log_ecn_error
= true;
30 module_param(log_ecn_error
, bool, 0644);
31 MODULE_PARM_DESC(log_ecn_error
, "Log packets received with corrupted ECN");
33 /* per-network namespace private data for this module */
35 static unsigned int bareudp_net_id
;
38 struct list_head bareudp_list
;
45 bool multi_proto_mode
;
48 /* Pseudo network device */
50 struct net
*net
; /* netns for packet i/o */
51 struct net_device
*dev
; /* netdev for bareudp tunnel */
55 bool multi_proto_mode
;
56 struct socket __rcu
*sock
;
57 struct list_head next
; /* bareudp node on namespace list */
58 struct gro_cells gro_cells
;
61 static int bareudp_udp_encap_recv(struct sock
*sk
, struct sk_buff
*skb
)
63 struct metadata_dst
*tun_dst
= NULL
;
64 IP_TUNNEL_DECLARE_FLAGS(key
) = { };
65 struct bareudp_dev
*bareudp
;
66 unsigned short family
;
73 bareudp
= rcu_dereference_sk_user_data(sk
);
77 if (skb
->protocol
== htons(ETH_P_IP
))
82 if (bareudp
->ethertype
== htons(ETH_P_IP
)) {
85 if (skb_copy_bits(skb
, BAREUDP_BASE_HLEN
, &ipversion
,
87 dev_core_stats_rx_dropped_inc(bareudp
->dev
);
93 proto
= htons(ETH_P_IP
);
94 } else if (ipversion
== 6 && bareudp
->multi_proto_mode
) {
95 proto
= htons(ETH_P_IPV6
);
97 dev_core_stats_rx_dropped_inc(bareudp
->dev
);
100 } else if (bareudp
->ethertype
== htons(ETH_P_MPLS_UC
)) {
101 struct iphdr
*tunnel_hdr
;
103 tunnel_hdr
= (struct iphdr
*)skb_network_header(skb
);
104 if (tunnel_hdr
->version
== 4) {
105 if (!ipv4_is_multicast(tunnel_hdr
->daddr
)) {
106 proto
= bareudp
->ethertype
;
107 } else if (bareudp
->multi_proto_mode
&&
108 ipv4_is_multicast(tunnel_hdr
->daddr
)) {
109 proto
= htons(ETH_P_MPLS_MC
);
111 dev_core_stats_rx_dropped_inc(bareudp
->dev
);
116 struct ipv6hdr
*tunnel_hdr_v6
;
118 tunnel_hdr_v6
= (struct ipv6hdr
*)skb_network_header(skb
);
120 ipv6_addr_type((struct in6_addr
*)&tunnel_hdr_v6
->daddr
);
121 if (!(addr_type
& IPV6_ADDR_MULTICAST
)) {
122 proto
= bareudp
->ethertype
;
123 } else if (bareudp
->multi_proto_mode
&&
124 (addr_type
& IPV6_ADDR_MULTICAST
)) {
125 proto
= htons(ETH_P_MPLS_MC
);
127 dev_core_stats_rx_dropped_inc(bareudp
->dev
);
132 proto
= bareudp
->ethertype
;
135 if (iptunnel_pull_header(skb
, BAREUDP_BASE_HLEN
,
137 !net_eq(bareudp
->net
,
138 dev_net(bareudp
->dev
)))) {
139 dev_core_stats_rx_dropped_inc(bareudp
->dev
);
143 __set_bit(IP_TUNNEL_KEY_BIT
, key
);
145 tun_dst
= udp_tun_rx_dst(skb
, family
, key
, 0, 0);
147 dev_core_stats_rx_dropped_inc(bareudp
->dev
);
150 skb_dst_set(skb
, &tun_dst
->dst
);
151 skb
->dev
= bareudp
->dev
;
152 skb_reset_mac_header(skb
);
154 /* Save offset of outer header relative to skb->head,
155 * because we are going to reset the network header to the inner header
156 * and might change skb->head.
158 nh
= skb_network_header(skb
) - skb
->head
;
160 skb_reset_network_header(skb
);
162 if (!pskb_inet_may_pull(skb
)) {
163 DEV_STATS_INC(bareudp
->dev
, rx_length_errors
);
164 DEV_STATS_INC(bareudp
->dev
, rx_errors
);
168 /* Get the outer header. */
169 oiph
= skb
->head
+ nh
;
171 if (!ipv6_mod_enabled() || family
== AF_INET
)
172 err
= IP_ECN_decapsulate(oiph
, skb
);
174 err
= IP6_ECN_decapsulate(oiph
, skb
);
178 if (!ipv6_mod_enabled() || family
== AF_INET
)
179 net_info_ratelimited("non-ECT from %pI4 "
181 &((struct iphdr
*)oiph
)->saddr
,
182 ((struct iphdr
*)oiph
)->tos
);
184 net_info_ratelimited("non-ECT from %pI6\n",
185 &((struct ipv6hdr
*)oiph
)->saddr
);
188 DEV_STATS_INC(bareudp
->dev
, rx_frame_errors
);
189 DEV_STATS_INC(bareudp
->dev
, rx_errors
);
195 err
= gro_cells_receive(&bareudp
->gro_cells
, skb
);
196 if (likely(err
== NET_RX_SUCCESS
))
197 dev_sw_netstats_rx_add(bareudp
->dev
, len
);
201 /* Consume bad packet */
207 static int bareudp_err_lookup(struct sock
*sk
, struct sk_buff
*skb
)
212 static int bareudp_init(struct net_device
*dev
)
214 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
217 err
= gro_cells_init(&bareudp
->gro_cells
, dev
);
224 static void bareudp_uninit(struct net_device
*dev
)
226 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
228 gro_cells_destroy(&bareudp
->gro_cells
);
231 static struct socket
*bareudp_create_sock(struct net
*net
, __be16 port
)
233 struct udp_port_cfg udp_conf
;
237 memset(&udp_conf
, 0, sizeof(udp_conf
));
239 if (ipv6_mod_enabled())
240 udp_conf
.family
= AF_INET6
;
242 udp_conf
.family
= AF_INET
;
244 udp_conf
.local_udp_port
= port
;
245 /* Open UDP socket */
246 err
= udp_sock_create(net
, &udp_conf
, &sock
);
250 udp_allow_gso(sock
->sk
);
254 /* Create new listen socket if needed */
255 static int bareudp_socket_create(struct bareudp_dev
*bareudp
, __be16 port
)
257 struct udp_tunnel_sock_cfg tunnel_cfg
;
260 sock
= bareudp_create_sock(bareudp
->net
, port
);
262 return PTR_ERR(sock
);
264 /* Mark socket as an encapsulation socket */
265 memset(&tunnel_cfg
, 0, sizeof(tunnel_cfg
));
266 tunnel_cfg
.sk_user_data
= bareudp
;
267 tunnel_cfg
.encap_type
= 1;
268 tunnel_cfg
.encap_rcv
= bareudp_udp_encap_recv
;
269 tunnel_cfg
.encap_err_lookup
= bareudp_err_lookup
;
270 tunnel_cfg
.encap_destroy
= NULL
;
271 setup_udp_tunnel_sock(bareudp
->net
, sock
, &tunnel_cfg
);
273 rcu_assign_pointer(bareudp
->sock
, sock
);
277 static int bareudp_open(struct net_device
*dev
)
279 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
282 ret
= bareudp_socket_create(bareudp
, bareudp
->port
);
286 static void bareudp_sock_release(struct bareudp_dev
*bareudp
)
290 sock
= bareudp
->sock
;
291 rcu_assign_pointer(bareudp
->sock
, NULL
);
293 udp_tunnel_sock_release(sock
);
296 static int bareudp_stop(struct net_device
*dev
)
298 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
300 bareudp_sock_release(bareudp
);
304 static int bareudp_xmit_skb(struct sk_buff
*skb
, struct net_device
*dev
,
305 struct bareudp_dev
*bareudp
,
306 const struct ip_tunnel_info
*info
)
308 bool udp_sum
= test_bit(IP_TUNNEL_CSUM_BIT
, info
->key
.tun_flags
);
309 bool xnet
= !net_eq(bareudp
->net
, dev_net(bareudp
->dev
));
310 bool use_cache
= ip_tunnel_dst_cache_usable(skb
, info
);
311 struct socket
*sock
= rcu_dereference(bareudp
->sock
);
312 const struct ip_tunnel_key
*key
= &info
->key
;
320 if (skb_vlan_inet_prepare(skb
, skb
->protocol
!= htons(ETH_P_TEB
)))
326 sport
= udp_flow_src_port(bareudp
->net
, skb
,
327 bareudp
->sport_min
, USHRT_MAX
,
329 rt
= udp_tunnel_dst_lookup(skb
, dev
, bareudp
->net
, 0, &saddr
, &info
->key
,
330 sport
, bareudp
->port
, key
->tos
,
332 (struct dst_cache
*)&info
->dst_cache
: NULL
);
337 skb_tunnel_check_pmtu(skb
, &rt
->dst
,
338 BAREUDP_IPV4_HLEN
+ info
->options_len
, false);
340 tos
= ip_tunnel_ecn_encap(key
->tos
, ip_hdr(skb
), skb
);
342 df
= test_bit(IP_TUNNEL_DONT_FRAGMENT_BIT
, key
->tun_flags
) ?
344 skb_scrub_packet(skb
, xnet
);
347 if (!skb_pull(skb
, skb_network_offset(skb
)))
350 min_headroom
= LL_RESERVED_SPACE(rt
->dst
.dev
) + rt
->dst
.header_len
+
351 BAREUDP_BASE_HLEN
+ info
->options_len
+ sizeof(struct iphdr
);
353 err
= skb_cow_head(skb
, min_headroom
);
357 err
= udp_tunnel_handle_offloads(skb
, udp_sum
);
361 skb_set_inner_protocol(skb
, bareudp
->ethertype
);
362 udp_tunnel_xmit_skb(rt
, sock
->sk
, skb
, saddr
, info
->key
.u
.ipv4
.dst
,
363 tos
, ttl
, df
, sport
, bareudp
->port
,
364 !net_eq(bareudp
->net
, dev_net(bareudp
->dev
)),
365 !test_bit(IP_TUNNEL_CSUM_BIT
,
366 info
->key
.tun_flags
));
370 dst_release(&rt
->dst
);
374 static int bareudp6_xmit_skb(struct sk_buff
*skb
, struct net_device
*dev
,
375 struct bareudp_dev
*bareudp
,
376 const struct ip_tunnel_info
*info
)
378 bool udp_sum
= test_bit(IP_TUNNEL_CSUM_BIT
, info
->key
.tun_flags
);
379 bool xnet
= !net_eq(bareudp
->net
, dev_net(bareudp
->dev
));
380 bool use_cache
= ip_tunnel_dst_cache_usable(skb
, info
);
381 struct socket
*sock
= rcu_dereference(bareudp
->sock
);
382 const struct ip_tunnel_key
*key
= &info
->key
;
383 struct dst_entry
*dst
= NULL
;
384 struct in6_addr saddr
, daddr
;
390 if (skb_vlan_inet_prepare(skb
, skb
->protocol
!= htons(ETH_P_TEB
)))
396 sport
= udp_flow_src_port(bareudp
->net
, skb
,
397 bareudp
->sport_min
, USHRT_MAX
,
399 dst
= udp_tunnel6_dst_lookup(skb
, dev
, bareudp
->net
, sock
, 0, &saddr
,
400 key
, sport
, bareudp
->port
, key
->tos
,
402 (struct dst_cache
*) &info
->dst_cache
: NULL
);
406 skb_tunnel_check_pmtu(skb
, dst
, BAREUDP_IPV6_HLEN
+ info
->options_len
,
409 prio
= ip_tunnel_ecn_encap(key
->tos
, ip_hdr(skb
), skb
);
412 skb_scrub_packet(skb
, xnet
);
415 if (!skb_pull(skb
, skb_network_offset(skb
)))
418 min_headroom
= LL_RESERVED_SPACE(dst
->dev
) + dst
->header_len
+
419 BAREUDP_BASE_HLEN
+ info
->options_len
+ sizeof(struct ipv6hdr
);
421 err
= skb_cow_head(skb
, min_headroom
);
425 err
= udp_tunnel_handle_offloads(skb
, udp_sum
);
429 daddr
= info
->key
.u
.ipv6
.dst
;
430 udp_tunnel6_xmit_skb(dst
, sock
->sk
, skb
, dev
,
431 &saddr
, &daddr
, prio
, ttl
,
432 info
->key
.label
, sport
, bareudp
->port
,
433 !test_bit(IP_TUNNEL_CSUM_BIT
,
434 info
->key
.tun_flags
));
442 static bool bareudp_proto_valid(struct bareudp_dev
*bareudp
, __be16 proto
)
444 if (bareudp
->ethertype
== proto
)
447 if (!bareudp
->multi_proto_mode
)
450 if (bareudp
->ethertype
== htons(ETH_P_MPLS_UC
) &&
451 proto
== htons(ETH_P_MPLS_MC
))
454 if (bareudp
->ethertype
== htons(ETH_P_IP
) &&
455 proto
== htons(ETH_P_IPV6
))
461 static netdev_tx_t
bareudp_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
463 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
464 struct ip_tunnel_info
*info
= NULL
;
467 if (!bareudp_proto_valid(bareudp
, skb
->protocol
)) {
472 info
= skb_tunnel_info(skb
);
473 if (unlikely(!info
|| !(info
->mode
& IP_TUNNEL_INFO_TX
))) {
479 if (ipv6_mod_enabled() && info
->mode
& IP_TUNNEL_INFO_IPV6
)
480 err
= bareudp6_xmit_skb(skb
, dev
, bareudp
, info
);
482 err
= bareudp_xmit_skb(skb
, dev
, bareudp
, info
);
492 DEV_STATS_INC(dev
, collisions
);
493 else if (err
== -ENETUNREACH
)
494 DEV_STATS_INC(dev
, tx_carrier_errors
);
496 DEV_STATS_INC(dev
, tx_errors
);
500 static int bareudp_fill_metadata_dst(struct net_device
*dev
,
503 struct ip_tunnel_info
*info
= skb_tunnel_info(skb
);
504 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
508 use_cache
= ip_tunnel_dst_cache_usable(skb
, info
);
509 sport
= udp_flow_src_port(bareudp
->net
, skb
,
510 bareudp
->sport_min
, USHRT_MAX
,
513 if (!ipv6_mod_enabled() || ip_tunnel_info_af(info
) == AF_INET
) {
517 rt
= udp_tunnel_dst_lookup(skb
, dev
, bareudp
->net
, 0, &saddr
,
518 &info
->key
, sport
, bareudp
->port
,
520 use_cache
? &info
->dst_cache
: NULL
);
525 info
->key
.u
.ipv4
.src
= saddr
;
526 } else if (ip_tunnel_info_af(info
) == AF_INET6
) {
527 struct dst_entry
*dst
;
528 struct in6_addr saddr
;
529 struct socket
*sock
= rcu_dereference(bareudp
->sock
);
531 dst
= udp_tunnel6_dst_lookup(skb
, dev
, bareudp
->net
, sock
,
532 0, &saddr
, &info
->key
,
533 sport
, bareudp
->port
, info
->key
.tos
,
534 use_cache
? &info
->dst_cache
: NULL
);
539 info
->key
.u
.ipv6
.src
= saddr
;
544 info
->key
.tp_src
= sport
;
545 info
->key
.tp_dst
= bareudp
->port
;
549 static const struct net_device_ops bareudp_netdev_ops
= {
550 .ndo_init
= bareudp_init
,
551 .ndo_uninit
= bareudp_uninit
,
552 .ndo_open
= bareudp_open
,
553 .ndo_stop
= bareudp_stop
,
554 .ndo_start_xmit
= bareudp_xmit
,
555 .ndo_fill_metadata_dst
= bareudp_fill_metadata_dst
,
558 static const struct nla_policy bareudp_policy
[IFLA_BAREUDP_MAX
+ 1] = {
559 [IFLA_BAREUDP_PORT
] = { .type
= NLA_U16
},
560 [IFLA_BAREUDP_ETHERTYPE
] = { .type
= NLA_U16
},
561 [IFLA_BAREUDP_SRCPORT_MIN
] = { .type
= NLA_U16
},
562 [IFLA_BAREUDP_MULTIPROTO_MODE
] = { .type
= NLA_FLAG
},
565 /* Info for udev, that this is a virtual tunnel endpoint */
566 static const struct device_type bareudp_type
= {
570 /* Initialize the device structure. */
571 static void bareudp_setup(struct net_device
*dev
)
573 dev
->netdev_ops
= &bareudp_netdev_ops
;
574 dev
->needs_free_netdev
= true;
575 SET_NETDEV_DEVTYPE(dev
, &bareudp_type
);
576 dev
->features
|= NETIF_F_SG
| NETIF_F_HW_CSUM
| NETIF_F_FRAGLIST
;
577 dev
->features
|= NETIF_F_RXCSUM
;
578 dev
->features
|= NETIF_F_GSO_SOFTWARE
;
579 dev
->hw_features
|= NETIF_F_SG
| NETIF_F_HW_CSUM
| NETIF_F_FRAGLIST
;
580 dev
->hw_features
|= NETIF_F_RXCSUM
;
581 dev
->hw_features
|= NETIF_F_GSO_SOFTWARE
;
582 dev
->hard_header_len
= 0;
584 dev
->mtu
= ETH_DATA_LEN
;
585 dev
->min_mtu
= IPV4_MIN_MTU
;
586 dev
->max_mtu
= IP_MAX_MTU
- BAREUDP_BASE_HLEN
;
587 dev
->type
= ARPHRD_NONE
;
589 dev
->priv_flags
|= IFF_NO_QUEUE
;
591 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
| IFF_MULTICAST
;
592 dev
->pcpu_stat_type
= NETDEV_PCPU_STAT_TSTATS
;
595 static int bareudp_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
596 struct netlink_ext_ack
*extack
)
599 NL_SET_ERR_MSG(extack
,
600 "Not enough attributes provided to perform the operation");
606 static int bareudp2info(struct nlattr
*data
[], struct bareudp_conf
*conf
,
607 struct netlink_ext_ack
*extack
)
609 memset(conf
, 0, sizeof(*conf
));
611 if (!data
[IFLA_BAREUDP_PORT
]) {
612 NL_SET_ERR_MSG(extack
, "port not specified");
615 if (!data
[IFLA_BAREUDP_ETHERTYPE
]) {
616 NL_SET_ERR_MSG(extack
, "ethertype not specified");
620 conf
->port
= nla_get_u16(data
[IFLA_BAREUDP_PORT
]);
621 conf
->ethertype
= nla_get_u16(data
[IFLA_BAREUDP_ETHERTYPE
]);
623 if (data
[IFLA_BAREUDP_SRCPORT_MIN
])
624 conf
->sport_min
= nla_get_u16(data
[IFLA_BAREUDP_SRCPORT_MIN
]);
626 if (data
[IFLA_BAREUDP_MULTIPROTO_MODE
])
627 conf
->multi_proto_mode
= true;
632 static struct bareudp_dev
*bareudp_find_dev(struct bareudp_net
*bn
,
633 const struct bareudp_conf
*conf
)
635 struct bareudp_dev
*bareudp
, *t
= NULL
;
637 list_for_each_entry(bareudp
, &bn
->bareudp_list
, next
) {
638 if (conf
->port
== bareudp
->port
)
644 static int bareudp_configure(struct net
*net
, struct net_device
*dev
,
645 struct bareudp_conf
*conf
,
646 struct netlink_ext_ack
*extack
)
648 struct bareudp_net
*bn
= net_generic(net
, bareudp_net_id
);
649 struct bareudp_dev
*t
, *bareudp
= netdev_priv(dev
);
654 t
= bareudp_find_dev(bn
, conf
);
656 NL_SET_ERR_MSG(extack
, "Another bareudp device using the same port already exists");
660 if (conf
->multi_proto_mode
&&
661 (conf
->ethertype
!= htons(ETH_P_MPLS_UC
) &&
662 conf
->ethertype
!= htons(ETH_P_IP
))) {
663 NL_SET_ERR_MSG(extack
, "Cannot set multiproto mode for this ethertype (only IPv4 and unicast MPLS are supported)");
667 bareudp
->port
= conf
->port
;
668 bareudp
->ethertype
= conf
->ethertype
;
669 bareudp
->sport_min
= conf
->sport_min
;
670 bareudp
->multi_proto_mode
= conf
->multi_proto_mode
;
672 err
= register_netdevice(dev
);
676 list_add(&bareudp
->next
, &bn
->bareudp_list
);
680 static int bareudp_link_config(struct net_device
*dev
,
686 err
= dev_set_mtu(dev
, nla_get_u32(tb
[IFLA_MTU
]));
693 static void bareudp_dellink(struct net_device
*dev
, struct list_head
*head
)
695 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
697 list_del(&bareudp
->next
);
698 unregister_netdevice_queue(dev
, head
);
701 static int bareudp_newlink(struct net
*net
, struct net_device
*dev
,
702 struct nlattr
*tb
[], struct nlattr
*data
[],
703 struct netlink_ext_ack
*extack
)
705 struct bareudp_conf conf
;
708 err
= bareudp2info(data
, &conf
, extack
);
712 err
= bareudp_configure(net
, dev
, &conf
, extack
);
716 err
= bareudp_link_config(dev
, tb
);
723 bareudp_dellink(dev
, NULL
);
727 static size_t bareudp_get_size(const struct net_device
*dev
)
729 return nla_total_size(sizeof(__be16
)) + /* IFLA_BAREUDP_PORT */
730 nla_total_size(sizeof(__be16
)) + /* IFLA_BAREUDP_ETHERTYPE */
731 nla_total_size(sizeof(__u16
)) + /* IFLA_BAREUDP_SRCPORT_MIN */
732 nla_total_size(0) + /* IFLA_BAREUDP_MULTIPROTO_MODE */
736 static int bareudp_fill_info(struct sk_buff
*skb
, const struct net_device
*dev
)
738 struct bareudp_dev
*bareudp
= netdev_priv(dev
);
740 if (nla_put_be16(skb
, IFLA_BAREUDP_PORT
, bareudp
->port
))
741 goto nla_put_failure
;
742 if (nla_put_be16(skb
, IFLA_BAREUDP_ETHERTYPE
, bareudp
->ethertype
))
743 goto nla_put_failure
;
744 if (nla_put_u16(skb
, IFLA_BAREUDP_SRCPORT_MIN
, bareudp
->sport_min
))
745 goto nla_put_failure
;
746 if (bareudp
->multi_proto_mode
&&
747 nla_put_flag(skb
, IFLA_BAREUDP_MULTIPROTO_MODE
))
748 goto nla_put_failure
;
756 static struct rtnl_link_ops bareudp_link_ops __read_mostly
= {
758 .maxtype
= IFLA_BAREUDP_MAX
,
759 .policy
= bareudp_policy
,
760 .priv_size
= sizeof(struct bareudp_dev
),
761 .setup
= bareudp_setup
,
762 .validate
= bareudp_validate
,
763 .newlink
= bareudp_newlink
,
764 .dellink
= bareudp_dellink
,
765 .get_size
= bareudp_get_size
,
766 .fill_info
= bareudp_fill_info
,
769 static __net_init
int bareudp_init_net(struct net
*net
)
771 struct bareudp_net
*bn
= net_generic(net
, bareudp_net_id
);
773 INIT_LIST_HEAD(&bn
->bareudp_list
);
777 static void bareudp_destroy_tunnels(struct net
*net
, struct list_head
*head
)
779 struct bareudp_net
*bn
= net_generic(net
, bareudp_net_id
);
780 struct bareudp_dev
*bareudp
, *next
;
782 list_for_each_entry_safe(bareudp
, next
, &bn
->bareudp_list
, next
)
783 unregister_netdevice_queue(bareudp
->dev
, head
);
786 static void __net_exit
bareudp_exit_batch_rtnl(struct list_head
*net_list
,
787 struct list_head
*dev_kill_list
)
791 list_for_each_entry(net
, net_list
, exit_list
)
792 bareudp_destroy_tunnels(net
, dev_kill_list
);
795 static struct pernet_operations bareudp_net_ops
= {
796 .init
= bareudp_init_net
,
797 .exit_batch_rtnl
= bareudp_exit_batch_rtnl
,
798 .id
= &bareudp_net_id
,
799 .size
= sizeof(struct bareudp_net
),
802 static int __init
bareudp_init_module(void)
806 rc
= register_pernet_subsys(&bareudp_net_ops
);
810 rc
= rtnl_link_register(&bareudp_link_ops
);
816 unregister_pernet_subsys(&bareudp_net_ops
);
820 late_initcall(bareudp_init_module
);
822 static void __exit
bareudp_cleanup_module(void)
824 rtnl_link_unregister(&bareudp_link_ops
);
825 unregister_pernet_subsys(&bareudp_net_ops
);
827 module_exit(bareudp_cleanup_module
);
829 MODULE_ALIAS_RTNL_LINK("bareudp");
830 MODULE_LICENSE("GPL");
831 MODULE_AUTHOR("Martin Varghese <martin.varghese@nokia.com>");
832 MODULE_DESCRIPTION("Interface driver for UDP encapsulated traffic");