[Olsr-cvs] olsrd-current/src net_olsr.c,1.11,1.12

Andreas T�nnesen (spam-protected)
Tue Jan 10 21:38:21 CET 2006


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

Modified Files:
	net_olsr.c 
Log Message:
Wow, there are some serious issue with libnet using UDP+IPv6... To bad since this is what we really wanted libnet for. I'll see if I can create a workaround, as for now there is no UDP checksum in the IPv6 packets beeing sent...

Index: net_olsr.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/net_olsr.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** net_olsr.c	8 Jan 2006 20:27:17 -0000	1.11
--- net_olsr.c	10 Jan 2006 20:38:19 -0000	1.12
***************
*** 402,405 ****
--- 402,436 ----
  }
  
+ /*
+  * Stolen from libnet
+  */
+ 
+ #define OLSR_CKSUM_CARRY(x) \
+     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
+ 
+ int
+ olsr_in_cksum(olsr_u16_t *buf, int len)
+ {
+     int sum;
+     u_int16_t last_byte;
+ 
+     sum = 0;
+     last_byte = 0;
+ 
+     while (len > 1)
+       {
+         sum += *buf++;
+         len -= 2;
+       }
+     if (len == 1)
+       {
+         *(u_int8_t*)&last_byte = *(u_int8_t*)buf;
+         sum += last_byte;
+       }
+     
+     return sum;
+ }
+ 
+ 
  /**
   *Sends a packet on a given interface.
***************
*** 456,460 ****
    printf("LIBNET TX %d bytes on %s\n", 
  	 netbufs[ifp->if_nr]->pending, ifp->int_name);
!   
    udp_ptag = libnet_build_udp(OLSRPORT, 
  			      OLSRPORT,
--- 487,491 ----
    printf("LIBNET TX %d bytes on %s\n", 
  	 netbufs[ifp->if_nr]->pending, ifp->int_name);
! 
    udp_ptag = libnet_build_udp(OLSRPORT, 
  			      OLSRPORT,
***************
*** 465,468 ****
--- 496,500 ----
  			      ifp->libnet_ctx,
  			      0);
+ 
    if(udp_ptag == -1)
      {
***************
*** 472,476 ****
        return -1;
      }
! 
    if(olsr_cnf->ip_version == AF_INET)
      {
--- 504,508 ----
        return -1;
      }
!   
    if(olsr_cnf->ip_version == AF_INET)
      {
***************
*** 502,509 ****
        /* IP version 6 */
        struct libnet_in6_addr src, dst;
  
        memcpy(&src, &ifp->ip_addr.v6, sizeof(src));
        memcpy(&dst, &((struct sockaddr_in6 *)&ifp->int6_multaddr)->sin6_addr, sizeof(dst));
!  
        ip_ptag = libnet_build_ipv6(0, /* Traffic class */
  				  0, /* Flow label */
--- 534,559 ----
        /* IP version 6 */
        struct libnet_in6_addr src, dst;
+       int sum;
  
        memcpy(&src, &ifp->ip_addr.v6, sizeof(src));
        memcpy(&dst, &((struct sockaddr_in6 *)&ifp->int6_multaddr)->sin6_addr, sizeof(dst));
! 
! 
!       /* !!!ATTENTION!!!
!        * There is a bug in libnet (libnet_build_udp) 1.1.2 that causes
!        * a crash if requesting auto-generated UDP checksums when
!        * using IPv6.
!        * Since we want backwards compability(well... as of now it
!        * is actually current compability), we MUST manually generate
!        * a checksum when in IPv6 mode.
!        * Yepp - it sux
!        * - Andreas
!        */
!       libnet_toggle_checksum(ifp->libnet_ctx, udp_ptag, LIBNET_OFF);
! 
!       /* TODO: generate and insert CHKSUM */
! 
!       printf("Build IPv6 size: %d\n",
! 	     LIBNET_IPV6_H + LIBNET_UDP_H + netbufs[ifp->if_nr]->pending);
        ip_ptag = libnet_build_ipv6(0, /* Traffic class */
  				  0, /* Flow label */
***************
*** 525,533 ****
  	  return -1;
  	}
!     }
    if((retval = libnet_write(ifp->libnet_ctx)) == -1)
      {
        OLSR_PRINTF (1, "libnet packet write: %s\n", libnet_geterror (ifp->libnet_ctx))
      }
  
    libnet_clear_packet(ifp->libnet_ctx);
--- 575,606 ----
  	  return -1;
  	}
! 
! #if 0
!  {
!    libnet_ptag_t ether_tag = 0;
!    unsigned char enet_broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
! 
!    ether_tag = libnet_build_ethernet(enet_broadcast,
! 				     libnet_get_hwaddr(ifp->libnet_ctx),
! 				     ETHERTYPE_IP,
! 				     NULL,        		/* payload */
! 				     0,           		/* payload size */
! 				     ifp->libnet_ctx, 		/* libnet handle */
! 				     0);  		        /* pblock tag */
!    if (ether_tag == -1)
!      {
!        OLSR_PRINTF (1, "libnet ethernet header: %s\n", libnet_geterror (ifp->libnet_ctx))
! 	 netbufs[ifp->if_nr]->pending = 0;
!        libnet_clear_packet(ifp->libnet_ctx);
!        return -1;
!      }
!  }
! #endif
! 
    if((retval = libnet_write(ifp->libnet_ctx)) == -1)
      {
        OLSR_PRINTF (1, "libnet packet write: %s\n", libnet_geterror (ifp->libnet_ctx))
      }
+   printf("RETVAL: %d\n", retval); fflush(stdout);
  
    libnet_clear_packet(ifp->libnet_ctx);





More information about the Olsr-cvs mailing list