]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/commitdiff
Support IPSEC AH mode, additional cleanup
authorTinku Mannan <tmannan@ti.com>
Tue, 8 Jan 2013 19:44:21 +0000 (14:44 -0500)
committerTinku Mannan <tmannan@ti.com>
Tue, 8 Jan 2013 19:44:21 +0000 (14:44 -0500)
ti/runtime/netapi/src/netapi_sec.c
ti/runtime/netapi/test/mt_test.c
ti/runtime/netapi/test/net_test.c
ti/runtime/netapi/test/net_test.h

index 7574bb8b47018f415c5f724ea401a7e0377743f6..c43d68584bc2ab7821a0dd75c7d7b96c7ea6fe36 100755 (executable)
@@ -93,7 +93,7 @@ NETCP_CFG_SA_T netapi_secAddSA(NETAPI_T h, //the  netapi handle
         {0}
     };
    void * mac_handle = netcp_cfgp_get_mac_handle(&netapi_get_global()->nwal_context,iface_no);
-
+    int  coreid = Osal_nwalGetProcId();
     *perr =0;
     if ((!n) || (!sa_info)  ||  (!p_data_mode_handle) ) {*perr = NETAPI_ERR_BAD_INPUT; return -1;}
 
@@ -101,7 +101,7 @@ NETCP_CFG_SA_T netapi_secAddSA(NETAPI_T h, //the  netapi handle
     tunnelId = netcp_cfgp_find_sa_slot(&netapi_get_global()->nwal_context,
                            iface_no);
 
-    printf("netapi_secAddSA called for tunnelId %d\n", tunnelId);
+    printf("coreid: %d, netapi_secAddSA called for tunnelId %d\n", coreid, tunnelId);
     if (tunnelId <0) {*perr= NETAPI_ERR_NOMEM;  return -1; }
     appId |=  (tunnelId<<8);
 
@@ -170,8 +170,8 @@ NETCP_CFG_SA_T netapi_secAddSA(NETAPI_T h, //the  netapi handle
         else if(retValue !=  nwal_OK)
         {
             *perr = NETAPI_ERR_NWAL_ERR0;
-            printf ("netapi_secAddSA: ERROR: nwal_setSecAssoc returned Error Code %d\n",
-                        retValue);
+            printf ("coreid: %d, netapi_secAddSA: ERROR: nwal_setSecAssoc returned Error Code %d\n",
+                        coreid, retValue);
             netapip_FreeTransInfo(pTransInfo);
             netcp_cfgp_delete_sa(&netapi_get_global()->nwal_context,tunnelId);
             return -1;
@@ -203,7 +203,7 @@ NETCP_CFG_SA_T netapi_secAddSA(NETAPI_T h, //the  netapi handle
                 return -1;
             }
         }
-        printf ("netapi_secAddSA: SA %d added to mac %d\n", tunnelId, iface_no);
+        printf ("coreid: %d, netapi_secAddSA: SA %d added to mac %d\n", coreid, tunnelId, iface_no);
 
         *p_inflow_mode_handle=pTransInfo->handle;
         netapip_FreeTransInfo(pTransInfo);
index 71ada420181fe5411417d512848c1138335cbc5d..6a550d27524c4105ff1891e34ecdfcd5815194c4 100755 (executable)
@@ -837,6 +837,8 @@ static uint8_t ourEncrKey[36] =
          0x30, 0x31, 0x32, 0x33 }; 
 
 
+ hplib_atomic32_T  spi = hplib_mAtomic32Init(0x11111111);
+
 /*************************END NETAPI OBJECTS***********************/
 
 #define START_SRC_IP 0x0a00000a
@@ -912,11 +914,14 @@ void house(NETAPI_SCHED_HANDLE_T * s)
 
 void  build_sa_db(int i)
 {
+    int coreid = Osal_nwalGetProcId();
     long tmp_spi;
-    static uint32_t spi = 11111111;
+    //static uint32_t spi = 11111111;
     if ((tx_sa[0].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[0].cipherMode == NWAL_SA_EALG_AES_CBC))
     {
-        tx_sa[0].spi = rx_sa[0].spi =spi++;
+        
+        tx_sa[0].spi = rx_sa[0].spi = hplib_mAtomic32AddReturn(&spi,1);
+        printf("coreid: %d, build_sa_db: spi %d\n", coreid, spi);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -958,7 +963,7 @@ void  build_sa_db(int i)
     }
     else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
     {
-        tx_sa[i].spi = rx_sa[i].spi =spi++;
+        tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -1001,7 +1006,7 @@ void  build_sa_db(int i)
     }
     else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
     {
       tx_sa[i].spi = rx_sa[i].spi =spi++;
tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -1042,7 +1047,7 @@ void  build_sa_db(int i)
     }
     else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
     {
-        tx_sa[i].spi = rx_sa[i].spi =spi++;
+  tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -1084,7 +1089,7 @@ void  build_sa_db(int i)
     }
     else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
     {
       tx_sa[i].spi = rx_sa[i].spi =spi++;
tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -1129,7 +1134,7 @@ void  build_sa_db(int i)
     }
     else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
     {
       tx_sa[i].spi = rx_sa[i].spi =spi++;
tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -1172,7 +1177,7 @@ void  build_sa_db(int i)
     }
     else if ((tx_sa[i].authMode == NWAL_SA_AALG_AES_XCBC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
     {
       tx_sa[i].spi = rx_sa[i].spi =spi++;
tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
         /* static configuration, will not change */
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
@@ -1366,6 +1371,7 @@ sleep(1);
             &err);
         //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
          if (err) {printf("addRxSa failed %d\n",err);}
+          sched_yield();
 
 
     }
@@ -1390,6 +1396,7 @@ sleep(1);
                 &(sa_info[i].tx_inflow_mode_handle),
                 &err);
     if (err) {printf("addTxSa failed %d\n",err); exit(1);}
+     sched_yield();
     }
 sleep(1);
 count = 0;
@@ -1555,7 +1562,7 @@ sleep(1);
             &err);
         //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
          if (err) {printf("addRxSa failed %d\n",err);}
-
+          sched_yield();
 
     }
     count = 0;
@@ -1579,11 +1586,12 @@ sleep(1);
                 &(sa_info[i].tx_inflow_mode_handle),
                 &err);
     if (err) {printf("addTxSa failed %d\n",err); exit(1);}
+     sched_yield();
     }
 
 sleep(1);
         count = 0;
-//#ifdef TEST_SA
+
         for (i = 32; i < SA_CREATE_LOOP_COUNT-1;i++)
         {
                 if (rx_policy[i])
index 33208dddeb9a17f29067f96793381b3d2ae61b76..f1bbf324b3eeffbfb8f7b79c07eedbda0ba3ee69 100755 (executable)
 
  *****************************************/
 #define DAL_REVIEW
-//#define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
+#define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
 #define NWAL_ENABLE_SA
 #endif
+#define AH_SUPPORT
 
 //define this for multi-thread
 #define MULTI_THREAD
@@ -287,6 +288,13 @@ long htonl(long x)
        return temp;
 }
 
+
+unsigned long peek(unsigned long * p)
+{
+  return *p;
+}
+
+
 /********************************************************************
  *  FUNCTION PURPOSE: Ones complement addition utility
  ********************************************************************
@@ -489,7 +497,7 @@ NETAPI_SEC_SA_INFO_T rx_sa [7] = {
 {
     NWAL_SA_DIR_INBOUND,
     0x11111111,  //spi
-    nwal_IpSecProtoESP, //ESP mode
+    nwal_IpSecProtoAH, //ESP mode
     nwal_SA_MODE_TUNNEL,  //tunnel mode
     nwal_IPV4, //v4
     { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
@@ -528,7 +536,7 @@ NETAPI_SEC_SA_INFO_T rx_sa [7] = {
 {
     NWAL_SA_DIR_INBOUND,
     0x44444444,  //spi
-    nwal_IpSecProtoESP, //ESP mode
+    nwal_IpSecProtoAH, //ESP mode
     nwal_SA_MODE_TUNNEL,  //tunnel mode
     nwal_IPV4, //v4
     { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (them) -> set below */
@@ -584,7 +592,7 @@ NETAPI_SEC_SA_INFO_T tx_sa[7]= {
 {
     NWAL_SA_DIR_OUTBOUND,
     0x11111111,  //spi
-    nwal_IpSecProtoESP, //ESP mode
+    nwal_IpSecProtoAH, //ESP mode
     nwal_SA_MODE_TUNNEL,  //tunnel mode
     nwal_IPV4, //v4
     { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
@@ -623,7 +631,7 @@ NETAPI_SEC_SA_INFO_T tx_sa[7]= {
 {
     NWAL_SA_DIR_OUTBOUND,
     0x44444444,  //spi
-    nwal_IpSecProtoESP, //ESP mode
+    nwal_IpSecProtoAH, //ESP mode
     nwal_SA_MODE_TUNNEL,  //tunnel mode
     nwal_IPV4, //v4
     { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  /* Src IP (us) -> set below */
@@ -1109,7 +1117,7 @@ static int eof=0;
  *--------------------back to source----------------------------
  *                   flag=1 => ipsec
  *--------------------------------------------------------------*/
-void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag)
+void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag, uint16_t enet_port)
 {
     unsigned char mac_temp[6];
     unsigned char ip_temp[4];
@@ -1122,6 +1130,12 @@ void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag)
     uint8_t p_iv[16];
     uint8_t p_add[8];
     Cppi_HostDesc*          pPloadDesc;
+    uint8_t ah_len;
+#ifdef AH_SUPPORT
+    HEAD_T * p_head;
+    HEAD_T temp_head;
+    int pkt_type;
+#endif
 
 #ifdef MULTI_THREAD
     int coreid=Osal_nwalGetProcId(); //who we are(thread local)
@@ -1142,7 +1156,9 @@ int coreid=0;
     memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
     memcpy(&p_pkt[14+12+4],&ip_temp,4);
 
+#ifdef AH_SUPPORT
+    p_head=&temp_head;
+#endif
     //outer checksum to 0
     if (!flag) 
     {
@@ -1152,7 +1168,26 @@ int coreid=0;
     //inner ip &udp for ipsec
     if (flag) 
     {
-        p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
+#ifdef AH_SUPPORT
+        memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
+
+        if ((p_head->ip[2]&0x0000ff00)==0x00003300)
+        {
+            p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN + 4]);
+            pkt_type = IPSEC_AH_PKT;
+            printf("flip_and_send_pkt: IPSEC AH packet received\n");
+        }
+        else if ((p_head->ip[2]&0x0000ff00)==0x00003200)
+        {
+            p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
+            pkt_type = IPSEC_ESP_PKT;
+
+            printf("flip_and_send_pkt: IPSEC ESP packet received\n");
+
+        }
+#endif
+
+        //p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN + 4]);
         p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
         if (p_sa_info == NULL)
         {
@@ -1166,10 +1201,10 @@ int coreid=0;
         }
 
         /* flip inner IP */
+        printf("flip_and_send_pkt: encOffSet %d\n", p_sa_info->tx_payload_info.encOffset);
         memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
-
         /* setting udp ports */
         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
         memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
@@ -1254,7 +1289,6 @@ int coreid=0;
             meta_tx.appCtxId = (nwal_AppId)hplib_mUtilGetPmuCCNT();
             meta.u.tx_sb_meta=&meta_tx;
 
-#ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
             /* Use the command label which was cached during create time
             * Update the Queue to receive output packet from SA to the local 
             * core Queue. Below information can be saved by application in 
@@ -1286,85 +1320,99 @@ int coreid=0;
                                        pPloadDesc,
                                        NWAL_DESC_SIZE);
 
-#else
-            //printf("flip_and_send_pkt(): sending for encryption\n");
-           pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
-#endif
-       }
-else
- {
-  //INFLOW TX *******************
-  //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
-           PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
-           int err;
-           nwalTxPktInfo_t meta_tx={0};
+        }
+        else
+        {
+            //INFLOW TX *******************
+            //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
+            PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
+            int err;
+            nwalTxPktInfo_t meta_tx={0};
 #define USE_COPY
 #ifdef USE_COPY
 //debug:  see if re-using RX descriptor for TX is causing our SA lockup
-{
-  int new_len=0;
-  Ti_Pkt new_tip =  get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0]   , len);
-  if (!new_tip)
-  {
-     printf("net_test> new_tip NULL\n");
-  }
-  else
-  {
-    Pktlib_setPacketLen(new_tip,new_len);
-    Pktlib_freePacket(tip);
-    tip=new_tip;  
-    Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len);  //reset p_pkt to point to new buffer as its used below
-    Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats[coreid].sec_tx); 
-  }
-}
-if (len <1500)  
-{
-  eof+=1;
-}
+            {
+            int new_len=0;
+            Ti_Pkt new_tip =  get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0]   , len);
+            if (!new_tip)
+            {
+                printf("net_test> new_tip NULL\n");
+            }
+            else
+            {
+                Pktlib_setPacketLen(new_tip,new_len);
+                Pktlib_freePacket(tip);
+                tip=new_tip;  
+                Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len);  //reset p_pkt to point to new buffer as its used below
+//                Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats[coreid].sec_tx); 
+            }
+            }
+            if (len <1500)  
+            {
+                eof+=1;
+            }
 #endif
-           meta.sa_handle=p_sa_info->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
-           //meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_META_DATA_VALID );
-           meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
-           meta_tx.enetPort=0;
 
-           meta_tx.saOffBytes=  p_sa_info->tx_pkt_info.saOffBytes;
-           meta_tx.saPayloadLen=len-14-20;   //don't include tag, mac and outer header
-           meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
-           meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset; 
-           meta_tx.l4OffBytes = p_sa_info->tx_pkt_info.l4OffBytes;
-           meta_tx.l4HdrLen = p_sa_info->tx_pkt_info.l4HdrLen;
-           meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
-           meta_tx.pseudoHdrChecksum =
-             test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
+            meta.sa_handle=p_sa_info->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
+            meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
+            meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset; 
+            meta_tx.l4OffBytes = p_sa_info->tx_pkt_info.l4OffBytes;
+            meta_tx.l4HdrLen = p_sa_info->tx_pkt_info.l4HdrLen;
+            meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
+            meta_tx.saOffBytes=  p_sa_info->tx_pkt_info.saOffBytes;
+            if (pkt_type == IPSEC_AH_PKT)
+            {
+                 memset(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+netTest_IPSEC_AH_FIXED_HDR_SIZE],0,netTest_IPSEC_AH_FIXED_HDR_SIZE);
+                meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
+                meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN;   //don't inlcude mac 
+                meta_tx.saAhMacSize = 12;
+                meta_tx.saAhIcvOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE;
+                meta_tx.enetPort = enet_port;
+            }
+            else if (pkt_type == IPSEC_ESP_PKT)
+            {
+                meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
+                meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN-netTest_IP_HEADER_LEN;   //don't include mac and ip outer header
+                meta_tx.enetPort = 0;
+            }
+            else
+            {
+                printf("flip_and_send_pkt: invalid ESP protocol\n");
+                return;
+            }
 
-           /* post it to netcp tx channel*/
-           meta.u.tx_meta=&meta_tx;
-           if (stats[coreid].sec_tx<20) dump_descr((long *) tip, stats[coreid].sec_tx);
-           pktio_send(netcp_tx_chan,tip,&meta,&err);
-           stats[coreid].tx +=1;
-           stats[coreid].sec_tx +=1;
-     }
-}
-else  //non ipsec send pkt directly, asking for IP and UDP checksum ofload
-{
-           PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
-           int err;
-           nwalTxPktInfo_t meta_tx2={0};
-           meta2.sa_handle=nwal_HANDLE_INVALID;
-           meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
-           meta_tx2.startOffset = 0;
-           meta_tx2.ipOffBytes = 14;
-           meta_tx2.l4OffBytes = 14+20;
-           meta_tx2.l4HdrLen = 8;
-           meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
-           meta_tx2.pseudoHdrChecksum =
-             test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
+            meta_tx.pseudoHdrChecksum =
+            test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
 
-           /* post it to netcp tx channel*/
-           meta2.u.tx_meta=&meta_tx2;
-           pktio_send(netcp_tx_chan,tip,&meta2,&err);
-           stats[coreid].tx +=1;
-}
+
+            /* post it to netcp tx channel*/
+            meta.u.tx_meta=&meta_tx;
+            if (stats[coreid].sec_tx<20) dump_descr((long *) tip, stats[coreid].sec_tx);
+            pktio_send(netcp_tx_chan,tip,&meta,&err);
+            stats[coreid].tx +=1;
+            stats[coreid].sec_tx +=1;
+        }
+    }
+    else  //non ipsec send pkt directly, asking for IP and UDP checksum ofload
+    {
+        PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
+        int err;
+        nwalTxPktInfo_t meta_tx2={0};
+        meta2.sa_handle=nwal_HANDLE_INVALID;
+        meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
+        meta_tx2.startOffset = 0;
+        meta_tx2.ipOffBytes = 14;
+        meta_tx2.l4OffBytes = 14+20;
+        meta_tx2.l4HdrLen = 8;
+        meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
+        meta_tx2.pseudoHdrChecksum =
+        test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
+
+        /* post it to netcp tx channel*/
+        meta2.u.tx_meta=&meta_tx2;
+        pktio_send(netcp_tx_chan,tip,&meta2,&err);
+        stats[coreid].tx +=1;
+    }
 }
 
 
@@ -1471,7 +1519,7 @@ unsigned long time, delta_time;
            tag_cmp = memcmp(&p_pkt[len-p_sa_info->auth_tag_size],(char*) &hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
            stats[coreid].n_auth_ok += !(tag_cmp);
            
-            flip_and_send_pkt(tip, p_pkt, len,1);  //flip packet to echo back and send
+            flip_and_send_pkt(tip, p_pkt, len,1, 0);  //flip packet to echo back and send
         }
         //this is an encrypt (tx tunnel) complete
         else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
@@ -1559,11 +1607,13 @@ void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
 
     Cppi_HostDesc*          pPloadDesc;
     int ifno;
+    uint16_t enet_port = 0;
+
 #ifdef MULTI_THREAD
     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
     //int coreid = our_core;
 #else
-int coreid=0;
+    int coreid=0;
 #endif
     p_head=&temp_head;
 
@@ -1571,6 +1621,7 @@ int coreid=0;
     for(i=0;i<n_pkts;i++)
     {
         ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
+        enet_port = meta[i].u.rx_meta->enetPort;
         tip = p_recv[i];
         
         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
@@ -1613,8 +1664,8 @@ int coreid=0;
         /* check header */
         memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
 
-        /* check for IPSEC packet, 0x32 is ESP tunnel mode */
-        if ((p_head->ip[2]&0x0000ff00)==0x00003200)
+        /* check for IPSEC ESP or AH packet, 0x32 is ESP tunnel mode, 0x33 is AH tunnel mode*/
+       if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
         {
             if (!check_header(p_head,&meta[i]))
             {
@@ -1736,7 +1787,7 @@ int coreid=0;
         else
         {
             //inflow mode.  flip and send
-            flip_and_send_pkt(tip,p_pkt,len,1);
+            flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
         }
     }
     else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
@@ -1770,7 +1821,7 @@ int coreid=0;
         send_pkt(tip,len);
 #endif
              //just flip and send
-            flip_and_send_pkt(tip,p_pkt,len,0);
+            flip_and_send_pkt(tip,p_pkt,len,0, enet_port);
         }
     }
     //printf("recv done\n");
@@ -2439,12 +2490,14 @@ void  build_sa_db(int i)
         sa_info[i].tx_payload_info.aadSize = 0;
         sa_info[i].tx_payload_info.pAad = NULL;
         sa_info[i].tx_payload_info.pAuthIV = NULL;
-        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;        /*done: same for all cipher suites */
+        //sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN + 24;        /*done: same for all cipher suites */
+        sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN;
 
         sa_info[i].tx_payload_info.encOffset =         netTest_MAC_HEADER_LEN +
                                                                      netTest_IP_HEADER_LEN +
-                                                                    netTest_ESP_HEADER_LEN +
-                                                                    netTest_NULL_IV_LEN;
+                                                                    netTest_NULL_ESP_HEADER_LEN +
+                                                                    netTest_NULL_IV_LEN +
+                                                                    24;
 
         
 #ifdef EXPERIMENTAL
@@ -2474,11 +2527,10 @@ void  build_sa_db(int i)
         sa_info[i].tx_pkt_info.lpbackPass = 0;
         sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
         sa_info[i].tx_pkt_info.pPkt = NULL;
-        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN;
+        sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN;
         sa_info[i].tx_pkt_info.saPayloadLen = 0;
         sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
-       
-        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
+        sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID ;
         tmp_spi = htonl((long)(tx_sa[i].spi));
          trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
     }
index b997b815a7e4bf1875c92b6397fd1649e01a8bad..3148dcd6327ff59eda36a25e68f41dff834458c1 100755 (executable)
 #define netTest_AES_GCM_CCM_ICV_LEN     16
 #define netTest_AES_GMAC_ICV_LEN     16
 
+#define IPSEC_AH_PKT    1
+#define IPSEC_ESP_PKT   2
+
+
+#define netTest_IPSEC_AH_FIXED_HDR_SIZE 12
+
+
+#define netTest_NULL_ESP_HEADER_LEN 0
 
 /* The input strings for the input config file is given below */
 #define INIT_CONFIG_MAC0            "mac0"
@@ -212,4 +220,6 @@ typedef struct key_t
   short dst_port;
 } KEY_T;
 
+#define IPSEC_AH_PKT 1
+#define  IPSEC_ESP_PKT 2