[Olsr-cvs] olsrd-current/lib/secure/src olsrd_secure.c, 1.28, 1.29 secure_messages.h, 1.3, 1.4

Bernd Petrovitsch (spam-protected)
Thu Nov 8 23:47:42 CET 2007


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

Modified Files:
	olsrd_secure.c secure_messages.h 
Log Message:
Another fat commit:

The main target was:
- Fixed the misleading definition of "v4" in "struct olsr_ip_addr" fom
  "olsr_u32_t" (in network-byteorder!) to "struct in_addr". Lots of
  temporary variables to call inet_ntoa()/inet_ptoa() vanished .....
- declare "int_addr", "int_netmask" and "int_broadaddr" in "struct interface"
  as "struct sockaddr_in" since it is that what we actually want there (and
  it is similar to the IPv6 code).

To get that thoroughly via compiler errors, we get:
- We have now ip4_to_string(), ip6_to_string() and olsr_ip_to_string()
  to print a "struct in_addr", "struct in6_addr" and "union olsr_ip_addr"
  into a string buffer.

Alas, this also annoyed me since ages:
- cleanup: olsr_ip_to_string() and similar non-reentrant functions now must
  get a target buffer. To ease that, there is the "struct ipaddr_str"
  which is large enough for all of them (read: for an IPv6 address). This
  also removes the cyclic buffer there.
  All of these function return a "const char *" which can be directly used
  for printf(3) and friends.

And some cleanups:
- const'ified more functions
- converted the source to UTF-8.
- "struct sig_msg" uses an olsr_u8_t for a byte array (and not "char")
- force the few inline function to always be inlined.
- #ifdef the body of the olsr_print_hna_set() and olsr_print_neighbor_table()
  if nothing is done
- use "inline_avl_comp_ipv4()" in "avl_comp_ipv4()"
- clean up the routes on more signals. Basically we want to do this on all
  signals which terminate the program.
- killed a superflous global buffer in src/main.c

This version was breing since weeks and running for severa day in Vienna's
FunkFeuer net without any noticably problem!

Please report anything that broke!



Index: secure_messages.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/secure/src/secure_messages.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** secure_messages.h	15 Jul 2007 21:47:17 -0000	1.3
--- secure_messages.h	8 Nov 2007 22:47:40 -0000	1.4
***************
*** 89,93 ****
  
    time_t        timestamp;
!   char          signature[SIGSIZE];
  };
  
--- 89,93 ----
  
    time_t        timestamp;
!   olsr_u8_t     signature[SIGSIZE];
  };
  

Index: olsrd_secure.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/secure/src/olsrd_secure.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** olsrd_secure.c	20 Oct 2007 15:16:32 -0000	1.28
--- olsrd_secure.c	8 Nov 2007 22:47:40 -0000	1.29
***************
*** 59,62 ****
--- 59,63 ----
  #include "parser.h"
  #include "scheduler.h"
+ #include "net_olsr.h"
  
  #ifdef USE_OPENSSL
***************
*** 151,160 ****
  #endif
  static int add_signature(olsr_u8_t *, int*);
! static int validate_packet(char *, int*);
  static void packet_parser(int);
  static void timeout_timestamps(void*);
  static int check_timestamp(union olsr_ip_addr *, time_t);
  static struct stamp *lookup_timestamp_entry(union olsr_ip_addr *);
! static int read_key_from_file(char *);
  
  /**
--- 152,161 ----
  #endif
  static int add_signature(olsr_u8_t *, int*);
! static int validate_packet(const char *, int*);
  static void packet_parser(int);
  static void timeout_timestamps(void*);
  static int check_timestamp(union olsr_ip_addr *, time_t);
  static struct stamp *lookup_timestamp_entry(union olsr_ip_addr *);
! static int read_key_from_file(const char *);
  
  /**
***************
*** 308,311 ****
--- 309,313 ----
    for (;;) 
      {
+       struct ipaddr_str buf;
        fromlen = sizeof(struct sockaddr_storage);
  
***************
*** 351,356 ****
        if((olsr_in_if = if_ifwithsock(fd)) == NULL)
  	{
  	  olsr_printf(1, "[ENC]Could not find input interface for message from %s size %d\n",
! 		      olsr_ip_to_string(&from_addr),
  		      cc);
  	  return ;
--- 353,359 ----
        if((olsr_in_if = if_ifwithsock(fd)) == NULL)
  	{
+           struct ipaddr_str buf;
  	  olsr_printf(1, "[ENC]Could not find input interface for message from %s size %d\n",
! 		      olsr_ip_to_string(&buf, &from_addr),
  		      cc);
  	  return ;
***************
*** 368,377 ****
        if(!validate_packet(inbuf.buf, &cc))
  	{
! 	  olsr_printf(1, "[ENC]Rejecting packet from %s\n", olsr_ip_to_string((union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr));
  	  return;
  	}
  
  
!       olsr_printf(1, "[ENC]Packet from %s OK size %d\n", olsr_ip_to_string((union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr), cc);
  
  
--- 371,380 ----
        if(!validate_packet(inbuf.buf, &cc))
  	{
! 	  olsr_printf(1, "[ENC]Rejecting packet from %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr));
  	  return;
  	}
  
  
!       olsr_printf(1, "[ENC]Packet from %s OK size %d\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr), cc);
  
  
***************
*** 452,456 ****
    unsigned int i;
    int j;
!   char *sigmsg;                                                                                        
  #endif
    
--- 455,459 ----
    unsigned int i;
    int j;
!   const olsr_u8_t *sigmsg;                                                                                        
  #endif
    
***************
*** 481,485 ****
    
    /* Set the new size */
!   *size = *size + sizeof(struct s_olsrmsg);
    
    {
--- 484,488 ----
    
    /* Set the new size */
!   *size += sizeof(struct s_olsrmsg);
    
    {
***************
*** 499,507 ****
  
    j = 0;
!   sigmsg = (char *)msg;
  
    for(i = 0; i < sizeof(struct s_olsrmsg); i++)
      {
!       olsr_printf(1, "  %3i", (u_char) sigmsg[i]);
        j++;
        if(j == 4)
--- 502,510 ----
  
    j = 0;
!   sigmsg = (olsr_u8_t *)msg;
  
    for(i = 0; i < sizeof(struct s_olsrmsg); i++)
      {
!       olsr_printf(1, "  %3i", sigmsg[i]);
        j++;
        if(j == 4)
***************
*** 520,525 ****
  
  
! int
! validate_packet(char *pck, int *size)
  {
    int packetsize;
--- 523,528 ----
  
  
! static int
! validate_packet(const char *pck, int *size)
  {
    int packetsize;
***************
*** 531,535 ****
    unsigned int i;
    int j;
!   olsr_u8_t *sigmsg;
  #endif
  
--- 534,538 ----
    unsigned int i;
    int j;
!   const olsr_u8_t *sigmsg;
  #endif
  
***************
*** 548,556 ****
    
    j = 0;
!   sigmsg = (olsr_u8_t *)sig;
  
    for(i = 0; i < sizeof(struct s_olsrmsg); i++)
      {
!       olsr_printf(1, "  %3i", (u_char) sigmsg[i]);
        j++;
        if(j == 4)
--- 551,559 ----
    
    j = 0;
!   sigmsg = (const olsr_u8_t *)sig;
  
    for(i = 0; i < sizeof(struct s_olsrmsg); i++)
      {
!       olsr_printf(1, "  %3i", sigmsg[i]);
        j++;
        if(j == 4)
***************
*** 564,568 ****
    /* Sanity check first */
    if((sig->olsr_msgtype != MESSAGE_TYPE) || 
!      (sig->olsr_vtime) ||
       (sig->olsr_msgsize != ntohs(sizeof(struct s_olsrmsg))) ||
       (sig->ttl != 1) ||
--- 567,571 ----
    /* Sanity check first */
    if((sig->olsr_msgtype != MESSAGE_TYPE) || 
!      (sig->olsr_vtime != 0) ||
       (sig->olsr_msgsize != ntohs(sizeof(struct s_olsrmsg))) ||
       (sig->ttl != 1) ||
***************
*** 589,594 ****
        olsr_printf(1, "[ENC]Unsupported sceme: %d enc: %d!\n", sig->sig.type, sig->sig.algorithm);
        return 0;
-       break;
- 
      }
    //olsr_printf(1, "Packet sane...\n");
--- 592,595 ----
***************
*** 611,619 ****
    olsr_printf(1, "Recevied hash:\n");
    
!   sigmsg = (olsr_u8_t *)sig->sig.signature;
  
    for(i = 0; i < SIGNATURE_SIZE; i++)
      {
!       olsr_printf(1, " %3i", (u_char) sigmsg[i]);
      }
    olsr_printf(1, "\n");
--- 612,620 ----
    olsr_printf(1, "Recevied hash:\n");
    
!   sigmsg = (const olsr_u8_t *)sig->sig.signature;
  
    for(i = 0; i < SIGNATURE_SIZE; i++)
      {
!       olsr_printf(1, " %3i", sigmsg[i]);
      }
    olsr_printf(1, "\n");
***************
*** 625,629 ****
    for(i = 0; i < SIGNATURE_SIZE; i++)
      {
!       olsr_printf(1, " %3i", (u_char) sigmsg[i]);
      }
    olsr_printf(1, "\n");
--- 626,630 ----
    for(i = 0; i < SIGNATURE_SIZE; i++)
      {
!       olsr_printf(1, " %3i", sigmsg[i]);
      }
    olsr_printf(1, "\n");
***************
*** 641,646 ****
    if(!check_timestamp((union olsr_ip_addr *)&sig->originator, rec_time))
      {
        olsr_printf(1, "[ENC]Timestamp missmatch in packet from %s!\n",
! 		  olsr_ip_to_string((union olsr_ip_addr *)&sig->originator));
        return 0;
      }
--- 642,648 ----
    if(!check_timestamp((union olsr_ip_addr *)&sig->originator, rec_time))
      {
+       struct ipaddr_str buf;
        olsr_printf(1, "[ENC]Timestamp missmatch in packet from %s!\n",
! 		  olsr_ip_to_string(&buf, (union olsr_ip_addr *)&sig->originator));
        return 0;
      }
***************
*** 715,718 ****
--- 717,721 ----
    struct stamp *entry;
    olsr_u32_t challenge, hash;
+   struct ipaddr_str buf;
  
    olsr_printf(1, "[ENC]Building CHALLENGE message\n");
***************
*** 753,757 ****
    }
    olsr_printf(3, "[ENC]Sending timestamp request to %s challenge 0x%x\n", 
! 	      olsr_ip_to_string(new_host),
  	      challenge);
  
--- 756,760 ----
    }
    olsr_printf(3, "[ENC]Sending timestamp request to %s challenge 0x%x\n", 
! 	      olsr_ip_to_string(&buf, new_host),
  	      challenge);
  
***************
*** 793,801 ****
    olsr_u8_t sha1_hash[SIGNATURE_SIZE];
    struct stamp *entry;
  
    msg = (struct c_respmsg *)in_msg;
  
    olsr_printf(1, "[ENC]Challenge-response message received\n");
!   olsr_printf(3, "[ENC]To: %s\n", olsr_ip_to_string((union olsr_ip_addr *)&msg->destination));
  
    if(if_ifwithaddr((union olsr_ip_addr *)&msg->destination) == NULL)
--- 796,805 ----
    olsr_u8_t sha1_hash[SIGNATURE_SIZE];
    struct stamp *entry;
+   struct ipaddr_str buf;
  
    msg = (struct c_respmsg *)in_msg;
  
    olsr_printf(1, "[ENC]Challenge-response message received\n");
!   olsr_printf(3, "[ENC]To: %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->destination));
  
    if(if_ifwithaddr((union olsr_ip_addr *)&msg->destination) == NULL)
***************
*** 835,840 ****
    if((entry = lookup_timestamp_entry((union olsr_ip_addr *)&msg->originator)) == NULL)
      {
        olsr_printf(1, "[ENC]Received challenge-response from non-registered node %s!\n",
! 		  olsr_ip_to_string((union olsr_ip_addr *)&msg->originator));
        return 0;
      }
--- 839,845 ----
    if((entry = lookup_timestamp_entry((union olsr_ip_addr *)&msg->originator)) == NULL)
      {
+       struct ipaddr_str buf;
        olsr_printf(1, "[ENC]Received challenge-response from non-registered node %s!\n",
! 		  olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->originator));
        return 0;
      }
***************
*** 858,863 ****
    if(memcmp(msg->res_sig, sha1_hash, SIGNATURE_SIZE) != 0)
      {
        olsr_printf(1, "[ENC]Error in challenge signature from %s!\n",
! 		  olsr_ip_to_string((union olsr_ip_addr *)&msg->originator));
        
        return 0;
--- 863,869 ----
    if(memcmp(msg->res_sig, sha1_hash, SIGNATURE_SIZE) != 0)
      {
+       struct ipaddr_str buf;
        olsr_printf(1, "[ENC]Error in challenge signature from %s!\n",
! 		  olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->originator));
        
        return 0;
***************
*** 877,881 ****
  
    olsr_printf(1, "[ENC]%s registered with diff %d!\n",
! 	      olsr_ip_to_string((union olsr_ip_addr *)&msg->originator),
  	      entry->diff);
  
--- 883,887 ----
  
    olsr_printf(1, "[ENC]%s registered with diff %d!\n",
! 	      olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->originator),
  	      entry->diff);
  
***************
*** 895,903 ****
    olsr_u8_t sha1_hash[SIGNATURE_SIZE];
    struct stamp *entry;
  
    msg = (struct r_respmsg *)in_msg;
  
    olsr_printf(1, "[ENC]Response-response message received\n");
!   olsr_printf(3, "[ENC]To: %s\n", olsr_ip_to_string((union olsr_ip_addr *)&msg->destination));
  
    if(if_ifwithaddr((union olsr_ip_addr *)&msg->destination) == NULL)
--- 901,910 ----
    olsr_u8_t sha1_hash[SIGNATURE_SIZE];
    struct stamp *entry;
+   struct ipaddr_str buf;
  
    msg = (struct r_respmsg *)in_msg;
  
    olsr_printf(1, "[ENC]Response-response message received\n");
!   olsr_printf(3, "[ENC]To: %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->destination));
  
    if(if_ifwithaddr((union olsr_ip_addr *)&msg->destination) == NULL)
***************
*** 935,940 ****
    if((entry = lookup_timestamp_entry((union olsr_ip_addr *)&msg->originator)) == NULL)
      {
        olsr_printf(1, "[ENC]Received response-response from non-registered node %s!\n",
! 		  olsr_ip_to_string((union olsr_ip_addr *)&msg->originator));
        return 0;
      }
--- 942,948 ----
    if((entry = lookup_timestamp_entry((union olsr_ip_addr *)&msg->originator)) == NULL)
      {
+       struct ipaddr_str buf;
        olsr_printf(1, "[ENC]Received response-response from non-registered node %s!\n",
! 		  olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->originator));
        return 0;
      }
***************
*** 958,963 ****
    if(memcmp(msg->res_sig, sha1_hash, SIGNATURE_SIZE) != 0)
      {
        olsr_printf(1, "[ENC]Error in response signature from %s!\n",
! 		  olsr_ip_to_string((union olsr_ip_addr *)&msg->originator));
        
        return 0;
--- 966,972 ----
    if(memcmp(msg->res_sig, sha1_hash, SIGNATURE_SIZE) != 0)
      {
+       struct ipaddr_str buf;
        olsr_printf(1, "[ENC]Error in response signature from %s!\n",
! 		  olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->originator));
        
        return 0;
***************
*** 977,981 ****
  
    olsr_printf(1, "[ENC]%s registered with diff %d!\n",
! 	      olsr_ip_to_string((union olsr_ip_addr *)&msg->originator),
  	      entry->diff);
  
--- 986,990 ----
  
    olsr_printf(1, "[ENC]%s registered with diff %d!\n",
! 	      olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->originator),
  	      entry->diff);
  
***************
*** 991,999 ****
    struct stamp *entry;
    olsr_u32_t hash;
! 
    msg = (struct challengemsg *)in_msg;
  
    olsr_printf(1, "[ENC]Challenge message received\n");
!   olsr_printf(3, "[ENC]To: %s\n", olsr_ip_to_string((union olsr_ip_addr *)&msg->destination));
  
    if(if_ifwithaddr((union olsr_ip_addr *)&msg->destination) == NULL)
--- 1000,1009 ----
    struct stamp *entry;
    olsr_u32_t hash;
!   struct ipaddr_str buf;
!           
    msg = (struct challengemsg *)in_msg;
  
    olsr_printf(1, "[ENC]Challenge message received\n");
!   olsr_printf(3, "[ENC]To: %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)&msg->destination));
  
    if(if_ifwithaddr((union olsr_ip_addr *)&msg->destination) == NULL)
***************
*** 1088,1091 ****
--- 1098,1102 ----
    struct c_respmsg crmsg;
    olsr_u32_t challenge;
+   struct ipaddr_str buf;
  
    olsr_printf(1, "[ENC]Building CRESPONSE message\n");
***************
*** 1148,1152 ****
  
    olsr_printf(3, "[ENC]Sending challenge response to %s challenge 0x%x\n", 
! 	      olsr_ip_to_string(to),
  	      challenge);
  
--- 1159,1163 ----
  
    olsr_printf(3, "[ENC]Sending challenge response to %s challenge 0x%x\n", 
! 	      olsr_ip_to_string(&buf, to),
  	      challenge);
  
***************
*** 1173,1176 ****
--- 1184,1188 ----
  {
    struct r_respmsg rrmsg;
+   struct ipaddr_str buf;
  
    olsr_printf(1, "[ENC]Building RRESPONSE message\n");
***************
*** 1226,1230 ****
  
    olsr_printf(3, "[ENC]Sending response response to %s\n", 
! 	      olsr_ip_to_string(to));
  
    /* add to buffer */
--- 1238,1242 ----
  
    olsr_printf(3, "[ENC]Sending response response to %s\n", 
! 	      olsr_ip_to_string(&buf, to));
  
    /* add to buffer */
***************
*** 1244,1247 ****
--- 1256,1260 ----
    olsr_u32_t hash;
    struct stamp *entry;
+   struct ipaddr_str buf;
  
    hash = olsr_hashing(adr);
***************
*** 1253,1262 ****
        if(memcmp(&entry->addr, adr, olsr_cnf->ipsize) == 0)
  	{
! 	  olsr_printf(3, "[ENC]Match for %s\n", olsr_ip_to_string(adr));
  	  return entry;
  	}
      }
  
!   olsr_printf(1, "[ENC]No match for %s\n", olsr_ip_to_string(adr));
  
    return NULL;
--- 1266,1275 ----
        if(memcmp(&entry->addr, adr, olsr_cnf->ipsize) == 0)
  	{
! 	  olsr_printf(3, "[ENC]Match for %s\n", olsr_ip_to_string(&buf, adr));
  	  return entry;
  	}
      }
  
!   olsr_printf(1, "[ENC]No match for %s\n", olsr_ip_to_string(&buf, adr));
  
    return NULL;
***************
*** 1287,1295 ****
  	  if((TIMED_OUT(tmp_list->valtime)) && (TIMED_OUT(tmp_list->conftime)))
  	    {
  	      entry_to_delete = tmp_list;
  	      tmp_list = tmp_list->next;
  
  	      olsr_printf(1, "[ENC]timestamp info for %s timed out.. deleting it\n", 
! 			  olsr_ip_to_string(&entry_to_delete->addr));
  
  	      /*Delete it*/
--- 1300,1309 ----
  	  if((TIMED_OUT(tmp_list->valtime)) && (TIMED_OUT(tmp_list->conftime)))
  	    {
+               struct ipaddr_str buf;
  	      entry_to_delete = tmp_list;
  	      tmp_list = tmp_list->next;
  
  	      olsr_printf(1, "[ENC]timestamp info for %s timed out.. deleting it\n", 
! 			  olsr_ip_to_string(&buf, &entry_to_delete->addr));
  
  	      /*Delete it*/
***************
*** 1310,1314 ****
  
  static int
! read_key_from_file(char *file)
  {
    FILE *kf;
--- 1324,1328 ----
  
  static int
! read_key_from_file(const char *file)
  {
    FILE *kf;





More information about the Olsr-cvs mailing list