fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / tipc / bcast.c
index a7b04f3..730c5c4 100644 (file)
 #include "name_table.h"
 #include "bcast.h"
 
-
 #define MAX_PKT_DEFAULT_MCAST 1500     /* bcast link max packet size (fixed) */
 
 #define BCLINK_WIN_DEFAULT 20          /* bcast link window size (default) */
 
 #define BCLINK_LOG_BUF_SIZE 0
 
+/*
+ * Loss rate for incoming broadcast frames; used to test retransmission code.
+ * Set to N to cause every N'th frame to be discarded; 0 => don't discard any.
+ */
+#define TIPC_BCAST_LOSS_RATE 0
+
 /**
  * struct bcbearer_pair - a pair of bearers used by broadcast link
  * @primary: pointer to primary bearer
@@ -75,7 +81,14 @@ struct bcbearer_pair {
  * @bearer: (non-standard) broadcast bearer structure
  * @media: (non-standard) broadcast media structure
  * @bpairs: array of bearer pairs
- * @bpairs_temp: array of bearer pairs used during creation of "bpairs"
+ * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort()
+ * @remains: temporary node map used by tipc_bcbearer_send()
+ * @remains_new: temporary node map used tipc_bcbearer_send()
+ * 
+ * Note: The fields labelled "temporary" are incorporated into the bearer
+ * to avoid consuming potentially limited stack space through the use of
+ * large local variables within multicast routines.  Concurrent access is
+ * prevented through use of the spinlock "bc_lock".
  */
 
 struct bcbearer {
@@ -83,6 +96,8 @@ struct bcbearer {
        struct media media;
        struct bcbearer_pair bpairs[MAX_BEARERS];
        struct bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1];
+       struct node_map remains;
+       struct node_map remains_new;
 };
 
 /**
@@ -102,27 +117,27 @@ struct bclink {
 static struct bcbearer *bcbearer = NULL;
 static struct bclink *bclink = NULL;
 static struct link *bcl = NULL;
-static spinlock_t bc_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(bc_lock);
 
 char tipc_bclink_name[] = "multicast-link";
 
 
-static inline u32 buf_seqno(struct sk_buff *buf)
+static u32 buf_seqno(struct sk_buff *buf)
 {
        return msg_seqno(buf_msg(buf));
 } 
 
-static inline u32 bcbuf_acks(struct sk_buff *buf)
+static u32 bcbuf_acks(struct sk_buff *buf)
 {
        return (u32)(unsigned long)TIPC_SKB_CB(buf)->handle;
 }
 
-static inline void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
+static void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
 {
        TIPC_SKB_CB(buf)->handle = (void *)(unsigned long)acks;
 }
 
-static inline void bcbuf_decr_acks(struct sk_buff *buf)
+static void bcbuf_decr_acks(struct sk_buff *buf)
 {
        bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
 }
@@ -134,7 +149,7 @@ static inline void bcbuf_decr_acks(struct sk_buff *buf)
  * Called with 'node' locked, bc_lock unlocked
  */
 
-static inline void bclink_set_gap(struct node *n_ptr)
+static void bclink_set_gap(struct node *n_ptr)
 {
        struct sk_buff *buf = n_ptr->bclink.deferred_head;
 
@@ -154,7 +169,7 @@ static inline void bclink_set_gap(struct node *n_ptr)
  *       distribute NACKs, but tries to use the same spacing (divide by 16). 
  */
 
-static inline int bclink_ack_allowed(u32 n)
+static int bclink_ack_allowed(u32 n)
 {
        return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag);
 }
@@ -165,21 +180,18 @@ static inline int bclink_ack_allowed(u32 n)
  * @after: sequence number of last packet to *not* retransmit
  * @to: sequence number of last packet to retransmit
  * 
- * Called with 'node' locked, bc_lock unlocked
+ * Called with bc_lock locked
  */
 
 static void bclink_retransmit_pkt(u32 after, u32 to)
 {
        struct sk_buff *buf;
 
-       spin_lock_bh(&bc_lock);
        buf = bcl->first_out;
        while (buf && less_eq(buf_seqno(buf), after)) {
                buf = buf->next;                
        }
-       if (buf != NULL)
-               tipc_link_retransmit(bcl, buf, mod(to - after));
-       spin_unlock_bh(&bc_lock);              
+       tipc_link_retransmit(bcl, buf, mod(to - after));
 }
 
 /** 
@@ -271,7 +283,7 @@ static void bclink_send_nack(struct node *n_ptr)
                msg_set_bcgap_to(msg, n_ptr->bclink.gap_to);
                msg_set_bcast_tag(msg, tipc_own_tag);
 
-               if (tipc_bearer_send(&bcbearer->bearer, buf, 0)) {
+               if (tipc_bearer_send(&bcbearer->bearer, buf, NULL)) {
                        bcl->stats.sent_nacks++;
                        buf_discard(buf);
                } else {
@@ -314,7 +326,7 @@ void tipc_bclink_check_gap(struct node *n_ptr, u32 last_sent)
  * Only tipc_net_lock set.
  */
 
-void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
+static void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
 {
        struct node *n_ptr = tipc_node_find(dest);
        u32 my_after, my_to;
@@ -346,8 +358,10 @@ void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
                for (; buf; buf = buf->next) {
                        u32 seqno = buf_seqno(buf);
 
-                       if (mod(seqno - prev) != 1)
+                       if (mod(seqno - prev) != 1) {
                                buf = NULL;
+                               break;
+                       }
                        if (seqno == gap_after)
                                break;
                        prev = seqno;
@@ -399,7 +413,10 @@ int tipc_bclink_send_msg(struct sk_buff *buf)
  */
 
 void tipc_bclink_recv_pkt(struct sk_buff *buf)
-{        
+{
+#if (TIPC_BCAST_LOSS_RATE)
+       static int rx_count = 0;
+#endif
        struct tipc_msg *msg = buf_msg(buf);
        struct node* node = tipc_node_find(msg_prevnode(msg));
        u32 next_in;
@@ -420,19 +437,31 @@ void tipc_bclink_recv_pkt(struct sk_buff *buf)
                        tipc_node_lock(node);
                        tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
                        tipc_node_unlock(node);
+                       spin_lock_bh(&bc_lock);
                        bcl->stats.recv_nacks++;
+                       bcl->owner->next = node;   /* remember requestor */
                        bclink_retransmit_pkt(msg_bcgap_after(msg),
                                              msg_bcgap_to(msg));
+                       bcl->owner->next = NULL;
+                       spin_unlock_bh(&bc_lock);              
                } else {
                        tipc_bclink_peek_nack(msg_destnode(msg),
-                                        msg_bcast_tag(msg),
-                                        msg_bcgap_after(msg),
-                                        msg_bcgap_to(msg));
+                                             msg_bcast_tag(msg),
+                                             msg_bcgap_after(msg),
+                                             msg_bcgap_to(msg));
                }
                buf_discard(buf);
                return;
        }
 
+#if (TIPC_BCAST_LOSS_RATE)
+       if (++rx_count == TIPC_BCAST_LOSS_RATE) {
+               rx_count = 0;
+               buf_discard(buf);
+               return;
+       }
+#endif
+
        tipc_node_lock(node);
 receive:
        deferred = node->bclink.deferred_head;
@@ -525,14 +554,12 @@ u32 tipc_bclink_acks_missing(struct node *n_ptr)
  * Returns 0 if packet sent successfully, non-zero if not
  */
 
-int tipc_bcbearer_send(struct sk_buff *buf,
-                      struct tipc_bearer *unused1,
-                      struct tipc_media_addr *unused2)
+static int tipc_bcbearer_send(struct sk_buff *buf,
+                             struct tipc_bearer *unused1,
+                             struct tipc_media_addr *unused2)
 {
        static int send_count = 0;
 
-       struct node_map remains;
-       struct node_map remains_new;
        int bp_index;
        int swap_time;
 
@@ -555,7 +582,7 @@ int tipc_bcbearer_send(struct sk_buff *buf,
 
        /* Send buffer over bearers until all targets reached */
        
-       remains = tipc_cltr_bcast_nodes;
+       bcbearer->remains = tipc_cltr_bcast_nodes;
 
        for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
                struct bearer *p = bcbearer->bpairs[bp_index].primary;
@@ -564,8 +591,8 @@ int tipc_bcbearer_send(struct sk_buff *buf,
                if (!p)
                        break;  /* no more bearers to try */
 
-               tipc_nmap_diff(&remains, &p->nodes, &remains_new);
-               if (remains_new.count == remains.count)
+               tipc_nmap_diff(&bcbearer->remains, &p->nodes, &bcbearer->remains_new);
+               if (bcbearer->remains_new.count == bcbearer->remains.count)
                        continue;       /* bearer pair doesn't add anything */
 
                if (!p->publ.blocked &&
@@ -583,10 +610,10 @@ swap:
                bcbearer->bpairs[bp_index].primary = s;
                bcbearer->bpairs[bp_index].secondary = p;
 update:
-               if (remains_new.count == 0)
+               if (bcbearer->remains_new.count == 0)
                        return TIPC_OK;
 
-               remains = remains_new;
+               bcbearer->remains = bcbearer->remains_new;
        }
        
        /* Unable to reach all targets */
@@ -747,11 +774,11 @@ int tipc_bclink_set_queue_limits(u32 limit)
 
 int tipc_bclink_init(void)
 {
-       bcbearer = kmalloc(sizeof(*bcbearer), GFP_ATOMIC);
-       bclink = kmalloc(sizeof(*bclink), GFP_ATOMIC);
+       bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC);
+       bclink = kzalloc(sizeof(*bclink), GFP_ATOMIC);
        if (!bcbearer || !bclink) {
  nomem:
-               warn("Memory squeeze; Failed to create multicast link\n");
+               warn("Multicast link creation failed, no memory\n");
                kfree(bcbearer);
                bcbearer = NULL;
                kfree(bclink);
@@ -759,17 +786,15 @@ int tipc_bclink_init(void)
                return -ENOMEM;
        }
 
-       memset(bcbearer, 0, sizeof(struct bcbearer));
        INIT_LIST_HEAD(&bcbearer->bearer.cong_links);
        bcbearer->bearer.media = &bcbearer->media;
        bcbearer->media.send_msg = tipc_bcbearer_send;
        sprintf(bcbearer->media.name, "tipc-multicast");
 
        bcl = &bclink->link;
-       memset(bclink, 0, sizeof(struct bclink));
        INIT_LIST_HEAD(&bcl->waiting_ports);
        bcl->next_out_no = 1;
-       bclink->node.lock =  SPIN_LOCK_UNLOCKED;        
+       spin_lock_init(&bclink->node.lock);
        bcl->owner = &bclink->node;
         bcl->max_pkt = MAX_PKT_DEFAULT_MCAST;
        tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);