Merge branch 'for_paulus' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc
[pandora-kernel.git] / net / tipc / eth_media.c
index b634d7a..682da4a 100644 (file)
@@ -1,33 +1,36 @@
 /*
  * net/tipc/eth_media.c: Ethernet bearer support for TIPC
  * 
- * Copyright (c) 2003-2005, Ericsson Research Canada
- * Copyright (c) 2005, Wind River Systems
- * Copyright (c) 2005-2006, Ericsson AB
+ * Copyright (c) 2001-2006, Ericsson AB
+ * Copyright (c) 2005-2006, Wind River Systems
  * 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 are met:
  *
- * Redistributions of source code must retain the above copyright notice, this 
- * list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, 
- * this list of conditions and the following disclaimer in the documentation 
- * and/or other materials provided with the distribution.
- * Neither the names of the copyright holders nor the names of its 
- * contributors may be used to endorse or promote products derived from this 
- * software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include <net/tipc/tipc_bearer.h>
 #include <net/tipc/tipc_msg.h>
 #include <linux/netdevice.h>
-#include <linux/version.h>
 
 #define MAX_ETH_BEARERS                2
-#define TIPC_PROTOCOL          0x88ca
-#define ETH_LINK_PRIORITY      10
+#define ETH_LINK_PRIORITY      TIPC_DEF_LINK_PRI
 #define ETH_LINK_TOLERANCE     TIPC_DEF_LINK_TOL
-
+#define ETH_LINK_WINDOW                TIPC_DEF_LINK_WIN
 
 /**
  * struct eth_bearer - Ethernet bearer data structure
@@ -75,7 +76,7 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,
                clone->nh.raw = clone->data;
                dev = ((struct eth_bearer *)(tb_ptr->usr_handle))->dev;
                clone->dev = dev;
-               dev->hard_header(clone, dev, TIPC_PROTOCOL
+               dev->hard_header(clone, dev, ETH_P_TIPC
                                 &dest->dev_addr.eth_addr,
                                 dev->dev_addr, clone->len);
                dev_queue_xmit(clone);
@@ -97,17 +98,19 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,
        u32 size;
 
        if (likely(eb_ptr->bearer)) {
-               size = msg_size((struct tipc_msg *)buf->data);
-               skb_trim(buf, size);
-               if (likely(buf->len == size)) {
-                       buf->next = NULL;
-                       tipc_recv_msg(buf, eb_ptr->bearer);
-               } else {
-                       kfree_skb(buf);
+              if (likely(!dev->promiscuity) ||
+                  !memcmp(buf->mac.raw,dev->dev_addr,ETH_ALEN) ||
+                  !memcmp(buf->mac.raw,dev->broadcast,ETH_ALEN)) {
+                       size = msg_size((struct tipc_msg *)buf->data);
+                       skb_trim(buf, size);
+                       if (likely(buf->len == size)) {
+                               buf->next = NULL;
+                               tipc_recv_msg(buf, eb_ptr->bearer);
+                               return TIPC_OK;
+                       }
                }
-       } else {
-               kfree_skb(buf);
        }
+       kfree_skb(buf);
        return TIPC_OK;
 }
 
@@ -124,8 +127,7 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
 
        /* Find device with specified name */
 
-       while (dev && dev->name &&
-              (memcmp(dev->name, driver_name, strlen(dev->name)))) {
+       while (dev && dev->name && strncmp(dev->name, driver_name, IFNAMSIZ)) { 
                dev = dev->next;
        }
        if (!dev)
@@ -138,7 +140,7 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
                return -EDQUOT;
        if (!eb_ptr->dev) {
                eb_ptr->dev = dev;
-               eb_ptr->tipc_packet_type.type = __constant_htons(TIPC_PROTOCOL);
+               eb_ptr->tipc_packet_type.type = __constant_htons(ETH_P_TIPC);
                eb_ptr->tipc_packet_type.dev = dev;
                eb_ptr->tipc_packet_type.func = recv_msg;
                eb_ptr->tipc_packet_type.af_packet_priv = eb_ptr;
@@ -168,7 +170,7 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
 
 static void disable_bearer(struct tipc_bearer *tb_ptr)
 {
-       ((struct eth_bearer *)tb_ptr->usr_handle)->bearer = 0;
+       ((struct eth_bearer *)tb_ptr->usr_handle)->bearer = NULL;
 }
 
 /**
@@ -237,13 +239,13 @@ static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size
 }
 
 /**
- * eth_media_start - activate Ethernet bearer support
+ * tipc_eth_media_start - activate Ethernet bearer support
  *
  * Register Ethernet media type with TIPC bearer code.  Also register
  * with OS for notifications about device state changes.
  */
 
-int eth_media_start(void)
+int tipc_eth_media_start(void)
 {                       
        struct tipc_media_addr bcast_addr;
        int res;
@@ -251,13 +253,15 @@ int eth_media_start(void)
        if (eth_started)
                return -EINVAL;
 
-       memset(&bcast_addr, 0xff, sizeof(bcast_addr));
+       bcast_addr.type = htonl(TIPC_MEDIA_TYPE_ETH);
+       memset(&bcast_addr.dev_addr, 0xff, ETH_ALEN);
+
        memset(eth_bearers, 0, sizeof(eth_bearers));
 
        res = tipc_register_media(TIPC_MEDIA_TYPE_ETH, "eth",
                                  enable_bearer, disable_bearer, send_msg, 
                                  eth_addr2str, &bcast_addr, ETH_LINK_PRIORITY, 
-                                 ETH_LINK_TOLERANCE, TIPC_DEF_LINK_WIN);
+                                 ETH_LINK_TOLERANCE, ETH_LINK_WINDOW);
        if (res)
                return res;
 
@@ -270,10 +274,10 @@ int eth_media_start(void)
 }
 
 /**
- * eth_media_stop - deactivate Ethernet bearer support
+ * tipc_eth_media_stop - deactivate Ethernet bearer support
  */
 
-void eth_media_stop(void)
+void tipc_eth_media_stop(void)
 {
        int i;
 
@@ -284,7 +288,7 @@ void eth_media_stop(void)
        for (i = 0; i < MAX_ETH_BEARERS ; i++) {
                if (eth_bearers[i].bearer) {
                        eth_bearers[i].bearer->blocked = 1;
-                       eth_bearers[i].bearer = 0;
+                       eth_bearers[i].bearer = NULL;
                }
                if (eth_bearers[i].dev) {
                        dev_remove_pack(&eth_bearers[i].tipc_packet_type);