KVM: SVM: Selective cr0 intercept
[safe/jmp/linux-2.6] / net / tipc / bearer.c
index e213a8e..327011f 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * net/tipc/bearer.c: TIPC bearer code
- * 
+ *
  * Copyright (c) 1996-2006, Ericsson AB
- * Copyright (c) 2004-2005, Wind River Systems
+ * Copyright (c) 2004-2006, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ struct bearer *tipc_bearers = NULL;
 
 /**
  * media_name_valid - validate media name
- * 
+ *
  * Returns 1 if media name is valid, otherwise 0.
  */
 
@@ -84,17 +84,17 @@ static struct media *media_find(const char *name)
 
 /**
  * tipc_register_media - register a media type
- * 
+ *
  * Bearers for this media type must be activated separately at a later stage.
  */
 
 int  tipc_register_media(u32 media_type,
-                        char *name, 
-                        int (*enable)(struct tipc_bearer *), 
-                        void (*disable)(struct tipc_bearer *), 
-                        int (*send_msg)(struct sk_buff *, 
+                        char *name,
+                        int (*enable)(struct tipc_bearer *),
+                        void (*disable)(struct tipc_bearer *),
+                        int (*send_msg)(struct sk_buff *,
                                         struct tipc_bearer *,
-                                        struct tipc_media_addr *), 
+                                        struct tipc_media_addr *),
                         char *(*addr2str)(struct tipc_media_addr *a,
                                           char *str_buf, int str_size),
                         struct tipc_media_addr *bcast_addr,
@@ -112,39 +112,42 @@ int  tipc_register_media(u32 media_type,
                goto exit;
 
        if (!media_name_valid(name)) {
-               warn("Media registration error: illegal name <%s>\n", name);
+               warn("Media <%s> rejected, illegal name\n", name);
                goto exit;
        }
        if (!bcast_addr) {
-               warn("Media registration error: no broadcast address supplied\n");
+               warn("Media <%s> rejected, no broadcast address\n", name);
                goto exit;
        }
-       if ((bearer_priority < TIPC_MIN_LINK_PRI) &&
+       if ((bearer_priority < TIPC_MIN_LINK_PRI) ||
            (bearer_priority > TIPC_MAX_LINK_PRI)) {
-               warn("Media registration error: priority %u\n", bearer_priority);
+               warn("Media <%s> rejected, illegal priority (%u)\n", name,
+                    bearer_priority);
                goto exit;
        }
-       if ((link_tolerance < TIPC_MIN_LINK_TOL) || 
+       if ((link_tolerance < TIPC_MIN_LINK_TOL) ||
            (link_tolerance > TIPC_MAX_LINK_TOL)) {
-               warn("Media registration error: tolerance %u\n", link_tolerance);
+               warn("Media <%s> rejected, illegal tolerance (%u)\n", name,
+                    link_tolerance);
                goto exit;
        }
 
        media_id = media_count++;
        if (media_id >= MAX_MEDIA) {
-               warn("Attempt to register more than %u media\n", MAX_MEDIA);
+               warn("Media <%s> rejected, media limit reached (%u)\n", name,
+                    MAX_MEDIA);
                media_count--;
                goto exit;
        }
        for (i = 0; i < media_id; i++) {
                if (media_list[i].type_id == media_type) {
-                       warn("Attempt to register second media with type %u\n", 
+                       warn("Media <%s> rejected, duplicate type (%u)\n", name,
                             media_type);
                        media_count--;
                        goto exit;
                }
                if (!strcmp(name, media_list[i].name)) {
-                       warn("Attempt to re-register media name <%s>\n", name);
+                       warn("Media <%s> rejected, duplicate name\n", name);
                        media_count--;
                        goto exit;
                }
@@ -188,14 +191,14 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
        if ((i < media_count) && (m_ptr->addr2str != NULL)) {
                char addr_str[MAX_ADDR_STR];
 
-               tipc_printf(pb, "%s(%s) ", m_ptr->name, 
+               tipc_printf(pb, "%s(%s)", m_ptr->name,
                            m_ptr->addr2str(a, addr_str, sizeof(addr_str)));
        } else {
                unchar *addr = (unchar *)&a->dev_addr;
 
-               tipc_printf(pb, "UNKNOWN(%u):", media_type);
+               tipc_printf(pb, "UNKNOWN(%u)", media_type);
                for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++) {
-                       tipc_printf(pb, "%02x ", addr[i]);
+                       tipc_printf(pb, "-%02x", addr[i]);
                }
        }
 }
@@ -216,7 +219,7 @@ struct sk_buff *tipc_media_get_names(void)
 
        read_lock_bh(&tipc_net_lock);
        for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) {
-               tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, m_ptr->name, 
+               tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, m_ptr->name,
                                    strlen(m_ptr->name) + 1);
        }
        read_unlock_bh(&tipc_net_lock);
@@ -227,11 +230,11 @@ struct sk_buff *tipc_media_get_names(void)
  * bearer_name_validate - validate & (optionally) deconstruct bearer name
  * @name - ptr to bearer name string
  * @name_parts - ptr to area for bearer name components (or NULL if not needed)
- * 
+ *
  * Returns 1 if bearer name is valid, otherwise 0.
  */
 
-static int bearer_name_validate(const char *name, 
+static int bearer_name_validate(const char *name,
                                struct bearer_name *name_parts)
 {
        char name_copy[TIPC_MAX_BEARER_NAME];
@@ -259,8 +262,8 @@ static int bearer_name_validate(const char *name,
 
        /* validate component parts of bearer name */
 
-       if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) || 
-           (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME) || 
+       if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
+           (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME) ||
            (strspn(media_name, tipc_alphabet) != (media_len - 1)) ||
            (strspn(if_name, tipc_alphabet) != (if_len - 1)))
                return 0;
@@ -283,6 +286,9 @@ static struct bearer *bearer_find(const char *name)
        struct bearer *b_ptr;
        u32 i;
 
+       if (tipc_mode != TIPC_NET_MODE)
+               return NULL;
+
        for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
                if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
                        return b_ptr;
@@ -330,8 +336,8 @@ struct sk_buff *tipc_bearer_get_names(void)
                for (j = 0; j < MAX_BEARERS; j++) {
                        b_ptr = &tipc_bearers[j];
                        if (b_ptr->active && (b_ptr->media == m_ptr)) {
-                               tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, 
-                                                   b_ptr->publ.name, 
+                               tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
+                                                   b_ptr->publ.name,
                                                    strlen(b_ptr->publ.name) + 1);
                        }
                }
@@ -364,7 +370,7 @@ void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest)
  */
 static int bearer_push(struct bearer *b_ptr)
 {
-       u32 res = TIPC_OK;
+       u32 res = 0;
        struct link *ln, *tln;
 
        if (b_ptr->publ.blocked)
@@ -395,8 +401,8 @@ void tipc_bearer_lock_push(struct bearer *b_ptr)
 
 
 /*
- * Interrupt enabling new requests after bearer congestion or blocking:    
- * See bearer_send().   
+ * Interrupt enabling new requests after bearer congestion or blocking:
+ * See bearer_send().
  */
 void tipc_continue(struct tipc_bearer *tb_ptr)
 {
@@ -411,9 +417,9 @@ void tipc_continue(struct tipc_bearer *tb_ptr)
 }
 
 /*
- * Schedule link for sending of messages after the bearer 
- * has been deblocked by 'continue()'. This method is called 
- * when somebody tries to send a message via this link while 
+ * Schedule link for sending of messages after the bearer
+ * has been deblocked by 'continue()'. This method is called
+ * when somebody tries to send a message via this link while
  * the bearer is congested. 'tipc_net_lock' is in read_lock here
  * bearer.lock is busy
  */
@@ -424,9 +430,9 @@ static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_p
 }
 
 /*
- * Schedule link for sending of messages after the bearer 
- * has been deblocked by 'continue()'. This method is called 
- * when somebody tries to send a message via this link while 
+ * Schedule link for sending of messages after the bearer
+ * has been deblocked by 'continue()'. This method is called
+ * when somebody tries to send a message via this link while
  * the bearer is congested. 'tipc_net_lock' is in read_lock here,
  * bearer.lock is free
  */
@@ -462,7 +468,7 @@ int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr)
 
 /**
  * tipc_enable_bearer - enable bearer with the given name
- */              
+ */
 
 int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
 {
@@ -475,26 +481,33 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
        u32 i;
        int res = -EINVAL;
 
-       if (tipc_mode != TIPC_NET_MODE)
+       if (tipc_mode != TIPC_NET_MODE) {
+               warn("Bearer <%s> rejected, not supported in standalone mode\n",
+                    name);
                return -ENOPROTOOPT;
-
-       if (!bearer_name_validate(name, &b_name) ||
-           !tipc_addr_domain_valid(bcast_scope) ||
-           !in_scope(bcast_scope, tipc_own_addr))
+       }
+       if (!bearer_name_validate(name, &b_name)) {
+               warn("Bearer <%s> rejected, illegal name\n", name);
                return -EINVAL;
-
+       }
+       if (!tipc_addr_domain_valid(bcast_scope) ||
+           !in_scope(bcast_scope, tipc_own_addr)) {
+               warn("Bearer <%s> rejected, illegal broadcast scope\n", name);
+               return -EINVAL;
+       }
        if ((priority < TIPC_MIN_LINK_PRI ||
             priority > TIPC_MAX_LINK_PRI) &&
-           (priority != TIPC_MEDIA_LINK_PRI))
+           (priority != TIPC_MEDIA_LINK_PRI)) {
+               warn("Bearer <%s> rejected, illegal priority\n", name);
                return -EINVAL;
+       }
 
        write_lock_bh(&tipc_net_lock);
-       if (!tipc_bearers)
-               goto failed;
 
        m_ptr = media_find(b_name.media_name);
        if (!m_ptr) {
-               warn("No media <%s>\n", b_name.media_name);
+               warn("Bearer <%s> rejected, media <%s> not registered\n", name,
+                    b_name.media_name);
                goto failed;
        }
 
@@ -510,23 +523,24 @@ restart:
                        continue;
                }
                if (!strcmp(name, tipc_bearers[i].publ.name)) {
-                       warn("Bearer <%s> already enabled\n", name);
+                       warn("Bearer <%s> rejected, already enabled\n", name);
                        goto failed;
                }
                if ((tipc_bearers[i].priority == priority) &&
                    (++with_this_prio > 2)) {
                        if (priority-- == 0) {
-                               warn("Third bearer <%s> with priority %u, unable to lower to %u\n",
-                                    name, priority + 1, priority);
+                               warn("Bearer <%s> rejected, duplicate priority\n",
+                                    name);
                                goto failed;
                        }
-                       warn("Third bearer <%s> with priority %u, lowering to %u\n",
+                       warn("Bearer <%s> priority adjustment required %u->%u\n",
                             name, priority + 1, priority);
                        goto restart;
                }
        }
        if (bearer_id >= MAX_BEARERS) {
-               warn("Attempt to enable more than %d bearers\n", MAX_BEARERS);
+               warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
+                    name, MAX_BEARERS);
                goto failed;
        }
 
@@ -536,7 +550,7 @@ restart:
        strcpy(b_ptr->publ.name, name);
        res = m_ptr->enable_bearer(&b_ptr->publ);
        if (res) {
-               warn("Failed to enable bearer <%s>\n", name);
+               warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
                goto failed;
        }
 
@@ -552,7 +566,7 @@ restart:
                b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr,
                                                          bcast_scope, 2);
        }
-       b_ptr->publ.lock = SPIN_LOCK_UNLOCKED;
+       spin_lock_init(&b_ptr->publ.lock);
        write_unlock_bh(&tipc_net_lock);
        info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
             name, addr_string_fill(addr_string, bcast_scope), priority);
@@ -573,9 +587,6 @@ int tipc_block_bearer(const char *name)
        struct link *l_ptr;
        struct link *temp_l_ptr;
 
-       if (tipc_mode != TIPC_NET_MODE)
-               return -ENOPROTOOPT;
-
        read_lock_bh(&tipc_net_lock);
        b_ptr = bearer_find(name);
        if (!b_ptr) {
@@ -584,10 +595,11 @@ int tipc_block_bearer(const char *name)
                return -EINVAL;
        }
 
+       info("Blocking bearer <%s>\n", name);
        spin_lock_bh(&b_ptr->publ.lock);
        b_ptr->publ.blocked = 1;
        list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
-               struct node *n_ptr = l_ptr->owner;
+               struct tipc_node *n_ptr = l_ptr->owner;
 
                spin_lock_bh(&n_ptr->lock);
                tipc_link_reset(l_ptr);
@@ -595,13 +607,12 @@ int tipc_block_bearer(const char *name)
        }
        spin_unlock_bh(&b_ptr->publ.lock);
        read_unlock_bh(&tipc_net_lock);
-       info("Blocked bearer <%s>\n", name);
-       return TIPC_OK;
+       return 0;
 }
 
 /**
  * bearer_disable -
- * 
+ *
  * Note: This routine assumes caller holds tipc_net_lock.
  */
 
@@ -611,15 +622,13 @@ static int bearer_disable(const char *name)
        struct link *l_ptr;
        struct link *temp_l_ptr;
 
-       if (tipc_mode != TIPC_NET_MODE)
-               return -ENOPROTOOPT;
-
        b_ptr = bearer_find(name);
        if (!b_ptr) {
                warn("Attempt to disable unknown bearer <%s>\n", name);
                return -EINVAL;
        }
 
+       info("Disabling bearer <%s>\n", name);
        tipc_disc_stop_link_req(b_ptr->link_req);
        spin_lock_bh(&b_ptr->publ.lock);
        b_ptr->link_req = NULL;
@@ -635,9 +644,8 @@ static int bearer_disable(const char *name)
                tipc_link_delete(l_ptr);
        }
        spin_unlock_bh(&b_ptr->publ.lock);
-       info("Disabled bearer <%s>\n", name);
        memset(b_ptr, 0, sizeof(struct bearer));
-       return TIPC_OK;
+       return 0;
 }
 
 int tipc_disable_bearer(const char *name)
@@ -657,12 +665,10 @@ int tipc_bearer_init(void)
        int res;
 
        write_lock_bh(&tipc_net_lock);
-       tipc_bearers = kmalloc(MAX_BEARERS * sizeof(struct bearer), GFP_ATOMIC);
-       media_list = kmalloc(MAX_MEDIA * sizeof(struct media), GFP_ATOMIC);
+       tipc_bearers = kcalloc(MAX_BEARERS, sizeof(struct bearer), GFP_ATOMIC);
+       media_list = kcalloc(MAX_MEDIA, sizeof(struct media), GFP_ATOMIC);
        if (tipc_bearers && media_list) {
-               memset(tipc_bearers, 0, MAX_BEARERS * sizeof(struct bearer));
-               memset(media_list, 0, MAX_MEDIA * sizeof(struct media));
-               res = TIPC_OK;
+               res = 0;
        } else {
                kfree(tipc_bearers);
                kfree(media_list);