root/net/inet/dev_mcast.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. dev_mc_upload
  2. dev_mc_delete
  3. dev_mc_add
  4. dev_mc_discard

   1 /*
   2  *      Linux NET3:     Multicast List maintenance. 
   3  *
   4  *      Authors:
   5  *              Tim Kordas <tjk@nostromo.eeap.cwru.edu> 
   6  *              Richard Underwood <richard@wuzz.demon.co.uk>
   7  *
   8  *      Stir fried together from the IP multicast and CAP patches above
   9  *              Alan Cox <Alan.Cox@linux.org>   
  10  *
  11  *      This program is free software; you can redistribute it and/or
  12  *      modify it under the terms of the GNU General Public License
  13  *      as published by the Free Software Foundation; either version
  14  *      2 of the License, or (at your option) any later version.
  15  */
  16  
  17 #include <asm/segment.h>
  18 #include <asm/system.h>
  19 #include <asm/bitops.h>
  20 #include <linux/types.h>
  21 #include <linux/kernel.h>
  22 #include <linux/sched.h>
  23 #include <linux/string.h>
  24 #include <linux/mm.h>
  25 #include <linux/socket.h>
  26 #include <linux/sockios.h>
  27 #include <linux/in.h>
  28 #include <linux/errno.h>
  29 #include <linux/interrupt.h>
  30 #include <linux/if_ether.h>
  31 #include <linux/inet.h>
  32 #include <linux/netdevice.h>
  33 #include <linux/etherdevice.h>
  34 #include "ip.h"
  35 #include "route.h"
  36 #include <linux/skbuff.h>
  37 #include "sock.h"
  38 #include "arp.h"
  39 
  40 
  41 /*
  42  *      Device multicast list maintenance. This knows about such little matters as promiscuous mode and
  43  *      converting from the list to the array the drivers use. At least until I fix the drivers up.
  44  *
  45  *      This is used both by IP and by the user level maintenance functions. Unlike BSD we maintain a usage count
  46  *      on a given multicast address so that a casual user application can add/delete multicasts used by protocols
  47  *      without doing damage to the protocols when it deletes the entries. It also helps IP as it tracks overlapping
  48  *      maps.
  49  */
  50  
  51 
  52 /*
  53  *      Update the multicast list into the physical NIC controller.
  54  */
  55  
  56 void dev_mc_upload(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58         struct dev_mc_list *dmi;
  59         char *data, *tmp;
  60 
  61         /* Don't do anything till we up the interface
  62            [dev_open will call this function so the list will
  63             stay sane] */
  64             
  65         if(!(dev->flags&IFF_UP))
  66                 return;
  67                 
  68                 
  69         /* Devices with no set multicast don't get set */
  70         if(dev->set_multicast_list==NULL)
  71                 return;
  72         /* Promiscuous is promiscuous - so no filter needed */
  73         if(dev->flags&IFF_PROMISC)
  74         {
  75                 dev->set_multicast_list(dev, -1, NULL);
  76                 return;
  77         }
  78         
  79         if(dev->mc_count==0)
  80         {
  81                 dev->set_multicast_list(dev,0,NULL);
  82                 return;
  83         }
  84         
  85         data=kmalloc(dev->mc_count*dev->addr_len, GFP_KERNEL);
  86         if(data==NULL)
  87         {
  88                 printk("Unable to get memory to set multicast list on %s\n",dev->name);
  89                 return;
  90         }
  91         for(tmp = data, dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
  92         {
  93                 memcpy(tmp,dmi->dmi_addr, dmi->dmi_addrlen);
  94                 tmp+=dev->addr_len;
  95         }
  96         dev->set_multicast_list(dev,dev->mc_count,data);
  97         kfree(data);
  98 }
  99   
 100 /*
 101  *      Delete a device level multicast
 102  */
 103  
 104 void dev_mc_delete(struct device *dev, void *addr, int alen, int all)
     /* [previous][next][first][last][top][bottom][index][help] */
 105 {
 106         struct dev_mc_list **dmi;
 107         for(dmi=&dev->mc_list;*dmi!=NULL;dmi=&(*dmi)->next)
 108         {
 109                 if(memcmp((*dmi)->dmi_addr,addr,(*dmi)->dmi_addrlen)==0 && alen==(*dmi)->dmi_addrlen)
 110                 {
 111                         struct dev_mc_list *tmp= *dmi;
 112                         if(--(*dmi)->dmi_users && !all)
 113                                 return;
 114                         *dmi=(*dmi)->next;
 115                         dev->mc_count--;
 116                         kfree_s(tmp,sizeof(*tmp));
 117                         return;
 118                 }
 119         }
 120         dev_mc_upload(dev);
 121 }
 122 
 123 /*
 124  *      Add a device level multicast
 125  */
 126  
 127 void dev_mc_add(struct device *dev, void *addr, int alen, int newonly)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129         struct dev_mc_list *dmi;
 130         for(dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
 131         {
 132                 if(memcmp(dmi->dmi_addr,addr,dmi->dmi_addrlen)==0 && dmi->dmi_addrlen==alen)
 133                 {
 134                         if(!newonly)
 135                                 dmi->dmi_users++;
 136                         return;
 137                 }
 138         }
 139         dmi=(struct dev_mc_list *)kmalloc(sizeof(*dmi),GFP_KERNEL);
 140         if(dmi==NULL)
 141                 return; /* GFP_KERNEL so can't happen anyway */
 142         memcpy(dmi->dmi_addr, addr, alen);
 143         dmi->dmi_addrlen=alen;
 144         dmi->next=dev->mc_list;
 145         dmi->dmi_users=1;
 146         dev->mc_list=dmi;
 147         dev->mc_count++;
 148         dev_mc_upload(dev);
 149 }
 150 
 151 /*
 152  *      Discard multicast list when a device is downed
 153  */
 154 
 155 void dev_mc_discard(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 156 {
 157         while(dev->mc_list!=NULL)
 158         {
 159                 struct dev_mc_list *tmp=dev->mc_list;
 160                 dev->mc_list=dev->mc_list->next;
 161                 kfree_s(tmp,sizeof(*tmp));
 162         }
 163         dev->mc_count=0;
 164 }
 165 

/* [previous][next][first][last][top][bottom][index][help] */