[BACK]Return to mld6.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / netinet6

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/netinet6/mld6.c between version 1.4 and 1.18

version 1.4, 1999/07/04 02:01:15 version 1.18, 2002/01/08 04:37:32
Line 1 
Line 1 
 /*      $NetBSD$        */  /*      $NetBSD$        */
   /*      $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $   */
   
 /*  /*
  * Copyright (C) 1998 WIDE Project.   * Copyright (C) 1998 WIDE Project.
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
  * are met:   * are met:
Line 15 
Line 16 
  * 3. Neither the name of the project nor the names of its contributors   * 3. Neither the name of the project nor the names of its contributors
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND   * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Line 68 
Line 69 
  *      @(#)igmp.c      8.1 (Berkeley) 7/19/93   *      @(#)igmp.c      8.1 (Berkeley) 7/19/93
  */   */
   
 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)  #include <sys/cdefs.h>
   __KERNEL_RCSID(0, "$NetBSD$");
   
 #include "opt_inet.h"  #include "opt_inet.h"
 #endif  
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/systm.h>  #include <sys/systm.h>
Line 83 
Line 85 
   
 #include <netinet/in.h>  #include <netinet/in.h>
 #include <netinet/in_var.h>  #include <netinet/in_var.h>
 #include <netinet6/in6.h>  #include <netinet/ip6.h>
 #include <netinet6/ip6.h>  
 #include <netinet6/ip6_var.h>  #include <netinet6/ip6_var.h>
 #include <netinet6/icmp6.h>  #include <netinet/icmp6.h>
 #include <netinet6/mld6_var.h>  #include <netinet6/mld6_var.h>
   
   #include <net/net_osdep.h>
   
 /*  /*
  * Protocol constants   * Protocol constants
  */   */
Line 119  mld6_init()
Line 122  mld6_init()
         mld6_timers_are_running = 0;          mld6_timers_are_running = 0;
   
         /* ip6h_nxt will be fill in later */          /* ip6h_nxt will be fill in later */
         hbh->ip6h_len = 0;      /* (8 >> 3) - 1*/          hbh->ip6h_len = 0;      /* (8 >> 3) - 1 */
   
         /* XXX: grotty hard coding... */          /* XXX: grotty hard coding... */
         hbh_buf[2] = IP6OPT_PADN;       /* 2 byte padding */          hbh_buf[2] = IP6OPT_PADN;       /* 2 byte padding */
Line 140  mld6_start_listening(in6m)
Line 143  mld6_start_listening(in6m)
         int s = splsoftnet();          int s = splsoftnet();
   
         /*          /*
          * (draft-ietf-ipngwg-mld, page 10)           * RFC2710 page 10:
          * The node never sends a Report or Done for the link-scope all-nodes           * The node never sends a Report or Done for the link-scope all-nodes
          * address.           * address.
          * MLD messages are never sent for multicast addresses whose scope is 0           * MLD messages are never sent for multicast addresses whose scope is 0
Line 184  mld6_input(m, off)
Line 187  mld6_input(m, off)
         int off;          int off;
 {  {
         struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);          struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
         struct mld6_hdr *mldh = (struct mld6_hdr *)(mtod(m, caddr_t) + off);          struct mld6_hdr *mldh;
         struct ifnet *ifp = m->m_pkthdr.rcvif;          struct ifnet *ifp = m->m_pkthdr.rcvif;
         struct in6_multi *in6m;          struct in6_multi *in6m;
         struct in6_ifaddr *ia;          struct in6_ifaddr *ia;
         int timer;              /* timer value in the MLD query header */          int timer;              /* timer value in the MLD query header */
   
   #ifndef PULLDOWN_TEST
           IP6_EXTHDR_CHECK(m, off, sizeof(*mldh),);
           mldh = (struct mld6_hdr *)(mtod(m, caddr_t) + off);
   #else
           IP6_EXTHDR_GET(mldh, struct mld6_hdr *, m, off, sizeof(*mldh));
           if (mldh == NULL) {
                   icmp6stat.icp6s_tooshort++;
                   return;
           }
   #endif
   
         /* source address validation */          /* source address validation */
           ip6 = mtod(m, struct ip6_hdr *);/* in case mpullup */
         if (!IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src)) {          if (!IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src)) {
   #if 0
                 log(LOG_ERR,                  log(LOG_ERR,
                     "mld6_input: src %s is not link-local\n",                      "mld6_input: src %s is not link-local (grp=%s)\n",
                     ip6_sprintf(&ip6->ip6_src));                      ip6_sprintf(&ip6->ip6_src),
                       ip6_sprintf(&mldh->mld6_addr));
   #endif
                 /*                  /*
                  * spec(draft-ietf-ipngwg-mld) does not explicitly                   * spec (RFC2710) does not explicitly
                  * specify to discard the packet from a non link-local                   * specify to discard the packet from a non link-local
                  * source address. But we believe it's expected to do so.                   * source address. But we believe it's expected to do so.
                    * XXX: do we have to allow :: as source?
                  */                   */
                   m_freem(m);
                 return;                  return;
         }          }
   
Line 214  mld6_input(m, off)
Line 234  mld6_input(m, off)
          * we have heard a report from another member, or MLD6_IREPORTEDLAST           * we have heard a report from another member, or MLD6_IREPORTEDLAST
          * if we sent the last report.           * if we sent the last report.
          */           */
         switch(mldh->mld6_type) {          switch (mldh->mld6_type) {
          case MLD6_LISTENER_QUERY:          case MLD6_LISTENER_QUERY:
                  if (ifp->if_flags & IFF_LOOPBACK)                  if (ifp->if_flags & IFF_LOOPBACK)
                          break;                          break;
   
                  if (!IN6_IS_ADDR_UNSPECIFIED(&mldh->mld6_addr) &&                  if (!IN6_IS_ADDR_UNSPECIFIED(&mldh->mld6_addr) &&
                      !IN6_IS_ADDR_MULTICAST(&mldh->mld6_addr))                      !IN6_IS_ADDR_MULTICAST(&mldh->mld6_addr))
                          break; /* print error or log stat? */                          break;  /* print error or log stat? */
                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))
                          mldh->mld6_addr.s6_addr16[1] =                          mldh->mld6_addr.s6_addr16[1] =
                                  htons(ifp->if_index); /* XXX */                                  htons(ifp->if_index); /* XXX */
   
                 /*                  /*
                  * - Start the timers in all of our membership records                   * - Start the timers in all of our membership records
Line 236  mld6_input(m, off)
Line 256  mld6_input(m, off)
                  * - Use the value specified in the query message as                   * - Use the value specified in the query message as
                  *   the maximum timeout.                   *   the maximum timeout.
                  */                   */
                  IFP_TO_IA6(ifp, ia);                  IFP_TO_IA6(ifp, ia);
                  if (ia == NULL)                  if (ia == NULL)
                          break;                          break;
   
                  /*                  /*
                   * XXX: System timer resolution is too low to handle Max                   * XXX: System timer resolution is too low to handle Max
                   * Response Delay, so set 1 to the internal timer even if                   * Response Delay, so set 1 to the internal timer even if
                   * the calculated value equals to zero when Max Response                   * the calculated value equals to zero when Max Response
                   * Delay is positive.                   * Delay is positive.
                   */                   */
                  timer = ntohs(mldh->mld6_maxdelay)*PR_FASTHZ/MLD6_TIMER_SCALE;                  timer = ntohs(mldh->mld6_maxdelay)*PR_FASTHZ/MLD6_TIMER_SCALE;
                  if (timer == 0 && mldh->mld6_maxdelay)                  if (timer == 0 && mldh->mld6_maxdelay)
                          timer = 1;                          timer = 1;
                  mld6_all_nodes_linklocal.s6_addr16[1] =                  mld6_all_nodes_linklocal.s6_addr16[1] =
                          htons(ifp->if_index); /* XXX */                          htons(ifp->if_index); /* XXX */
   
                  for (in6m = ia->ia6_multiaddrs.lh_first;                  for (in6m = ia->ia6_multiaddrs.lh_first;
                       in6m;                       in6m;
                       in6m = in6m->in6m_entry.le_next) {                       in6m = in6m->in6m_entry.le_next)
                          if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr,                  {
                           if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr,
                                                 &mld6_all_nodes_linklocal) ||                                                  &mld6_all_nodes_linklocal) ||
                              IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) <                              IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) <
                              IPV6_ADDR_SCOPE_LINKLOCAL)                              IPV6_ADDR_SCOPE_LINKLOCAL)
                              continue;                                  continue;
   
                          if (IN6_IS_ADDR_UNSPECIFIED(&mldh->mld6_addr) ||                          if (IN6_IS_ADDR_UNSPECIFIED(&mldh->mld6_addr) ||
                              IN6_ARE_ADDR_EQUAL(&mldh->mld6_addr,                              IN6_ARE_ADDR_EQUAL(&mldh->mld6_addr,
                                                 &in6m->in6m_addr)) {                                                  &in6m->in6m_addr))
                                  if (timer == 0) {                          {
                                          /* send a report immediately */                                  if (timer == 0) {
                                          mld6_sendpkt(in6m, MLD6_LISTENER_REPORT,                                          /* send a report immediately */
                                                       NULL);                                          mld6_sendpkt(in6m, MLD6_LISTENER_REPORT,
                                          in6m->in6m_timer = 0; /* reset timer */                                                  NULL);
                                          in6m->in6m_state = MLD6_IREPORTEDLAST;                                          in6m->in6m_timer = 0; /* reset timer */
                                  }                                          in6m->in6m_state = MLD6_IREPORTEDLAST;
                                  else if (in6m->in6m_timer == 0 || /*idle state*/                                  }
                                           in6m->in6m_timer > timer) {                                  else if (in6m->in6m_timer == 0 || /*idle state*/
                                          in6m->in6m_timer =                                          in6m->in6m_timer > timer) {
                                                  MLD6_RANDOM_DELAY(timer);                                          in6m->in6m_timer =
                                          mld6_timers_are_running = 1;                                                  MLD6_RANDOM_DELAY(timer);
                                  }                                          mld6_timers_are_running = 1;
                          }                                  }
                  }                          }
                   }
                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))  
                          mldh->mld6_addr.s6_addr16[1] = 0; /* XXX */                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))
                  break;                          mldh->mld6_addr.s6_addr16[1] = 0; /* XXX */
          case MLD6_LISTENER_REPORT:                  break;
           case MLD6_LISTENER_REPORT:
                 /*                  /*
                  * For fast leave to work, we have to know that we are the                   * For fast leave to work, we have to know that we are the
                  * last person to send a report for this group.  Reports                   * last person to send a report for this group.  Reports
Line 293  mld6_input(m, off)
Line 315  mld6_input(m, off)
                  * ifp for this purpose, since ip6_mloopback pass the physical                   * ifp for this purpose, since ip6_mloopback pass the physical
                  * interface to looutput.                   * interface to looutput.
                  */                   */
                  if (m->m_flags & M_LOOP) /* XXX: grotty flag, but efficient */                  if (m->m_flags & M_LOOP) /* XXX: grotty flag, but efficient */
                          break;                          break;
   
                  if (!IN6_IS_ADDR_MULTICAST(&mldh->mld6_addr))                  if (!IN6_IS_ADDR_MULTICAST(&mldh->mld6_addr))
                          break;                          break;
   
                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))
                          mldh->mld6_addr.s6_addr16[1] =                          mldh->mld6_addr.s6_addr16[1] =
                                  htons(ifp->if_index); /* XXX */                                  htons(ifp->if_index); /* XXX */
                 /*                  /*
                  * If we belong to the group being reported, stop                   * If we belong to the group being reported, stop
                  * our timer for that group.                   * our timer for that group.
                  */                   */
                  IN6_LOOKUP_MULTI(mldh->mld6_addr, ifp, in6m);                  IN6_LOOKUP_MULTI(mldh->mld6_addr, ifp, in6m);
                  if (in6m) {                  if (in6m) {
                          in6m->in6m_timer = 0; /* transit to idle state */                          in6m->in6m_timer = 0; /* transit to idle state */
                          in6m->in6m_state = MLD6_OTHERLISTENER; /* clear flag */                          in6m->in6m_state = MLD6_OTHERLISTENER; /* clear flag */
                  }                  }
   
                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))                  if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))
                          mldh->mld6_addr.s6_addr16[1] = 0; /* XXX */                          mldh->mld6_addr.s6_addr16[1] = 0; /* XXX */
                  break;                  break;
          default:               /* this is impossible */          default:                /* this is impossible */
                  log(LOG_ERR, "mld6_input: illegal type(%d)", mldh->mld6_type);  #if 0
                  break;                  log(LOG_ERR, "mld6_input: illegal type(%d)", mldh->mld6_type);
   #endif
                   break;
         }          }
   
           m_freem(m);
 }  }
   
 void  void
 mld6_fasttimeo()  mld6_fasttimeo()
 {  {
         register struct in6_multi *in6m;          struct in6_multi *in6m;
         struct in6_multistep step;          struct in6_multistep step;
         int s;          int s;
   
Line 369  mld6_sendpkt(in6m, type, dst)
Line 395  mld6_sendpkt(in6m, type, dst)
          * At first, find a link local address on the outgoing interface           * At first, find a link local address on the outgoing interface
          * to use as the source address of the MLD packet.           * to use as the source address of the MLD packet.
          */           */
         if ((ia = in6ifa_ifpforlinklocal(ifp)) == NULL)          if ((ia = in6ifa_ifpforlinklocal(ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST))
               == NULL)
                 return;                  return;
   
         /*          /*
Line 387  mld6_sendpkt(in6m, type, dst)
Line 414  mld6_sendpkt(in6m, type, dst)
         }          }
         mh->m_next = md;          mh->m_next = md;
   
 #ifdef IPSEC  
         mh->m_pkthdr.rcvif = NULL;  
 #endif  
         mh->m_pkthdr.len = sizeof(struct ip6_hdr) + sizeof(struct mld6_hdr);          mh->m_pkthdr.len = sizeof(struct ip6_hdr) + sizeof(struct mld6_hdr);
         mh->m_len = sizeof(struct ip6_hdr);          mh->m_len = sizeof(struct ip6_hdr);
         MH_ALIGN(mh, sizeof(struct ip6_hdr));          MH_ALIGN(mh, sizeof(struct ip6_hdr));
Line 397  mld6_sendpkt(in6m, type, dst)
Line 421  mld6_sendpkt(in6m, type, dst)
         /* fill in the ip6 header */          /* fill in the ip6 header */
         ip6 = mtod(mh, struct ip6_hdr *);          ip6 = mtod(mh, struct ip6_hdr *);
         ip6->ip6_flow = 0;          ip6->ip6_flow = 0;
         ip6->ip6_vfc = IPV6_VERSION;          ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
           ip6->ip6_vfc |= IPV6_VERSION;
         /* ip6_plen will be set later */          /* ip6_plen will be set later */
         ip6->ip6_nxt = IPPROTO_ICMPV6;          ip6->ip6_nxt = IPPROTO_ICMPV6;
         /* ip6_hlim will be set by im6o.im6o_multicast_hlim */          /* ip6_hlim will be set by im6o.im6o_multicast_hlim */
Line 416  mld6_sendpkt(in6m, type, dst)
Line 441  mld6_sendpkt(in6m, type, dst)
         mldh->mld6_addr = in6m->in6m_addr;          mldh->mld6_addr = in6m->in6m_addr;
         if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))          if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld6_addr))
                 mldh->mld6_addr.s6_addr16[1] = 0; /* XXX */                  mldh->mld6_addr.s6_addr16[1] = 0; /* XXX */
         mldh->mld6_cksum = in6_cksum(mh, IPPROTO_ICMPV6, sizeof(struct ip6_hdr),          mldh->mld6_cksum = in6_cksum(mh, IPPROTO_ICMPV6,
                                        sizeof(struct ip6_hdr),
                                      sizeof(struct mld6_hdr));                                       sizeof(struct mld6_hdr));
   
         /* construct multicast option */          /* construct multicast option */
Line 433  mld6_sendpkt(in6m, type, dst)
Line 459  mld6_sendpkt(in6m, type, dst)
         /* increment output statictics */          /* increment output statictics */
         icmp6stat.icp6s_outhist[type]++;          icmp6stat.icp6s_outhist[type]++;
   
         ip6_output(mh, &ip6_opts, NULL, 0, &im6o);          ip6_output(mh, &ip6_opts, NULL, 0, &im6o, NULL);
           icmp6_ifstat_inc(ifp, ifs6_out_msg);
           switch (type) {
           case MLD6_LISTENER_QUERY:
                   icmp6_ifstat_inc(ifp, ifs6_out_mldquery);
                   break;
           case MLD6_LISTENER_REPORT:
                   icmp6_ifstat_inc(ifp, ifs6_out_mldreport);
                   break;
           case MLD6_LISTENER_DONE:
                   icmp6_ifstat_inc(ifp, ifs6_out_mlddone);
                   break;
           }
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.18

CVSweb <webmaster@jp.NetBSD.org>