]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
lsack.c cleaned. Better names for functions and
authorOndrej Filip <feela@network.cz>
Fri, 4 Jun 2004 16:30:04 +0000 (16:30 +0000)
committerOndrej Filip <feela@network.cz>
Fri, 4 Jun 2004 16:30:04 +0000 (16:30 +0000)
DIRECT acks can be sent in one packet now.

proto/ospf/lsack.c
proto/ospf/lsack.h
proto/ospf/lsupd.c
proto/ospf/neighbor.c
proto/ospf/ospf.h
proto/ospf/packet.c

index 47c7f6bc4500fc75d630026a9be8c43a07960ac8..ba9717bce8848d4e3fba90b41d1d5ba042e3ae53 100644 (file)
@@ -1,54 +1,35 @@
 /*
  *     BIRD -- OSPF
  *
- *     (c) 2000 Ondrej Filip <feela@network.cz>
+ *     (c) 2000-2004 Ondrej Filip <feela@network.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 
 #include "ospf.h"
 
-/* Note, that h is in network endianity! */
-void
-ospf_lsack_direct_tx(struct ospf_neighbor *n,struct ospf_lsa_header *h)
-{
-  struct ospf_packet *op;
-  struct ospf_lsack_packet *pk;
-  sock *sk=n->ifa->ip_sk;
-  struct proto *p=&n->ifa->proto->proto;
-  u16 len;
-
-  DBG("Sending direct ACK to %I for Type: %u, ID: %I, RT: %I\n",n->rid,
-    h->type, ntohl(h->id), ntohl(h->rt));
-
-  pk=(struct ospf_lsack_packet *)sk->tbuf;
-  op=(struct ospf_packet *)sk->tbuf;
-
-  fill_ospf_pkt_hdr(n->ifa, pk, LSACK_P);
-
-  memcpy(pk+1,h,sizeof(struct ospf_lsa_header));
-  len=sizeof(struct ospf_lsack_packet)+sizeof(struct ospf_lsa_header);
-  op->length=htons(len);
-  ospf_pkt_finalize(n->ifa, op);
-  sk_send_to(sk,len, n->ip, OSPF_PROTO);
-  OSPF_TRACE(D_PACKETS, "LS ack sent to %I", n->ip);
-}
+char *s_queue[]={ "direct", "delayed" };
 
+/*
+ * =====================================
+ * Note, that h is in network endianity!
+ * =====================================
+ */
 void
-ospf_lsa_delay(struct ospf_neighbor *n,struct ospf_lsa_header *h,
-  struct proto *p)
+ospf_lsack_enqueue(struct ospf_neighbor *n,struct ospf_lsa_header *h,
+  struct proto *p, int queue)
 {
   struct lsah_n *no;
 
   no=mb_alloc(n->pool,sizeof(struct lsah_n));
   memcpy(&no->lsa,h,sizeof(struct ospf_lsa_header));
-  add_tail(&n->ackl, NODE no);
-  DBG("Adding delay ack for %I, ID: %I, RT: %I, Type: %u\n",n->rid,
+  add_tail(&n->ackl[queue], NODE no);
+  DBG("Adding (%s) ack for %I, ID: %I, RT: %I, Type: %u\n", s_queue[queue], n->rid,
     ntohl(h->id), ntohl(h->rt),h->type);
 }
 
 void
-ospf_lsack_delay_tx(struct ospf_neighbor *n)
+ospf_lsack_send(struct ospf_neighbor *n, int queue)
 {
   struct ospf_packet *op;
   struct ospf_lsack_packet *pk;
@@ -59,7 +40,9 @@ ospf_lsack_delay_tx(struct ospf_neighbor *n)
   struct ospf_iface *ifa=n->ifa;
   struct proto *p=&n->ifa->proto->proto;
 
-  OSPF_TRACE(D_PACKETS, "LS ack sent to %I (delayed)",n->ip);
+  if(EMPTY_LIST(n->ackl[queue])) return;
+
+  OSPF_TRACE(D_PACKETS, "LS ack sent to %I (%s)", n->ip, s_queue[queue]);
 
   if(ifa->type==OSPF_IT_BCAST)
   {
@@ -76,9 +59,9 @@ ospf_lsack_delay_tx(struct ospf_neighbor *n)
   fill_ospf_pkt_hdr(n->ifa, pk, LSACK_P);
   h=(struct ospf_lsa_header *)(pk+1);
 
-  while(!EMPTY_LIST(n->ackl))
+  while(!EMPTY_LIST(n->ackl[queue]))
   {
-    no=(struct lsah_n *)HEAD(n->ackl);
+    no=(struct lsah_n *)HEAD(n->ackl[queue]);
     memcpy(h+i,&no->lsa, sizeof(struct ospf_lsa_header));
     i++;
     DBG("Iter %u ID: %I, RT: %I, Type: %u\n",i, ntohl((h+i)->id),
@@ -88,7 +71,7 @@ ospf_lsack_delay_tx(struct ospf_neighbor *n)
     if((i*sizeof(struct ospf_lsa_header)+sizeof(struct ospf_lsack_packet)+SIPH)>
       n->ifa->iface->mtu)
     {
-      if(!EMPTY_LIST(n->ackl))
+      if(!EMPTY_LIST(n->ackl[queue]))
       {
         len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
        op->length=htons(len);
@@ -131,11 +114,11 @@ ospf_lsack_delay_tx(struct ospf_neighbor *n)
   {
     if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
     {
-      sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
+      sk_send_to(sklen, AllSPFRouters, OSPF_PROTO);
     }
     else
     {
-      sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
+      sk_send_to(sklen, AllDRouters, OSPF_PROTO);
     }
   }
   else
@@ -145,7 +128,7 @@ ospf_lsack_delay_tx(struct ospf_neighbor *n)
 }
 
 void
-ospf_lsack_rx(struct ospf_lsack_packet *ps, struct proto *p,
+ospf_lsack_receive(struct ospf_lsack_packet *ps, struct proto *p,
   struct ospf_iface *ifa, u16 size)
 {
   u32 nrid, myrid;
index 55198a4cde038e6d523a81c9bd96e581390677da..484c43459ed471c87ca8146227851030f06a6e63 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *      BIRD -- OSPF
  *
- *      (c) 2000 Ondrej Filip <feela@network.cz>
+ *      (c) 2000--2004 Ondrej Filip <feela@network.cz>
  *
  *      Can be freely distributed and used under the terms of the GNU GPL.
  *
@@ -14,10 +14,9 @@ struct lsah_n {
   struct ospf_lsa_header lsa;
 };
 
-void ospf_lsack_direct_tx(struct ospf_neighbor *n,struct ospf_lsa_header *h);
-void ospf_lsack_rx(struct ospf_lsack_packet *ps, struct proto *p,
+void ospf_lsack_receive(struct ospf_lsack_packet *ps, struct proto *p,
   struct ospf_iface *ifa, u16 size);
-void ospf_lsack_delay_tx(struct ospf_neighbor *n);
-void ospf_lsa_delay(struct ospf_neighbor *n,struct ospf_lsa_header *h,
-  struct proto *p);
+void ospf_lsack_send(struct ospf_neighbor *n, int queue);
+void ospf_lsack_enqueue(struct ospf_neighbor *n,struct ospf_lsa_header *h,
+  struct proto *p, int queue);
 #endif /* _BIRD_OSPF_LSACK_H_ */
index 39a089dc7c6e6730951fa34c584cc61f8429844c..f56974c966e1b7a07222f45e80c39c920297d9bf 100644 (file)
@@ -366,7 +366,7 @@ ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
     /* pg 143 (4) */
     if((lsatmp.age==LSA_MAXAGE)&&(lsadb==NULL)&&can_flush_lsa(oa))
     {
-      ospf_lsack_direct_tx(n,lsa);
+      ospf_lsack_enqueue(n, lsa, p, ACKL_DIRECT);
       continue;
     }
 
@@ -399,7 +399,7 @@ ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
 
         if((lsatmp.age==LSA_MAXAGE)&&(lsatmp.sn==LSA_MAXSEQNO))
         {
-          ospf_lsack_direct_tx(n,lsa);
+          ospf_lsack_enqueue(n, lsa, p, ACKL_DIRECT);
           continue;
         }
 
@@ -432,9 +432,9 @@ ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
         DBG("Wasn't flooded back\n");  /* ps 144(5e), pg 153 */
         if(ifa->state==OSPF_IS_BACKUP)
        {
-         if(ifa->drid==n->rid) ospf_lsa_delay(n, lsa, p);
+         if(ifa->drid==n->rid) ospf_lsack_enqueue(n, lsa, p, ACKL_DELAY);
        }
-       else ospf_lsa_delay(n, lsa, p);
+       else ospf_lsack_enqueue(n, lsa, p, ACKL_DELAY);
       }
 
       /* Remove old from all ret lists */
@@ -488,13 +488,13 @@ ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
         ospf_hash_delete(n->lsrth, en);
         if(ifa->state==OSPF_IS_BACKUP)
         {
-          if(n->rid==ifa->drid) ospf_lsa_delay(n, lsa, p);
+          if(n->rid==ifa->drid) ospf_lsack_enqueue(n, lsa, p, ACKL_DELAY);
         }
       }
       else
       {
         /* pg145 (7b) */
-        ospf_lsack_direct_tx(n,lsa);
+        ospf_lsack_enqueue(n, lsa, p, ACKL_DIRECT);
       }
       continue;
     }
@@ -517,6 +517,9 @@ ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
     }
   }
 
+  /* Send direct LSAs */
+  ospf_lsack_send(n, ACKL_DIRECT);
+
   if(n->state==NEIGHBOR_LOADING)
   {
     ospf_lsreq_tx(n);  /* Send me another part of database */
index e533eb68ec356fc3b32f006bc4956061f4eb4ca2..eb777b7a472d1805af5cfcbfe1a962c8093fe2b4 100644 (file)
@@ -67,7 +67,8 @@ ospf_neighbor_new(struct ospf_iface *ifa)
   n->ackd_timer->randomize = 0;
   n->ackd_timer->hook = ackd_timer_hook;
   n->ackd_timer->recurrent = ifa->rxmtint/2;
-  init_list(&n->ackl);
+  init_list(&n->ackl[ACKL_DIRECT]);
+  init_list(&n->ackl[ACKL_DELAY]);
   tm_start(n->ackd_timer,n->ifa->rxmtint/2);
   DBG("%s: Installing ackd timer.\n", p->name);
 
@@ -306,10 +307,10 @@ ospf_neigh_sm(struct ospf_neighbor *n, int event)
       {
         neigh_chstate(n,NEIGHBOR_EXCHANGE);
        s_init(&(n->dbsi), &(n->ifa->oa->lsal));
-        while(!EMPTY_LIST(n->ackl))
+        while(!EMPTY_LIST(n->ackl[ACKL_DELAY]))
         {
           struct lsah_n *no;
-          no=(struct lsah_n *)HEAD(n->ackl);
+          no=(struct lsah_n *)HEAD(n->ackl[ACKL_DELAY]);
           rem_node(NODE no);
           mb_free(no);
         }
@@ -611,6 +612,6 @@ void
 ackd_timer_hook(timer *t)
 {
   struct ospf_neighbor *n=t->data;
-  if(!EMPTY_LIST(n->ackl)) ospf_lsack_delay_tx(n);
+  ospf_lsack_send(n, ACKL_DELAY);
 }
 
index 51441505a89ab027726640e8180abee0d96a19fa..56471b687c01fd54c0312392b65ca8f75ea52324 100644 (file)
@@ -356,7 +356,9 @@ struct ospf_neighbor
   struct top_graph *lsrth;
   void *ldbdes;                /* Last database description packet */
   timer *rxmt_timer;   /* RXMT timer */
-  list ackl;
+  list ackl[2];
+#define ACKL_DIRECT 0
+#define ACKL_DELAY 1
   timer *ackd_timer;   /* Delayed ack timer */
 };
 
index 8ee6cba3ec7476d022b420bfd7df729051ab252b..53daa8f2edc176fd375514cbdd84aabeb0146f54 100644 (file)
@@ -192,7 +192,7 @@ ospf_rx_hook (sock * sk, int size)
       break;
     case LSACK_P:
       DBG ("%s: Link state ack received.\n", p->name);
-      ospf_lsack_r((struct ospf_lsack_packet *) ps, p, ifa, size);
+      ospf_lsack_receive((struct ospf_lsack_packet *) ps, p, ifa, size);
       break;
     default:
       log ("%s: Bad packet received: wrong type %u", p->name, ps->type);