← Back to team overview

rohc team mailing list archive

Support of ESP (Profil 0x0003)

 

 Hello all,

To complete the RoHC library, I add code to support profile 0x0003 (ESP: Encapsulating Security Payload) in the current trunk.

The special case when the NULL encryption algorithm is used, is not supported in this version.

Attached are a patch file for the existing source files, and an archive file for the new ones.

 Non-regression tests are ok.

 Best regards,

                  FWX.
=== modified file 'src/common/crc.c'
--- old/src/common/crc.c	2011-11-27 12:16:55 +0000
+++ new/src/common/crc.c	2011-12-22 11:50:12 +0000
@@ -24,6 +24,7 @@
 
 #include "crc.h"
 #include "rohc.h"
+#include "esp.h"  //FWX
 #include "rtp.h"
 
 #include <netinet/udp.h>
@@ -502,6 +503,98 @@
 }
 
 
+// Begin FWX
+
+/**
+ * @brief Compute the CRC-STATIC part of an ESP header
+ *
+ * Concerned fields are:
+ *  all fields expect those for CRC-DYNAMIC
+ *    - bytes 1-4 in original ESP header
+ * 
+ * @param ip          The outer IP packet
+ * @param ip2         The inner IP packet if there is 2 IP headers, NULL otherwise
+ * @param next_header The next header located after the IP header(s)
+ * @param crc_type    The type of CRC
+ * @param init_val    The initial CRC value
+ * @param crc_table   The pre-computed table for fast CRC computation
+ * @return            The checksum
+ */
+unsigned int esp_compute_crc_static(const unsigned char *const ip,
+                                    const unsigned char *const ip2,
+                                    const unsigned char *const next_header,
+                                    const unsigned int crc_type,
+                                    const unsigned int init_val,
+                                    const unsigned char *const crc_table)
+{
+	unsigned int crc;
+	struct esphdr *esp;
+
+	assert(ip != NULL);
+	assert(next_header != NULL);
+	assert(crc_table != NULL);
+
+	crc = init_val;
+
+	/* compute the CRC-STATIC value for IP and IP2 headers */
+	crc = compute_crc_static(ip, ip2, next_header, crc_type, crc, crc_table);
+
+	/* get the start of ESP header */
+	esp = (struct esphdr *) next_header;
+
+	/* bytes 1-4 (Security parameters index) */
+	crc = crc_calculate(crc_type, (unsigned char *)(&esp->security_parameters_index), 4,
+	                    crc, crc_table);
+
+	return crc;
+}
+
+
+/**
+ * @brief Compute the CRC-DYNAMIC part of an ESP header
+ *
+ * Concerned fields are:
+ *   - bytes 5-8 in original ESP header
+ * 
+ * @param ip          The outer IP packet
+ * @param ip2         The inner IP packet if there is 2 IP headers, NULL otherwise
+ * @param next_header The next header located after the IP header(s)
+ * @param crc_type    The type of CRC
+ * @param init_val    The initial CRC value
+ * @param crc_table   The pre-computed table for fast CRC computation
+ * @return            The checksum
+ */
+unsigned int esp_compute_crc_dynamic(const unsigned char *const ip,
+                                     const unsigned char *const ip2,
+                                     const unsigned char *const next_header,
+                                     const unsigned int crc_type,
+                                     const unsigned int init_val,
+                                     const unsigned char *const crc_table)
+{
+	unsigned int crc;
+	struct esphdr *esp;
+
+	assert(ip != NULL);
+	assert(next_header != NULL);
+	assert(crc_table != NULL);
+
+	crc = init_val;
+
+	/* compute the CRC-DYNAMIC value for IP and IP2 headers */
+	crc = compute_crc_dynamic(ip, ip2, next_header, crc_type, crc, crc_table);
+
+	/* get the start of ESP header */
+	esp = (struct esphdr *) next_header;
+
+	/* bytes 5-8 (Sequence number) */
+	crc = crc_calculate(crc_type, (unsigned char *)(&esp->sequence_number), 4,
+	                    crc, crc_table);
+
+	return crc;
+}
+
+// End FWX
+
 /**
  * @brief Compute the CRC-STATIC part of a RTP header
  *

=== modified file 'src/common/crc.h'
--- old/src/common/crc.h	2011-11-26 14:10:43 +0000
+++ new/src/common/crc.h	2011-12-22 12:13:16 +0000
@@ -85,6 +85,23 @@
                                      const unsigned char *const crc_table)
 	__attribute__((nonnull(1, 3, 6)));
 
+// Begin FWX
+unsigned int esp_compute_crc_static(const unsigned char *const ip,
+                                    const unsigned char *const ip2,
+                                    const unsigned char *const next_header,
+                                    const unsigned int crc_type,
+                                    const unsigned int init_val,
+                                    const unsigned char *const crc_table)
+	__attribute__((nonnull(1, 3, 6)));
+unsigned int esp_compute_crc_dynamic(const unsigned char *const ip,
+                                     const unsigned char *const ip2,
+                                     const unsigned char *const next_header,
+                                     const unsigned int crc_type,
+                                     const unsigned int init_val,
+                                     const unsigned char *const crc_table)
+	__attribute__((nonnull(1, 3, 6)));
+// End FWX
+
 unsigned int rtp_compute_crc_static(const unsigned char *const ip,
                                     const unsigned char *const ip2,
                                     const unsigned char *const next_header,

=== modified file 'src/common/rohc.h'
--- old/src/common/rohc.h	2011-11-29 21:07:40 +0000
+++ new/src/common/rohc.h	2011-12-22 11:51:01 +0000
@@ -464,6 +464,8 @@
 #define ROHC_PROFILE_RTP           0x0001
 /// The number allocated for the ROHC UDP profile
 #define ROHC_PROFILE_UDP           0x0002
+/// The number allocated for the ROHC ESP profile
+#define ROHC_PROFILE_ESP           0x0003  // FWX
 /// The number allocated for the ROHC IP-only profile (see 5 in the RFC 3843)
 #define ROHC_PROFILE_IP            0x0004
 /// The number allocated for the ROHC UDP-Lite profile (see 7 in the RFC 4019)

=== modified file 'src/comp/Makefile.am'
--- old/src/comp/Makefile.am	2011-11-26 13:30:57 +0000
+++ new/src/comp/Makefile.am	2011-12-22 11:58:33 +0000
@@ -13,6 +13,7 @@
 	c_ip.c \
 	c_udp.c \
 	c_udp_lite.c \
+	c_esp.c \
 	c_rtp.c
 
 INCLUDES = \
@@ -29,5 +30,6 @@
 	c_ip.h \
 	c_udp.h \
 	c_udp_lite.h \
+	c_esp.h \
 	c_rtp.h
 

=== modified file 'src/comp/c_generic.c'
--- old/src/comp/c_generic.c	2011-12-18 17:57:02 +0000
+++ new/src/comp/c_generic.c	2011-12-22 11:55:57 +0000
@@ -551,6 +551,7 @@
 			break;
 		case ROHC_PROFILE_UNCOMPRESSED:
 		case ROHC_PROFILE_UDP:
+		case ROHC_PROFILE_ESP: // FWX
 		case ROHC_PROFILE_IP:
 		case ROHC_PROFILE_UDPLITE:
 			p = -1;
@@ -7683,6 +7684,9 @@
 				case ROHC_PROFILE_UDP:
 					total_size += 6; /* UDP part in IR packet */
 					break;
+                                case ROHC_PROFILE_ESP:
+                                        total_size += 8; /* ESP part in IR packet */  // FWX
+                                        break;
 				case ROHC_PROFILE_UDPLITE:
 					total_size += 8; /* size of UDP-lite part in IR packet */
 					break;
@@ -7737,6 +7741,8 @@
 				case ROHC_PROFILE_UDP:
 					total_size += 2; /* size of UDP part in IR packet */
 					break;
+                                case ROHC_PROFILE_ESP: // FWX
+                                        break;
 				case ROHC_PROFILE_UDPLITE:
 					total_size += 4; /* size of UDP-lite part in IR packet */
 					break;

=== modified file 'src/comp/rohc_comp.c'
--- old/src/comp/rohc_comp.c	2011-11-26 12:51:01 +0000
+++ new/src/comp/rohc_comp.c	2011-12-22 13:33:09 +0000
@@ -46,6 +46,7 @@
 extern struct c_profile c_rtp_profile,
                         c_udp_profile,
                         c_udp_lite_profile,
+                        c_esp_profile,                // FWX
                         c_ip_profile,
                         c_uncompressed_profile;
 
@@ -57,6 +58,7 @@
 	&c_rtp_profile,
 	&c_udp_profile,
 	&c_udp_lite_profile,
+	&c_esp_profile,                // FWX
 	&c_ip_profile,
 	&c_uncompressed_profile,
 };
@@ -1250,6 +1252,8 @@
 	/* test all compression profiles */
 	for(i = 0; i < C_NUM_PROFILES; i++)
 	{
+/* FWX */	rohc_debugf(3, "try profile %d '%s' (0x%04x)\n",
+			            i, c_profiles[i]->description, c_profiles[i]->id);
 		/* skip profile if the profile is not enabled */
 		if(!comp->profiles[i])
 		{

=== modified file 'src/comp/rohc_comp_internals.h'
--- old/src/comp/rohc_comp_internals.h	2011-11-26 12:51:01 +0000
+++ new/src/comp/rohc_comp_internals.h	2011-12-22 11:59:12 +0000
@@ -39,7 +39,7 @@
  */
 
 /** The number of ROHC profiles ready to be used */
-#define C_NUM_PROFILES 5
+#define C_NUM_PROFILES 6 // FWX
 
 /** The maximal number of outgoing feedbacks that can be queued */
 #define FEEDBACK_RING_SIZE 10

=== modified file 'src/decomp/Makefile.am'
--- old/src/decomp/Makefile.am	2010-06-06 17:51:59 +0000
+++ new/src/decomp/Makefile.am	2011-12-22 12:03:54 +0000
@@ -14,6 +14,7 @@
 	d_ip.c \
 	d_udp.c \
 	d_udp_lite.c \
+	d_esp.c \
 	d_rtp.c
 
 INCLUDES = \
@@ -31,5 +32,6 @@
 	d_ip.h \
 	d_udp.h \
 	d_udp_lite.h \
+	d_esp.h \
 	d_rtp.h
 

=== modified file 'src/decomp/rohc_decomp.c'
--- old/src/decomp/rohc_decomp.c	2011-11-26 18:28:24 +0000
+++ new/src/decomp/rohc_decomp.c	2011-12-22 12:10:08 +0000
@@ -43,6 +43,7 @@
                         d_udp_profile,
                         d_ip_profile,
                         d_udplite_profile,
+                        d_esp_profile,       // FWX                                           
                         d_rtp_profile;
 
 /**
@@ -54,6 +55,7 @@
 	&d_udp_profile,
 	&d_ip_profile,
 	&d_udplite_profile,
+	&d_esp_profile,                      // FWX
 	&d_rtp_profile,
 };
 
@@ -483,7 +485,7 @@
 	decomp->statistics.packets_received++;
 	rohc_debugf(1, "decompress the %d-byte packet #%u\n",
 	            isize, decomp->statistics.packets_received);
-	
+
 	ret = d_decode_header(decomp, ibuf, isize, obuf, osize, &ddata);
 	if(ddata.active == NULL &&
 	   (ret == ROHC_ERROR_PACKET_FAILED ||

=== modified file 'src/decomp/rohc_decomp.h'
--- old/src/decomp/rohc_decomp.h	2011-11-26 14:23:46 +0000
+++ new/src/decomp/rohc_decomp.h	2011-12-22 12:15:52 +0000
@@ -29,7 +29,7 @@
 #include "rohc_comp.h"
 
 /// The number of ROHC profiles ready to be used
-#define D_NUM_PROFILES 5
+#define D_NUM_PROFILES 6  // FWX
 
 
 /// ROHC decompressor states (see 4.3.2 in the RFC 3095)

=== modified file 'test/non_regression/test_non_regression.c'
--- old/test/non_regression/test_non_regression.c	2011-12-18 17:57:02 +0000
+++ new/test/non_regression/test_non_regression.c	2011-12-22 12:07:43 +0000
@@ -794,6 +794,7 @@
 	rohc_activate_profile(comp1, ROHC_PROFILE_IP);
 	rohc_activate_profile(comp1, ROHC_PROFILE_UDPLITE);
 	rohc_activate_profile(comp1, ROHC_PROFILE_RTP);
+	rohc_activate_profile(comp1, ROHC_PROFILE_ESP); // FWX
 	rohc_c_set_large_cid(comp1, use_large_cid);
 
 	/* create the compressor 2 */
@@ -813,6 +814,7 @@
 	rohc_activate_profile(comp2, ROHC_PROFILE_IP);
 	rohc_activate_profile(comp2, ROHC_PROFILE_UDPLITE);
 	rohc_activate_profile(comp2, ROHC_PROFILE_RTP);
+	rohc_activate_profile(comp2, ROHC_PROFILE_ESP); // FWX
 	rohc_c_set_large_cid(comp2, use_large_cid);
 
 	/* create the decompressor 1 */

Attachment: src_esp.tgz
Description: application/compressed-tar


Follow ups