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/config.h>
  21 #include <linux/types.h>
  22 #include <linux/kernel.h>
  23 #include <linux/sched.h>
  24 #include <linux/string.h>
  25 #include <linux/mm.h>
  26 #include <linux/socket.h>
  27 #include <linux/sockios.h>
  28 #include <linux/in.h>
  29 #include <linux/errno.h>
  30 #include <linux/interrupt.h>
  31 #include <linux/if_ether.h>
  32 #include <linux/inet.h>
  33 #include <linux/netdevice.h>
  34 #include <linux/etherdevice.h>
  35 #include "ip.h"
  36 #include "route.h"
  37 #include <linux/skbuff.h>
  38 #include "sock.h"
  39 #include "arp.h"
  40 
  41 
  42 /*
  43  *      Device multicast list maintenance. This knows about such little matters as promiscuous mode and
  44  *      converting from the list to the array the drivers use. At least until I fix the drivers up.
  45  *
  46  *      This is used both by IP and by the user level maintenance functions. Unlike BSD we maintain a usage count
  47  *      on a given multicast address so that a casual user application can add/delete multicasts used by protocols
  48  *      without doing damage to the protocols when it deletes the entries. It also helps IP as it tracks overlapping
  49  *      maps.
  50  */
  51  
  52 
  53 /*
  54  *      Update the multicast list into the physical NIC controller.
  55  */
  56  
  57 void dev_mc_upload(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59         struct dev_mc_list *dmi;
  60         char *data;
  61         
  62         /* Promiscuous is promiscuous - so no filter needed */
  63         
  64         if(dev->flags&IFF_PROMISC)
  65                 return;
  66                 
  67         /* Devices with no set multicast don't get set */
  68         if(dev->set_multicast_list==NULL)
  69                 return;
  70         if(dev->mc_count==0)
  71         {
  72                 dev->set_multicast_list(dev,0,NULL);
  73                 return;
  74         }
  75         
  76         data=kmalloc(dev->mc_count*dev->addr_len, GFP_KERNEL);
  77         if(data==NULL)
  78         {
  79                 printk("Unable to get memory to set multicast list on %s\n",dev->name);
  80                 return;
  81         }
  82         for(dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
  83         {
  84                 memcpy(data,dmi->dmi_addr, dmi->dmi_addrlen);
  85                 data+=dev->addr_len;
  86         }
  87         dev->set_multicast_list(dev,dev->mc_count,data);
  88         kfree_s(data,dev->mc_count*dev->addr_len);
  89 }
  90   
  91 /*
  92  *      Delete a device level multicast
  93  */
  94  
  95 void dev_mc_delete(struct device *dev, void *addr, int alen, int all)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97         struct dev_mc_list **dmi;
  98         for(dmi=&dev->mc_list;*dmi!=NULL;dmi=&(*dmi)->next)
  99         {
 100                 if(memcmp((*dmi)->dmi_addr,addr,(*dmi)->dmi_addrlen)==0 && alen==(*dmi)->dmi_addrlen)
 101                 {
 102                         struct dev_mc_list *tmp= *dmi;
 103                         if((*dmi)->dmi_users-- && !all)
 104                                 return;
 105                         *dmi=(*dmi)->next;
 106                         dev->mc_count--;
 107                         kfree_s(tmp,sizeof(*tmp));
 108                         return;
 109                 }
 110         }
 111         dev_mc_upload(dev);
 112 }
 113 
 114 /*
 115  *      Add a device level multicast
 116  */
 117  
 118 void dev_mc_add(struct device *dev, void *addr, int alen, int newonly)
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120         struct dev_mc_list *dmi;
 121         for(dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
 122         {
 123                 if(memcmp(dmi->dmi_addr,addr,dmi->dmi_addrlen)==0 && dmi->dmi_addrlen==alen)
 124                 {
 125                         if(!newonly)
 126                                 dmi->dmi_users++;
 127                         return;
 128                 }
 129         }
 130         dmi=(struct dev_mc_list *)kmalloc(sizeof(*dmi),GFP_KERNEL);
 131         if(dmi==NULL)
 132                 return; /* GFP_KERNEL so can't happen anyway */
 133         memcpy(dmi->dmi_addr, addr, alen);
 134         dmi->dmi_addrlen=alen;
 135         dmi->next=dev->mc_list;
 136         dmi->dmi_users=1;
 137         dev->mc_list=dmi;
 138         dev->mc_count++;
 139         dev_mc_upload(dev);
 140 }
 141 
 142 /*
 143  *      Discard multicast list when a device is downed
 144  */
 145 
 146 void dev_mc_discard(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148         while(dev->mc_list!=NULL)
 149         {
 150                 struct dev_mc_list *tmp=dev->mc_list;
 151                 dev->mc_list=dev->mc_list->next;
 152                 kfree_s(tmp,sizeof(*tmp));
 153         }
 154         dev->mc_count=0;
 155 }
 156 

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