diff options
author | yalei wang <wylandrea@gmail.com> | 2018-08-14 06:58:19 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2018-08-14 06:58:19 +0000 |
commit | 55c3082a6a7a3982de66d0a97b1519105871f855 (patch) | |
tree | e7c76d51cf2df0ea42909f3bc7d84ebb2ced441d /stacks/lwip_stack/lwip_src/include | |
parent | 9a4f5e18e7ae40e11d9f8a946182871b735a260e (diff) | |
parent | 7dc65518819f2b453fd2837e92c115592d8832ec (diff) |
Merge "Feat : LWIP integration part1"
Diffstat (limited to 'stacks/lwip_stack/lwip_src/include')
24 files changed, 2658 insertions, 0 deletions
diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/config_common.h b/stacks/lwip_stack/lwip_src/include/ip_module/config_common.h new file mode 100644 index 0000000..0c88139 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ip_module/config_common.h @@ -0,0 +1,64 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _NSTACK_CONFIG_COMMON_H_ +#define _NSTACK_CONFIG_COMMON_H_ + +#include "ip_module_api.h" + +#define MAX_IP_MODULE_BUFF_SIZE 1024*1024 + +/* ip module config types */ +#define IP_MODULE_TYPE_IP "ip" +#define IP_MODULE_TYPE_NETWORK "network" +#define IP_MODULE_TYPE_PORT "port" +#define IP_MODULE_TYPE_SETLOG "setlog" +#define IP_MODULE_TYPE_SNAPSHOT "snapshot" +#define IP_MODULE_TYPE_SETTRACE "settrace" + +#define TCP_MODULE_TYPE_SET_OOS_LEN "ooslen" + +#define IP_MODULE_NAME "./nStackCtrl: " +#define IP_MODULE_INVALID_ARGUMENT_S "invalid argument -- \"%s\"\n" +#define IP_MODULE_MORE_OPTION "need more options -- " +#define IP_MODULE_LESS_OPTION "no need option -- " + +/* Error codes */ +#define IP_MODULE_OK 0 +#define IP_MODULE_DATA_ERROR 1 +#define IP_MODULE_DATA_NOT_EXIST 2 + +struct config_param +{ + int action; + char type[IP_MODULE_LENGTH_256]; + char name[IP_MODULE_LENGTH_256]; + char value[IP_MODULE_LENGTH_64]; + char container_id[IP_MODULE_LENGTH_256]; + int error; + + char error_desc[NSCRTL_ERRBUF_LEN]; + + u64 traceid; +}; + +struct config_data +{ + struct config_param param; + char json_buff[MAX_IP_MODULE_BUFF_SIZE - sizeof (struct config_param)]; +}; + +#endif diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/configuration_reader.h b/stacks/lwip_stack/lwip_src/include/ip_module/configuration_reader.h new file mode 100644 index 0000000..779ace8 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ip_module/configuration_reader.h @@ -0,0 +1,26 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _CONFIGURATION_READER_H +#define _CONFIGURATION_READER_H +#include <semaphore.h> +#include "config_common.h" + +struct config_data *get_config_data (); +int get_str_value (const char *arg); +int setlog_level_value (const char *param, const char *value); + +#endif diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/container_ip.h b/stacks/lwip_stack/lwip_src/include/ip_module/container_ip.h new file mode 100644 index 0000000..e83c607 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ip_module/container_ip.h @@ -0,0 +1,39 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _CONTAINER_IP_H +#define _CONTAINER_IP_H +#include "ip_module_api.h" +#include "json.h" + +struct ip_action_param +{ + char container_id[IP_MODULE_LENGTH_256]; + char port_name[IP_MODULE_LENGTH_256]; +}; + +void free_container (struct container_ip *container, bool_t only_free); +struct container_port *parse_port_obj (struct json_object *port_obj); +struct container_ip *parse_container_ip_json (char *param); +int add_container (struct container_ip *container); +struct container_ip *get_container_by_container_id (char *container_id); + +int del_port (char *container_id, char *port_name); +struct container_port *get_port (char *container_id, char *port_name); +struct container_port *get_port_from_container (struct container_port *port); +int getIpCfgAll (char *jsonBuf, size_t size); + +#endif diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h b/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h new file mode 100644 index 0000000..488e13e --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ip_module/ip_module_api.h @@ -0,0 +1,222 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _IP_MODULE_API_H_ +#define _IP_MODULE_API_H_ +#include "types.h" + +typedef int bool_t; +#define IP_MODULE_TRUE 1 +#define IP_MODULE_FALSE 0 +#define IP_MODULE_LENGTH_32 32 +#define IP_MODULE_LENGTH_64 64 +#define IP_MODULE_LENGTH_256 256 +#define IP_MODULE_LENGTH_1024 1024 +#define IP_MODULE_SUBNET_MASK_LEN IP_MODULE_LENGTH_32 +#define IP_MODULE_MAX_NAME_LEN IP_MODULE_LENGTH_256 +#define IP_MODULE_PORT_JSON_LEN (2048 * 2) +#define IP_MODULE_NETWORK_JSON_LEN (2048 * 2) +#define MAX_NETWORK_COUNT IP_MODULE_LENGTH_64 +#define MAX_NETWORK_IP_COUNT IP_MODULE_LENGTH_1024 +#define MAX_NETWORK_NUM (MAX_NETWORK_COUNT * 2) +COMPAT_PROTECT (MAX_NETWORK_NUM, 128); +#define MAX_PORT_NUM (MAX_NETWORK_IP_COUNT * 2) +COMPAT_PROTECT (MAX_PORT_NUM, 2048); +#define NSCRTL_ERRBUF_LEN IP_MODULE_LENGTH_256 + +#define INVALID_EXPIRE_TIME 0x7FFFFFFF +#define NSTACLCTRL_MAX_TRY_TIMES 60 + +/*sockaddr_un.sun_path is an array of 108 bytes*/ +#define IP_MODULE_MAX_PATH_LEN 108 + +typedef enum enumADERRCODE +{ + NSCRTL_OK = 0, + NSCRTL_ERR, + NSCRTL_RD_NOT_EXIST, + NSCRTL_RD_EXIST = 3, + NSCRTL_INPUT_ERR, + NSCRTL_STATUS_ERR, + NSCRTL_NETWORK_COUNT_EXCEED, + NSCRTL_IP_COUNT_EXCEED, + NSCRTL_FREE_ALL_PORT, //when all ports in container were deleted, need to free container. + + NSCRTL_MAX_ERR = 127 +} NSCRTL_ERR_CODE; + +#define NSOPR_SET_ERRINFO(_errno, fmt, ...) \ + {\ + struct config_data* cf_data = get_config_data(); \ + if (cf_data)\ + {\ + size_t len_error_desc = strlen(cf_data->param.error_desc); \ + cf_data->param.error = _errno; \ + if ((_errno != NSCRTL_OK) && (len_error_desc < NSCRTL_ERRBUF_LEN))\ + {\ + if (-1 == (SNPRINTF_S(cf_data->param.error_desc + len_error_desc, \ + NSCRTL_ERRBUF_LEN - len_error_desc, NSCRTL_ERRBUF_LEN - len_error_desc - 1, fmt, ## __VA_ARGS__)))\ + {\ + NSOPR_LOGERR("SNPRINTF_S failed]"); \ + } \ + } \ + } \ + } \ + +struct ref_nic +{ + struct ref_nic *next; + char nic_name[IP_MODULE_MAX_NAME_LEN]; +}; + +struct phy_net +{ + struct ref_nic *header; + char bond_name[IP_MODULE_MAX_NAME_LEN]; + int bond_mode; +}; + +struct container_port_ip_cidr +{ + struct container_port_ip_cidr *next; + unsigned int ip; + unsigned int mask_len; +}; + +struct container_multicast_id +{ + struct container_multicast_id *next; + unsigned int ip; +}; + +typedef struct +{ + char port_json[IP_MODULE_PORT_JSON_LEN]; +} port_buffer; + +struct container_port +{ + struct container_port *next; + struct container_port_ip_cidr *ip_cidr_list; + struct container_multicast_id *multicast_list; + char port_name[IP_MODULE_MAX_NAME_LEN]; + port_buffer *buffer; +}; + +#define get_port_json(obj) obj->buffer->port_json + +struct container_ip +{ + struct container_ip *next; + struct container_port *ports_list; + char container_id[IP_MODULE_MAX_NAME_LEN]; +}; + +struct container_list +{ + struct container_ip *header; +}; + +struct ip_subnet +{ + struct ip_subnet *next; + unsigned int subnet; + unsigned int mask_len; +}; + +typedef struct +{ + char network_json[IP_MODULE_NETWORK_JSON_LEN]; +} network_buffer; + +struct network_configuration +{ + struct network_configuration *next; + struct phy_net *phy_net; + struct ip_subnet *ip_subnet; + char network_name[IP_MODULE_MAX_NAME_LEN]; + char type_name[IP_MODULE_MAX_NAME_LEN]; + network_buffer *buffer; +}; + +#define get_network_json(obj) obj->buffer->network_json + +struct network_list +{ + struct network_configuration *header; +}; + +void ip_subnet_print (struct ip_subnet *subnet); +bool_t is_in_same_network (unsigned int src_ip, unsigned int dst_ip); +bool_t is_ip_match_netif (unsigned int ip, char *netif_name); +bool_t is_ip_exist (unsigned int ip); +struct network_configuration *get_network_list (); +inline struct network_configuration *get_network_by_ip_with_tree (unsigned int + ip); + +/* "type" option */ +typedef enum +{ + IP_MODULE_NETWORK, + IP_MODULE_IP, + IP_MODULE_NETWORK_ALL, + IP_MODULE_IP_ALL, + IP_MODULE_ALL, +} ip_module_type; + +/* "action" option */ +typedef enum +{ + IP_MODULE_OPERATE_NULL, + IP_MODULE_OPERATE_ADD, + IP_MODULE_OPERATE_DEL, + IP_MODULE_OPERATE_QUERY, + IP_MODULE_OPERATE_SET, + IP_MODULE_GET_VERSION, + IP_MODULE_QUERY_NET, + IP_MODULE_MAX, //new type should be added before IP_MODULE_MAX + IP_MODULE_BOTTOM = 0xFFFFFFFF +} ip_module_operate_type; + +typedef int (*post_to_fn) (void *arg, ip_module_type type, + ip_module_operate_type operate_type); +typedef int (*add_netif_ip_fn) (char *netif_name, unsigned int ip, + unsigned int mask); +typedef int (*del_netif_ip_fn) (char *netif_name, unsigned int ip); + +typedef struct +{ + post_to_fn post_to; + add_netif_ip_fn add_netif_ip; + del_netif_ip_fn del_netif_ip; +} output_api; + +void regist_output_api (output_api * api); +output_api *get_output_api (); +int init_configuration_reader (); +int process_post (void *arg, ip_module_type type, + ip_module_operate_type operate_type); +int process_configuration (void *arg, ip_module_type type, + ip_module_operate_type operate_type); + +port_buffer *malloc_port_buffer (); +void free_port_buffer (port_buffer * buffer); +network_buffer *malloc_network_buffer (); +void free_network_buffer (network_buffer * buffer); +int get_network_json_data (); +int get_ip_json_data (); + +#endif diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/network.h b/stacks/lwip_stack/lwip_src/include/ip_module/network.h new file mode 100644 index 0000000..117b71c --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ip_module/network.h @@ -0,0 +1,36 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _NETWORK_H +#define _NETWORK_H +#include "ip_module_api.h" + +void free_network_configuration (struct network_configuration *network, + bool_t only_free); +struct network_configuration *parse_network_obj (struct json_object + *network_obj); +struct network_configuration *parse_network_json (char *param, + struct network_configuration + *network_list); +int add_network_configuration (struct network_configuration + *network_configuration); +struct network_configuration *get_network_by_name (char *name); +struct network_configuration *get_network_by_nic_name (char *name); +int del_network_by_name (char *name); +int get_network_all (char *jsonBuf, size_t size); +int nic_already_init (const char *nic_name); + +#endif diff --git a/stacks/lwip_stack/lwip_src/include/ip_module/trp_rb_tree.h b/stacks/lwip_stack/lwip_src/include/ip_module/trp_rb_tree.h new file mode 100644 index 0000000..ef0ac37 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ip_module/trp_rb_tree.h @@ -0,0 +1,77 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TRP_RB_TREE_H__ +#define __TRP_RB_TREE_H__ + +typedef void *trp_key_t; +typedef void *trp_data_t; + +#define RB_RED 0 +#define RB_BLACK 1 + +typedef int (*key_compare) (trp_key_t left, trp_key_t right); // return > 0 left > right, return 0 left = right, return < 0 left < right + +typedef struct trp_rb_node +{ + struct trp_rb_node *rb_parent; + struct trp_rb_node *rb_right; + struct trp_rb_node *rb_left; + key_compare key_compare_fn; + trp_key_t key; + trp_data_t data; + unsigned int color; +} trp_rb_node_t; + +typedef struct trp_rb_root +{ + struct trp_rb_node *rb_node; +} trp_rb_root_t; + +int trp_rb_insert (trp_key_t, trp_data_t, trp_rb_root_t *, key_compare); +int trp_rb_insert_allow_same_key (trp_key_t, trp_data_t, trp_rb_root_t *, + key_compare); +void trp_rb_erase (trp_key_t, trp_rb_root_t *, key_compare key_compare_fn); +void trp_rb_erase_with_data (trp_key_t key, trp_data_t data, + trp_rb_root_t * root, int count, + key_compare key_compare_fn); + +static inline trp_rb_node_t * +trp_rb_search (trp_key_t key, trp_rb_root_t * root, + key_compare key_compare_fn) +{ + trp_rb_node_t *node = root->rb_node; + int ret; + while (node) + { + ret = key_compare_fn (node->key, key); + if (0 < ret) + { + node = node->rb_left; + } + else if (0 > ret) + { + node = node->rb_right; + } + else + { + return node; + } + } + + return NULL; +} +#endif diff --git a/stacks/lwip_stack/lwip_src/include/ipv4/stackx/spl_ip_addr.h b/stacks/lwip_stack/lwip_src/include/ipv4/stackx/spl_ip_addr.h new file mode 100644 index 0000000..ae5c31f --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/ipv4/stackx/spl_ip_addr.h @@ -0,0 +1,162 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __LWIP_IP_ADDR_H__ +#define __LWIP_IP_ADDR_H__ + +#include "spl_opt.h" +#include "spl_def.h" +#include "ip_module_api.h" +#include "stackx_ip_addr.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** ip_addr_t uses a struct for convenience only, so that the same defines can + * operate both on ip_addr_t as well as on ip_addr_p_t. */ +/* Forward declaration to not include netif.h */ +struct netif; +#if BYTE_ORDER == BIG_ENDIAN + +/** Set an IPaddress given by the four byte-parts */ +#define SPL_IP4_ADDR(ipaddr, a, b, c, d) \ + (ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \ + ((u32_t)((b) & 0xff) << 16) | \ + ((u32_t)((c) & 0xff) << 8) | \ + (u32_t)((d) & 0xff) +#else + +/** Set an IPaddress given by the four byte-parts. + Little-endian version that prevents the use of htonl. */ +#define SPL_IP4_ADDR(ipaddr, a, b, c, d) \ + (ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \ + ((u32_t)((c) & 0xff) << 16) | \ + ((u32_t)((b) & 0xff) << 8) | \ + (u32_t)((a) & 0xff) +#endif + +/** memcpy-like copying of IPaddresses where addresses are known to be + * 16-bit-aligned if the port is correctly configured (so a port could define + * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ +#ifndef IPADDR2_COPY +#define IPADDR2_COPY(dest, src) MEMCPY_S(dest, sizeof(ip_addr_t), src, sizeof(ip_addr_t)) +#endif + +/** Copy IPaddress - faster than spl_ip_addr_set: no NULL check */ +#define spl_ip_addr_copy(dest, src) ((dest).addr = (src).addr) + +/** Safely copy one IPaddress to another (src may be NULL) */ +#define spl_ip_addr_set(dest, src) ((dest)->addr = \ + ((src) == NULL ? 0 : \ + (src)->addr)) + +/** Safely copy one IPaddress to another and change byte order + * from host- to network-order. */ +#define spl_ip_addr_set_hton(dest, src) ((dest)->addr = \ + ((src) == NULL ? 0 : \ + htonl((src)->addr))) + +/** Get the network address by combining host address with netmask */ +#define spl_ip_addr_get_network(target, host, netmask) ((target)->addr = ((host)->addr) & ((netmask)->addr)) + +/** + * Determine if two address are on the same network. + * + * @arg addr1 IPaddress 1 + * @arg addr2 IPaddress 2 + * @arg mask network identifier mask + * @return !0 if the network identifiers of both address match + */ +#define spl_ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ + (mask)->addr) == \ + ((addr2)->addr & \ + (mask)->addr)) + +/* && ((dest)->addr & tmp->netmask.addr) == (tmp->ip_addr.addr & tmp->netmask.addr) */ +/* add "netif = netif->root; \"*/ +#define ip_net_netif_cmp( dest, netif) ({ \ + netif = netif->root; \ + struct netif* tmp = netif; \ + int find = 0; \ + while(tmp) \ + { \ + if (is_in_same_network((dest)->addr, tmp->ip_addr.addr)) \ + { \ + netif->ip_addr.addr = tmp->ip_addr.addr; \ + netif->netmask.addr = tmp->netmask.addr; \ + find = 1; \ + break; \ + } \ + if (netif->is_out) \ + { \ + break; \ + } \ + tmp = tmp->vnext; \ + } \ + (!!find); \ + }) + +/* Check if netif match dest , if not , find one and swap */ +/* add "netif = netif->root; \"*/ + +#define ip_addr_netif_cmp_and_swap( dest, pnetif) ({ \ + pnetif = pnetif->root; \ + struct netif* tmp = pnetif; \ + int find = 0; \ + while(tmp) \ + { \ + if ((dest)->addr == tmp->ip_addr.addr) \ + { \ + pnetif->ip_addr.addr = tmp->ip_addr.addr; \ + pnetif->netmask.addr = tmp->netmask.addr; \ + find = 1; \ + break; \ + } \ + if (pnetif->is_out) \ + { \ + break; \ + } \ + tmp = tmp->vnext; \ + } \ + (!!find); \ + }) + +#define ip_addr_netif_cmp( dest, pnetif) ({ \ + pnetif = pnetif->root; \ + struct netif* tmp = pnetif; \ + int find = 0; \ + while(tmp) \ + { \ + if ((dest)->addr == tmp->ip_addr.addr) \ + { \ + find = 1; \ + break; \ + } \ + tmp = tmp->vnext; \ + } \ + (!!find); \ + }) + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __LWIP_IP_ADDR_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/netif/common.h b/stacks/lwip_stack/lwip_src/include/netif/common.h new file mode 100644 index 0000000..45e9c8f --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/netif/common.h @@ -0,0 +1,233 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _COMMON_H_ +#define _COMMON_H_ +#include <stddef.h> /* for size_t */ +#include "stackx_common.h" +#include "netif.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +//yyq + +/* define common names for structures shared between server and client */ + +#define MP_STACKX_INSTANCE_POLL_NAME "VppTCP_instance_poll" +#define MP_STACKX_PORT_ZONE "VppTCP_stackx_port_zone" +#define MP_STACKX_PORT_INFO "VppTCP_stackx_port_info" +#define MP_MEMPOLL_RX_NAME "VppTCP_MBUF_%u_%u_RX" +#define MP_MEMPOLL_RXMSG_NAME "VppTCP_MSG_%u_%u_RX" +#define MP_MEMPOLL_TX_NAME "VppTCP_MBUF_TX" +#define MP_MEMPOLL_SEG_NAME "VppTCP_MBUF_SEG" +#define MP_STACKX_MSG_NAME "VppTCP_msg" +#define MP_STACKX_RING_NAME "VppTCP_%u_ring" +#define MP_STACKX_LRING_NAME "VppTCP_%u_lring" + +#define MP_STACKX_BIT_SET_NAME "%s_bit_set" + +#define MP_STACKX_SOCKET_FREE_LIST_NAME "VppTCP_socket_list" + +#define MP_NETIF_LIST_NAME "VppTCP_Netif_list" + +/* + move sharemem create from App to nstackMain +advice rename app_tx_mbuf to VppTCP_APP_TXBUF_POOL +*/ +#define MP_STACKX_APP_TXBUF_POOL "app_tx_mbuf" + +#define MP_MEMPOLL_TCP_BUFF_NAME "VppTCP_MBUF_%u_TCP_BUFF" + +extern int spl_snprintf (char *buffer, int buflen, const char *format, ...); + +/*According to the number of network cards, the establishment of recv lring, + *each separate, each proc_id each NIC queue independent lring + */ +static inline const char * +get_mempoll_rx_name (unsigned proc_id, unsigned nic_id) +{ + /* buffer for return value. Size calculated by %u being replaced + * by maximum 3 digits (plus an extra byte for safety) + * the id may reach 65535, need add more space*/ + static char buffer[sizeof (MP_MEMPOLL_RX_NAME) + 32]; + + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, MP_MEMPOLL_RX_NAME, proc_id, nic_id); //???????????buffer?? + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_mempoll_rxmsg_name (unsigned proc_id, unsigned nic_id) +{ + /* buffer for return value. Size calculated by %u being replaced + * by maximum 3 digits (plus an extra byte for safety) + * the id may reach 65535, need add more space*/ + static char buffer[sizeof (MP_MEMPOLL_RXMSG_NAME) + 32]; + + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, MP_MEMPOLL_RXMSG_NAME, proc_id, nic_id); //???????????buffer?? + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_mempoll_ring_name (unsigned proc_id) +{ + static char buffer[sizeof (MP_STACKX_RING_NAME) + 16]; + + int retVal = + spl_snprintf (buffer, sizeof (buffer) - 1, MP_STACKX_RING_NAME, proc_id); + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_mempoll_lring_name (unsigned proc_id) +{ + static char buffer[sizeof (MP_STACKX_LRING_NAME) + 16]; + + int retVal = + spl_snprintf (buffer, sizeof (buffer) - 1, MP_STACKX_LRING_NAME, proc_id); + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_mempoll_msg_name () +{ + static char buffer[sizeof (MP_STACKX_MSG_NAME) + 16]; + + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, MP_STACKX_MSG_NAME); + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_mempoll_tx_name () +{ + /* buffer for return value. Size calculated by %u being replaced + * by maximum 3 digits (plus an extra byte for safety) */ + static char buffer[sizeof (MP_MEMPOLL_TX_NAME) + 16]; + + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, MP_MEMPOLL_TX_NAME); //???????????buffer?? + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_mempoll_seg_name () +{ + /* buffer for return value. Size calculated by %u being replaced + * by maximum 3 digits (plus an extra byte for safety) */ + static char buffer[sizeof (MP_MEMPOLL_SEG_NAME) + 16]; + + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, MP_MEMPOLL_SEG_NAME); //???????????buffer?? + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_memStatusBitSet_name (const char *name, unsigned int num) +{ + static char buffer[64]; + + int retVal = + spl_snprintf (buffer, sizeof (buffer) - 1, MP_STACKX_BIT_SET_NAME "%d", + name, num); + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_memNameWithProc (const char *name) +{ + static char buffer[64]; + + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, "%s", name); + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +static inline const char * +get_memInstancePoll_name (unsigned int type) +{ + static char buffer[sizeof (MP_STACKX_INSTANCE_POLL_NAME) + 32]; + int retVal = spl_snprintf (buffer, sizeof (buffer) - 1, "%s" "%d", + MP_STACKX_INSTANCE_POLL_NAME, type); + if (-1 == retVal) + { + NSPOL_LOGERR ("spl_snprintf failed]"); + return NULL; + } + + return buffer; +} + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif diff --git a/stacks/lwip_stack/lwip_src/include/netif/kni_proc.h b/stacks/lwip_stack/lwip_src/include/netif/kni_proc.h new file mode 100644 index 0000000..bcf4129 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/netif/kni_proc.h @@ -0,0 +1,103 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _KNI_PROC_H_ +#define _KNI_PROC_H_ +#include <rte_kni.h> +#include <rte_mempool.h> +#include <rte_mbuf.h> + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +#define KNI_MAX_KTHREAD 32 + +/* the kni is runned on the lcore from below on */ +#define DEFAULT_KNI_LCORE_BASE 24 + +/* Structure of kni para */ +struct disp_kni_para +{ + u8_t queue_id; + u8_t port_id; +}; + +/* + * Structure of port parameters + */ +struct kni_port_params +{ + uint8_t port_id; /* Port ID */ + unsigned lcore_rx; /* lcore ID for RX */ + unsigned lcore_tx; /* lcore ID for TX */ + uint32_t nb_lcore_k; /* Number of lcores for KNI multi kernel threads */ + uint32_t nb_kni; /* Number of KNI devices to be created */ + unsigned lcore_k[KNI_MAX_KTHREAD]; /* lcore ID list for kthreads */ + struct rte_kni *kni[KNI_MAX_KTHREAD]; /* KNI context pointers */ + struct rte_mempool *kni_pktmbuf_pool; + u8_t ip_reconfigured; +} __rte_cache_aligned; + +/* Structure type for storing kni interface specific stats */ +struct kni_interface_stats +{ + /* number of pkts received from NIC, and sent to KNI */ + uint64_t rx_packets; + + /* number of pkts received from NIC, but failed to send to KNI */ + uint64_t rx_dropped; + + /* number of pkts received from KNI, and sent to NIC */ + uint64_t tx_packets; + + /* number of pkts received from KNI, but failed to send to NIC */ + uint64_t tx_dropped; +}; + +/* External interface for initilizing KNI subsystem */ +int kni_proc_init (enum rte_proc_type_t proc_type, int proc_id, u32_t pmask, + struct kni_port_params **kni_para); + +int kni_proc_init_secondary (int proc_id, int port_id); +/* External interface for destroy KNI subsystem */ +void kni_proc_free (void); + +/* External interface for kni tx thread entry */ +void kni_tx_thread_cycle (void *arg); + +int kni_config_net (void); +void kni_handler_eth_operate_request (int port); + +/* External interface for commiting packet to kni device */ +void kni_dispatch_to_kernel (uint8_t port_id, + struct rte_mbuf *pkts_burst[], uint8_t nb_rx); + +/* the lcore kni tx/rx thread run on */ +unsigned kni_get_tx_lcore (uint8_t port_id); +unsigned kni_get_rx_lcore (uint8_t port_id); + +void init_kni (void); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /*#ifndef _KNI_PROC_H_ */ diff --git a/stacks/lwip_stack/lwip_src/include/netif/sc_dpdk.h b/stacks/lwip_stack/lwip_src/include/netif/sc_dpdk.h new file mode 100644 index 0000000..99c3bc6 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/netif/sc_dpdk.h @@ -0,0 +1,80 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef SC_DPDK_H_ +#define SC_DPDK_H_ + +#include <pbuf.h> +#include <sharedmemory.h> + +#include "lwip/etharp.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +#define NSTACK_CONFIG_SHM "nstack_config" + +#define MBUF_DATA_SIZE 2048 +#define MBUF_SIZE (MBUF_DATA_SIZE + sizeof(struct common_mem_mbuf) + COMMON_PKTMBUF_HEADROOM) + +extern int g_nstack_bind_cpu; + +inline uint16_t spl_mbuf_refcnt_update (void *mbuf, int16_t value); +struct stack_proc_content *get_stack_proc_content (); + +inline int spl_msg_malloc (data_com_msg ** p_msg_entry); +#define spl_msg_free(p_msg_entry) msg_free(p_msg_entry) +struct spl_pbuf *spl_mbuf_malloc (uint16_t len, spl_pbuf_type type, + u16_t * count); + +inline void spl_mbuf_free (void *mbuf); + +inline int spl_set_lcore_id (unsigned dest_lcore_id); + +static inline unsigned +spl_get_lcore_id () +{ + unsigned core_id = 0; + +#if (DPDK_MODULE != 1) +#ifdef HAL_LIB +#else + core_id = rte_lcore_id (); +#endif + if (core_id >= MAX_THREAD_NUM) + { + core_id = 0; + } +#endif + + return core_id; +} + +int set_share_config (); + +int init_instance (); + +void printmeminfo (); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#endif /* SERVER_DPDK_H_ */ diff --git a/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h b/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h new file mode 100644 index 0000000..0a92ea0 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/netif/sharedmemory.h @@ -0,0 +1,148 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef SHAREDMEMORY_H_ +#define SHAREDMEMORY_H_ +#include "stackxopts.h" +#include <sys/types.h> +#include <semaphore.h> +//#include "stackx/raw.h" +#include "tcp.h" +#include "udp.h" +//#include "stackx/ip.h" +#include "spl_err.h" +#include "list.h" +#include "arch/queue.h" +#include "spl_opt.h" +#include "stackx/spl_ip_addr.h" + +#include "stackx/spl_api.h" +#include <arch/sys_arch.h> +#include "common_mem_api.h" +//#include "stackx/memp.h" +#include "stackx_instance.h" + +#include "hal_api.h" +#ifdef HAL_LIB +#else +#include "rte_ring.h" +#endif + +/** Description for a task waiting in select */ +struct stackx_select_cb +{ + /** Pointer to the next waiting task */ + union + { + struct stackx_select_cb *next; + PTR_ALIGN_TYPE next_a; + }; + + /** Pointer to the previous waiting task */ + union + { + struct stackx_select_cb *prev; + PTR_ALIGN_TYPE prev_a; + }; + + /** semaphore to wake up a task waiting for select */ + //sys_sem_t sem; + union + { + sys_sem_t_v1 sem; + PTR_ALIGN_TYPE sem_a; + }; + + /** readset passed to select */ + fd_set readset; + + /** writeset passed to select */ + fd_set writeset; + + /** unimplemented: exceptset passed to select */ + fd_set exceptset; + + /** don't signal the same semaphore twice: set to 1 when signalled */ + volatile int sem_signalled; + + uint8_t pad_64bit[4]; +}; +/** From epoll.h: Definition of struct stackx_sock and stackx_select_cb ---------End*/ + +enum tcp_run_type +{ + TCP_MUTIPL_INSTANCE = 0, + TCP_MASTER_WORKER, + TCP_DISTRIBUTOR_WORKER, + TCP_RUN_TO_COMPETE, + TCP_PROC_TYPE_END +}; + +enum proc_run_type +{ + PROC_MAIN_RUN_TYPE = 0, + PROC_BACKUP_RUN_TYPE, + PROC_RUN_TYPE_END +}; + +struct linux_port_info +{ + char if_name[HAL_MAX_NIC_NAME_LEN]; + char ip_addr_linux[18]; //uint32_t ip_addr_linux; + char mask_linux[18]; //uint32_t mask_linux; + char bcast_linux[18]; //uint32_t bcast_linux; + char mac_addr[20]; //struct ether_addr mac_addr; + hal_hdl_t hdl; +}; + +struct stackx_port_info +{ + struct stackx_port_info *next_use_port; + struct linux_port_info linux_ip; +}; + +struct stackx_port_zone +{ + unsigned int port_num; + unsigned int bonded_port_num; + struct stackx_port_info *stackx_one_port; +}; + +struct select_cb_entry +{ + struct stackx_select_cb select_cb; + + union + { + sem_t semForSelect; + ALIGN_TYPE pad_64bit[4]; + }; + + union + { + struct select_cb_entry *pre_empty_entry; + PTR_ALIGN_TYPE pre_empty_entry_a; + }; + + union + { + struct select_cb_entry *next_empty_entry; + PTR_ALIGN_TYPE next_empty_entry_a; + }; + +}; + +#endif /* SHAREDMEMORY_H_ */ diff --git a/stacks/lwip_stack/lwip_src/include/netif/spl_hal.h b/stacks/lwip_stack/lwip_src/include/netif/spl_hal.h new file mode 100644 index 0000000..ca56663 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/netif/spl_hal.h @@ -0,0 +1,114 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef SPL_HAL_H_ +#define SPL_HAL_H_ + +#include "hal_api.h" +#include "netif.h" +#include "nsfw_maintain_api.h" +#include "stackx_spl_share.h" +#include "stackx_pbuf_comm.h" +#include "netifapi.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +int spl_hal_init (int argc, char *argv[]); +int spl_hal_port_init (); + +int spl_hal_stats_display (struct netif *pnetif, char *str, u32_t len, + char *json, u32_t json_len); + +err_t spl_hal_output (struct netif *netif, struct pbuf *buf); +void spl_hal_input (struct netif *netif, struct spl_pbuf **buf); + +inline u16_t spl_hal_recv (struct netif *netif, u8_t id); + +int spl_hal_tx_ip_cksum_enable (); +int spl_hal_tx_udp_cksum_enable (); +int spl_hal_tx_tcp_cksum_enable (); + +u32 spl_hal_is_nic_exist (const char *name); + +int spl_hal_is_bond_netif (struct netif *pnetif); + +static inline void +spl_do_dump (struct spl_pbuf *p, u16 direction) +{ + struct spl_pbuf *q = p; + while (q) + { + ntcpdump (q->payload, q->len, direction); + q = q->next; + } +} + +/* information of bond*/ +#define MAX_BOND_PORT_NUM 4 + +/* information of one bond port */ +struct bond_set +{ + char bond_port_name[HAL_MAX_NIC_NAME_LEN]; + char slave_ports[HAL_MAX_SLAVES_PER_BOND][HAL_MAX_NIC_NAME_LEN]; + u8_t slave_port_cnt; +}; + +#define NETIF_ETH_ADDR_LEN 6 + +/* information of all bond ports */ +struct bond_ports_info +{ + u8_t cnt; + struct bond_set ports[MAX_BOND_PORT_NUM]; +}; + +struct ether_addr +{ + u8_t addr_bytes[NETIF_ETH_ADDR_LEN]; + +}; + +struct netif *get_netif_by_ip (unsigned int ip); +struct netif *netif_check_broadcast_addr (spl_ip_addr_t * addr); +struct netifExt *getNetifExt (u16_t id); +int netifExt_add (struct netif *netif); + +int add_netif_ip (char *netif_name, unsigned int ip, unsigned int mask); +int del_netif_ip (char *netif_name, unsigned int ip); + +err_t spl_netifapi_netif_add (struct netif *pnetif, + spl_ip_addr_t * ipaddr, + spl_ip_addr_t * netmask, + spl_ip_addr_t * gw, + void *state, + netif_init_fn init, + netif_input_fn input, + netifapi_void_fn voidfunc); +struct netif *find_netif_by_if_name (char *if_name); +void ethernetif_packets_input (struct netif *pstnetif); +err_t ethernetif_init (struct netif *pnetif); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#endif /* SPL_HAL_H_ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/internal_msg.h b/stacks/lwip_stack/lwip_src/include/stackx/internal_msg.h new file mode 100644 index 0000000..584ab06 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/internal_msg.h @@ -0,0 +1,90 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __internal_msg_h__ +#define __internal_msg_h__ + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +#include "nsfw_msg.h" +#include "netif.h" +#include "lwip/netifapi.h" +#include "ip_module_api.h" + +enum netif_msg_type +{ + NETIF_DO_ADD, + NETIF_MSG_API_MAX = MAX_MINOR_TYPE +}; + +/* NETIF_DO_ADD */ +typedef struct msg_add_netif_T +{ + void (*function) (struct msg_add_netif_T * m); + struct netif *netif; + spl_ip_addr_t *ipaddr; + spl_ip_addr_t *netmask; + spl_ip_addr_t *gw; + void *state; + netif_init_fn init; + netif_input_fn input; + netifapi_void_fn voidfunc; + /* no need to extend member */ +} msg_add_netif; + +typedef struct +{ + ip_module_type type; + ip_module_operate_type operate_type; + void *arg; +} msg_ip_module; + +typedef struct msg_internal_callback_T +{ + void (*function) (void *ctx); + void *ctx; +} msg_internal_callback; + +enum timer_msg_type +{ + TIMER_MSG_TIMEOUT, + TIMER_MSG_CLEAR, + TIMER_MSG_MAX = MAX_MINOR_TYPE +}; + +typedef struct msg_timer_T +{ + void *act; + void *arg; +} msg_timer; + +enum mt_msg_type +{ + MT_MSG_VER_MGR, + MT_MSG_MAX = MAX_MINOR_TYPE +}; + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __internal_msg_h__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_api.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_api.h new file mode 100644 index 0000000..ea63e90 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_api.h @@ -0,0 +1,276 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __SPL_API_H__ +#define __SPL_API_H__ + +#include "opt.h" +#include "common_mem_base_type.h" +#include <stddef.h> /* for size_t */ +#include "arch/queue.h" +#include "arch/sys_arch.h" +#include "arch/atomic_32.h" +#include "stackx_common_opt.h" +#include "stackx_spl_share.h" + +/* From lwip */ +#include "api.h" +#include "sys.h" +#include "sys_arch.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +#define MAX_WAIT_TIMEOUT 0x7FFFFFFF + +/* Throughout this file, IPaddresses and port numbers are expected to be in + * the same byte order as in the corresponding pcb. + */ + +/* Flags for struct netconn.flags (u8_t) */ + +/** TCP: when data passed to netconn_write doesn't fit into the send buffer, + this temporarily stores whether to wake up the original application task + if data couldn't be sent in the first try. */ +#define SPL_NETCONN_FLAG_WRITE_DELAYED 0x01 + +/** Should this netconn avoid blocking? */ +#define SPL_NETCONN_FLAG_NON_BLOCKING 0x02 + +/** Was the last connect action a non-blocking one? */ +#define SPL_NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 + +/** If this is set, a TCP netconn must call netconn_recved() to update + the TCP receive window (done automatically if not set). */ +#define SPL_NETCONN_FLAG_NO_AUTO_RECVED 0x08 + +/** If a nonblocking write has been rejected before, poll_tcp needs to + check if the netconn is writable again */ +// #define NETCONN_FLAG_CHECK_WRITESPACE 0x10 + +enum stackx_model +{ + SOCKET_STACKX = 0, + CALLBACK_STACKX +}; + +enum callback_type +{ + API_ACCEPT_EVENT = 0xF0, + API_RECV_EVENT, + API_SEND_EVENT, + API_CLOSE_EVENT +}; +#if 1 +/** Use to inform the callback function about changes */ +enum spl_netconn_evt +{ + SPL_NETCONN_EVT_RCVPLUS, + SPL_NETCONN_EVT_RCVMINUS, + SPL_NETCONN_EVT_SENDPLUS, + SPL_NETCONN_EVT_SENDMINUS, + SPL_NETCONN_EVT_ERROR, + SPL_NETCONN_EVT_HUP, + SPL_NETCONN_EVT_RDHUP, + SPL_NETCONN_EVT_AGAIN, + SPL_NETCONN_EVT_ACCEPT +}; +#endif +enum +{ + INET_ECN_NOT_ECT = 0, + INET_ECN_ECT_1 = 1, + INET_ECN_ECT_0 = 2, + INET_ECN_CE = 3, + INET_ECN_MASK = 3, +}; + +#define SPL_NETCONNTYPE_GROUP(t) (t & 0xF0) +#define SPL_NETCONNTYPE_DATAGRAM(t) (t & 0xE0) + +/* forward-declare some structs to avoid to include their headers */ +typedef struct common_pcb +{ + enum stackx_model model; + + int socket; + + /** type of the netconn (TCP, UDP or RAW) */ + enum spl_netconn_type type; + + /* share memory between sbr and stackx */ + spl_netconn_t *conn; + + u16 bind_thread_index; + u8 close_progress; + u8 recv_ring_not_empty; + + /** TCP: when data passed to netconn_write doesn't fit into the send buffer, + this temporarily stores the message. + Also used during connect and close. + */ + data_com_msg *current_msg; + + msg_write_buf *msg_head; + msg_write_buf *msg_tail; + + size_t write_offset; + + /** timeout to wait for new data to be received + (or connections to arrive for listening netconns) */ + int recv_timeout; + + /* timeout to wait for send buffer writtable */ + int send_timeout; + + int sk_rcvlowat; + + //DFX stat for connection packet + /* dfx_conn_t dfx; */ + + /*store the hostpid info for release */ + uint32_t hostpid; + u8_t l4_tick; /* if is odd number, use l4 ring first */ + u8_t dataSentFlag; + + nsfw_res res_chk; +} common_pcb; + +/** A callback prototype to inform about events for a netconn */ +//typedef void (*netconn_callback)(struct spl_netconn *, enum netconn_evt, u16_t len); + +/* Though these callback pointers are not set and referenced in nStack Core, still +the padding is required since the structure will be used in netconn and it needs +padding across 32-bit and 64-bit architecture */ +typedef struct +{ + union + { + int (*accept_event) (struct spl_netconn * conn); + PTR_ALIGN_TYPE accept_event_a; + }; + + union + { + int (*recv_event) (struct spl_netconn * conn); + PTR_ALIGN_TYPE recv_event_a; + }; + union + { + int (*send_event) (struct spl_netconn * conn); + PTR_ALIGN_TYPE send_event_a; + }; + union + { + int (*close_event) (struct spl_netconn * conn); + PTR_ALIGN_TYPE close_event_a; + }; +} callback_funcation; + +union ring_addr_u +{ + void *ring_addr; + PTR_ALIGN_TYPE ring_addr_a; +}; + +struct mem_manage +{ + volatile uint32_t current_read; + volatile uint32_t current_write; + union ring_addr_u ring_addr[RECV_MAX_POOL]; + union ring_addr_u l4_ring; /* recv ring for l4 */ + //void *ring_addr[RECV_MAX_POOL]; +}; + +/* Pbuf free should be done in network stack */ +struct spl_netconn_recvbuf_recoder +{ + struct spl_pbuf *head; + struct spl_pbuf *tail; + int totalLen; +}; + +/** Register an Network connection event */ +void spl_event_callback (spl_netconn_t * conn, enum spl_netconn_evt evt, + int postFlag); + +#define SPL_API_EVENT(c, e, p) spl_event_callback(c, e, p) + +/** Set conn->last_err to err but don't overwrite fatal errors */ +#define SPL_NETCONN_SET_SAFE_ERR(conn, err) do { \ + SYS_ARCH_PROTECT(lev); \ + if (!ERR_IS_FATAL((conn)->last_err)) { \ + (conn)->last_err = err; \ + } \ + SYS_ARCH_UNPROTECT(lev); \ + } while (0); + +/** Set the blocking status of netconn calls (@todo: write/send is missing) */ +#define spl_netconn_set_nonblocking(conn, val) do { if (val) { \ + (conn)->flags |= SPL_NETCONN_FLAG_NON_BLOCKING; \ + } else { \ + (conn)->flags &= ~SPL_NETCONN_FLAG_NON_BLOCKING; }} while (0) + +/** Get the blocking status of netconn calls (@todo: write/send is missing) */ +#define spl_netconn_is_nonblocking(conn) (((conn)->flags & SPL_NETCONN_FLAG_NON_BLOCKING) != 0) + +/** TCP: Set the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */ +#define spl_netconn_set_noautorecved(conn, val) do { if (val) { \ + (conn)->flags |= SPL_NETCONN_FLAG_NO_AUTO_RECVED; \ + } else { \ + (conn)->flags &= ~SPL_NETCONN_FLAG_NO_AUTO_RECVED; }} while (0) + +/** TCP: Get the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */ +#define spl_netconn_get_noautorecved(conn) (((conn)->flags & SPL_NETCONN_FLAG_NO_AUTO_RECVED) != 0) + +/** Set the receive timeout in milliseconds */ +#define spl_netconn_set_recvtimeout(cpcb, timeout) ((cpcb)->recv_timeout = (timeout)) + +/** Get the receive timeout in milliseconds */ +#define spl_netconn_get_recvtimeout(cpcb) ((cpcb)->recv_timeout) + +/** Set the send timeout in milliseconds */ +#define spl_netconn_set_sendtimeout(cpcb, timeout) ((cpcb)->send_timeout = (timeout)) + +/** Get the send timeout in milliseconds */ +#define spl_netconn_get_sendtimeout(cpcb) ((cpcb)->send_timeout) + +#define spl_netconn_set_sendbufsize(conn, sendbufsize) ((conn)->send_bufsize = (sendbufsize)) + +/* "man 7 socket" information + SO_SNDBUF + Sets or _gets the maximum socket send buffer in bytes. The kernel doubles + this value (to allow space for bookkeeping overhead) when it is set using + setsockopt(2), and this doubled value is returned by getsockopt(2). +*/ +#define spl_netconn_get_sendbufsize(conn) (2 *((conn)->send_bufsize)) + +#define spl_netconn_set_reclowbufsize(cpcb, recvlowbufsize) ((cpcb)->sk_rcvlowat = ((recvlowbufsize) > 0) ? recvlowbufsize : 1) +#define spl_netconn_get_reclowbufsize(cpcb) ((cpcb)->sk_rcvlowat) + +extern int spl_post_msg (u16 mod, u16 maj, u16 min, u16 op, char *data, + u16 data_len, u32 src_pid); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __LWIP_API_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_api_msg.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_api_msg.h new file mode 100644 index 0000000..94b681e --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_api_msg.h @@ -0,0 +1,129 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __LWIP_API_MSG_H__ +#define __LWIP_API_MSG_H__ + +#include <stddef.h> +#include <net/if.h> +#include <sys/ioctl.h> + +#include "nsfw_msg.h" +#include "spl_opt.h" +#include "spl_ip_addr.h" +#include "spl_err.h" +#include "spl_api.h" +//#include "sockets.h" +#include "stackx_spl_share.h" +#include "stackx_spl_msg.h" + +/* From lwip */ +#include "tcp.h" +#include "udp.h" +#include "sys.h" + +#ifdef HAL_LIB +#else +#include "rte_memcpy.h" +#endif + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/* For the netconn API, these values are use as a bitmask! */ +#define NETCONN_SHUT_RD 1 +#define NETCONN_SHUT_WR 2 +#define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) + +struct callback_fn +{ + tcp_sent_fn sent_fn; + tcp_recv_fn recv_fn; + tcp_connected_fn connected_fn; + tcp_poll_fn poll_fn; + tcp_err_fn err_fn; + tcp_err_fn close_fn; + tcp_accept_fn accept_fn; +}; + +#ifdef HAL_LIB +#else +typedef enum _mbuf_recyle_flg +{ + MBUF_UNUSED = 0, + MBUF_HLD_BY_APP = 1, + MBUF_HLD_BY_SPL = 2, +} mbuf_recycle_flg; +#endif + +err_t sp_enqueue (struct common_pcb *cpcb, void *p); +err_t accept_dequeue (spl_netconn_t * lconn, void **new_buf, + u32_t timeout /*miliseconds */ ); +err_t accept_enqueue (spl_netconn_t * conn, void *p); +void free_conn_by_spl (spl_netconn_t * conn); +void unlink_pcb (struct common_pcb *cpcb); +void do_try_delconn (void *close_data, u32 delay_sec); +void do_delconn (struct common_pcb *cpcb, msg_delete_netconn * msg); +void do_bind (struct common_pcb *cpcb, msg_bind * msg); +void do_pbuf_free (struct spl_pbuf *buf); +void do_connect (struct common_pcb *cpcb, msg_connect * msg); +void do_listen (struct common_pcb *cpcb, msg_listen * msg); +void do_send (struct common_pcb *cpcb, msg_send_buf * msg); +void do_recv (struct common_pcb *cpcb, msg_recv_buf * msg); +void do_write (struct common_pcb *cpcb, msg_write_buf * msg); +void do_getaddr (struct common_pcb *cpcb, msg_getaddrname * msg); +void do_close (struct common_pcb *cpcb, msg_close * msg); +void do_getsockopt_internal (struct common_pcb *cpcb, + msg_setgetsockopt * smsg); +void do_setsockopt_internal (struct common_pcb *cpcb, + msg_setgetsockopt * smsg); +void do_getsockname (struct common_pcb *cpcb, msg_getaddrname * amsg); +int netconn_drain (enum spl_netconn_type t, spl_netconn_t * conn); +int spl_pcb_new (msg_new_netconn * m); +void do_app_touch (msg_app_touch * smsg); +int do_close_finished (struct common_pcb *cpcb, u8_t close_finished, + u8_t shut, err_t err, int OpShutDown); +err_t do_writemore (struct spl_netconn *conn); +err_t do_close_internal (struct common_pcb *cpcb, int OpShutDown); + +u8 get_shut_op (data_com_msg * m); +int ks_to_stk_opt (int opt); +void update_tcp_state (spl_netconn_t * conn, enum tcp_state state); + +err_t spl_poll_tcp (void *arg, struct tcp_pcb *pcb); +err_t spl_recv_tcp (void *arg, struct tcp_pcb *pcb, struct pbuf *p, + err_t err); +err_t spl_sent_tcp (void *arg, struct tcp_pcb *pcb, u16_t len); +void spl_err_tcp (void *arg, err_t err); +err_t spl_tcp_recv_null (void *arg, struct tcp_pcb *pcb, struct pbuf *p, + err_t err); +err_t spl_do_connected (void *arg, struct tcp_pcb *pcb, err_t err); +err_t spl_accept_function (void *arg, struct tcp_pcb *newpcb, err_t err); + +struct common_pcb *alloc_common_pcb (); +void free_common_pcb (struct common_pcb *cpcb); +int common_pcb_init (struct common_pcb *cpcb); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __LWIP_API_MSG_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_err.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_err.h new file mode 100644 index 0000000..a0188be --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_err.h @@ -0,0 +1,40 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __STACKX_ERR_H__ +#define __STACKX_ERR_H__ + +#include "spl_opt.h" +#include "lwip/arch.h" +#include "stackx_err.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +typedef s8_t err_t; + +/* Definitions for error constants. */ + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __LWIP_ERR_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_instance.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_instance.h new file mode 100644 index 0000000..697c67d --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_instance.h @@ -0,0 +1,30 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _SPL_INSTANCE_H_ +#define _SPL_INSTANCE_H_ +#include "nsfw_msg_api.h" +#include "stackx_instance.h" + +extern stackx_instance *p_def_stack_instance; + +int spl_process (data_com_msg * m); + +void add_disp_netif (struct netif *netif); +void do_update_pcbstate (); +void init_stackx_lwip (); + +#endif /* _SPL_INSTANCE_H_ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_netbuf.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_netbuf.h new file mode 100644 index 0000000..cd2e1bf --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_netbuf.h @@ -0,0 +1,52 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __LWIP_NETBUF_H__ +#define __LWIP_NETBUF_H__ + +#include "spl_opt.h" +#include "spl_pbuf.h" +#include "spl_ip_addr.h" +#include "common_mem_base_type.h" +#include "common_mem_pal.h" +#include "common_pal_bitwide_adjust.h" +#include "stackx_netbuf.h" +#include <sys/uio.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <errno.h> + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** This spl_netbuf has dest-addr/port set */ +#define NETBUF_FLAG_DESTADDR 0x01 + +/** This spl_netbuf includes a checksum */ +#define NETBUF_FLAG_CHKSUM 0x02 + +void spl_netbuf_delete (struct spl_netbuf *buf); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __LWIP_NETBUF_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h new file mode 100644 index 0000000..01fe242 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h @@ -0,0 +1,173 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __STACKX_PBUF_H__ +#define __STACKX_PBUF_H__ + +#include "cc.h" + +#include "common_mem_base_type.h" +#include "stackx_pbuf_comm.h" +#include "common_mem_mbuf.h" + +#ifdef HAL_LIB +#else +#include "common_pal_bitwide_adjust.h" +#endif + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +extern u16_t g_offSetArry[SPL_PBUF_MAX_LAYER]; + +/** indicates this pbuf is loop buf .*/ +#define PBUF_FLAG_LOOPBUF 0x08U + +#define PBUF_SET_LOOP_FLAG(buf) ((buf)->flags |= PBUF_FLAG_LOOPBUF) +#define PBUF_IS_LOOP_BUF(buf) ((buf)->flags & PBUF_FLAG_LOOPBUF) + +/*Add 1 parameter, the last one, indicating which dpdk_malloc + *should be allocated from the pool; non-PBUF_ALLOC type regardless of this parameter*/ +struct spl_pbuf *spl_pbuf_alloc_hugepage (spl_pbuf_layer l, u16_t length, + spl_pbuf_type type, + u16_t thread_index, void *net_conn); +struct pbuf *spl_convert_spl_pbuf_to_pbuf (struct spl_pbuf *p_from); +err_t pbuf_to_splpbuf_copy (struct spl_pbuf *p_to, struct pbuf *p_from); +err_t splpbuf_to_pbuf_copy (struct pbuf *p_to, struct spl_pbuf *p_from); +spl_pbuf_layer get_pbuf_layer_from_pbuf_payload (struct pbuf *buf); +void print_pbuf_payload_info (struct pbuf *buf, bool send); + +static inline u8_t +spl_pbuf_header (struct spl_pbuf *p, s16_t header_size_increment) +{ + u8_t pbuf_ret; + /* header max len is tcp len+ ip len: 0xf*4+PBUF_IP_HLEN */ + if (unlikely + (((header_size_increment) < 0 && (-(header_size_increment)) > p->len) + || (header_size_increment > 0 + && (header_size_increment) >= (0xf * 4 + SPL_PBUF_IP_HLEN)))) + { + pbuf_ret = 1; + } + else + { + p->payload_a = p->payload_a - (header_size_increment); + p->len += (header_size_increment); + p->tot_len += (header_size_increment); + pbuf_ret = 0; + } + return pbuf_ret; +} + +void spl_pbuf_realloc (struct spl_pbuf *p, u32_t size); + +void spl_pbuf_cat (struct spl_pbuf *head, struct spl_pbuf *tail); +void spl_pbuf_free (struct spl_pbuf *p); + +#define pbuf_free_safe(x)\ +{\ + spl_pbuf_free((x));\ + (x) = NULL;\ +} + +/** + * Count number of pbufs in a chain + * + * @param p first pbuf of chain + * @return the number of pbufs in a chain + */ +static inline u16_t +spl_pbuf_clen (struct spl_pbuf *p) +{ + u16_t len = 0; + while (p != NULL) + { + ++len; + p = (struct spl_pbuf *) ADDR_SHTOL (p->next_a); + } + return len; +} + +static inline u16_t +mbuf_count (struct spl_pbuf *p) +{ + u16_t count = 0; + struct spl_pbuf *buf = p; + struct common_mem_mbuf *mbuf; + while (buf) + { + mbuf = + (struct common_mem_mbuf *) ((char *) buf - + sizeof (struct common_mem_mbuf)); + while (mbuf) + { + count++; +#ifdef HAL_LIB +#else + mbuf = mbuf->next; +#endif + } + buf = (struct spl_pbuf *) ADDR_SHTOL (buf->next_a); //buf->next; + } + return count; +} + +static inline u16_t +mbuf_count_in_one_pbuf (struct spl_pbuf *p) +{ + + u16_t cnt = 0; + struct common_mem_mbuf *mbuf; + if (NULL == p) + { + NSPOL_LOGERR ("Invalid param : p(null) !"); + return 0; + } + + mbuf = + (struct common_mem_mbuf *) ((char *) p - sizeof (struct common_mem_mbuf)); + + /* no need to check mbuf itself */ +#ifdef HAL_LIB +#else + if (!mbuf->next) +#endif + return 1; + + while (mbuf) + { + ++cnt; +#ifdef HAL_LIB +#else + mbuf = mbuf->next; +#endif + } + + return cnt; +} + +inline int pbuf_internal_copy (struct spl_pbuf *dst, struct spl_pbuf *src); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __STACKX_PBUF_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_sbr.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_sbr.h new file mode 100644 index 0000000..a4d6ccc --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_sbr.h @@ -0,0 +1,33 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _SPL_SBR_H_ +#define _SPL_SBR_H_ +#include "nsfw_msg_api.h" +#include "tcp.h" +#include "udp.h" +//#include "stackx/raw.h" +#define COMM_PRIVATE_PTR(m) \ + ((m->param.receiver) ? ((struct common_pcb *)m->param.comm_receiver) : 0) +#define TCP_PRIVATE_PTR(m) \ + ((m->param.receiver) ? (*(struct tcp_pcb **)m->param.receiver) : 0) +#define UDP_PRIVATE_PTR(m) \ + ((m->param.receiver) ? (*(struct udp_pcb **)m->param.receiver) : 0) +/*#define RAW_PRIVATE_PTR(m) \ + ((m->param.receiver) ? (*(void *)m->param.receiver) : 0) */ + +int spl_sbr_process (data_com_msg * m); +#endif /* _SPL_SBR_H_ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_sockets.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_sockets.h new file mode 100644 index 0000000..278bb02 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_sockets.h @@ -0,0 +1,252 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __STACKX_SOCKETS_H__ +#define __STACKX_SOCKETS_H__ + +#include <errno.h> +#include <stddef.h> /* for size_t */ +#include "arch/sys_arch.h" +#include "sys/socket.h" +#include <errno.h> +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +#ifndef socklen_t +#define socklen_t u32_t +#endif + +#define SET_STACKP_ERRNO(err) (errno = (err)) //thread-local errno + +#ifndef set_errno +#define set_errno(err) SET_STACKP_ERRNO(err) +#endif + +#define sock_set_errno(sk, e) do { \ + (sk)->err = (e); \ + if ((sk)->err != 0) \ + set_errno((sk)->err); \ + } while (0) + +#ifndef __BITS_SOCKET_H +/* Socket protocol types (TCP/UDP/RAW) */ +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 +/* + * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) + */ +#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info storing */ +#define SO_REUSEADDR 0x0002 +#endif + +#define SO_DONTROUTE 5 //0x0010 /* Unimplemented: just use interface addresses */ +#define SO_BROADCAST 6 //0x0020 /* permit to send and to receive broad cast messages*/ +#define SO_KEEPALIVE 9 //0x0008 gaussdb /* keep connections alive */ +#define SO_OOBINLINE 10 //0x0100 /* Unimplemented: leave received OOB data in line */ +#define SO_LINGER 13 //0x0080 /* linger on close if data present */ +#define SO_REUSEPORT 15 /* Unimplemented: allow local address & port reuse */ +#define SO_ACCEPTCONN 30 //0x0002 /* socket has had listen() */ +#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ + +#define SO_DONTLINGER ((int)(~SO_LINGER)) + +/* + * Additional options, not kept in so_options. + */ +#define SO_TYPE 3 /* get socket type */ +#define SO_ERROR 4 +#define SO_SNDBUF 7 /* send buffer size */ +#define SO_RCVBUF 8 /* receive buffer size */ +#define SO_NO_CHECK 11 /* don't create UDP checksum */ +#define SO_RCVLOWAT 18 /* receive low-water mark */ +#define SO_SNDLOWAT 19 /* send low-water mark */ +#define SO_RCVTIMEO 20 /* receive timeout */ +#define SO_SNDTIMEO 21 /* Unimplemented: send timeout */ + +#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 1 //0xfff + +#ifndef __BITS_SOCKET_H + +#define AF_UNSPEC 0 +#define PF_UNSPEC AF_UNSPEC +#define AF_INET 2 +#define PF_INET AF_INET + +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#define IPPROTO_UDPLITE 136 + +#define IPPROTO_IP 0 + +#define MSG_PEEK 0x02 +#define MSG_WAITALL 0x100 +#define MSG_OOB 0x01 +#define MSG_DONTWAIT 0x40 +#define MSG_MORE 0x8000 +#endif + +#define IP_TOS 1 +#define IP_TTL 2 + +#define RCV_WND 0x21 +#define RCV_ANN_WND 0x22 +#define INIT_CWND 0x23 +#define THRESHOLD_FACTOR 0x24 +#define TMR_INTERVAL 0x25 + +/* + * Options and types for UDP multicast traffic handling + */ +#ifndef __BITS_SOCKET_H +#define IP_ADD_MEMBERSHIP 3 +#define IP_DROP_MEMBERSHIP 4 +#define IP_MULTICAST_TTL 5 +#define IP_MULTICAST_IF 6 +#define IP_MULTICAST_LOOP 7 +#endif + +/* + * The Type of Service provides an indication of the abstract + * parameters of the quality of service desired. These parameters are + * to be used to guide the selection of the actual service parameters + * when transmitting a datagram through a particular network. Several + * networks offer service precedence, which somehow treats high + * precedence traffic as more important than other traffic (generally + * by accepting only traffic above a certain precedence at time of high + * load). The major choice is a three way tradeoff between low-delay, + * high-reliability, and high-throughput. + * The use of the Delay, Throughput, and Reliability indications may + * increase the cost (in some sense) of the service. In many networks + * better performance for one of these parameters is coupled with worse + * performance on another. Except for very unusual cases at most two + * of these three indications should be set. + */ +#define IPTOS_LOWCOST 0x02 +#define IPTOS_RELIABILITY 0x04 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_TOS_MASK 0x1E +#define IPTOS_MINCOST IPTOS_LOWCOST +#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) + +/* + * The Network Control precedence designation is intended to be used + * within a network only. The actual use and control of that + * designation is up to each network. The Internetwork Control + * designation is intended for use by gateway control originators only. + * If the actual use of these precedence designations is of concern to + * a particular network, it is the responsibility of that network to + * control the access to, and use of, those precedence designations. + */ +#define IPTOS_PREC_ROUTINE 0x00 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_MASK 0xe0 +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) + +#if !defined (FIONREAD) || !defined (FIONBIO) +#define IOC_VOID 0x20000000UL /* no parameters */ +#define IOC_OUT 0x40000000UL /* copy out parameters */ +#define IOC_IN 0x80000000UL /* copy in parameters */ +#define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ +#define IOC_INOUT (IOC_IN | IOC_OUT) /* 0x20000000 distinguishes new & old ioctl's */ + +#define _IO(x, y) (((x) << 8) | (y) |IOC_VOID ) + +#define _IOR(x, y, t) (IOC_OUT | (((long)sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y)) + +#define _IOW(x, y, t) (IOC_IN | (((long)sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y)) +#endif /* !defined(FIONREAD) || !defined(FIONBIO) */ + +#ifndef FIONREAD +#define FIONREAD _IOR('f', 127, unsigned long) +#endif +#ifndef FIONBIO +#define FIONBIO _IOW('f', 126, unsigned long) +#endif + +/*unimplemented */ +#ifndef SIOCSHIWAT +#define SIOCSHIWAT _IOW('s', 0, unsigned long) +#define SIOCGHIWAT _IOR('s', 1, unsigned long) +#define SIOCSLOWAT _IOW('s', 2, unsigned long) +#define SIOCGLOWAT _IOR('s', 3, unsigned long) +#ifndef __BITS_SOCKET_H +#define SIOCATMARK _IOR('s', 7, unsigned long) +#endif +#endif + +/* commands for fnctl */ +#ifndef F_GETFL +#define F_GETFL 3 +#endif +#ifndef F_SETFL +#define F_SETFL 4 +#endif + +/* File status flags and file access modes for fnctl, + these are bits in an int. */ +#ifndef O_NONBLOCK +#define O_NONBLOCK 0X800 /* nonblocking I/O */ +#endif +#ifndef O_NDELAY +#define O_NDELAY O_NONBLOCK /* same as O_NONBLOCK, for compatibility */ +#endif + +#ifndef O_CLOEXEC +#define O_CLOEXEC 0x80000 /* set close_on_exec */ +#endif +#ifndef __BITS_SOCKET_H +#define SOCK_CLOEXEC O_CLOEXEC +#endif +#ifndef FD_CLOEXEC +#define FD_CLOEXEC 1 +#endif +#ifndef SHUT_RD +#define SHUT_RD 0 +#define SHUT_WR 1 +#define SHUT_RDWR 2 +#endif + +struct pollfd +{ + + int fd; /* file descriptor */ + short events; /* wait event */ + short revents; /* actual event happened */ +}; + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __STACKX_SOCKETS_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_tcpip.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_tcpip.h new file mode 100644 index 0000000..0f885d6 --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_tcpip.h @@ -0,0 +1,80 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __STACKX_TCPIP_H__ +#define __STACKX_TCPIP_H__ + +#include "spl_opt.h" +#include "stackx/spl_ip_addr.h" +#include "tcp.h" + +#define USEAGE_LOW 60 +#define USEAGE_HIGHT 80 +#define USEAGE_INVALID 0xFF + +/*** Put into stackx_instance ********* + +************************************/ +#include "stackx/spl_api_msg.h" +#include "netifapi.h" +#include "stackx/spl_pbuf.h" +#include "stackx/spl_api.h" +#include "sys.h" +#include "netif.h" +#include "ip_module_api.h" +#include "internal_msg.h" +#include "pbuf.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** Function prototype for send timeout message */ +err_t ltt_apimsg (sys_timeout_handler h, void *arg); + +/** Function prototype for the init_done function passed to tcpip_init */ +typedef void (*tcpip_init_done_fn) (void *arg); + +/** Function prototype for functions passed to tcpip_callback() */ +typedef void (*tcpip_callback_fn) (void *ctx); + +int init_by_main_thread (); +int init_by_tcpip_thread (); +err_t spl_tcpip_input (struct pbuf *p, struct netif *inp); + +int post_ip_module_msg (void *arg, ip_module_type type, + ip_module_operate_type operate_type); +int process_ip_module_msg (void *arg, ip_module_type type, + ip_module_operate_type operate_type); +int init_new_network_configuration (); + +#if STACKX_NETIF_API +err_t tcpip_netif_add (msg_add_netif * tmp); +#endif /* STACKX_NETIF_API */ + +err_t ltt_clearTmrmsg (void *pcb, void *arg); + +sys_mbox_t get_primary_box (); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __STACKX_TCPIP_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_timers.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_timers.h new file mode 100644 index 0000000..4809b2b --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_timers.h @@ -0,0 +1,108 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __SPL_TIMERS_H__ +#define __SPL_TIMERS_H__ + +#include "opt.h" +#include "common_mem_base_type.h" + +typedef void (*sys_timeout_handler) (void *arg); + +#include "rb_tree.h" + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** Function prototype for a timeout callback function. Register such a function + * using sys_timeout(). + * + * @param arg Additional argument to pass to the function - set up by sys_timeout() + */ + +/* + * ************************************************************************* + * PTIMER defined 2013/3/15 + * ************************************************************************* + */ +#define PTIMER_DEFAULT 0x00 /* periodic mode */ +#define PTIMER_ONESHOT 0x01 +#define PTIMER_USER_DEF 0x02 + +enum msg_type +{ + SYS_PTIMEROUT_MSG, + SYS_UNPTIMEROUT_MSG, +}; + +struct msg_context +{ + unsigned long msec; + union + { + sys_timeout_handler handle; + } action; +#define _act_category action.act_category +#define _phandle action.handle + u32_t flags; /* oneshot|user_def|... */ + void *ctx; /* pcb ptr */ +}; + +struct ptimer_node +{ + struct rb_node node; + unsigned long abs_nsec; + struct msg_context info; + unsigned long state; + u16_t index; /* store a lwip thread message box id */ +}; + +struct ptimer_msg +{ + enum msg_type msg_type; + struct ptimer_node *node; + struct ptimer_msg *next, *prev; +}; + +struct ptimer_base +{ + struct rb_root active; + struct rb_node *first; /* point the recently timeout */ + pthread_mutex_t lock; + pthread_cond_t cond; + struct ptimer_msg *head, *tail; +}; + +/* + * ***************************************************** + * ptimer E-N-D + * ***************************************************** + */ +void ptimer_thread (void *arg); +void timeout_phandler (void *act, void *arg); +void regedit_ptimer (enum msg_type type, sys_timeout_handler handler, + struct ptimer_node *node); + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __LWIP_TIMERS_H__ */ diff --git a/stacks/lwip_stack/lwip_src/include/stackx/stackx_instance.h b/stacks/lwip_stack/lwip_src/include/stackx/stackx_instance.h new file mode 100644 index 0000000..679d2ac --- /dev/null +++ b/stacks/lwip_stack/lwip_src/include/stackx/stackx_instance.h @@ -0,0 +1,91 @@ +/* +* +* Copyright (c) 2018 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at: +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __STACKX_INSTANCE_H__ +#define __STACKX_INSTANCE_H__ + +#include "stackx/spl_tcpip.h" +#include "netif.h" +#include "lwip/ip4_frag.h" +#include "stackx/spl_pbuf.h" +#include "arch/sys_arch.h" +#include "arch/queue.h" +#include "stackx_tx_box.h" +#include "nsfw_msg.h" +#include "stackx_app_res.h" +#include "ip_module_api.h" +#include "tcp.h" +#include "udp.h" + +#define PKT_BURST 32 + +#define TASK_BURST 16 + +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +#define MAX_NETBUFS 1024*2 //define for C10M + +#define TOTAL_MSG_QUEUE_NUM (MSG_PRIO_QUEUE_NUM+1) /* three priority queue and one primary queue */ + +struct stackx_stat +{ + struct rti_queue primary_stat; //primary box stat + u64_t extend_member_bit; +}; + +struct stackx_stack +{ + struct queue primary_mbox; + struct queue priority_mbox[MSG_PRIO_QUEUE_NUM]; //0-highest; 1-medium; 2-lowest + //stackx_apis stackx_api; +}; + +struct disp_netif_list +{ + struct disp_netif_list *next; + struct netif *netif; +}; + +typedef struct stackx_instance +{ + uint16_t rss_queue_id; + + mpool_handle mp_tx; + //mring_handle mp_seg; + mring_handle cpcb_seg; + mring_handle lmsg_pool; + + struct stackx_stack lstack; + struct stackx_stat lstat; //point to p_stackx_table->lstat[i]; + + /** + * Header of the input packet currently being processed. + */ + /* global variables */ + struct disp_netif_list *netif_list; +} stackx_instance; + +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif + +#endif /* __STACKX_INSTANCE_H__ */ |