James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * L2TPv3 ethernet pseudowire driver |
| 3 | * |
| 4 | * Copyright (c) 2008,2009,2010 Katalix Systems Ltd |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Joe Perches | a4ca44f | 2012-05-16 09:55:56 +0000 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/skbuff.h> |
| 16 | #include <linux/socket.h> |
| 17 | #include <linux/hash.h> |
| 18 | #include <linux/l2tp.h> |
| 19 | #include <linux/in.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/spinlock.h> |
| 22 | #include <net/sock.h> |
| 23 | #include <net/ip.h> |
| 24 | #include <net/icmp.h> |
| 25 | #include <net/udp.h> |
| 26 | #include <net/inet_common.h> |
| 27 | #include <net/inet_hashtables.h> |
| 28 | #include <net/tcp_states.h> |
| 29 | #include <net/protocol.h> |
| 30 | #include <net/xfrm.h> |
| 31 | #include <net/net_namespace.h> |
| 32 | #include <net/netns/generic.h> |
R. Parameswaran | b784e7e | 2017-04-05 17:00:07 -0700 | [diff] [blame] | 33 | #include <linux/ip.h> |
| 34 | #include <linux/ipv6.h> |
| 35 | #include <linux/udp.h> |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 36 | |
| 37 | #include "l2tp_core.h" |
| 38 | |
| 39 | /* Default device name. May be overridden by name specified by user */ |
| 40 | #define L2TP_ETH_DEV_NAME "l2tpeth%d" |
| 41 | |
| 42 | /* via netdev_priv() */ |
| 43 | struct l2tp_eth { |
| 44 | struct net_device *dev; |
| 45 | struct sock *tunnel_sock; |
| 46 | struct l2tp_session *session; |
| 47 | struct list_head list; |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 48 | atomic_long_t tx_bytes; |
| 49 | atomic_long_t tx_packets; |
Eric Dumazet | b8c8430 | 2012-06-28 20:15:13 +0000 | [diff] [blame] | 50 | atomic_long_t tx_dropped; |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 51 | atomic_long_t rx_bytes; |
| 52 | atomic_long_t rx_packets; |
| 53 | atomic_long_t rx_errors; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /* via l2tp_session_priv() */ |
| 57 | struct l2tp_eth_sess { |
| 58 | struct net_device *dev; |
| 59 | }; |
| 60 | |
| 61 | /* per-net private data for this module */ |
| 62 | static unsigned int l2tp_eth_net_id; |
| 63 | struct l2tp_eth_net { |
| 64 | struct list_head l2tp_eth_dev_list; |
| 65 | spinlock_t l2tp_eth_lock; |
| 66 | }; |
| 67 | |
| 68 | static inline struct l2tp_eth_net *l2tp_eth_pernet(struct net *net) |
| 69 | { |
| 70 | return net_generic(net, l2tp_eth_net_id); |
| 71 | } |
| 72 | |
| 73 | static int l2tp_eth_dev_init(struct net_device *dev) |
| 74 | { |
| 75 | struct l2tp_eth *priv = netdev_priv(dev); |
| 76 | |
| 77 | priv->dev = dev; |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 78 | eth_hw_addr_random(dev); |
Joe Perches | 1cea7e2 | 2015-03-02 19:54:59 -0800 | [diff] [blame] | 79 | eth_broadcast_addr(dev->broadcast); |
Eric Dumazet | d3fff6c | 2016-06-09 07:45:12 -0700 | [diff] [blame] | 80 | netdev_lockdep_set_classes(dev); |
Eric Dumazet | f9eb8ae | 2016-06-06 09:37:15 -0700 | [diff] [blame] | 81 | |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static void l2tp_eth_dev_uninit(struct net_device *dev) |
| 86 | { |
| 87 | struct l2tp_eth *priv = netdev_priv(dev); |
| 88 | struct l2tp_eth_net *pn = l2tp_eth_pernet(dev_net(dev)); |
| 89 | |
| 90 | spin_lock(&pn->l2tp_eth_lock); |
| 91 | list_del_init(&priv->list); |
| 92 | spin_unlock(&pn->l2tp_eth_lock); |
| 93 | dev_put(dev); |
| 94 | } |
| 95 | |
| 96 | static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev) |
| 97 | { |
| 98 | struct l2tp_eth *priv = netdev_priv(dev); |
| 99 | struct l2tp_session *session = priv->session; |
Eric Dumazet | b8c8430 | 2012-06-28 20:15:13 +0000 | [diff] [blame] | 100 | unsigned int len = skb->len; |
| 101 | int ret = l2tp_xmit_skb(session, skb, session->hdr_len); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 102 | |
WANG Cong | a4cd027 | 2016-11-21 23:24:43 -0800 | [diff] [blame] | 103 | if (likely(ret == NET_XMIT_SUCCESS)) { |
Eric Dumazet | b8c8430 | 2012-06-28 20:15:13 +0000 | [diff] [blame] | 104 | atomic_long_add(len, &priv->tx_bytes); |
| 105 | atomic_long_inc(&priv->tx_packets); |
| 106 | } else { |
| 107 | atomic_long_inc(&priv->tx_dropped); |
| 108 | } |
Eric Dumazet | aa214de0 | 2012-06-25 00:45:14 +0000 | [diff] [blame] | 109 | return NETDEV_TX_OK; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 110 | } |
| 111 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 112 | static void l2tp_eth_get_stats64(struct net_device *dev, |
| 113 | struct rtnl_link_stats64 *stats) |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 114 | { |
| 115 | struct l2tp_eth *priv = netdev_priv(dev); |
| 116 | |
| 117 | stats->tx_bytes = atomic_long_read(&priv->tx_bytes); |
| 118 | stats->tx_packets = atomic_long_read(&priv->tx_packets); |
Eric Dumazet | b8c8430 | 2012-06-28 20:15:13 +0000 | [diff] [blame] | 119 | stats->tx_dropped = atomic_long_read(&priv->tx_dropped); |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 120 | stats->rx_bytes = atomic_long_read(&priv->rx_bytes); |
| 121 | stats->rx_packets = atomic_long_read(&priv->rx_packets); |
| 122 | stats->rx_errors = atomic_long_read(&priv->rx_errors); |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Julia Lawall | eb94737 | 2016-09-15 22:23:26 +0200 | [diff] [blame] | 125 | static const struct net_device_ops l2tp_eth_netdev_ops = { |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 126 | .ndo_init = l2tp_eth_dev_init, |
| 127 | .ndo_uninit = l2tp_eth_dev_uninit, |
| 128 | .ndo_start_xmit = l2tp_eth_dev_xmit, |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 129 | .ndo_get_stats64 = l2tp_eth_get_stats64, |
Alexander Couzens | fe15912 | 2014-11-19 13:24:39 +0100 | [diff] [blame] | 130 | .ndo_set_mac_address = eth_mac_addr, |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | static void l2tp_eth_dev_setup(struct net_device *dev) |
| 134 | { |
| 135 | ether_setup(dev); |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 136 | dev->priv_flags &= ~IFF_TX_SKB_SHARING; |
| 137 | dev->features |= NETIF_F_LLTX; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 138 | dev->netdev_ops = &l2tp_eth_netdev_ops; |
| 139 | dev->destructor = free_netdev; |
| 140 | } |
| 141 | |
| 142 | static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len) |
| 143 | { |
| 144 | struct l2tp_eth_sess *spriv = l2tp_session_priv(session); |
| 145 | struct net_device *dev = spriv->dev; |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 146 | struct l2tp_eth *priv = netdev_priv(dev); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 147 | |
| 148 | if (session->debug & L2TP_MSG_DATA) { |
| 149 | unsigned int length; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 150 | |
| 151 | length = min(32u, skb->len); |
| 152 | if (!pskb_may_pull(skb, length)) |
| 153 | goto error; |
| 154 | |
Joe Perches | a4ca44f | 2012-05-16 09:55:56 +0000 | [diff] [blame] | 155 | pr_debug("%s: eth recv\n", session->name); |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 156 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, skb->data, length); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Eric Dumazet | c0cc88a | 2012-09-04 15:54:55 -0400 | [diff] [blame] | 159 | if (!pskb_may_pull(skb, ETH_HLEN)) |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 160 | goto error; |
| 161 | |
| 162 | secpath_reset(skb); |
| 163 | |
| 164 | /* checksums verified by L2TP */ |
| 165 | skb->ip_summed = CHECKSUM_NONE; |
| 166 | |
| 167 | skb_dst_drop(skb); |
| 168 | nf_reset(skb); |
| 169 | |
| 170 | if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) { |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 171 | atomic_long_inc(&priv->rx_packets); |
| 172 | atomic_long_add(data_len, &priv->rx_bytes); |
| 173 | } else { |
| 174 | atomic_long_inc(&priv->rx_errors); |
| 175 | } |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 176 | return; |
| 177 | |
| 178 | error: |
Eric Dumazet | a2842a1 | 2012-06-25 05:35:45 +0000 | [diff] [blame] | 179 | atomic_long_inc(&priv->rx_errors); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 180 | kfree_skb(skb); |
| 181 | } |
| 182 | |
| 183 | static void l2tp_eth_delete(struct l2tp_session *session) |
| 184 | { |
| 185 | struct l2tp_eth_sess *spriv; |
| 186 | struct net_device *dev; |
| 187 | |
| 188 | if (session) { |
| 189 | spriv = l2tp_session_priv(session); |
| 190 | dev = spriv->dev; |
| 191 | if (dev) { |
| 192 | unregister_netdev(dev); |
| 193 | spriv->dev = NULL; |
Eric Dumazet | a06998b | 2012-06-07 00:07:20 +0000 | [diff] [blame] | 194 | module_put(THIS_MODULE); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
Javier Martinez Canillas | 9dd7994 | 2016-09-09 08:43:17 -0400 | [diff] [blame] | 199 | #if IS_ENABLED(CONFIG_L2TP_DEBUGFS) |
James Chapman | 0ad6614 | 2010-04-02 06:19:33 +0000 | [diff] [blame] | 200 | static void l2tp_eth_show(struct seq_file *m, void *arg) |
| 201 | { |
| 202 | struct l2tp_session *session = arg; |
| 203 | struct l2tp_eth_sess *spriv = l2tp_session_priv(session); |
| 204 | struct net_device *dev = spriv->dev; |
| 205 | |
| 206 | seq_printf(m, " interface %s\n", dev->name); |
| 207 | } |
| 208 | #endif |
| 209 | |
R. Parameswaran | b784e7e | 2017-04-05 17:00:07 -0700 | [diff] [blame] | 210 | static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel, |
| 211 | struct l2tp_session *session, |
| 212 | struct net_device *dev) |
| 213 | { |
| 214 | unsigned int overhead = 0; |
| 215 | struct dst_entry *dst; |
| 216 | u32 l3_overhead = 0; |
| 217 | |
| 218 | /* if the encap is UDP, account for UDP header size */ |
| 219 | if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { |
| 220 | overhead += sizeof(struct udphdr); |
| 221 | dev->needed_headroom += sizeof(struct udphdr); |
| 222 | } |
| 223 | if (session->mtu != 0) { |
| 224 | dev->mtu = session->mtu; |
| 225 | dev->needed_headroom += session->hdr_len; |
| 226 | return; |
| 227 | } |
R. Parameswaran | 57240d0 | 2017-04-12 18:31:04 -0700 | [diff] [blame] | 228 | lock_sock(tunnel->sock); |
R. Parameswaran | b784e7e | 2017-04-05 17:00:07 -0700 | [diff] [blame] | 229 | l3_overhead = kernel_sock_ip_overhead(tunnel->sock); |
R. Parameswaran | 57240d0 | 2017-04-12 18:31:04 -0700 | [diff] [blame] | 230 | release_sock(tunnel->sock); |
R. Parameswaran | b784e7e | 2017-04-05 17:00:07 -0700 | [diff] [blame] | 231 | if (l3_overhead == 0) { |
| 232 | /* L3 Overhead couldn't be identified, this could be |
| 233 | * because tunnel->sock was NULL or the socket's |
| 234 | * address family was not IPv4 or IPv6, |
| 235 | * dev mtu stays at 1500. |
| 236 | */ |
| 237 | return; |
| 238 | } |
| 239 | /* Adjust MTU, factor overhead - underlay L3, overlay L2 hdr |
| 240 | * UDP overhead, if any, was already factored in above. |
| 241 | */ |
| 242 | overhead += session->hdr_len + ETH_HLEN + l3_overhead; |
| 243 | |
| 244 | /* If PMTU discovery was enabled, use discovered MTU on L2TP device */ |
| 245 | dst = sk_dst_get(tunnel->sock); |
| 246 | if (dst) { |
| 247 | /* dst_mtu will use PMTU if found, else fallback to intf MTU */ |
| 248 | u32 pmtu = dst_mtu(dst); |
| 249 | |
| 250 | if (pmtu != 0) |
| 251 | dev->mtu = pmtu; |
| 252 | dst_release(dst); |
| 253 | } |
| 254 | session->mtu = dev->mtu - overhead; |
| 255 | dev->mtu = session->mtu; |
| 256 | dev->needed_headroom += session->hdr_len; |
| 257 | } |
| 258 | |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 259 | static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) |
| 260 | { |
Guillaume Nault | c39855f | 2017-04-24 14:16:06 +0200 | [diff] [blame^] | 261 | unsigned char name_assign_type; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 262 | struct net_device *dev; |
| 263 | char name[IFNAMSIZ]; |
| 264 | struct l2tp_tunnel *tunnel; |
| 265 | struct l2tp_session *session; |
| 266 | struct l2tp_eth *priv; |
| 267 | struct l2tp_eth_sess *spriv; |
| 268 | int rc; |
| 269 | struct l2tp_eth_net *pn; |
| 270 | |
| 271 | tunnel = l2tp_tunnel_find(net, tunnel_id); |
| 272 | if (!tunnel) { |
| 273 | rc = -ENODEV; |
| 274 | goto out; |
| 275 | } |
| 276 | |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 277 | if (cfg->ifname) { |
| 278 | dev = dev_get_by_name(net, cfg->ifname); |
| 279 | if (dev) { |
| 280 | dev_put(dev); |
| 281 | rc = -EEXIST; |
| 282 | goto out; |
| 283 | } |
| 284 | strlcpy(name, cfg->ifname, IFNAMSIZ); |
Guillaume Nault | c39855f | 2017-04-24 14:16:06 +0200 | [diff] [blame^] | 285 | name_assign_type = NET_NAME_USER; |
| 286 | } else { |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 287 | strcpy(name, L2TP_ETH_DEV_NAME); |
Guillaume Nault | c39855f | 2017-04-24 14:16:06 +0200 | [diff] [blame^] | 288 | name_assign_type = NET_NAME_ENUM; |
| 289 | } |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 290 | |
| 291 | session = l2tp_session_create(sizeof(*spriv), tunnel, session_id, |
| 292 | peer_session_id, cfg); |
Guillaume Nault | dbdbc73 | 2017-03-31 13:02:27 +0200 | [diff] [blame] | 293 | if (IS_ERR(session)) { |
| 294 | rc = PTR_ERR(session); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 295 | goto out; |
| 296 | } |
| 297 | |
Guillaume Nault | c39855f | 2017-04-24 14:16:06 +0200 | [diff] [blame^] | 298 | dev = alloc_netdev(sizeof(*priv), name, name_assign_type, |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 299 | l2tp_eth_dev_setup); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 300 | if (!dev) { |
| 301 | rc = -ENOMEM; |
| 302 | goto out_del_session; |
| 303 | } |
| 304 | |
| 305 | dev_net_set(dev, net); |
Jarod Wilson | 8b1efc0 | 2016-10-20 23:25:27 -0400 | [diff] [blame] | 306 | dev->min_mtu = 0; |
| 307 | dev->max_mtu = ETH_MAX_MTU; |
R. Parameswaran | b784e7e | 2017-04-05 17:00:07 -0700 | [diff] [blame] | 308 | l2tp_eth_adjust_mtu(tunnel, session, dev); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 309 | |
| 310 | priv = netdev_priv(dev); |
| 311 | priv->dev = dev; |
| 312 | priv->session = session; |
| 313 | INIT_LIST_HEAD(&priv->list); |
| 314 | |
| 315 | priv->tunnel_sock = tunnel->sock; |
| 316 | session->recv_skb = l2tp_eth_dev_recv; |
| 317 | session->session_close = l2tp_eth_delete; |
Javier Martinez Canillas | 9dd7994 | 2016-09-09 08:43:17 -0400 | [diff] [blame] | 318 | #if IS_ENABLED(CONFIG_L2TP_DEBUGFS) |
James Chapman | 0ad6614 | 2010-04-02 06:19:33 +0000 | [diff] [blame] | 319 | session->show = l2tp_eth_show; |
| 320 | #endif |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 321 | |
| 322 | spriv = l2tp_session_priv(session); |
| 323 | spriv->dev = dev; |
| 324 | |
| 325 | rc = register_netdev(dev); |
| 326 | if (rc < 0) |
| 327 | goto out_del_dev; |
| 328 | |
Eric Dumazet | a06998b | 2012-06-07 00:07:20 +0000 | [diff] [blame] | 329 | __module_get(THIS_MODULE); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 330 | /* Must be done after register_netdev() */ |
| 331 | strlcpy(session->ifname, dev->name, IFNAMSIZ); |
| 332 | |
| 333 | dev_hold(dev); |
| 334 | pn = l2tp_eth_pernet(dev_net(dev)); |
| 335 | spin_lock(&pn->l2tp_eth_lock); |
| 336 | list_add(&priv->list, &pn->l2tp_eth_dev_list); |
| 337 | spin_unlock(&pn->l2tp_eth_lock); |
| 338 | |
| 339 | return 0; |
| 340 | |
| 341 | out_del_dev: |
| 342 | free_netdev(dev); |
Tom Parkin | 7893363 | 2012-10-29 23:41:48 +0000 | [diff] [blame] | 343 | spriv->dev = NULL; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 344 | out_del_session: |
| 345 | l2tp_session_delete(session); |
| 346 | out: |
| 347 | return rc; |
| 348 | } |
| 349 | |
| 350 | static __net_init int l2tp_eth_init_net(struct net *net) |
| 351 | { |
Jiri Pirko | 3a73702 | 2010-04-23 01:01:52 +0000 | [diff] [blame] | 352 | struct l2tp_eth_net *pn = net_generic(net, l2tp_eth_net_id); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 353 | |
| 354 | INIT_LIST_HEAD(&pn->l2tp_eth_dev_list); |
| 355 | spin_lock_init(&pn->l2tp_eth_lock); |
| 356 | |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 357 | return 0; |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 358 | } |
| 359 | |
James Chapman | 8aa525a | 2011-03-21 18:10:25 -0700 | [diff] [blame] | 360 | static struct pernet_operations l2tp_eth_net_ops = { |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 361 | .init = l2tp_eth_init_net, |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 362 | .id = &l2tp_eth_net_id, |
| 363 | .size = sizeof(struct l2tp_eth_net), |
| 364 | }; |
| 365 | |
| 366 | |
| 367 | static const struct l2tp_nl_cmd_ops l2tp_eth_nl_cmd_ops = { |
| 368 | .session_create = l2tp_eth_create, |
| 369 | .session_delete = l2tp_session_delete, |
| 370 | }; |
| 371 | |
| 372 | |
| 373 | static int __init l2tp_eth_init(void) |
| 374 | { |
| 375 | int err = 0; |
| 376 | |
| 377 | err = l2tp_nl_register_ops(L2TP_PWTYPE_ETH, &l2tp_eth_nl_cmd_ops); |
| 378 | if (err) |
| 379 | goto out; |
| 380 | |
| 381 | err = register_pernet_device(&l2tp_eth_net_ops); |
| 382 | if (err) |
| 383 | goto out_unreg; |
| 384 | |
Joe Perches | a4ca44f | 2012-05-16 09:55:56 +0000 | [diff] [blame] | 385 | pr_info("L2TP ethernet pseudowire support (L2TPv3)\n"); |
James Chapman | d9e31d1 | 2010-04-02 06:19:26 +0000 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | |
| 389 | out_unreg: |
| 390 | l2tp_nl_unregister_ops(L2TP_PWTYPE_ETH); |
| 391 | out: |
| 392 | return err; |
| 393 | } |
| 394 | |
| 395 | static void __exit l2tp_eth_exit(void) |
| 396 | { |
| 397 | unregister_pernet_device(&l2tp_eth_net_ops); |
| 398 | l2tp_nl_unregister_ops(L2TP_PWTYPE_ETH); |
| 399 | } |
| 400 | |
| 401 | module_init(l2tp_eth_init); |
| 402 | module_exit(l2tp_eth_exit); |
| 403 | |
| 404 | MODULE_LICENSE("GPL"); |
| 405 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); |
| 406 | MODULE_DESCRIPTION("L2TP ethernet pseudowire driver"); |
| 407 | MODULE_VERSION("1.0"); |
stephen hemminger | f1f39f9 | 2015-09-23 21:33:34 -0700 | [diff] [blame] | 408 | MODULE_ALIAS_L2TP_PWTYPE(5); |