Support double lwip eport, use mongoose.a

This commit is contained in:
TXuian
2023-12-06 15:59:27 +08:00
parent e0e314e301
commit 616dc4584f
41 changed files with 417 additions and 10941 deletions
@@ -640,7 +640,8 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s));
sock = get_socket(s);
if (!sock) {
return -1;
KPrintf("sock = get_socket(s);\n");
return -1;
}
/* wait for a new connection */
@@ -655,6 +656,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
sock_set_errno(sock, err_to_errno(err));
}
done_socket(sock);
KPrintf("err = netconn_accept(sock->conn, &newconn);\n");
return -1;
}
LWIP_ASSERT("newconn != NULL", newconn != NULL);
@@ -664,6 +666,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
netconn_delete(newconn);
sock_set_errno(sock, ENFILE);
done_socket(sock);
KPrintf("newsock = alloc_socket(newconn, 1);\n");
return -1;
}
LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET));
@@ -701,6 +704,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
free_socket(nsock, 1);
sock_set_errno(sock, err_to_errno(err));
done_socket(sock);
KPrintf("err = netconn_peer(newconn, &naddr, &port);\n");
return -1;
}
@@ -1242,6 +1246,8 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n",
s, lwip_strerr(err)));
KPrintf("lwip_recvfrom[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n",
s, lwip_strerr(err));
sock_set_errno(sock, err_to_errno(err));
done_socket(sock);
return -1;
@@ -272,13 +272,16 @@ a lot of data that needs to be copied, this should be set high. */
#define MEMP_NUM_PBUF 32
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
per active UDP "connection". */
#define MEMP_NUM_UDP_PCB 4
#define MEMP_NUM_UDP_PCB 32
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
connections. */
#define MEMP_NUM_TCP_PCB 64
#define MEMP_NUM_TCP_PCB 32
#define MEMP_NUM_RAW_PCB 32
#define MEMP_NUM_REASSDATA 32
#define MEMP_NUM_NETCONN 32
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 2
#define MEMP_NUM_TCP_PCB_LISTEN 32
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
segments. */
#define MEMP_NUM_TCP_SEG 256
@@ -384,12 +387,6 @@ a lot of data that needs to be copied, this should be set high. */
/* ---------- ICMP options ---------- */
#define LWIP_ICMP 1
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
turning this on does currently not work. */
#define LWIP_DHCP 1
/* ---------- UDP options ---------- */
#define LWIP_UDP 1
#define UDP_TTL 255
@@ -521,7 +518,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. */
#define LWIP_DHCP 1
#define LWIP_DHCP 0
/* 1 if you want to do an ARP check on the offered address
(recommended). */
@@ -76,7 +76,7 @@ char lwip_eth0_ipaddr[20] = { 192, 168, 130, 77 };
char lwip_eth0_netmask[20] = { 255, 255, 254, 0 };
char lwip_eth0_gwaddr[20] = { 192, 168, 130, 1 };
char lwip_eth1_ipaddr[20] = { 192, 168, 130, 88 };
char lwip_eth1_ipaddr[20] = { 192, 168, 131, 88 };
char lwip_eth1_netmask[20] = { 255, 255, 254, 0 };
char lwip_eth1_gwaddr[20] = { 192, 168, 130, 1 };
@@ -346,7 +346,9 @@ void lwip_config_input(int eport, struct netif* net)
if (eport == 0) {
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
} else if (eport == 1) {
#ifdef NETIF_ENET1_INIT_FUNC
th_id = sys_thread_new("eth_input2", ethernetif_input2, net, LWIP_TASK_STACK_SIZE, 30);
#endif
}
}
@@ -360,7 +362,6 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
if (chk_lwip_bit(LWIP_INIT_FLAG)) {
lw_print("lw: [%s] already ...\n", __func__);
return;
}
set_lwip_bit(LWIP_INIT_FLAG);
@@ -384,12 +385,13 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lw_print("Not Netif driver for Eport 0\n");
return;
#endif
#ifdef NETIF_ENET0_INIT_FUNC
lw_print("Add netif eport 0\n");
netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET0_INIT_FUNC,
tcpip_input);
// netif_set_default(&gnetif);
// netif_set_up(&gnetif);
netif_set_default(&gnetif);
netif_set_up(&gnetif);
lw_print("\r\n************************************************\r\n");
lw_print(" Network Configuration\r\n");
@@ -404,6 +406,7 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lwip_config_input(enet_port, &gnetif);
is_init_0 = 1;
#endif
} else if (1 == enet_port) {
if (is_init_1 == 1) {
@@ -413,11 +416,12 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lw_print("Not Netif driver for Eport 1\n");
return;
#endif
#ifdef NETIF_ENET1_INIT_FUNC
lw_print("Add netif eport 1\n");
netif_add(&gnetif2, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET1_INIT_FUNC,
tcpip_input);
netif_set_default(&gnetif2);
// netif_set_default(&gnetif2);
netif_set_up(&gnetif2);
lw_print("\r\n************************************************\r\n");
@@ -433,5 +437,6 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lwip_config_input(enet_port, &gnetif2);
is_init_1 = 1;
#endif
}
}
@@ -228,6 +228,95 @@ ip4_route(const ip4_addr_t *dest)
return netif_default;
}
/**
* Finds the appropriate network interface for a given IP address. It
* searches the list of network interfaces linearly. A match is found
* if the masked IP address of the network interface equals the masked
* IP address given to the function.
*
* @param dest the destination IP address for which to find the route
* @return the netif on which to send to reach dest
*/
struct netif*
ip4_route2(const ip4_addr_t* src, const ip4_addr_t* dest)
{
#if !LWIP_SINGLE_NETIF
struct netif* netif;
LWIP_ASSERT_CORE_LOCKED();
#if LWIP_MULTICAST_TX_OPTIONS
/* Use administratively selected interface for multicast by default */
if (ip4_addr_ismulticast(dest) && ip4_default_multicast_netif) {
return ip4_default_multicast_netif;
}
#endif /* LWIP_MULTICAST_TX_OPTIONS */
/* bug #54569: in case LWIP_SINGLE_NETIF=1 and LWIP_DEBUGF() disabled, the following loop is optimized away */
LWIP_UNUSED_ARG(dest);
/* iterate through netifs */
NETIF_FOREACH(netif)
{
/* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
/* network mask matches? */
// if (ip4_addr_netcmp(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) {
if (ip4_addr_cmp(src, netif_ip4_addr(netif))) {
/* return netif on which to forward IP packet */
return netif;
}
/* gateway matches on a non broadcast interface? (i.e. peer in a point to point interface) */
if (((netif->flags & NETIF_FLAG_BROADCAST) == 0) && ip4_addr_cmp(dest, netif_ip4_gw(netif))) {
/* return netif on which to forward IP packet */
return netif;
}
}
}
#if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
/* loopif is disabled, looopback traffic is passed through any netif */
if (ip4_addr_isloopback(dest)) {
/* don't check for link on loopback traffic */
if (netif_default != NULL && netif_is_up(netif_default)) {
return netif_default;
}
/* default netif is not up, just use any netif for loopback traffic */
NETIF_FOREACH(netif)
{
if (netif_is_up(netif)) {
return netif;
}
}
return NULL;
}
#endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
netif = LWIP_HOOK_IP4_ROUTE_SRC(NULL, dest);
if (netif != NULL) {
return netif;
}
#elif defined(LWIP_HOOK_IP4_ROUTE)
netif = LWIP_HOOK_IP4_ROUTE(dest);
if (netif != NULL) {
return netif;
}
#endif
#endif /* !LWIP_SINGLE_NETIF */
if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) || ip4_addr_isany_val(*netif_ip4_addr(netif_default)) || ip4_addr_isloopback(dest)) {
/* No matching netif found and default netif is not usable.
If this is not good enough for you, use LWIP_HOOK_IP4_ROUTE() */
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_route: No route to %" U16_F ".%" U16_F ".%" U16_F ".%" U16_F "\n", ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
IP_STATS_INC(ip.rterr);
MIB2_STATS_INC(mib2.ipoutnoroutes);
return NULL;
}
return netif_default;
}
#if IP_FORWARD
/**
* Determine whether an IP address is in a reserved set of addresses
@@ -63,39 +63,41 @@ extern "C" {
#define ip_init() /* Compatibility define, no init needed. */
struct netif *ip4_route(const ip4_addr_t *dest);
struct netif* ip4_route2(const ip4_addr_t* src, const ip4_addr_t* dest);
#if LWIP_IPV4_SRC_ROUTING
struct netif *ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest);
struct netif* ip4_route_src(const ip4_addr_t* src, const ip4_addr_t* dest);
#else /* LWIP_IPV4_SRC_ROUTING */
#define ip4_route_src(src, dest) ip4_route(dest)
// #define ip4_route_src(src, dest) ip4_route(dest)
#define ip4_route_src(src, dest) ip4_route2(src, dest)
#endif /* LWIP_IPV4_SRC_ROUTING */
err_t ip4_input(struct pbuf *p, struct netif *inp);
err_t ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto);
err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
err_t ip4_input(struct pbuf* p, struct netif* inp);
err_t ip4_output(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto);
err_t ip4_output_if(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif);
err_t ip4_output_if_src(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif);
#if LWIP_NETIF_USE_HINTS
err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif_hint *netif_hint);
err_t ip4_output_hinted(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif_hint* netif_hint);
#endif /* LWIP_NETIF_USE_HINTS */
#if IP_OPTIONS_SEND
err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
u16_t optlen);
err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
u16_t optlen);
err_t ip4_output_if_opt(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif, void* ip_options,
u16_t optlen);
err_t ip4_output_if_opt_src(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif, void* ip_options,
u16_t optlen);
#endif /* IP_OPTIONS_SEND */
#if LWIP_MULTICAST_TX_OPTIONS
void ip4_set_default_multicast_netif(struct netif* default_multicast_netif);
void ip4_set_default_multicast_netif(struct netif* default_multicast_netif);
#endif /* LWIP_MULTICAST_TX_OPTIONS */
#define ip4_netif_get_local_ip(netif) (((netif) != NULL) ? netif_ip_addr4(netif) : NULL)
#if IP_DEBUG
void ip4_debug_print(struct pbuf *p);
void ip4_debug_print(struct pbuf* p);
#else
#define ip4_debug_print(p)
#endif /* IP_DEBUG */
@@ -521,7 +521,7 @@
* (only needed if you use the sequential API, like api_lib.c)
*/
#if !defined MEMP_NUM_NETBUF || defined __DOXYGEN__
#define MEMP_NUM_NETBUF 2
#define MEMP_NUM_NETBUF 8
#endif
/**
@@ -529,7 +529,7 @@
* (only needed if you use the sequential API, like api_lib.c)
*/
#if !defined MEMP_NUM_NETCONN || defined __DOXYGEN__
#define MEMP_NUM_NETCONN 4
#define MEMP_NUM_NETCONN 8
#endif
/**
@@ -538,7 +538,7 @@
* In that case, you need one per thread calling lwip_select.)
*/
#if !defined MEMP_NUM_SELECT_CB || defined __DOXYGEN__
#define MEMP_NUM_SELECT_CB 4
#define MEMP_NUM_SELECT_CB 4
#endif
/**
@@ -547,7 +547,7 @@
* (only needed if you use tcpip.c)
*/
#if !defined MEMP_NUM_TCPIP_MSG_API || defined __DOXYGEN__
#define MEMP_NUM_TCPIP_MSG_API 8
#define MEMP_NUM_TCPIP_MSG_API 8
#endif
/**
@@ -556,7 +556,7 @@
* (only needed if you use tcpip.c)
*/
#if !defined MEMP_NUM_TCPIP_MSG_INPKT || defined __DOXYGEN__
#define MEMP_NUM_TCPIP_MSG_INPKT 8
#define MEMP_NUM_TCPIP_MSG_INPKT 8
#endif
/**
@@ -564,7 +564,7 @@
* (before freeing the corresponding memory using lwip_freeaddrinfo()).
*/
#if !defined MEMP_NUM_NETDB || defined __DOXYGEN__
#define MEMP_NUM_NETDB 1
#define MEMP_NUM_NETDB 2
#endif
/**
@@ -572,7 +572,7 @@
* if DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1.
*/
#if !defined MEMP_NUM_LOCALHOSTLIST || defined __DOXYGEN__
#define MEMP_NUM_LOCALHOSTLIST 1
#define MEMP_NUM_LOCALHOSTLIST 2
#endif
/**