Skip to content
Snippets Groups Projects
dev.c 149 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	struct net_device *dev, *aux;
    
    	 * Push all migratable network devices back to the
    
    	 * initial network namespace
    	 */
    	rtnl_lock();
    
    	for_each_netdev_safe(net, dev, aux) {
    
    
    		/* Ignore unmoveable devices (i.e. loopback) */
    		if (dev->features & NETIF_F_NETNS_LOCAL)
    			continue;
    
    
    		/* Leave virtual devices for the generic cleanup */
    		if (dev->rtnl_link_ops)
    			continue;
    
    		/* Push remaing network devices to init_net */
    
    		snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
    		err = dev_change_net_namespace(dev, &init_net, fb_name);
    
    			printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n",
    
    static void __net_exit default_device_exit_batch(struct list_head *net_list)
    {
    	/* At exit all network devices most be removed from a network
    	 * namespace.  Do this in the reverse order of registeration.
    	 * Do this across as many network namespaces as possible to
    	 * improve batching efficiency.
    	 */
    	struct net_device *dev;
    	struct net *net;
    	LIST_HEAD(dev_kill_list);
    
    	rtnl_lock();
    	list_for_each_entry(net, net_list, exit_list) {
    		for_each_netdev_reverse(net, dev) {
    			if (dev->rtnl_link_ops)
    				dev->rtnl_link_ops->dellink(dev, &dev_kill_list);
    			else
    				unregister_netdevice_queue(dev, &dev_kill_list);
    		}
    	}
    	unregister_netdevice_many(&dev_kill_list);
    	rtnl_unlock();
    }
    
    
    static struct pernet_operations __net_initdata default_device_ops = {
    
    	.exit_batch = default_device_exit_batch,
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    /*
     *	Initialize the DEV module. At boot time this walks the device list and
     *	unhooks any devices that fail to initialise (normally hardware not
     *	present) and leaves us with a valid list of present and active devices.
     *
     */
    
    /*
     *       This is called single threaded during boot, so no need
     *       to take the rtnl semaphore.
     */
    static int __init net_dev_init(void)
    {
    	int i, rc = -ENOMEM;
    
    	BUG_ON(!dev_boot_phase);
    
    	if (dev_proc_init())
    		goto out;
    
    
    	if (netdev_kobject_init())
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		goto out;
    
    	INIT_LIST_HEAD(&ptype_all);
    
    	for (i = 0; i < PTYPE_HASH_SIZE; i++)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		INIT_LIST_HEAD(&ptype_base[i]);
    
    
    	if (register_pernet_subsys(&netdev_net_ops))
    		goto out;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    	/*
    	 *	Initialise the packet receive queues.
    	 */
    
    
    	for_each_possible_cpu(i) {
    
    Eric Dumazet's avatar
    Eric Dumazet committed
    		struct softnet_data *sd = &per_cpu(softnet_data, i);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    
    Changli Gao's avatar
    Changli Gao committed
    		memset(sd, 0, sizeof(*sd));
    
    Eric Dumazet's avatar
    Eric Dumazet committed
    		skb_queue_head_init(&sd->input_pkt_queue);
    
    		skb_queue_head_init(&sd->process_queue);
    
    Eric Dumazet's avatar
    Eric Dumazet committed
    		sd->completion_queue = NULL;
    		INIT_LIST_HEAD(&sd->poll_list);
    
    		sd->output_queue = NULL;
    		sd->output_queue_tailp = &sd->output_queue;
    
    Eric Dumazet's avatar
    Eric Dumazet committed
    #ifdef CONFIG_RPS
    
    Eric Dumazet's avatar
    Eric Dumazet committed
    		sd->csd.func = rps_trigger_softirq;
    		sd->csd.info = sd;
    		sd->csd.flags = 0;
    		sd->cpu = i;
    
    Eric Dumazet's avatar
    Eric Dumazet committed
    		sd->backlog.poll = process_backlog;
    		sd->backlog.weight = weight_p;
    		sd->backlog.gro_list = NULL;
    		sd->backlog.gro_count = 0;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	}
    
    	dev_boot_phase = 0;
    
    
    	/* The loopback device is special if any other network devices
    	 * is present in a network namespace the loopback device must
    	 * be present. Since we now dynamically allocate and free the
    	 * loopback device ensure this invariant is maintained by
    	 * keeping the loopback device as the first device on the
    	 * list of network devices.  Ensuring the loopback devices
    	 * is the first device that appears and the last network device
    	 * that disappears.
    	 */
    	if (register_pernet_device(&loopback_net_ops))
    		goto out;
    
    	if (register_pernet_device(&default_device_ops))
    		goto out;
    
    
    	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
    	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    	hotcpu_notifier(dev_cpu_callback, 0);
    	dst_init();
    	dev_mcast_init();
    	rc = 0;
    out:
    	return rc;
    }
    
    subsys_initcall(net_dev_init);
    
    
    static int __init initialize_hashrnd(void)
    {
    
    	get_random_bytes(&hashrnd, sizeof(hashrnd));
    
    	return 0;
    }
    
    late_initcall_sync(initialize_hashrnd);