[Olsr-cvs] olsrd-current/lib/secure/src secure_messages.h, NONE, 1.1 olsrd_plugin.c, 1.9, 1.10 olsrd_secure.c, 1.13, 1.14 olsrd_secure.h, 1.4, 1.5 olsrd_plugin.h, 1.14, NONE

Bruno Randolf (spam-protected)
Sun May 29 14:47:46 CEST 2005


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

Modified Files:
	olsrd_plugin.c olsrd_secure.c olsrd_secure.h 
Added Files:
	secure_messages.h 
Removed Files:
	olsrd_plugin.h 
Log Message:
new plugin interface:
  - plugins can now directly access all olsrd data structures
  - a plugin only has to include "olsrd_plugin.h" and provide 3 interface functions:
      1. olsrd_plugin_interface_version()
      2. olsrd_plugin_register_param()
      3. olsrd_plugin_init()
    which are called in the above order
  - moved all plugins to the new interface


--- NEW FILE: secure_messages.h ---

/*
 * Secure OLSR plugin
 * http://www.olsr.org
 *
 * Copyright (c) 2004, Andreas Tønnesen((spam-protected))
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or 
 * without modification, are permitted provided that the following 
 * conditions are met:
 *
 * * Redistributions of source code must retain the above copyright 
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright 
 *   notice, this list of conditions and the following disclaimer in 
 *   the documentation and/or other materials provided with the 
 *   distribution.
 * * Neither the name of olsrd, olsr.org nor the names of its 
 *   contributors may be used to endorse or promote products derived 
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: secure_messages.h,v 1.1 2005/05/29 12:47:44 br1 Exp $
 */


/*
 * olsr.org olsr daemon security plugin
 */

#ifndef _OLSRD_SECURE_MSG
#define _OLSRD_SECURE_MSG


#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <time.h>
#include <math.h>
#include <stdio.h>

#include "olsr_types.h"
#include "interfaces.h"

/* The type of message you will use */
#define MESSAGE_TYPE 10

/* The type of messages we will receive - can be set to promiscuous */
#define PARSER_TYPE MESSAGE_TYPE

#define TYPE_CHALLENGE 11
#define TYPE_CRESPONSE 12
#define TYPE_RRESPONSE 13


char keyfile[FILENAME_MAX];


#ifdef USE_OPENSSL
#define SIGSIZE   20
#else
#define SIGSIZE   16
#endif

/****************************************************************************
 *                            PACKET SECTION                                *
 ****************************************************************************/

struct sig_msg
{
  olsr_u8_t     type;
  olsr_u8_t     algorithm;
  olsr_u16_t    reserved;

  time_t        timestamp;
  char          signature[SIGSIZE];
};

/*
 * OLSR message (several can exist in one OLSR packet)
 */

struct s_olsrmsg
{
  olsr_u8_t     olsr_msgtype;
  olsr_u8_t     olsr_vtime;
  olsr_u16_t    olsr_msgsize;
  olsr_u32_t    originator;
  olsr_u8_t     ttl;
  olsr_u8_t     hopcnt;
  olsr_u16_t    seqno;

  /* YOUR PACKET GOES HERE */
  struct sig_msg sig;

};


/*
 * Challenge response messages
 */

struct challengemsg
{
  olsr_u8_t     olsr_msgtype;
  olsr_u8_t     olsr_vtime;
  olsr_u16_t    olsr_msgsize;
  olsr_u32_t    originator;
  olsr_u8_t     ttl;
  olsr_u8_t     hopcnt;
  olsr_u16_t    seqno;

  olsr_u32_t    destination;
  olsr_u32_t    challenge;

  char          signature[SIGSIZE];

};



struct c_respmsg
{
  olsr_u8_t     olsr_msgtype;
  olsr_u8_t     olsr_vtime;
  olsr_u16_t    olsr_msgsize;
  olsr_u32_t    originator;
  olsr_u8_t     ttl;
  olsr_u8_t     hopcnt;
  olsr_u16_t    seqno;

  olsr_u32_t    destination;
  olsr_u32_t    challenge;
  time_t        timestamp;

  char          res_sig[SIGSIZE];

  char          signature[SIGSIZE];

};


struct r_respmsg
{
  olsr_u8_t     olsr_msgtype;
  olsr_u8_t     olsr_vtime;
  olsr_u16_t    olsr_msgsize;
  olsr_u32_t    originator;
  olsr_u8_t     ttl;
  olsr_u8_t     hopcnt;
  olsr_u16_t    seqno;

  olsr_u32_t    destination;
  time_t        timestamp;

  char          res_sig[SIGSIZE];

  char          signature[SIGSIZE];
};


/*
 *IPv6
 */

struct s_olsrmsg6
{
  olsr_u8_t        olsr_msgtype;
  olsr_u8_t        olsr_vtime;
  olsr_u16_t       olsr_msgsize;
  struct in6_addr  originator;
  olsr_u8_t        ttl;
  olsr_u8_t        hopcnt;
  olsr_u16_t       seqno;

  /* YOUR PACKET GOES HERE */
  struct sig_msg   sig;
};

/*
 * Generic OLSR packet - DO NOT ALTER
 */

struct s_olsr 
{
  olsr_u16_t	  olsr_packlen;		/* packet length */
  olsr_u16_t	  olsr_seqno;
  struct s_olsrmsg  olsr_msg[1];          /* variable messages */
};


struct s_olsr6
{
  olsr_u16_t	    olsr_packlen;        /* packet length */
  olsr_u16_t	    olsr_seqno;
  struct s_olsrmsg6   olsr_msg[1];         /* variable messages */
};


#endif

Index: olsrd_secure.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/secure/src/olsrd_secure.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** olsrd_secure.h	10 Mar 2005 19:57:48 -0000	1.4
--- olsrd_secure.h	29 May 2005 12:47:44 -0000	1.5
***************
*** 42,46 ****
  #define _OLSRD_PLUGIN_TEST
  
! #include "olsrd_plugin.h"
  
  #define KEYFILE "/root/.olsr/olsrd_secure_key"
--- 42,49 ----
  #define _OLSRD_PLUGIN_TEST
  
! #include "secure_messages.h"
! 
! #include "hashing.h"
! 
  
  #define KEYFILE "/root/.olsr/olsrd_secure_key"
***************
*** 53,58 ****
  #define MD5_INCLUDING_KEY   2
  
- #define	MAXMESSAGESIZE 512
- 
  #ifdef USE_OPENSSL
  #define SIGNATURE_SIZE 20
--- 56,59 ----
***************
*** 145,149 ****
  
  void
! timeout_timestamps(void);
  
  int
--- 146,150 ----
  
  void
! timeout_timestamps(void*);
  
  int
***************
*** 156,158 ****
--- 157,177 ----
  read_key_from_file(char *);
  
+ void
+ olsr_get_timestamp(olsr_u32_t, struct timeval *);
+ 
+ void
+ olsr_init_timer(olsr_u32_t, struct timeval *);
+ 
+ int
+ olsr_timed_out(struct timeval *);
+ 
+ int
+ secure_plugin_init(void);
+ 
+ void
+ secure_plugin_exit(void);
+ 
+ int
+ plugin_ipc_init(void);
+ 
  #endif

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/secure/src/olsrd_plugin.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** olsrd_plugin.c	25 Feb 2005 22:43:11 -0000	1.9
--- olsrd_plugin.c	29 May 2005 12:47:43 -0000	1.10
***************
*** 40,58 ****
  
  #include "olsrd_plugin.h"
  #include <stdio.h>
  #include <string.h>
- #include "plugin_loader.h"
  
! void __attribute__ ((constructor)) 
  my_init(void);
  
! void __attribute__ ((destructor)) 
  my_fini(void);
  
- int
- register_olsr_data(struct olsr_plugin_data *);
- 
- int
- fetch_olsrd_data(void);
  
  /*
--- 40,60 ----
  
  #include "olsrd_plugin.h"
+ #include "olsrd_secure.h"
  #include <stdio.h>
  #include <string.h>
  
! 
! #define PLUGIN_NAME    "OLSRD signature plugin"
! #define PLUGIN_VERSION "0.5"
! #define PLUGIN_AUTHOR   "Andreas Tønnesen"
! #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! 
! 
! static void __attribute__ ((constructor)) 
  my_init(void);
  
! static void __attribute__ ((destructor)) 
  my_fini(void);
  
  
  /*
***************
*** 62,68 ****
   */
  int 
! get_plugin_interface_version()
  {
!   return PLUGIN_INTERFACE_VERSION;
  }
  
--- 64,70 ----
   */
  int 
! olsrd_plugin_interface_version()
  {
!   return OLSRD_PLUGIN_INTERFACE_VERSION;
  }
  
***************
*** 72,76 ****
   *Constructor
   */
! void
  my_init()
  {
--- 74,78 ----
   *Constructor
   */
! static void
  my_init()
  {
***************
*** 79,85 ****
    printf("%s\n", MOD_DESC);
    printf("[ENC]Accepted parameter pairs: (\"Keyfile\" <FILENAME>)\n"); 
-   ifs = NULL;
- 
-   return;
  }
  
--- 81,84 ----
***************
*** 87,91 ****
   *Destructor
   */
! void
  my_fini()
  {
--- 86,90 ----
   *Destructor
   */
! static void
  my_fini()
  {
***************
*** 97,108 ****
     * should happen there - NOT HERE!
     */
!   olsr_plugin_exit();
! 
!   return;
  }
  
  
  int
! register_olsr_param(char *key, char *value)
  {
    if(!strcmp(key, "Keyfile"))
--- 96,105 ----
     * should happen there - NOT HERE!
     */
!   secure_plugin_exit();
  }
  
  
  int
! olsrd_plugin_register_param(char *key, char *value)
  {
    if(!strcmp(key, "Keyfile"))
***************
*** 115,151 ****
  
  
- /**
-  *Register needed functions and pointers
-  *
-  *This function should not be changed!
-  *
-  */
  int
! register_olsr_data(struct olsr_plugin_data *data)
! {
!   /* IPversion */
!   ipversion = data->ipversion;
!   /* Main address */
!   main_addr = data->main_addr;
! 
!   /* Multi-purpose function */
!   olsr_plugin_io = data->olsr_plugin_io;
! 
!   /* Set size of IP address */
!   if(ipversion == AF_INET)
!     {
!       ipsize = sizeof(olsr_u32_t);
!     }
!   else
!     {
!       ipsize = sizeof(struct in6_addr);
!     }
! 
!   if(!fetch_olsrd_data())
!     {
!       fprintf(stderr, "Could not fetch the neccessary functions from olsrd!\n");
!       return 0;
!     }
! 
    /* Calls the initialization function
     * olsr_plugin_init()
--- 112,117 ----
  
  
  int
! olsrd_plugin_init() {
    /* Calls the initialization function
     * olsr_plugin_init()
***************
*** 154,158 ****
     * should happen there - NOT HERE!
     */
!   if(!olsr_plugin_init())
      {
        fprintf(stderr, "Could not initialize plugin!\n");
--- 120,124 ----
     * should happen there - NOT HERE!
     */
!   if(!secure_plugin_init())
      {
        fprintf(stderr, "Could not initialize plugin!\n");
***************
*** 168,337 ****
  
  }
- 
- 
- 
- int
- fetch_olsrd_data()
- {
-   int retval = 1;
- 
- 
-   if(!olsr_plugin_io(GETF__NET_RESERVE_BUFSPACE, 
- 		     &net_reserve_bufspace, 
- 		     sizeof(net_reserve_bufspace)))
-   {
-     net_reserve_bufspace = NULL;
-     retval = 0;
-   }
- 
-   if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH_RESERVED, 
- 		     &net_outbuffer_push_reserved, 
- 		     sizeof(net_outbuffer_push_reserved)))
-   {
-     net_outbuffer_push_reserved = NULL;
-     retval = 0;
-   }
- 
-   if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH, 
- 		     &net_outbuffer_push, 
- 		     sizeof(net_outbuffer_push)))
-   {
-     net_outbuffer_push = NULL;
-     retval = 0;
-   }
- 
- 
-   if(!olsr_plugin_io(GETF__OLSR_PRINTF, 
- 		     &olsr_printf, 
- 		     sizeof(olsr_printf)))
-   {
-     olsr_printf = NULL;
-     retval = 0;
-   }
- 
-   if(!olsr_plugin_io(GETD__NOW, 
- 		     &now, 
- 		     sizeof(now)))
-   {
-     now = NULL;
-     retval = 0;
-   }
- 
-   if(!olsr_plugin_io(GETF__NET_OUTPUT, 
- 		     &net_output, 
- 		     sizeof(net_output)))
-   {
-     net_output = NULL;
-     retval = 0;
-   }
- 
-   /* Olsr malloc wrapper */
-   if(!olsr_plugin_io(GETF__OLSR_MALLOC, 
- 		     &olsr_malloc, 
- 		     sizeof(olsr_malloc)))
-   {
-     olsr_malloc = NULL;
-     retval = 0;
-   }
- 
-   /* Scheduler event registration */
-   if(!olsr_plugin_io(GETF__OLSR_REGISTER_SCHEDULER_EVENT, 
- 		     &olsr_register_scheduler_event, 
- 		     sizeof(olsr_register_scheduler_event)))
-   {
-     olsr_register_scheduler_event = NULL;
-     retval = 0;
-   }
- 
- 
-   /* Interface list */
-   if(!olsr_plugin_io(GETD__IFNET, &ifs, sizeof(ifs)))
-   {
-     ifs = NULL;
-     retval = 0;
-   }
- 
- 
- 
-   /* Add socket to OLSR select function */
-   if(!olsr_plugin_io(GETF__ADD_OLSR_SOCKET, &add_olsr_socket, sizeof(add_olsr_socket)))
-   {
-     add_olsr_socket = NULL;
-     retval = 0;
-   }
- 
-   /* Remove socket from OLSR select function */
-   if(!olsr_plugin_io(GETF__REMOVE_OLSR_SOCKET, &remove_olsr_socket, sizeof(remove_olsr_socket)))
-   {
-     remove_olsr_socket = NULL;
-     retval = 0;
-   }
- 
-   /* Add packet transform function */
-   if(!olsr_plugin_io(GETF__ADD_PTF, &add_ptf, sizeof(add_ptf)))
-   {
-     add_ptf = NULL;
-     retval = 0;
-   }
- 
-   /* Remove packet transform function */
-   if(!olsr_plugin_io(GETF__DEL_PTF, &del_ptf, sizeof(del_ptf)))
-   {
-     del_ptf = NULL;
-     retval = 0;
-   }
- 
-   /* Get message seqno function */
-   if(!olsr_plugin_io(GETF__GET_MSG_SEQNO, &get_msg_seqno, sizeof(get_msg_seqno)))
-   {
-     get_msg_seqno = NULL;
-     retval = 0;
-   }
- 
-   /* Socket read function */
-   if(!olsr_plugin_io(GETF__OLSR_INPUT, &olsr_input, sizeof(olsr_input)))
-   {
-     olsr_input = NULL;
-     retval = 0;
-   }
- 
-   /* Default packet parser */
-   if(!olsr_plugin_io(GETF__PARSE_PACKET, &parse_packet, sizeof(parse_packet)))
-   {
-     parse_packet = NULL;
-     retval = 0;
-   }
- 
-   /* Find interface by socket */
-   if(!olsr_plugin_io(GETF__IF_IFWITHSOCK, &if_ifwithsock, sizeof(if_ifwithsock)))
-   {
-     if_ifwithsock = NULL;
-     retval = 0;
-   }
- 
-   /* Find interface by address */
-   if(!olsr_plugin_io(GETF__IF_IFWITHADDR, &if_ifwithaddr, sizeof(if_ifwithaddr)))
-   {
-     if_ifwithaddr = NULL;
-     retval = 0;
-   }
- 
- 
-   /* Add ifchange function */
-   if(!olsr_plugin_io(GETF__ADD_IFCHGF, &add_ifchgf, sizeof(add_ifchgf)))
-   {
-     add_ifchgf = NULL;
-     retval = 0;
-   }
- 
-   /* Remove ifchange function */
-   if(!olsr_plugin_io(GETF__DEL_IFCHGF, &del_ifchgf, sizeof(del_ifchgf)))
-   {
-     del_ifchgf = NULL;
-     retval = 0;
-   }
- 
- 
-   return retval;
- 
- }
--- 134,135 ----

--- olsrd_plugin.h DELETED ---

Index: olsrd_secure.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/secure/src/olsrd_secure.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** olsrd_secure.c	25 May 2005 13:50:22 -0000	1.13
--- olsrd_secure.c	29 May 2005 12:47:44 -0000	1.14
***************
*** 43,46 ****
--- 43,47 ----
  
  #include "olsrd_secure.h"
+ 
  #include <stdio.h>
  #include <string.h>
***************
*** 53,56 ****
--- 54,63 ----
  #include <signal.h>
  
+ #include "defs.h"
+ #include "olsr.h"
+ #include "socket_parser.h"
+ #include "parser.h"
+ #include "scheduler.h"
+ 
  #ifdef USE_OPENSSL
  /* OpenSSL stuff */
***************
*** 112,116 ****
  
  int
! olsr_plugin_init()
  {
    struct interface *ints;
--- 119,123 ----
  
  int
! secure_plugin_init()
  {
    struct interface *ints;
***************
*** 149,153 ****
  
    /* Hijack OLSR socket parser functions */
!   ints = ifs;
    while(ints)
      {
--- 156,160 ----
  
    /* Hijack OLSR socket parser functions */
!   ints = ifnet;
    while(ints)
      {
***************
*** 158,162 ****
       
        /* Reducing maxmessagesize */
!       net_reserve_bufspace(ints, sizeof(struct olsrmsg));
  
        ints = ints->int_next;
--- 165,169 ----
       
        /* Reducing maxmessagesize */
!       net_reserve_bufspace(ints, sizeof(struct s_olsrmsg));
  
        ints = ints->int_next;
***************
*** 169,172 ****
--- 176,180 ----
  }
  
+ 
  int
  plugin_ipc_init()
***************
*** 180,205 ****
   */
  void
! olsr_plugin_exit()
! {
! }
! 
! 
! 
! /* Mulitpurpose funtion */
! int
! plugin_io(int cmd, void *data, size_t size)
  {
- 
-   switch(cmd)
-     {
-     default:
-       return 0;
-     }
-   
-   return 1;
  }
  
  
- 
  /**
   *Scheduled event
--- 188,196 ----
   */
  void
! secure_plugin_exit()
  {
  }
  
  
  /**
   *Scheduled event
***************
*** 232,236 ****
        add_olsr_socket(ifn->olsr_socket, &packet_parser);
        /* Reducing maxmessagesize */
!       net_reserve_bufspace(ifn, sizeof(struct olsrmsg));
        break;
  
--- 223,227 ----
        add_olsr_socket(ifn->olsr_socket, &packet_parser);
        /* Reducing maxmessagesize */
!       net_reserve_bufspace(ifn, sizeof(struct s_olsrmsg));
        break;
  
***************
*** 283,287 ****
  	}
  
!       if(ipversion == AF_INET)
  	{
  	  /* IPv4 sender address */
--- 274,278 ----
  	}
  
!       if(olsr_cnf->ip_version == AF_INET)
  	{
  	  /* IPv4 sender address */
***************
*** 345,351 ****
  
        //printf("\nCC: %d FROMLEN: %d\n\n", cc, fromlen);
!       if ((ipversion == AF_INET) && (fromlen != sizeof (struct sockaddr_in)))
  	break;
!       else if ((ipversion == AF_INET6) && (fromlen != sizeof (struct sockaddr_in6)))
  	break;
  
--- 336,342 ----
  
        //printf("\nCC: %d FROMLEN: %d\n\n", cc, fromlen);
!       if ((olsr_cnf->ip_version == AF_INET) && (fromlen != sizeof (struct sockaddr_in)))
  	break;
!       else if ((olsr_cnf->ip_version == AF_INET6) && (fromlen != sizeof (struct sockaddr_in6)))
  	break;
  
***************
*** 410,414 ****
  add_signature(char *pck, int *size)
  {
!   struct olsrmsg *msg;
  #ifdef DEBUG
    int i, j;
--- 401,405 ----
  add_signature(char *pck, int *size)
  {
!   struct s_olsrmsg *msg;
  #ifdef DEBUG
    int i, j;
***************
*** 419,431 ****
    fflush(stdout);
    
!   msg = (struct olsrmsg *)&pck[*size];
    /* Update size */
!   ((struct olsr*)pck)->olsr_packlen = htons(*size + sizeof(struct olsrmsg));
    
    /* Fill packet header */
    msg->olsr_msgtype = MESSAGE_TYPE;
    msg->olsr_vtime = 0;
!   msg->olsr_msgsize = htons(sizeof(struct olsrmsg));
!   memcpy(&msg->originator, main_addr, ipsize);
    msg->ttl = 1;
    msg->hopcnt = 0;
--- 410,422 ----
    fflush(stdout);
    
!   msg = (struct s_olsrmsg *)&pck[*size];
    /* Update size */
!   ((struct olsr*)pck)->olsr_packlen = htons(*size + sizeof(struct s_olsrmsg));
    
    /* Fill packet header */
    msg->olsr_msgtype = MESSAGE_TYPE;
    msg->olsr_vtime = 0;
!   msg->olsr_msgsize = htons(sizeof(struct s_olsrmsg));
!   memcpy(&msg->originator, &main_addr, ipsize);
    msg->ttl = 1;
    msg->hopcnt = 0;
***************
*** 438,446 ****
    
    /* Add timestamp */
!   msg->sig.timestamp = htonl(now->tv_sec);
!   olsr_printf(3, "[ENC]timestamp: %d\n", now->tv_sec);
    
    /* Set the new size */
!   *size = *size + sizeof(struct olsrmsg);
    
    /* Create packet + key cache */
--- 429,437 ----
    
    /* Add timestamp */
!   msg->sig.timestamp = htonl(now.tv_sec);
!   olsr_printf(3, "[ENC]timestamp: %d\n", now.tv_sec);
    
    /* Set the new size */
!   *size = *size + sizeof(struct s_olsrmsg);
    
    /* Create packet + key cache */
***************
*** 460,464 ****
    sigmsg = (char *)msg;
  
!   for(i = 0; i < sizeof(struct olsrmsg); i++)
      {
        olsr_printf(1, "  %3i", (u_char) sigmsg[i]);
--- 451,455 ----
    sigmsg = (char *)msg;
  
!   for(i = 0; i < sizeof(struct s_olsrmsg); i++)
      {
        olsr_printf(1, "  %3i", (u_char) sigmsg[i]);
***************
*** 484,488 ****
    int packetsize;
    char sha1_hash[SIGNATURE_SIZE];
!   struct olsrmsg *sig;
    time_t rec_time;
  
--- 475,479 ----
    int packetsize;
    char sha1_hash[SIGNATURE_SIZE];
!   struct s_olsrmsg *sig;
    time_t rec_time;
  
***************
*** 493,502 ****
  
    /* Find size - signature message */
!   packetsize = *size - sizeof(struct olsrmsg);
  
    if(packetsize < 4)
      return 0;
  
!   sig = (struct olsrmsg *)&pck[packetsize];
  
    //olsr_printf(1, "Size: %d\n", packetsize);
--- 484,493 ----
  
    /* Find size - signature message */
!   packetsize = *size - sizeof(struct s_olsrmsg);
  
    if(packetsize < 4)
      return 0;
  
!   sig = (struct s_olsrmsg *)&pck[packetsize];
  
    //olsr_printf(1, "Size: %d\n", packetsize);
***************
*** 508,512 ****
    sigmsg = (char *)sig;
  
!   for(i = 0; i < sizeof(struct olsrmsg); i++)
      {
        olsr_printf(1, "  %3i", (u_char) sigmsg[i]);
--- 499,503 ----
    sigmsg = (char *)sig;
  
!   for(i = 0; i < sizeof(struct s_olsrmsg); i++)
      {
        olsr_printf(1, "  %3i", (u_char) sigmsg[i]);
***************
*** 523,527 ****
    if((sig->olsr_msgtype != MESSAGE_TYPE) || 
       (sig->olsr_vtime) ||
!      (sig->olsr_msgsize != ntohs(sizeof(struct olsrmsg))) ||
       (sig->ttl != 1) ||
       (sig->hopcnt != 0))
--- 514,518 ----
    if((sig->olsr_msgtype != MESSAGE_TYPE) || 
       (sig->olsr_vtime) ||
!      (sig->olsr_msgsize != ntohs(sizeof(struct s_olsrmsg))) ||
       (sig->ttl != 1) ||
       (sig->hopcnt != 0))
***************
*** 603,607 ****
      }
  
!   olsr_printf(1, "[ENC]Received timestamp %d diff: %d\n", rec_time, now->tv_sec - rec_time);
  
    /* Remove signature message */
--- 594,598 ----
      }
  
!   olsr_printf(1, "[ENC]Received timestamp %d diff: %d\n", rec_time, now.tv_sec - rec_time);
  
    /* Remove signature message */
***************
*** 634,638 ****
      }
  
!   diff = entry->diff - (now->tv_sec - tstamp);
  
    olsr_printf(3, "[ENC]Timestamp slack: %d\n", diff);
--- 625,629 ----
      }
  
!   diff = entry->diff - (now.tv_sec - tstamp);
  
    olsr_printf(3, "[ENC]Timestamp slack: %d\n", diff);
***************
*** 645,650 ****
  
    /* ok - update diff */
!   entry->diff = ((now->tv_sec - tstamp) + entry->diff) ?
!     ((now->tv_sec - tstamp) + entry->diff) / 2 : 0;
  
    olsr_printf(3, "[ENC]Diff set to : %d\n", entry->diff);
--- 636,641 ----
  
    /* ok - update diff */
!   entry->diff = ((now.tv_sec - tstamp) + entry->diff) ?
!     ((now.tv_sec - tstamp) + entry->diff) / 2 : 0;
  
    olsr_printf(3, "[ENC]Diff set to : %d\n", entry->diff);
***************
*** 684,688 ****
    cmsg.olsr_vtime = 0;
    cmsg.olsr_msgsize = htons(sizeof(struct challengemsg));
!   memcpy(&cmsg.originator, main_addr, ipsize);
    cmsg.ttl = 1;
    cmsg.hopcnt = 0;
--- 675,679 ----
    cmsg.olsr_vtime = 0;
    cmsg.olsr_msgsize = htons(sizeof(struct challengemsg));
!   memcpy(&cmsg.originator, &main_addr, ipsize);
    cmsg.ttl = 1;
    cmsg.hopcnt = 0;
***************
*** 820,824 ****
    entry->challenge = 0;
    entry->validated = 1;
!   entry->diff = now->tv_sec - msg->timestamp;
  
    /* update validtime - validated entry */
--- 811,815 ----
    entry->challenge = 0;
    entry->validated = 1;
!   entry->diff = now.tv_sec - msg->timestamp;
  
    /* update validtime - validated entry */
***************
*** 915,919 ****
    entry->challenge = 0;
    entry->validated = 1;
!   entry->diff = now->tv_sec - msg->timestamp;
  
    /* update validtime - validated entry */
--- 906,910 ----
    entry->challenge = 0;
    entry->validated = 1;
!   entry->diff = now.tv_sec - msg->timestamp;
  
    /* update validtime - validated entry */
***************
*** 1045,1049 ****
    crmsg.olsr_vtime = 0;
    crmsg.olsr_msgsize = htons(sizeof(struct c_respmsg));
!   memcpy(&crmsg.originator, main_addr, ipsize);
    crmsg.ttl = 1;
    crmsg.hopcnt = 0;
--- 1036,1040 ----
    crmsg.olsr_vtime = 0;
    crmsg.olsr_msgsize = htons(sizeof(struct c_respmsg));
!   memcpy(&crmsg.originator, &main_addr, ipsize);
    crmsg.ttl = 1;
    crmsg.hopcnt = 0;
***************
*** 1051,1055 ****
  
    /* set timestamp */
!   crmsg.timestamp = now->tv_sec;
    olsr_printf(3, "[ENC]Timestamp %d\n", crmsg.timestamp);
  
--- 1042,1046 ----
  
    /* set timestamp */
!   crmsg.timestamp = now.tv_sec;
    olsr_printf(3, "[ENC]Timestamp %d\n", crmsg.timestamp);
  
***************
*** 1119,1123 ****
    rrmsg.olsr_vtime = 0;
    rrmsg.olsr_msgsize = htons(sizeof(struct r_respmsg));
!   memcpy(&rrmsg.originator, main_addr, ipsize);
    rrmsg.ttl = 1;
    rrmsg.hopcnt = 0;
--- 1110,1114 ----
    rrmsg.olsr_vtime = 0;
    rrmsg.olsr_msgsize = htons(sizeof(struct r_respmsg));
!   memcpy(&rrmsg.originator, &main_addr, ipsize);
    rrmsg.ttl = 1;
    rrmsg.hopcnt = 0;
***************
*** 1125,1129 ****
  
    /* set timestamp */
!   rrmsg.timestamp = now->tv_sec;
    olsr_printf(3, "[ENC]Timestamp %d\n", rrmsg.timestamp);
  
--- 1116,1120 ----
  
    /* set timestamp */
!   rrmsg.timestamp = now.tv_sec;
    olsr_printf(3, "[ENC]Timestamp %d\n", rrmsg.timestamp);
  
***************
*** 1204,1208 ****
   */
  void
! timeout_timestamps()
  {
    struct stamp *tmp_list;
--- 1195,1199 ----
   */
  void
! timeout_timestamps(void* foo)
  {
    struct stamp *tmp_list;
***************
*** 1278,1311 ****
  
  /**
-  *Hashing function. Creates a key based on
-  *an 32-bit address.
-  *@param address the address to hash
-  *@return the hash(a value in the 0-31 range)
-  */
- olsr_u32_t
- olsr_hashing(union olsr_ip_addr *address)
- {
-   olsr_u32_t hash;
-   char *tmp;
- 
-   if(ipversion == AF_INET)
-     /* IPv4 */  
-     hash = (ntohl(address->v4));
-   else
-     {
-       /* IPv6 */
-       tmp = (char *) &address->v6;
-       hash = (ntohl(*tmp));
-     }
- 
-   //hash &= 0x7fffffff; 
-   hash &= HASHMASK;
- 
-   return hash;
- }
- 
- 
- 
- /**
   *Checks if a timer has times out. That means
   *if it is smaller than present time.
--- 1269,1272 ----
***************
*** 1318,1322 ****
  olsr_timed_out(struct timeval *timer)
  {
!   return(timercmp(timer, now, <));
  }
  
--- 1279,1283 ----
  olsr_timed_out(struct timeval *timer)
  {
!   return(timercmp(timer, &now, <));
  }
  
***************
*** 1364,1407 ****
    time_value_msec= delay - (delay*1000);
  
!   hold_timer->tv_sec = now->tv_sec + time_value_sec;
!   hold_timer->tv_usec = now->tv_usec + (time_value_msec*1000);   
! }
! 
! 
! /**
!  *Converts a olsr_ip_addr to a string
!  *Goes for both IPv4 and IPv6
!  *
!  *NON REENTRANT! If you need to use this
!  *function twice in e.g. the same printf
!  *it will not work.
!  *You must use it in different calls e.g.
!  *two different printfs
!  *
!  *@param the IP to convert
!  *@return a pointer to a static string buffer
!  *representing the address in "dots and numbers"
!  *
!  */
! char *
! olsr_ip_to_string(union olsr_ip_addr *addr)
! {
! 
!   char *ret;
!   struct in_addr in;
!   
!   if(ipversion == AF_INET)
!     {
!       in.s_addr=addr->v4;
!       ret = inet_ntoa(in);
!     }
!   else
!     {
!       /* IPv6 */
!       ret = (char *)inet_ntop(AF_INET6, &addr->v6, ipv6_buf, sizeof(ipv6_buf));
!     }
! 
!   return ret;
  }
  
- 
--- 1325,1330 ----
    time_value_msec= delay - (delay*1000);
  
!   hold_timer->tv_sec = now.tv_sec + time_value_sec;
!   hold_timer->tv_usec = now.tv_usec + (time_value_msec*1000);   
  }
  




More information about the Olsr-cvs mailing list