]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blobdiff - ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c
Added IPV6 and bridge interface support
[keystone-rtos/netapi.git] / ti / runtime / netapi / applications / ipsec_offload / ipsecmgr / src / netapilib_interface.c
index bf1b8d6715fa9af2094f1e9f54bedc94f92b6dcf..73a196c190f26118e2b678941c5ddf28a52b812a 100755 (executable)
@@ -54,16 +54,30 @@ int compareIPAddr(unsigned char* ip1, unsigned char* ip2, int ip_type)
 {
     int found = 1;
     int i;
-    for (i = 0; i<4; i++)
+    if (ip_type == nwal_IPV4)
     {
-        if (ip1[i] != ip2[i])
+        for (i = 0; i < NWAL_IPV4_ADDR_SIZE; i++)
         {
-        found = 0;
-        break;
+            if (ip1[i] != ip2[i])
+            {
+                found = 0;
+                break;
+            }
         }
-    
+        return found;
+    }
+    else
+    {
+        for (i = 0; i < NWAL_IPV6_ADDR_SIZE; i++)
+        {
+            if (ip1[i] != ip2[i])
+            {
+                found = 0;
+                break;
+            }
+        }
+        return found;
     }
-    return found;
 }
 /**************************************************************************
  * FUNCTION PURPOSE:  Internal function to find a free slot to store APPID
@@ -145,15 +159,13 @@ int netapilib_ifAddSA
     memset((void *)&route, 0, sizeof (NETCP_CFG_ROUTE_T));
     memset((void *)&flow, 0, sizeof (NETCP_CFG_FLOW_T));
 
-
-
     /* Initialize the SA Config structure. */
     /* Get the IP protocol version. */
     if (af == IPSECMGR_AF_IPV4)
     {
         saInfo.ipType = nwal_IPV4;
         /* Populate the source and destination IP addresses. */
-        for (index = 0; index < 4; index++)
+        for (index = 0; index < NWAL_IPV4_ADDR_SIZE; index++)
         {
             saInfo.dst.ipv4[index] = sa_id->daddr.ipv4[index];
             saInfo.src.ipv4[index] = sa_info->saddr.ipv4[index];
@@ -164,7 +176,7 @@ int netapilib_ifAddSA
         saInfo.ipType = nwal_IPV6;
 
         /* Populate the source and destination IP addresses. */
-        for (index = 0; index < 16; index++)
+        for (index = 0; index < NWAL_IPV6_ADDR_SIZE; index++)
         {
             saInfo.dst.ipv6[index] = sa_id->daddr.ipv6[index];
             saInfo.src.ipv6[index] = sa_info->saddr.ipv6[index];
@@ -195,25 +207,46 @@ int netapilib_ifAddSA
         {
             /* get interface for destination ip address */
             if (compareIPAddr(&ipConfigList[i].ip[0], 
-                              &saInfo.dst.ipv4[0],
+                              saInfo.ipType == nwal_IPV4 ?
+                              &saInfo.dst.ipv4[0]:
+                              &saInfo.dst.ipv6[0],
                               saInfo.ipType))
             {
                 pTok = strtok(ipConfigList[i].name, ":.");
                 /* now we have the interface name, is this eth0 or eth1 */
                 if (pTok)
-                /* now we have eth0 or eth1, now find the i/f number */
-                    sscanf(pTok,"eth%d", &iface);
-                
+                {
+                    /* now we have interface name, now find the i/f number */
+                    if(strstr(pTok,"eth"))
+                    {
+                        sscanf(pTok,"eth%d", &iface);
+                    }
+                    else if(strstr(pTok,"br"))
+                    {
+                        sscanf(pTok,"br%d", &iface);
+                    }
+                    else
+                    {
+                        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                        "netapilib_ifAddSA: invalid interface\n");
+                        return -1;
+                    }
+                }
                 globalDB.rx_sa[slot].iface = iface;
                 flow.dma_engine= 1;
                 flow.flowid = globalDB.flowId[iface];
+                printf("add_sa: iface: %d, flowid: %d\n",
+                    iface,
+                    flow.flowid);
+
                 route.p_flow = &flow;
                 route.p_dest_q = globalDB.pktio_channel[iface];
+                printf("add_sa: p_dest_q: 0x%x, flowId: 0x%x\n",
+                route.p_dest_q, route.p_flow->flowid);
+                printf("add_sa: pktio_handle: 0x%x\n", globalDB.pktio_channel[iface]);
                 break;
-                
             }
         }
-        
     }
     else if (sa_info->dir == DIR_OUTBOUND)
     {
@@ -445,6 +478,7 @@ int32_t netapilib_ifAddSP
 )
 {
 #ifdef ENABLE_ADD_POLICY
+#warning "ENABLE_ADD_POLICY"
     NETCP_CFG_IPSEC_POLICY_T spAppIdIn;
     int error, index, slot;
     nwal_IpType ipType;
@@ -487,7 +521,7 @@ int32_t netapilib_ifAddSP
     {
         ipType = nwal_IPV4;
         /* Populate the source and destination IP addresses. */
-        for (index = 0; index < 4; index++)
+        for (index = 0; index < NWAL_IPV4_ADDR_SIZE; index++)
         {
             dst_ip_addr.ipv4[index] = sel->daddr.ipv4[index];
             src_ip_addr.ipv4[index] = sel->saddr.ipv4[index];
@@ -497,7 +531,7 @@ int32_t netapilib_ifAddSP
     { 
         ipType = nwal_IPV6;
         /* Populate the source and destination IP addresses. */
-        for (index = 0; index < 16; index++)
+        for (index = 0; index < NWAL_IPV6_ADDR_SIZE; index++)
         {
             dst_ip_addr.ipv6[index] = sel->daddr.ipv6[index];
             src_ip_addr.ipv6[index] = sel->saddr.ipv6[index];