]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/tipc/node.c
Pull platform-drivers into test branch
[linux-2.6-omap-h63xx.git] / net / tipc / node.c
index 861322b935daf1be3aee4ac4e5eca284c4a7c89a..4111a31def7997548dd0e49024d6f92612123eb6 100644 (file)
@@ -2,7 +2,7 @@
  * net/tipc/node.c: TIPC node management routines
  * 
  * Copyright (c) 2000-2006, Ericsson AB
- * Copyright (c) 2005, Wind River Systems
+ * Copyright (c) 2005-2006, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -60,7 +60,7 @@ struct node *tipc_node_create(u32 addr)
        struct node *n_ptr;
         struct node **curr_node;
 
-       n_ptr = kmalloc(sizeof(*n_ptr),GFP_ATOMIC);
+       n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC);
        if (!n_ptr) {
                warn("Node creation failed, no memory\n");
                return NULL;
@@ -75,7 +75,6 @@ struct node *tipc_node_create(u32 addr)
                return NULL;
        }
                
-       memset(n_ptr, 0, sizeof(*n_ptr));
        n_ptr->addr = addr;
                 spin_lock_init(&n_ptr->lock);
        INIT_LIST_HEAD(&n_ptr->nsub);
@@ -592,12 +591,12 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
        struct sk_buff *buf;
        struct node *n_ptr;
         struct tipc_node_info node_info;
+       u32 payload_size;
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
 
-       domain = *(u32 *)TLV_DATA(req_tlv_area);
-       domain = ntohl(domain);
+       domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        if (!tipc_addr_domain_valid(domain))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (network address)");
@@ -608,8 +607,11 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
        /* For now, get space for all other nodes 
           (will need to modify this when slave nodes are supported */
 
-       buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(node_info)) *
-                                  (tipc_max_nodes - 1));
+       payload_size = TLV_SPACE(sizeof(node_info)) * (tipc_max_nodes - 1);
+       if (payload_size > 32768u)
+               return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
+                                                  " (too many nodes)");
+       buf = tipc_cfg_reply_alloc(payload_size);
        if (!buf)
                return NULL;
 
@@ -633,31 +635,33 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
        struct sk_buff *buf;
        struct node *n_ptr;
         struct tipc_link_info link_info;
+       u32 payload_size;
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
 
-       domain = *(u32 *)TLV_DATA(req_tlv_area);
-       domain = ntohl(domain);
+       domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        if (!tipc_addr_domain_valid(domain))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (network address)");
 
-        if (!tipc_nodes)
+        if (tipc_mode != TIPC_NET_MODE)
                 return tipc_cfg_reply_none();
-
-       /* For now, get space for 2 links to all other nodes + bcast link 
-          (will need to modify this when slave nodes are supported */
-
-       buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(link_info)) *
-                                  (2 * (tipc_max_nodes - 1) + 1));
+       
+       /* Get space for all unicast links + multicast link */
+
+       payload_size = TLV_SPACE(sizeof(link_info)) *
+               (tipc_net.zones[tipc_zone(tipc_own_addr)]->links + 1);
+       if (payload_size > 32768u)
+               return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
+                                                  " (too many links)");
+       buf = tipc_cfg_reply_alloc(payload_size);
        if (!buf)
                return NULL;
 
        /* Add TLV for broadcast link */
 
-        link_info.dest = tipc_own_addr & 0xfffff00;
-       link_info.dest = htonl(link_info.dest);
+        link_info.dest = htonl(tipc_own_addr & 0xfffff00);
         link_info.up = htonl(1);
         sprintf(link_info.str, tipc_bclink_name);
        tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));