Merge branch 'linus' into cont_syslog
[safe/jmp/linux-2.6] / net / bridge / br_input.c
index fa0f571..d36e700 100644 (file)
@@ -5,14 +5,13 @@
  *     Authors:
  *     Lennert Buytenhek               <buytenh@gnu.org>
  *
- *     $Id: br_input.c,v 1.10 2001/12/24 04:50:20 davem Exp $
- *
  *     This program is free software; you can redistribute it and/or
  *     modify it under the terms of the GNU General Public License
  *     as published by the Free Software Foundation; either version
  *     2 of the License, or (at your option) any later version.
  */
 
+#include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 /* Bridge group multicast address 802.1d (pg 51). */
 const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
 
-static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
+static int br_pass_frame_up(struct sk_buff *skb)
 {
-       struct net_device *indev, *brdev = br->dev;
+       struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
+       struct net_bridge *br = netdev_priv(brdev);
+       struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats);
 
-       brdev->stats.rx_packets++;
-       brdev->stats.rx_bytes += skb->len;
+       brstats->rx_packets++;
+       brstats->rx_bytes += skb->len;
 
        indev = skb->dev;
        skb->dev = brdev;
 
-       NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
-               netif_receive_skb);
+       return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
+                      netif_receive_skb);
 }
 
 /* note: already called with rcu_read_lock (preempt_disabled) */
@@ -43,6 +44,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
        struct net_bridge_port *p = rcu_dereference(skb->dev->br_port);
        struct net_bridge *br;
        struct net_bridge_fdb_entry *dst;
+       struct net_bridge_mdb_entry *mdst;
        struct sk_buff *skb2;
 
        if (!p || p->state == BR_STATE_DISABLED)
@@ -52,9 +54,15 @@ int br_handle_frame_finish(struct sk_buff *skb)
        br = p->br;
        br_fdb_update(br, p, eth_hdr(skb)->h_source);
 
+       if (is_multicast_ether_addr(dest) &&
+           br_multicast_rcv(br, p, skb))
+               goto drop;
+
        if (p->state == BR_STATE_LEARNING)
                goto drop;
 
+       BR_INPUT_SKB_CB(skb)->brdev = br->dev;
+
        /* The packet skb2 goes to the local host (NULL to skip). */
        skb2 = NULL;
 
@@ -64,27 +72,35 @@ int br_handle_frame_finish(struct sk_buff *skb)
        dst = NULL;
 
        if (is_multicast_ether_addr(dest)) {
+               mdst = br_mdb_get(br, skb);
+               if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) {
+                       if ((mdst && !hlist_unhashed(&mdst->mglist)) ||
+                           br_multicast_is_router(br))
+                               skb2 = skb;
+                       br_multicast_forward(mdst, skb, skb2);
+                       skb = NULL;
+                       if (!skb2)
+                               goto out;
+               } else
+                       skb2 = skb;
+
                br->dev->stats.multicast++;
-               skb2 = skb;
        } else if ((dst = __br_fdb_get(br, dest)) && dst->is_local) {
                skb2 = skb;
                /* Do not forward the packet since it's local. */
                skb = NULL;
        }
 
-       if (skb2 == skb)
-               skb2 = skb_clone(skb, GFP_ATOMIC);
-
-       if (skb2)
-               br_pass_frame_up(br, skb2);
-
        if (skb) {
                if (dst)
-                       br_forward(dst->dst, skb);
+                       br_forward(dst->dst, skb, skb2);
                else
-                       br_flood_forward(br, skb);
+                       br_flood_forward(br, skb, skb2);
        }
 
+       if (skb2)
+               return br_pass_frame_up(skb2);
+
 out:
        return 0;
 drop:
@@ -136,16 +152,18 @@ struct sk_buff *br_handle_frame(struct net_bridge_port *p, struct sk_buff *skb)
                if (skb->protocol == htons(ETH_P_PAUSE))
                        goto drop;
 
-               /* Process STP BPDU's through normal netif_receive_skb() path */
-               if (p->br->stp_enabled != BR_NO_STP) {
-                       if (NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
-                                   NULL, br_handle_local_finish))
-                               return NULL;
-                       else
-                               return skb;
-               }
+               /* If STP is turned off, then forward */
+               if (p->br->stp_enabled == BR_NO_STP && dest[5] == 0)
+                       goto forward;
+
+               if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
+                           NULL, br_handle_local_finish))
+                       return NULL;    /* frame consumed by filter */
+               else
+                       return skb;     /* continue processing */
        }
 
+forward:
        switch (p->state) {
        case BR_STATE_FORWARDING:
                rhook = rcu_dereference(br_should_route_hook);
@@ -159,7 +177,7 @@ struct sk_buff *br_handle_frame(struct net_bridge_port *p, struct sk_buff *skb)
                if (!compare_ether_addr(p->br->dev->dev_addr, dest))
                        skb->pkt_type = PACKET_HOST;
 
-               NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
+               NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
                        br_handle_frame_finish);
                break;
        default: