[ofw] patch: [ipoib] when checking if a packet is a dhcp packet, make sure to check the offset and not the flags

Smith, Stan stan.smith at intel.com
Mon Oct 3 15:10:25 PDT 2011


Hello,
  Oops, there are cases where the offset+flags word is not handled correctly.
  While applying this patch, I realized we already have a macro defined in ip_packet.h which embodies your patch: IP_FRAGMENT_OFFSET().
By using IP_FRAGMENT() instead of 'cl_ntoh16(((ip_hdr_t*)p_ip_hdr)->offset_flags) & OFFSET_MASK' it cleans the code up and we do not need the #define OFFSET_MASK.

The patch becomes

Index: inc/kernel/ip_packet.h
===================================================================
--- inc/kernel/ip_packet.h           (revision 7290)
+++ inc/kernel/ip_packet.h        (working copy)
@@ -221,7 +221,7 @@
               uint8_t                 svc_type;
               net16_t                                length;
               net16_t                                id;
-              net16_t                                offset;
+             net16_t                                offset_flags;
               uint8_t                 ttl;
               uint8_t                 prot;
               net16_t                                chksum;


--- ulp/ipoib/kernel/ipoib_port.cpp   Fri Sep 23 11:57:50 2011

+++ ulp/ipoib/kernel/ipoib_port.cpp   (working copy) Mon Oct 03 14:51:35 2011

@@ -451,7 +451,7 @@

                     p_ip_hdr->svc_type,

                     cl_ntoh16( p_ip_hdr->length ),

                     cl_ntoh16( p_ip_hdr->id ),

-                     cl_ntoh16( p_ip_hdr->offset ),

+                     cl_ntoh16( p_ip_hdr->offset_flags ),

                     p_ip_hdr->ttl,

                     p_ip_hdr->prot,

                     cl_ntoh16( p_ip_hdr->chksum ),

@@ -2987,7 +2987,7 @@

                     break;

               }

-               if( p_ipoib->type.ip.hdr.offset ||

+               if( IP_FRAGMENT_OFFSET(&p_ipoib->type.ip.hdr) ||

                     p_ipoib->type.ip.hdr.prot != IP_PROT_UDP )

               {

                     /* Unfiltered.  Setup the ethernet header and report. */

@@ -5415,7 +5415,7 @@

    PERF_DECLARE( FilterDhcp );

     XIPOIB_ENTER( IPOIB_DBG_SEND );

-    if ( (ethertype == ETH_PROT_TYPE_IP) && ((ip_hdr_t*)p_ip_hdr)->offset > 0 )

+    if ( (ethertype == ETH_PROT_TYPE_IP) && IP_FRAGMENT_OFFSET((ip_hdr_t*)p_ip_hdr) > 0 )

     {

          /* This is a fragmented part of UDP packet

           * Only first packet will contain UDP header in such case

@@ -9713,7 +9721,7 @@

    uint16_t*  p_hdr = (uint16_t*)p_ip_hdr;

     p_ip_hdr->length = cl_hton16( fragment_size ); // bytes

-    p_ip_hdr->offset = cl_hton16( fragment_offset ); // 8-byte units

+    p_ip_hdr->offset_flags = cl_hton16( fragment_offset ); // 8-byte units

     if( more_fragments )

    {

Thoughts?

Stan.


From: ofw-bounces at lists.openfabrics.org [mailto:ofw-bounces at lists.openfabrics.org] On Behalf Of Tzachi Dar
Sent: Sunday, October 02, 2011 2:44 AM
To: ofw at lists.openfabrics.org
Subject: [ofw] patch: [ipoib] when checking if a packet is a dhcp packet, make sure to check the offset and not the flags

On an ip header there are 3 bits flags and 13 bits of offset.
We used to look at them as one word, which cause us not to use flags well.

The following code fixes this.

Thanks
Tzachi


Index: inc/kernel/ip_packet.h
===================================================================
--- inc/kernel/ip_packet.h           (revision 7290)
+++ inc/kernel/ip_packet.h        (working copy)
@@ -221,7 +221,7 @@
               uint8_t                 svc_type;
               net16_t                                length;
               net16_t                                id;
-              net16_t                                offset;
+             net16_t                                offset_flags;
               uint8_t                 ttl;
               uint8_t                 prot;
               net16_t                                chksum;
@@ -264,6 +264,10 @@
* SEE ALSO
*            IB Network Drivers, eth_hdr_t, arp_pkt_t, tcp_hdr_t, udp_hdr_t
*********/
+
+#define OFFSET_MASK  0x1fff
+
+
#include <complib/cl_packoff.h>

 #include <complib/cl_packon.h>
Index: ulp/ipoib_NDIS6_CM/kernel/ipoib_port.cpp
===================================================================
--- ulp/ipoib_NDIS6_CM/kernel/ipoib_port.cpp                (revision 7290)
+++ ulp/ipoib_NDIS6_CM/kernel/ipoib_port.cpp             (working copy)
@@ -441,7 +441,7 @@
                                                               p_ip_hdr->svc_type,
                                                               cl_ntoh16( p_ip_hdr->length ),
                                                               cl_ntoh16( p_ip_hdr->id ),
-                                                              cl_ntoh16( p_ip_hdr->offset ),
+                                                             cl_ntoh16( p_ip_hdr->offset_flags ),
                                                               p_ip_hdr->ttl,
                                                               p_ip_hdr->prot,
                                                               cl_ntoh16( p_ip_hdr->chksum ),
@@ -2821,7 +2821,7 @@
                                                               break;
                                               }

-                                              if( p_ipoib->type.ip.hdr.offset ||
+                                             if( (cl_ntoh16(p_ipoib->type.ip.hdr.offset_flags) & OFFSET_MASK) ||
                                                                p_ipoib->type.ip.hdr.prot != IP_PROT_UDP )
                                               {
                                                               /* Unfiltered.    Setup the ethernet header and report. */
@@ -5102,7 +5102,7 @@
               PERF_DECLARE( FilterDhcp );
               IPOIB_ENTER( IPOIB_DBG_SEND );

-              if ( (ethertype == ETH_PROT_TYPE_IP) && ((ip_hdr_t*)p_ip_hdr)->offset > 0 )
+             if ( (ethertype == ETH_PROT_TYPE_IP) && (cl_ntoh16(((ip_hdr_t*)p_ip_hdr)->offset_flags) & OFFSET_MASK) > 0 )
               {
                               /* This is a fragmented part of UDP packet
                                * Only first packet will contain UDP header in such case
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20111003/570457a9/attachment.html>


More information about the ofw mailing list