From Henning Rogge <rogge@fgan.de>: join LQ and non-LQ Hello execution paths
authorHannes Gredler <hannes@gredler.at>
Mon, 14 Jan 2008 15:53:50 +0000 (16:53 +0100)
committerHannes Gredler <hannes@gredler.at>
Mon, 14 Jan 2008 15:53:50 +0000 (16:53 +0100)
src/lq_packet.c
src/process_package.c
src/process_package.h
src/rebuild_packet.c

index 97a490d..1523b6f 100644 (file)
@@ -576,59 +576,6 @@ serialize_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
   net_outbuffer_push(outif, msg_buffer, size + off);
 }
 
-
-static int
-deserialize_lq_hello(struct hello_message *hello,
-                     const void *ser)
-{
-    const unsigned char *limit;
-    olsr_u8_t type;
-    olsr_u16_t size;
-  
-    const unsigned char *curr = ser;
-    pkt_get_u8(&curr, &type);
-    if (type != LQ_HELLO_MESSAGE) {
-        /* No need to do anything more */
-        return 1;
-    }
-    pkt_get_double(&curr, &hello->vtime);
-    pkt_get_u16(&curr, &size);
-    pkt_get_ipaddress(&curr, &hello->source_addr);
-
-    pkt_get_u8(&curr, &hello->ttl);
-    pkt_get_u8(&curr, &hello->hop_count);
-    pkt_get_u16(&curr, &hello->packet_seq_number);
-    pkt_ignore_u16(&curr);
-
-    pkt_get_double(&curr, &hello->htime);
-    pkt_get_u8(&curr, &hello->willingness);
-
-    hello->neighbors = NULL;
-    limit = ((const unsigned char *)ser) + size;
-    while (curr < limit) {
-        const struct lq_hello_info_header *info_head = (const struct lq_hello_info_header *)curr;
-        const unsigned char *limit2 = curr + ntohs(info_head->size);
-
-        curr = (const unsigned char *)(info_head + 1);      
-        while (curr < limit2) {
-            struct hello_neighbor *neigh = olsr_malloc(sizeof (struct hello_neighbor),
-                                                       "LQ_HELLO deserialization");
-            pkt_get_ipaddress(&curr, &neigh->address);
-
-            pkt_get_lq(&curr, &neigh->link_quality);
-            pkt_get_lq(&curr, &neigh->neigh_link_quality);
-            pkt_ignore_u16(&curr);
-
-            neigh->link   = EXTRACT_LINK(info_head->link_code);
-            neigh->status = EXTRACT_STATUS(info_head->link_code);
-
-            neigh->next = hello->neighbors;
-            hello->neighbors = neigh;
-        }
-    }
-    return 0;
-}
-
 void
 olsr_output_lq_hello(void *para)
 {
@@ -699,19 +646,3 @@ olsr_output_lq_tc(void *para)
     set_buffer_timer(outif);
   }
 }
-
-void
-olsr_input_lq_hello(union olsr_message *ser,
-                    struct interface *inif,
-                    union olsr_ip_addr *from)
-{
-  struct hello_message hello;
-
-  if (ser == NULL) {
-    return;
-  }
-  if (deserialize_lq_hello(&hello, ser) != 0) {
-    return;
-  }
-  olsr_hello_tap(&hello, inif, from);
-}
index 06c4b58..7b14c8a 100644 (file)
@@ -414,6 +414,66 @@ lookup_mpr_status(const struct hello_message *message, const struct interface *i
   return 0;
 }
 
+static int deserialize_hello(struct hello_message *hello, const void *ser) {
+       const unsigned char *limit;
+       olsr_u8_t type;
+       olsr_u16_t size;
+       
+       const unsigned char *curr = ser;
+       pkt_get_u8(&curr, &type);
+       if (type != HELLO_MESSAGE && type != LQ_HELLO_MESSAGE) {
+               /* No need to do anything more */
+               return 1;
+       }
+       pkt_get_double(&curr, &hello->vtime);
+       pkt_get_u16(&curr, &size);
+       pkt_get_ipaddress(&curr, &hello->source_addr);
+       
+       pkt_get_u8(&curr, &hello->ttl);
+       pkt_get_u8(&curr, &hello->hop_count);
+       pkt_get_u16(&curr, &hello->packet_seq_number);
+       pkt_ignore_u16(&curr);
+       
+       pkt_get_double(&curr, &hello->htime);
+       pkt_get_u8(&curr, &hello->willingness);
+       
+       hello->neighbors = NULL;
+       limit = ((const unsigned char *)ser) + size;
+       while (curr < limit) {
+               const struct lq_hello_info_header *info_head = (const struct lq_hello_info_header *)curr;
+               const unsigned char *limit2 = curr + ntohs(info_head->size);
+               
+               curr = (const unsigned char *)(info_head + 1);
+               while (curr < limit2) {
+                       struct hello_neighbor *neigh = olsr_malloc(sizeof(struct hello_neighbor), "HELLO deserialization");
+                       pkt_get_ipaddress(&curr, &neigh->address);
+                       
+                       if (type == LQ_HELLO_MESSAGE) {
+                               pkt_get_lq(&curr, &neigh->link_quality);
+                               pkt_get_lq(&curr, &neigh->neigh_link_quality);
+                               pkt_ignore_u16(&curr);
+                       }
+                       neigh->link = EXTRACT_LINK(info_head->link_code);
+                       neigh->status = EXTRACT_STATUS(info_head->link_code);
+                       
+                       neigh->next = hello->neighbors;
+                       hello->neighbors = neigh;
+               }
+       }
+       return 0;
+}
+
+void olsr_input_hello(union olsr_message *ser, struct interface *inif, union olsr_ip_addr *from) {
+       struct hello_message hello;
+       
+       if (ser == NULL) {
+               return;
+       }
+       if (deserialize_hello(&hello, ser) != 0) {
+               return;
+       }
+       olsr_hello_tap(&hello, inif, from);
+}
 
 /**
  *Initializing the parser functions we are using
@@ -423,12 +483,12 @@ olsr_init_package_process(void)
 {
   if (olsr_cnf->lq_level == 0)
     {
-      olsr_parser_add_function(&olsr_process_received_hello, HELLO_MESSAGE, 1);
+      olsr_parser_add_function(&olsr_input_hello, HELLO_MESSAGE, 1);
       olsr_parser_add_function(&olsr_input_tc, TC_MESSAGE, 1);
     }
   else
     {
-      olsr_parser_add_function(&olsr_input_lq_hello, LQ_HELLO_MESSAGE, 1);
+      olsr_parser_add_function(&olsr_input_hello, LQ_HELLO_MESSAGE, 1);
       olsr_parser_add_function(&olsr_input_tc, LQ_TC_MESSAGE, 1);
     }
 
@@ -555,25 +615,6 @@ olsr_hello_tap(struct hello_message *message,
   return;
 }
 
-/**
- *Processes a received HELLO message. 
- *
- *@param m the incoming OLSR message
- *@return 0 on sucess
- */
-
-void
-olsr_process_received_hello(union olsr_message *m,
-                            struct interface *in_if,
-                            union olsr_ip_addr *from_addr)
-{
-  struct hello_message      message;
-
-  hello_chgestruct(&message, m);
-
-  olsr_hello_tap(&message, in_if, from_addr);
-}
-
 /**
  *Process a received(and parsed) MID message
  *For every address check if there is a topology node
index 755e2e6..83a6898 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
+ * Copyright (c) 2004, Andreas Tnnesen(andreto@olsr.org)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without 
@@ -46,6 +46,9 @@
 #include "packet.h"
 #include "neighbor_table.h"
 
+void
+olsr_input_hello(union olsr_message *ser, struct interface *inif, union olsr_ip_addr *from);
+
 void
 olsr_init_package_process(void);
 
index aea4b76..a3498b3 100644 (file)
@@ -218,116 +218,3 @@ unk_chgestruct(struct unknown_message *umsg, const union olsr_message *m)
     }
   
 }
-
-
-
-/**
- *Process/rebuild HELLO message. Converts the OLSR
- *packet to the internal hello_message format.
- *@param hmsg the hello_message struct in wich infomation
- *is to be put.
- *@param m the entire OLSR message revieved.
- *@return negative on error
- */
-
-void
-hello_chgestruct(struct hello_message *hmsg, const union olsr_message *m)
-{
-  const union olsr_ip_addr *hadr;
-  struct hello_neighbor *nb;
-  
-  hmsg->neighbors = NULL;
-
-  if ((!m) || (m->v4.olsr_msgtype != HELLO_MESSAGE))
-    return;
-
-  if(olsr_cnf->ip_version == AF_INET)
-    {
-      const struct hellinfo *hinf;
-
-      /* IPv4 */
-      hmsg->source_addr.v4.s_addr = m->v4.originator;
-      hmsg->packet_seq_number = ntohs(m->v4.seqno);
-
-
-      /* Get vtime */
-      hmsg->vtime = me_to_double(m->v4.olsr_vtime);
-
-      /* Get htime */
-      hmsg->htime = me_to_double(m->v4.message.hello.htime);
-
-      /* Willingness */
-      hmsg->willingness = m->v4.message.hello.willingness;
-
-      OLSR_PRINTF(3, "Got HELLO vtime: %f htime: %f\n", hmsg->vtime, hmsg->htime);
-
-      for (hinf = m->v4.message.hello.hell_info; 
-          (const char *)hinf < ((const char *)m + (ntohs(m->v4.olsr_msgsize))); 
-          hinf = (const struct hellinfo *)((const char *)hinf + ntohs(hinf->size)))
-       {
-         
-         for (hadr = (const union olsr_ip_addr  *)&hinf->neigh_addr; 
-              (const char *)hadr < (const char *)hinf + ntohs(hinf->size); 
-              hadr = (const union olsr_ip_addr *)&hadr->v6.s6_addr[4])
-           {
-             nb = olsr_malloc(sizeof (struct hello_neighbor), "HELLO chgestruct");
-
-             nb->address = *hadr;
-
-             /* Fetch link and status */
-             nb->link = EXTRACT_LINK(hinf->link_code);
-             nb->status = EXTRACT_STATUS(hinf->link_code);
-
-             nb->next = hmsg->neighbors;
-             hmsg->neighbors = nb;
-           }
-       }
-
-      
-    }
-  else
-    {
-      const struct hellinfo6 *hinf6;
-
-      /* IPv6 */
-      hmsg->source_addr.v6 = m->v6.originator;
-      //printf("parsing HELLO from %s\n", olsr_ip_to_string(&buf, &hmsg->source_addr));
-      hmsg->packet_seq_number = ntohs(m->v6.seqno);
-
-      /* Get vtime */
-      hmsg->vtime = me_to_double(m->v6.olsr_vtime);
-
-      /* Get htime */
-      hmsg->htime = me_to_double(m->v6.message.hello.htime);
-
-      /* Willingness */
-      hmsg->willingness = m->v6.message.hello.willingness;
-
-      OLSR_PRINTF(3, "Got HELLO vtime: %f htime: %f\n", hmsg->vtime, hmsg->htime);
-
-
-      for (hinf6 = m->v6.message.hello.hell_info; 
-          (const char *)hinf6 < ((const char *)m + (ntohs(m->v6.olsr_msgsize))); 
-          hinf6 = (const struct hellinfo6 *)((const char *)hinf6 + ntohs(hinf6->size)))
-       {
-
-         for (hadr = (const union olsr_ip_addr *)hinf6->neigh_addr; 
-              (const char *)hadr < (const char *)hinf6 + ntohs(hinf6->size); 
-              hadr++)
-           {
-             nb = olsr_malloc(sizeof (struct hello_neighbor), "OLSR chgestruct 2");
-
-             nb->address = *hadr;
-
-             /* Fetch link and status */
-             nb->link = EXTRACT_LINK(hinf6->link_code);
-             nb->status = EXTRACT_STATUS(hinf6->link_code);
-
-             nb->next = hmsg->neighbors;
-             hmsg->neighbors = nb;
-           }
-       }
-
-    }
-
-}