[keystone-rtos/netapi.git] / ti / runtime / netapi / applications / ipsec_offload / ipsecmgr / src / netapi_ipsecmgr.c
diff --git a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapi_ipsecmgr.c b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapi_ipsecmgr.c
index 943018216b2e3663effd9b0d831032ef080b1f99..8e95419a79c7205791056d7c74f0ae03b821c45e 100755 (executable)
**********************************************************************/
char* DTS_LOG_FILE_QUEUE_ETHx[] = {
"/proc/device-tree/soc/pktdma@2004000/channels/netrx0/complete-queue"};
-
-#if 0
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx1/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx2/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx3/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx4/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx5/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx6/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx7/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx8/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx9/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx10/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx11/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx12/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx13/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx14/complete-queue",
- "/proc/device-tree/soc/pktdma@2004000/channels/netrx15/complete-queue"
-};
-#endif
char* DTS_LOG_FILE_FLOW_ETHx[] = {
"/proc/device-tree/soc/pktdma@2004000/channels/netrx0/flow"};
-#if 0
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx1/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx2/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx3/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx4/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx5/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx6/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx7/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx8/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx9/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx10/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx11/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx12/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx13/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx14/flow",
-"/proc/device-tree/soc/pktdma@2004000/channels/netrx15/flow",
-};
-#endif
+
+
/**********************************************************************
************************** Global Variables **************************
**********************************************************************/
//paSysStats_t netcp_stats;
ipsecMgrMcb_t globalDB;
-ipsecMgrIfConfigEntry_T ipConfigList[16];
/* Lock file for the daemon */
#define LOCK_FILE "/var/lock/ipsecmgr_daemon"
64, //#descriptors w/o buffers in default heap
TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
128, //tail room
- 256, //extra room,
+ 256, //extra room
0
};
}
static void* snoop_run_thread (void* arg)
{
- printf( "snoop_run_thread: daemon entering forever event loop\n");
+ cpu_set_t cpu_set;
+ CPU_ZERO( &cpu_set);
+ CPU_SET( 0, &cpu_set);
+
+ hplib_utilSetupThread(0, &cpu_set, hplib_spinLock_Type_LOL);
+ ipsecmgr_syslog_msg(SYSLOG_LEVEL_INFO,
+ "snoop_run_thread: daemon entering forever event loop\n");
int count=0;
int sat=500000;
while (1)
/* Poll for message from Kernel */
ipsecmgr_snoop_run();
#if 1
- if((count % 50000) == 0)
+ if((count % 500000) == 0)
utilsStatsCb(netapi_handle);
#endif
return -1;
}
+
+
+#ifdef GDB_DEBUG
+ snoop_run_thread(NULL);
+#else
/* Create the task context for snoop library */
pthread_attr_init(&threadAttr);
pthread_attr_setstacksize(&threadAttr, 0x10000);
}
/* Wait for the NETAPI Proxy task to finish its processing and exit. */
pthread_join (snoop_run_th, NULL);
-
+#endif
return 0;
}
return;
}
-/* FUNCTION PURPOSE:validate and process inputs to the application */
-int32_t parse_cmd_line_args(int argc, char** argv)
-{
- int32_t i;
-
- /* Valid command line options */
- if (argc == 1)
- {
- printf("netapi_proxyParseCommandLineArgs, argc =1\n");
- return 0;
- }
- else
- {
- printf("netapi_proxyParseCommandLineArgs, argc=%d\n", argc);
- }
-
- /* Scan and parse the command line options */
- for (i = 1; i < argc; i ++)
- {
- if (argv[i][0] == '-' && argv[i][1] == 'f')
- {
- /* Log file name */
- if (i+1 >= argc || argv[i+1] == NULL)
- return -1;
- i++;
- }
- else
- {
- /* Invalid options */
- return -1;
- }
- }
- /* Success */
- return 0;
-}
-
-int get_kernel_config(int index)
+int get_kernel_config()
{
uint32_t temp=0;
FILE *pDts = NULL;
- pDts = fopen(DTS_LOG_FILE_QUEUE_ETHx[index], "rb");
+ pDts = fopen(DTS_LOG_FILE_QUEUE_ETHx[0], "rb");
if(pDts)
{
fread((void*)&temp, sizeof(uint32_t), 1, pDts);
- globalDB.qNum[index]= (int)swap32(temp);
+ globalDB.qNum = (int)swap32(temp);
fclose(pDts);
}
else
{
ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
- "main: error opening device tree file: %s\n",DTS_LOG_FILE_QUEUE_ETHx[index]);
+ "main: error opening device tree file: %s\n",DTS_LOG_FILE_QUEUE_ETHx[0]);
return -1;
}
pDts = NULL;
- pDts = fopen(DTS_LOG_FILE_FLOW_ETHx[index], "rb");
+ pDts = fopen(DTS_LOG_FILE_FLOW_ETHx[0], "rb");
if(pDts)
{
fread((void*)&temp, sizeof(uint32_t), 1, pDts);
- globalDB.flowId[index] = (int)swap32(temp);
+ globalDB.flowId = (int)swap32(temp);
fclose(pDts);
}
else
{
ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
- "main: error opening device tree file: %s\n",DTS_LOG_FILE_FLOW_ETHx[index]);
+ "main: error opening device tree file: %s\n",DTS_LOG_FILE_FLOW_ETHx[0]);
return -1;
}
ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
- "get_kernel_config(%d): flow: 0x%x, qNum: 0x%x\n",
- index, globalDB.flowId[index], globalDB.qNum[index]);
+ "get_kernel_config: flow: 0x%x, qNum: 0x%x\n",
+ globalDB.flowId, globalDB.qNum);
return 0;
}
-int create_pktio_channel(int index)
+int create_pktio_channel()
{
static int count = 0;
int error = 0;
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];
+ sprintf(&name[0],"%s","offload_0");
+ pktio_cfg.qnum = globalDB.qNum;
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,
+ globalDB.pktio_channel = netapi_pktioCreate(netapi_handle,
&name[0],
(PKTIO_CB)recv_cb,
&pktio_cfg,
&error);
- if (!globalDB.pktio_channel[index])
+ if (!globalDB.pktio_channel)
{
ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
"create_pktio_channel: failed\n");
return -1;
}
- ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,
- "create_pktio_channel: index: %d, qnum: %d, pktio_handle: 0x%x\n",
- index,
+ printf("create_pktio_channel: qnum: %d, pktio_handle: 0x%x\n",
pktio_cfg.qnum,
- globalDB.pktio_channel[index]);
+ globalDB.pktio_channel);
- /* 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];
+ flow.flowid = globalDB.flowId;
+ route.p_dest_q = globalDB.pktio_channel;
route.p_flow = &flow;
-
+ route.valid_params |= NETCP_CFG_VALID_PARAM_ROUTE_TYPE;
+ route.routeType = NWAL_ROUTE_RX_INTF_W_FLOW;
/* enable exception packet handling for fragmented packets */
expPkt_appid = netapi_netcpCfgExceptions(netapi_handle,
7,
ipsecmgr_syslog_init();
memset(&globalDB, 0, sizeof(globalDB));
- memset(&ipConfigList, 0, sizeof(ipConfigList));
- /* assign main net_test thread to run on core 0 */
+ /* assign main net_test thread to run on core 0 */
CPU_ZERO( &cpu_set);
CPU_SET( 0, &cpu_set);
hplib_utilSetupThread(0, &cpu_set, hplib_spinLock_Type_LOL);
/* create netapi */
- netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
-
+ netapi_handle = netapi_init(NETAPI_SYS_MASTER,
+ &our_netapi_default_cfg);
if(netapi_handle == NULL)
{
- ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR, "ERROR: netapi_init failed\n");
+ ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+ "ERROR: netapi_init failed\n");
return -1;
}
else
- netapi_netcpCfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
-
- for (i = 0; i < 1; i++)
- {
- if (get_kernel_config(i))
- {
- ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
- "ERROR: main: get_kernel_config() failed\n");
- continue;
- }
- else
- {
- /* create pktio channel */
- if(create_pktio_channel(i))
- {
- ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
- "ERROR: main: pktio channel creation failed\n");
- }
- }
- }
- /* Read and parse command line options */
- if (parse_cmd_line_args (argc, argv) < 0)
- {
- printf ("Usage format: netfpproxy.out [-f <log_file>]\n");
- return -1;
- }
-
-
- /* Create the proxy daemon. */
- /*printf("main: calling daemonize\n");
- daemonize (LOCK_FILE); */
+ netapi_netcpCfgExceptions(netapi_handle,
+ NETCP_CFG_ALL_EXCEPTIONS,
+ NETCP_CFG_ACTION_DISCARD,
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL);
-
-#if to_delete
- if (getifaddrs(&ifaddr) == -1)
+ if (get_kernel_config())
{
ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
- "main: getifaddrs failure\n");
+ "ERROR: main: get_kernel_config() failed\n");
return -1;
}
-
- for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
+ else
{
- if (ifa->ifa_addr == NULL)
- continue;
-
- family = ifa->ifa_addr->sa_family;
-
- 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))
+ /* create pktio channel */
+ if(create_pktio_channel())
{
- 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;
- }
- if (family == AF_INET)
- {
- 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, 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
- {
- ipConfigList[ip_entry_count].iface = -1;
- }
- ip_entry_count++;
- }
+ ipsecmgr_syslog_msg (SYSLOG_LEVEL_ERROR,
+ "ERROR: main: pktio channel creation failed\n");
+ return -1;
}
}
+ /*Create the proxy daemon. */
+ printf("main: calling daemonize\n");
+ daemonize (LOCK_FILE);
- if (ifaddr)
- freeifaddrs(ifaddr);
-#endif
/* Initialize and start the IPSec Mgr Snoop functionality */
if ((retVal = init_ipsecmgr ()) < 0)
{