Added IPV6 and bridge interface support
[keystone-rtos/netapi.git] / ti / runtime / netapi / applications / ipsec_offload / ipsecmgr / src / netapi_ipsecmgr.c
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
                 {