Cleanups of message generation code
authorAndreas Tonnesen <andreto@olsr.org>
Wed, 2 Feb 2005 19:59:31 +0000 (19:59 +0000)
committerAndreas Tonnesen <andreto@olsr.org>
Wed, 2 Feb 2005 19:59:31 +0000 (19:59 +0000)
src/build_msg.c
src/build_msg.h
src/generate_msg.c
src/olsr.c
src/packet.c
src/packet.h
src/process_package.c

index b5618b5..de6ccfb 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: build_msg.c,v 1.24 2005/01/16 19:49:28 kattemat Exp $
+ * $Id: build_msg.c,v 1.25 2005/02/02 19:59:17 kattemat Exp $
  */
 
 
 #include "olsr.h"
 
 
+#define BMSG_DBGLVL 5
+
+#define OLSR_IPV4_HDRSIZE          12
+#define OLSR_IPV6_HDRSIZE          24
+
+#define OLSR_HELLO_IPV4_HDRSIZE    (OLSR_IPV4_HDRSIZE + 4)   
+#define OLSR_HELLO_IPV6_HDRSIZE    (OLSR_IPV6_HDRSIZE + 4)
+#define OLSR_TC_IPV4_HDRSIZE       (OLSR_IPV4_HDRSIZE + 4)
+#define OLSR_TC_IPV6_HDRSIZE       (OLSR_IPV6_HDRSIZE + 4)
+#define OLSR_MID_IPV4_HDRSIZE      OLSR_IPV4_HDRSIZE
+#define OLSR_MID_IPV6_HDRSIZE      OLSR_IPV6_HDRSIZE
+#define OLSR_HNA_IPV4_HDRSIZE      OLSR_IPV4_HDRSIZE
+#define OLSR_HNA_IPV6_HDRSIZE      OLSR_IPV6_HDRSIZE
+
+
 /* All these functions share this buffer */
 
 static char msg_buffer[MAXMESSAGESIZE - OLSR_HEADERSIZE];
@@ -55,30 +70,30 @@ static char msg_buffer[MAXMESSAGESIZE - OLSR_HEADERSIZE];
 /* IPv4 */
 
 static olsr_bool
-hello_build4(struct hello_message *, struct interface *);
+serialize_hello4(struct hello_message *, struct interface *);
 
 static olsr_bool
-tc_build4(struct tc_message *, struct interface *);
+serialize_tc4(struct tc_message *, struct interface *);
 
 static olsr_bool
-mid_build4(struct interface *);
+serialize_mid4(struct interface *);
 
 static olsr_bool
-hna_build4(struct interface *);
+serialize_hna4(struct interface *);
 
 /* IPv6 */
 
 static olsr_bool
-hello_build6(struct hello_message *, struct interface *);
+serialize_hello6(struct hello_message *, struct interface *);
 
 static olsr_bool
-tc_build6(struct tc_message *, struct interface *);
+serialize_tc6(struct tc_message *, struct interface *);
 
 static olsr_bool
-mid_build6(struct interface *);
+serialize_mid6(struct interface *);
 
 static olsr_bool
-hna_build6(struct interface *);
+serialize_hna6(struct interface *);
 
 
 
@@ -87,7 +102,7 @@ hna_build6(struct interface *);
  * If this won't fit in one packet, chop it up into several.
  * Send the packet if the size of the data contained in the output buffer
  * reach maxmessagesize. Can generate an empty HELLO packet if the 
- * neighbor table is empty. The parameter messag is not used.
+ * neighbor table is empty. 
  *
  *
  *@param message the hello_message struct containing the info
@@ -98,14 +113,18 @@ hna_build6(struct interface *);
  */
 
 olsr_bool
-hello_build(struct hello_message *message, struct interface *ifp)
+queue_hello(struct hello_message *message, struct interface *ifp)
 {
+#ifdef DEBUG
+  olsr_printf(BMSG_DBGLVL, "Building HELLO on %s\n-------------------\n", ifp->int_name);
+#endif
+
   switch(olsr_cnf->ip_version)
     {
     case(AF_INET):
-      return hello_build4(message, ifp);
+      return serialize_hello4(message, ifp);
     case(AF_INET6):
-      return hello_build6(message, ifp);
+      return serialize_hello6(message, ifp);
     }
   return OLSR_FALSE;
 }
@@ -115,14 +134,7 @@ hello_build(struct hello_message *message, struct interface *ifp)
  * Generate TC packet with the contents of the parameter "message".
  * If this won't fit in one packet, chop it up into several.
  * Send the packet if the size of the data contained in the output buffer
- * reach maxmessagesize. Don't generate an empty TC packet.
- * The parameter messag is not used.
- *
- *If parameter ifp = NULL then this is a TC packet who is to be
- *forwarded. In that case each chump of the packet(if bigger then
- *maxmessagesize the packet has to be split) must be forwarded
- *on each interface(exept the one it came on - if it was a wired interface)
- *and seqnumbers must be taken from the recieved packet.
+ * reach maxmessagesize. 
  *
  *@param message the tc_message struct containing the info
  *to send
@@ -132,14 +144,18 @@ hello_build(struct hello_message *message, struct interface *ifp)
  */
 
 olsr_bool
-tc_build(struct tc_message *message, struct interface *ifp)           
+queue_tc(struct tc_message *message, struct interface *ifp)           
 {
+#ifdef DEBUG
+  olsr_printf(BMSG_DBGLVL, "Building TC on %s\n-------------------\n", ifp->int_name);
+#endif
+
   switch(olsr_cnf->ip_version)
     {
     case(AF_INET):
-      return tc_build4(message, ifp);
+      return serialize_tc4(message, ifp);
     case(AF_INET6):
-      return tc_build6(message, ifp);
+      return serialize_tc6(message, ifp);
     }
   return OLSR_FALSE;
 }
@@ -154,14 +170,18 @@ tc_build(struct tc_message *message, struct interface *ifp)
  */
 
 olsr_bool
-mid_build(struct interface *ifn)
+queue_mid(struct interface *ifp)
 {
+#ifdef DEBUG
+  olsr_printf(BMSG_DBGLVL, "Building MID on %s\n-------------------\n", ifp->int_name);
+#endif
+
   switch(olsr_cnf->ip_version)
     {
     case(AF_INET):
-      return mid_build4(ifn);
+      return serialize_mid4(ifp);
     case(AF_INET6):
-      return mid_build6(ifn);
+      return serialize_mid6(ifp);
     }
   return OLSR_FALSE;
 }
@@ -175,14 +195,18 @@ mid_build(struct interface *ifn)
  *@return nada
  */
 olsr_bool
-hna_build(struct interface *ifp)
+queue_hna(struct interface *ifp)
 {
+#ifdef DEBUG
+  olsr_printf(BMSG_DBGLVL, "Building HNA on %s\n-------------------\n", ifp->int_name);
+#endif
+
   switch(olsr_cnf->ip_version)
     {
     case(AF_INET):
-      return hna_build4(ifp);
+      return serialize_hna4(ifp);
     case(AF_INET6):
-      return hna_build6(ifp);
+      return serialize_hna6(ifp);
     }
   return OLSR_FALSE;
 }
@@ -192,6 +216,16 @@ hna_build(struct interface *ifp)
  */
 
 
+static void
+check_buffspace(int msgsize, int buffsize, char *type)
+{
+  if(msgsize > buffsize)
+    {
+      olsr_printf(1, "%s build, outputbuffer to small(%d/%d)!\n", type, msgsize, buffsize);
+      olsr_syslog(OLSR_LOG_ERR, "%s build, outputbuffer to small(%d/%d)!\n", type, msgsize, buffsize);
+      olsr_exit(__func__, EXIT_FAILURE);
+    }
+}
 
 
 /**
@@ -205,28 +239,25 @@ hna_build(struct interface *ifp)
  */
 
 static olsr_bool
-hello_build4(struct hello_message *message, struct interface *ifp)
+serialize_hello4(struct hello_message *message, struct interface *ifp)
 {
   int remainsize, curr_size;
-  struct hello_neighbor *nb, *prev_nb;
+  struct hello_neighbor *nb;
   union olsr_message *m;
   struct hellomsg *h;
   struct hellinfo *hinfo;
   union olsr_ip_addr *haddr;
-  int i, j, sametype;
-  int lastpacket = 0; /* number of neighbors with the same
-                        greater link status in the last packet */
+  int i, j;
+  olsr_bool first_entry;
+
   if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET))
     return OLSR_FALSE;
 
   remainsize = net_outbuffer_bytes_left(ifp);
 
-  //printf("HELLO build outputsize: %d\n", outputsize);
-
   m = (union olsr_message *)msg_buffer;
 
-  curr_size = 12; /* OLSR message header */
-  curr_size += 4; /* Hello header */
+  curr_size = OLSR_HELLO_IPV4_HDRSIZE;
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -234,13 +265,13 @@ hello_build4(struct hello_message *message, struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  /* Sanity check */
+  check_buffspace(curr_size, remainsize, "HELLO");
 
   h = &m->v4.message.hello;
   hinfo = h->hell_info;
   haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
   
-  //printf("Neighbor addr: %s\n", olsr_ip_to_string(haddr));fflush(stdout);
-
   /* Fill message header */
   m->v4.ttl = message->ttl;
   m->v4.hopcnt = 0;
@@ -265,148 +296,94 @@ hello_build4(struct hello_message *message, struct interface *ifp)
   /* Nighbor statuses */
   for (i = 0; i <= MAX_NEIGH; i++) 
     {
-      /* Link ststuses */
+      /* Link statuses */
       for(j = 0; j <= MAX_LINK; j++)
        {
 
-         /*
-          *HYSTERESIS
-          *Not adding neighbors with link type HIDE
-          */
+         /* HYSTERESIS - Not adding neighbors with link type HIDE */
          
          if(j == HIDE_LINK)
              continue;
 
-         lastpacket = sametype = 0;
-
-         //printf("Neighbortype %d outputsize %d\n", i, outputsize);
+         first_entry = OLSR_TRUE;
 
-         /*
-          *Looping trough neighbors
-          */
+         /* Looping trough neighbors */
          for (nb = message->neighbors; nb != NULL; nb = nb->next) 
            {     
-             if ((nb->status == i) && (nb->link == j))
+             if ((nb->status != i) || (nb->link != j))
+               continue;
+
+#ifdef DEBUG
+             olsr_printf(BMSG_DBGLVL, "\t%s - ", olsr_ip_to_string(&nb->address));
+             olsr_printf(BMSG_DBGLVL, "L:%d N:%d\n", j, i);
+#endif           
+             /*
+              * If there is not enough room left 
+              * for the data in the outputbuffer
+              * we must send a partial HELLO and
+              * continue building the rest of the
+              * data in a new HELLO message
+              *
+              * If this is the first neighbor in 
+              * a group, we must check for an extra
+              * 4 bytes
+              */
+             if((curr_size + ipsize + (first_entry ? 4 : 0)) > remainsize)
                {
-                 sametype++;
-                 if (sametype == 1)
+                 /* Only send partial HELLO if it contains data */
+                 if(curr_size > OLSR_HELLO_IPV4_HDRSIZE)
                    {
-
-                     /*
-                      * If there is not enough room left 
-                      * for the data in tho outputbuffer
-                      * we must send a partial HELLO and
-                      * continue building the rest of the
-                      * data in a new HELLO message
-                      * Add ipsize in check since there is
-                      * no use sending just the type header
-                      */
-                     if((curr_size + 4 + ipsize) > remainsize)
-                       {
-                         /* Only send partial HELLO if it contains data */
-                         if(curr_size > (12 + 4))
-                           {
-                             /* Complete the headers */
-                             m->v4.seqno = htons(get_msg_seqno());
-                             m->v4.olsr_msgsize = htons(curr_size);
-                             
-                             hinfo->size = (char *)haddr - (char *)hinfo;
-                             hinfo->size = ntohs(hinfo->size);
-                             
-                             /* Send partial packet */
-                             net_outbuffer_push(ifp, msg_buffer, curr_size);
-
-                             curr_size = 12; /* OLSR message header */
-                             curr_size += 4; /* Hello header */
-                             
-                             h = &m->v4.message.hello;
-                             hinfo = h->hell_info;
-                             haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
-                           }
-
-                         net_output(ifp);                        
-                         /* Reset size and pointers */
-                         remainsize = net_outbuffer_bytes_left(ifp);
-                       }
-                     memset(&hinfo->reserved, 0, sizeof(olsr_u8_t));
-                     /* Set link and status for this group of neighbors (this is the first) */
-                     hinfo->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
-                     //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
-                     curr_size += 4; /* HELLO type section header */
-                   }
-
 #ifdef DEBUG
-                 olsr_printf(5, "\tLink status of %s: ", olsr_ip_to_string(&nb->address));
-                 olsr_printf(5, "%d\n", nb->link);
+                     olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
 #endif
-                 
-                 /*
-                  * If there is not enough room left 
-                  * for the data in tho outputbuffer
-                  * we must send a partial HELLO and
-                  * continue building the rest of the
-                  * data in a new HELLO message
-                  */
-                 if((curr_size + ipsize) > remainsize)
-                   {
-                     /* If we get here the message contains data
-                      * - no need to check 
-                      */
                      /* Complete the headers */
                      m->v4.seqno = htons(get_msg_seqno());
                      m->v4.olsr_msgsize = htons(curr_size);
                      
-                     hinfo->size = (char *)haddr - (char *)hinfo;
-                     hinfo->size = ntohs(hinfo->size);
+                     hinfo->size = htons((char *)haddr - (char *)hinfo);
                      
                      /* Send partial packet */
                      net_outbuffer_push(ifp, msg_buffer, curr_size);
-                     net_output(ifp);
                      
-                     /* Reset size and pointers */
-                     remainsize = net_outbuffer_bytes_left(ifp);
-                     curr_size = 12; /* OLSR message header */
-                     curr_size += 4; /* Hello header */
+                     curr_size = OLSR_HELLO_IPV4_HDRSIZE;
                      
                      h = &m->v4.message.hello;
                      hinfo = h->hell_info;
-                     haddr = (union olsr_ip_addr *)hinfo->neigh_addr;
-                     
-                     /* Rebuild TYPE header */
-                     memset(&hinfo->reserved, 0, sizeof(olsr_u8_t));
-                     /* Set link and status for this group of neighbors (this is the first) */
-                     hinfo->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
-                     //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
-                     curr_size += 4; /* HELLO type section header */
-                     
+                     haddr = (union olsr_ip_addr *)hinfo->neigh_addr;                    
+                     /* Make sure typeheader is added */
+                     first_entry = OLSR_TRUE;
                    }
-
-                 COPY_IP(haddr, &nb->address);
-
-                 //printf("\n\n1: %d\n", (char *)haddr - packet);
-                 /*
-                  *Point to next address
-                  */
-                 haddr = (union olsr_ip_addr *)&haddr->v6.s6_addr[4];
-                 curr_size += ipsize; /* IP address added */
-
-                 //printf("\n2: %d\n\n", (char *)haddr - packet); 
-                 //printf("Ipsize: %d\n", ipsize);
-
-                 //printf("Adding neighbor %s\n", olsr_ip_to_string(&nb->address));
-   
+                 
+                 net_output(ifp);                        
+                 /* Reset size and pointers */
+                 remainsize = net_outbuffer_bytes_left(ifp);
+                 
+                 /* Sanity check */
+                 check_buffspace(curr_size + ipsize + 4, remainsize, "HELLO2");
                }
-    
-           }/* looping trough neighbors */
-           
+             
+             if (first_entry)
+               {
+                 memset(&hinfo->reserved, 0, sizeof(olsr_u8_t));
+                 /* Set link and status for this group of neighbors (this is the first) */
+                 hinfo->link_code = CREATE_LINK_CODE(i, j);
+                 curr_size += 4; /* HELLO type section header */
+               }
+             
+             COPY_IP(haddr, &nb->address);
+             
+             /* Point to next address */
+             haddr = (union olsr_ip_addr *)&haddr->v6.s6_addr[4];
+             curr_size += ipsize; /* IP address added */
 
-         if (sametype && sametype > lastpacket)
+             first_entry = OLSR_FALSE;
+           }
+    
+         if(!first_entry)
            {
-             hinfo->size = (char *)haddr - (char *)hinfo;
-             hinfo->size = ntohs(hinfo->size);
+             hinfo->size = htons((char *)haddr - (char *)hinfo);
              hinfo = (struct hellinfo *)((char *)haddr);
              haddr = (union olsr_ip_addr *)&hinfo->neigh_addr;
-             
            }
        } /* for j */
     } /* for i*/
@@ -416,19 +393,6 @@ hello_build4(struct hello_message *message, struct interface *ifp)
   
   net_outbuffer_push(ifp, msg_buffer, curr_size);
 
-  /*
-   * Delete the list of neighbor messages.
-   */
-     
-  nb = message->neighbors;
-     
-  while (nb)
-    {
-      prev_nb = nb;
-      nb = nb->next;
-      free(prev_nb);
-    }
-
   /* HELLO will always be generated */
   return OLSR_TRUE;
 }
@@ -448,30 +412,24 @@ hello_build4(struct hello_message *message, struct interface *ifp)
 
 
 static olsr_bool
-hello_build6(struct hello_message *message, struct interface *ifp)
+serialize_hello6(struct hello_message *message, struct interface *ifp)
 {
   int remainsize, curr_size;
-  struct hello_neighbor *nb, *prev_nb;
+  struct hello_neighbor *nb;
   union olsr_message *m;
   struct hellomsg6 *h6;
   struct hellinfo6 *hinfo6;
   union olsr_ip_addr *haddr;
+  int i, j;
+  olsr_bool first_entry;
 
-  int i, j, sametype;
-  int lastpacket = 0; /* number of neighbors with the same
-                        greater link status in the last packet */
   if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET6))
     return OLSR_FALSE;
 
-
   remainsize = net_outbuffer_bytes_left(ifp);
-
-  //printf("HELLO build outputsize: %d\n", outputsize);
-
   m = (union olsr_message *)msg_buffer;
 
-  curr_size = 24; /* OLSR message header */
-  curr_size += 4; /* Hello header */
+  curr_size = OLSR_HELLO_IPV6_HDRSIZE; /* OLSR message header */
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -479,8 +437,8 @@ hello_build6(struct hello_message *message, struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  check_buffspace(curr_size + ipsize + 4, remainsize, "HELLO");
 
-  //printf("HELLO build outputsize: %d\n", outputsize);
   h6 = &m->v6.message.hello;
   hinfo6 = h6->hell_info;
   haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
@@ -497,12 +455,8 @@ hello_build6(struct hello_message *message, struct interface *ifp)
   
   /* Fill packet header */
   h6->willingness = message->willingness; 
-
   h6->htime = ifp->hello_etime;
-
   memset(&h6->reserved, 0, sizeof(olsr_u16_t));
-  
-  
 
   /*
    *Loops trough all possible neighbor statuses
@@ -513,124 +467,87 @@ hello_build6(struct hello_message *message, struct interface *ifp)
     {
       for(j = 0; j <= MAX_LINK; j++)
        {
-         
-         
-         lastpacket = sametype = 0;
-         
-         
-         //printf("Neighbortype %d outputsize %d\n", i, outputsize);
+         first_entry = OLSR_TRUE;
                  
          /*
           *Looping trough neighbors
           */
          for (nb = message->neighbors; nb != NULL; nb = nb->next) 
            {         
-             if ((nb->status == i) && (nb->link == j))
-               {             
-                 sametype++;
-                 if (sametype == 1)
-                   {
-                     /* Check if there is room for header + one address */
-                     if((curr_size + 4 + ipsize) > remainsize)
-                       {
-                         /* Only send partial HELLO if it contains data */
-                         if(curr_size > (24 + 4))
-                           {
-                             /* Complete the headers */
-                             m->v6.seqno = htons(get_msg_seqno());
-                             m->v6.olsr_msgsize = htons(curr_size);
-                             
-                             hinfo6->size = (char *)haddr - (char *)hinfo6;
-                             hinfo6->size = ntohs(hinfo6->size);
-                             
-                             /* Send partial packet */
-                             net_outbuffer_push(ifp, msg_buffer, curr_size);
-                             curr_size = 24; /* OLSR message header */
-                             curr_size += 4; /* Hello header */
-                             
-                             h6 = &m->v6.message.hello;
-                             hinfo6 = h6->hell_info;
-                             haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
-                           }
-                         net_output(ifp);
-                         /* Reset size and pointers */
-                         remainsize = net_outbuffer_bytes_left(ifp);
-                       }
-                     memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));
-                     /* Set link and status for this group of neighbors (this is the first) */
-                     hinfo6->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
-                     //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
-                     curr_size += 4; /* HELLO type section header */
-                   }
+             if ((nb->status != i) || (nb->link != j))
+               continue;
 
 #ifdef DEBUG
-                 olsr_printf(5, "\tLink status of %s: ", olsr_ip_to_string(&nb->address));
-                 olsr_printf(5, "%d\n", nb->link);
-#endif
-
-                 /*
-                  * If there is not enough room left 
-                  * for the data in the outputbuffer
-                  * we must send a partial HELLO and
-                  * continue building the rest of the
-                  * data in a new HELLO message
-                  */
-                 if((curr_size + ipsize) > remainsize)
+             olsr_printf(BMSG_DBGLVL, "\t%s - ", olsr_ip_to_string(&nb->address));
+             olsr_printf(BMSG_DBGLVL, "L:%d N:%d\n", j, i);
+#endif           
+
+
+             /*
+              * If there is not enough room left 
+              * for the data in the outputbuffer
+              * we must send a partial HELLO and
+              * continue building the rest of the
+              * data in a new HELLO message
+              *
+              * If this is the first neighbor in 
+              * a group, we must check for an extra
+              * 4 bytes
+              */
+             if((curr_size + ipsize + (first_entry ? 4 : 0)) > remainsize)
+               {
+                 /* Only send partial HELLO if it contains data */
+                 if(curr_size > OLSR_HELLO_IPV6_HDRSIZE)
                    {
-                     /* If we get here the message contains data
-                      * - no need to check 
-                      */
+#ifdef DEBUG
+                     olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
                      /* Complete the headers */
                      m->v6.seqno = htons(get_msg_seqno());
                      m->v6.olsr_msgsize = htons(curr_size);
-                     
+                         
                      hinfo6->size = (char *)haddr - (char *)hinfo6;
-                     hinfo6->size = ntohs(hinfo6->size);
-                     
+                     hinfo6->size = htons(hinfo6->size);
+                         
                      /* Send partial packet */
-                         net_outbuffer_push(ifp, msg_buffer, curr_size);
-                     curr_size = 24; /* OLSR message header */
-                     curr_size += 4; /* Hello header */
-                     
+                     net_outbuffer_push(ifp, msg_buffer, curr_size);
+                     curr_size = OLSR_HELLO_IPV6_HDRSIZE;
+                         
                      h6 = &m->v6.message.hello;
                      hinfo6 = h6->hell_info;
                      haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;
-                     
-                     /* Rebuild TYPE header */
-                     memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));
-                     /* Set link and status for this group of neighbors (this is the first) */
-                     hinfo6->link_code = CREATE_LINK_CODE(i, j);//j | (i<<2);
-                     //printf("(2)Setting neighbor link status: %x\n", hinfo->link_code);
-                     curr_size += 4; /* HELLO type section header */
-
-                     net_output(ifp);                
-                     /* Reset size */
-                     remainsize = net_outbuffer_bytes_left(ifp);
-                     
+                     /* Make sure typeheader is added */
+                     first_entry = OLSR_TRUE;
                    }
+                 net_output(ifp);
+                 /* Reset size and pointers */
+                 remainsize = net_outbuffer_bytes_left(ifp);
+
+                 check_buffspace(curr_size + ipsize + 4, remainsize, "HELLO2");
+                     
+               }
 
-                 COPY_IP(haddr, &nb->address);
+             if(first_entry)
+               {
+                 memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));
+                 /* Set link and status for this group of neighbors (this is the first) */
+                 hinfo6->link_code = CREATE_LINK_CODE(i, j);
+                 curr_size += 4; /* HELLO type section header */
+               }
                  
-                 //printf("\n\n1: %d\n", (char *)haddr - packet);
-                 /*
-                  *Point to next address
-                  */
-                 haddr++;
-                 curr_size += ipsize; /* IP address added */ 
-                 //printf("\n2: %d\n\n", (char *)haddr - packet); 
-                 //printf("Ipsize: %d\n", ipsize);
+             COPY_IP(haddr, &nb->address);
                  
-                 //printf("Adding neighbor %s\n", olsr_ip_to_string(&nb->address));
+             /* Point to next address */
+             haddr++;
+             curr_size += ipsize; /* IP address added */ 
                  
-               }
-             
+             first_entry = OLSR_FALSE;
            }/* looping trough neighbors */
-           
          
-         if (sametype && sametype > lastpacket)
+         
+         if (!first_entry)
            {
-             hinfo6->size = (char *)haddr - (char *)hinfo6;
-             hinfo6->size = ntohs(hinfo6->size);
+             hinfo6->size = htons((char *)haddr - (char *)hinfo6);
              hinfo6 = (struct hellinfo6 *)((char *)haddr);
              haddr = (union olsr_ip_addr *)&hinfo6->neigh_addr;
            }
@@ -643,27 +560,12 @@ hello_build6(struct hello_message *message, struct interface *ifp)
 
   net_outbuffer_push(ifp, msg_buffer, curr_size);
 
-  /*
-   * Delete the list of neighbor messages.
-   */
-     
-  nb = message->neighbors;
-     
-  while (nb)
-    {
-      prev_nb = nb;
-      nb = nb->next;
-      free(prev_nb);
-    }
-
   /* HELLO is always buildt */
   return OLSR_TRUE;
 }
 
 
 
-
-
 /**
  *IP version 4
  *
@@ -675,11 +577,11 @@ hello_build6(struct hello_message *message, struct interface *ifp)
  */
 
 static olsr_bool
-tc_build4(struct tc_message *message, struct interface *ifp)           
+serialize_tc4(struct tc_message *message, struct interface *ifp)           
 {
 
   int remainsize, curr_size;
-  struct tc_mpr_addr *mprs, *prev_mprs;
+  struct tc_mpr_addr *mprs;
   union olsr_message *m;
   struct tcmsg *tc;
   struct neigh_info *mprsaddr; 
@@ -696,8 +598,7 @@ tc_build4(struct tc_message *message, struct interface *ifp)
 
 
   mprsaddr = tc->neigh;
-  curr_size = 12; /* OLSR message header */
-  curr_size += 4; /* TC header */
+  curr_size = OLSR_TC_IPV4_HDRSIZE;
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -705,6 +606,7 @@ tc_build4(struct tc_message *message, struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  check_buffspace(curr_size, remainsize, "TC");
 
   /* Fill header */
   m->v4.olsr_vtime = ifp->valtimes.tc;
@@ -726,8 +628,12 @@ tc_build4(struct tc_message *message, struct interface *ifp)
        {
 
          /* Only add TC message if it contains data */
-         if(curr_size > (12 + 4 ))
+         if(curr_size > OLSR_TC_IPV4_HDRSIZE)
            {
+#ifdef DEBUG
+             olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
+
              m->v4.olsr_msgsize = htons(curr_size);
              m->v4.seqno = htons(get_msg_seqno());
 
@@ -735,18 +641,21 @@ tc_build4(struct tc_message *message, struct interface *ifp)
              
              /* Reset stuff */
              mprsaddr = tc->neigh;
-             curr_size = 12; /* OLSR message header */
-             curr_size += 4; /* TC header */
+             curr_size = OLSR_TC_IPV4_HDRSIZE;
              found = OLSR_FALSE;
              partial_sent = OLSR_TRUE;
            }
 
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left(ifp);
+         check_buffspace(curr_size + ipsize, remainsize, "TC2");
 
        }
       found = OLSR_TRUE;
-      
+#ifdef DEBUG
+         olsr_printf(BMSG_DBGLVL, "\t%s\n", 
+                     olsr_ip_to_string(&mprs->address));
+#endif 
       COPY_IP(&mprsaddr->addr, &mprs->address);
 
       curr_size += ipsize;
@@ -777,27 +686,11 @@ tc_build4(struct tc_message *message, struct interface *ifp)
        }
     }
 
-
-  /*
-   * Delete the list of mprs messages
-   */
-       
-  mprs = message->multipoint_relay_selector_address;
-       
-  while (mprs)
-    {
-      prev_mprs = mprs;
-      mprs = mprs->next;
-      free(prev_mprs);
-    }
-
-
-  return found ? OLSR_TRUE : OLSR_FALSE;       
+  return found;        
 }
 
 
 
-
 /**
  *IP version 6
  *
@@ -809,11 +702,11 @@ tc_build4(struct tc_message *message, struct interface *ifp)
  */
 
 static olsr_bool
-tc_build6(struct tc_message *message, struct interface *ifp)           
+serialize_tc6(struct tc_message *message, struct interface *ifp)           
 {
 
   int remainsize, curr_size;
-  struct tc_mpr_addr *mprs, *prev_mprs;
+  struct tc_mpr_addr *mprs;
   union olsr_message *m;
   struct tcmsg6 *tc6;
   struct neigh_info6 *mprsaddr6; 
@@ -829,8 +722,7 @@ tc_build6(struct tc_message *message, struct interface *ifp)
   tc6 = &m->v6.message.tc;
 
   mprsaddr6 = tc6->neigh;
-  curr_size = 24; /* OLSR message header */
-  curr_size += 4; /* TC header */
+  curr_size = OLSR_TC_IPV6_HDRSIZE;
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -838,6 +730,7 @@ tc_build6(struct tc_message *message, struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  check_buffspace(curr_size, remainsize, "TC");
 
   /* Fill header */
   m->v6.olsr_vtime = ifp->valtimes.tc;
@@ -859,27 +752,30 @@ tc_build6(struct tc_message *message, struct interface *ifp)
       if((curr_size + ipsize) > remainsize)
        {
          /* Only add TC message if it contains data */
-         if(curr_size > (24 + 4 ))
+         if(curr_size > OLSR_TC_IPV6_HDRSIZE)
            {
+#ifdef DEBUG
+             olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
              m->v6.olsr_msgsize = htons(curr_size);
              m->v6.seqno = htons(get_msg_seqno());
 
              net_outbuffer_push(ifp, msg_buffer, curr_size);
              mprsaddr6 = tc6->neigh;
-             curr_size = 24; /* OLSR message header */
-             curr_size += 4; /* TC header */
+             curr_size = OLSR_TC_IPV6_HDRSIZE;
              found = OLSR_FALSE;
              partial_sent = OLSR_TRUE;
            }
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left(ifp);
-               
+         check_buffspace(curr_size + ipsize, remainsize, "TC2");
 
        }
       found = OLSR_TRUE;
-
-      //printf("mprsaddr6 is %x\n", (char *)mprsaddr6 - packet);
-      //printf("Adding MPR-selector: %s\n", olsr_ip_to_string(&mprs->address));fflush(stdout);     
+#ifdef DEBUG
+         olsr_printf(BMSG_DBGLVL, "\t%s\n", 
+                     olsr_ip_to_string(&mprs->address));
+#endif
       COPY_IP(&mprsaddr6->addr, &mprs->address);
       curr_size += ipsize;
 
@@ -909,20 +805,7 @@ tc_build6(struct tc_message *message, struct interface *ifp)
        }
     }
 
-  /*
-   * Delete the list of mprs messages
-   */
-       
-  mprs = message->multipoint_relay_selector_address;
-       
-  while (mprs)
-    {
-      prev_mprs = mprs;
-      mprs = mprs->next;
-      free(prev_mprs);
-    }
-
-  return found ? OLSR_TRUE : OLSR_FALSE;       
+  return found;        
 }
 
 
@@ -937,7 +820,7 @@ tc_build6(struct tc_message *message, struct interface *ifp)
  */
 
 static olsr_bool
-mid_build4(struct interface *ifp)
+serialize_mid4(struct interface *ifp)
 {
   int remainsize, curr_size;
   /* preserve existing data in output buffer */
@@ -953,7 +836,7 @@ mid_build4(struct interface *ifp)
 
   m = (union olsr_message *)msg_buffer;
 
-  curr_size = 12; /* OLSR message header */
+  curr_size = OLSR_MID_IPV4_HDRSIZE;
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -961,6 +844,7 @@ mid_build4(struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  check_buffspace(curr_size, remainsize, "MID");
 
   /* Fill header */
   m->v4.hopcnt = 0;
@@ -981,19 +865,28 @@ mid_build4(struct interface *ifp)
          if((curr_size + ipsize) > remainsize)
            {
              /* Only add MID message if it contains data */
-             if(curr_size > 12)
+             if(curr_size > OLSR_MID_IPV4_HDRSIZE)
                {
+#ifdef DEBUG
+                 olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
                  /* set size */
                  m->v4.olsr_msgsize = htons(curr_size);
                  m->v4.seqno = htons(get_msg_seqno());/* seqnumber */
                  
                  net_outbuffer_push(ifp, msg_buffer, curr_size);
-                 curr_size = 12; /* OLSR message header */
+                 curr_size = OLSR_MID_IPV4_HDRSIZE;
                  addrs = m->v4.message.mid.mid_addr;
                }
              net_output(ifp);
              remainsize = net_outbuffer_bytes_left(ifp);
+             check_buffspace(curr_size, remainsize, "MID2");
            }
+#ifdef DEBUG
+         olsr_printf(BMSG_DBGLVL, "\t%s(%s)\n", 
+                     olsr_ip_to_string(&ifs->ip_addr), 
+                     ifs->int_name);
+#endif
          
          COPY_IP(&addrs->addr, &ifs->ip_addr);
          addrs++;
@@ -1023,7 +916,7 @@ mid_build4(struct interface *ifp)
  */
 
 static olsr_bool
-mid_build6(struct interface *ifp)
+serialize_mid6(struct interface *ifp)
 {
   int remainsize, curr_size;
   /* preserve existing data in output buffer */
@@ -1039,7 +932,7 @@ mid_build6(struct interface *ifp)
 
   remainsize = net_outbuffer_bytes_left(ifp);
 
-  curr_size = 24; /* OLSR message header */
+  curr_size = OLSR_MID_IPV6_HDRSIZE;
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -1047,6 +940,7 @@ mid_build6(struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  check_buffspace(curr_size + ipsize, remainsize, "MID");
 
   m = (union olsr_message *)msg_buffer;
     
@@ -1069,19 +963,28 @@ mid_build6(struct interface *ifp)
          if((curr_size + ipsize) > remainsize)
            {
              /* Only add MID message if it contains data */
-             if(curr_size > 24)
+             if(curr_size > OLSR_MID_IPV6_HDRSIZE)
                {
+#ifdef DEBUG
+                 olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
                  /* set size */
                  m->v6.olsr_msgsize = htons(curr_size);
                  m->v6.seqno = htons(get_msg_seqno());/* seqnumber */
                  
                  net_outbuffer_push(ifp, msg_buffer, curr_size);
-                 curr_size = 24; /* OLSR message header */
+                 curr_size = OLSR_MID_IPV6_HDRSIZE;
                  addrs6 = m->v6.message.mid.mid_addr;
                }
              net_output(ifp);
              remainsize = net_outbuffer_bytes_left(ifp);
+             check_buffspace(curr_size + ipsize, remainsize, "MID2");
            }
+#ifdef DEBUG
+                 olsr_printf(BMSG_DBGLVL, "\t%s(%s)\n", 
+                             olsr_ip_to_string(&ifs->ip_addr), 
+                             ifs->int_name);
+#endif
 
          COPY_IP(&addrs6->addr, &ifs->ip_addr);
          addrs6++;
@@ -1108,7 +1011,7 @@ mid_build6(struct interface *ifp)
  *@return nada
  */
 static olsr_bool
-hna_build4(struct interface *ifp)
+serialize_hna4(struct interface *ifp)
 {
   int remainsize, curr_size;
   /* preserve existing data in output buffer */
@@ -1122,7 +1025,7 @@ hna_build4(struct interface *ifp)
     
   remainsize = net_outbuffer_bytes_left(ifp);
   
-  curr_size = 12; /* OLSR message header */
+  curr_size = OLSR_HNA_IPV4_HDRSIZE;
   
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -1130,7 +1033,8 @@ hna_build4(struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
-  
+  check_buffspace(curr_size, remainsize, "HNA");
+
   m = (union olsr_message *)msg_buffer;
   
   
@@ -1149,17 +1053,26 @@ hna_build4(struct interface *ifp)
       if((curr_size + (2 * ipsize)) > remainsize)
        {
          /* Only add HNA message if it contains data */
-         if(curr_size > 12)
+         if(curr_size > OLSR_HNA_IPV4_HDRSIZE)
            {
+#ifdef DEBUG
+             olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
              m->v4.seqno = htons(get_msg_seqno());
              m->v4.olsr_msgsize = htons(curr_size);
              net_outbuffer_push(ifp, msg_buffer, curr_size);
-             curr_size = 12; /* OLSR message header */
+             curr_size = OLSR_HNA_IPV4_HDRSIZE;
              pair = m->v4.message.hna.hna_net;
            }
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left(ifp);
+         check_buffspace(curr_size + (2 * ipsize), remainsize, "HNA2");
        }
+#ifdef DEBUG
+      olsr_printf(BMSG_DBGLVL, "\tNet: %s/%s\n", 
+                 olsr_ip_to_string(&h->net),
+                 olsr_ip_to_string(&h->netmask));
+#endif
       COPY_IP(&pair->addr, &h->net);
       COPY_IP(&pair->netmask, &h->netmask);
       pair++;
@@ -1187,7 +1100,7 @@ hna_build4(struct interface *ifp)
  *@return nada
  */
 static olsr_bool
-hna_build6(struct interface *ifp)
+serialize_hna6(struct interface *ifp)
 {
   int remainsize, curr_size;
   /* preserve existing data in output buffer */
@@ -1203,7 +1116,7 @@ hna_build6(struct interface *ifp)
     
   remainsize = net_outbuffer_bytes_left(ifp);
 
-  curr_size = 24; /* OLSR message header */
+  curr_size = OLSR_HNA_IPV6_HDRSIZE;
 
   /* Send pending packet if not room in buffer */
   if(curr_size > remainsize)
@@ -1211,6 +1124,7 @@ hna_build6(struct interface *ifp)
       net_output(ifp);
       remainsize = net_outbuffer_bytes_left(ifp);
     }
+  check_buffspace(curr_size, remainsize, "HNA");
 
   m = (union olsr_message *)msg_buffer;   
 
@@ -1229,19 +1143,26 @@ hna_build6(struct interface *ifp)
       if((curr_size + (2 * ipsize)) > remainsize)
        {
          /* Only add HNA message if it contains data */
-         if(curr_size > 24)
+         if(curr_size > OLSR_HNA_IPV6_HDRSIZE)
            {
+#ifdef DEBUG
+             olsr_printf(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
+#endif
              m->v6.seqno = htons(get_msg_seqno());
              m->v6.olsr_msgsize = htons(curr_size);
              net_outbuffer_push(ifp, msg_buffer, curr_size);
-             curr_size = 24; /* OLSR message header */
+             curr_size = OLSR_HNA_IPV6_HDRSIZE;
              pair6 = m->v6.message.hna.hna_net;
            }
          net_output(ifp);
          remainsize = net_outbuffer_bytes_left(ifp);
+         check_buffspace(curr_size + (2 * ipsize), remainsize, "HNA2");
        }
-      
-      //printf("Adding %s\n", olsr_ip_to_string(&h->hna_net.addr));
+#ifdef DEBUG
+      olsr_printf(BMSG_DBGLVL, "\tNet: %s/%d\n", 
+                 olsr_ip_to_string(&h->net),
+                 h->prefix_len);
+#endif
       COPY_IP(&pair6->addr, &h->net);
       olsr_prefix_to_netmask(&tmp_netmask, h->prefix_len);
       COPY_IP(&pair6->netmask, &tmp_netmask);
index e385fac..5f11310 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: build_msg.h,v 1.11 2004/12/12 18:57:51 kattemat Exp $
+ * $Id: build_msg.h,v 1.12 2005/02/02 19:59:18 kattemat Exp $
  */
 
 #ifndef _BUILD_MSG_H
 #include "olsr_protocol.h"
 
 olsr_bool
-hello_build(struct hello_message *, struct interface *);
+queue_hello(struct hello_message *, struct interface *);
 
 olsr_bool
-tc_build(struct tc_message *, struct interface *);
+queue_tc(struct tc_message *, struct interface *);
 
 olsr_bool
-mid_build(struct interface *);
+queue_mid(struct interface *);
 
 olsr_bool
-hna_build(struct interface *);
+queue_hna(struct interface *);
 
 #endif
index f809584..06ab6b4 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: generate_msg.c,v 1.21 2005/01/16 19:49:28 kattemat Exp $
+ * $Id: generate_msg.c,v 1.22 2005/02/02 19:59:18 kattemat Exp $
  */
 
 #include "generate_msg.h"
@@ -70,8 +70,11 @@ generate_hello(void *p)
 
   olsr_build_hello_packet(&hellopacket, ifn);
       
-  if(hello_build(&hellopacket, ifn))
+  if(queue_hello(&hellopacket, ifn))
     net_output(ifn);
+
+  olsr_free_hello_packet(&hellopacket);
+
 }
 
 void
@@ -82,10 +85,12 @@ generate_tc(void *p)
 
   olsr_build_tc_packet(&tcpacket);
 
-  if(tc_build(&tcpacket, ifn) && TIMED_OUT(fwdtimer[ifn->if_nr]))
+  if(queue_tc(&tcpacket, ifn) && TIMED_OUT(fwdtimer[ifn->if_nr]))
     {
       set_buffer_timer(ifn);
     }
+
+  olsr_free_tc_packet(&tcpacket);
 }
 
 void
@@ -93,7 +98,7 @@ generate_mid(void *p)
 {
   struct interface *ifn = (struct interface *)p;
   
-  if(mid_build(ifn) && TIMED_OUT(fwdtimer[ifn->if_nr]))
+  if(queue_mid(ifn) && TIMED_OUT(fwdtimer[ifn->if_nr]))
     {
       set_buffer_timer(ifn);
     }
@@ -107,7 +112,7 @@ generate_hna(void *p)
 {
   struct interface *ifn = (struct interface *)p;
   
-  if(hna_build(ifn) && TIMED_OUT(fwdtimer[ifn->if_nr]))
+  if(queue_hna(ifn) && TIMED_OUT(fwdtimer[ifn->if_nr]))
     {
       set_buffer_timer(ifn);
     }
index 95686ad..1e4a2e8 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: olsr.c,v 1.37 2005/01/22 12:25:25 tlopatic Exp $
+ * $Id: olsr.c,v 1.38 2005/02/02 19:59:18 kattemat Exp $
  */
 
 /**
 #include <signal.h>
 
 
-/**
- *Checks if a timer has timed out.
- */
-
-
 /**
  *Initiates a "timer", wich is a timeval structure,
  *with the value given in time_value.
 inline void
 olsr_init_timer(olsr_u32_t time_value, struct timeval *hold_timer)
 { 
-  olsr_u16_t  time_value_sec;
-  olsr_u16_t  time_value_msec;
-
-  time_value_sec = time_value/1000;
-  time_value_msec = time_value-(time_value_sec*1000);
+  olsr_u16_t  time_value_sec = time_value/1000;
+  olsr_u16_t  time_value_msec = time_value-(time_value_sec*1000);
 
   hold_timer->tv_sec = time_value_sec;
   hold_timer->tv_usec = time_value_msec*1000;   
index 14feff2..e2855c1 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: packet.c,v 1.14 2005/01/16 19:49:28 kattemat Exp $
+ * $Id: packet.c,v 1.15 2005/02/02 19:59:31 kattemat Exp $
  */
 
 
 
 static olsr_bool sending_tc = OLSR_FALSE;
 
+
+
+/**
+ *Free the memory allocated for a HELLO packet.
+ *
+ *@param message the pointer to the packet to erase
+ *
+ *@return nada
+ */
+void
+olsr_free_hello_packet(struct hello_message *message)
+{
+  struct hello_neighbor *nb, *prev_nb;
+
+  if(!message)
+    return;
+  
+  nb = message->neighbors;
+  
+  while (nb)
+    {
+      prev_nb = nb;
+      nb = nb->next;
+      free(prev_nb);
+    }
+}
+
 /**
  *Build an internal HELLO package for this
  *node. This MUST be done for each interface.
@@ -290,6 +317,31 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
 }
 
 
+/**
+ *Free the memory allocated for a TC packet.
+ *
+ *@param message the pointer to the packet to erase
+ *
+ *@return nada
+ */
+void 
+olsr_free_tc_packet(struct tc_message *message)
+{
+  struct tc_mpr_addr *mprs, *prev_mprs;
+
+  if(!message)
+    return;
+
+  mprs = message->multipoint_relay_selector_address;
+  
+  while (mprs)
+    {
+      prev_mprs = mprs;
+      mprs = mprs->next;
+      free(prev_mprs);
+    }
+}
+
 /**
  *Build an internal TC package for this
  *node.
@@ -401,59 +453,6 @@ olsr_build_tc_packet(struct tc_message *message)
 }
 
 
-
-
-/**
- *Free the memory allocated for a HELLO packet.
- *
- *@param message the pointer to the packet to erase
- *
- *@return nada
- */
-void
-olsr_destroy_hello_message(struct hello_message *message)
-{
-  struct hello_neighbor  *neighbors;
-  struct hello_neighbor  *neighbors_tmp;
-
-
-  neighbors=message->neighbors;
-  
-  while(neighbors!=NULL)
-    {
-      neighbors_tmp=neighbors;
-      neighbors=neighbors->next;
-      free(neighbors_tmp);
-    }
-}
-
-
-/**
- *Free the memory allocated for a TC packet.
- *
- *@param message the pointer to the packet to erase
- *
- *@return nada
- */
-
-void
-olsr_destroy_tc_message(struct tc_message *message)
-{
-  struct tc_mpr_addr  *mpr_set;
-  struct tc_mpr_addr  *mpr_set_tmp;
-
-  mpr_set=message->multipoint_relay_selector_address;
-
-  while( mpr_set!=NULL)
-    {
-      mpr_set_tmp=mpr_set;
-      mpr_set=mpr_set->next;
-      free(mpr_set_tmp);
-    }
-}
-
-
-
 /**
  *Free the memory allocated for a HNA packet.
  *
index 3e719fc..e7d7bb7 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: packet.h,v 1.12 2004/12/04 17:06:57 tlopatic Exp $
+ * $Id: packet.h,v 1.13 2005/02/02 19:59:31 kattemat Exp $
  */
 
 
@@ -162,9 +162,15 @@ struct unknown_message
 };
 
 
+void
+olsr_free_hello_packet(struct hello_message *);
+
 int
 olsr_build_hello_packet(struct hello_message *, struct interface *);
 
+void 
+olsr_free_tc_packet(struct tc_message *);
+
 int
 olsr_build_tc_packet(struct tc_message *);
 
index 5cb081f..b640fd9 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: process_package.c,v 1.26 2005/01/17 20:18:21 kattemat Exp $
+ * $Id: process_package.c,v 1.27 2005/02/02 19:59:31 kattemat Exp $
  */
 
 
@@ -181,7 +181,7 @@ olsr_hello_tap(struct hello_message *message, struct interface *in_if,
   /* Process changes immedeatly in case of MPR updates */
   olsr_process_changes();
 
-  olsr_destroy_hello_message(message);
+  olsr_free_hello_packet(message);
 
   return;
 }
@@ -229,7 +229,7 @@ olsr_tc_tap(struct tc_message *message, struct interface *in_if,
     {
       olsr_printf(2, "Received TC from NON SYM neighbor %s\n",
                   olsr_ip_to_string(from_addr));
-      olsr_destroy_tc_message(message);
+      olsr_free_tc_packet(message);
       return;
     }
 
@@ -297,7 +297,7 @@ olsr_tc_tap(struct tc_message *message, struct interface *in_if,
                        in_if,
                        from_addr);
 
-  olsr_destroy_tc_message(message);
+  olsr_free_tc_packet(message);
 
   return;
 }