Added IPV6 and bridge interface support DEV.NETAPI.01.00.00.09
authorTinku Mannan <tmannan@ti.com>
Thu, 19 Sep 2013 20:46:38 +0000 (16:46 -0400)
committerTinku Mannan <tmannan@ti.com>
Fri, 20 Sep 2013 17:21:07 +0000 (13:21 -0400)
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapi_ipsecmgr.c
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c
ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.h

index 6d6a3ae09e06e66c09e21ee786aeadd48043edb8..eefd5adced05d695302be7d206fd40d22f643e62 100755 (executable)
@@ -199,12 +199,10 @@ void cleanup_sa_sp()
     }
 }
 
-
 static void* snoop_run_thread (void* arg)
 {
     ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
         "snoop_run_thread: daemon entering forever event loop\n");
-
     while (1)
     {
         /* Poll for message from user application */
@@ -212,11 +210,11 @@ static void* snoop_run_thread (void* arg)
 
         /* Poll for message from Kernel */
         ipsecmgr_snoop_run();
-
         if (QUIT == 1)
             break;
     }
-    printf("snoop_run_thread: calling shutdown\n");
+    ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+        "snoop_run_thread: calling shutdown\n");
     ipsecmgr_snoop_shutdown ();
     cleanup_sa_sp();
     netapi_shutdown(netapi_handle);
@@ -524,7 +522,7 @@ static int32_t init_ipsecmgr (void)
 
     /* Create the task context for snoop library */
     pthread_attr_init(&threadAttr);
-    pthread_attr_setstacksize(&threadAttr, 0x8000);
+    pthread_attr_setstacksize(&threadAttr, 0x10000);
     if (pthread_create(&snoop_run_th, (void*) NULL, snoop_run_thread, NULL))
     {
         ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
@@ -655,7 +653,6 @@ int32_t parse_cmd_line_args(int argc, char** argv)
     else
     {
            printf("netapi_proxyParseCommandLineArgs, argc=%d\n", argc);
-     
     }
 
     /* Scan and parse the command line options */
@@ -721,35 +718,58 @@ int get_kernel_config(int index)
 
 int create_pktio_channel(int index)
 {
+    static int count = 0;
     int error = 0;
     char name[19];
     PKTIO_HANDLE_T *pktio_channel;
     PKTIO_CFG_T pktio_cfg;
+    NETCP_CFG_ROUTE_T route;
+    NETCP_CFG_FLOW_T flow;
+    NETCP_CFG_EXCEPTION_PKT_T expPkt_appid = 0;
+
+    memset(&pktio_cfg,0,sizeof(PKTIO_CFG_T));
+    memset((void *)&route, 0, sizeof (NETCP_CFG_ROUTE_T));
+    memset((void *)&flow, 0, sizeof (NETCP_CFG_FLOW_T));
+
+    sprintf(&name[0],"%s%d","offload_", index);
+    pktio_cfg.qnum = globalDB.qNum[index];
+    pktio_cfg.flags1 = PKTIO_RX;
+    pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
+    pktio_cfg.max_n = 8;
+
+    globalDB.pktio_channel[index] = netapi_pktioCreate(netapi_handle,
+                                               &name[0],
+                                               (PKTIO_CB)recv_cb,
+                                               &pktio_cfg,
+                                               &error);
+    if (!globalDB.pktio_channel[index])
+    {
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+            "create_pktio_channel: failed\n");
+        return -1;
+    }
 
-        memset(&pktio_cfg,0,sizeof(PKTIO_CFG_T));
+    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+            "create_pktio_channel: index: %d, qnum: %d, pktio_handle: 0x%x\n",
+            index, 
+            pktio_cfg.qnum,
+            globalDB.pktio_channel[index]);
 
-        sprintf(&name[0],"%s%d","offload_", index);
-        pktio_cfg.qnum = globalDB.qNum[index];
-        pktio_cfg.flags1 = PKTIO_RX;
-        pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
-        pktio_cfg.max_n = 8;
+    /* Only want to create exception route for 1st interface */
+    if (index != 0)
+        return 0;
+    flow.dma_engine= 1;
+    flow.flowid = globalDB.flowId[index];
+    route.p_dest_q = globalDB.pktio_channel[index];
+    route.p_flow = &flow;
+
+    /* enable exception packet handling for fragmented packets */
+    expPkt_appid = netapi_netcpCfgExceptions(netapi_handle,
+                                             7,
+                                             NETCP_CFG_ACTION_TO_SW,
+                                             (NETCP_CFG_ROUTE_HANDLE_T) &route);
+    printf("create_pktio_channel: expPkt appid: 0x%x\n", expPkt_appid);
 
-        globalDB.pktio_channel[index] = netapi_pktioCreate(netapi_handle,
-                                                   &name[0],
-                                                   (PKTIO_CB)recv_cb,
-                                                   &pktio_cfg,
-                                                   &error);
-        if (!globalDB.pktio_channel[index])
-        {
-            ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
-                "create_pktio_channel: failed\n");
-            return -1;
-        }
-        else
-        {
-            ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
-            "created pktio channel for queue :0x%x\n", globalDB.qNum[index]);
-        }
     return 0;
 }
 /**
@@ -774,9 +794,10 @@ int32_t main (int argc, char* argv[])
     char* pTok = NULL;
     int ip_entry_count = 0;
     struct ifaddrs *ifaddr, *ifa;
-           int family, s;
-           char host[NI_MAXHOST];
-           char sa_data[14];
+    int family, s;
+    char host[NI_MAXHOST];
+    struct sockaddr_in6 ipv6_addr;
+
     ipsecmgr_syslog_init();
 
     memset(&globalDB, 0, sizeof(globalDB));
@@ -792,9 +813,6 @@ int32_t main (int argc, char* argv[])
     else
         netapi_netcpCfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
 
-    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO, "ERROR: netapi_init failed\n");
-
-
     for (i = 0; i < 16; i++)
     {
         if (get_kernel_config(i))
@@ -838,35 +856,74 @@ int32_t main (int argc, char* argv[])
 
         family = ifa->ifa_addr->sa_family;
 
-        if (family == AF_INET)
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+                        "%s  address family: %d%s\n",
+                        ifa->ifa_name, family,
+                        (family == AF_PACKET) ? " (AF_PACKET)" :
+                        (family == AF_INET) ?   " (AF_INET)" :
+                        (family == AF_INET6) ?  " (AF_INET6)" : "");
+        if ((family == AF_INET) ||(family == AF_INET6))
         {
-            s = getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in),
-                            host,
-                            NI_MAXHOST,
-                            NULL,
-                            0,
-                            NI_NUMERICHOST); 
+            s = getnameinfo(ifa->ifa_addr,
+                (family == AF_INET) ? sizeof(struct sockaddr_in):
+                                      sizeof(struct sockaddr_in6),
+                host,
+                NI_MAXHOST,
+                NULL,
+                0,
+                NI_NUMERICHOST);
+
             if (s != 0)
             {
                 ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
                     "getnameinfo() failed: %s\n", gai_strerror(s));
                     continue;
             }
-            for (i=0;i<4;i++)
+            if (family == AF_INET)
             {
-                ipConfigList[ip_entry_count].ip[i] = ifa->ifa_addr->sa_data[i+2];
+                ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+                                    "ipv4 string %s\n", host);
+                for (i=0;i<NWAL_IPV4_ADDR_SIZE;i++)
+                {
+                    ipConfigList[ip_entry_count].ip[i] =
+                                    ifa->ifa_addr->sa_data[i+2];
+                }
+            }
+            else
+            {
+                pTok = strtok(host,"%");
+                for (i=0;i<NWAL_IPV6_ADDR_SIZE;i++)
+                {
+                    inet_pton(AF_INET6, pTok, &(ipv6_addr.sin6_addr));
+
+                    ipConfigList[ip_entry_count].ip[i] =
+                        ipv6_addr.sin6_addr.s6_addr[i];
+                    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+                        "ipv6[%d]: 0x%x\n",
+                        i,
+                        ipConfigList[ip_entry_count].ip[i]);
+                }
             }
             memcpy(&ipConfigList[ip_entry_count].name[0],
                     ifa->ifa_name,
                     strlen(ifa->ifa_name));
             pTok = strtok(ifa->ifa_name, ":.");
-            /* now we have the interface name, is this eth0 or eth1 */
+            /* now we have the interface name, is this eth0, eth1 or bridge i/f */
             if (pTok)
             {
                 if(strstr(pTok,"eth"))
                 {
                     sscanf(pTok,"eth%d", &iface);
                     ipConfigList[ip_entry_count].iface = iface;
+                    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+                        "eth i/f found with iface %d\n", iface);
+                }
+                else if(strstr(pTok,"br"))
+                {
+                    sscanf(pTok,"br%d", &iface);
+                    ipConfigList[ip_entry_count].iface = iface;
+                    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+                        "bridge i/f found with iface %d\n", iface);
                 }
                 else
                 {
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];
index 46aaf173ea8b4216139309b5ba457259f5d8d784..92c7be813b31d77a88e9d6437b44c7389d05c951 100755 (executable)
@@ -62,7 +62,7 @@ typedef struct {
 /* Container for applicaion ID's for offloaded SA's */
 typedef struct {
     char    name[NI_MAXHOST];
-    char    ip[4];
+    char    ip[16];
     int     iface;
 } ipsecMgrIfConfigEntry_T;