dev.c (dba0a918722ee0f0ba3442575e4448c3ab622be4) | dev.c (d314774cf2cd5dfeb39a00d37deee65d4c627927) |
---|---|
1/* 2 * NET3 Protocol independent device support routines. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 7 * 2 of the License, or (at your option) any later version. 8 * --- 94 unchanged lines hidden (view full) --- 103#include <linux/if_macvlan.h> 104#include <net/dst.h> 105#include <net/pkt_sched.h> 106#include <net/checksum.h> 107#include <linux/highmem.h> 108#include <linux/init.h> 109#include <linux/kmod.h> 110#include <linux/module.h> | 1/* 2 * NET3 Protocol independent device support routines. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 7 * 2 of the License, or (at your option) any later version. 8 * --- 94 unchanged lines hidden (view full) --- 103#include <linux/if_macvlan.h> 104#include <net/dst.h> 105#include <net/pkt_sched.h> 106#include <net/checksum.h> 107#include <linux/highmem.h> 108#include <linux/init.h> 109#include <linux/kmod.h> 110#include <linux/module.h> |
111#include <linux/kallsyms.h> | |
112#include <linux/netpoll.h> 113#include <linux/rcupdate.h> 114#include <linux/delay.h> 115#include <net/wext.h> 116#include <net/iw_handler.h> 117#include <asm/current.h> 118#include <linux/audit.h> 119#include <linux/dmaengine.h> --- 799 unchanged lines hidden (view full) --- 919 return err; 920 } 921 else if (__dev_get_by_name(net, newname)) 922 return -EEXIST; 923 else 924 strlcpy(dev->name, newname, IFNAMSIZ); 925 926rollback: | 111#include <linux/netpoll.h> 112#include <linux/rcupdate.h> 113#include <linux/delay.h> 114#include <net/wext.h> 115#include <net/iw_handler.h> 116#include <asm/current.h> 117#include <linux/audit.h> 118#include <linux/dmaengine.h> --- 799 unchanged lines hidden (view full) --- 918 return err; 919 } 920 else if (__dev_get_by_name(net, newname)) 921 return -EEXIST; 922 else 923 strlcpy(dev->name, newname, IFNAMSIZ); 924 925rollback: |
927 ret = device_rename(&dev->dev, dev->name); 928 if (ret) { 929 memcpy(dev->name, oldname, IFNAMSIZ); 930 return ret; | 926 /* For now only devices in the initial network namespace 927 * are in sysfs. 928 */ 929 if (net == &init_net) { 930 ret = device_rename(&dev->dev, dev->name); 931 if (ret) { 932 memcpy(dev->name, oldname, IFNAMSIZ); 933 return ret; 934 } |
931 } 932 933 write_lock_bh(&dev_base_lock); 934 hlist_del(&dev->name_hlist); 935 hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name)); 936 write_unlock_bh(&dev_base_lock); 937 938 ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev); --- 111 unchanged lines hidden (view full) --- 1050 * the device is moved into the up state and a %NETDEV_UP message is 1051 * sent to the netdev notifier chain. 1052 * 1053 * Calling this function on an active interface is a nop. On a failure 1054 * a negative errno code is returned. 1055 */ 1056int dev_open(struct net_device *dev) 1057{ | 935 } 936 937 write_lock_bh(&dev_base_lock); 938 hlist_del(&dev->name_hlist); 939 hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name)); 940 write_unlock_bh(&dev_base_lock); 941 942 ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev); --- 111 unchanged lines hidden (view full) --- 1054 * the device is moved into the up state and a %NETDEV_UP message is 1055 * sent to the netdev notifier chain. 1056 * 1057 * Calling this function on an active interface is a nop. On a failure 1058 * a negative errno code is returned. 1059 */ 1060int dev_open(struct net_device *dev) 1061{ |
1062 const struct net_device_ops *ops = dev->netdev_ops; |
|
1058 int ret = 0; 1059 1060 ASSERT_RTNL(); 1061 1062 /* 1063 * Is it already up? 1064 */ 1065 --- 6 unchanged lines hidden (view full) --- 1072 if (!netif_device_present(dev)) 1073 return -ENODEV; 1074 1075 /* 1076 * Call device private open method 1077 */ 1078 set_bit(__LINK_STATE_START, &dev->state); 1079 | 1063 int ret = 0; 1064 1065 ASSERT_RTNL(); 1066 1067 /* 1068 * Is it already up? 1069 */ 1070 --- 6 unchanged lines hidden (view full) --- 1077 if (!netif_device_present(dev)) 1078 return -ENODEV; 1079 1080 /* 1081 * Call device private open method 1082 */ 1083 set_bit(__LINK_STATE_START, &dev->state); 1084 |
1080 if (dev->validate_addr) 1081 ret = dev->validate_addr(dev); | 1085 if (ops->ndo_validate_addr) 1086 ret = ops->ndo_validate_addr(dev); |
1082 | 1087 |
1083 if (!ret && dev->open) 1084 ret = dev->open(dev); | 1088 if (!ret && ops->ndo_open) 1089 ret = ops->ndo_open(dev); |
1085 1086 /* 1087 * If it went open OK then: 1088 */ 1089 1090 if (ret) 1091 clear_bit(__LINK_STATE_START, &dev->state); 1092 else { --- 27 unchanged lines hidden (view full) --- 1120 * 1121 * This function moves an active device into down state. A 1122 * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device 1123 * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier 1124 * chain. 1125 */ 1126int dev_close(struct net_device *dev) 1127{ | 1090 1091 /* 1092 * If it went open OK then: 1093 */ 1094 1095 if (ret) 1096 clear_bit(__LINK_STATE_START, &dev->state); 1097 else { --- 27 unchanged lines hidden (view full) --- 1125 * 1126 * This function moves an active device into down state. A 1127 * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device 1128 * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier 1129 * chain. 1130 */ 1131int dev_close(struct net_device *dev) 1132{ |
1133 const struct net_device_ops *ops = dev->netdev_ops; |
|
1128 ASSERT_RTNL(); 1129 1130 might_sleep(); 1131 1132 if (!(dev->flags & IFF_UP)) 1133 return 0; 1134 1135 /* --- 16 unchanged lines hidden (view full) --- 1152 1153 /* 1154 * Call the device specific close. This cannot fail. 1155 * Only if device is UP 1156 * 1157 * We allow it to be called even after a DETACH hot-plug 1158 * event. 1159 */ | 1134 ASSERT_RTNL(); 1135 1136 might_sleep(); 1137 1138 if (!(dev->flags & IFF_UP)) 1139 return 0; 1140 1141 /* --- 16 unchanged lines hidden (view full) --- 1158 1159 /* 1160 * Call the device specific close. This cannot fail. 1161 * Only if device is UP 1162 * 1163 * We allow it to be called even after a DETACH hot-plug 1164 * event. 1165 */ |
1160 if (dev->stop) 1161 dev->stop(dev); | 1166 if (ops->ndo_stop) 1167 ops->ndo_stop(dev); |
1162 1163 /* 1164 * Device is now down. 1165 */ 1166 1167 dev->flags &= ~IFF_UP; 1168 1169 /* --- 1076 unchanged lines hidden (view full) --- 2246 skb_reset_transport_header(skb); 2247 skb->mac_len = skb->network_header - skb->mac_header; 2248 2249 pt_prev = NULL; 2250 2251 rcu_read_lock(); 2252 2253 /* Don't receive packets in an exiting network namespace */ | 1168 1169 /* 1170 * Device is now down. 1171 */ 1172 1173 dev->flags &= ~IFF_UP; 1174 1175 /* --- 1076 unchanged lines hidden (view full) --- 2252 skb_reset_transport_header(skb); 2253 skb->mac_len = skb->network_header - skb->mac_header; 2254 2255 pt_prev = NULL; 2256 2257 rcu_read_lock(); 2258 2259 /* Don't receive packets in an exiting network namespace */ |
2254 if (!net_alive(dev_net(skb->dev))) | 2260 if (!net_alive(dev_net(skb->dev))) { 2261 kfree_skb(skb); |
2255 goto out; | 2262 goto out; |
2263 } |
|
2256 2257#ifdef CONFIG_NET_CLS_ACT 2258 if (skb->tc_verd & TC_NCLS) { 2259 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); 2260 goto ncls; 2261 } 2262#endif 2263 --- 102 unchanged lines hidden (view full) --- 2366 local_irq_restore(flags); 2367} 2368EXPORT_SYMBOL(__napi_schedule); 2369 2370 2371static void net_rx_action(struct softirq_action *h) 2372{ 2373 struct list_head *list = &__get_cpu_var(softnet_data).poll_list; | 2264 2265#ifdef CONFIG_NET_CLS_ACT 2266 if (skb->tc_verd & TC_NCLS) { 2267 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); 2268 goto ncls; 2269 } 2270#endif 2271 --- 102 unchanged lines hidden (view full) --- 2374 local_irq_restore(flags); 2375} 2376EXPORT_SYMBOL(__napi_schedule); 2377 2378 2379static void net_rx_action(struct softirq_action *h) 2380{ 2381 struct list_head *list = &__get_cpu_var(softnet_data).poll_list; |
2374 unsigned long start_time = jiffies; | 2382 unsigned long time_limit = jiffies + 2; |
2375 int budget = netdev_budget; 2376 void *have; 2377 2378 local_irq_disable(); 2379 2380 while (!list_empty(list)) { 2381 struct napi_struct *n; 2382 int work, weight; 2383 2384 /* If softirq window is exhuasted then punt. | 2383 int budget = netdev_budget; 2384 void *have; 2385 2386 local_irq_disable(); 2387 2388 while (!list_empty(list)) { 2389 struct napi_struct *n; 2390 int work, weight; 2391 2392 /* If softirq window is exhuasted then punt. |
2385 * 2386 * Note that this is a slight policy change from the 2387 * previous NAPI code, which would allow up to 2 2388 * jiffies to pass before breaking out. The test 2389 * used to be "jiffies - start_time > 1". | 2393 * Allow this to run for 2 jiffies since which will allow 2394 * an average latency of 1.5/HZ. |
2390 */ | 2395 */ |
2391 if (unlikely(budget <= 0 || jiffies != start_time)) | 2396 if (unlikely(budget <= 0 || time_after(jiffies, time_limit))) |
2392 goto softnet_break; 2393 2394 local_irq_enable(); 2395 2396 /* Even though interrupts have been re-enabled, this 2397 * access is safe because interrupts can only add new 2398 * entries to the tail of this list, and only ->poll() 2399 * calls can remove this head entry from the list. --- 392 unchanged lines hidden (view full) --- 2792} 2793 2794static void ptype_seq_stop(struct seq_file *seq, void *v) 2795 __releases(RCU) 2796{ 2797 rcu_read_unlock(); 2798} 2799 | 2397 goto softnet_break; 2398 2399 local_irq_enable(); 2400 2401 /* Even though interrupts have been re-enabled, this 2402 * access is safe because interrupts can only add new 2403 * entries to the tail of this list, and only ->poll() 2404 * calls can remove this head entry from the list. --- 392 unchanged lines hidden (view full) --- 2797} 2798 2799static void ptype_seq_stop(struct seq_file *seq, void *v) 2800 __releases(RCU) 2801{ 2802 rcu_read_unlock(); 2803} 2804 |
2800static void ptype_seq_decode(struct seq_file *seq, void *sym) 2801{ 2802#ifdef CONFIG_KALLSYMS 2803 unsigned long offset = 0, symsize; 2804 const char *symname; 2805 char *modname; 2806 char namebuf[128]; 2807 2808 symname = kallsyms_lookup((unsigned long)sym, &symsize, &offset, 2809 &modname, namebuf); 2810 2811 if (symname) { 2812 char *delim = ":"; 2813 2814 if (!modname) 2815 modname = delim = ""; 2816 seq_printf(seq, "%s%s%s%s+0x%lx", delim, modname, delim, 2817 symname, offset); 2818 return; 2819 } 2820#endif 2821 2822 seq_printf(seq, "[%p]", sym); 2823} 2824 | |
2825static int ptype_seq_show(struct seq_file *seq, void *v) 2826{ 2827 struct packet_type *pt = v; 2828 2829 if (v == SEQ_START_TOKEN) 2830 seq_puts(seq, "Type Device Function\n"); 2831 else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) { 2832 if (pt->type == htons(ETH_P_ALL)) 2833 seq_puts(seq, "ALL "); 2834 else 2835 seq_printf(seq, "%04x", ntohs(pt->type)); 2836 | 2805static int ptype_seq_show(struct seq_file *seq, void *v) 2806{ 2807 struct packet_type *pt = v; 2808 2809 if (v == SEQ_START_TOKEN) 2810 seq_puts(seq, "Type Device Function\n"); 2811 else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) { 2812 if (pt->type == htons(ETH_P_ALL)) 2813 seq_puts(seq, "ALL "); 2814 else 2815 seq_printf(seq, "%04x", ntohs(pt->type)); 2816 |
2837 seq_printf(seq, " %-8s ", 2838 pt->dev ? pt->dev->name : ""); 2839 ptype_seq_decode(seq, pt->func); 2840 seq_putc(seq, '\n'); | 2817 seq_printf(seq, " %-8s %pF\n", 2818 pt->dev ? pt->dev->name : "", pt->func); |
2841 } 2842 2843 return 0; 2844} 2845 2846static const struct seq_operations ptype_seq_ops = { 2847 .start = ptype_seq_start, 2848 .next = ptype_seq_next, --- 100 unchanged lines hidden (view full) --- 2949 slave->flags &= ~IFF_SLAVE; 2950 2951 rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE); 2952 return 0; 2953} 2954 2955static void dev_change_rx_flags(struct net_device *dev, int flags) 2956{ | 2819 } 2820 2821 return 0; 2822} 2823 2824static const struct seq_operations ptype_seq_ops = { 2825 .start = ptype_seq_start, 2826 .next = ptype_seq_next, --- 100 unchanged lines hidden (view full) --- 2927 slave->flags &= ~IFF_SLAVE; 2928 2929 rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE); 2930 return 0; 2931} 2932 2933static void dev_change_rx_flags(struct net_device *dev, int flags) 2934{ |
2957 if (dev->flags & IFF_UP && dev->change_rx_flags) 2958 dev->change_rx_flags(dev, flags); | 2935 const struct net_device_ops *ops = dev->netdev_ops; 2936 2937 if ((dev->flags & IFF_UP) && ops->ndo_change_rx_flags) 2938 ops->ndo_change_rx_flags(dev, flags); |
2959} 2960 2961static int __dev_set_promiscuity(struct net_device *dev, int inc) 2962{ 2963 unsigned short old_flags = dev->flags; 2964 2965 ASSERT_RTNL(); 2966 --- 103 unchanged lines hidden (view full) --- 3070/* 3071 * Upload unicast and multicast address lists to device and 3072 * configure RX filtering. When the device doesn't support unicast 3073 * filtering it is put in promiscuous mode while unicast addresses 3074 * are present. 3075 */ 3076void __dev_set_rx_mode(struct net_device *dev) 3077{ | 2939} 2940 2941static int __dev_set_promiscuity(struct net_device *dev, int inc) 2942{ 2943 unsigned short old_flags = dev->flags; 2944 2945 ASSERT_RTNL(); 2946 --- 103 unchanged lines hidden (view full) --- 3050/* 3051 * Upload unicast and multicast address lists to device and 3052 * configure RX filtering. When the device doesn't support unicast 3053 * filtering it is put in promiscuous mode while unicast addresses 3054 * are present. 3055 */ 3056void __dev_set_rx_mode(struct net_device *dev) 3057{ |
3058 const struct net_device_ops *ops = dev->netdev_ops; 3059 |
|
3078 /* dev_open will call this function so the list will stay sane. */ 3079 if (!(dev->flags&IFF_UP)) 3080 return; 3081 3082 if (!netif_device_present(dev)) 3083 return; 3084 | 3060 /* dev_open will call this function so the list will stay sane. */ 3061 if (!(dev->flags&IFF_UP)) 3062 return; 3063 3064 if (!netif_device_present(dev)) 3065 return; 3066 |
3085 if (dev->set_rx_mode) 3086 dev->set_rx_mode(dev); | 3067 if (ops->ndo_set_rx_mode) 3068 ops->ndo_set_rx_mode(dev); |
3087 else { 3088 /* Unicast addresses changes may only happen under the rtnl, 3089 * therefore calling __dev_set_promiscuity here is safe. 3090 */ 3091 if (dev->uc_count > 0 && !dev->uc_promisc) { 3092 __dev_set_promiscuity(dev, 1); 3093 dev->uc_promisc = 1; 3094 } else if (dev->uc_count == 0 && dev->uc_promisc) { 3095 __dev_set_promiscuity(dev, -1); 3096 dev->uc_promisc = 0; 3097 } 3098 | 3069 else { 3070 /* Unicast addresses changes may only happen under the rtnl, 3071 * therefore calling __dev_set_promiscuity here is safe. 3072 */ 3073 if (dev->uc_count > 0 && !dev->uc_promisc) { 3074 __dev_set_promiscuity(dev, 1); 3075 dev->uc_promisc = 1; 3076 } else if (dev->uc_count == 0 && dev->uc_promisc) { 3077 __dev_set_promiscuity(dev, -1); 3078 dev->uc_promisc = 0; 3079 } 3080 |
3099 if (dev->set_multicast_list) 3100 dev->set_multicast_list(dev); | 3081 if (ops->ndo_set_multicast_list) 3082 ops->ndo_set_multicast_list(dev); |
3101 } 3102} 3103 3104void dev_set_rx_mode(struct net_device *dev) 3105{ 3106 netif_addr_lock_bh(dev); 3107 __dev_set_rx_mode(dev); 3108 netif_addr_unlock_bh(dev); --- 342 unchanged lines hidden (view full) --- 3451 * dev_set_mtu - Change maximum transfer unit 3452 * @dev: device 3453 * @new_mtu: new transfer unit 3454 * 3455 * Change the maximum transfer size of the network device. 3456 */ 3457int dev_set_mtu(struct net_device *dev, int new_mtu) 3458{ | 3083 } 3084} 3085 3086void dev_set_rx_mode(struct net_device *dev) 3087{ 3088 netif_addr_lock_bh(dev); 3089 __dev_set_rx_mode(dev); 3090 netif_addr_unlock_bh(dev); --- 342 unchanged lines hidden (view full) --- 3433 * dev_set_mtu - Change maximum transfer unit 3434 * @dev: device 3435 * @new_mtu: new transfer unit 3436 * 3437 * Change the maximum transfer size of the network device. 3438 */ 3439int dev_set_mtu(struct net_device *dev, int new_mtu) 3440{ |
3441 const struct net_device_ops *ops = dev->netdev_ops; |
|
3459 int err; 3460 3461 if (new_mtu == dev->mtu) 3462 return 0; 3463 3464 /* MTU must be positive. */ 3465 if (new_mtu < 0) 3466 return -EINVAL; 3467 3468 if (!netif_device_present(dev)) 3469 return -ENODEV; 3470 3471 err = 0; | 3442 int err; 3443 3444 if (new_mtu == dev->mtu) 3445 return 0; 3446 3447 /* MTU must be positive. */ 3448 if (new_mtu < 0) 3449 return -EINVAL; 3450 3451 if (!netif_device_present(dev)) 3452 return -ENODEV; 3453 3454 err = 0; |
3472 if (dev->change_mtu) 3473 err = dev->change_mtu(dev, new_mtu); | 3455 if (ops->ndo_change_mtu) 3456 err = ops->ndo_change_mtu(dev, new_mtu); |
3474 else 3475 dev->mtu = new_mtu; | 3457 else 3458 dev->mtu = new_mtu; |
3459 |
|
3476 if (!err && dev->flags & IFF_UP) 3477 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); 3478 return err; 3479} 3480 3481/** 3482 * dev_set_mac_address - Change Media Access Control Address 3483 * @dev: device 3484 * @sa: new address 3485 * 3486 * Change the hardware (MAC) address of the device 3487 */ 3488int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) 3489{ | 3460 if (!err && dev->flags & IFF_UP) 3461 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); 3462 return err; 3463} 3464 3465/** 3466 * dev_set_mac_address - Change Media Access Control Address 3467 * @dev: device 3468 * @sa: new address 3469 * 3470 * Change the hardware (MAC) address of the device 3471 */ 3472int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) 3473{ |
3474 const struct net_device_ops *ops = dev->netdev_ops; |
|
3490 int err; 3491 | 3475 int err; 3476 |
3492 if (!dev->set_mac_address) | 3477 if (!ops->ndo_set_mac_address) |
3493 return -EOPNOTSUPP; 3494 if (sa->sa_family != dev->type) 3495 return -EINVAL; 3496 if (!netif_device_present(dev)) 3497 return -ENODEV; | 3478 return -EOPNOTSUPP; 3479 if (sa->sa_family != dev->type) 3480 return -EINVAL; 3481 if (!netif_device_present(dev)) 3482 return -ENODEV; |
3498 err = dev->set_mac_address(dev, sa); | 3483 err = ops->ndo_set_mac_address(dev, sa); |
3499 if (!err) 3500 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3501 return err; 3502} 3503 3504/* 3505 * Perform the SIOCxIFxxx calls, inside read_lock(dev_base_lock) 3506 */ --- 63 unchanged lines hidden (view full) --- 3570 3571/* 3572 * Perform the SIOCxIFxxx calls, inside rtnl_lock() 3573 */ 3574static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) 3575{ 3576 int err; 3577 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); | 3484 if (!err) 3485 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3486 return err; 3487} 3488 3489/* 3490 * Perform the SIOCxIFxxx calls, inside read_lock(dev_base_lock) 3491 */ --- 63 unchanged lines hidden (view full) --- 3555 3556/* 3557 * Perform the SIOCxIFxxx calls, inside rtnl_lock() 3558 */ 3559static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) 3560{ 3561 int err; 3562 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
3563 const struct net_device_ops *ops = dev->netdev_ops; |
|
3578 3579 if (!dev) 3580 return -ENODEV; 3581 3582 switch (cmd) { 3583 case SIOCSIFFLAGS: /* Set interface flags */ 3584 return dev_change_flags(dev, ifr->ifr_flags); 3585 --- 11 unchanged lines hidden (view full) --- 3597 if (ifr->ifr_hwaddr.sa_family != dev->type) 3598 return -EINVAL; 3599 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, 3600 min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); 3601 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3602 return 0; 3603 3604 case SIOCSIFMAP: | 3564 3565 if (!dev) 3566 return -ENODEV; 3567 3568 switch (cmd) { 3569 case SIOCSIFFLAGS: /* Set interface flags */ 3570 return dev_change_flags(dev, ifr->ifr_flags); 3571 --- 11 unchanged lines hidden (view full) --- 3583 if (ifr->ifr_hwaddr.sa_family != dev->type) 3584 return -EINVAL; 3585 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, 3586 min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); 3587 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3588 return 0; 3589 3590 case SIOCSIFMAP: |
3605 if (dev->set_config) { | 3591 if (ops->ndo_set_config) { |
3606 if (!netif_device_present(dev)) 3607 return -ENODEV; | 3592 if (!netif_device_present(dev)) 3593 return -ENODEV; |
3608 return dev->set_config(dev, &ifr->ifr_map); | 3594 return ops->ndo_set_config(dev, &ifr->ifr_map); |
3609 } 3610 return -EOPNOTSUPP; 3611 3612 case SIOCADDMULTI: | 3595 } 3596 return -EOPNOTSUPP; 3597 3598 case SIOCADDMULTI: |
3613 if ((!dev->set_multicast_list && !dev->set_rx_mode) || | 3599 if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || |
3614 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3615 return -EINVAL; 3616 if (!netif_device_present(dev)) 3617 return -ENODEV; 3618 return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data, 3619 dev->addr_len, 1); 3620 3621 case SIOCDELMULTI: | 3600 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3601 return -EINVAL; 3602 if (!netif_device_present(dev)) 3603 return -ENODEV; 3604 return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data, 3605 dev->addr_len, 1); 3606 3607 case SIOCDELMULTI: |
3622 if ((!dev->set_multicast_list && !dev->set_rx_mode) || | 3608 if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || |
3623 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3624 return -EINVAL; 3625 if (!netif_device_present(dev)) 3626 return -ENODEV; 3627 return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data, 3628 dev->addr_len, 1); 3629 3630 case SIOCSIFTXQLEN: --- 21 unchanged lines hidden (view full) --- 3652 cmd == SIOCBONDCHANGEACTIVE || 3653 cmd == SIOCGMIIPHY || 3654 cmd == SIOCGMIIREG || 3655 cmd == SIOCSMIIREG || 3656 cmd == SIOCBRADDIF || 3657 cmd == SIOCBRDELIF || 3658 cmd == SIOCWANDEV) { 3659 err = -EOPNOTSUPP; | 3609 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3610 return -EINVAL; 3611 if (!netif_device_present(dev)) 3612 return -ENODEV; 3613 return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data, 3614 dev->addr_len, 1); 3615 3616 case SIOCSIFTXQLEN: --- 21 unchanged lines hidden (view full) --- 3638 cmd == SIOCBONDCHANGEACTIVE || 3639 cmd == SIOCGMIIPHY || 3640 cmd == SIOCGMIIREG || 3641 cmd == SIOCSMIIREG || 3642 cmd == SIOCBRADDIF || 3643 cmd == SIOCBRDELIF || 3644 cmd == SIOCWANDEV) { 3645 err = -EOPNOTSUPP; |
3660 if (dev->do_ioctl) { | 3646 if (ops->ndo_do_ioctl) { |
3661 if (netif_device_present(dev)) | 3647 if (netif_device_present(dev)) |
3662 err = dev->do_ioctl(dev, ifr, 3663 cmd); | 3648 err = ops->ndo_do_ioctl(dev, ifr, cmd); |
3664 else 3665 err = -ENODEV; 3666 } 3667 } else 3668 err = -EINVAL; 3669 3670 } 3671 return err; --- 244 unchanged lines hidden (view full) --- 3916 */ 3917 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 3918 3919 /* 3920 * Flush the unicast and multicast chains 3921 */ 3922 dev_addr_discard(dev); 3923 | 3649 else 3650 err = -ENODEV; 3651 } 3652 } else 3653 err = -EINVAL; 3654 3655 } 3656 return err; --- 244 unchanged lines hidden (view full) --- 3901 */ 3902 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 3903 3904 /* 3905 * Flush the unicast and multicast chains 3906 */ 3907 dev_addr_discard(dev); 3908 |
3924 if (dev->uninit) 3925 dev->uninit(dev); | 3909 if (dev->netdev_ops->ndo_uninit) 3910 dev->netdev_ops->ndo_uninit(dev); |
3926 3927 /* Notifier chain MUST detach us from master device. */ 3928 WARN_ON(dev->master); 3929 3930 /* Remove entries from kobject tree */ 3931 netdev_unregister_kobject(dev); 3932 3933 synchronize_net(); --- 73 unchanged lines hidden (view full) --- 4007 * will not get the same name. 4008 */ 4009 4010int register_netdevice(struct net_device *dev) 4011{ 4012 struct hlist_head *head; 4013 struct hlist_node *p; 4014 int ret; | 3911 3912 /* Notifier chain MUST detach us from master device. */ 3913 WARN_ON(dev->master); 3914 3915 /* Remove entries from kobject tree */ 3916 netdev_unregister_kobject(dev); 3917 3918 synchronize_net(); --- 73 unchanged lines hidden (view full) --- 3992 * will not get the same name. 3993 */ 3994 3995int register_netdevice(struct net_device *dev) 3996{ 3997 struct hlist_head *head; 3998 struct hlist_node *p; 3999 int ret; |
4015 struct net *net; | 4000 struct net *net = dev_net(dev); |
4016 4017 BUG_ON(dev_boot_phase); 4018 ASSERT_RTNL(); 4019 4020 might_sleep(); 4021 4022 /* When net_device's are persistent, this will be fatal. */ 4023 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); | 4001 4002 BUG_ON(dev_boot_phase); 4003 ASSERT_RTNL(); 4004 4005 might_sleep(); 4006 4007 /* When net_device's are persistent, this will be fatal. */ 4008 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); |
4024 BUG_ON(!dev_net(dev)); 4025 net = dev_net(dev); | 4009 BUG_ON(!net); |
4026 4027 spin_lock_init(&dev->addr_list_lock); 4028 netdev_set_addr_lockdep_class(dev); 4029 netdev_init_queue_locks(dev); 4030 4031 dev->iflink = -1; 4032 | 4010 4011 spin_lock_init(&dev->addr_list_lock); 4012 netdev_set_addr_lockdep_class(dev); 4013 netdev_init_queue_locks(dev); 4014 4015 dev->iflink = -1; 4016 |
4017#ifdef CONFIG_COMPAT_NET_DEV_OPS 4018 /* Netdevice_ops API compatiability support. 4019 * This is temporary until all network devices are converted. 4020 */ 4021 if (dev->netdev_ops) { 4022 const struct net_device_ops *ops = dev->netdev_ops; 4023 4024 dev->init = ops->ndo_init; 4025 dev->uninit = ops->ndo_uninit; 4026 dev->open = ops->ndo_open; 4027 dev->change_rx_flags = ops->ndo_change_rx_flags; 4028 dev->set_rx_mode = ops->ndo_set_rx_mode; 4029 dev->set_multicast_list = ops->ndo_set_multicast_list; 4030 dev->set_mac_address = ops->ndo_set_mac_address; 4031 dev->validate_addr = ops->ndo_validate_addr; 4032 dev->do_ioctl = ops->ndo_do_ioctl; 4033 dev->set_config = ops->ndo_set_config; 4034 dev->change_mtu = ops->ndo_change_mtu; 4035 dev->tx_timeout = ops->ndo_tx_timeout; 4036 dev->get_stats = ops->ndo_get_stats; 4037 dev->vlan_rx_register = ops->ndo_vlan_rx_register; 4038 dev->vlan_rx_add_vid = ops->ndo_vlan_rx_add_vid; 4039 dev->vlan_rx_kill_vid = ops->ndo_vlan_rx_kill_vid; 4040#ifdef CONFIG_NET_POLL_CONTROLLER 4041 dev->poll_controller = ops->ndo_poll_controller; 4042#endif 4043 } else { 4044 char drivername[64]; 4045 pr_info("%s (%s): not using net_device_ops yet\n", 4046 dev->name, netdev_drivername(dev, drivername, 64)); 4047 4048 /* This works only because net_device_ops and the 4049 compatiablity structure are the same. */ 4050 dev->netdev_ops = (void *) &(dev->init); 4051 } 4052#endif 4053 |
|
4033 /* Init, if this function is available */ | 4054 /* Init, if this function is available */ |
4034 if (dev->init) { 4035 ret = dev->init(dev); | 4055 if (dev->netdev_ops->ndo_init) { 4056 ret = dev->netdev_ops->ndo_init(dev); |
4036 if (ret) { 4037 if (ret > 0) 4038 ret = -EIO; 4039 goto out; 4040 } 4041 } 4042 4043 if (!dev_valid_name(dev->name)) { --- 61 unchanged lines hidden (view full) --- 4105 rollback_registered(dev); 4106 dev->reg_state = NETREG_UNREGISTERED; 4107 } 4108 4109out: 4110 return ret; 4111 4112err_uninit: | 4057 if (ret) { 4058 if (ret > 0) 4059 ret = -EIO; 4060 goto out; 4061 } 4062 } 4063 4064 if (!dev_valid_name(dev->name)) { --- 61 unchanged lines hidden (view full) --- 4126 rollback_registered(dev); 4127 dev->reg_state = NETREG_UNREGISTERED; 4128 } 4129 4130out: 4131 return ret; 4132 4133err_uninit: |
4113 if (dev->uninit) 4114 dev->uninit(dev); | 4134 if (dev->netdev_ops->ndo_uninit) 4135 dev->netdev_ops->ndo_uninit(dev); |
4115 goto out; 4116} 4117 4118/** 4119 * register_netdev - register a network device 4120 * @dev: device to register 4121 * 4122 * Take a completed network device structure and add it to the kernel --- 335 unchanged lines hidden (view full) --- 4458 4459 ASSERT_RTNL(); 4460 4461 /* Don't allow namespace local devices to be moved. */ 4462 err = -EINVAL; 4463 if (dev->features & NETIF_F_NETNS_LOCAL) 4464 goto out; 4465 | 4136 goto out; 4137} 4138 4139/** 4140 * register_netdev - register a network device 4141 * @dev: device to register 4142 * 4143 * Take a completed network device structure and add it to the kernel --- 335 unchanged lines hidden (view full) --- 4479 4480 ASSERT_RTNL(); 4481 4482 /* Don't allow namespace local devices to be moved. */ 4483 err = -EINVAL; 4484 if (dev->features & NETIF_F_NETNS_LOCAL) 4485 goto out; 4486 |
4487#ifdef CONFIG_SYSFS 4488 /* Don't allow real devices to be moved when sysfs 4489 * is enabled. 4490 */ 4491 err = -EINVAL; 4492 if (dev->dev.parent) 4493 goto out; 4494#endif 4495 |
|
4466 /* Ensure the device has been registrered */ 4467 err = -EINVAL; 4468 if (dev->reg_state != NETREG_REGISTERED) 4469 goto out; 4470 4471 /* Get out if there is nothing todo */ 4472 err = 0; 4473 if (net_eq(dev_net(dev), net)) --- 41 unchanged lines hidden (view full) --- 4515 */ 4516 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 4517 4518 /* 4519 * Flush the unicast and multicast chains 4520 */ 4521 dev_addr_discard(dev); 4522 | 4496 /* Ensure the device has been registrered */ 4497 err = -EINVAL; 4498 if (dev->reg_state != NETREG_REGISTERED) 4499 goto out; 4500 4501 /* Get out if there is nothing todo */ 4502 err = 0; 4503 if (net_eq(dev_net(dev), net)) --- 41 unchanged lines hidden (view full) --- 4545 */ 4546 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 4547 4548 /* 4549 * Flush the unicast and multicast chains 4550 */ 4551 dev_addr_discard(dev); 4552 |
4553 netdev_unregister_kobject(dev); 4554 |
|
4523 /* Actually switch the network namespace */ 4524 dev_net_set(dev, net); 4525 4526 /* Assign the new device name */ 4527 if (destname != dev->name) 4528 strcpy(dev->name, destname); 4529 4530 /* If there is an ifindex conflict assign a new one */ 4531 if (__dev_get_by_index(net, dev->ifindex)) { 4532 int iflink = (dev->iflink == dev->ifindex); 4533 dev->ifindex = dev_new_index(net); 4534 if (iflink) 4535 dev->iflink = dev->ifindex; 4536 } 4537 4538 /* Fixup kobjects */ | 4555 /* Actually switch the network namespace */ 4556 dev_net_set(dev, net); 4557 4558 /* Assign the new device name */ 4559 if (destname != dev->name) 4560 strcpy(dev->name, destname); 4561 4562 /* If there is an ifindex conflict assign a new one */ 4563 if (__dev_get_by_index(net, dev->ifindex)) { 4564 int iflink = (dev->iflink == dev->ifindex); 4565 dev->ifindex = dev_new_index(net); 4566 if (iflink) 4567 dev->iflink = dev->ifindex; 4568 } 4569 4570 /* Fixup kobjects */ |
4539 netdev_unregister_kobject(dev); | |
4540 err = netdev_register_kobject(dev); 4541 WARN_ON(err); 4542 4543 /* Add the device back in the hashes */ 4544 list_netdevice(dev); 4545 4546 /* Notify protocols, that a new device appeared. */ 4547 call_netdevice_notifiers(NETDEV_REGISTER, dev); --- 290 unchanged lines hidden (view full) --- 4838 for_each_netdev_safe(net, dev, next) { 4839 int err; 4840 char fb_name[IFNAMSIZ]; 4841 4842 /* Ignore unmoveable devices (i.e. loopback) */ 4843 if (dev->features & NETIF_F_NETNS_LOCAL) 4844 continue; 4845 | 4571 err = netdev_register_kobject(dev); 4572 WARN_ON(err); 4573 4574 /* Add the device back in the hashes */ 4575 list_netdevice(dev); 4576 4577 /* Notify protocols, that a new device appeared. */ 4578 call_netdevice_notifiers(NETDEV_REGISTER, dev); --- 290 unchanged lines hidden (view full) --- 4869 for_each_netdev_safe(net, dev, next) { 4870 int err; 4871 char fb_name[IFNAMSIZ]; 4872 4873 /* Ignore unmoveable devices (i.e. loopback) */ 4874 if (dev->features & NETIF_F_NETNS_LOCAL) 4875 continue; 4876 |
4877 /* Delete virtual devices */ 4878 if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) { 4879 dev->rtnl_link_ops->dellink(dev); 4880 continue; 4881 } 4882 |
|
4846 /* Push remaing network devices to init_net */ 4847 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); 4848 err = dev_change_net_namespace(dev, &init_net, fb_name); 4849 if (err) { 4850 printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n", 4851 __func__, dev->name, err); 4852 BUG(); 4853 } --- 30 unchanged lines hidden (view full) --- 4884 4885 INIT_LIST_HEAD(&ptype_all); 4886 for (i = 0; i < PTYPE_HASH_SIZE; i++) 4887 INIT_LIST_HEAD(&ptype_base[i]); 4888 4889 if (register_pernet_subsys(&netdev_net_ops)) 4890 goto out; 4891 | 4883 /* Push remaing network devices to init_net */ 4884 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); 4885 err = dev_change_net_namespace(dev, &init_net, fb_name); 4886 if (err) { 4887 printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n", 4888 __func__, dev->name, err); 4889 BUG(); 4890 } --- 30 unchanged lines hidden (view full) --- 4921 4922 INIT_LIST_HEAD(&ptype_all); 4923 for (i = 0; i < PTYPE_HASH_SIZE; i++) 4924 INIT_LIST_HEAD(&ptype_base[i]); 4925 4926 if (register_pernet_subsys(&netdev_net_ops)) 4927 goto out; 4928 |
4892 if (register_pernet_device(&default_device_ops)) 4893 goto out; 4894 | |
4895 /* 4896 * Initialise the packet receive queues. 4897 */ 4898 4899 for_each_possible_cpu(i) { 4900 struct softnet_data *queue; 4901 4902 queue = &per_cpu(softnet_data, i); 4903 skb_queue_head_init(&queue->input_pkt_queue); 4904 queue->completion_queue = NULL; 4905 INIT_LIST_HEAD(&queue->poll_list); 4906 4907 queue->backlog.poll = process_backlog; 4908 queue->backlog.weight = weight_p; 4909 } 4910 | 4929 /* 4930 * Initialise the packet receive queues. 4931 */ 4932 4933 for_each_possible_cpu(i) { 4934 struct softnet_data *queue; 4935 4936 queue = &per_cpu(softnet_data, i); 4937 skb_queue_head_init(&queue->input_pkt_queue); 4938 queue->completion_queue = NULL; 4939 INIT_LIST_HEAD(&queue->poll_list); 4940 4941 queue->backlog.poll = process_backlog; 4942 queue->backlog.weight = weight_p; 4943 } 4944 |
4911 netdev_dma_register(); 4912 | |
4913 dev_boot_phase = 0; 4914 | 4945 dev_boot_phase = 0; 4946 |
4947 /* The loopback device is special if any other network devices 4948 * is present in a network namespace the loopback device must 4949 * be present. Since we now dynamically allocate and free the 4950 * loopback device ensure this invariant is maintained by 4951 * keeping the loopback device as the first device on the 4952 * list of network devices. Ensuring the loopback devices 4953 * is the first device that appears and the last network device 4954 * that disappears. 4955 */ 4956 if (register_pernet_device(&loopback_net_ops)) 4957 goto out; 4958 4959 if (register_pernet_device(&default_device_ops)) 4960 goto out; 4961 4962 netdev_dma_register(); 4963 |
|
4915 open_softirq(NET_TX_SOFTIRQ, net_tx_action); 4916 open_softirq(NET_RX_SOFTIRQ, net_rx_action); 4917 4918 hotcpu_notifier(dev_cpu_callback, 0); 4919 dst_init(); 4920 dev_mcast_init(); 4921 rc = 0; 4922out: --- 49 unchanged lines hidden --- | 4964 open_softirq(NET_TX_SOFTIRQ, net_tx_action); 4965 open_softirq(NET_RX_SOFTIRQ, net_rx_action); 4966 4967 hotcpu_notifier(dev_cpu_callback, 0); 4968 dst_init(); 4969 dev_mcast_init(); 4970 rc = 0; 4971out: --- 49 unchanged lines hidden --- |