1 #ifndef __NET_TEST_UTIL_H__
2 #define __NET_TEST_UTIL_H__
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <string.h>
12 #include "net_test.h"
14 #ifdef __LINUX_USER_SPACE
15 #define Debug_printf
16 #else
17 #define Debug_printf
18 #endif
20 #define MAX_SEC_INDEX 16
21 #define NET_TEST_MAX_MAC 10
22 #define NET_TEST_MAX_IP 10
24 #define MAX_LINE_LENGTH 512
25 #define MAX_ROUTES 16
27 /* The input strings requird for parsing certain configuration
28 * paremeters from the config file */
29 #define INIT_CONFIG_IPSEC_MODE_RX "ipsec_mode_rx"
30 #define INIT_CONFIG_IPSEC_MODE_TX "ipsec_mode_tx"
31 #define INIT_CONFIG_IPSEC_IF_NO "ipsec_if"
32 #define CONFIG_STRING_LEN 128
34 //IPSEC MODE(only choose one rx and one tx)
35 #define IPSEC_MODE_RX_INFLOW 1
36 #define IPSEC_MODE_TX_INFLOW 2
37 #define IPSEC_MODE_RX_SIDEBAND 3
38 #define IPSEC_MODE_TX_SIDEBAND 4
40 #define PKT_LEN 1400
42 typedef struct {
43 unsigned char mac[NET_TEST_MAX_MAC][6];
44 uint8_t num_macs;
45 uint8_t switch_port[NET_TEST_MAX_MAC];
46 nwalIpAddr_t ip[NET_TEST_MAX_IP];
47 uint8_t num_ips;
48 uint8_t attach_iface[NET_TEST_MAX_IP];
49 nwalIpAddr_t local_ipsec_ip;
50 nwalIpAddr_t remote_ipsec_ip;
51 uint8_t ipsec_mode_rx;
52 uint8_t ipsec_mode_tx;
53 int ipsec_if_no;
54 uint8_t auth_key[MAX_SEC_INDEX][36];
55 uint8_t encr_key[MAX_SEC_INDEX][36];
56 uint32_t tunnel_id[MAX_SEC_INDEX];
57 NETAPI_SEC_SA_INFO_T sa_info[MAX_SEC_INDEX];
58 nwalSecKeyParams_t key_params[MAX_SEC_INDEX];
60 } netTestConfig_t;
62 typedef struct
63 {
64 char dir[CONFIG_STRING_LEN];
65 char spi[CONFIG_STRING_LEN];
66 char proto[CONFIG_STRING_LEN];
67 char saMode[CONFIG_STRING_LEN];
68 char ipType[CONFIG_STRING_LEN];
69 char src[CONFIG_STRING_LEN];
70 char dst[CONFIG_STRING_LEN];
71 char replayWindow[CONFIG_STRING_LEN];
72 char authMode[CONFIG_STRING_LEN];
73 char cipherMode[CONFIG_STRING_LEN];
74 char esnLo[CONFIG_STRING_LEN];
75 char esnHi[CONFIG_STRING_LEN];
76 char encKeySize[CONFIG_STRING_LEN];
77 char macKeySize[CONFIG_STRING_LEN];
78 char auth_key[CONFIG_STRING_LEN];
79 char encr_key[CONFIG_STRING_LEN];
80 char tunnel_id[CONFIG_STRING_LEN];
81 } netTestConfigSA_t;
83 typedef struct{
84 char mac[NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
85 char switch_port[NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
86 char ip[NET_TEST_MAX_IP][CONFIG_STRING_LEN];
87 char attach_iface [NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
88 char ipsec_mode_rx[CONFIG_STRING_LEN];
89 char ipsec_mode_tx[CONFIG_STRING_LEN];
90 char routes[MAX_ROUTES][CONFIG_STRING_LEN];
91 char ports[MAX_ROUTES][CONFIG_STRING_LEN];
92 char dst_ips[MAX_ROUTES][CONFIG_STRING_LEN];
93 char paths[MAX_ROUTES][CONFIG_STRING_LEN];
94 char ipsec_if_no[CONFIG_STRING_LEN];
95 char tunnel_id[CONFIG_STRING_LEN];
96 netTestConfigSA_t sa_config[MAX_SEC_INDEX];
98 } netTestConfigFile_t;
100 struct LastPktInfo
101 {
102 int iface;
103 int ipcsum;
104 int l4csum;
105 } ;
106 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta);
108 void mysig(int x);
109 unsigned long peek(unsigned long * p);
110 void dump_descr(unsigned long *p, int n);
111 void dump_header(unsigned long *p, int n, int a, int r);
112 void netapi_dump_buf(unsigned long * buf,uint32_t buf_length);
113 long htonl(long x);
114 unsigned char hex2dec(char *p_s);
115 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2);
116 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords);
117 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen);
118 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher);
119 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher);
120 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats);
121 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
122 void parse_one_mac(char * p_mac_str, unsigned char *p_mac);
123 void parse_one_key(char *p_key_str, unsigned char *p_key);
124 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip);
125 void parse_mac_address(netTestConfigFile_t *pConfig);
126 void parse_ip_address(netTestConfigFile_t *pConfig);
127 void parse_ipsec_mode(netTestConfigFile_t *pConfig);
128 void parse_auth_mode(char *auth_mode_str, nwal_saAALG *auth_mode);
129 void parse_encr_mode(char *ency_mode_str, nwal_saEALG*encr_mode);
130 void parse_proto(char *proto_str, nwal_IpSecProto *proto);
131 void parse_mode(char *mode_str, nwal_saMode *mode);
132 void parse_ipType(char *ip_type_str, nwal_IpType *ipType);
133 void parse_spi(char *spi_str, uint32_t *spi);
134 void parse_replayWindow(char *replay_window_str, uint32_t *replay_window);
135 void parse_esn(char *esn_str, uint32_t *esn);
136 void parse_key_size(char *key_size_str, uint16_t *key_size);
137 void parse_tunnel_id(char * tunnel_id_str, uint32_t *tunnel_id);
138 void parse_dir(char* dir_str, nwal_SaDir *dir);
139 void parse_sa(netTestConfigFile_t *pConfig, int i);
140 #ifdef EXPERIMENTAL
141 void parse_routes(netTestConfigFile_t *pConfig);
142 #endif
143 void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig);
145 void house(NETAPI_SCHED_HANDLE_T *s);
147 void create_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1);
148 void delete_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1);
149 #endif