]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/8021q/vlan_dev.c
[NET]: Move hardware header operations out of netdevice.
[linux-2.6-omap-h63xx.git] / net / 8021q / vlan_dev.c
index 95afe387b95296ca3e1ffb1006ffa80d0b8849f4..1a1740aa9a8b52ced5b71c4b2443b2eea773c0a7 100644 (file)
@@ -116,12 +116,27 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
                  struct packet_type* ptype, struct net_device *orig_dev)
 {
        unsigned char *rawp = NULL;
-       struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data);
+       struct vlan_hdr *vhdr;
        unsigned short vid;
        struct net_device_stats *stats;
        unsigned short vlan_TCI;
        __be16 proto;
 
+       if (dev->nd_net != &init_net) {
+               kfree_skb(skb);
+               return -1;
+       }
+
+       if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
+               return -1;
+
+       if (unlikely(!pskb_may_pull(skb, VLAN_HLEN))) {
+               kfree_skb(skb);
+               return -1;
+       }
+
+       vhdr = (struct vlan_hdr *)(skb->data);
+
        /* vlan_TCI = ntohs(get_unaligned(&vhdr->h_vlan_TCI)); */
        vlan_TCI = ntohs(vhdr->h_vlan_TCI);
 
@@ -328,8 +343,8 @@ static inline unsigned short vlan_dev_get_egress_qos_mask(struct net_device* dev
  *  physical devices.
  */
 int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
-                        unsigned short type, void *daddr, void *saddr,
-                        unsigned len)
+                        unsigned short type,
+                        const void *daddr, const void *saddr, unsigned len)
 {
        struct vlan_hdr *vhdr;
        unsigned short veth_TCI = 0;
@@ -419,21 +434,19 @@ int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
 
        if (build_vlan_header) {
                /* Now make the underlying real hard header */
-               rc = dev->hard_header(skb, dev, ETH_P_8021Q, daddr, saddr, len + VLAN_HLEN);
-
-               if (rc > 0) {
+               rc = dev_hard_header(skb, dev, ETH_P_8021Q, daddr, saddr,
+                                    len + VLAN_HLEN);
+               if (rc > 0)
                        rc += VLAN_HLEN;
-               } else if (rc < 0) {
+               else if (rc < 0)
                        rc -= VLAN_HLEN;
-               }
-       } else {
+       } else
                /* If here, then we'll just make a normal looking ethernet frame,
                 * but, the hard_start_xmit method will insert the tag (it has to
                 * be able to do this for bridged and other skbs that don't come
                 * down the protocol stack in an orderly manner.
                 */
-               rc = dev->hard_header(skb, dev, type, daddr, saddr, len);
-       }
+               rc = dev_hard_header(skb, dev, type, daddr, saddr, len);
 
        return rc;
 }
@@ -612,139 +625,43 @@ void vlan_dev_get_vid(const struct net_device *dev, unsigned short *result)
        *result = VLAN_DEV_INFO(dev)->vlan_id;
 }
 
-int vlan_dev_set_mac_address(struct net_device *dev, void *addr_struct_p)
-{
-       struct sockaddr *addr = (struct sockaddr *)(addr_struct_p);
-       int i;
-
-       if (netif_running(dev))
-               return -EBUSY;
-
-       memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
-
-       printk("%s: Setting MAC address to ", dev->name);
-       for (i = 0; i < 6; i++)
-               printk(" %2.2x", dev->dev_addr[i]);
-       printk(".\n");
-
-       if (memcmp(VLAN_DEV_INFO(dev)->real_dev->dev_addr,
-                  dev->dev_addr,
-                  dev->addr_len) != 0) {
-               if (!(VLAN_DEV_INFO(dev)->real_dev->flags & IFF_PROMISC)) {
-                       int flgs = VLAN_DEV_INFO(dev)->real_dev->flags;
-
-                       /* Increment our in-use promiscuity counter */
-                       dev_set_promiscuity(VLAN_DEV_INFO(dev)->real_dev, 1);
-
-                       /* Make PROMISC visible to the user. */
-                       flgs |= IFF_PROMISC;
-                       printk("VLAN (%s):  Setting underlying device (%s) to promiscious mode.\n",
-                              dev->name, VLAN_DEV_INFO(dev)->real_dev->name);
-                       dev_change_flags(VLAN_DEV_INFO(dev)->real_dev, flgs);
-               }
-       } else {
-               printk("VLAN (%s):  Underlying device (%s) has same MAC, not checking promiscious mode.\n",
-                      dev->name, VLAN_DEV_INFO(dev)->real_dev->name);
-       }
-
-       return 0;
-}
-
-static inline int vlan_dmi_equals(struct dev_mc_list *dmi1,
-                                 struct dev_mc_list *dmi2)
-{
-       return ((dmi1->dmi_addrlen == dmi2->dmi_addrlen) &&
-               (memcmp(dmi1->dmi_addr, dmi2->dmi_addr, dmi1->dmi_addrlen) == 0));
-}
-
-/** dmi is a single entry into a dev_mc_list, a single node.  mc_list is
- *  an entire list, and we'll iterate through it.
- */
-static int vlan_should_add_mc(struct dev_mc_list *dmi, struct dev_mc_list *mc_list)
+int vlan_dev_open(struct net_device *dev)
 {
-       struct dev_mc_list *idmi;
-
-       for (idmi = mc_list; idmi != NULL; ) {
-               if (vlan_dmi_equals(dmi, idmi)) {
-                       if (dmi->dmi_users > idmi->dmi_users)
-                               return 1;
-                       else
-                               return 0;
-               } else {
-                       idmi = idmi->next;
-               }
-       }
-
-       return 1;
-}
+       struct vlan_dev_info *vlan = VLAN_DEV_INFO(dev);
+       struct net_device *real_dev = vlan->real_dev;
+       int err;
 
-static inline void vlan_destroy_mc_list(struct dev_mc_list *mc_list)
-{
-       struct dev_mc_list *dmi = mc_list;
-       struct dev_mc_list *next;
+       if (!(real_dev->flags & IFF_UP))
+               return -ENETDOWN;
 
-       while(dmi) {
-               next = dmi->next;
-               kfree(dmi);
-               dmi = next;
+       if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) {
+               err = dev_unicast_add(real_dev, dev->dev_addr, ETH_ALEN);
+               if (err < 0)
+                       return err;
        }
-}
+       memcpy(vlan->real_dev_addr, real_dev->dev_addr, ETH_ALEN);
 
-static void vlan_copy_mc_list(struct dev_mc_list *mc_list, struct vlan_dev_info *vlan_info)
-{
-       struct dev_mc_list *dmi, *new_dmi;
-
-       vlan_destroy_mc_list(vlan_info->old_mc_list);
-       vlan_info->old_mc_list = NULL;
+       if (dev->flags & IFF_ALLMULTI)
+               dev_set_allmulti(real_dev, 1);
+       if (dev->flags & IFF_PROMISC)
+               dev_set_promiscuity(real_dev, 1);
 
-       for (dmi = mc_list; dmi != NULL; dmi = dmi->next) {
-               new_dmi = kmalloc(sizeof(*new_dmi), GFP_ATOMIC);
-               if (new_dmi == NULL) {
-                       printk(KERN_ERR "vlan: cannot allocate memory. "
-                              "Multicast may not work properly from now.\n");
-                       return;
-               }
-
-               /* Copy whole structure, then make new 'next' pointer */
-               *new_dmi = *dmi;
-               new_dmi->next = vlan_info->old_mc_list;
-               vlan_info->old_mc_list = new_dmi;
-       }
+       return 0;
 }
 
-static void vlan_flush_mc_list(struct net_device *dev)
+int vlan_dev_stop(struct net_device *dev)
 {
-       struct dev_mc_list *dmi = dev->mc_list;
-
-       while (dmi) {
-               printk(KERN_DEBUG "%s: del %.2x:%.2x:%.2x:%.2x:%.2x:%.2x mcast address from vlan interface\n",
-                      dev->name,
-                      dmi->dmi_addr[0],
-                      dmi->dmi_addr[1],
-                      dmi->dmi_addr[2],
-                      dmi->dmi_addr[3],
-                      dmi->dmi_addr[4],
-                      dmi->dmi_addr[5]);
-               dev_mc_delete(dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-               dmi = dev->mc_list;
-       }
-
-       /* dev->mc_list is NULL by the time we get here. */
-       vlan_destroy_mc_list(VLAN_DEV_INFO(dev)->old_mc_list);
-       VLAN_DEV_INFO(dev)->old_mc_list = NULL;
-}
+       struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
 
-int vlan_dev_open(struct net_device *dev)
-{
-       if (!(VLAN_DEV_INFO(dev)->real_dev->flags & IFF_UP))
-               return -ENETDOWN;
+       dev_mc_unsync(real_dev, dev);
+       if (dev->flags & IFF_ALLMULTI)
+               dev_set_allmulti(real_dev, -1);
+       if (dev->flags & IFF_PROMISC)
+               dev_set_promiscuity(real_dev, -1);
 
-       return 0;
-}
+       if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr))
+               dev_unicast_delete(real_dev, dev->dev_addr, dev->addr_len);
 
-int vlan_dev_stop(struct net_device *dev)
-{
-       vlan_flush_mc_list(dev);
        return 0;
 }
 
@@ -764,9 +681,6 @@ int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                if (real_dev->do_ioctl && netif_device_present(real_dev))
                        err = real_dev->do_ioctl(real_dev, &ifrr, cmd);
                break;
-
-       case SIOCETHTOOL:
-               err = dev_ethtool(&ifrr);
        }
 
        if (!err)
@@ -775,68 +689,18 @@ int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        return err;
 }
 
-/** Taken from Gleb + Lennert's VLAN code, and modified... */
-void vlan_dev_set_multicast_list(struct net_device *vlan_dev)
+void vlan_change_rx_flags(struct net_device *dev, int change)
 {
-       struct dev_mc_list *dmi;
-       struct net_device *real_dev;
-       int inc;
-
-       if (vlan_dev && (vlan_dev->priv_flags & IFF_802_1Q_VLAN)) {
-               /* Then it's a real vlan device, as far as we can tell.. */
-               real_dev = VLAN_DEV_INFO(vlan_dev)->real_dev;
-
-               /* compare the current promiscuity to the last promisc we had.. */
-               inc = vlan_dev->promiscuity - VLAN_DEV_INFO(vlan_dev)->old_promiscuity;
-               if (inc) {
-                       printk(KERN_INFO "%s: dev_set_promiscuity(master, %d)\n",
-                              vlan_dev->name, inc);
-                       dev_set_promiscuity(real_dev, inc); /* found in dev.c */
-                       VLAN_DEV_INFO(vlan_dev)->old_promiscuity = vlan_dev->promiscuity;
-               }
-
-               inc = vlan_dev->allmulti - VLAN_DEV_INFO(vlan_dev)->old_allmulti;
-               if (inc) {
-                       printk(KERN_INFO "%s: dev_set_allmulti(master, %d)\n",
-                              vlan_dev->name, inc);
-                       dev_set_allmulti(real_dev, inc); /* dev.c */
-                       VLAN_DEV_INFO(vlan_dev)->old_allmulti = vlan_dev->allmulti;
-               }
-
-               /* looking for addresses to add to master's list */
-               for (dmi = vlan_dev->mc_list; dmi != NULL; dmi = dmi->next) {
-                       if (vlan_should_add_mc(dmi, VLAN_DEV_INFO(vlan_dev)->old_mc_list)) {
-                               dev_mc_add(real_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-                               printk(KERN_DEBUG "%s: add %.2x:%.2x:%.2x:%.2x:%.2x:%.2x mcast address to master interface\n",
-                                      vlan_dev->name,
-                                      dmi->dmi_addr[0],
-                                      dmi->dmi_addr[1],
-                                      dmi->dmi_addr[2],
-                                      dmi->dmi_addr[3],
-                                      dmi->dmi_addr[4],
-                                      dmi->dmi_addr[5]);
-                       }
-               }
+       struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
 
-               /* looking for addresses to delete from master's list */
-               for (dmi = VLAN_DEV_INFO(vlan_dev)->old_mc_list; dmi != NULL; dmi = dmi->next) {
-                       if (vlan_should_add_mc(dmi, vlan_dev->mc_list)) {
-                               /* if we think we should add it to the new list, then we should really
-                                * delete it from the real list on the underlying device.
-                                */
-                               dev_mc_delete(real_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
-                               printk(KERN_DEBUG "%s: del %.2x:%.2x:%.2x:%.2x:%.2x:%.2x mcast address from master interface\n",
-                                      vlan_dev->name,
-                                      dmi->dmi_addr[0],
-                                      dmi->dmi_addr[1],
-                                      dmi->dmi_addr[2],
-                                      dmi->dmi_addr[3],
-                                      dmi->dmi_addr[4],
-                                      dmi->dmi_addr[5]);
-                       }
-               }
+       if (change & IFF_ALLMULTI)
+               dev_set_allmulti(real_dev, dev->flags & IFF_ALLMULTI ? 1 : -1);
+       if (change & IFF_PROMISC)
+               dev_set_promiscuity(real_dev, dev->flags & IFF_PROMISC ? 1 : -1);
+}
 
-               /* save multicast list */
-               vlan_copy_mc_list(vlan_dev->mc_list, VLAN_DEV_INFO(vlan_dev));
-       }
+/** Taken from Gleb + Lennert's VLAN code, and modified... */
+void vlan_dev_set_multicast_list(struct net_device *vlan_dev)
+{
+       dev_mc_sync(VLAN_DEV_INFO(vlan_dev)->real_dev, vlan_dev);
 }