[ofw][patch] fixes client id insertion

Anatoly Greenblatt anatolyg at voltaire.com
Wed Jun 25 07:13:08 PDT 2008


 <<fix_client_id_insertion.patch>> Hi,

The client id inserted in dhcp packets w/o updating lengths in udp and
ip headers. As a result in some cases the dhcp packet was not accepted
by dhcp server ("parameter is larger than buffer" error).

The fix updates length in udp and ip header and calculate ip header
checksum if needed. Also fixes incorrect return code.

Best regards,
Anatoly

Index: ipoib_port.c
===================================================================
--- ipoib_port.c	(revision 1295)
+++ ipoib_port.c	(working copy)
@@ -3216,6 +3216,19 @@
 }
 
 
+unsigned short ipchksum(unsigned short *ip, int len)
+{
+    unsigned long sum = 0;
+
+    len >>= 1;
+    while (len--) {
+        sum += *(ip++);
+        if (sum > 0xFFFF)
+            sum -= 0xFFFF;
+    }
+    return (unsigned short)((~sum) & 0x0000FFFF);
+}
+
 static NDIS_STATUS
 __send_mgr_filter_dhcp(
 	IN				ipoib_port_t* const
p_port,
@@ -3317,7 +3330,7 @@
 				{
 					IPOIB_PRINT_EXIT(
TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,
 						("Can't convert CID to
IPoIB format.\n") );
-					return IB_INSUFFICIENT_MEMORY;
+					return NDIS_STATUS_RESOURCES;
 				}
 				/* Move the existing options down, and
add a new CID option */
 				len = p_option - ( p_cid + p_cid[1] + 2
);
@@ -3357,10 +3370,21 @@
 
 		CL_ASSERT( p_cid[1] == 21 );
 		p_cid[23]= DHCP_OPT_END;
-		ib_gid_set_default( &gid,
p_port->p_adapter->guids.port_guid.guid );
+		ib_gid_set_default( &gid,
p_port->p_adapter->guids.port_guid );
 		cl_memcpy( &p_cid[7], &gid, sizeof(ib_gid_t) );
 		cl_memcpy( &p_cid[3], &p_port->ib_mgr.qpn,
sizeof(p_port->ib_mgr.qpn) );		
 		p_ib_dhcp->htype = DHCP_HW_TYPE_IB;
+
+		/* update lengths to include any change we made */
+		p_desc->p_buf->ip.hdr.length = cl_ntoh16(
sizeof(ip_hdr_t) + sizeof(udp_hdr_t) + sizeof(dhcp_pkt_t) );
+		p_desc->p_buf->ip.prot.udp.hdr.length = cl_ntoh16(
sizeof(udp_hdr_t) + sizeof(dhcp_pkt_t) );
+
+		/* update crc in ip header */
+		if( !p_port->p_adapter->params.send_chksum_offload )
+		{
+			p_desc->p_buf->ip.hdr.chksum = 0;
+			p_desc->p_buf->ip.hdr.chksum =
ipchksum((unsigned short*) &p_desc->p_buf->ip.hdr, sizeof(ip_hdr_t));
+		}
 		break;
 
 	/* Server messages. */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_client_id_insertion.patch
Type: application/octet-stream
Size: 1857 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20080625/0927832b/attachment.obj>


More information about the ofw mailing list