未验证 提交 f7a494d5 编写于 作者: O openharmony_ci 提交者: Gitee

!49 轻鸿蒙内核支持网络容器

Merge pull request !49 from zhushengle/net_container
......@@ -24,7 +24,7 @@
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LWIPDIR = "//third_party/lwip/src"
......@@ -52,6 +52,7 @@ COREFILES = [
"$LWIPDIR/core/tcp_out.c",
"$LWIPDIR/core/timeouts.c",
"$LWIPDIR/core/udp.c",
"$LWIPDIR/core/net_group.c",
]
CORE4FILES = [
......
......@@ -52,6 +52,7 @@ set(lwipcore_SRCS
${LWIP_DIR}/src/core/tcp_out.c
${LWIP_DIR}/src/core/timeouts.c
${LWIP_DIR}/src/core/udp.c
${LWIP_DIR}/src/core/net_group.c
)
set(lwipcore4_SRCS
${LWIP_DIR}/src/core/ipv4/autoip.c
......
......@@ -49,7 +49,8 @@ COREFILES=$(LWIPDIR)/core/init.c \
$(LWIPDIR)/core/tcp_in.c \
$(LWIPDIR)/core/tcp_out.c \
$(LWIPDIR)/core/timeouts.c \
$(LWIPDIR)/core/udp.c
$(LWIPDIR)/core/udp.c \
$(LWIPDIR)/core/net_group.c
CORE4FILES=$(LWIPDIR)/core/ipv4/autoip.c \
$(LWIPDIR)/core/ipv4/dhcp.c \
......
......@@ -606,7 +606,11 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
* @param msg the api_msg describing the connection type
*/
static void
#ifdef LOSCFG_NET_CONTAINER
pcb_new(struct api_msg *msg, struct net_group *group)
#else
pcb_new(struct api_msg *msg)
#endif
{
enum lwip_ip_addr_type iptype = IPADDR_TYPE_V4;
......@@ -625,6 +629,9 @@ pcb_new(struct api_msg *msg)
case NETCONN_RAW:
msg->conn->pcb.raw = raw_new_ip_type(iptype, msg->msg.n.proto);
if (msg->conn->pcb.raw != NULL) {
#ifdef LOSCFG_NET_CONTAINER
set_raw_pcb_net_group(msg->conn->pcb.raw, group);
#endif
#if LWIP_IPV6
/* ICMPv6 packets should always have checksum calculated by the stack as per RFC 3542 chapter 3.1 */
if (NETCONNTYPE_ISIPV6(msg->conn->type) && msg->conn->pcb.raw->protocol == IP6_NEXTH_ICMP6) {
......@@ -640,6 +647,9 @@ pcb_new(struct api_msg *msg)
case NETCONN_UDP:
msg->conn->pcb.udp = udp_new_ip_type(iptype);
if (msg->conn->pcb.udp != NULL) {
#ifdef LOSCFG_NET_CONTAINER
set_udp_pcb_net_group(msg->conn->pcb.udp, group);
#endif
#if LWIP_UDPLITE
if (NETCONNTYPE_ISUDPLITE(msg->conn->type)) {
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
......@@ -656,6 +666,9 @@ pcb_new(struct api_msg *msg)
case NETCONN_TCP:
msg->conn->pcb.tcp = tcp_new_ip_type(iptype);
if (msg->conn->pcb.tcp != NULL) {
#ifdef LOSCFG_NET_CONTAINER
set_tcp_pcb_net_group(msg->conn->pcb.tcp, group);
#endif
setup_tcp(msg->conn);
}
break;
......@@ -683,7 +696,11 @@ lwip_netconn_do_newconn(void *m)
msg->err = ERR_OK;
if (msg->conn->pcb.tcp == NULL) {
#ifdef LOSCFG_NET_CONTAINER
pcb_new(msg, get_curr_process_net_group());
#else
pcb_new(msg);
#endif
}
/* Else? This "new" connection already has a PCB allocated. */
/* Is this an error condition? Should it be deleted? */
......@@ -1248,6 +1265,7 @@ lwip_netconn_do_bind(void *m)
msg->err = err;
TCPIP_APIMSG_ACK(msg);
}
/**
* Bind a pcb contained in a netconn to an interface
* Called from netconn_bind_if.
......@@ -1261,8 +1279,17 @@ lwip_netconn_do_bind_if(void *m)
struct netif *netif;
struct api_msg *msg = (struct api_msg *)m;
err_t err;
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_ippcb(msg->conn->pcb.ip);
if (group != NULL) {
netif = netif_get_by_index(msg->msg.bc.if_idx, group);
} else {
netif = NULL;
}
#else
netif = netif_get_by_index(msg->msg.bc.if_idx);
#endif
if ((netif != NULL) && (msg->conn->pcb.tcp != NULL)) {
err = ERR_OK;
......@@ -2064,8 +2091,18 @@ lwip_netconn_do_join_leave_group_netif(void *m)
{
struct api_msg *msg = (struct api_msg *)m;
struct netif *netif;
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_ippcb(msg->conn->pcb.ip);
if (group != NULL) {
netif = netif_get_by_index(msg->msg.jl.if_idx, group);
} else {
netif = NULL;
}
#else
netif = netif_get_by_index(msg->msg.jl.if_idx);
#endif
if (netif == NULL) {
msg->err = ERR_IF;
goto done;
......
......@@ -63,8 +63,11 @@ netifapi_do_netif_add(struct tcpip_api_call_data *m)
/* cast through void* to silence alignment warnings.
* We know it works because the structs have been instantiated as struct netifapi_msg */
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
#ifdef LOSCFG_NET_CONTAINER
if (!netif_add( msg->netif, get_curr_process_net_group(),
#else
if (!netif_add( msg->netif,
#endif
#if LWIP_IPV4
API_EXPR_REF(msg->msg.add.ipaddr),
API_EXPR_REF(msg->msg.add.netmask),
......@@ -122,7 +125,11 @@ netifapi_do_index_to_name(struct tcpip_api_call_data *m)
* We know it works because the structs have been instantiated as struct netifapi_msg */
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
#ifdef LOSCFG_NET_CONTAINER
if (!netif_index_to_name(msg->msg.ifs.index, msg->msg.ifs.name, get_curr_process_net_group())) {
#else
if (!netif_index_to_name(msg->msg.ifs.index, msg->msg.ifs.name)) {
#endif
/* return failure via empty name */
msg->msg.ifs.name[0] = '\0';
}
......
......@@ -3696,7 +3696,11 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ipv6_mreq, NETCONN_UDP);
inet6_addr_to_ip6addr(&multi_addr, &imr->ipv6mr_multiaddr);
LWIP_ASSERT("Invalid netif index", imr->ipv6mr_interface <= 0xFFu);
#ifdef LOSCFG_NET_CONTAINER
netif = netif_get_by_index((u8_t)imr->ipv6mr_interface, get_net_group_from_ippcb(sock->conn->pcb.ip));
#else
netif = netif_get_by_index((u8_t)imr->ipv6mr_interface);
#endif
if (netif == NULL) {
err = EADDRNOTAVAIL;
break;
......
......@@ -57,6 +57,9 @@
#include "lwip/nd6.h"
#include "lwip/mld6.h"
#include "lwip/api.h"
#ifdef LOSCFG_NET_CONTAINER
#include "lwip/net_group.h"
#endif
#include "netif/ppp/ppp_opts.h"
#include "netif/ppp/ppp_impl.h"
......@@ -349,7 +352,11 @@ lwip_init(void)
mem_init();
memp_init();
pbuf_init();
#ifdef LOSCFG_NET_CONTAINER
netif_init(get_root_net_group());
#else
netif_init();
#endif
#if LWIP_IPV4
ip_init();
#if LWIP_ARP
......
......@@ -164,4 +164,18 @@ ip_input(struct pbuf *p, struct netif *inp)
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#ifdef LOSCFG_NET_CONTAINER
void set_ippcb_net_group(struct ip_pcb *pcb, struct net_group *group)
{
get_default_net_group_ops()->set_ippcb_net_group(pcb, group);
}
struct net_group *get_net_group_from_ippcb(struct ip_pcb *pcb)
{
if (pcb != NULL) {
return get_default_net_group_ops()->get_net_group_from_ippcb(pcb);
}
return NULL;
}
#endif
#endif /* LWIP_IPV4 || LWIP_IPV6 */
......@@ -438,7 +438,11 @@ dhcp_coarse_tmr(void)
struct netif *netif;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_coarse_tmr()\n"));
/* iterate through all network interfaces */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
/* only act on DHCP configured interfaces */
struct dhcp *dhcp = netif_dhcp_data(netif);
if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) {
......@@ -475,7 +479,11 @@ dhcp_fine_tmr(void)
{
struct netif *netif;
/* loop through netif's */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
struct dhcp *dhcp = netif_dhcp_data(netif);
/* only act on DHCP configured interfaces */
if (dhcp != NULL) {
......
......@@ -508,8 +508,11 @@ etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr)
ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr),
(u16_t)ethaddr->addr[0], (u16_t)ethaddr->addr[1], (u16_t)ethaddr->addr[2],
(u16_t)ethaddr->addr[3], (u16_t)ethaddr->addr[4], (u16_t)ethaddr->addr[5]));
#ifdef LOSCFG_NET_CONTAINER
netif = ip4_route(ipaddr, get_root_net_group());
#else
netif = ip4_route(ipaddr);
#endif
if (netif == NULL) {
return ERR_RTE;
}
......
......@@ -388,10 +388,18 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
{
ip4_addr_t iphdr_dst;
ip4_addr_copy(iphdr_dst, iphdr->dest);
#ifdef LOSCFG_NET_CONTAINER
netif = ip4_route_src(&iphdr_dst, &iphdr_src, get_root_net_group());
#else
netif = ip4_route_src(&iphdr_dst, &iphdr_src);
#endif
}
#else
#ifdef LOSCFG_NET_CONTAINER
netif = ip4_route(&iphdr_src, get_root_net_group());
#else
netif = ip4_route(&iphdr_src);
#endif
#endif
if (netif != NULL) {
/* calculate checksum */
......
......@@ -458,7 +458,11 @@ igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
LWIP_ERROR("igmp_joingroup: attempt to join allsystems address", (!ip4_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
/* loop through netif's */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
/* Should we join this interface ? */
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip4_addr_isany(ifaddr) || ip4_addr_cmp(netif_ip4_addr(netif), ifaddr)))) {
err = igmp_joingroup_netif(netif, groupaddr);
......@@ -555,7 +559,11 @@ igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
LWIP_ERROR("igmp_leavegroup: attempt to leave allsystems address", (!ip4_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
/* loop through netif's */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
/* Should we leave this interface ? */
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip4_addr_isany(ifaddr) || ip4_addr_cmp(netif_ip4_addr(netif), ifaddr)))) {
err_t res = igmp_leavegroup_netif(netif, groupaddr);
......@@ -641,8 +649,11 @@ void
igmp_tmr(void)
{
struct netif *netif;
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
struct igmp_group *group = netif_igmp_data(netif);
while (group != NULL) {
......
......@@ -126,7 +126,11 @@ ip4_set_default_multicast_netif(struct netif *default_multicast_netif)
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides the parameters.
*/
struct netif *
#ifdef LOSCFG_NET_CONTAINER
ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest, struct net_group *group)
#else
ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest)
#endif
{
if (src != NULL) {
/* when src==NULL, the hook is called from ip4_route(dest) */
......@@ -135,7 +139,11 @@ ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest)
return netif;
}
}
#ifdef LOSCFG_NET_CONTAINER
return ip4_route(dest, group);
#else
return ip4_route(dest);
#endif
}
#endif /* LWIP_HOOK_IP4_ROUTE_SRC */
......@@ -149,7 +157,11 @@ ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest)
* @return the netif on which to send to reach dest
*/
struct netif *
#ifdef LOSCFG_NET_CONTAINER
ip4_route(const ip4_addr_t *dest, struct net_group *group)
#else
ip4_route(const ip4_addr_t *dest)
#endif
{
#if !LWIP_SINGLE_NETIF
struct netif *netif;
......@@ -167,7 +179,11 @@ ip4_route(const ip4_addr_t *dest)
LWIP_UNUSED_ARG(dest);
/* iterate through netifs */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
/* 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? */
......@@ -187,11 +203,20 @@ ip4_route(const ip4_addr_t *dest)
/* loopif is disabled, looopback traffic is passed through any netif */
if (ip4_addr_isloopback(dest)) {
/* don't check for link on loopback traffic */
#ifdef LOSCFG_NET_CONTAINER
if (group->netif_default != NULL && netif_is_up(group->netif_default)) {
return group->netif_default;
#else
if (netif_default != NULL && netif_is_up(netif_default)) {
return netif_default;
#endif
}
/* default netif is not up, just use any netif for loopback traffic */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (netif_is_up(netif)) {
return netif;
}
......@@ -212,9 +237,14 @@ ip4_route(const ip4_addr_t *dest)
}
#endif
#endif /* !LWIP_SINGLE_NETIF */
#ifdef LOSCFG_NET_CONTAINER
if ((group->netif_default == NULL) || !netif_is_up(group->netif_default) ||
!netif_is_link_up(group->netif_default) ||
ip4_addr_isany_val(*netif_ip4_addr(group->netif_default)) || ip4_addr_isloopback(dest)) {
#else
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)) {
#endif
/* 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",
......@@ -223,8 +253,11 @@ ip4_route(const ip4_addr_t *dest)
MIB2_STATS_INC(mib2.ipoutnoroutes);
return NULL;
}
#ifdef LOSCFG_NET_CONTAINER
return group->netif_default;
#else
return netif_default;
#endif
}
#if IP_FORWARD
......@@ -441,6 +474,10 @@ ip4_input(struct pbuf *p, struct netif *inp)
IP_STATS_INC(ip.recv);
MIB2_STATS_INC(mib2.ipinreceives);
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_netif(inp);
#endif
/* identify the IP header */
iphdr = (struct ip_hdr *)p->payload;
if (IPH_V(iphdr) != 4) {
......@@ -552,7 +589,11 @@ ip4_input(struct pbuf *p, struct netif *inp)
#endif /* !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF */
{
#if !LWIP_SINGLE_NETIF
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (netif == inp) {
/* we checked that before already */
continue;
......@@ -1031,8 +1072,13 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
struct netif *netif;
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_curr_process_net_group();
if ((netif = ip4_route_src(src, dest, group)) == NULL) {
#else
if ((netif = ip4_route_src(src, dest)) == NULL) {
#endif
LWIP_DEBUGF(IP_DEBUG, ("ip4_output: 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);
......
......@@ -800,7 +800,11 @@ dhcp6_tmr(void)
{
struct netif *netif;
/* loop through netif's */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
struct dhcp6 *dhcp6 = netif_dhcp6_data(netif);
/* only act on DHCPv6 configured interfaces */
if (dhcp6 != NULL) {
......
......@@ -360,7 +360,11 @@ icmp6_send_response_with_addrs(struct pbuf *p, u8_t code, u32_t data, u8_t type,
/* Swap source and destination for the reply. */
reply_dest = src_addr;
reply_src = dest_addr;
#ifdef LOSCFG_NET_CONTAINER
netif = ip6_route(reply_src, reply_dest, get_root_net_group());
#else
netif = ip6_route(reply_src, reply_dest);
#endif
if (netif == NULL) {
ICMP6_STATS_INC(icmp6.rterr);
return;
......
......@@ -83,7 +83,11 @@
* @return the netif on which to send to reach dest
*/
struct netif *
#ifdef LOSCFG_NET_CONTAINER
ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest, struct net_group *group)
#else
ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
#endif
{
#if LWIP_SINGLE_NETIF
LWIP_UNUSED_ARG(src);
......@@ -95,12 +99,22 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
LWIP_ASSERT_CORE_LOCKED();
/* If single netif configuration, fast return. */
#ifdef LOSCFG_NET_CONTAINER
if ((group->netif_list != NULL) && (group->netif_list->next == NULL)) {
if (!netif_is_up(group->netif_list) || !netif_is_link_up(group->netif_list) ||
(ip6_addr_has_zone(dest) && !ip6_addr_test_zone(dest, group->netif_list))) {
#else
if ((netif_list != NULL) && (netif_list->next == NULL)) {
if (!netif_is_up(netif_list) || !netif_is_link_up(netif_list) ||
(ip6_addr_has_zone(dest) && !ip6_addr_test_zone(dest, netif_list))) {
#endif
return NULL;
}
#ifdef LOSCFG_NET_CONTAINER
return group->netif_list;
#else
return netif_list;
#endif
}
#if LWIP_IPV6_SCOPES
......@@ -113,7 +127,11 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
IP6_ADDR_ZONECHECK(dest);
/* Find a netif based on the zone. For custom mappings, one zone may map
* to multiple netifs, so find one that can actually send a packet. */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (ip6_addr_test_zone(dest, netif) &&
netif_is_up(netif) && netif_is_link_up(netif)) {
return netif;
......@@ -150,7 +168,11 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
#if LWIP_IPV6_SCOPES
if (ip6_addr_has_zone(src)) {
/* Find a netif matching the source zone (relatively cheap). */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (netif_is_up(netif) && netif_is_link_up(netif) &&
ip6_addr_test_zone(src, netif)) {
return netif;
......@@ -160,7 +182,11 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
#endif /* LWIP_IPV6_SCOPES */
{
/* Find a netif matching the source address (relatively expensive). */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (!netif_is_up(netif) || !netif_is_link_up(netif)) {
continue;
}
......@@ -193,7 +219,11 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
* such, the destination address may still match a local address, and so we
* still need to check for exact matches here. By (lwIP) policy, statically
* configured addresses do always have an implied local /64 subnet. */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (!netif_is_up(netif) || !netif_is_link_up(netif)) {
continue;
}
......@@ -216,7 +246,11 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
/* Try with the netif that matches the source address. Given the earlier rule
* for scoped source addresses, this applies to unscoped addresses only. */
if (!ip6_addr_isany(src)) {
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (!netif_is_up(netif) || !netif_is_link_up(netif)) {
continue;
}
......@@ -233,11 +267,20 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
/* loopif is disabled, loopback traffic is passed through any netif */
if (ip6_addr_isloopback(dest)) {
/* don't check for link on loopback traffic */
#ifdef LOSCFG_NET_CONTAINER
if (group->netif_default != NULL && netif_is_up(group->netif_default)) {
return group->netif_default;
#else
if (netif_default != NULL && netif_is_up(netif_default)) {
return netif_default;
#endif
}
/* default netif is not up, just use any netif for loopback traffic */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (netif_is_up(netif)) {
return netif;
}
......@@ -248,10 +291,19 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
#endif /* !LWIP_SINGLE_NETIF */
/* no matching netif found, use default netif, if up */
#ifdef LOSCFG_NET_CONTAINER
if ((group->netif_default == NULL) || !netif_is_up(group->netif_default) ||
!netif_is_link_up(group->netif_default)) {
#else
if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default)) {
#endif
return NULL;
}
#ifdef LOSCFG_NET_CONTAINER
return group->netif_default;
#else
return netif_default;
#endif
}
/**
......@@ -524,6 +576,10 @@ ip6_input(struct pbuf *p, struct netif *inp)
IP6_STATS_INC(ip6.recv);
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_netif(inp);
#endif
/* identify the IP header */
ip6hdr = (struct ip6_hdr *)p->payload;
if (IP6H_V(ip6hdr) != 6) {
......@@ -652,7 +708,11 @@ ip6_input(struct pbuf *p, struct netif *inp)
}
#endif /* !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF */
#if !LWIP_SINGLE_NETIF
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, group) {
#else
NETIF_FOREACH(netif) {
#endif
if (netif == inp) {
/* we checked that before already */
continue;
......@@ -1297,14 +1357,26 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_curr_process_net_group();
#endif
if (dest != LWIP_IP_HDRINCL) {
#ifdef LOSCFG_NET_CONTAINER
netif = ip6_route(src, dest, group);
#else
netif = ip6_route(src, dest);
#endif
} else {
/* IP header included in p, read addresses. */
ip6hdr = (struct ip6_hdr *)p->payload;
ip6_addr_copy_from_packed(src_addr, ip6hdr->src);
ip6_addr_copy_from_packed(dest_addr, ip6hdr->dest);
#ifdef LOSCFG_NET_CONTAINER
netif = ip6_route(&src_addr, &dest_addr, group);
#else
netif = ip6_route(&src_addr, &dest_addr);
#endif
dest = &dest_addr;
}
......
......@@ -320,7 +320,11 @@ mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
LWIP_ASSERT_CORE_LOCKED();
/* loop through netif's */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
/* Should we join this interface ? */
if (ip6_addr_isany(srcaddr) ||
netif_get_ip6_addr_match(netif, srcaddr) >= 0) {
......@@ -409,7 +413,11 @@ mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
LWIP_ASSERT_CORE_LOCKED();
/* loop through netif's */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
/* Should we leave this interface ? */
if (ip6_addr_isany(srcaddr) ||
netif_get_ip6_addr_match(netif, srcaddr) >= 0) {
......@@ -497,7 +505,11 @@ mld6_tmr(void)
{
struct netif *netif;
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
struct mld_group *group = netif_mld6_data(netif);
while (group != NULL) {
......
......@@ -1061,7 +1061,11 @@ nd6_tmr(void)
}
/* Process our own addresses, updating address lifetimes and/or DAD state. */
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
u8_t addr_state;
#if LWIP_IPV6_ADDRESS_LIFETIMES
......@@ -1142,7 +1146,11 @@ nd6_tmr(void)
/* Send router solicitation messages, if necessary. */
if (!nd6_tmr_rs_reduction) {
nd6_tmr_rs_reduction = (ND6_RTR_SOLICITATION_INTERVAL / ND6_TMR_INTERVAL) - 1;
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(netif, get_root_net_group()) {
#else
NETIF_FOREACH(netif) {
#endif
if ((netif->rs_count > 0) && netif_is_up(netif) &&
netif_is_link_up(netif) &&
!ip6_addr_isinvalid(netif_ip6_addr_state(netif, 0)) &&
......
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_NET_CONTAINER
#include "lwip/net_group.h"
#include "lwip/netif.h"
static struct netif root_loop_netif = {0};
static struct net_group root_net_group = {
.loop_netif = &root_loop_netif,
};
struct net_group *get_root_net_group(void)
{
return &root_net_group;
}
struct net_group *get_curr_process_net_group(void)
{
return get_default_net_group_ops()->get_curr_process_net_group();
}
static void do_set_netif_net_group(struct netif *netif, struct net_group *group)
{
(void)netif;
(void)group;
}
static struct net_group *do_get_net_group_from_netif(struct netif *netif)
{
(void)netif;
return get_root_net_group();
}
static void do_set_ippcb_net_group(struct ip_pcb *pcb, struct net_group *group)
{
(void)pcb;
(void)group;
}
static struct net_group *do_get_net_group_from_ippcb(struct ip_pcb *pcb)
{
(void)pcb;
return get_root_net_group();
}
static struct net_group_ops root_net_group_ops = {
.get_curr_process_net_group = get_root_net_group,
.set_netif_net_group = do_set_netif_net_group,
.get_net_group_from_netif = do_get_net_group_from_netif,
.set_ippcb_net_group = do_set_ippcb_net_group,
.get_net_group_from_ippcb = do_get_net_group_from_ippcb,
};
struct net_group_ops *default_net_group_ops = &root_net_group_ops;
void set_default_net_group_ops(struct net_group_ops *ops) {
default_net_group_ops = ops;
}
struct net_group_ops *get_default_net_group_ops(void) {
return default_net_group_ops;
}
#endif
......@@ -106,13 +106,17 @@
static netif_ext_callback_t *ext_callback;
#endif
#ifndef LOSCFG_NET_CONTAINER
#if !LWIP_SINGLE_NETIF
struct netif *netif_list;
#endif /* !LWIP_SINGLE_NETIF */
struct netif *netif_default;
#endif
#define netif_index_to_num(index) ((index) - 1)
#ifndef LOSCFG_NET_CONTAINER
static u8_t netif_num;
#endif
#if LWIP_NUM_NETIF_CLIENT_DATA > 0
static u8_t netif_client_id;
......@@ -138,7 +142,16 @@ static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const i
#endif
#ifdef LOSCFG_NET_CONTAINER
struct net_group *get_net_group_from_netif(struct netif *netif) {
if (netif != NULL) {
return get_default_net_group_ops()->get_net_group_from_netif(netif);
}
return NULL;
}
#else
static struct netif loop_netif;
#endif
/**
* Initialize a lwip network interface structure for a loopback interface
......@@ -174,7 +187,11 @@ netif_loopif_init(struct netif *netif)
#endif /* LWIP_HAVE_LOOPIF */
void
#ifdef LOSCFG_NET_CONTAINER
netif_init(struct net_group *group)
#else
netif_init(void)
#endif
{
#if LWIP_HAVE_LOOPIF
#if LWIP_IPV4
......@@ -187,19 +204,41 @@ netif_init(void)
#define LOOPIF_ADDRINIT
#endif /* LWIP_IPV4 */
#ifdef LOSCFG_NET_CONTAINER
struct netif *loop_netif = group->loop_netif;
#endif
#if NO_SYS
#ifdef LOSCFG_NET_CONTAINER
netif_add(loop_netif, group, LOOPIF_ADDRINIT NULL, netif_loopif_init, ip_input);
#else
netif_add(&loop_netif, LOOPIF_ADDRINIT NULL, netif_loopif_init, ip_input);
#endif
#else /* NO_SYS */
#ifdef LOSCFG_NET_CONTAINER
netif_add(loop_netif, group, LOOPIF_ADDRINIT NULL, netif_loopif_init, tcpip_input);
#else
netif_add(&loop_netif, LOOPIF_ADDRINIT NULL, netif_loopif_init, tcpip_input);
#endif
#endif /* NO_SYS */
#if LWIP_IPV6
#ifdef LOSCFG_NET_CONTAINER
IP_ADDR6_HOST(loop_netif->ip6_addr, 0, 0, 0, 0x00000001UL);
loop_netif->ip6_addr_state[0] = IP6_ADDR_VALID;
#else
IP_ADDR6_HOST(loop_netif.ip6_addr, 0, 0, 0, 0x00000001UL);
loop_netif.ip6_addr_state[0] = IP6_ADDR_VALID;
#endif
#endif /* LWIP_IPV6 */
#ifdef LOSCFG_NET_CONTAINER
netif_set_link_up(loop_netif);
netif_set_up(loop_netif);
#else
netif_set_link_up(&loop_netif);
netif_set_up(&loop_netif);
#endif
#endif /* LWIP_HAVE_LOOPIF */
}
......@@ -236,9 +275,17 @@ netif_input(struct pbuf *p, struct netif *inp)
* Same as @ref netif_add but without IPv4 addresses
*/
struct netif *
#ifdef LOSCFG_NET_CONTAINER
netif_add_noaddr(struct netif *netif, struct net_group *group, void *state, netif_init_fn init, netif_input_fn input)
#else
netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
#endif
{
#ifdef LOSCFG_NET_CONTAINER
return netif_add(netif, group,
#else
return netif_add(netif,
#endif
#if LWIP_IPV4
NULL, NULL, NULL,
#endif /* LWIP_IPV4*/
......@@ -273,7 +320,11 @@ netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_inp
* @return netif, or NULL if failed.
*/
struct netif *
#ifdef LOSCFG_NET_CONTAINER
netif_add(struct netif *netif, struct net_group *group,
#else
netif_add(struct netif *netif,
#endif
#if LWIP_IPV4
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
#endif /* LWIP_IPV4 */
......@@ -285,8 +336,16 @@ netif_add(struct netif *netif,
LWIP_ASSERT_CORE_LOCKED();
#ifdef LOSCFG_NET_CONTAINER
get_default_net_group_ops()->set_netif_net_group(netif, group);
#endif
#if LWIP_SINGLE_NETIF
#ifdef LOSCFG_NET_CONTAINER
if (group->loop_netif != NULL) {
#else
if (netif_default != NULL) {
#endif
LWIP_ASSERT("single netif already set", 0);
return NULL;
}
......@@ -351,7 +410,11 @@ netif_add(struct netif *netif,
/* remember netif specific state information data */
netif->state = state;
#ifdef LOSCFG_NET_CONTAINER
netif->num = group->netif_num;
#else
netif->num = netif_num;
#endif
netif->input = input;
NETIF_RESET_HINTS(netif);
......@@ -394,7 +457,11 @@ netif_add(struct netif *netif,
netif->num = 0;
}
num_netifs = 0;
#ifdef LOSCFG_NET_CONTAINER
for (netif2 = group->netif_list; netif2 != NULL; netif2 = netif2->next) {
#else
for (netif2 = netif_list; netif2 != NULL; netif2 = netif2->next) {
#endif
LWIP_ASSERT("netif already added", netif2 != netif);
num_netifs++;
LWIP_ASSERT("too many netifs, max. supported number is 255", num_netifs <= 255);
......@@ -406,14 +473,27 @@ netif_add(struct netif *netif,
} while (netif2 != NULL);
}
if (netif->num == 254) {
#ifdef LOSCFG_NET_CONTAINER
group->netif_num = 0;
#else
netif_num = 0;
#endif
} else {
#ifdef LOSCFG_NET_CONTAINER
group->netif_num = (u8_t)(netif->num + 1);
#else
netif_num = (u8_t)(netif->num + 1);
#endif
}
/* add this netif to the list */
#ifdef LOSCFG_NET_CONTAINER
netif->next = group->netif_list;
group->netif_list = netif;
#else
netif->next = netif_list;
netif_list = netif;
#endif
#endif /* "LWIP_SINGLE_NETIF */
mib2_netif_added(netif);
......@@ -748,7 +828,13 @@ netif_remove(struct netif *netif)
if (netif == NULL) {
return;
}
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_netif(netif);
if (group == NULL) {
return;
}
#endif
netif_invoke_ext_callback(netif, LWIP_NSC_NETIF_REMOVED, NULL);
#if LWIP_IPV4
......@@ -783,18 +869,35 @@ netif_remove(struct netif *netif)
mib2_remove_ip4(netif);
/* this netif is default? */
#ifdef LOSCFG_NET_CONTAINER
if (group->netif_default == netif) {
#else
if (netif_default == netif) {
#endif
/* reset default netif */
#ifdef LOSCFG_NET_CONTAINER
netif_set_default(NULL, group);
#else
netif_set_default(NULL);
#endif
}
#if !LWIP_SINGLE_NETIF
/* is it the first netif? */
#ifdef LOSCFG_NET_CONTAINER
if (group->netif_list == netif) {
group->netif_list = netif->next;
#else
if (netif_list == netif) {
netif_list = netif->next;
#endif
} else {
/* look for netif further down the list */
struct netif *tmp_netif;
#ifdef LOSCFG_NET_CONTAINER
NETIF_FOREACH(tmp_netif, group) {
#else
NETIF_FOREACH(tmp_netif) {
#endif
if (tmp_netif->next == netif) {
tmp_netif->next = netif->next;
break;
......@@ -822,7 +925,11 @@ netif_remove(struct netif *netif)
* @param netif the default network interface
*/
void
#ifdef LOSCFG_NET_CONTAINER
netif_set_default(struct netif *netif, struct net_group *group)
#else
netif_set_default(struct netif *netif)
#endif
{
LWIP_ASSERT_CORE_LOCKED();
......@@ -833,11 +940,22 @@ netif_set_default(struct netif *netif)
/* install default route */
mib2_add_route_ip4(1, netif);
}
#ifdef LOSCFG_NET_CONTAINER
group->netif_default = netif;
#else
netif_default = netif;
#endif
LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
}
#ifdef LOSCFG_NET_CONTAINER
void
netif_set_default2(struct netif *netif)
{
netif_set_default(netif, get_curr_process_net_group());
}
#endif
/**
* @ingroup netif
* Bring an interface up, available for processing
......@@ -1094,7 +1212,11 @@ netif_loop_output(struct netif *netif, struct pbuf *p)
* if not they are adjusted for 'netif'. */
#if MIB2_STATS
#if LWIP_HAVE_LOOPIF
#ifdef LOSCFG_NET_CONTAINER
struct netif *stats_if = get_net_group_from_netif(netif)->loop_netif;
#else
struct netif *stats_if = &loop_netif;
#endif
#else /* LWIP_HAVE_LOOPIF */
struct netif *stats_if = netif;
#endif /* LWIP_HAVE_LOOPIF */
......@@ -1219,7 +1341,11 @@ netif_poll(struct netif *netif)
* if not they are adjusted for 'netif'. */
#if MIB2_STATS
#if LWIP_HAVE_LOOPIF
#ifdef LOSCFG_NET_CONTAINER
struct netif *stats_if = get_net_group_from_netif(netif)->loop_netif;
#else
struct netif *stats_if = &loop_netif;
#endif
#else /* LWIP_HAVE_LOOPIF */
struct netif *stats_if = netif;
#endif /* LWIP_HAVE_LOOPIF */
......@@ -1671,9 +1797,17 @@ netif_name_to_index(const char *name)
* @param name char buffer of at least NETIF_NAMESIZE bytes
*/
char *
#ifdef LOSCFG_NET_CONTAINER
netif_index_to_name(u8_t idx, char *name, struct net_group *group)
#else
netif_index_to_name(u8_t idx, char *name)
#endif
{
#ifdef LOSCFG_NET_CONTAINER
struct netif *netif = netif_get_by_index(idx, group);
#else
struct netif *netif = netif_get_by_index(idx);
#endif
if (netif != NULL) {
name[0] = netif->name[0];
......@@ -1691,14 +1825,23 @@ netif_index_to_name(u8_t idx, char *name)
* @param idx index of netif to find
*/
struct netif *
#ifdef LOSCFG_NET_CONTAINER
netif_get_by_index(u8_t idx, struct net_group *group)
#else
netif_get_by_index(u8_t idx)
#endif
{
struct netif *netif;
LWIP_ASSERT_CORE_LOCKED();
#ifdef LOSCFG_NET_CONTAINER
if (idx != NETIF_NO_INDEX && group != NULL) {
NETIF_FOREACH(netif, group) {
#else
if (idx != NETIF_NO_INDEX) {
NETIF_FOREACH(netif) {
#endif
if (idx == netif_get_index(netif)) {
return netif; /* found! */
}
......
......@@ -135,6 +135,9 @@ raw_input_state_t
raw_input(struct pbuf *p, struct netif *inp)
{
struct raw_pcb *pcb, *prev;
#ifdef LOSCFG_NET_CONTAINER
struct net_group *inp_net_group = get_net_group_from_netif(inp);
#endif
s16_t proto;
raw_input_state_t ret = RAW_INPUT_NONE;
u8_t broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), ip_current_netif());
......@@ -164,7 +167,12 @@ raw_input(struct pbuf *p, struct netif *inp)
/* loop through all raw pcbs until the packet is eaten by one */
/* this allows multiple pcbs to match against the packet by design */
while (pcb != NULL) {
#ifdef LOSCFG_NET_CONTAINER
if (inp_net_group == get_net_group_from_raw_pcb(pcb) &&
(pcb->protocol == proto) && raw_input_local_match(pcb, broadcast) &&
#else
if ((pcb->protocol == proto) && raw_input_local_match(pcb, broadcast) &&
#endif
(((pcb->flags & RAW_FLAGS_CONNECTED) == 0) ||
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) {
/* receive callback function available? */
......@@ -362,8 +370,15 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_sendto\n"));
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_raw_pcb(pcb);
#endif
if (pcb->netif_idx != NETIF_NO_INDEX) {
#ifdef LOSCFG_NET_CONTAINER
netif = netif_get_by_index(pcb->netif_idx, group);
#else
netif = netif_get_by_index(pcb->netif_idx);
#endif
} else {
#if LWIP_MULTICAST_TX_OPTIONS
netif = NULL;
......@@ -371,13 +386,21 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
/* For multicast-destined packets, use the user-provided interface index to
* determine the outgoing interface, if an interface index is set and a
* matching netif can be found. Otherwise, fall back to regular routing. */
#ifdef LOSCFG_NET_CONTAINER
netif = netif_get_by_index(pcb->mcast_ifindex, group);
#else
netif = netif_get_by_index(pcb->mcast_ifindex);
#endif
}
if (netif == NULL)
#endif /* LWIP_MULTICAST_TX_OPTIONS */
{
#ifdef LOSCFG_NET_CONTAINER
netif = ip_route(&pcb->local_ip, ipaddr, group);
#else
netif = ip_route(&pcb->local_ip, ipaddr);
#endif
}
}
......@@ -580,6 +603,16 @@ raw_remove(struct raw_pcb *pcb)
memp_free(MEMP_RAW_PCB, pcb);
}
#ifdef LOSCFG_NET_CONTAINER
void set_raw_pcb_net_group(struct raw_pcb *pcb, struct net_group *group)
{
set_ippcb_net_group((struct ip_pcb *)pcb, group);
}
struct net_group *get_net_group_from_raw_pcb(struct raw_pcb *pcb) {
return get_net_group_from_ippcb((struct ip_pcb *)pcb);
}
#endif
/**
* @ingroup raw_raw
* Create a RAW PCB.
......
......@@ -194,6 +194,17 @@ static err_t tcp_close_shutdown_fin(struct tcp_pcb *pcb);
static void tcp_ext_arg_invoke_callbacks_destroyed(struct tcp_pcb_ext_args *ext_args);
#endif
#ifdef LOSCFG_NET_CONTAINER
void set_tcp_pcb_net_group(struct tcp_pcb *pcb, struct net_group *group)
{
set_ippcb_net_group((struct ip_pcb *)pcb, group);
}
struct net_group *get_net_group_from_tcp_pcb(const struct tcp_pcb *pcb)
{
return get_net_group_from_ippcb((struct ip_pcb *)pcb);
}
#endif
/**
* Initialize this module.
*/
......@@ -715,7 +726,11 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
/* Check if the address already is in use (on all lists) */
for (i = 0; i < max_pcb_list; i++) {
for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
#ifdef LOSCFG_NET_CONTAINER
if (cpcb->local_port == port && (get_net_group_from_tcp_pcb(pcb) == get_net_group_from_tcp_pcb(cpcb))) {
#else
if (cpcb->local_port == port) {
#endif
#if SO_REUSE
/* Omit checking for the same port if both pcbs have REUSEADDR set.
For SO_REUSEADDR, the duplicate-check for a 5-tuple is done in
......@@ -885,6 +900,9 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
res = ERR_MEM;
goto done;
}
#ifdef LOSCFG_NET_CONTAINER
set_tcp_pcb_net_group((struct tcp_pcb *)lpcb, get_net_group_from_tcp_pcb(pcb));
#endif
lpcb->callback_arg = pcb->callback_arg;
lpcb->local_port = pcb->local_port;
lpcb->state = LISTEN;
......@@ -1080,15 +1098,27 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_tcp_pcb(pcb);
LWIP_ERROR("tcp_connect: invalid net group", group != NULL, return ERR_RTE);
#endif
LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
ip_addr_set(&pcb->remote_ip, ipaddr);
pcb->remote_port = port;
if (pcb->netif_idx != NETIF_NO_INDEX) {
#ifdef LOSCFG_NET_CONTAINER
netif = netif_get_by_index(pcb->netif_idx, group);
#else
netif = netif_get_by_index(pcb->netif_idx);
#endif
} else {
/* check if we have a route to the remote host */
#ifdef LOSCFG_NET_CONTAINER
netif = ip_route(&pcb->local_ip, &pcb->remote_ip, group);
#else
netif = ip_route(&pcb->local_ip, &pcb->remote_ip);
#endif
}
if (netif == NULL) {
/* Don't even try to send a SYN packet if we have no route since that will fail. */
......
......@@ -119,6 +119,9 @@ tcp_input(struct pbuf *p, struct netif *inp)
{
struct tcp_pcb *pcb, *prev;
struct tcp_pcb_listen *lpcb;
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_netif(inp);
#endif
#if SO_REUSE
struct tcp_pcb *lpcb_prev = NULL;
struct tcp_pcb_listen *lpcb_any = NULL;
......@@ -259,7 +262,12 @@ tcp_input(struct pbuf *p, struct netif *inp)
continue;
}
#ifdef LOSCFG_NET_CONTAINER
if (group == get_net_group_from_tcp_pcb(pcb) &&
pcb->remote_port == tcphdr->src &&
#else
if (pcb->remote_port == tcphdr->src &&
#endif
pcb->local_port == tcphdr->dest &&
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()) &&
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
......@@ -292,7 +300,12 @@ tcp_input(struct pbuf *p, struct netif *inp)
continue;
}
#ifdef LOSCFG_NET_CONTAINER
if (group == get_net_group_from_tcp_pcb(pcb) &&
pcb->remote_port == tcphdr->src &&
#else
if (pcb->remote_port == tcphdr->src &&
#endif
pcb->local_port == tcphdr->dest &&
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()) &&
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
......@@ -323,7 +336,11 @@ tcp_input(struct pbuf *p, struct netif *inp)
continue;
}
#ifdef LOSCFG_NET_CONTAINER
if (group == get_net_group_from_tcp_pcb((struct tcp_pcb *)lpcb) && lpcb->local_port == tcphdr->dest) {
#else
if (lpcb->local_port == tcphdr->dest) {
#endif
if (IP_IS_ANY_TYPE_VAL(lpcb->local_ip)) {
/* found an ANY TYPE (IPv4/IPv6) match */
#if SO_REUSE
......@@ -640,6 +657,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
LWIP_ASSERT("tcp_listen_input: invalid pcb", pcb != NULL);
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_tcp_pcb((struct tcp_pcb *)pcb);
#endif
/* In the LISTEN state, we check for incoming SYN segments,
creates a new PCB, and responds with a SYN|ACK. */
if (flags & TCP_ACK) {
......@@ -668,6 +688,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
LWIP_UNUSED_ARG(err); /* err not useful here */
return;
}
#ifdef LOSCFG_NET_CONTAINER
set_tcp_pcb_net_group(npcb, group);
#endif
#if TCP_LISTEN_BACKLOG
pcb->accepts_pending++;
tcp_set_flags(npcb, TF_BACKLOGPEND);
......@@ -703,7 +726,11 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
npcb->snd_wnd_max = npcb->snd_wnd;
#if TCP_CALCULATE_EFF_SEND_MSS
#ifdef LOSCFG_NET_CONTAINER
npcb->mss = tcp_eff_send_mss(npcb->mss, &npcb->local_ip, &npcb->remote_ip, group);
#else
npcb->mss = tcp_eff_send_mss(npcb->mss, &npcb->local_ip, &npcb->remote_ip);
#endif
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
MIB2_STATS_INC(mib2.tcppassiveopens);
......@@ -792,6 +819,9 @@ tcp_process(struct tcp_pcb *pcb)
err_t err;
err = ERR_OK;
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_tcp_pcb(pcb);
#endif
LWIP_ASSERT("tcp_process: invalid pcb", pcb != NULL);
......@@ -867,7 +897,11 @@ tcp_process(struct tcp_pcb *pcb)
pcb->state = ESTABLISHED;
#if TCP_CALCULATE_EFF_SEND_MSS
#ifdef LOSCFG_NET_CONTAINER
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip, group);
#else
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip);
#endif
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss);
......
......@@ -132,11 +132,23 @@ static struct netif *
tcp_route(const struct tcp_pcb *pcb, const ip_addr_t *src, const ip_addr_t *dst)
{
LWIP_UNUSED_ARG(src); /* in case IPv4-only and source-based routing is disabled */
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_tcp_pcb(pcb);
LWIP_ERROR("tcp_route: invalid net group", group != NULL, return NULL);
#endif
if ((pcb != NULL) && (pcb->netif_idx != NETIF_NO_INDEX)) {
#ifdef LOSCFG_NET_CONTAINER
return netif_get_by_index(pcb->netif_idx, group);
#else
return netif_get_by_index(pcb->netif_idx);
#endif
} else {
#ifdef LOSCFG_NET_CONTAINER
return ip_route(src, dst, group);
#else
return ip_route(src, dst);
#endif
}
}
......
......@@ -80,6 +80,17 @@ static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
/* exported in udp.h (was static) */
struct udp_pcb *udp_pcbs;
#ifdef LOSCFG_NET_CONTAINER
void set_udp_pcb_net_group(struct udp_pcb *pcb, struct net_group *group)
{
set_ippcb_net_group((struct ip_pcb *)pcb, group);
}
struct net_group *get_net_group_from_udp_pcb(struct udp_pcb *pcb)
{
return get_net_group_from_ippcb((struct ip_pcb *)pcb);
}
#endif
/**
* Initialize this module.
*/
......@@ -196,6 +207,9 @@ udp_input(struct pbuf *p, struct netif *inp)
struct udp_hdr *udphdr;
struct udp_pcb *pcb, *prev;
struct udp_pcb *uncon_pcb;
#ifdef LOSCFG_NET_CONTAINER
struct net_group *inp_net_group = get_net_group_from_netif(inp);
#endif
u16_t src, dest;
u8_t broadcast;
u8_t for_us = 0;
......@@ -259,7 +273,11 @@ udp_input(struct pbuf *p, struct netif *inp)
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
/* compare PCB local addr+port to UDP destination addr+port */
#ifdef LOSCFG_NET_CONTAINER
if (inp_net_group == get_net_group_from_udp_pcb(pcb) && (pcb->local_port == dest) &&
#else
if ((pcb->local_port == dest) &&
#endif
(udp_input_local_match(pcb, inp, broadcast) != 0)) {
if ((pcb->flags & UDP_FLAGS_CONNECTED) == 0) {
if (uncon_pcb == NULL) {
......@@ -381,7 +399,11 @@ udp_input(struct pbuf *p, struct netif *inp)
if SOF_REUSEADDR is set on the first match */
struct udp_pcb *mpcb;
for (mpcb = udp_pcbs; mpcb != NULL; mpcb = mpcb->next) {
#ifdef LOSCFG_NET_CONTAINER
if (mpcb != pcb && inp_net_group == get_net_group_from_udp_pcb(mpcb)) {
#else
if (mpcb != pcb) {
#endif
/* compare PCB local addr+port to UDP destination addr+port */
if ((mpcb->local_port == dest) &&
(udp_input_local_match(mpcb, inp, broadcast) != 0)) {
......@@ -547,8 +569,16 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
#ifdef LOSCFG_NET_CONTAINER
struct net_group *group = get_net_group_from_udp_pcb(pcb);
LWIP_ERROR("udp_sendto: invalid net group", group != NULL, return ERR_VAL);
#endif
if (pcb->netif_idx != NETIF_NO_INDEX) {
#ifdef LOSCFG_NET_CONTAINER
netif = netif_get_by_index(pcb->netif_idx, group);
#else
netif = netif_get_by_index(pcb->netif_idx);
#endif
} else {
#if LWIP_MULTICAST_TX_OPTIONS
netif = NULL;
......@@ -560,7 +590,11 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
* list, but by doing so we skip a route lookup. If the interface index has
* gone stale, we fall through and do the regular route lookup after all. */
if (pcb->mcast_ifindex != NETIF_NO_INDEX) {
#ifdef LOSCFG_NET_CONTAINER
netif = netif_get_by_index(pcb->mcast_ifindex, group);
#else
netif = netif_get_by_index(pcb->mcast_ifindex);
#endif
}
#if LWIP_IPV4
else
......@@ -575,7 +609,11 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
fails, we try regular routing as though no override was set. */
if (!ip4_addr_isany_val(pcb->mcast_ip4) &&
!ip4_addr_cmp(&pcb->mcast_ip4, IP4_ADDR_BROADCAST)) {
#ifdef LOSCFG_NET_CONTAINER
netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4, group);
#else
netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4);
#endif
}
}
#endif /* LWIP_IPV4 */
......@@ -585,7 +623,11 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
#endif /* LWIP_MULTICAST_TX_OPTIONS */
{
/* find the outgoing network interface for this packet */
#ifdef LOSCFG_NET_CONTAINER
netif = ip_route(&pcb->local_ip, dst_ip, group);
#else
netif = ip_route(&pcb->local_ip, dst_ip);
#endif
}
}
......@@ -990,7 +1032,11 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
}
} else {
for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
#ifdef LOSCFG_NET_CONTAINER
if (pcb != ipcb && (get_net_group_from_udp_pcb(pcb) == get_net_group_from_udp_pcb(ipcb))) {
#else
if (pcb != ipcb) {
#endif
/* By default, we don't allow to bind to a port that any other udp
PCB is already bound to, unless *all* PCBs with that port have tha
REUSEADDR flag set. */
......
......@@ -47,6 +47,9 @@
#include "lwip/ip4.h"
#include "lwip/ip6.h"
#include "lwip/prot/ip.h"
#ifdef LOSCFG_NET_CONTAINER
#include "lwip/net_group.h"
#endif
#ifdef __cplusplus
extern "C" {
......@@ -69,10 +72,33 @@ extern "C" {
#define IP_PCB_NETIFHINT
#endif /* LWIP_NETIF_USE_HINTS */
#ifdef LOSCFG_NET_CONTAINER
#ifndef IP_PCB_NETGROUP
#define IP_PCB_NETGROUP
#endif
#endif
/** This is the common part of all PCB types. It needs to be at the
beginning of a PCB type definition. It is located here so that
changes to this common part are made in one location instead of
having to change all PCB structs. */
#ifdef LOSCFG_NET_CONTAINER
#define IP_PCB \
/* ip addresses in network byte order */ \
ip_addr_t local_ip; \
ip_addr_t remote_ip; \
/* Bound netif index */ \
u8_t netif_idx; \
/* Socket options */ \
u8_t so_options; \
/* Type Of Service */ \
u8_t tos; \
/* Time To Live */ \
u8_t ttl \
/* link layer address resolution hint */ \
IP_PCB_NETIFHINT \
IP_PCB_NETGROUP
#else
#define IP_PCB \
/* ip addresses in network byte order */ \
ip_addr_t local_ip; \
......@@ -87,6 +113,7 @@ extern "C" {
u8_t ttl \
/* link layer address resolution hint */ \
IP_PCB_NETIFHINT
#endif
struct ip_pcb {
/* Common members of all PCB types */
......@@ -259,10 +286,17 @@ extern struct ip_globals ip_data;
* @ingroup ip
* Get netif for address combination. See \ref ip6_route and \ref ip4_route
*/
#ifdef LOSCFG_NET_CONTAINER
#define ip_route(src, dest, group) \
(IP_IS_V6(dest) ? \
ip6_route(ip_2_ip6(src), ip_2_ip6(dest), group) : \
ip4_route_src(ip_2_ip4(src), ip_2_ip4(dest), group))
#else
#define ip_route(src, dest) \
(IP_IS_V6(dest) ? \
ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \
ip4_route_src(ip_2_ip4(src), ip_2_ip4(dest)))
#endif
/**
* @ingroup ip
* Get netif for IP.
......@@ -321,6 +355,10 @@ err_t ip_input(struct pbuf *p, struct netif *inp);
(ipaddr) = ip_netif_get_local_ip(netif, dest); \
}while(0)
#ifdef LOSCFG_NET_CONTAINER
void set_ippcb_net_group(struct ip_pcb *pcb, struct net_group *group);
struct net_group *get_net_group_from_ippcb(struct ip_pcb *pcb);
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -62,11 +62,19 @@ extern "C" {
#define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP)
#define ip_init() /* Compatibility define, no init needed. */
#ifdef LOSCFG_NET_CONTAINER
struct netif *ip4_route(const ip4_addr_t *dest, struct net_group *group);
#else
struct netif *ip4_route(const ip4_addr_t *dest);
#endif
#if LWIP_IPV4_SRC_ROUTING
struct netif *ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest);
#else /* LWIP_IPV4_SRC_ROUTING */
#ifdef LOSCFG_NET_CONTAINER
#define ip4_route_src(src, dest, group) ip4_route(dest, group)
#else
#define ip4_route_src(src, dest) ip4_route(dest)
#endif
#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,
......
......@@ -57,7 +57,11 @@
extern "C" {
#endif
#ifdef LOSCFG_NET_CONTAINER
struct netif *ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest, struct net_group *group);
#else
struct netif *ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest);
#endif
const ip_addr_t *ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest);
err_t ip6_input(struct pbuf *p, struct netif *inp);
err_t ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
......
......@@ -246,12 +246,20 @@ enum lwip_ipv6_scope_type
* @param dest the IPv6 address for which to select and set a zone.
* @param src source IPv6 address (const); may be equal to dest.
*/
#ifdef LOSCFG_NET_CONTAINER
#define ip6_addr_select_zone(dest, src) do { struct netif *selected_netif; \
selected_netif = ip6_route((src), (dest), get_root_net_group()); \
if (selected_netif != NULL) { \
ip6_addr_assign_zone((dest), IP6_UNKNOWN, selected_netif); \
} } while (0)
#else
#define ip6_addr_select_zone(dest, src) do { struct netif *selected_netif; \
selected_netif = ip6_route((src), (dest)); \
if (selected_netif != NULL) { \
ip6_addr_assign_zone((dest), IP6_UNKNOWN, selected_netif); \
} } while (0)
#endif
/**
* @}
*/
......
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef LOSCFG_NET_CONTAINER
#ifndef _NET_GROUP_H
#define _NET_GROUP_H
#include "lwip/arch.h"
struct netif;
struct ip_pcb;
struct net_group {
u8_t netif_num;
/** The default network interface. */
struct netif *netif_default;
/** The list of network interfaces. */
struct netif *netif_list;
struct netif *loop_netif;
};
struct net_group_ops {
struct net_group *(*get_curr_process_net_group)(void);
void (*set_netif_net_group)(struct netif *, struct net_group *);
struct net_group *(*get_net_group_from_netif)(struct netif *);
void (*set_ippcb_net_group)(struct ip_pcb *, struct net_group *);
struct net_group *(*get_net_group_from_ippcb)(struct ip_pcb *);
};
struct net_group *get_root_net_group(void);
struct net_group *get_curr_process_net_group(void);
struct net_group_ops *get_default_net_group_ops(void);
void set_default_net_group_ops(struct net_group_ops *ops);
#endif
#endif /* _NET_GROUP_H */
......@@ -48,6 +48,9 @@
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#ifdef LOSCFG_NET_CONTAINER
#include "lwip/net_group.h"
#endif
#ifdef __cplusplus
extern "C" {
......@@ -403,21 +406,46 @@ struct netif {
#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
#if LWIP_SINGLE_NETIF
#ifdef LOSCFG_NET_CONTAINER
#define NETIF_FOREACH(netif, group) if (((netif) = group->netif_default) != NULL)
#else
#define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL)
#endif
#else /* LWIP_SINGLE_NETIF */
#ifdef LOSCFG_NET_CONTAINER
#define NETIF_FOREACH(netif, group) for ((netif) = group->netif_list; (netif) != NULL; (netif) = (netif)->next)
#else
/** The list of network interfaces. */
extern struct netif *netif_list;
#define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next)
#endif
#endif /* LWIP_SINGLE_NETIF */
#ifndef LOSCFG_NET_CONTAINER
/** The default network interface. */
extern struct netif *netif_default;
#endif
#ifdef LOSCFG_NET_CONTAINER
struct net_group *get_net_group_from_netif(struct netif *netif);
void netif_init(struct net_group *group);
#else
void netif_init(void);
#endif
#ifdef LOSCFG_NET_CONTAINER
struct netif *netif_add_noaddr(struct netif *netif, struct net_group *group,
void *state, netif_init_fn init, netif_input_fn input);
#else
struct netif *netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input);
#endif
#if LWIP_IPV4
#ifdef LOSCFG_NET_CONTAINER
struct netif *netif_add(struct netif *netif, struct net_group *group,
#else
struct netif *netif_add(struct netif *netif,
#endif
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
void *state, netif_init_fn init, netif_input_fn input);
void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
......@@ -433,7 +461,12 @@ void netif_remove(struct netif * netif);
structure. */
struct netif *netif_find(const char *name);
#ifdef LOSCFG_NET_CONTAINER
void netif_set_default(struct netif *netif, struct net_group *group);
void netif_set_default2(struct netif *netif);
#else
void netif_set_default(struct netif *netif);
#endif
#if LWIP_IPV4
void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
......@@ -553,8 +586,13 @@ err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t
#endif /* LWIP_NETIF_USE_HINTS */
u8_t netif_name_to_index(const char *name);
#ifdef LOSCFG_NET_CONTAINER
char * netif_index_to_name(u8_t idx, char *name, struct net_group *group);
struct netif* netif_get_by_index(u8_t idx, struct net_group *group);
#else
char * netif_index_to_name(u8_t idx, char *name);
struct netif* netif_get_by_index(u8_t idx);
#endif
/* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/
#define netif_get_index(netif) ((u8_t)((netif)->num + 1))
......
......@@ -96,7 +96,11 @@ err_t netifapi_netif_index_to_name(u8_t index, char *name);
/** @ingroup netifapi_netif
* @see netif_set_default()
*/
#ifdef LOSCFG_NET_CONTAINER
#define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default2, NULL)
#else
#define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL)
#endif
/** @ingroup netifapi_netif
* @see netif_set_link_up()
*/
......
......@@ -478,8 +478,13 @@ void tcp_trigger_input_pcb_close(void);
#if TCP_CALCULATE_EFF_SEND_MSS
u16_t tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif,
const ip_addr_t *dest);
#ifdef LOSCFG_NET_CONTAINER
#define tcp_eff_send_mss(sendmss, src, dest, group) \
tcp_eff_send_mss_netif(sendmss, ip_route(src, dest, group), dest)
#else
#define tcp_eff_send_mss(sendmss, src, dest) \
tcp_eff_send_mss_netif(sendmss, ip_route(src, dest), dest)
#endif
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
#if LWIP_CALLBACK_API
......
......@@ -101,6 +101,10 @@ struct raw_pcb {
/* The following functions is the application layer interface to the
RAW code. */
#ifdef LOSCFG_NET_CONTAINER
void set_raw_pcb_net_group(struct raw_pcb *pcb, struct net_group *group);
struct net_group *get_net_group_from_raw_pcb(struct raw_pcb *pcb);
#endif
struct raw_pcb * raw_new (u8_t proto);
struct raw_pcb * raw_new_ip_type(u8_t type, u8_t proto);
void raw_remove (struct raw_pcb *pcb);
......
......@@ -408,6 +408,10 @@ err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
#endif /* LWIP_EVENT_API */
/* Application program's interface: */
#ifdef LOSCFG_NET_CONTAINER
void set_tcp_pcb_net_group(struct tcp_pcb *pcb, struct net_group *group);
struct net_group *get_net_group_from_tcp_pcb(const struct tcp_pcb *pcb);
#endif
struct tcp_pcb * tcp_new (void);
struct tcp_pcb * tcp_new_ip_type (u8_t type);
......
......@@ -116,6 +116,10 @@ extern struct udp_pcb *udp_pcbs;
/* The following functions is the application layer interface to the
UDP code. */
#ifdef LOSCFG_NET_CONTAINER
void set_udp_pcb_net_group(struct udp_pcb *pcb, struct net_group *group);
struct net_group *get_net_group_from_udp_pcb(struct udp_pcb *pcb);
#endif
struct udp_pcb * udp_new (void);
struct udp_pcb * udp_new_ip_type(u8_t type);
void udp_remove (struct udp_pcb *pcb);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册