]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/ip6_input.c
[IPV6] MROUTE: Support multicast forwarding.
[net-next-2.6.git] / net / ipv6 / ip6_input.c
index be0ee8a34f9bd379a3e23d53099299e8ff6beea5..09a3201e408aa9fd32d78d15d525db49968462d4 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/netdevice.h>
 #include <linux/in6.h>
 #include <linux/icmpv6.h>
+#include <linux/mroute6.h>
 
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv6.h>
@@ -86,7 +87,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
         *
         * BTW, when we send a packet for our own local address on a
         * non-loopback interface (e.g. ethX), it is being delivered
-        * via the loopback interface (lo) here; skb->dev = &loopback_dev.
+        * via the loopback interface (lo) here; skb->dev = loopback_dev.
         * It, however, should be considered as if it is being
         * arrived via the sending interface (ethX), because of the
         * nature of scoping architecture. --yoshfuji
@@ -120,7 +121,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
        }
 
        if (hdr->nexthdr == NEXTHDR_HOP) {
-               if (ipv6_parse_hopopts(&skb) < 0) {
+               if (ipv6_parse_hopopts(skb) < 0) {
                        IP6_INC_STATS_BH(idev, IPSTATS_MIB_INHDRERRORS);
                        rcu_read_unlock();
                        return 0;
@@ -129,7 +130,8 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 
        rcu_read_unlock();
 
-       return NF_HOOK(PF_INET6,NF_IP6_PRE_ROUTING, skb, dev, NULL, ip6_rcv_finish);
+       return NF_HOOK(PF_INET6, NF_INET_PRE_ROUTING, skb, dev, NULL,
+                      ip6_rcv_finish);
 err:
        IP6_INC_STATS_BH(idev, IPSTATS_MIB_INHDRERRORS);
 drop:
@@ -144,12 +146,11 @@ out:
  */
 
 
-static inline int ip6_input_finish(struct sk_buff *skb)
+static int ip6_input_finish(struct sk_buff *skb)
 {
        struct inet6_protocol *ipprot;
-       struct sock *raw_sk;
        unsigned int nhoff;
-       int nexthdr;
+       int nexthdr, raw;
        u8 hash;
        struct inet6_dev *idev;
 
@@ -165,9 +166,7 @@ resubmit:
        nhoff = IP6CB(skb)->nhoff;
        nexthdr = skb_network_header(skb)[nhoff];
 
-       raw_sk = sk_head(&raw_v6_htable[nexthdr & (MAX_INET_PROTOS - 1)]);
-       if (raw_sk && !ipv6_raw_deliver(skb, nexthdr))
-               raw_sk = NULL;
+       raw = raw6_local_deliver(skb, nexthdr);
 
        hash = nexthdr & (MAX_INET_PROTOS - 1);
        if ((ipprot = rcu_dereference(inet6_protos[hash])) != NULL) {
@@ -194,13 +193,13 @@ resubmit:
                    !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
                        goto discard;
 
-               ret = ipprot->handler(&skb);
+               ret = ipprot->handler(skb);
                if (ret > 0)
                        goto resubmit;
                else if (ret == 0)
                        IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDELIVERS);
        } else {
-               if (!raw_sk) {
+               if (!raw) {
                        if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
                                IP6_INC_STATS_BH(idev, IPSTATS_MIB_INUNKNOWNPROTOS);
                                icmpv6_send(skb, ICMPV6_PARAMPROB,
@@ -224,7 +223,8 @@ discard:
 
 int ip6_input(struct sk_buff *skb)
 {
-       return NF_HOOK(PF_INET6,NF_IP6_LOCAL_IN, skb, skb->dev, NULL, ip6_input_finish);
+       return NF_HOOK(PF_INET6, NF_INET_LOCAL_IN, skb, skb->dev, NULL,
+                      ip6_input_finish);
 }
 
 int ip6_mc_input(struct sk_buff *skb)
@@ -235,39 +235,86 @@ int ip6_mc_input(struct sk_buff *skb)
        IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_INMCASTPKTS);
 
        hdr = ipv6_hdr(skb);
-       deliver = likely(!(skb->dev->flags & (IFF_PROMISC|IFF_ALLMULTI))) ||
-           ipv6_chk_mcast_addr(skb->dev, &hdr->daddr, NULL);
+       deliver = ipv6_chk_mcast_addr(skb->dev, &hdr->daddr, NULL);
 
+#ifdef CONFIG_IPV6_MROUTE
        /*
-        *      IPv6 multicast router mode isnt currently supported.
+        *      IPv6 multicast router mode is now supported ;)
         */
-#if 0
-       if (ipv6_config.multicast_route) {
-               int addr_type;
-
-               addr_type = ipv6_addr_type(&hdr->daddr);
-
-               if (!(addr_type & (IPV6_ADDR_LOOPBACK | IPV6_ADDR_LINKLOCAL))) {
-                       struct sk_buff *skb2;
-                       struct dst_entry *dst;
+       if (ipv6_devconf.mc_forwarding &&
+           likely(!(IP6CB(skb)->flags & IP6SKB_FORWARDED))) {
+               /*
+                * Okay, we try to forward - split and duplicate
+                * packets.
+                */
+               struct sk_buff *skb2;
+               struct inet6_skb_parm *opt = IP6CB(skb);
+
+               /* Check for MLD */
+               if (unlikely(opt->ra)) {
+                       /* Check if this is a mld message */
+                       u8 *ptr = skb_network_header(skb) + opt->ra;
+                       struct icmp6hdr *icmp6;
+                       u8 nexthdr = hdr->nexthdr;
+                       int offset;
+
+                       /* Check if the value of Router Alert
+                        * is for MLD (0x0000).
+                        */
+                       if ((ptr[2] | ptr[3]) == 0) {
+                               if (!ipv6_ext_hdr(nexthdr)) {
+                                       /* BUG */
+                                       goto discard;
+                               }
+                               offset = ipv6_skip_exthdr(skb, sizeof(*hdr),
+                                                         &nexthdr);
+                               if (offset < 0)
+                                       goto discard;
+
+                               if (nexthdr != IPPROTO_ICMPV6)
+                                       goto discard;
+
+                               if (!pskb_may_pull(skb, (skb_network_header(skb) +
+                                                  offset + 1 - skb->data)))
+                                       goto discard;
+
+                               icmp6 = (struct icmp6hdr *)(skb_network_header(skb) + offset);
+
+                               switch (icmp6->icmp6_type) {
+                               case ICMPV6_MGM_QUERY:
+                               case ICMPV6_MGM_REPORT:
+                               case ICMPV6_MGM_REDUCTION:
+                               case ICMPV6_MLD2_REPORT:
+                                       break;
+                               default:
+                                       /* Bogus */
+                                       goto discard;
+                               }
+                               deliver = 1;
+                               goto out;
+                       }
+                       /* unknown RA - process it normally */
+               }
 
-                       dst = skb->dst;
+               if (deliver)
+                       skb2 = skb_clone(skb, GFP_ATOMIC);
+               else {
+                       skb2 = skb;
+                       skb = NULL;
+               }
 
-                       if (deliver) {
-                               skb2 = skb_clone(skb, GFP_ATOMIC);
-                               dst_output(skb2);
-                       } else {
-                               dst_output(skb);
-                               return 0;
-                       }
+               if (skb2) {
+                       skb2->dev = skb2->dst->dev;
+                       ip6_mr_input(skb2);
                }
        }
 #endif
-
+out:
        if (likely(deliver)) {
                ip6_input(skb);
                return 0;
        }
+discard:
        /* discard */
        kfree_skb(skb);