loopback.c (5f6d88b9149d537f3db0798f7d312be632422e15) loopback.c (2774c7aba6c97a2535be3309a2209770953780b3)
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Pseudo-driver for the loopback interface.
7 *
8 * Version: @(#)loopback.c 1.0.4b 08/16/93

--- 43 unchanged lines hidden (view full) ---

52#include <linux/ethtool.h>
53#include <net/sock.h>
54#include <net/checksum.h>
55#include <linux/if_ether.h> /* For the statistics structure. */
56#include <linux/if_arp.h> /* For ARPHRD_ETHER */
57#include <linux/ip.h>
58#include <linux/tcp.h>
59#include <linux/percpu.h>
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Pseudo-driver for the loopback interface.
7 *
8 * Version: @(#)loopback.c 1.0.4b 08/16/93

--- 43 unchanged lines hidden (view full) ---

52#include <linux/ethtool.h>
53#include <net/sock.h>
54#include <net/checksum.h>
55#include <linux/if_ether.h> /* For the statistics structure. */
56#include <linux/if_arp.h> /* For ARPHRD_ETHER */
57#include <linux/ip.h>
58#include <linux/tcp.h>
59#include <linux/percpu.h>
60#include <net/net_namespace.h>
60
61struct pcpu_lstats {
62 unsigned long packets;
63 unsigned long bytes;
64};
65
66#define LOOPBACK_OVERHEAD (128 + MAX_HEADER + 16 + 16)
67

--- 179 unchanged lines hidden (view full) ---

247 | NETIF_F_LLTX
248 | NETIF_F_NETNS_LOCAL,
249 dev->ethtool_ops = &loopback_ethtool_ops;
250 dev->init = loopback_dev_init;
251 dev->destructor = loopback_dev_free;
252}
253
254/* Setup and register the loopback device. */
61
62struct pcpu_lstats {
63 unsigned long packets;
64 unsigned long bytes;
65};
66
67#define LOOPBACK_OVERHEAD (128 + MAX_HEADER + 16 + 16)
68

--- 179 unchanged lines hidden (view full) ---

248 | NETIF_F_LLTX
249 | NETIF_F_NETNS_LOCAL,
250 dev->ethtool_ops = &loopback_ethtool_ops;
251 dev->init = loopback_dev_init;
252 dev->destructor = loopback_dev_free;
253}
254
255/* Setup and register the loopback device. */
255static int __init loopback_init(void)
256static int loopback_net_init(struct net *net)
256{
257 struct net_device *dev;
258 int err;
259
260 err = -ENOMEM;
261 dev = alloc_netdev(0, "lo", loopback_setup);
262 if (!dev)
263 goto out;
264
257{
258 struct net_device *dev;
259 int err;
260
261 err = -ENOMEM;
262 dev = alloc_netdev(0, "lo", loopback_setup);
263 if (!dev)
264 goto out;
265
266 dev->nd_net = net;
265 err = register_netdev(dev);
266 if (err)
267 goto out_free_netdev;
268
269 err = 0;
267 err = register_netdev(dev);
268 if (err)
269 goto out_free_netdev;
270
271 err = 0;
270 loopback_dev = dev;
272 net->loopback_dev = dev;
271
272out:
273 if (err)
274 panic("loopback: Failed to register netdevice: %d\n", err);
275 return err;
276
277out_free_netdev:
278 free_netdev(dev);
279 goto out;
280}
281
273
274out:
275 if (err)
276 panic("loopback: Failed to register netdevice: %d\n", err);
277 return err;
278
279out_free_netdev:
280 free_netdev(dev);
281 goto out;
282}
283
282fs_initcall(loopback_init);
284static void loopback_net_exit(struct net *net)
285{
286 struct net_device *dev = net->loopback_dev;
283
287
284struct net_device *loopback_dev;
285EXPORT_SYMBOL(loopback_dev);
288 unregister_netdev(dev);
289}
290
291static struct pernet_operations loopback_net_ops = {
292 .init = loopback_net_init,
293 .exit = loopback_net_exit,
294};
295
296static int __init loopback_init(void)
297{
298 return register_pernet_device(&loopback_net_ops);
299}
300
301fs_initcall(loopback_init);