Skip to content
Snippets Groups Projects
dev.c 125 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	if (net->dev_index_head == NULL)
    		goto err_idx;
    
    
    err_idx:
    	kfree(net->dev_name_head);
    err_name:
    	return -ENOMEM;
    
    /**
     *	netdev_drivername - network driver for the device
     *	@dev: network device
     *	@buffer: buffer for resulting name
     *	@len: size of buffer
     *
     *	Determine network driver for device.
     */
    
    char *netdev_drivername(const struct net_device *dev, char *buffer, int len)
    
    	const struct device_driver *driver;
    	const struct device *parent;
    
    
    	if (len <= 0 || !buffer)
    		return buffer;
    	buffer[0] = 0;
    
    	parent = dev->dev.parent;
    
    	if (!parent)
    		return buffer;
    
    	driver = parent->driver;
    	if (driver && driver->name)
    		strlcpy(buffer, driver->name, len);
    	return buffer;
    }
    
    
    static void __net_exit netdev_exit(struct net *net)
    
    {
    	kfree(net->dev_name_head);
    	kfree(net->dev_index_head);
    }
    
    
    static struct pernet_operations __net_initdata netdev_net_ops = {
    
    static void __net_exit default_device_exit(struct net *net)
    
    	/*
    	 * Push all migratable of the network devices back to the
    	 * initial network namespace
    	 */
    	rtnl_lock();
    
    
    		/* Ignore unmoveable devices (i.e. loopback) */
    		if (dev->features & NETIF_F_NETNS_LOCAL)
    			continue;
    
    
    		/* Delete virtual devices */
    		if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) {
    			dev->rtnl_link_ops->dellink(dev);
    
    		/* 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 struct pernet_operations __net_initdata default_device_ops = {
    
    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) {
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		struct softnet_data *queue;
    
    		queue = &per_cpu(softnet_data, i);
    		skb_queue_head_init(&queue->input_pkt_queue);
    		queue->completion_queue = NULL;
    		INIT_LIST_HEAD(&queue->poll_list);
    
    
    		queue->backlog.poll = process_backlog;
    		queue->backlog.weight = weight_p;
    
    		queue->backlog.gro_list = NULL;
    
    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);
    
    EXPORT_SYMBOL(__dev_get_by_index);
    EXPORT_SYMBOL(__dev_get_by_name);
    EXPORT_SYMBOL(__dev_remove_pack);
    
    EXPORT_SYMBOL(dev_valid_name);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    EXPORT_SYMBOL(dev_add_pack);
    EXPORT_SYMBOL(dev_alloc_name);
    EXPORT_SYMBOL(dev_close);
    EXPORT_SYMBOL(dev_get_by_flags);
    EXPORT_SYMBOL(dev_get_by_index);
    EXPORT_SYMBOL(dev_get_by_name);
    EXPORT_SYMBOL(dev_open);
    EXPORT_SYMBOL(dev_queue_xmit);
    EXPORT_SYMBOL(dev_remove_pack);
    EXPORT_SYMBOL(dev_set_allmulti);
    EXPORT_SYMBOL(dev_set_promiscuity);
    EXPORT_SYMBOL(dev_change_flags);
    EXPORT_SYMBOL(dev_set_mtu);
    EXPORT_SYMBOL(dev_set_mac_address);
    EXPORT_SYMBOL(free_netdev);
    EXPORT_SYMBOL(netdev_boot_setup_check);
    EXPORT_SYMBOL(netdev_set_master);
    EXPORT_SYMBOL(netdev_state_change);
    EXPORT_SYMBOL(netif_receive_skb);
    EXPORT_SYMBOL(netif_rx);
    EXPORT_SYMBOL(register_gifconf);
    EXPORT_SYMBOL(register_netdevice);
    EXPORT_SYMBOL(register_netdevice_notifier);
    EXPORT_SYMBOL(skb_checksum_help);
    EXPORT_SYMBOL(synchronize_net);
    EXPORT_SYMBOL(unregister_netdevice);
    EXPORT_SYMBOL(unregister_netdevice_notifier);
    EXPORT_SYMBOL(net_enable_timestamp);
    EXPORT_SYMBOL(net_disable_timestamp);
    EXPORT_SYMBOL(dev_get_flags);
    
    #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
    EXPORT_SYMBOL(br_handle_frame_hook);
    EXPORT_SYMBOL(br_fdb_get_hook);
    EXPORT_SYMBOL(br_fdb_put_hook);
    #endif
    
    EXPORT_SYMBOL(dev_load);
    
    EXPORT_PER_CPU_SYMBOL(softnet_data);