[Olsr-cvs] olsrd-current/lib/bmf/src Address.c, 1.3, 1.4 Address.h, 1.2, 1.3 Bmf.c, 1.4, 1.5 Bmf.h, 1.2, 1.3 DropList.c, 1.2, 1.3 DropList.h, 1.2, 1.3 NetworkInterfaces.c, 1.4, 1.5 NetworkInterfaces.h, 1.2, 1.3 Packet.c, 1.3, 1.4 Packet.h, 1.2, 1.3 PacketHistory.c, 1.3, 1.4 PacketHistory.h, 1.2, 1.3 olsrd_plugin.c, 1.3, 1.4

Bernd Petrovitsch (spam-protected)
Sun Apr 22 19:40:41 CEST 2007


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

Modified Files:
	Address.c Address.h Bmf.c Bmf.h DropList.c DropList.h 
	NetworkInterfaces.c NetworkInterfaces.h Packet.c Packet.h 
	PacketHistory.c PacketHistory.h olsrd_plugin.c 
Log Message:
* bmf-plugin 1.4

Index: Packet.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/Packet.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Packet.h	10 Feb 2007 17:05:56 -0000	1.2
--- Packet.h	22 Apr 2007 17:40:38 -0000	1.3
***************
*** 39,43 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 39,42 ----
***************
*** 68,72 ****
  } __attribute__((__packed__));
  
! #define	ENCAP_HDR_LEN (sizeof(struct TEncapHeader))
  
  struct TSaveTtl
--- 67,71 ----
  } __attribute__((__packed__));
  
! #define	ENCAP_HDR_LEN ((int)sizeof(struct TEncapHeader))
  
  struct TSaveTtl
***************
*** 76,85 ****
  } __attribute__((__packed__));
  
! int GetIpPacketLength(unsigned char* buffer);
! int GetIpHeaderLength(unsigned char* buffer);
! int GetIpTtl(unsigned char* buffer);
! void SaveTtlAndChecksum(unsigned char* buffer, struct TSaveTtl* sttl);
! void RestoreTtlAndChecksum(unsigned char* buffer, struct TSaveTtl* sttl);
! void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* buffer);
  
  #endif /* _BMF_PACKET_H */
--- 75,92 ----
  } __attribute__((__packed__));
  
! int IsIpFragment(unsigned char* ipPacket);
! u_int16_t GetTotalLength(unsigned char* ipPacket);
! unsigned int GetHeaderLength(unsigned char* ipPacket);
! u_int8_t GetTtl(unsigned char* ipPacket);
! void SaveTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl);
! void RestoreTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl);
! void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* ipPacket);
! u_int16_t GetEtherType(unsigned char* ethernetFrame);
! struct ip* GetIpHeader(unsigned char* ethernetFrame);
! unsigned char* GetIpPacket(unsigned char* ethernetFrame);
! u_int16_t GetFrameLength(unsigned char* ethernetFrame);
! void SetFrameSourceMac(unsigned char* ethernetFrame, unsigned char* srcMac);
! unsigned char* GetEthernetFrame(unsigned char* encapsulationUdpData);
! u_int16_t GetEncapsulationUdpDataLength(unsigned char* encapsulationUdpData);
  
  #endif /* _BMF_PACKET_H */

Index: Address.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/Address.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Address.h	10 Feb 2007 17:05:55 -0000	1.2
--- Address.h	22 Apr 2007 17:40:38 -0000	1.3
***************
*** 39,43 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 39,42 ----
***************
*** 51,56 ****
  int DoLocalBroadcast(const char* enable);
  int IsMulticast(union olsr_ip_addr* ipAddress);
! int IsLocalBroadcast(union olsr_ip_addr* destIp, struct sockaddr* broadAddr);
! int IsOlsrOrBmfPacket(struct TBmfInterface* intf, unsigned char* ethPkt, size_t len);
  
  #endif /* _BMF_ADDRESS_H */
--- 50,54 ----
  int DoLocalBroadcast(const char* enable);
  int IsMulticast(union olsr_ip_addr* ipAddress);
! int IsOlsrOrBmfPacket(unsigned char* ipPacket);
  
  #endif /* _BMF_ADDRESS_H */

Index: DropList.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/DropList.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DropList.h	10 Feb 2007 17:05:56 -0000	1.2
--- DropList.h	22 Apr 2007 17:40:38 -0000	1.3
***************
*** 39,43 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 39,42 ----

Index: Packet.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/Packet.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Packet.c	10 Feb 2007 17:05:56 -0000	1.3
--- Packet.c	22 Apr 2007 17:40:38 -0000	1.4
***************
*** 33,40 ****
  /* -------------------------------------------------------------------------
   * File       : Packet.c
!  * Description: BMF and IP packet processing functions
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 33,39 ----
  /* -------------------------------------------------------------------------
   * File       : Packet.c
!  * Description: IP packet and Ethernet frame processing functions
   * Created    : 29 Jun 2006
   *
   * ------------------------------------------------------------------------- */
  
***************
*** 42,105 ****
  
  /* System includes */
  #include <assert.h> /* assert() */
! #include <sys/types.h> /* u_int32_t */
  #include <netinet/in.h> /* ntohs(), htons() */
  #include <netinet/ip.h> /* struct iphdr */
  
- #include <stdio.h>
  /* -------------------------------------------------------------------------
!  * Function   : GetIpPacketLength
!  * Description: Retrieve the IP packet length (in bytes) of the passed
!  *              ethernet-IP packet
!  * Input      : buffer - the ethernet-IP packet
   * Output     : none
   * Return     : IP packet length
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! int GetIpPacketLength(unsigned char* buffer)
  {
    struct iphdr* iph;
  
!   assert(buffer != NULL);
  
!   iph = (struct iphdr*) (buffer + IP_HDR_OFFSET);
    return ntohs(iph->tot_len);
  }
  
  /* -------------------------------------------------------------------------
!  * Function   : GetIpHeaderLength
!  * Description: Retrieve the IP header length (in bytes) of the passed
!  *              ethernet-IP packet
!  * Input      : buffer - the ethernet-IP packet
   * Output     : none
   * Return     : IP header length
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! int GetIpHeaderLength(unsigned char* buffer)
  {
    struct iphdr* iph;
  
!   assert(buffer != NULL);
  
!   iph = (struct iphdr*) (buffer + IP_HDR_OFFSET);
    return iph->ihl << 2;
  }
  
  /* -------------------------------------------------------------------------
!  * Function   : GetIpTtl
   * Description: Retrieve the TTL (Time To Live) value from the IP header of
!  *              the passed ethernet-IP packet
!  * Input      : buffer - the ethernet-IP packet
   * Output     : none
   * Return     : TTL value
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! int GetIpTtl(unsigned char* buffer)
  {
    struct iphdr* iph;
  
!   assert(buffer != NULL);
  
!   iph = (struct iphdr*) (buffer + IP_HDR_OFFSET);
    return iph->ttl;
  }
--- 41,126 ----
  
  /* System includes */
+ #include <stddef.h> /* NULL */
  #include <assert.h> /* assert() */
! #include <string.h> /* memcpy() */
! #include <sys/types.h> /* u_int8_t, u_int16_t, u_int32_t */
  #include <netinet/in.h> /* ntohs(), htons() */
  #include <netinet/ip.h> /* struct iphdr */
  
  /* -------------------------------------------------------------------------
!  * Function   : IsIpFragment
!  * Description: Check if an IP packet is an IP fragment
!  * Input      : ipPacket - the IP packet
!  * Output     : none
!  * Return     : true (1) or false (0)
!  * Data Used  : none
!  * ------------------------------------------------------------------------- */
! int IsIpFragment(unsigned char* ipPacket)
! {
!   struct ip* iph;
! 
!   assert(ipPacket != NULL);
! 
!   iph = (struct ip*) ipPacket;
!   if ((ntohs(iph->ip_off) & IP_OFFMASK) != 0)
!   {
!     return 1;
!   }
!   return 0;
! }
! 
! /* -------------------------------------------------------------------------
!  * Function   : GetTotalLength
!  * Description: Retrieve the total length of the IP packet (in bytes) of
!  *              an IP packet
!  * Input      : ipPacket - the IP packet
   * Output     : none
   * Return     : IP packet length
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! u_int16_t GetTotalLength(unsigned char* ipPacket)
  {
    struct iphdr* iph;
  
!   assert(ipPacket != NULL);
  
!   iph = (struct iphdr*) ipPacket;
    return ntohs(iph->tot_len);
  }
  
  /* -------------------------------------------------------------------------
!  * Function   : GetHeaderLength
!  * Description: Retrieve the IP header length (in bytes) of an IP packet
!  * Input      : ipPacket - the IP packet
   * Output     : none
   * Return     : IP header length
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! unsigned int GetHeaderLength(unsigned char* ipPacket)
  {
    struct iphdr* iph;
  
!   assert(ipPacket != NULL);
  
!   iph = (struct iphdr*) ipPacket;
    return iph->ihl << 2;
  }
  
  /* -------------------------------------------------------------------------
!  * Function   : GetTtl
   * Description: Retrieve the TTL (Time To Live) value from the IP header of
!  *              an IP packet
!  * Input      : ipPacket - the IP packet
   * Output     : none
   * Return     : TTL value
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! u_int8_t GetTtl(unsigned char* ipPacket)
  {
    struct iphdr* iph;
  
!   assert(ipPacket != NULL);
  
!   iph = (struct iphdr*) ipPacket;
    return iph->ttl;
  }
***************
*** 108,124 ****
   * Function   : SaveTtlAndChecksum
   * Description: Save the TTL (Time To Live) value and IP checksum as found in
!  *              the IP header of the passed ethernet-IP packet
!  * Input      : buffer - the ethernet-IP packet
   * Output     : sttl - the TTL and checksum values
   * Return     : none
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! void SaveTtlAndChecksum(unsigned char* buffer, struct TSaveTtl* sttl)
  {
    struct iphdr* iph;
  
!   assert(buffer != NULL && sttl != NULL);
  
!   iph = (struct iphdr*) (buffer + IP_HDR_OFFSET);
    sttl->ttl = iph->ttl;
    sttl->check = ntohs(iph->check);
--- 129,145 ----
   * Function   : SaveTtlAndChecksum
   * Description: Save the TTL (Time To Live) value and IP checksum as found in
!  *              the IP header of an IP packet
!  * Input      : ipPacket - the IP packet
   * Output     : sttl - the TTL and checksum values
   * Return     : none
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! void SaveTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl)
  {
    struct iphdr* iph;
  
!   assert(ipPacket != NULL && sttl != NULL);
  
!   iph = (struct iphdr*) ipPacket;
    sttl->ttl = iph->ttl;
    sttl->check = ntohs(iph->check);
***************
*** 128,133 ****
   * Function   : RestoreTtlAndChecksum
   * Description: Restore the TTL (Time To Live) value and IP checksum in
!  *              the IP header of the passed ethernet-IP packet
!  * Input      : buffer - the ethernet-IP packet
   *              sttl - the TTL and checksum values
   * Output     : none
--- 149,154 ----
   * Function   : RestoreTtlAndChecksum
   * Description: Restore the TTL (Time To Live) value and IP checksum in
!  *              the IP header of an IP packet
!  * Input      : ipPacket - the IP packet
   *              sttl - the TTL and checksum values
   * Output     : none
***************
*** 135,145 ****
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! void RestoreTtlAndChecksum(unsigned char* buffer, struct TSaveTtl* sttl)
  {
    struct iphdr* iph;
  
!   assert(buffer != NULL && sttl != NULL);
  
!   iph = (struct iphdr*) (buffer + IP_HDR_OFFSET);
    iph->ttl = sttl->ttl;
    iph->check = htons(sttl->check);
--- 156,166 ----
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! void RestoreTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl)
  {
    struct iphdr* iph;
  
!   assert(ipPacket != NULL && sttl != NULL);
  
!   iph = (struct iphdr*) ipPacket;
    iph->ttl = sttl->ttl;
    iph->check = htons(sttl->check);
***************
*** 150,154 ****
   * Description: For an IP packet, decrement the TTL value and update the IP header
   *              checksum accordingly.
!  * Input      : buffer - the ethernet-IP packet
   * Output     : none
   * Return     : none
--- 171,175 ----
   * Description: For an IP packet, decrement the TTL value and update the IP header
   *              checksum accordingly.
!  * Input      : ipPacket - the IP packet
   * Output     : none
   * Return     : none
***************
*** 156,167 ****
   * Notes      : See also RFC1141
   * ------------------------------------------------------------------------- */
! void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* buffer)
  {
    struct iphdr* iph;
    u_int32_t sum;
  
!   assert(buffer != NULL);
  
!   iph = (struct iphdr*) (buffer + IP_HDR_OFFSET);
  
    iph->ttl--; /* decrement ttl */
--- 177,188 ----
   * Notes      : See also RFC1141
   * ------------------------------------------------------------------------- */
! void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* ipPacket)
  {
    struct iphdr* iph;
    u_int32_t sum;
  
!   assert(ipPacket != NULL);
  
!   iph = (struct iphdr*) ipPacket;
  
    iph->ttl--; /* decrement ttl */
***************
*** 169,170 ****
--- 190,287 ----
    iph->check = htons(sum + (sum>>16)); /* add carry */
  }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : GetEtherType
+  * Description: Retrieve the EtherType of an Ethernet frame
+  * Input      : ethernetFrame - the Ethernet frame
+  * Output     : none
+  * Return     : EtherType
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ u_int16_t GetEtherType(unsigned char* ethernetFrame)
+ {
+   u_int16_t type;
+   memcpy(&type, ethernetFrame + ETH_TYPE_OFFSET, 2);
+   return ntohs(type);
+ }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : GetIpHeader
+  * Description: Retrieve the IP header from an Ethernet frame
+  * Input      : ethernetFrame - the Ethernet frame
+  * Output     : none
+  * Return     : IP header
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ struct ip* GetIpHeader(unsigned char* ethernetFrame)
+ {
+   return (struct ip*)(ethernetFrame + IP_HDR_OFFSET);
+ }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : GetIpPacket
+  * Description: Retrieve the IP packet from an Ethernet frame
+  * Input      : ethernetFrame - the Ethernet frame
+  * Output     : none
+  * Return     : IP packet
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ unsigned char* GetIpPacket(unsigned char* ethernetFrame)
+ {
+   return ethernetFrame + IP_HDR_OFFSET;
+ }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : GetFrameLength
+  * Description: Return the Ethernet frame length of an Ethernet frame containing
+  *              an IP packet
+  * Input      : ethernetFrame - the Ethernet frame
+  * Output     : none
+  * Return     : The frame length
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ u_int16_t GetFrameLength(unsigned char* ethernetFrame)
+ {
+   return GetTotalLength(GetIpPacket(ethernetFrame)) + IP_HDR_OFFSET;
+ }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : SetFrameSourceMac
+  * Description: Set the source MAC address of an Ethernet frame
+  * Input      : ethernetFrame - the Ethernet frame
+               : srcMac - the source MAC address
+  * Output     : none
+  * Return     : none
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ void SetFrameSourceMac(unsigned char* ethernetFrame, unsigned char* srcMac)
+ {
+   memcpy(ethernetFrame + IFHWADDRLEN, srcMac, IFHWADDRLEN);
+ }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : GetEthernetFrame
+  * Description: Retrieve the Ethernet frame from BMF encapsulation UDP data
+  * Input      : encapsulationUdpData - the encapsulation UDP data
+  * Output     : none
+  * Return     : The Ethernet frame
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ unsigned char* GetEthernetFrame(unsigned char* encapsulationUdpData)
+ {
+   return encapsulationUdpData + ENCAP_HDR_LEN;
+ }
+ 
+ /* -------------------------------------------------------------------------
+  * Function   : GetEncapsulationUdpDataLength
+  * Description: Return the length of BMF encapsulation UDP data
+  * Input      : encapsulationUdpData - the encapsulation UDP data
+  * Output     : none
+  * Return     : The packet length
+  * Data Used  : none
+  * ------------------------------------------------------------------------- */
+ u_int16_t GetEncapsulationUdpDataLength(unsigned char* encapsulationUdpData)
+ {
+   return GetFrameLength(GetEthernetFrame(encapsulationUdpData)) + ENCAP_HDR_LEN;
+ }
+ 

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/olsrd_plugin.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** olsrd_plugin.c	20 Apr 2007 14:06:18 -0000	1.3
--- olsrd_plugin.c	22 Apr 2007 17:40:39 -0000	1.4
***************
*** 36,45 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
  /* System includes */
  #include <assert.h> /* assert() */
! #include <stdio.h>
  
  /* OLSRD includes */
--- 36,44 ----
   * Created    : 29 Jun 2006
   *
   * ------------------------------------------------------------------------- */
  
  /* System includes */
  #include <assert.h> /* assert() */
! #include <stddef.h> /* NULL */
  
  /* OLSRD includes */

Index: DropList.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/DropList.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DropList.c	10 Feb 2007 17:05:55 -0000	1.2
--- DropList.c	22 Apr 2007 17:40:38 -0000	1.3
***************
*** 37,41 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 37,40 ----
***************
*** 45,49 ****
  /* System includes */
  #include <assert.h> /* assert() */
! #include <stdio.h> /* NULL */
  #include <stdlib.h> /* malloc */
  #include <string.h> /* memcmp */
--- 44,49 ----
  /* System includes */
  #include <assert.h> /* assert() */
! #include <stddef.h> /* NULL */
! #include <stdio.h> /* sscanf */
  #include <stdlib.h> /* malloc */
  #include <string.h> /* memcmp */

Index: Address.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/Address.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Address.c	20 Apr 2007 14:06:17 -0000	1.3
--- Address.c	22 Apr 2007 17:40:38 -0000	1.4
***************
*** 36,40 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
   
--- 36,39 ----
***************
*** 42,45 ****
--- 41,45 ----
  
  /* System includes */
+ #include <stddef.h> /* NULL */
  #include <assert.h> /* assert() */
  #include <netinet/ip.h> /* struct ip */
***************
*** 100,227 ****
  
  /* -------------------------------------------------------------------------
-  * Function   : IsLocalBroadcast
-  * Description: Check if an IP address is a local broadcast address for a
-  *              given network interface
-  * Input      : destIp, broadAddr
-  * Output     : none
-  * Return     : true (1) or false (0)
-  * Data Used  : none
-  * ------------------------------------------------------------------------- */
- int IsLocalBroadcast(union olsr_ip_addr* destIp, struct sockaddr* broadAddr)
- {
-   struct sockaddr_in* sin;
-   
-   assert(destIp != NULL && broadAddr != NULL);
- 
-   /* Cast down to correct sockaddr subtype */
-   sin = (struct sockaddr_in*)broadAddr;
- 
-   return COMP_IP(&(sin->sin_addr.s_addr), destIp);
- }
- 
- /* -------------------------------------------------------------------------
   * Function   : IsOlsrOrBmfPacket
!  * Description: Check if an ethernet packet is an OLSR packet or a BMF packet
!  * Input      : intf, ethPkt, len
   * Output     : none
   * Return     : true (1) or false (0)
   * Data Used  : none
-  * Assumption : len >= IP_HDR_OFFSET + GetIpHeaderLength(ethPkt)
   * ------------------------------------------------------------------------- */
! int IsOlsrOrBmfPacket(struct TBmfInterface* intf __attribute__((unused)), unsigned char* ethPkt, size_t len)
  {
!   struct ip* ipData;
    unsigned int ipHeaderLen;
!   struct udphdr* udpData;
    u_int16_t destPort;
  
!   assert(ethPkt != NULL);
  
!   /* Consider OLSR and BMF packets not to be local broadcast
!    * OLSR packets are UDP - port 698
     * OLSR-BMF packets are UDP - port 50698
!    * OLSR-Autodetect probe packets are UDP - port 51698
!    * Fragments of the above packets are also not local broadcast */
  
!   ipData = (struct ip*) (ethPkt + IP_HDR_OFFSET);
!   if (ipData->ip_p != SOL_UDP)
    {
      return 0;
    }
  
!   /* Check if the packet is an IP-fragment */
!   if ((ntohs(ipData->ip_off) & IP_OFFMASK) != 0)
!   {
! #if 0
!     int i;
!     for (i = 0; i < FRAGMENT_HISTORY_SIZE; i++)
!     {
!       /* Quick-access pointer */
!       struct TFragmentHistory* entry = &intf->fragmentHistory[i];
! 
!       /* Match */
!       if (entry->ipId == ntohs(ipData->ip_id) &&
!           entry->ipProto == ipData->ip_p &&
!           entry->ipSrc.s_addr == ntohl(ipData->ip_src.s_addr) &&
!           entry->ipDst.s_addr == ntohl(ipData->ip_dst.s_addr))
!       {
!         /* Found matching history entry, so packet is assumed to be a fragment
!          * of an earlier OLSR/OLSR-BMF/OLSR-Autodetect packet */
! 
!         /* More fragments? If not, invalidate entry */
!         if (((ntohs(ipData->ip_off) & IP_MF) == 0))
!         {
!           memset(entry, 0, sizeof(struct TFragmentHistory));
!         }
! 
!         return 1;
!       }
!     }
! 
!     /* Matching history entry not found, so packet is not assumed to be a fragment
!      * of an earlier OLSR/OLSR-BMF/OLSR-Autodetect packet */
! #endif
!     /* OOPS! IP-fragments may come in earlier than their main packet. In that case,
!      * their relation with the main packet is not detected by the above code, resulting
!      * in stray fragments being forwarded all ove the network. Solution for now is to
!      * not forward any IP-fragments at all. */
!     /*return 0;*/
!     return 1;
!   }
! 
!   /* The packet is the first (or only) IP-fragment */
! 
!   /* Check length first */
!   ipHeaderLen = ipData->ip_hl << 2;
!   if (len < IP_HDR_OFFSET + ipHeaderLen + sizeof(struct udphdr))
    {
      return 0;
    }
  
    /* Go into the UDP header and check port number */
!   udpData = (struct udphdr*) (ethPkt + IP_HDR_OFFSET + ipHeaderLen);
!   destPort = ntohs(udpData->dest);
  
    if (destPort == OLSRPORT || destPort == BMF_ENCAP_PORT || destPort == 51698)
        /* TODO: #define for 51698 */
    {
- #if 0
-     /* If more fragments are expected, keep a record in the fragment history */
-     if ((ntohs(ipData->ip_off) & IP_MF) != 0)
-     {
-       /* Quick-access pointer */
-       struct TFragmentHistory* entry = &intf->fragmentHistory[intf->nextFragmentHistoryEntry];
- 
-       /* Store in fragment history */
-       entry->ipId = ntohs(ipData->ip_id);
-       entry->ipProto = ipData->ip_p;
-       entry->ipSrc.s_addr = ntohl(ipData->ip_src.s_addr);
-       entry->ipDst.s_addr = ntohl(ipData->ip_dst.s_addr);
- 
-       /* Advance to next entry */
-       intf->nextFragmentHistoryEntry++;
-       intf->nextFragmentHistoryEntry %= FRAGMENT_HISTORY_SIZE;
-     }
- #endif
      return 1;
    }
--- 100,146 ----
  
  /* -------------------------------------------------------------------------
   * Function   : IsOlsrOrBmfPacket
!  * Description: Check if an IP packet is either an OLSR packet or a BMF packet
!  * Input      : ipPacket
   * Output     : none
   * Return     : true (1) or false (0)
   * Data Used  : none
   * ------------------------------------------------------------------------- */
! int IsOlsrOrBmfPacket(unsigned char* ipPacket)
  {
!   struct ip* ipHeader;
    unsigned int ipHeaderLen;
!   struct udphdr* udpHeader;
    u_int16_t destPort;
  
!   assert(ipPacket != NULL);
  
!   /* OLSR packets are UDP - port 698
     * OLSR-BMF packets are UDP - port 50698
!    * OLSR-Autodetect probe packets are UDP - port 51698 */
  
!   /* Check if UDP */
!   ipHeader = (struct ip*) ipPacket;
!   if (ipHeader->ip_p != SOL_UDP)
    {
+     /* Not UDP */
      return 0;
    }
  
!   /* The total length must be at least large enough to store the UDP header */
!   ipHeaderLen = GetHeaderLength(ipPacket);
!   if (GetTotalLength(ipPacket) < ipHeaderLen + sizeof(struct udphdr))
    {
+     /* Not long enough */
      return 0;
    }
  
    /* Go into the UDP header and check port number */
!   udpHeader = (struct udphdr*) (ipPacket + ipHeaderLen);
!   destPort = ntohs(udpHeader->dest);
  
    if (destPort == OLSRPORT || destPort == BMF_ENCAP_PORT || destPort == 51698)
        /* TODO: #define for 51698 */
    {
      return 1;
    }

Index: Bmf.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/Bmf.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Bmf.h	10 Feb 2007 17:05:55 -0000	1.2
--- Bmf.h	22 Apr 2007 17:40:38 -0000	1.3
***************
*** 39,43 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 39,42 ----
***************
*** 45,49 ****
  #define PLUGIN_NAME "OLSRD Basic Multicast Forwarding (BMF) plugin"
  #define PLUGIN_NAME_SHORT "OLSRD BMF"
! #define PLUGIN_VERSION "1.3 (" __DATE__ " " __TIME__ ")"
  #define PLUGIN_COPYRIGHT "  (C) Thales Communications Huizen, Netherlands"
  #define PLUGIN_AUTHOR "  Erik Tromp ((spam-protected))"
--- 44,48 ----
  #define PLUGIN_NAME "OLSRD Basic Multicast Forwarding (BMF) plugin"
  #define PLUGIN_NAME_SHORT "OLSRD BMF"
! #define PLUGIN_VERSION "1.4 (" __DATE__ " " __TIME__ ")"
  #define PLUGIN_COPYRIGHT "  (C) Thales Communications Huizen, Netherlands"
  #define PLUGIN_AUTHOR "  Erik Tromp ((spam-protected))"
***************
*** 53,58 ****
--- 52,60 ----
  #define BMF_ENCAP_PORT 50698
  
+ /* Forward declaration of OLSR interface type */
  struct interface;
  
+ void BmfPError(char* format, ...) __attribute__((format(printf, 1, 2)));
+ union olsr_ip_addr* MainAddressOf(union olsr_ip_addr* ip);
  int InterfaceChange(struct interface* interf, int action);
  int InitBmf(struct interface* skipThisIntf);

Index: PacketHistory.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/PacketHistory.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PacketHistory.c	20 Apr 2007 14:06:18 -0000	1.3
--- PacketHistory.c	22 Apr 2007 17:40:38 -0000	1.4
***************
*** 37,41 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 37,40 ----
***************
*** 43,46 ****
--- 42,46 ----
  
  /* System includes */
+ #include <stddef.h> /* NULL */
  #include <assert.h> /* assert() */
  #include <string.h> /* memset */
***************
*** 51,55 ****
  #include "olsr.h" /* olsr_printf */
  
! /* Plugin includes */
  #include "Packet.h"
  
--- 51,55 ----
  #include "olsr.h" /* olsr_printf */
  
! /* NULLPlugin includes */
  #include "Packet.h"
  
***************
*** 147,153 ****
  /* -------------------------------------------------------------------------
   * Function   : PacketCrc32
!  * Description: Calculates the CRC-32 value for an Ethernet packet
!  * Input      : ethPkt - the Ethernet packet
!  *              len - the number of octets in the Ethernet packet
   * Output     : none
   * Return     : 32-bits hash value
--- 147,153 ----
  /* -------------------------------------------------------------------------
   * Function   : PacketCrc32
!  * Description: Calculates the CRC-32 value for an Ethernet frame
!  * Input      : ethernetFrame - the Ethernet frame
!  *              len - the number of octets in the Ethernet frame
   * Output     : none
   * Return     : 32-bits hash value
***************
*** 156,167 ****
   *              in the CRC calculation.
   * ------------------------------------------------------------------------- */
! u_int32_t PacketCrc32(unsigned char* ethPkt, ssize_t len)
  {
    ssize_t nCrcBytes;
    struct TSaveTtl sttl;
!   struct iphdr* iph;
    u_int32_t result;
  
!   assert(ethPkt != NULL);
  
    /* Start CRC calculation at ethertype; skip source and destination MAC 
--- 156,167 ----
   *              in the CRC calculation.
   * ------------------------------------------------------------------------- */
! u_int32_t PacketCrc32(unsigned char* ethernetFrame, ssize_t len)
  {
    ssize_t nCrcBytes;
    struct TSaveTtl sttl;
!   struct ip* ipHeader;
    u_int32_t result;
  
!   assert(ethernetFrame != NULL);
  
    /* Start CRC calculation at ethertype; skip source and destination MAC 
***************
*** 184,196 ****
    }
  
!   SaveTtlAndChecksum(ethPkt, &sttl);
  
!   iph = (struct iphdr*) (ethPkt + IP_HDR_OFFSET);
!   iph->ttl = 0xFF; /* fixed value of TTL for CRC-32 calculation */
!   iph->check = 0x5A5A; /* fixed value of IP header checksum for CRC-32 calculation */
  
!   result = CalcCrc32(ethPkt + IP_HDR_OFFSET, nCrcBytes);
  
!   RestoreTtlAndChecksum(ethPkt, &sttl);
    return result;
  }
--- 184,196 ----
    }
  
!   SaveTtlAndChecksum(GetIpPacket(ethernetFrame), &sttl);
  
!   ipHeader = GetIpHeader(ethernetFrame);
!   ipHeader->ip_ttl = 0xFF; /* fixed value of TTL for CRC-32 calculation */
!   ipHeader->ip_sum = 0x5A5A; /* fixed value of IP header checksum for CRC-32 calculation */
  
!   result = CalcCrc32(ethernetFrame + IP_HDR_OFFSET, nCrcBytes);
  
!   RestoreTtlAndChecksum(GetIpPacket(ethernetFrame), &sttl);
    return result;
  }

Index: NetworkInterfaces.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/NetworkInterfaces.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NetworkInterfaces.h	10 Feb 2007 17:05:56 -0000	1.2
--- NetworkInterfaces.h	22 Apr 2007 17:40:38 -0000	1.3
***************
*** 39,43 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 39,42 ----
***************
*** 45,48 ****
--- 44,50 ----
  #include <netinet/in.h> /* struct in_addr */
  
+ /* OLSR includes */
+ #include "olsr_types.h" /* olsr_ip_addr */
+ 
  /* Plugin includes */
  #include "Packet.h" /* IFHWADDRLEN */
***************
*** 60,63 ****
--- 62,69 ----
    int encapsulatingSkfd;
  
+   /* File descriptor of UDP packet socket, used for listening to encapsulation packets.
+    * Used only when PlParam "BmfMechanism" is set to "UnicastPromiscuous". */
+   int listeningSkfd;
+ 
    unsigned char macAddr[IFHWADDRLEN];
  
***************
*** 69,76 ****
  
    /* IP address of this network interface */
!   struct sockaddr intAddr;
  
    /* Broadcast address of this network interface */
!   struct sockaddr broadAddr;
  
    #define FRAGMENT_HISTORY_SIZE 10
--- 75,82 ----
  
    /* IP address of this network interface */
!   union olsr_ip_addr intAddr;
  
    /* Broadcast address of this network interface */
!   union olsr_ip_addr broadAddr;
  
    #define FRAGMENT_HISTORY_SIZE 10
***************
*** 85,88 ****
--- 91,99 ----
    int nextFragmentHistoryEntry;
  
+   /* Number of received and transmitted BMF packets on this interface */
+   u_int32_t nBmfPacketsRx;
+   u_int32_t nBmfPacketsRxDup;
+   u_int32_t nBmfPacketsTx;
+ 
    /* Next element in list */
    struct TBmfInterface* next; 
***************
*** 98,101 ****
--- 109,115 ----
  extern char EtherTunTapIfName[];
  
+ /* 10.255.255.253 in host byte order */
+ #define ETHERTUNTAPDEFAULTIP 0x0AFFFFFD
+ 
  extern u_int32_t EtherTunTapIp;
  extern u_int32_t EtherTunTapIpMask;
***************
*** 107,114 ****
--- 121,140 ----
  extern enum TTunOrTap TunOrTap;
  
+ enum TBmfMechanism { BM_BROADCAST = 0, BM_UNICAST_PROMISCUOUS };
+ extern enum TBmfMechanism BmfMechanism;
+ 
  int SetBmfInterfaceName(const char* ifname);
  int SetBmfInterfaceType(const char* iftype);
  int SetBmfInterfaceIp(const char* ip);
  int SetCapturePacketsOnOlsrInterfaces(const char* enable);
+ int SetBmfMechanism(const char* mechanism);
+ int DeactivateSpoofFilter(void);
+ void RestoreSpoofFilter(void);
+ struct link_entry* GetBestNeighbor(
+   struct TBmfInterface* intf,
+   union olsr_ip_addr* source,
+   union olsr_ip_addr* forwardedBy,
+   union olsr_ip_addr* forwardedTo,
+   int* multipleNeighbors);
  int CreateBmfNetworkInterfaces(struct interface* skipThisIntf);
  void AddInterface(struct interface* newIntf);
***************
*** 116,120 ****
  int AddNonOlsrBmfIf(const char* ifName);
  int IsNonOlsrBmfIf(const char* ifName);
! void CheckAndUpdateLocalBroadcast(unsigned char* buffer, struct sockaddr* broadAddr);
  
  #endif /* _BMF_NETWORKINTERFACES_H */
--- 142,148 ----
  int AddNonOlsrBmfIf(const char* ifName);
  int IsNonOlsrBmfIf(const char* ifName);
! void CheckAndUpdateLocalBroadcast(unsigned char* ipPacket, union olsr_ip_addr* broadAddr);
! void AddMulticastRoute(void);
! void DeleteMulticastRoute(void);
  
  #endif /* _BMF_NETWORKINTERFACES_H */

Index: Bmf.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/Bmf.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Bmf.c	20 Apr 2007 14:58:35 -0000	1.4
--- Bmf.c	22 Apr 2007 17:40:38 -0000	1.5
***************
*** 36,40 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 36,39 ----
***************
*** 44,50 ****
  
  /* System includes */
[...2251 lines suppressed...]
!     BmfPError("pthread_join() error");
    }
  
!   /* Clean up after the BmfThread has been killed */
    CloseBmfNetworkInterfaces();
  }
***************
*** 1367,1372 ****
--- 1456,1466 ----
      return SetCapturePacketsOnOlsrInterfaces(value);
    }
+   else if (strcmp(key, "BmfMechanism") == 0)
+   {
+     return SetBmfMechanism(value);
+   }
  
    /* Key not recognized */
    return 0;
  }
+ 

Index: NetworkInterfaces.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/NetworkInterfaces.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** NetworkInterfaces.c	20 Apr 2007 14:06:17 -0000	1.4
--- NetworkInterfaces.c	22 Apr 2007 17:40:38 -0000	1.5
***************
*** 36,40 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 36,39 ----
***************
*** 42,45 ****
--- 41,45 ----
  
[...1993 lines suppressed...]
+     ((struct sockaddr_in*)&kernel_route.rt_genmask)->sin_family = AF_INET;
+ 
+     /* 224.0.0.0/4 */
+     ((struct sockaddr_in *)&kernel_route.rt_dst)->sin_addr.s_addr = htonl(0xE0000000);
+     ((struct sockaddr_in *)&kernel_route.rt_genmask)->sin_addr.s_addr = htonl(0xF0000000);
+ 
+     kernel_route.rt_metric = 0;
+     kernel_route.rt_flags = RTF_UP;
+ 
+     kernel_route.rt_dev = EtherTunTapIfName;
+ 
+     if (ioctl(ioctlSkfd, SIOCDELRT, &kernel_route) < 0)
+     {
+       BmfPError("error deleting multicast route via EtherTunTap interface \"%s\"", EtherTunTapIfName);
+ 
+       /* Continue anyway */
+     }
+     close(ioctlSkfd);
+   }
+ }

Index: PacketHistory.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/bmf/src/PacketHistory.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PacketHistory.h	10 Feb 2007 17:05:56 -0000	1.2
--- PacketHistory.h	22 Apr 2007 17:40:39 -0000	1.3
***************
*** 40,44 ****
   * Created    : 29 Jun 2006
   *
-  * $Id$ 
   * ------------------------------------------------------------------------- */
  
--- 40,43 ----





More information about the Olsr-cvs mailing list