rk: revert 20f3d0b+v3.0.66 to v3.0
[firefly-linux-kernel-4.4.55.git] / net / core / dev.c
index 465f1f62766e94d5dfad503d2b603942c9ec429b..9c58c1ec41a9dba24cca0318f723b01208c7b880 100644 (file)
@@ -1045,8 +1045,6 @@ rollback:
  */
 int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 {
-       char *new_ifalias;
-
        ASSERT_RTNL();
 
        if (len >= IFALIASZ)
@@ -1060,10 +1058,9 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
                return 0;
        }
 
-       new_ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
-       if (!new_ifalias)
+       dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
+       if (!dev->ifalias)
                return -ENOMEM;
-       dev->ifalias = new_ifalias;
 
        strlcpy(dev->ifalias, alias, len+1);
        return len;
@@ -1166,7 +1163,6 @@ static int __dev_open(struct net_device *dev)
                net_dmaengine_get();
                dev_set_rx_mode(dev);
                dev_activate(dev);
-               add_device_randomness(dev->dev_addr, dev->addr_len);
        }
 
        return ret;
@@ -1410,34 +1406,14 @@ EXPORT_SYMBOL(register_netdevice_notifier);
  *     register_netdevice_notifier(). The notifier is unlinked into the
  *     kernel structures and may then be reused. A negative errno code
  *     is returned on a failure.
- *
- *     After unregistering unregister and down device events are synthesized
- *     for all devices on the device list to the removed notifier to remove
- *     the need for special case cleanup code.
  */
 
 int unregister_netdevice_notifier(struct notifier_block *nb)
 {
-       struct net_device *dev;
-       struct net *net;
        int err;
 
        rtnl_lock();
        err = raw_notifier_chain_unregister(&netdev_chain, nb);
-       if (err)
-               goto unlock;
-
-       for_each_net(net) {
-               for_each_netdev(net, dev) {
-                       if (dev->flags & IFF_UP) {
-                               nb->notifier_call(nb, NETDEV_GOING_DOWN, dev);
-                               nb->notifier_call(nb, NETDEV_DOWN, dev);
-                       }
-                       nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
-                       nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev);
-               }
-       }
-unlock:
        rtnl_unlock();
        return err;
 }
@@ -1537,14 +1513,10 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
                kfree_skb(skb);
                return NET_RX_DROP;
        }
-       skb->dev = dev;
-       skb_dst_drop(skb);
+       skb_set_dev(skb, dev);
        skb->tstamp.tv64 = 0;
        skb->pkt_type = PACKET_HOST;
        skb->protocol = eth_type_trans(skb, dev);
-       skb->mark = 0;
-       secpath_reset(skb);
-       nf_reset(skb);
        return netif_rx(skb);
 }
 EXPORT_SYMBOL_GPL(dev_forward_skb);
@@ -1799,6 +1771,36 @@ void netif_device_attach(struct net_device *dev)
 }
 EXPORT_SYMBOL(netif_device_attach);
 
+/**
+ * skb_dev_set -- assign a new device to a buffer
+ * @skb: buffer for the new device
+ * @dev: network device
+ *
+ * If an skb is owned by a device already, we have to reset
+ * all data private to the namespace a device belongs to
+ * before assigning it a new device.
+ */
+#ifdef CONFIG_NET_NS
+void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
+{
+       skb_dst_drop(skb);
+       if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) {
+               secpath_reset(skb);
+               nf_reset(skb);
+               skb_init_secmark(skb);
+               skb->mark = 0;
+               skb->priority = 0;
+               skb->nf_trace = 0;
+               skb->ipvs_property = 0;
+#ifdef CONFIG_NET_SCHED
+               skb->tc_index = 0;
+#endif
+       }
+       skb->dev = dev;
+}
+EXPORT_SYMBOL(skb_set_dev);
+#endif /* CONFIG_NET_NS */
+
 /*
  * Invalidate hardware checksum when packet is to be mangled, and
  * complete checksum manually on outgoing path.
@@ -2038,8 +2040,7 @@ static bool can_checksum_protocol(unsigned long features, __be16 protocol)
 
 static u32 harmonize_features(struct sk_buff *skb, __be16 protocol, u32 features)
 {
-       if (skb->ip_summed != CHECKSUM_NONE &&
-           !can_checksum_protocol(features, protocol)) {
+       if (!can_checksum_protocol(features, protocol)) {
                features &= ~NETIF_F_ALL_CSUM;
                features &= ~NETIF_F_SG;
        } else if (illegal_highdma(skb->dev, skb)) {
@@ -2054,9 +2055,6 @@ u32 netif_skb_features(struct sk_buff *skb)
        __be16 protocol = skb->protocol;
        u32 features = skb->dev->features;
 
-       if (skb_shinfo(skb)->gso_segs > skb->dev->gso_max_segs)
-               features &= ~NETIF_F_GSO_MASK;
-
        if (protocol == htons(ETH_P_8021Q)) {
                struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
                protocol = veh->h_vlan_encapsulated_proto;
@@ -2560,17 +2558,16 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
        poff = proto_ports_offset(ip_proto);
        if (poff >= 0) {
                nhoff += ihl * 4 + poff;
-               if (pskb_may_pull(skb, nhoff + 4))
+               if (pskb_may_pull(skb, nhoff + 4)) {
                        ports.v32 = * (__force u32 *) (skb->data + nhoff);
+                       if (ports.v16[1] < ports.v16[0])
+                               swap(ports.v16[0], ports.v16[1]);
+               }
        }
 
        /* get a consistent hash (same value on both flow directions) */
-       if (addr2 < addr1 ||
-           (addr2 == addr1 &&
-            ports.v16[1] < ports.v16[0])) {
+       if (addr2 < addr1)
                swap(addr1, addr2);
-               swap(ports.v16[0], ports.v16[1]);
-       }
 
        hash = jhash_3words(addr1, addr2, ports.v32, hashrnd);
        if (!hash)
@@ -2706,10 +2703,8 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
                if (unlikely(tcpu != next_cpu) &&
                    (tcpu == RPS_NO_CPU || !cpu_online(tcpu) ||
                     ((int)(per_cpu(softnet_data, tcpu).input_queue_head -
-                     rflow->last_qtail)) >= 0)) {
-                       tcpu = next_cpu;
+                     rflow->last_qtail)) >= 0))
                        rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
-               }
 
                if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) {
                        *rflowp = rflow;
@@ -3439,20 +3434,14 @@ static inline gro_result_t
 __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
 {
        struct sk_buff *p;
-       unsigned int maclen = skb->dev->hard_header_len;
 
        for (p = napi->gro_list; p; p = p->next) {
                unsigned long diffs;
 
                diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev;
                diffs |= p->vlan_tci ^ skb->vlan_tci;
-               if (maclen == ETH_HLEN)
-                       diffs |= compare_ether_header(skb_mac_header(p),
-                                                     skb_gro_mac_header(skb));
-               else if (!diffs)
-                       diffs = memcmp(skb_mac_header(p),
-                                      skb_gro_mac_header(skb),
-                                      maclen);
+               diffs |= compare_ether_header(skb_mac_header(p),
+                                             skb_gro_mac_header(skb));
                NAPI_GRO_CB(p)->same_flow = !diffs;
                NAPI_GRO_CB(p)->flush = 0;
        }
@@ -3509,8 +3498,7 @@ EXPORT_SYMBOL(napi_gro_receive);
 static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
 {
        __skb_pull(skb, skb_headlen(skb));
-       /* restore the reserve we had after netdev_alloc_skb_ip_align() */
-       skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN - skb_headroom(skb));
+       skb_reserve(skb, NET_IP_ALIGN - skb_headroom(skb));
        skb->vlan_tci = 0;
        skb->dev = napi->dev;
        skb->skb_iif = 0;
@@ -4741,7 +4729,6 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
        err = ops->ndo_set_mac_address(dev, sa);
        if (!err)
                call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
-       add_device_randomness(dev->dev_addr, dev->addr_len);
        return err;
 }
 EXPORT_SYMBOL(dev_set_mac_address);
@@ -5519,7 +5506,6 @@ int register_netdevice(struct net_device *dev)
        dev_init_scheduler(dev);
        dev_hold(dev);
        list_netdevice(dev);
-       add_device_randomness(dev->dev_addr, dev->addr_len);
 
        /* Notify protocols, that a new device appeared. */
        ret = call_netdevice_notifiers(NETDEV_REGISTER, dev);
@@ -5880,7 +5866,6 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
        dev_net_set(dev, &init_net);
 
        dev->gso_max_size = GSO_MAX_SIZE;
-       dev->gso_max_segs = GSO_MAX_SEGS;
 
        INIT_LIST_HEAD(&dev->ethtool_ntuple_list.list);
        dev->ethtool_ntuple_list.count = 0;
@@ -6120,7 +6105,6 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
        */
        call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
        call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev);
-       rtmsg_ifinfo(RTM_DELLINK, dev, ~0U);
 
        /*
         *      Flush the unicast and multicast chains
@@ -6264,8 +6248,7 @@ static struct hlist_head *netdev_create_hash(void)
 /* Initialize per network namespace state */
 static int __net_init netdev_init(struct net *net)
 {
-       if (net != &init_net)
-               INIT_LIST_HEAD(&net->dev_base_head);
+       INIT_LIST_HEAD(&net->dev_base_head);
 
        net->dev_name_head = netdev_create_hash();
        if (net->dev_name_head == NULL)