[Olsr-cvs] olsrd-current/src rebuild_packet.h, 1.10, 1.11 rebuild_packet.c, 1.27, 1.28 process_package.c, 1.48, 1.49 packet.h, 1.19, 1.20 packet.c, 1.28, 1.29 lq_packet.h, 1.10, 1.11

Bernd Petrovitsch (spam-protected)
Fri Nov 30 00:03:09 CET 2007


Update of /cvsroot/olsrd/olsrd-current/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23889/src

Modified Files:
	rebuild_packet.h rebuild_packet.c process_package.c packet.h 
	packet.c lq_packet.h 
Log Message:
- killed hna_chgestruct to reduce malloc()/free() churn


Index: lq_packet.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/lq_packet.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** lq_packet.h	16 Nov 2007 22:56:54 -0000	1.10
--- lq_packet.h	29 Nov 2007 23:03:07 -0000	1.11
***************
*** 46,49 ****
--- 46,50 ----
  #include "packet.h"
  #include "mantissa.h"
+ #include "ipcalc.h"
  
  #define LQ_HELLO_MESSAGE      201
***************
*** 142,154 ****
  };
  
! static INLINE void        pkt_get_u8(const olsr_u8_t **p, olsr_u8_t  *var)         { *var =       *(const olsr_u8_t *)(*p);   *p += sizeof(olsr_u8_t); }
! static INLINE void       pkt_get_u16(const olsr_u8_t **p, olsr_u16_t *var)         { *var = ntohs(*(const olsr_u16_t *)(*p)); *p += sizeof(olsr_u16_t); }
! static INLINE void       pkt_get_u32(const olsr_u8_t **p, olsr_u32_t *var)         { *var = ntohl(*(const olsr_u32_t *)(p));  *p += sizeof(olsr_u32_t); }
! static INLINE void        pkt_get_s8(const olsr_u8_t **p, olsr_8_t  *var)          { *var =       *(const olsr_8_t *)(*p);    *p += sizeof(olsr_8_t); }
! static INLINE void       pkt_get_s16(const olsr_u8_t **p, olsr_16_t *var)          { *var = ntohs(*(const olsr_16_t *)(*p));  *p += sizeof(olsr_16_t); }
! static INLINE void       pkt_get_s32(const olsr_u8_t **p, olsr_32_t *var)          { *var = ntohl(*(const olsr_32_t *)(*p));  *p += sizeof(olsr_32_t); }
! static INLINE void    pkt_get_double(const olsr_u8_t **p, double *var)             { *var = me_to_double(**p);                *p += sizeof(olsr_u8_t); }
! static INLINE void pkt_get_ipaddress(const olsr_u8_t **p, union olsr_ip_addr *var) { memcpy(var, *p, olsr_cnf->ipsize);       *p += olsr_cnf->ipsize; }
! static INLINE void        pkt_get_lq(const olsr_u8_t **p, double *var)             { *var = (const double)**p / 255.0;        *p += sizeof(olsr_u8_t); }
  
  static INLINE void        pkt_ignore_u8(const olsr_u8_t **p) { *p += sizeof(olsr_u8_t); }
--- 143,156 ----
  };
  
! static INLINE void        pkt_get_u8(const olsr_u8_t **p, olsr_u8_t  *var)         { *var =       *(const olsr_u8_t *)(*p);          *p += sizeof(olsr_u8_t); }
! static INLINE void       pkt_get_u16(const olsr_u8_t **p, olsr_u16_t *var)         { *var = ntohs(*(const olsr_u16_t *)(*p));        *p += sizeof(olsr_u16_t); }
! static INLINE void       pkt_get_u32(const olsr_u8_t **p, olsr_u32_t *var)         { *var = ntohl(*(const olsr_u32_t *)(p));         *p += sizeof(olsr_u32_t); }
! static INLINE void        pkt_get_s8(const olsr_u8_t **p, olsr_8_t  *var)          { *var =       *(const olsr_8_t *)(*p);           *p += sizeof(olsr_8_t); }
! static INLINE void       pkt_get_s16(const olsr_u8_t **p, olsr_16_t *var)          { *var = ntohs(*(const olsr_16_t *)(*p));         *p += sizeof(olsr_16_t); }
! static INLINE void       pkt_get_s32(const olsr_u8_t **p, olsr_32_t *var)          { *var = ntohl(*(const olsr_32_t *)(*p));         *p += sizeof(olsr_32_t); }
! static INLINE void    pkt_get_double(const olsr_u8_t **p, double *var)             { *var = me_to_double(**p);                       *p += sizeof(olsr_u8_t); }
! static INLINE void pkt_get_ipaddress(const olsr_u8_t **p, union olsr_ip_addr *var) { memcpy(var, *p, olsr_cnf->ipsize);              *p += olsr_cnf->ipsize; }
! static INLINE void pkt_get_prefixlen(const olsr_u8_t **p, olsr_u8_t *var)          { *var = netmask_to_prefix(*p, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
! static INLINE void        pkt_get_lq(const olsr_u8_t **p, double *var)             { *var = (const double)**p / 255.0;               *p += sizeof(olsr_u8_t); }
  
  static INLINE void        pkt_ignore_u8(const olsr_u8_t **p) { *p += sizeof(olsr_u8_t); }
***************
*** 159,172 ****
  static INLINE void       pkt_ignore_s32(const olsr_u8_t **p) { *p += sizeof(olsr_32_t); }
  static INLINE void pkt_ignore_ipaddress(const olsr_u8_t **p) { *p += olsr_cnf->ipsize; }
  
! static INLINE void        pkt_put_u8(olsr_u8_t **p, const olsr_u8_t  var)         { *(olsr_u8_t *)(*p)  = var;        *p += sizeof(olsr_u8_t); }
! static INLINE void       pkt_put_u16(olsr_u8_t **p, const olsr_u16_t var)         { *(olsr_u16_t *)(*p) = htons(var); *p += sizeof(olsr_u16_t); }
! static INLINE void       pkt_put_u32(olsr_u8_t **p, const olsr_u32_t var)         { *(olsr_u32_t *)(*p) = htonl(var); *p += sizeof(olsr_u32_t); }
! static INLINE void        pkt_put_s8(olsr_u8_t **p, const olsr_8_t  var)          { *(olsr_8_t *)(*p)   = var;        *p += sizeof(olsr_8_t); }
! static INLINE void       pkt_put_s16(olsr_u8_t **p, const olsr_16_t var)          { *(olsr_16_t *)(*p)  = htons(var); *p += sizeof(olsr_16_t); }
! static INLINE void       pkt_put_s32(olsr_u8_t **p, const olsr_32_t var)          { *(olsr_32_t *)(*p)  = htonl(var); *p += sizeof(olsr_32_t); }
! static INLINE void    pkt_put_double(olsr_u8_t **p, const double var)             { **p = double_to_me(var);          *p += sizeof(olsr_u8_t); }
! static INLINE void pkt_put_ipaddress(olsr_u8_t **p, const union olsr_ip_addr var) { memcpy(*p, &var, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
! static INLINE void        pkt_put_lq(olsr_u8_t **p, const double var)             { **p  = var * 255.0;               *p += sizeof(olsr_u8_t); }
  
  void olsr_output_lq_hello(void *para);
--- 161,176 ----
  static INLINE void       pkt_ignore_s32(const olsr_u8_t **p) { *p += sizeof(olsr_32_t); }
  static INLINE void pkt_ignore_ipaddress(const olsr_u8_t **p) { *p += olsr_cnf->ipsize; }
+ static INLINE void pkt_ignore_prefixlen(const olsr_u8_t **p) { *p += olsr_cnf->ipsize; }
  
! static INLINE void        pkt_put_u8(olsr_u8_t **p, olsr_u8_t  var)                { *(olsr_u8_t *)(*p)  = var;          *p += sizeof(olsr_u8_t); }
! static INLINE void       pkt_put_u16(olsr_u8_t **p, olsr_u16_t var)                { *(olsr_u16_t *)(*p) = htons(var);   *p += sizeof(olsr_u16_t); }
! static INLINE void       pkt_put_u32(olsr_u8_t **p, olsr_u32_t var)                { *(olsr_u32_t *)(*p) = htonl(var);   *p += sizeof(olsr_u32_t); }
! static INLINE void        pkt_put_s8(olsr_u8_t **p, olsr_8_t  var)                 { *(olsr_8_t *)(*p)   = var;          *p += sizeof(olsr_8_t); }
! static INLINE void       pkt_put_s16(olsr_u8_t **p, olsr_16_t var)                 { *(olsr_16_t *)(*p)  = htons(var);   *p += sizeof(olsr_16_t); }
! static INLINE void       pkt_put_s32(olsr_u8_t **p, olsr_32_t var)                 { *(olsr_32_t *)(*p)  = htonl(var);   *p += sizeof(olsr_32_t); }
! static INLINE void    pkt_put_double(olsr_u8_t **p, double var)                    { **p = double_to_me(var);            *p += sizeof(olsr_u8_t); }
! static INLINE void pkt_put_ipaddress(olsr_u8_t **p, const union olsr_ip_addr *var) { memcpy(*p, var, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
! static INLINE void pkt_put_prefixlen(olsr_u8_t **p, olsr_u8_t var)                 { prefix_to_netmask(*p, olsr_cnf->ipsize, var); *p += olsr_cnf->ipsize; }
! static INLINE void        pkt_put_lq(olsr_u8_t **p, double var)                    { **p  = var * 255.0;                 *p += sizeof(olsr_u8_t); }
  
  void olsr_output_lq_hello(void *para);

Index: packet.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/packet.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** packet.h	29 Nov 2007 00:49:39 -0000	1.19
--- packet.h	29 Nov 2007 23:03:07 -0000	1.20
***************
*** 91,121 ****
  
  /*
-  *HNA message format:
-  *NET
-  *NETMASK
-  *NET
-  *NETMASK
-  *......
-  */
- 
- struct hna_net_addr
- {
-   union olsr_ip_addr  net;
-   olsr_u8_t           prefixlen;
-   struct hna_net_addr *next;
- };
- 
- 
- struct hna_message
- {
-   double               vtime;
-   union olsr_ip_addr   originator;
-   olsr_u16_t           packet_seq_number;
-   olsr_u8_t            hop_count;
-   struct hna_net_addr *hna_net;
- };
- 
- 
- /*
   *MID messages - format:
   *
--- 91,94 ----
***************
*** 167,172 ****
  olsr_free_mid_packet(struct mid_message *);
  
- void
- olsr_free_hna_packet(struct hna_message *);
- 
  #endif
--- 140,142 ----

Index: rebuild_packet.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/rebuild_packet.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** rebuild_packet.c	29 Nov 2007 18:10:17 -0000	1.27
--- rebuild_packet.c	29 Nov 2007 23:03:07 -0000	1.28
***************
*** 40,44 ****
   */
  
- 
  #include "rebuild_packet.h"
  #include "ipcalc.h"
--- 40,43 ----
***************
*** 50,165 ****
  
  /**
-  *Process/rebuild HNA message. Converts the OLSR
-  *packet to the internal hna_message format.
-  *@param hmsg the hna_message struct in wich infomation
-  *is to be put.
-  *@param m the entire OLSR message revieved.
-  *@return negative on error
-  */
- 
- void
- hna_chgestruct(struct hna_message *hmsg, const union olsr_message *m)
- {
-   struct hna_net_addr *hna_pairs, *tmp_pairs;
-   int no_pairs, i;
- 
-   /*Check if everyting is ok*/
-   if ((!m) || (m->v4.olsr_msgtype != HNA_MESSAGE))
-     return;
-   
- 
-   if(olsr_cnf->ip_version == AF_INET)
-     {
-       /* IPv4 */
-       const struct hnapair *haddr = m->v4.message.hna.hna_net;
- 
-       /*
-        * How many HNA pairs?
-        * nextmsg contains size of
-        * the addresses + 12 bytes(nextmessage, from address and the header)
-        */
-       no_pairs = (ntohs(m->v4.olsr_msgsize) - 12) / 8;
-       
-       hmsg->originator.v4.s_addr = m->v4.originator;
- 
-       hmsg->packet_seq_number = ntohs(m->v4.seqno);
-       hmsg->hop_count =  m->v4.hopcnt;
- 
-       //printf("HNA from %s\n\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&hmsg->originator));
- 
-       /* Get vtime */
-       hmsg->vtime = me_to_double(m->v4.olsr_vtime);
- 
-       tmp_pairs = NULL;
-       hna_pairs = NULL;
- 
-       for(i = 0; i < no_pairs; i++) {	  
- 	  hna_pairs = olsr_malloc(sizeof(struct hna_net_addr), "HNA chgestruct");
- 	  
-           hna_pairs->net.v4.s_addr = haddr->addr;
-           hna_pairs->prefixlen = olsr_netmask4_to_prefix(&haddr->netmask);
- 
- 	  hna_pairs->next = tmp_pairs;	  
- 	  tmp_pairs = hna_pairs;
- 	  haddr++;
- 	}
-     }
-   else
-     {
-       /* IPv6 */
-       const struct hnapair6 *haddr6 = m->v6.message.hna.hna_net;
- 
-       /*
-        * How many HNA pairs?
-        * nextmsg contains size of
-        * the addresses + 12 bytes(nextmessage, from address and the header)
-        */
-       no_pairs = (ntohs(m->v6.olsr_msgsize) - 24) / 32; /* NB 32 not 8 */
-       
-       hmsg->originator.v6 = m->v6.originator;
-       hmsg->packet_seq_number = ntohs(m->v6.seqno);
-       hmsg->hop_count =  m->v6.hopcnt;
-       
-       /* Get vtime */
-       hmsg->vtime = me_to_double(m->v6.olsr_vtime);
-       
-       tmp_pairs = NULL;
-       hna_pairs = NULL;
-       
-       for(i = 0; i < no_pairs; i++)
- 	{
- 	  
- 	  hna_pairs = olsr_malloc(sizeof(struct hna_net_addr), "HNA chgestruct 2");	  
- 	  
- 	  hna_pairs->net.v6 = haddr6->addr;
-           hna_pairs->prefixlen = olsr_netmask6_to_prefix(&haddr6->netmask);
- 
- 	  hna_pairs->next = tmp_pairs;
- 	  
- 	  tmp_pairs = hna_pairs;
- 	  haddr6++;	  
- 	}
-     }      
- 
-   /* 
-      tmp_pairs = hna_pairs;
- 	 
-      while(tmp_pairs)
-      {
-      printf("\t net: %s ", ip_to_string(&tmp_pairs->net));
-      printf("\t mask: %s\n", ip_to_string(&tmp_pairs->netmask));
-      tmp_pairs = tmp_pairs->next;
-      }
-      printf("\n");
-   */
- 
- 
- 
-   hmsg->hna_net = hna_pairs;
-  
- }
- 
- 
- /**
   *Process/rebuild MID message. Converts the OLSR
   *packet to the internal mid_message format.
--- 49,52 ----

Index: process_package.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/process_package.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** process_package.c	29 Nov 2007 18:10:17 -0000	1.48
--- process_package.c	29 Nov 2007 23:03:07 -0000	1.49
***************
*** 56,59 ****
--- 56,60 ----
  #include "net_olsr.h"
  
+ #include <stddef.h>
  
  static void process_message_neighbors(struct neighbor_entry *, const struct hello_message *);
***************
*** 672,677 ****
                            union olsr_ip_addr *from_addr)
  {
!   struct hna_net_addr  *hna_tmp;
!   struct  hna_message message;
  
  #ifdef DEBUG
--- 673,687 ----
                            union olsr_ip_addr *from_addr)
  {
! 
!   olsr_u8_t          olsr_msgtype;
!   double             vtime;
!   olsr_u16_t         olsr_msgsize;
!   union olsr_ip_addr originator;
!   //olsr_u8_t          ttl; unused
!   olsr_u8_t          hop_count;
!   olsr_u16_t         packet_seq_number;
! 
!   int                hnasize;
!   const olsr_u8_t    *curr, *curr_end;
  
  #ifdef DEBUG
***************
*** 679,694 ****
  #endif
  
!   hna_chgestruct(&message, m);
  
!   if(!olsr_validate_address(&message.originator)) {
!     olsr_free_hna_packet(&message);
      return;
    }
  
!   if (olsr_check_dup_table_proc(&message.originator, 
!                                 message.packet_seq_number)) {
  
!     hna_tmp = message.hna_net;
  
      /*
       *      If the sender interface (NB: not originator) of this message
--- 689,738 ----
  #endif
  
!   /* Check if everyting is ok */
!   if (!m) {
!     return;
!   }
!   curr = (const olsr_u8_t *)m;
  
!   /* olsr_msgtype */
!   pkt_get_u8(&curr, &olsr_msgtype);
!   if (olsr_msgtype != HNA_MESSAGE) {
!     OLSR_PRINTF(0, "not a HNA message!\n");
      return;
    }
+   /* Get vtime */
+   pkt_get_double(&curr, &vtime);
  
!   /* olsr_msgsize */
!   pkt_get_u16(&curr, &olsr_msgsize);
!   hnasize = olsr_msgsize - (olsr_cnf->ip_version == AF_INET ? offsetof(struct olsrmsg, message) : offsetof(struct olsrmsg6, message));
!   if (hnasize < 0) {
!     OLSR_PRINTF(0, "message size %d too small (at least %d)!\n", olsr_msgsize, (olsr_cnf->ip_version == AF_INET ? offsetof(struct olsrmsg, message) : offsetof(struct olsrmsg6, message)));
!     return;
!   }
!   if ((hnasize % (2 * olsr_cnf->ipsize)) != 0) {
!     OLSR_PRINTF(0, "Illegal message size %d!\n", olsr_msgsize);
!     return;
!   }
!   curr_end = (const olsr_u8_t *)m + olsr_msgsize;
  
!   /* validate originator */
!   pkt_get_ipaddress(&curr, &originator);
!   //printf("HNA from %s\n\n", olsr_ip_to_string(&buf, &originator));
!   if (!olsr_validate_address(&originator)) {
!     OLSR_PRINTF(0, "invalid address!\n");
!     return;
!   }
! 
!   /* ttl */
!   pkt_ignore_u8(&curr);
! 
!   /* hopcnt */
!   pkt_get_u8(&curr, &hop_count);
! 
!   /* seqno */
!   pkt_get_u16(&curr, &packet_seq_number);
  
+   if (olsr_check_dup_table_proc(&originator, packet_seq_number)) {
      /*
       *      If the sender interface (NB: not originator) of this message
***************
*** 696,723 ****
       *      message MUST be discarded.
       */
!     if(check_neighbor_link(from_addr) != SYM_LINK) {
  #ifndef NODEBUG
        struct ipaddr_str buf;
  #endif
        OLSR_PRINTF(2, "Received HNA from NON SYM neighbor %s\n", olsr_ip_to_string(&buf, from_addr));
-       olsr_free_hna_packet(&message);
        return;
      }
  
      while (hna_tmp) {
        /* Don't add an HNA entry that we are advertising ourselves. */
        if (!ip_prefix_list_find(olsr_cnf->hna_entries, &hna_tmp->net, hna_tmp->prefixlen)) {
          olsr_update_hna_entry(&message.originator, &hna_tmp->net, hna_tmp->prefixlen, message.vtime);
        }
- 
-       hna_tmp = hna_tmp->next;
      }
    }
- 
    olsr_forward_message(m, 
! 		       &message.originator, 
! 		       message.packet_seq_number, 
! 		       in_if,
! 		       from_addr);
!   olsr_free_hna_packet(&message);
  }
--- 740,775 ----
       *      message MUST be discarded.
       */
!     if (check_neighbor_link(from_addr) != SYM_LINK) {
  #ifndef NODEBUG
        struct ipaddr_str buf;
  #endif
        OLSR_PRINTF(2, "Received HNA from NON SYM neighbor %s\n", olsr_ip_to_string(&buf, from_addr));
        return;
      }
+ #if 1
+     while (curr < curr_end) {
+       union olsr_ip_addr net;
+       olsr_u8_t prefixlen;
+       struct ip_prefix_list *entry;
  
+       pkt_get_ipaddress(&curr, &net);
+       pkt_get_prefixlen(&curr, &prefixlen);
+       entry = ip_prefix_list_find(olsr_cnf->hna_entries, &net, prefixlen);
+       if (entry == NULL) {
+         /* only update if it's not from us */
+         olsr_update_hna_entry(&originator, &net, prefixlen, vtime);
+ #else
      while (hna_tmp) {
        /* Don't add an HNA entry that we are advertising ourselves. */
        if (!ip_prefix_list_find(olsr_cnf->hna_entries, &hna_tmp->net, hna_tmp->prefixlen)) {
          olsr_update_hna_entry(&message.originator, &hna_tmp->net, hna_tmp->prefixlen, message.vtime);
+ #endif
        }
      }
    }
    olsr_forward_message(m, 
!                        &originator, 
!                        packet_seq_number, 
!                        in_if,
!                        from_addr);
  }

Index: rebuild_packet.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/rebuild_packet.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** rebuild_packet.h	16 Nov 2007 21:43:55 -0000	1.10
--- rebuild_packet.h	29 Nov 2007 23:03:07 -0000	1.11
***************
*** 50,56 ****
  
  void
- hna_chgestruct(struct hna_message *, const union olsr_message *);
- 
- void
  mid_chgestruct(struct mid_message *, const union olsr_message *);
  
--- 50,53 ----

Index: packet.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/packet.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** packet.c	29 Nov 2007 18:10:16 -0000	1.28
--- packet.c	29 Nov 2007 23:03:07 -0000	1.29
***************
*** 439,468 ****
  }
  
- 
- /**
-  *Free the memory allocated for a HNA packet.
-  *
-  *@param message the pointer to the packet to erase
-  *
-  *@return nada
-  */
- 
- void
- olsr_free_hna_packet(struct hna_message *message)
- {
-   struct hna_net_addr  *hna_tmp, *hna_tmp2;
- 
-   hna_tmp = message->hna_net;
- 
-   while(hna_tmp)
-     {
-       hna_tmp2 = hna_tmp;
-       hna_tmp = hna_tmp->next;
-       free(hna_tmp2);
-     }
- }
- 
- 
- 
  /**
   *Free the memory allocated for a MID packet.
--- 439,442 ----





More information about the Olsr-cvs mailing list