SDOCM00107645: ipsecmgr sampe application needs to provide option for user to give...
authorTinku Mannan <tmannan@ti.com>
Thu, 8 May 2014 13:41:33 +0000 (09:41 -0400)
committerTinku Mannan <tmannan@ti.com>
Thu, 8 May 2014 13:41:33 +0000 (09:41 -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 0380089c6b4a4c26514cf53ede82a7670ab27de0..da7a046b2f9523042f879f0d6ebe370e0f792421 100755 (executable)
@@ -783,21 +783,60 @@ int32_t main (int argc, char* argv[])
     char host[NI_MAXHOST];
     struct sockaddr_in6 ipv6_addr;
     cpu_set_t cpu_set;
-    ipsecmgr_syslog_init();
-
+    int c;
+    static char usage[] = "usage: %s -s <outbound sequence number> -f <SA transmit flow Id>\n";
 
+    ipsecmgr_syslog_init();
 
     memset(&globalDB, 0, sizeof(globalDB));
-
-    if (argc == 2)
-    {
-        globalDB.oseq_offset = atoi(argv[1]);
-    }
-    else
+    globalDB.sa_tx_flow = -1;
+    int temp;
+    while ((c = getopt (argc, argv, "s:f:")) != -1)
     {
-        globalDB.oseq_offset = 0;
+       switch (c)
+       {
+            case 's':
+                /* check is user input 0 for oseq_offset (valid but also default)*/
+                if(strncmp("0", optarg,1) == 0)
+                {
+                    globalDB.oseq_offset = 0;
+                }
+                else
+                {
+                    globalDB.oseq_offset = (uint32_t)strtol(optarg, NULL,0);
+                    if(!globalDB.oseq_offset)
+                    {
+                        printf(usage, argv[0]);
+                        exit(EXIT_FAILURE);
+                    }
+                }
+                break;
+            case 'f':
+                /* check is user input 0 for sa_tx_flow(valid) */
+                if(strncmp("0", optarg,1) == 0)
+                {
+                    globalDB.sa_tx_flow= 0;
+                }
+                else
+                {
+                    globalDB.sa_tx_flow = (uint32_t)strtol(optarg, NULL,0);
+                    if(!globalDB.sa_tx_flow)
+                    {
+                        printf(usage, argv[0]);
+                        exit(EXIT_FAILURE);
+                    }
+                }
+                break;
+            case '?':
+                printf(usage, argv[0]);
+                exit(EXIT_FAILURE);
+            default:
+                break;
+        }
     }
-
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+                   "main: oseq_offset: %d, sa_tx_flow: %d\n",
+                    globalDB.oseq_offset, globalDB.sa_tx_flow);
 
     /* assign main net_test thread to run on core 0 */
     CPU_ZERO( &cpu_set);
@@ -835,8 +874,8 @@ int32_t main (int argc, char* argv[])
         }
     }
      /*Create the proxy daemon. */
-    printf("main: calling daemonize\n");
-    daemonize (LOCK_FILE); 
+    ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO, "main: calling daemonize\n");
+    daemonize (LOCK_FILE);
 
     /* Initialize and start the IPSec Mgr Snoop functionality */
     if ((retVal = init_ipsecmgr ()) < 0)
@@ -849,5 +888,6 @@ int32_t main (int argc, char* argv[])
     else
         ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
                              "main: ipsecmgr daemon shutdonw complete\n");
+    exit(EXIT_SUCCESS);
 
 }
index c147f098855f7f4a9b3050bf5f87ec7633f46070..c53fe477cd1bdd53180f65b964015eca1327fe6a 100755 (executable)
@@ -172,16 +172,18 @@ int netapilib_ifAddSA
 
         flow.dma_engine= 1;
         flow.flowid = globalDB.flowId;
-        printf("add_sa:flowid: %d\n",flow.flowid);
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+                           "add_sa:flowid: %d\n",flow.flowid);
 
         route.p_flow = &flow;
         route.p_dest_q = globalDB.pktio_channel;
 
-        printf("add_sa: p_dest_q: 0x%x, flowId: 0x%x\n",
-                route.p_dest_q, 
-                route.p_flow->flowid);
-                route.valid_params |= NETCP_CFG_VALID_PARAM_ROUTE_TYPE;
-                route.routeType = NWAL_ROUTE_RX_INTF_W_FLOW;
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+                       "add_sa: p_dest_q: 0x%x, flowId: 0x%x\n",
+                       route.p_dest_q,
+                       route.p_flow->flowid);
+       route.valid_params |= NETCP_CFG_VALID_PARAM_ROUTE_TYPE;
+       route.routeType = NWAL_ROUTE_RX_INTF_W_FLOW;
     }
     else if (sa_info->dir == DIR_OUTBOUND)
     {
@@ -223,7 +225,7 @@ int netapilib_ifAddSA
         saInfo.saMode = nwal_SA_MODE_TUNNEL;
     else
     {
-        ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+        ipsecmgr_syslog_msg(SYSLOG_LEVEL_ERROR,
             "netapilib_ifAddSA: IPSec mode (%d) is invalid.\n", sa_info->mode);
         return -1;
     }
@@ -573,20 +575,28 @@ int netapilib_ifGetSACtx
     hw_ctx->swinfo[0] = swInfo0;
     hw_ctx->swinfo[1] = swInfo1;
 
-    retVal = nwal_getGlobCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
-        &info);
-    if (retVal != nwal_OK)
+    if(globalDB.sa_tx_flow == -1)
     {
-        ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
-            "netapilib_ifGetSACtx: nwal_getGlobCxtInfo returned error: 0x%x\n", retVal);
-        return -1;
-    }
-    hw_ctx->flow_id = info.rxSaPaFlowId;
-
-    ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
+       retVal = nwal_getGlobCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,
+                                      &info);
+        if (retVal != nwal_OK)
+        {
+            ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+                "netapilib_ifGetSACtx: nwal_getGlobCxtInfo returned error: 0x%x\n", retVal);
+            return -1;
+        }
+        hw_ctx->flow_id = info.rxSaPaFlowId;
+        ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
             "netapilib_ifGetSACtx: rxPaSaflowId: 0x%x, rxSaPaflowId: 0x%x\n",
             info.rxPaSaFlowId,
             info.rxSaPaFlowId);
+    }
+    else
+    {
+        hw_ctx->flow_id = globalDB.sa_tx_flow;
+    }
+
     ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
             "netapilib_ifGetSACtx: swInfo0: 0x%x, swInfo1: 0x%x, flowId: 0x%x\n",
             hw_ctx->swinfo[0],
index 1c2e06843c93e50bf6e317c0f9869c372044504b..b515a2570fe140c1696d17f1d5966e5d71a0cef1 100755 (executable)
@@ -47,15 +47,16 @@ typedef struct {
 } ipsecMgrAppId_T;
 
 typedef struct {
-    int                 flowId;
-    int                 qNum;
-    PKTIO_HANDLE_T*     pktio_channel;
+    int             flowId;
+    int             qNum;
+    PKTIO_HANDLE_T* pktio_channel;
 
     /* list to store offloaded RX SA appIds and RX Policies */
     ipsecMgrAppId_T rx_sa[64];
     /* list to store offloaded TX SA appIds */
     ipsecMgrAppId_T tx_sa[64];
     uint32_t        oseq_offset; /* offset to outbound/egress sequence number */
+    int             sa_tx_flow;  /* flow SA to use to transmit packet */
 } ipsecMgrMcb_t;
 
 int netapilib_ifAddSA