summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-04-18 15:48:19 (GMT)
committer Hanhui <sylixos@gmail.com>2019-04-18 15:48:19 (GMT)
commit80679bc07b157813c48c7bb735c4add2ad19ede7 (patch)
tree8e3f9d05a8125d3cab856aabdb4a6fa34a138113
parent70a69e4ee08f8689f966808af8e053f64e6c113a (diff)
parenteaed3abbc627f342c1141bd2d9d80ece7d60d0c8 (diff)
downloadAIC-OS-80679bc07b157813c48c7bb735c4add2ad19ede7.zip
Merge branch 'AIC-OS'
-rw-r--r--SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c4
-rw-r--r--SylixOS/config/cpu/cpu_cfg_mips.h2
-rw-r--r--SylixOS/debug/gdb/gdbserver.c4
-rw-r--r--SylixOS/driver/can/sja1000.c15
-rw-r--r--SylixOS/driver/can/sja1000.h2
-rw-r--r--SylixOS/driver/net/dm9000.c6
-rw-r--r--SylixOS/driver/net/smethnd.c4
-rw-r--r--SylixOS/fs/mtd/nand/nand_base.c10
-rw-r--r--SylixOS/include/net/if_arp.h15
-rw-r--r--SylixOS/include/net/if_hwaddr.h59
-rw-r--r--SylixOS/include/network/lwip/netif.h14
-rw-r--r--SylixOS/include/network/lwip/snmp.h5
-rw-r--r--SylixOS/include/sys/wait.h2
-rw-r--r--SylixOS/kernel/core/_CandTable.c11
-rw-r--r--SylixOS/kernel/include/k_kernel.h2
-rw-r--r--SylixOS/kernel/interface/ThreadDelete.c4
-rw-r--r--SylixOS/kernel/show/ThreadShow.c2
-rw-r--r--SylixOS/loader/include/loader_vppatch.h5
-rw-r--r--SylixOS/loader/src/loader_vppatch.c119
-rw-r--r--SylixOS/loader/src/loader_vpthread.c12
-rw-r--r--SylixOS/loader/src/loader_wait.c66
-rw-r--r--SylixOS/net/libc/getifaddrs.c20
-rw-r--r--SylixOS/net/lwip/bonding/netbonding.c23
-rw-r--r--SylixOS/net/lwip/bridge/netbridge.c25
-rw-r--r--SylixOS/net/lwip/lwip_fix.c6
-rw-r--r--SylixOS/net/lwip/lwip_fix.h14
-rw-r--r--SylixOS/net/lwip/lwip_ifctl.c24
-rw-r--r--SylixOS/net/lwip/netdev/netdesc.c33
-rw-r--r--SylixOS/net/lwip/netdev/netdev.c50
-rw-r--r--SylixOS/net/lwip/netdev/netdev.h6
-rw-r--r--SylixOS/net/lwip/netdev/vnetdev.c3
-rw-r--r--SylixOS/net/lwip/src/api/api_lib.c1
-rw-r--r--SylixOS/net/lwip/src/api/api_msg.c1
-rw-r--r--SylixOS/net/lwip/src/core/ipv4/ip4.c28
-rw-r--r--SylixOS/net/lwip/src/core/netif.c4
-rw-r--r--SylixOS/net/lwip/src/core/pbuf.c14
-rw-r--r--SylixOS/net/lwip/tools/nat/lwip_natlib.c265
-rw-r--r--SylixOS/net/lwip/tools/qos/lwip_qos.c8
-rw-r--r--SylixOS/posix/include/px_pthread.h4
-rw-r--r--SylixOS/posix/include/px_pthread_np.h1
-rw-r--r--SylixOS/posix/pthread/pthread.c36
-rw-r--r--SylixOS/posix/pthread/pthread_attr.c59
-rw-r--r--SylixOS/posix/pthread/pthread_key.c18
-rw-r--r--SylixOS/shell/ttinyShell/ttinyShellLib.c16
-rw-r--r--SylixOS/shell/ttinyShell/ttinyShellSysCmd.c4
-rw-r--r--SylixOS/system/signal/signal.c22
-rw-r--r--SylixOS/system/signal/signalEvent.c12
-rw-r--r--SylixOS/system/signal/signalLib.c231
-rw-r--r--SylixOS/vpmpdm/net/getifaddrs.c20
49 files changed, 957 insertions, 354 deletions
diff --git a/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c b/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c
index caad1ac..3f23695 100644
--- a/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c
+++ b/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c
@@ -35,9 +35,11 @@
*********************************************************************************************************/
VOID armv7mIntHandle (UINT32 uiVector)
{
- archIntEnableForce(); /* 打开中断, 允许嵌套 */
+ KN_INT_ENABLE_FORCE(); /* 打开中断, 允许嵌套 */
API_InterVectorIsr((ULONG)uiVector);
+
+ KN_INT_DISABLE(); /* 禁能中断 */
}
/*********************************************************************************************************
** 函数名称: armv7mNMIIntHandle
diff --git a/SylixOS/config/cpu/cpu_cfg_mips.h b/SylixOS/config/cpu/cpu_cfg_mips.h
index f77f092..af86c45 100644
--- a/SylixOS/config/cpu/cpu_cfg_mips.h
+++ b/SylixOS/config/cpu/cpu_cfg_mips.h
@@ -136,7 +136,7 @@
LL/SC nesting detect fail bug
*********************************************************************************************************/
-#if (LW_CFG_MIPS_CPU_LOONGSON3 > 0) || (LW_CFG_MIPS_CPU_LOONGSON2K > 0) || defined(_MIPS_ARCH_HR2)
+#if (LW_CFG_MIPS_CPU_LOONGSON3 > 0) || (LW_CFG_MIPS_CPU_LOONGSON2K > 0)
#define LW_CFG_MIPS_NEST_LLSC_BUG 1
#else
#define LW_CFG_MIPS_NEST_LLSC_BUG 0
diff --git a/SylixOS/debug/gdb/gdbserver.c b/SylixOS/debug/gdb/gdbserver.c
index 17d0e59..f77fb34 100644
--- a/SylixOS/debug/gdb/gdbserver.c
+++ b/SylixOS/debug/gdb/gdbserver.c
@@ -2456,8 +2456,8 @@ static VOID gdbExit (INT iSigNo)
}
if (!pparam->GDB_bAttached && !pparam->GDB_bExited) { /* 如果不是attch则停止进程 */
- kill(pparam->GDB_iPid, SIGABRT); /* 强制进程停止 */
- LW_GDB_MSG("[GDB]Warning: Process is killed (SIGABRT) by GDB server.\n"
+ kill(pparam->GDB_iPid, SIGKILL); /* 强制进程停止 */
+ LW_GDB_MSG("[GDB]Warning: Process is killed (SIGKILL) by GDB server.\n"
" Restart SylixOS is recommended!\n");
}
#if LW_CFG_SMP_EN > 0
diff --git a/SylixOS/driver/can/sja1000.c b/SylixOS/driver/can/sja1000.c
index 2761c15..d3cb6d4 100644
--- a/SylixOS/driver/can/sja1000.c
+++ b/SylixOS/driver/can/sja1000.c
@@ -700,14 +700,13 @@ static INT sja1000Ioctl (SJA1000_CHAN *pcanchan, INT cmd, LONG arg)
sja1000TxStartup(pcanchan);
break;
- case CAN_DEV_GET_DEV_ECC_CODE: /* 获取错误代码捕捉寄存器的值 */
- mode = GET_REG(pcanchan, ECC);
- *(UINT8 *)arg = mode;
- break;
-
- case CAN_DEV_GET_DEV_IDT_CODE: /* 获取仲裁丢失捕捉寄存器的值 */
- mode = GET_REG(pcanchan, ALC);
- *(UINT8 *)arg = mode;
+ case SJA1000_SET_FLITER: /* sja1000 filter */
+ if (arg) {
+ SJA1000_FILTER *pfilter = (SJA1000_FILTER *)arg;
+ pcanchan->filter.acr_code = pfilter->acr_code;
+ pcanchan->filter.amr_code = pfilter->amr_code;
+ pcanchan->filter.mode = pfilter->mode;
+ }
break;
default:
diff --git a/SylixOS/driver/can/sja1000.h b/SylixOS/driver/can/sja1000.h
index 46fe39c..145ec4b 100644
--- a/SylixOS/driver/can/sja1000.h
+++ b/SylixOS/driver/can/sja1000.h
@@ -185,6 +185,8 @@ typedef struct sja1000_filter {
int mode; /* 1:singel 0:double */
} SJA1000_FILTER;
+#define SJA1000_SET_FLITER (FIOUSRFUNC + 1) /* set sja1000 filter */
+
/*********************************************************************************************************
sja1000 can channel
*********************************************************************************************************/
diff --git a/SylixOS/driver/net/dm9000.c b/SylixOS/driver/net/dm9000.c
index 15f9f83..0edee26 100644
--- a/SylixOS/driver/net/dm9000.c
+++ b/SylixOS/driver/net/dm9000.c
@@ -808,6 +808,7 @@ static void dm9000_receive (struct netdev *netdev, int (*input)(struct netdev *
UINT8 rx_byte;
UINT16 rx_len;
UINT16 rx_status;
+ int mcast;
int good_pkt;
int err;
@@ -863,7 +864,8 @@ static void dm9000_receive (struct netdev *netdev, int (*input)(struct netdev *
(priv->inblk)(dm9000, q->payload, q->len);
}
- err = input(netdev, p);
+ mcast = ((UINT8 *)p->payload)[0] & 1;
+ err = input(netdev, p);
if (err) {
netdev_pbuf_free(p);
p = NULL;
@@ -874,7 +876,7 @@ static void dm9000_receive (struct netdev *netdev, int (*input)(struct netdev *
} else {
netdev_linkinfo_recv_inc(netdev);
netdev_statinfo_total_add(netdev, LINK_INPUT, rx_len);
- if (((UINT8 *)p->payload)[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev, LINK_INPUT);
diff --git a/SylixOS/driver/net/smethnd.c b/SylixOS/driver/net/smethnd.c
index 68dcc8b..df6065d 100644
--- a/SylixOS/driver/net/smethnd.c
+++ b/SylixOS/driver/net/smethnd.c
@@ -257,6 +257,7 @@ static void smethnd_receive (struct netdev *netdev, int (*input)(struct netdev
addr_t packet_base;
size_t offset;
struct pbuf *p, *q;
+ int mcast;
if (!config->block_msg) {
return;
@@ -280,6 +281,7 @@ static void smethnd_receive (struct netdev *netdev, int (*input)(struct netdev
offset += q->len;
}
+ mcast = ((UINT8 *)p->payload)[0] & 1;
if (input(netdev, p)) {
netdev_pbuf_free(p);
p = NULL;
@@ -290,7 +292,7 @@ static void smethnd_receive (struct netdev *netdev, int (*input)(struct netdev
} else {
netdev_linkinfo_recv_inc(netdev);
netdev_statinfo_total_add(netdev, LINK_INPUT, packet->len);
- if (((UINT8 *)p->payload)[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev, LINK_INPUT);
diff --git a/SylixOS/fs/mtd/nand/nand_base.c b/SylixOS/fs/mtd/nand/nand_base.c
index 46c474f..4ae30a7 100644
--- a/SylixOS/fs/mtd/nand/nand_base.c
+++ b/SylixOS/fs/mtd/nand/nand_base.c
@@ -85,6 +85,7 @@ static struct nand_ecclayout nand_oob_8 = {
.length = 2} }
};
+#ifdef NO_YAFFS_512_COMPAT
static struct nand_ecclayout nand_oob_16 = {
.eccbytes = 6,
.eccpos = {0, 1, 2, 3, 6, 7},
@@ -92,6 +93,15 @@ static struct nand_ecclayout nand_oob_16 = {
{.offset = 8,
. length = 8} }
};
+#else /* Zhang.ZG */
+static struct nand_ecclayout nand_oob_16 = {
+ .eccbytes = 6,
+ .eccpos = {8, 9, 10, 13, 14, 15},
+ .oobfree = {
+ {.offset = 0,
+ .length = 16} }
+};
+#endif
static struct nand_ecclayout nand_oob_64 = {
.eccbytes = 24,
diff --git a/SylixOS/include/net/if_arp.h b/SylixOS/include/net/if_arp.h
index e4bb3c2..1a79c45 100644
--- a/SylixOS/include/net/if_arp.h
+++ b/SylixOS/include/net/if_arp.h
@@ -47,9 +47,18 @@ extern "C" {
struct arphdr {
u_short ar_hrd; /* format of hardware address */
-#define ARPHRD_ETHER 1 /* ethernet hardware format */
-#define ARPHRD_IEEE802 6 /* token-ring hardware format */
-#define ARPHRD_FRELAY 15 /* frame relay hardware format */
+#define ARPHRD_ETHER 1 /* ethernet hardware format */
+#define ARPHRD_IEEE802 6 /* token-ring hardware format */
+#define ARPHRD_FRELAY 15 /* frame relay hardware format */
+#define ARPHRD_IEEE1394 24 /* firewire hardware format */
+#define ARPHRD_INFINIBAND 32 /* infiniband hardware format */
+#define ARPHRD_IEEE802_TR 800 /* Magic type ident for TR */
+#define ARPHRD_IEEE80211 801 /* IEEE 802.11 */
+#define ARPHRD_IEEE80211_PRISM 802 /* IEEE 802.11 + Prism2 header */
+#define ARPHRD_IEEE80211_RADIOTAP 803 /* IEEE 802.11 + radiotap header */
+#define ARPHRD_IEEE802154 804 /* IEEE 802.15.4 */
+#define ARPHRD_VOID 0xffff /* Void type, nothing is known */
+#define ARPHRD_NONE 0xfffe /* zero header length */
u_short ar_pro; /* format of protocol address */
u_char ar_hln; /* length of hardware address */
u_char ar_pln; /* length of protocol address */
diff --git a/SylixOS/include/net/if_hwaddr.h b/SylixOS/include/net/if_hwaddr.h
new file mode 100644
index 0000000..79741d0
--- /dev/null
+++ b/SylixOS/include/net/if_hwaddr.h
@@ -0,0 +1,59 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: if_hwaddr.h
+**
+** 创 建 人: Han.Hui (韩辉)
+**
+** 文件创建日期: 2019 年 05 月 11 日
+**
+** 描 述: ARP.
+*********************************************************************************************************/
+
+#ifndef __IF_HWADDR_H
+#define __IF_HWADDR_H
+
+#include <sys/types.h>
+
+/*********************************************************************************************************
+ 裁剪控制
+*********************************************************************************************************/
+#if LW_CFG_NET_EN > 0
+
+#define IFHWADDR_MAXLEN 25
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct sockaddr_ha {
+ u_char sha_type_hi; /* hal type high => sa_len */
+ u_char sha_type_lo; /* hal type low => sa_family */
+ u_char sha_ha[IFHWADDR_MAXLEN]; /* hal hwaddr */
+ u_char sha_alen; /* hal hwaddr length */
+};
+
+#define HALTYPE_FROM_SA(sa) (((u_short)(sa)->sa_len << 8) + (sa)->sa_family)
+#define HALTYPE_FROM_SAHA(saha) (((u_short)(saha)->sha_type_hi << 8) + (saha)->sha_type_lo)
+
+#define HALALEN_FROM_SA(sa) (sa)->sa_data[25]
+#define HALALEN_FROM_SAHA(saha) (saha)->sha_alen
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LW_CFG_NET_EN */
+#endif /* __IF_HWADDR_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/include/network/lwip/netif.h b/SylixOS/include/network/lwip/netif.h
index 954509a..77c9506 100644
--- a/SylixOS/include/network/lwip/netif.h
+++ b/SylixOS/include/network/lwip/netif.h
@@ -361,7 +361,11 @@ struct netif {
#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
#if MIB2_STATS
/** link type (from "snmp_ifType" enum from snmp_mib2.h) */
+#ifdef SYLIXOS /* SylixOS Need u16_t link type */
+ u16_t link_type;
+#else /* SYLIXOS */
u8_t link_type;
+#endif /* !SYLIXOS */
/** (estimate) link speed */
u32_t link_speed;
/** timestamp at last change made (up/down) */
@@ -410,7 +414,8 @@ struct netif {
#define NETIF_FLAG2_PROMISC 2
#define NETIF_FLAG2_ALLMULTI 4
int priv_flags;
- void *ext_eth; /* net bridge or bonding ctl */
+ void *ext_eth; /* net bridge or bonding or ... eth node */
+ void *ext_ctl; /* net bridge or bonding or ... ctl block */
void *flowctl; /* net flow ctl */
u16_t vlanid; /* include tag & pri */
int metric; /* netif metric (NOT support now) */
@@ -420,6 +425,13 @@ struct netif {
/* SylixOS mip externed */
struct netif *mipif;
struct netif *masterif;
+ /* NAT mode */
+#define NETIF_NAT_NONE 0
+#define NETIF_NAT_AP 1
+#define NETIF_NAT_LOCAL 2
+ u8_t nat_mode;
+ /* ARPHRD_xxx */
+ u16_t ar_hrd;
void *reserve[6];
#endif /* SYLIXOS */
};
diff --git a/SylixOS/include/network/lwip/snmp.h b/SylixOS/include/network/lwip/snmp.h
index 69b479d..9929c89 100644
--- a/SylixOS/include/network/lwip/snmp.h
+++ b/SylixOS/include/network/lwip/snmp.h
@@ -91,6 +91,11 @@ enum snmp_ifType {
snmp_ifType_ds3, /* T-3 */
snmp_ifType_sip, /* SMDS */
snmp_ifType_frame_relay
+#ifdef SYLIXOS /* SYLIXOS Add some ifType */
+ ,
+ snmp_ifType_ieee80211 = 71,
+ snmp_ifType_ieee802154 = 259
+#endif /* SYLIXOS */
};
/** This macro has a precision of ~49 days because sys_now returns u32_t. \#define your own if you want ~490 days. */
diff --git a/SylixOS/include/sys/wait.h b/SylixOS/include/sys/wait.h
index 71b1086..b7e48cf 100644
--- a/SylixOS/include/sys/wait.h
+++ b/SylixOS/include/sys/wait.h
@@ -82,6 +82,8 @@ pid_t wait4(pid_t pid, int *stat_loc, int options, struct rusage *prusage);
SylixOS extern API.
*********************************************************************************************************/
+BOOL ischild(pid_t pid);
+BOOL isbrother(pid_t pid);
void reclaimchild(pid_t pid);
int detach(pid_t pid);
diff --git a/SylixOS/kernel/core/_CandTable.c b/SylixOS/kernel/core/_CandTable.c
index 812cd5e..b0d048c 100644
--- a/SylixOS/kernel/core/_CandTable.c
+++ b/SylixOS/kernel/core/_CandTable.c
@@ -95,18 +95,13 @@ static PLW_CLASS_TCB _CandTableNext (PLW_CLASS_PCBBMAP ppcbbmap, UINT8 ucPrio
ppcb = &ppcbbmap->PCBM_pcb[ucPriority];
ptcb = _LIST_ENTRY(ppcb->PCB_pringReadyHeader,
- LW_CLASS_TCB,
- TCB_ringReady); /* 从就绪环中取出一个线程 */
+ LW_CLASS_TCB, TCB_ringReady); /* 从就绪环中取出一个线程 */
- if (ptcb->TCB_ucSchedPolicy == LW_OPTION_SCHED_FIFO) { /* 如果是 FIFO 直接运行 */
- return (ptcb);
-
- } else if (ptcb->TCB_usSchedCounter == 0) { /* 缺少时间片 */
+ if (ptcb->TCB_usSchedCounter == 0) { /* 缺少时间片 */
ptcb->TCB_usSchedCounter = ptcb->TCB_usSchedSlice; /* 补充时间片 */
_list_ring_next(&ppcb->PCB_pringReadyHeader); /* 下一个 */
ptcb = _LIST_ENTRY(ppcb->PCB_pringReadyHeader,
- LW_CLASS_TCB,
- TCB_ringReady);
+ LW_CLASS_TCB, TCB_ringReady);
}
return (ptcb);
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index d4432c3..29b4bfe 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -51,7 +51,7 @@
#define __SYLIXOS_MAJOR_VER 1
#define __SYLIXOS_MINOR_VER 9
#define __SYLIXOS_PATCH_VER 9
-#define __SYLIXOS_PATCH_PAD 8
+#define __SYLIXOS_PATCH_PAD 9
/*********************************************************************************************************
版本格式
diff --git a/SylixOS/kernel/interface/ThreadDelete.c b/SylixOS/kernel/interface/ThreadDelete.c
index a28ab56..fbd7d9d 100644
--- a/SylixOS/kernel/interface/ThreadDelete.c
+++ b/SylixOS/kernel/interface/ThreadDelete.c
@@ -434,7 +434,7 @@ void exit (int iCode)
if (pvprocCur) {
if (pvprocCur->VP_ulMainThread == ulId) {
- vprocExit(__LW_VP_GET_CUR_PROC(), ulId, iCode); /* 进程结束 */
+ vprocExit(pvprocCur, ulId, iCode); /* 进程结束 */
}
#if LW_CFG_SIGNAL_EN > 0
else {
@@ -475,7 +475,7 @@ void _exit (int iCode)
if (pvprocCur) {
pvprocCur->VP_bRunAtExit = LW_FALSE; /* 不执行 atexit 安装函数 */
if (pvprocCur->VP_ulMainThread == ulId) {
- vprocExit(__LW_VP_GET_CUR_PROC(), ulId, iCode); /* 进程结束 */
+ vprocExit(pvprocCur, ulId, iCode); /* 进程结束 */
}
#if LW_CFG_SIGNAL_EN > 0
else {
diff --git a/SylixOS/kernel/show/ThreadShow.c b/SylixOS/kernel/show/ThreadShow.c
index e79c3e3..7994676 100644
--- a/SylixOS/kernel/show/ThreadShow.c
+++ b/SylixOS/kernel/show/ThreadShow.c
@@ -116,7 +116,7 @@ VOID API_ThreadShowEx (pid_t pid)
}
#if LW_CFG_CPU_WORD_LENGHT == 64
- if (tcbdesc.TCBD_ulWakeupLeft > 9999999999l) {
+ if (tcbdesc.TCBD_ulWakeupLeft > 999999999l) {
lib_strcpy(cWakeupLeft, "--");
} else
#endif
diff --git a/SylixOS/loader/include/loader_vppatch.h b/SylixOS/loader/include/loader_vppatch.h
index 8c47c9c..8af3e69 100644
--- a/SylixOS/loader/include/loader_vppatch.h
+++ b/SylixOS/loader/include/loader_vppatch.h
@@ -101,6 +101,7 @@ typedef struct lw_ld_vproc {
LW_FD_DESC VP_fddescTbl[LW_VP_MAX_FILES]; /* 进程 fd 表 */
+ BOOL VP_bKillPrepare; /* 清除进程前是否需要 release */
INT VP_iExitMode; /* 退出模式 */
LW_LD_VPROC_T VP_vptimer[3]; /* REAL / VIRTUAL / PROF 定时器*/
INT64 VP_i64Tick; /* itimer tick 辅助变量 */
@@ -164,7 +165,9 @@ pid_t vprocGetPidByTcb(PLW_CLASS_TCB ptcb);
pid_t vprocGetPidByTcbNoLock(PLW_CLASS_TCB ptcb);
pid_t vprocGetPidByTcbdesc(PLW_CLASS_TCB_DESC ptcbdesc);
pid_t vprocGetPidByThread(LW_OBJECT_HANDLE ulId);
+VOID vprocKillPrepare(pid_t pid, LW_OBJECT_HANDLE ulId);
LW_OBJECT_HANDLE vprocMainThread(pid_t pid);
+BOOL vprocIsMainThread(VOID);
INT vprocNotifyParent(LW_LD_VPROC *pvproc, INT iSigCode, BOOL bUpDateStat);
VOID vprocReclaim(LW_LD_VPROC *pvproc, BOOL bFreeVproc);
INT vprocSetImmediatelyTerm(pid_t pid);
@@ -198,7 +201,7 @@ ssize_t vprocGetModsSvr4Info(pid_t pid, PCHAR pcBuff, size_t stMax
VOID vprocThreadAdd(PVOID pvVProc, PLW_CLASS_TCB ptcb);
VOID vprocThreadDelete(PVOID pvVProc, PLW_CLASS_TCB ptcb);
INT vprocThreadNum(pid_t pid, ULONG *pulNum);
-VOID vprocThreadKill(PVOID pvVProc);
+VOID vprocThreadKill(PVOID pvVProc, PLW_CLASS_TCB ptcbExcp);
#if LW_CFG_SIGNAL_EN > 0
INT vprocThreadSigaction(PVOID pvVProc, VOIDFUNCPTR pfunc, INT iSigIndex,
diff --git a/SylixOS/loader/src/loader_vppatch.c b/SylixOS/loader/src/loader_vppatch.c
index ac552eb..82690d8 100644
--- a/SylixOS/loader/src/loader_vppatch.c
+++ b/SylixOS/loader/src/loader_vppatch.c
@@ -103,6 +103,12 @@ INT vprocProcAdd(LW_LD_VPROC *pvproc);
INT vprocProcDelete(LW_LD_VPROC *pvproc);
#endif /* LW_CFG_PROCFS_EN > 0 */
/*********************************************************************************************************
+ POSIX
+*********************************************************************************************************/
+#if LW_CFG_POSIX_EN > 0
+VOID _PthreadKeyCleanup(PLW_CLASS_TCB ptcbDel);
+#endif /* LW_CFG_POSIX_EN > 0 */
+/*********************************************************************************************************
** 函数名称: __moduleVpPatchVersion
** 功能描述: vp 补丁版本
** 输 入 : pmodule 进程主模块句柄
@@ -768,6 +774,85 @@ pid_t vprocGetPidByThread (LW_OBJECT_HANDLE ulId)
return (pid);
}
/*********************************************************************************************************
+** 函数名称: vprocKillPrepare
+** 功能描述: 停止进程内的除主线程外的所有线程.
+** 输 入 : pid 进程号
+** ulId 主线程
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID vprocKillPrepare (pid_t pid, LW_OBJECT_HANDLE ulId)
+{
+ LW_LD_VPROC *pvproc;
+ PLW_LIST_LINE plineTemp;
+ PLW_CLASS_TCB ptcb;
+
+ if (pid > 0 && pid <= LW_CFG_MAX_THREADS) {
+ LW_LD_LOCK();
+ pvproc = _G_pvprocTable[pid - 1];
+ if (pvproc && !pvproc->VP_bKillPrepare) {
+ LW_VP_LOCK(pvproc); /* 锁定目标进程 */
+ pvproc->VP_bKillPrepare = LW_TRUE; /* 删除前需要解锁 */
+
+ LW_LD_UNLOCK();
+ for (plineTemp = pvproc->VP_plineThread;
+ plineTemp != LW_NULL;
+ plineTemp = _list_line_get_next(plineTemp)) {
+
+ ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_ulId == ulId) {
+ continue; /* 不停止主任务 */
+ }
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadStop(ptcb);
+ __KERNEL_EXIT(); /* 退出内核 */
+ }
+ LW_VP_UNLOCK(pvproc); /* 解锁目标进程 */
+
+ } else {
+ LW_LD_UNLOCK();
+ }
+ }
+}
+/*********************************************************************************************************
+** 函数名称: vprocKillRelease
+** 功能描述: 继续运行除主线程以外的其他线程.
+** 输 入 : pid 进程号
+** ulId 主线程
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID vprocKillRelease (PLW_CLASS_TCB ptcbCur)
+{
+ LW_LD_VPROC *pvproc;
+ PLW_LIST_LINE plineTemp;
+ PLW_CLASS_TCB ptcb;
+
+ pvproc = (LW_LD_VPROC *)ptcbCur->TCB_pvVProcessContext;
+ if (pvproc && pvproc->VP_bKillPrepare) {
+ LW_VP_LOCK(pvproc); /* 锁定目标进程 */
+ pvproc->VP_bKillPrepare = LW_FALSE;
+
+ for (plineTemp = pvproc->VP_plineThread;
+ plineTemp != LW_NULL;
+ plineTemp = _list_line_get_next(plineTemp)) {
+
+ ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb == ptcbCur) {
+ continue;
+ }
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadContinue(ptcb, LW_FALSE);
+ __KERNEL_EXIT(); /* 退出内核 */
+ }
+ LW_VP_UNLOCK(pvproc); /* 解锁目标进程 */
+ }
+}
+/*********************************************************************************************************
** 函数名称: vprocMainThread
** 功能描述: 通过进程号, 查找对应的主线程.
** 输 入 : pid 进程号
@@ -790,6 +875,28 @@ LW_OBJECT_HANDLE vprocMainThread (pid_t pid)
return (lId);
}
/*********************************************************************************************************
+** 函数名称: vprocCurIsMainThread
+** 功能描述: 当前线程是否为主线程.
+** 输 入 : NONE
+** 输 出 : 是否为主线程
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+BOOL vprocIsMainThread (VOID)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_LD_VPROC *pvproc;
+
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
+
+ pvproc = (LW_LD_VPROC *)ptcbCur->TCB_pvVProcessContext;
+ if (pvproc && (pvproc->VP_ulMainThread == ptcbCur->TCB_ulId)) {
+ return (LW_TRUE);
+ }
+
+ return (LW_FALSE);
+}
+/*********************************************************************************************************
** 函数名称: vprocNotifyParent
** 功能描述: 进程通知父系进程
** 输 入 : pvproc 进程控制块指针
@@ -988,16 +1095,20 @@ VOID vprocExit (LW_LD_VPROC *pvproc, LW_OBJECT_HANDLE ulId, INT iCode)
return;
}
-#if LW_CFG_THREAD_EXT_EN > 0
LW_TCB_GET_CUR_SAFE(ptcbCur);
+
__recheck:
+#if LW_CFG_THREAD_EXT_EN > 0
_TCBCleanupPopExt(ptcbCur); /* 提前执行 cleanup pop 操作 */
-#else
-__recheck:
#endif /* LW_CFG_THREAD_EXT_EN > 0 */
+#if LW_CFG_POSIX_EN > 0
+ _PthreadKeyCleanup(ptcbCur); /* 提前执行 key cleanup 操作 */
+#endif /* LW_CFG_POSIX_EN > 0 */
+
if (pvproc->VP_iExitMode == LW_VPROC_EXIT_FORCE) { /* 强制退出删除除主线程外的线程*/
- vprocThreadKill(pvproc);
+ vprocThreadKill(pvproc, ptcbCur);
+ vprocKillRelease(ptcbCur);
}
do { /* 等待所有的线程安全退出 */
diff --git a/SylixOS/loader/src/loader_vpthread.c b/SylixOS/loader/src/loader_vpthread.c
index 6b2de9b..e48a7b4 100644
--- a/SylixOS/loader/src/loader_vpthread.c
+++ b/SylixOS/loader/src/loader_vpthread.c
@@ -108,21 +108,17 @@ INT vprocThreadNum (pid_t pid, ULONG *pulNum)
** 函数名称: vprocThreadKill
** 功能描述: 杀死进程内的除主线程外的所有线程
** 输 入 : pvVProc 进程控制块指针
-** ulThread 线程表
-** uiTableNum 表容量
-** 输 出 : 总线程数
+** ptcbExcp 除此之外
+** 输 出 : NONE
** 全局变量:
** 调用模块:
** 注 意 : 由于此函数中间将释放系统控制权, 所以必须使用 VP_LOCK 保证安全.
*********************************************************************************************************/
-VOID vprocThreadKill (PVOID pvVProc)
+VOID vprocThreadKill (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
{
LW_LD_VPROC *pvproc = (LW_LD_VPROC *)pvVProc;
PLW_LIST_LINE plineTemp;
PLW_CLASS_TCB ptcb;
- PLW_CLASS_TCB ptcbCur;
-
- LW_TCB_GET_CUR_SAFE(ptcbCur);
LW_VP_LOCK(pvproc); /* 锁定当前进程 */
for (plineTemp = pvproc->VP_plineThread;
@@ -130,7 +126,7 @@ VOID vprocThreadKill (PVOID pvVProc)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
- if (ptcb != ptcbCur) { /* ptcbCur 为主线程 */
+ if (ptcb != ptcbExcp) { /* ptcbCur 为主线程 */
_excJobAdd((VOIDFUNCPTR)kill, (PVOID)ptcb->TCB_ulId, (PVOID)SIGKILL, 0, 0, 0, 0);
}
}
diff --git a/SylixOS/loader/src/loader_wait.c b/SylixOS/loader/src/loader_wait.c
index 6f4a0bc..256a14e 100644
--- a/SylixOS/loader/src/loader_wait.c
+++ b/SylixOS/loader/src/loader_wait.c
@@ -696,6 +696,69 @@ void reclaimchild (pid_t pid)
} while (1);
}
/*********************************************************************************************************
+** 函数名称: ischild
+** 功能描述: 是否为当前进程子进程
+** 输 入 : pid 进程 ID
+** 输 出 : LW_TRUE: 是当前进程子进程, LW_FALSE 否
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+BOOL ischild (pid_t pid)
+{
+ LW_LD_VPROC *pvproc = __LW_VP_GET_CUR_PROC();
+
+ if (pvproc == LW_NULL) {
+ return (LW_FALSE);
+ }
+
+ return (__haveThisChild(pvproc, pid));
+}
+/*********************************************************************************************************
+** 函数名称: isbrother
+** 功能描述: 是否为当前进程兄弟进程
+** 输 入 : pid 进程 ID
+** 输 出 : LW_TRUE: 是当前进程兄弟进程, LW_FALSE 否
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+BOOL isbrother (pid_t pid)
+{
+ BOOL bRet = LW_FALSE;
+ LW_LD_VPROC *pvproc = __LW_VP_GET_CUR_PROC();
+ LW_LD_VPROC *pvprocChild;
+ LW_LD_VPROC *pvprocFather;
+ PLW_LIST_LINE plineList;
+
+ if (pvproc == LW_NULL) {
+ return (LW_FALSE);
+ }
+
+ LW_LD_LOCK();
+ pvprocFather = pvproc->VP_pvprocFather;
+ if (!pvprocFather) {
+ LW_LD_UNLOCK();
+ return (LW_FALSE);
+ }
+
+ for (plineList = pvprocFather->VP_plineChild;
+ plineList != LW_NULL;
+ plineList = _list_line_get_next(plineList)) {
+
+ pvprocChild = _LIST_ENTRY(plineList, LW_LD_VPROC, VP_lineBrother);
+ if (pvprocChild->VP_pid == pid) {
+ bRet = LW_TRUE;
+ break;
+ }
+ }
+ LW_LD_UNLOCK();
+
+ return (bRet);
+}
+/*********************************************************************************************************
** 函数名称: detach
** 功能描述: 脱离与父进程关系
** 输 入 : pid 指定的子线程
@@ -756,7 +819,6 @@ int daemon (int nochdir, int noclose)
return (ERROR_NONE);
}
-#else /* NO MODULELOADER */
/*********************************************************************************************************
** 函数名称: getpid
** 功能描述: 获得当前进程号
@@ -766,6 +828,8 @@ int daemon (int nochdir, int noclose)
** 调用模块:
API 函数
*********************************************************************************************************/
+#else /* NO MODULELOADER */
+
LW_API
pid_t getpid (void)
{
diff --git a/SylixOS/net/libc/getifaddrs.c b/SylixOS/net/libc/getifaddrs.c
index 9fa79ba..977bb9e 100644
--- a/SylixOS/net/libc/getifaddrs.c
+++ b/SylixOS/net/libc/getifaddrs.c
@@ -34,6 +34,7 @@
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
+#include <net/if_hwaddr.h>
#include <net/if_types.h>
#include <netinet6/in6.h>
#include <netpacket/packet.h>
@@ -93,23 +94,23 @@ __init_in6 (struct sockaddr_in6 *in6)
#endif
static void
-__init_ll (struct sockaddr_ll *ll)
+__init_ll (struct sockaddr_ll *ll, u_short hatype, u_char alen)
{
bzero(ll, sizeof(struct sockaddr_ll));
ll->sll_len = sizeof(struct sockaddr_ll);
ll->sll_family = AF_PACKET;
- ll->sll_hatype = ARPHRD_ETHER;
- ll->sll_halen = IFHWADDRLEN;
+ ll->sll_hatype = hatype;
+ ll->sll_halen = alen;
}
static void
-__init_dl (struct sockaddr_dl *dl)
+__init_dl (struct sockaddr_dl *dl, u_char alen)
{
bzero(dl, sizeof(struct sockaddr_dl));
dl->sdl_len = sizeof(struct sockaddr_dl);
dl->sdl_family = AF_LINK;
dl->sdl_nlen = 4;
- dl->sdl_alen = IFHWADDRLEN;
+ dl->sdl_alen = alen;
}
#if LWIP_IPV6
@@ -268,11 +269,16 @@ getifaddrs(struct ifaddrs **pif)
#endif /* LWIP_IPV6 */
if (ioctl(s, SIOCGIFHWADDR, &req[i]) == 0) { /* get hwaddr */
+ u_short hatype;
+ u_char alen;
struct ifaddrs *ifaddr_ll;
struct ifaddrs *ifaddr_dl;
struct sockaddr_ll *ll;
struct sockaddr_dl *dl;
+ hatype = HALTYPE_FROM_SA(&req[i].ifr_hwaddr);
+ alen = HALALEN_FROM_SA(&req[i].ifr_hwaddr);
+
/* setup AF_PACKET */
ifaddr_ll = (struct ifaddrs *)malloc(IFADDR_SIZE);
if (ifaddr_ll == NULL) {
@@ -285,7 +291,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_ll->ifa_flags = ifaddr->ifa_flags;
ll = (struct sockaddr_ll *)ifaddr_ll->ifa_addr;
- __init_ll(ll);
+ __init_ll(ll, hatype, alen);
ll->sll_ifindex = netif_index;
memcpy(ll->sll_addr, req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);
@@ -306,7 +312,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_dl->ifa_flags = ifaddr->ifa_flags;
dl = (struct sockaddr_dl *)ifaddr_dl->ifa_addr;
- __init_dl(dl);
+ __init_dl(dl, alen);
dl->sdl_index = netif_index;
memcpy(LLADDR(dl), req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);
diff --git a/SylixOS/net/lwip/bonding/netbonding.c b/SylixOS/net/lwip/bonding/netbonding.c
index dd0e143..089a7ea 100644
--- a/SylixOS/net/lwip/bonding/netbonding.c
+++ b/SylixOS/net/lwip/bonding/netbonding.c
@@ -331,6 +331,7 @@ static err_t netbd_input (struct pbuf *p, struct netif *netif)
netbd_t *netbd = (netbd_t *)netdev_bd->priv;
struct netif *netif_bd = (struct netif *)netdev_bd->sys;
struct eth_hdr *eh = (struct eth_hdr *)p->payload;
+ int mcast = eh->dest.addr[0] & 1;
if (netdev->init_flags & NETDEV_INIT_TIGHT) {
u16_t type;
@@ -367,7 +368,7 @@ to_sub:
} else {
netdev_linkinfo_recv_inc(netdev);
netdev_statinfo_total_add(netdev, LINK_INPUT, (p->tot_len - ETH_PAD_SIZE));
- if (eh->dest.addr[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev, LINK_INPUT);
@@ -423,7 +424,7 @@ input: /* TODO: this function may be parallelization, and statistical variables
} else {
netdev_linkinfo_recv_inc(netdev_bd);
netdev_statinfo_total_add(netdev_bd, LINK_INPUT, (p->tot_len - ETH_PAD_SIZE));
- if (eh->dest.addr[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev_bd, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev_bd, LINK_INPUT);
@@ -505,7 +506,7 @@ int netbd_add_dev (const char *bddev, const char *sub, int sub_is_ifname)
found = 1;
}
}
- if (!found || netif->ext_eth || (netdev->net_type != NETDEV_TYPE_ETHERNET)) {
+ if (!found || netif->ext_ctl || (netdev->net_type != NETDEV_TYPE_ETHERNET)) {
LWIP_IF_LIST_UNLOCK();
errno = ENXIO;
return (-1);
@@ -571,6 +572,7 @@ int netbd_add_dev (const char *bddev, const char *sub, int sub_is_ifname)
netbd_eth->input = netif->input; /* save the old input function */
netif->input = netbd_input; /* set new input function */
netif->ext_eth = (void *)netbd_eth;
+ netif->ext_ctl = (void *)netbd;
if (need_up) {
netifapi_netif_set_up(netif_bd); /* make bonding up */
@@ -705,7 +707,7 @@ int netbd_delete_dev (const char *bddev, const char *sub, int sub_is_ifname)
NETBD_UNLOCK(netbd);
netif->input = netbd_eth->input; /* restore old input function */
- netif->ext_eth = NULL;
+ netif->ext_ctl = netif->ext_eth = NULL;
mem_free(netbd_eth);
@@ -1101,7 +1103,7 @@ int netbd_delete (const char *bddev)
}
netif->input = netbd_eth->input; /* restore input function */
- netif->ext_eth = NULL;
+ netif->ext_ctl = netif->ext_eth = NULL;
mem_free(netbd_eth);
@@ -1132,7 +1134,8 @@ int netbd_delete (const char *bddev)
return (0);
}
-/* net bonding sub device delete hook */
+/* net bonding sub device delete hook
+ NOTICE: this is in LWIP_IF_LIST_LOCK status */
void netbd_sub_delete_hook (netdev_t *netdev)
{
int i, flags;
@@ -1141,11 +1144,9 @@ void netbd_sub_delete_hook (netdev_t *netdev)
netbd_eth_t *netbd_eth;
struct ifreq ifreq;
- LWIP_IF_LIST_LOCK(FALSE);
netif = (struct netif *)netdev->sys;
- netbd = (netbd_t *)netif->ext_eth;
+ netbd = (netbd_t *)netif->ext_ctl;
if (!netbd || netbd->magic_no != NETBONDING_MAGIC) {
- LWIP_IF_LIST_UNLOCK();
return;
}
netbd_eth = (netbd_eth_t *)netbd->eth_ring;
@@ -1156,10 +1157,8 @@ void netbd_sub_delete_hook (netdev_t *netdev)
netbd_eth = (netbd_eth_t *)_list_ring_get_next(&netbd_eth->ring);
}
if (i >= netbd->eth_cnt) {
- LWIP_IF_LIST_UNLOCK();
return;
}
- LWIP_IF_LIST_UNLOCK();
if (netif->flags & NETIF_FLAG_UP) {
netif->flags &= ~NETIF_FLAG_UP;
@@ -1201,7 +1200,7 @@ void netbd_sub_delete_hook (netdev_t *netdev)
NETBD_UNLOCK(netbd);
netif->input = netbd_eth->input; /* restore old input function */
- netif->ext_eth = NULL;
+ netif->ext_ctl = netif->ext_eth = NULL;
mem_free(netbd_eth);
}
diff --git a/SylixOS/net/lwip/bridge/netbridge.c b/SylixOS/net/lwip/bridge/netbridge.c
index cd5b442..51388fb 100644
--- a/SylixOS/net/lwip/bridge/netbridge.c
+++ b/SylixOS/net/lwip/bridge/netbridge.c
@@ -163,6 +163,7 @@ static err_t netbr_input (struct pbuf *p, struct netif *netif)
netbr_mcache_t *mac;
LW_LIST_LINE *pline;
struct eth_hdr *eh = (struct eth_hdr *)p->payload;
+ int mcast = eh->dest.addr[0] & 1;
SYS_ARCH_DECL_PROTECT(lev);
@@ -201,7 +202,7 @@ to_sub:
} else {
netdev_linkinfo_recv_inc(netdev);
netdev_statinfo_total_add(netdev, LINK_INPUT, (p->tot_len - ETH_PAD_SIZE));
- if (eh->dest.addr[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev, LINK_INPUT);
@@ -303,7 +304,7 @@ input_p: /* TODO: this function may be parallelization, and statistical variable
} else {
netdev_linkinfo_recv_inc(netdev_br);
netdev_statinfo_total_add(netdev_br, LINK_INPUT, (p->tot_len - ETH_PAD_SIZE));
- if (eh->dest.addr[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev_br, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev_br, LINK_INPUT);
@@ -385,7 +386,7 @@ int netbr_add_dev (const char *brdev, const char *sub, int sub_is_ifname)
found = 1;
}
}
- if (!found || netif->ext_eth || (netdev->net_type != NETDEV_TYPE_ETHERNET)) {
+ if (!found || netif->ext_ctl || (netdev->net_type != NETDEV_TYPE_ETHERNET)) {
LWIP_IF_LIST_UNLOCK();
errno = ENXIO;
return (-1);
@@ -433,7 +434,8 @@ int netbr_add_dev (const char *brdev, const char *sub, int sub_is_ifname)
netbr_eth->input = netif->input; /* save the old input function */
netif->input = netbr_input; /* set new input function */
netif->ext_eth = (void *)netbr_eth;
-
+ netif->ext_ctl = (void *)netbr;
+
if (need_up) {
netifapi_netif_set_up(netif_br); /* make bridge up */
}
@@ -550,7 +552,7 @@ int netbr_delete_dev (const char *brdev, const char *sub, int sub_is_ifname)
NETBR_UNLOCK(netbr);
netif->input = netbr_eth->input; /* restore old input function */
- netif->ext_eth = NULL;
+ netif->ext_ctl = netif->ext_eth = NULL;
mem_free(netbr_eth);
@@ -711,7 +713,7 @@ int netbr_delete (const char *brdev)
}
netif->input = netbr_eth->input; /* restore input function */
- netif->ext_eth = NULL;
+ netif->ext_ctl = netif->ext_eth = NULL;
mem_free(netbr_eth);
@@ -786,7 +788,8 @@ int netbr_flush_cache (const char *brdev)
return (0);
}
-/* net bridge sub device delete hook */
+/* net bridge sub device delete hook
+ NOTICE: this is in LWIP_IF_LIST_LOCK status */
void netbr_sub_delete_hook (netdev_t *netdev)
{
int flags;
@@ -796,11 +799,9 @@ void netbr_sub_delete_hook (netdev_t *netdev)
struct ifreq ifreq;
LW_LIST_LINE *pline;
- LWIP_IF_LIST_LOCK(FALSE);
netif = (struct netif *)netdev->sys;
- netbr = (netbr_t *)netif->ext_eth;
+ netbr = (netbr_t *)netif->ext_ctl;
if (!netbr || netbr->magic_no != NETBRIDGE_MAGIC) {
- LWIP_IF_LIST_UNLOCK();
return;
}
for (pline = netbr->eth_list; pline != NULL; pline = _list_line_get_next(pline)) {
@@ -810,10 +811,8 @@ void netbr_sub_delete_hook (netdev_t *netdev)
}
}
if (!pline) {
- LWIP_IF_LIST_UNLOCK();
return;
}
- LWIP_IF_LIST_UNLOCK();
if (netif->flags & NETIF_FLAG_UP) {
netif->flags &= ~NETIF_FLAG_UP;
@@ -840,7 +839,7 @@ void netbr_sub_delete_hook (netdev_t *netdev)
NETBR_UNLOCK(netbr);
netif->input = netbr_eth->input; /* restore old input function */
- netif->ext_eth = NULL;
+ netif->ext_ctl = netif->ext_eth = NULL;
mem_free(netbr_eth);
}
diff --git a/SylixOS/net/lwip/lwip_fix.c b/SylixOS/net/lwip/lwip_fix.c
index db145a4..9c5d105 100644
--- a/SylixOS/net/lwip/lwip_fix.c
+++ b/SylixOS/net/lwip/lwip_fix.c
@@ -711,6 +711,9 @@ u32_t sys_arch_mbox_fetch (sys_mbox_t *pmbox, void **msg, u32_t timeout)
ULONG ulNowTime;
if (pmbox == LW_NULL) {
+ if (msg) {
+ *msg = LW_NULL; /* No Message */
+ }
return (SYS_ARCH_TIMEOUT);
}
@@ -725,6 +728,9 @@ u32_t sys_arch_mbox_fetch (sys_mbox_t *pmbox, void **msg, u32_t timeout)
ulError = API_MsgQueueReceive(*pmbox, &pvMsg, sizeof(PVOID), &stMsgLen, ulTimeout);
if (ulError) {
+ if (msg) {
+ *msg = LW_NULL; /* No Message */
+ }
return (SYS_ARCH_TIMEOUT);
} else {
diff --git a/SylixOS/net/lwip/lwip_fix.h b/SylixOS/net/lwip/lwip_fix.h
index fe9e478..70860d7 100644
--- a/SylixOS/net/lwip/lwip_fix.h
+++ b/SylixOS/net/lwip/lwip_fix.h
@@ -164,6 +164,20 @@ void sys_arch_unprotect(INTREG ireg);
#define SYS_ARCH_UNPROTECT(x) sys_arch_unprotect(x)
/*********************************************************************************************************
+ ATOMIC
+*********************************************************************************************************/
+
+#if defined(SYLIXOS) && \
+ (LW_CFG_CPU_ATOMIC_EN > 0) && \
+ (LW_CFG_LWIP_PBUF_ATOMIC > 0) && \
+ (LWIP_PBUF_REF_T == int)
+#define SYS_ARCH_INC(var, val) __LW_ATOMIC_ADD((val), (atomic_t *)&(var))
+#define SYS_ARCH_DEC(var, val) __LW_ATOMIC_SUB((val), (atomic_t *)&(var))
+#define SYS_ARCH_GET(var, ret) (ret) = __LW_ATOMIC_GET((atomic_t *)&(var))
+#define SYS_ARCH_SET(var, val) __LW_ATOMIC_SET((val), (atomic_t *)&(var))
+#endif
+
+/*********************************************************************************************************
Measurement calls made throughout lwip, these can be defined to nothing.
*********************************************************************************************************/
diff --git a/SylixOS/net/lwip/lwip_ifctl.c b/SylixOS/net/lwip/lwip_ifctl.c
index 411608e..abf938b 100644
--- a/SylixOS/net/lwip/lwip_ifctl.c
+++ b/SylixOS/net/lwip/lwip_ifctl.c
@@ -26,6 +26,7 @@
#if LW_CFG_NET_EN > 0
#include "net/if.h"
#include "net/if_arp.h"
+#include "net/if_hwaddr.h"
#include "net/if_types.h"
#include "net/if_lock.h"
#include "net/if_flags.h"
@@ -149,8 +150,8 @@ static INT __ifReq6Size (struct in6_ifreq *pifreq6)
*********************************************************************************************************/
static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
{
+ INT i, iIsUp, iFlags;
INT iRet = PX_ERROR;
- INT iFlags;
struct ifreq *pifreq = LW_NULL;
struct netif *pnetif;
@@ -237,12 +238,18 @@ static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
break;
case SIOCGIFHWADDR: /* 获得物理地址 */
- if (pnetif->flags & (NETIF_FLAG_ETHERNET | NETIF_FLAG_ETHARP)) {
- INT i;
- for (i = 0; i < IFHWADDRLEN; i++) {
+ if (pnetif->hwaddr_len && (pnetif->hwaddr_len <= IFHWADDR_MAXLEN)) {
+ if (pnetif->ar_hrd != ARPHRD_VOID) {
+ pifreq->ifr_hwaddr.sa_len = pnetif->ar_hrd >> 8;
+ pifreq->ifr_hwaddr.sa_family = pnetif->ar_hrd & 0xff; /* 设置网卡地址类型 */
+ } else {
+ pifreq->ifr_hwaddr.sa_len = 0;
+ pifreq->ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ }
+ for (i = 0; i < pnetif->hwaddr_len; i++) {
pifreq->ifr_hwaddr.sa_data[i] = pnetif->hwaddr[i];
}
- pifreq->ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ HALALEN_FROM_SA(&pifreq->ifr_hwaddr) = pnetif->hwaddr_len;
iRet = ERROR_NONE;
} else {
_ErrorHandle(EINVAL);
@@ -250,14 +257,13 @@ static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
break;
case SIOCSIFHWADDR: /* 设置 mac 地址 */
- if (pnetif->flags & (NETIF_FLAG_ETHERNET | NETIF_FLAG_ETHARP)) {
- INT i;
- INT iIsUp = netif_is_up(pnetif);
+ if (pnetif->hwaddr_len && (pnetif->hwaddr_len <= IFHWADDR_MAXLEN)) {
+ iIsUp = netif_is_up(pnetif);
if (pnetif->ioctl) {
netifapi_netif_set_down(pnetif); /* 关闭网口 */
iRet = pnetif->ioctl(pnetif, SIOCSIFHWADDR, pvArg);
if (iRet == ERROR_NONE) {
- for (i = 0; i < IFHWADDRLEN; i++) {
+ for (i = 0; i < pnetif->hwaddr_len; i++) {
pnetif->hwaddr[i] = pifreq->ifr_hwaddr.sa_data[i];
}
}
diff --git a/SylixOS/net/lwip/netdev/netdesc.c b/SylixOS/net/lwip/netdev/netdesc.c
index 650bf5b..6b6014a 100644
--- a/SylixOS/net/lwip/netdev/netdesc.c
+++ b/SylixOS/net/lwip/netdev/netdesc.c
@@ -542,6 +542,39 @@ struct pbuf *netdev_desc_rx_input (struct netdev_desc_helper *helper, int idx, i
return (p);
}
+/* netdev_desc_rx_input_offset (you must ensure 'idx' is valid) */
+struct pbuf *netdev_desc_rx_input_offset (struct netdev_desc_helper *helper, int idx, int len, int offset)
+{
+ struct pbuf *p;
+ struct netdev_desc_buf *rx_buf;
+
+ rx_buf = NETDEV_RX_DESC_BUF(helper, idx);
+ if (rx_buf->p) {
+ p = rx_buf->p;
+ p->tot_len = p->len = (u16_t)len;
+ rx_buf->p = NULL;
+#if LW_CFG_CACHE_EN > 0
+ if (helper->cache_zc_invalid) {
+ cacheInvalidate(DATA_CACHE, p->payload, p->tot_len);
+ }
+#endif /* LW_CFG_CACHE_EN */
+
+ } else {
+ p = netdev_pbuf_alloc((u16_t)len);
+ if (!p) {
+ return (NULL);
+ }
+#if LW_CFG_CACHE_EN > 0
+ if (helper->cache_rs_invalid) {
+ cacheInvalidate(DATA_CACHE, (char *)rx_buf->buffer + offset, len);
+ }
+#endif /* LW_CFG_CACHE_EN */
+ pbuf_take(p, (char *)rx_buf->buffer + offset, (u16_t)len);
+ }
+
+ return (p);
+}
+
/* netdev_desc_rx_refill (you must ensure 'idx' is valid) */
netdev_desc_btype netdev_desc_rx_refill (struct netdev_desc_helper *helper, int idx)
{
diff --git a/SylixOS/net/lwip/netdev/netdev.c b/SylixOS/net/lwip/netdev/netdev.c
index aa460f4..9d49483 100644
--- a/SylixOS/net/lwip/netdev/netdev.c
+++ b/SylixOS/net/lwip/netdev/netdev.c
@@ -52,6 +52,7 @@
#include "netif/ethernet.h"
#include "netif/lowpan6.h"
#include "netif/lowpan6_ble.h"
+#include "net/if_arp.h"
#include "net/if_lock.h"
#include "net/if_flags.h"
#include "net/if_param.h"
@@ -561,10 +562,11 @@ static void netdev_netif_set_linkup (netdev_t *netdev, int linkup, UINT32 speed
netif->ts = sys_jiffies();
netdev->speed = speed;
- if (!netif->ext_eth) { /* not in net bridge or bonding */
+ if (!netif->ext_ctl) { /* not in net bridge or bonding */
netifapi_netif_set_link_up(netif);
} else {
netif_set_flags(netif, NETIF_FLAG_LINK_UP);
+ netdev_netif_linkup(netif);
}
if (speed > 0xffffffff) {
@@ -574,10 +576,11 @@ static void netdev_netif_set_linkup (netdev_t *netdev, int linkup, UINT32 speed
}
} else {
- if (!netif->ext_eth) { /* not in net bridge or bonding */
+ if (!netif->ext_ctl) { /* not in net bridge or bonding */
netifapi_netif_set_link_down(netif);
} else {
netif_clear_flags(netif, NETIF_FLAG_LINK_UP);
+ netdev_netif_linkup(netif);
}
}
@@ -607,10 +610,11 @@ static err_t netdev_netif_init (struct netif *netif)
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_ETHER;
break;
case NETDEV_TYPE_LOWPAN:
- MIB2_INIT_NETIF(netif, snmp_ifType_other, 0);
+ MIB2_INIT_NETIF(netif, snmp_ifType_ieee802154, 0);
netif->flags = NETIF_FLAG_BROADCAST;
netif->output = netdev_netif_nulloutput4;
#if LWIP_IPV6
@@ -620,10 +624,11 @@ static err_t netdev_netif_init (struct netif *netif)
lowpan6_timer = 1;
}
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_IEEE802154;
break;
case NETDEV_TYPE_LOWPAN_BLE:
- MIB2_INIT_NETIF(netif, snmp_ifType_other, 0);
+ MIB2_INIT_NETIF(netif, snmp_ifType_ieee802154, 0);
netif->flags = 0;
netif->output = netdev_netif_nulloutput4;
#if LWIP_IPV6
@@ -634,6 +639,7 @@ static err_t netdev_netif_init (struct netif *netif)
rfc7668_set_local_addr_mac48(netif, netdev->hwaddr, netif->hwaddr_len, 0); /* not public ? */
}
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_IEEE802154;
break;
default:
@@ -643,6 +649,7 @@ static err_t netdev_netif_init (struct netif *netif)
#if LWIP_IPV6
netif->output_ip6 = netdev_netif_rawoutput6;
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_VOID;
break;
}
@@ -1049,6 +1056,8 @@ int netdev_delete (netdev_t *netdev)
netif = (struct netif *)netdev->sys;
+ LWIP_IF_LIST_LOCK(LW_TRUE);
+
#if LW_CFG_NET_DEV_BRIDGE_EN > 0
netbr_sub_delete_hook(netdev);
#endif /* LW_CFG_NET_DEV_BONDING_EN > 0 */
@@ -1057,7 +1066,6 @@ int netdev_delete (netdev_t *netdev)
netbd_sub_delete_hook(netdev);
#endif /* LW_CFG_NET_DEV_BONDING_EN > 0 */
- LWIP_IF_LIST_LOCK(LW_TRUE);
NETIF_FOREACH(tmp_netif) {
if (tmp_netif == netif) {
break;
@@ -1287,6 +1295,38 @@ int netdev_ifname (netdev_t *netdev, char *ifname)
return (0);
}
+/* netdev set/get format of hardware address
+ * NOTICE: you can call these function after netdev_add() */
+int netdev_set_ar_hdr (netdev_t *netdev, UINT16 ar_hdr)
+{
+ struct netif *netif;
+
+ if (!netdev || (netdev->magic_no != NETDEV_MAGIC)) {
+ return (-1);
+ }
+
+ netif = (struct netif *)netdev->sys;
+
+ netif->ar_hrd = ar_hdr;
+
+ return (0);
+}
+
+int netdev_get_ar_hdr (netdev_t *netdev, UINT16 *ar_hdr)
+{
+ struct netif *netif;
+
+ if (!netdev || !ar_hdr || (netdev->magic_no != NETDEV_MAGIC)) {
+ return (-1);
+ }
+
+ netif = (struct netif *)netdev->sys;
+
+ *ar_hdr = netif->ar_hrd;
+
+ return (0);
+}
+
/* netdev set/get tcp ack frequecy
* NOTICE: you can call these function after netdev_add() */
int netdev_set_tcpaf (netdev_t *netdev, UINT8 tcpaf)
diff --git a/SylixOS/net/lwip/netdev/netdev.h b/SylixOS/net/lwip/netdev/netdev.h
index 0af5fd3..aa69d75 100644
--- a/SylixOS/net/lwip/netdev/netdev.h
+++ b/SylixOS/net/lwip/netdev/netdev.h
@@ -352,6 +352,11 @@ netdev_t *netdev_find_by_index(unsigned int index);
netdev_t *netdev_find_by_ifname(const char *if_name);
netdev_t *netdev_find_by_devname(const char *dev_name);
+/* netdev set/get format of hardware address
+ * NOTICE: you can call these function after netdev_add() */
+int netdev_set_ar_hdr(netdev_t *netdev, UINT16 ar_hdr);
+int netdev_get_ar_hdr(netdev_t *netdev, UINT16 *ar_hdr);
+
/* netdev set/get tcp ack frequecy
* NOTICE: you can call these function after netdev_add() */
int netdev_set_tcpaf(netdev_t *netdev, UINT8 tcpaf);
@@ -494,6 +499,7 @@ netdev_desc_btype netdev_desc_tx_prepare(struct netdev_desc_helper *helper, int
void netdev_desc_tx_clean(struct netdev_desc_helper *helper, int idx);
/* get Rx descriptor buffer (you must ensure 'idx' is valid) */
struct pbuf *netdev_desc_rx_input(struct netdev_desc_helper *helper, int idx, int len);
+struct pbuf *netdev_desc_rx_input_offset(struct netdev_desc_helper *helper, int idx, int len, int offset);
/* refill Rx descriptor buffer (you must ensure 'idx' is valid) */
netdev_desc_btype netdev_desc_rx_refill(struct netdev_desc_helper *helper, int idx);
netdev_desc_btype netdev_desc_rx_refill_res(struct netdev_desc_helper *helper, int idx, UINT16 res);
diff --git a/SylixOS/net/lwip/netdev/vnetdev.c b/SylixOS/net/lwip/netdev/vnetdev.c
index e09285c..22484a8 100644
--- a/SylixOS/net/lwip/netdev/vnetdev.c
+++ b/SylixOS/net/lwip/netdev/vnetdev.c
@@ -261,6 +261,7 @@ int vnetdev_put (struct vnetdev *vnetdev, struct pbuf *p)
{
struct netdev *netdev = &vnetdev->netdev;
struct netif *netif = (struct netif *)netdev->sys;
+ int mcast = ((UINT8 *)p->payload)[0] & 1;
if (!netif_is_link_up(netif)) {
return (-1);
@@ -282,7 +283,7 @@ int vnetdev_put (struct vnetdev *vnetdev, struct pbuf *p)
netdev_linkinfo_recv_inc(netdev);
netdev_statinfo_total_add(netdev, LINK_INPUT, p->tot_len);
- if (((UINT8 *)p->payload)[0] & 1) {
+ if (mcast) {
netdev_statinfo_mcasts_inc(netdev, LINK_INPUT);
} else {
netdev_statinfo_ucasts_inc(netdev, LINK_INPUT);
diff --git a/SylixOS/net/lwip/src/api/api_lib.c b/SylixOS/net/lwip/src/api/api_lib.c
index e03b8b7..0a2fa2b 100644
--- a/SylixOS/net/lwip/src/api/api_lib.c
+++ b/SylixOS/net/lwip/src/api/api_lib.c
@@ -55,6 +55,7 @@
/* This is the part of the API that is linked with
the application */
+#define __SYLIXOS_KERNEL /* SylixOS Add this to export atomic */
#include "lwip/opt.h"
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
diff --git a/SylixOS/net/lwip/src/api/api_msg.c b/SylixOS/net/lwip/src/api/api_msg.c
index 926f231..bf94be4 100644
--- a/SylixOS/net/lwip/src/api/api_msg.c
+++ b/SylixOS/net/lwip/src/api/api_msg.c
@@ -36,6 +36,7 @@
*
*/
+#define __SYLIXOS_KERNEL /* SylixOS Add this to export atomic */
#include "lwip/opt.h"
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
diff --git a/SylixOS/net/lwip/src/core/ipv4/ip4.c b/SylixOS/net/lwip/src/core/ipv4/ip4.c
index 681ea70..50055a4 100644
--- a/SylixOS/net/lwip/src/core/ipv4/ip4.c
+++ b/SylixOS/net/lwip/src/core/ipv4/ip4.c
@@ -393,13 +393,15 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
IP_STATS_INC(ip.err);
return p; /* SylixOS Add return value */
}
- p = lwip_ip_nat_hook(IP_HOOK_V4, IP_HT_NAT_POST_ROUTING, p, inp, netif);
- if (p == NULL) {
- return p; /* SylixOS Add return value (Outer do not free pbuf) */
- }
+ if (inp->nat_mode == NETIF_NAT_LOCAL && netif->nat_mode == NETIF_NAT_AP) { /* need call nat hook? */
+ p = lwip_ip_nat_hook(IP_HOOK_V4, IP_HT_NAT_POST_ROUTING, p, inp, netif);
+ if (p == NULL) {
+ return p; /* SylixOS Add return value (Outer do not free pbuf) */
+ }
#if IP_REASSEMBLY
- iphdr = (struct ip_hdr *)p->payload; /* Maybe lwip_ip_nat_hook() changed the pbuf */
+ iphdr = (struct ip_hdr *)p->payload; /* Maybe lwip_ip_nat_hook() changed the pbuf */
#endif /* IP_REASSEMBLY */
+ }
#endif /* SYLIXOS */
LWIP_DEBUGF(IP_DEBUG, ("ip4_forward: forwarding packet to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
@@ -584,13 +586,15 @@ ip4_input(struct pbuf *p, struct netif *inp)
IP_STATS_INC(ip.drop);
return ERR_OK;
}
- p = lwip_ip_nat_hook(IP_HOOK_V4, IP_HT_NAT_PRE_ROUTING, p, inp, NULL);
- if (p == NULL) {
- return ERR_OK;
- }
+ if (inp->nat_mode == NETIF_NAT_AP) { /* need call nat hook? */
+ p = lwip_ip_nat_hook(IP_HOOK_V4, IP_HT_NAT_PRE_ROUTING, p, inp, NULL);
+ if (p == NULL) {
+ return ERR_OK;
+ }
#if IP_REASSEMBLY
- iphdr = (struct ip_hdr *)p->payload; /* Maybe lwip_ip_nat_hook() changed the pbuf */
+ iphdr = (struct ip_hdr *)p->payload; /* Maybe lwip_ip_nat_hook() changed the pbuf */
#endif /* IP_REASSEMBLY */
+ }
#endif /* SYLIXOS */
/* copy IP addresses to aligned ip_addr_t */
@@ -1116,6 +1120,10 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d
IP_STATS_INC(ip.err);
return ERR_RTE;
}
+ if (netif->nat_mode == NETIF_NAT_AP) { /* need call nat hook? */
+ p = lwip_ip_nat_hook(IP_HOOK_V4, IP_HT_NAT_POST_ROUTING, p, NULL, netif);
+ LWIP_ASSERT("NAT can not free local output packet", (p != NULL));
+ }
#endif /* SYLIXOS */
IP_STATS_INC(ip.xmit);
diff --git a/SylixOS/net/lwip/src/core/netif.c b/SylixOS/net/lwip/src/core/netif.c
index 525290a..fdf04ac 100644
--- a/SylixOS/net/lwip/src/core/netif.c
+++ b/SylixOS/net/lwip/src/core/netif.c
@@ -371,6 +371,7 @@ netif_add(struct netif *netif,
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
#ifdef SYLIXOS /* SylixOS Add */
+ netif->hwaddr_len = 0;
netif->ioctl = NULL;
netif->up = NULL;
netif->down = NULL;
@@ -383,6 +384,7 @@ netif_add(struct netif *netif,
netif->flags2 = 0;
netif->priv_flags = 0;
netif->ext_eth = NULL;
+ netif->ext_ctl = NULL;
netif->flowctl = NULL;
netif->vlanid = (u16_t)-1;
netif->metric = 1;
@@ -390,6 +392,8 @@ netif_add(struct netif *netif,
netif->tcp_wnd = TCP_WND;
netif->mipif = NULL;
netif->masterif = NULL;
+ netif->nat_mode = NETIF_NAT_NONE;
+ netif->ar_hrd = 0xffff;
lib_bzero(netif->reserve, sizeof(void *[6]));
#endif /* SYLIXOS */
diff --git a/SylixOS/net/lwip/src/core/pbuf.c b/SylixOS/net/lwip/src/core/pbuf.c
index 3b6102f..88929a3 100644
--- a/SylixOS/net/lwip/src/core/pbuf.c
+++ b/SylixOS/net/lwip/src/core/pbuf.c
@@ -129,7 +129,14 @@ void
pbuf_free_ooseq(void)
{
struct tcp_pcb *pcb;
+#ifdef SYLIXOS /* SylixOS pending flag use state machine NOT atomic */
+ SYS_ARCH_DECL_PROTECT(old_level);
+ SYS_ARCH_PROTECT(old_level);
+ pbuf_free_ooseq_pending = 0;
+ SYS_ARCH_UNPROTECT(old_level);
+#else /* SYLIXOS */
SYS_ARCH_SET(pbuf_free_ooseq_pending, 0);
+#endif /* !SYLIXOS */
for (pcb = tcp_active_pcbs; NULL != pcb; pcb = pcb->next) {
if (pcb->ooseq != NULL) {
@@ -158,7 +165,14 @@ static void
pbuf_pool_is_empty(void)
{
#ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
+#ifdef SYLIXOS /* SylixOS pending flag use state machine NOT atomic */
+ SYS_ARCH_DECL_PROTECT(old_level);
+ SYS_ARCH_PROTECT(old_level);
+ pbuf_free_ooseq_pending = 1;
+ SYS_ARCH_UNPROTECT(old_level);
+#else /* SYLIXOS */
SYS_ARCH_SET(pbuf_free_ooseq_pending, 1);
+#endif /* !SYLIXOS */
#else /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
u8_t queued;
SYS_ARCH_DECL_PROTECT(old_level);
diff --git a/SylixOS/net/lwip/tools/nat/lwip_natlib.c b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
index eafa6bc..6f2f1a6 100644
--- a/SylixOS/net/lwip/tools/nat/lwip_natlib.c
+++ b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
@@ -38,6 +38,7 @@
2018.01.16 使用 iphook 实现更加灵活的 NAT 管理.
2018.04.06 NAT 支持提前分片重组.
2019.02.15 本地 TCP SYN, CLOSING 仅保持 1 分钟.
+2019.04.09 NAT AP 端口支持主机安全隔离.
*********************************************************************************************************/
#define __SYLIXOS_STDIO
#define __SYLIXOS_KERNEL
@@ -137,6 +138,7 @@ VOID nat_netif_add_hook (struct netif *pnetif)
if (_G_natifAp[i].NATIF_pnetif == LW_NULL) {
if (!lib_strcmp(cIfName, _G_natifAp[i].NATIF_cIfName)) {
_G_natifAp[i].NATIF_pnetif = pnetif;
+ pnetif->nat_mode = NETIF_NAT_AP;
goto out;
}
}
@@ -145,6 +147,7 @@ VOID nat_netif_add_hook (struct netif *pnetif)
if (_G_natifLocal[i].NATIF_pnetif == LW_NULL) {
if (!lib_strcmp(cIfName, _G_natifLocal[i].NATIF_cIfName)) {
_G_natifLocal[i].NATIF_pnetif = pnetif;
+ pnetif->nat_mode = NETIF_NAT_LOCAL;
goto out;
}
}
@@ -753,41 +756,35 @@ static INT __natApInput (struct pbuf *p, struct netif *netifIn)
ip4_addr_p_t ipaddr; /* 内网映射服务器 IP */
u16_t usSrcHash = iphdr->src.addr % pnatmap->NATM_usLocalCnt;
/* 外网 hash */
- if (ip4_addr_cmp(&pnatmap->NATM_ipaddrLocalIp,
- netif_ip4_addr(netifIn))) { /* 本机映射 */
- ipaddr.addr = pnatmap->NATM_ipaddrLocalIp.addr;
-
- } else { /* 内网其他主机映射 */
- for (plineTemp = plineHeader;
- plineTemp != LW_NULL;
- plineTemp = _list_line_get_next(plineTemp)) {
+ for (plineTemp = plineHeader; /* 内网主机映射 */
+ plineTemp != LW_NULL;
+ plineTemp = _list_line_get_next(plineTemp)) {
- pnatcb = _LIST_ENTRY(plineTemp, __NAT_CB, NAT_lineManage);
- if ((usSrcHash == pnatcb->NAT_usSrcHash) &&
- (usDestPort == pnatcb->NAT_usAssPort) &&
- (ucProto == pnatcb->NAT_ucProto)) {
- break; /* 找到了 NAT 控制块 */
- }
+ pnatcb = _LIST_ENTRY(plineTemp, __NAT_CB, NAT_lineManage);
+ if ((usSrcHash == pnatcb->NAT_usSrcHash) &&
+ (usDestPort == pnatcb->NAT_usAssPort) &&
+ (ucProto == pnatcb->NAT_ucProto)) {
+ break; /* 找到了 NAT 控制块 */
}
- if (plineTemp == LW_NULL) {
- u32_t uiHost;
+ }
+ if (plineTemp == LW_NULL) {
+ u32_t uiHost;
- uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
- uiHost += usSrcHash; /* 根据源地址散列做均衡 */
- ipaddr.addr = (u32_t)PP_HTONL(uiHost);
+ uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
+ uiHost += usSrcHash; /* 根据源地址散列做均衡 */
+ ipaddr.addr = (u32_t)PP_HTONL(uiHost);
- pnatcb = __natNew(&ipaddr, /* 新建控制块 */
- pnatmap->NATM_usLocalPort, ucProto);
+ pnatcb = __natNew(&ipaddr, /* 新建控制块 */
+ pnatmap->NATM_usLocalPort, ucProto);
- pnatcb->NAT_usSrcHash = usSrcHash;
- pnatcb->NAT_usAssPortSave = pnatcb->NAT_usAssPort; /* 保存端口资源 */
- pnatcb->NAT_usAssPort = pnatmap->NATM_usAssPort;
-
- } else {
- ipaddr.addr = pnatcb->NAT_ipaddrLocalIp.addr;
+ pnatcb->NAT_usSrcHash = usSrcHash;
+ pnatcb->NAT_usAssPortSave = pnatcb->NAT_usAssPort; /* 保存端口资源 */
+ pnatcb->NAT_usAssPort = pnatmap->NATM_usAssPort;
- pnatcb->NAT_ulIdleTimer = 0; /* 刷新空闲时间 */
- }
+ } else {
+ ipaddr.addr = pnatcb->NAT_ipaddrLocalIp.addr;
+
+ pnatcb->NAT_ulIdleTimer = 0; /* 刷新空闲时间 */
}
/*
@@ -995,10 +992,6 @@ static INT __natApOutput (struct pbuf *p, struct netif *pnetifIn, struct netif
}
}
if (plineTemp == LW_NULL) {
- pnatcb = LW_NULL; /* 没有找到 */
- }
-
- if (pnatcb == LW_NULL) {
pnatcb = __natNew(&iphdr->src, usSrcPort, ucProto); /* 新建控制块 */
}
@@ -1103,55 +1096,52 @@ static INT __natApOutput (struct pbuf *p, struct netif *pnetifIn, struct netif
*********************************************************************************************************/
static struct pbuf *__natIpInput (struct pbuf *p, struct netif *pnetifIn, struct netif *pnetifOut)
{
- INT i;
struct ip_hdr *iphdr;
iphdr = (struct ip_hdr *)p->payload;
- for (i = 0; i < LW_CFG_NET_NAT_MAX_AP_IF; i++) {
- if (_G_natifAp[i].NATIF_pnetif == pnetifIn) {
- if (ip4_addr_cmp(&iphdr->dest, netif_ip4_addr(pnetifIn))) {
- if (IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) { /* 分片数据包 */
- switch (IPH_PROTO(iphdr)) {
-
- case IP_PROTO_TCP:
- if (!_G_bNatTcpFrag) {
- return (p);
- }
- break;
-
- case IP_PROTO_UDP:
- if (!_G_bNatUdpFrag) {
- return (p);
- }
- break;
-
- case IP_PROTO_ICMP:
- if (!_G_bNatIcmpFrag) {
- return (p);
- }
- break;
-
- default:
- return (p);
- }
+ if (!ip4_addr_cmp(&iphdr->dest, netif_ip4_addr(pnetifIn))) {
+ return (p);
+ }
-#if IP_REASSEMBLY
- p = ip4_reass(p); /* 提前进行分片重组 */
- if (p == LW_NULL) {
- return (p); /* 分片不全 */
- }
-#else /* IP_REASSEMBLY */
- return (p);
-#endif /* !IP_REASSEMBLY */
- }
- if (__natApInput(p, pnetifIn)) { /* NAT 输入 */
- pbuf_free(p);
- p = LW_NULL;
- }
+ if (IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) { /* 分片数据包 */
+ switch (IPH_PROTO(iphdr)) {
+
+ case IP_PROTO_TCP:
+ if (!_G_bNatTcpFrag) {
+ return (p);
}
break;
+
+ case IP_PROTO_UDP:
+ if (!_G_bNatUdpFrag) {
+ return (p);
+ }
+ break;
+
+ case IP_PROTO_ICMP:
+ if (!_G_bNatIcmpFrag) {
+ return (p);
+ }
+ break;
+
+ default:
+ return (p);
+ }
+
+#if IP_REASSEMBLY
+ p = ip4_reass(p); /* 提前进行分片重组 */
+ if (p == LW_NULL) {
+ return (p); /* 分片不全 */
}
+#else /* IP_REASSEMBLY */
+ return (p);
+#endif /* !IP_REASSEMBLY */
+ }
+
+ if (__natApInput(p, pnetifIn)) { /* NAT 输入 */
+ pbuf_free(p);
+ p = LW_NULL;
}
return (p);
@@ -1168,80 +1158,60 @@ static struct pbuf *__natIpInput (struct pbuf *p, struct netif *pnetifIn, stru
*********************************************************************************************************/
static struct pbuf *__natIpOutput (struct pbuf *p, struct netif *pnetifIn, struct netif *pnetifOut)
{
- INT i, j;
struct ip_hdr *iphdr;
+ iphdr = (struct ip_hdr *)p->payload;
+
if (!pnetifIn) { /* 本机发送 */
+ if (!(IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF))) {
+ __natApOutput(p, pnetifIn, pnetifOut); /* NAT 输出 */
+ }
return (p);
}
-
- iphdr = (struct ip_hdr *)p->payload;
-
- for (i = 0; i < LW_CFG_NET_NAT_MAX_AP_IF; i++) {
- if (_G_natifAp[i].NATIF_pnetif == pnetifOut) { /* AP 输出 */
- for (j = 0; j < LW_CFG_NET_NAT_MAX_LOCAL_IF; j++) {
- if (_G_natifLocal[j].NATIF_pnetif == pnetifIn) {
- break; /* LOCAL 输入 */
- }
+
+ if (IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) { /* 分片数据包 */
+ switch (IPH_PROTO(iphdr)) {
+
+ case IP_PROTO_TCP:
+ if (!_G_bNatTcpFrag) {
+ pbuf_free(p);
+ return (LW_NULL);
}
- if (j >= LW_CFG_NET_NAT_MAX_LOCAL_IF) {
- return (p); /* 不需要进行 NAT 地址转换 */
+ break;
+
+ case IP_PROTO_UDP:
+ if (!_G_bNatUdpFrag) {
+ pbuf_free(p);
+ return (LW_NULL);
}
-
- if (IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) { /* 分片数据包 */
- switch (IPH_PROTO(iphdr)) {
-
- case IP_PROTO_TCP:
- if (!_G_bNatTcpFrag) {
- pbuf_free(p);
- return (LW_NULL);
- }
- break;
-
- case IP_PROTO_UDP:
- if (!_G_bNatUdpFrag) {
- pbuf_free(p);
- return (LW_NULL);
- }
- break;
-
- case IP_PROTO_ICMP:
- if (!_G_bNatIcmpFrag) {
- pbuf_free(p);
- return (LW_NULL);
- }
- break;
-
- default:
- pbuf_free(p);
- return (LW_NULL);
- }
+ break;
-#if IP_REASSEMBLY
- p = ip4_reass(p); /* 提前进行分片重组 */
- if (p == LW_NULL) {
- return (p); /* 分片不全 */
- }
-#else
+ case IP_PROTO_ICMP:
+ if (!_G_bNatIcmpFrag) {
pbuf_free(p);
return (LW_NULL);
-#endif
- if (__natApOutput(p, pnetifIn, pnetifOut)) { /* NAT 输出 */
- pbuf_free(p);
- return (LW_NULL);
-
- } else {
- return (p);
- }
-
- } else {
- if (__natApOutput(p, pnetifIn, pnetifOut)) { /* NAT 输出 */
- pbuf_free(p);
- return (LW_NULL);
- }
}
break;
+
+ default:
+ pbuf_free(p);
+ return (LW_NULL);
}
+
+#if IP_REASSEMBLY
+ p = ip4_reass(p); /* 提前进行分片重组 */
+ if (p == LW_NULL) {
+ return (p); /* 分片不全 */
+ }
+#else
+ pbuf_free(p);
+ return (LW_NULL);
+#endif
+ }
+
+ if (__natApOutput(p, pnetifIn, pnetifOut)) { /* NAT 输出 */
+ pbuf_free(p);
+ p = LW_NULL;
}
return (p);
@@ -1313,7 +1283,14 @@ INT __natStart (CPCHAR pcLocal, CPCHAR pcAp)
lib_strlcpy(_G_natifLocal[0].NATIF_cIfName, pcLocal, IF_NAMESIZE);
_G_natifLocal[0].NATIF_pnetif = netif_find(pcLocal);
- _G_natifAp[0].NATIF_pnetif = netif_find(pcAp);
+ if (_G_natifLocal[0].NATIF_pnetif) {
+ _G_natifLocal[0].NATIF_pnetif->nat_mode = NETIF_NAT_LOCAL;
+ }
+
+ _G_natifAp[0].NATIF_pnetif = netif_find(pcAp);
+ if (_G_natifAp[0].NATIF_pnetif) {
+ _G_natifAp[0].NATIF_pnetif->nat_mode = NETIF_NAT_AP;
+ }
if (net_ip_hook_nat_add(__natIphook)) {
return (PX_ERROR);
@@ -1350,12 +1327,18 @@ INT __natStop (VOID)
__NAT_LOCK();
for (i = 1; i < LW_CFG_NET_NAT_MAX_AP_IF; i++) {
_G_natifAp[i].NATIF_cIfName[0] = PX_EOS;
- _G_natifAp[i].NATIF_pnetif = LW_NULL;
+ if (_G_natifAp[i].NATIF_pnetif) {
+ _G_natifAp[i].NATIF_pnetif->nat_mode = NETIF_NAT_NONE;
+ _G_natifAp[i].NATIF_pnetif = LW_NULL;
+ }
}
for (i = 1; i < LW_CFG_NET_NAT_MAX_LOCAL_IF; i++) {
_G_natifLocal[i].NATIF_cIfName[0] = PX_EOS;
- _G_natifLocal[i].NATIF_pnetif = LW_NULL;
+ if (_G_natifLocal[i].NATIF_pnetif) {
+ _G_natifLocal[i].NATIF_pnetif->nat_mode = NETIF_NAT_NONE;
+ _G_natifLocal[i].NATIF_pnetif = LW_NULL;
+ }
}
_G_bNatStart = LW_FALSE;
__NAT_UNLOCK();
@@ -1457,6 +1440,9 @@ INT __natAddLocal (CPCHAR pcLocal)
__NAT_UNLOCK();
_G_natifLocal[i].NATIF_pnetif = netif_find(pcLocal);
+ if (_G_natifLocal[i].NATIF_pnetif) {
+ _G_natifLocal[i].NATIF_pnetif->nat_mode = NETIF_NAT_LOCAL;
+ }
return (ERROR_NONE);
}
@@ -1492,6 +1478,9 @@ INT __natAddAp (CPCHAR pcAp)
__NAT_UNLOCK();
_G_natifAp[i].NATIF_pnetif = netif_find(pcAp);
+ if (_G_natifAp[i].NATIF_pnetif) {
+ _G_natifAp[i].NATIF_pnetif->nat_mode = NETIF_NAT_AP;
+ }
return (ERROR_NONE);
}
diff --git a/SylixOS/net/lwip/tools/qos/lwip_qos.c b/SylixOS/net/lwip/tools/qos/lwip_qos.c
index 5d8cd92..4b17c9e 100644
--- a/SylixOS/net/lwip/tools/qos/lwip_qos.c
+++ b/SylixOS/net/lwip/tools/qos/lwip_qos.c
@@ -819,11 +819,11 @@ INT API_INetQosInit (VOID)
API_TShellHelpAdd("qoss", "show QoS rule(s).\n");
API_TShellKeywordAdd("qosruleadd", __tshellNetQosRuleAdd);
- API_TShellFormatAdd("qosruleadd", " [netifname] [rule] [args...] [prio] [dont_drop]");
+ API_TShellFormatAdd("qosruleadd", " [netifname] [rule] [args...] [s|d|b] [prio] [dont_drop]");
API_TShellHelpAdd("qosruleadd", "add a rule into QoS.\n"
- " qosruleadd en1 ip 192.168.0.5 192.168.0.10 5 no\n"
- " qosruleadd lo0 udp 0.0.0.0 255.255.255.255 433 500 6 yes\n"
- " qosruleadd wl2 tcp 192.168.0.1 192.168.0.200 169 169 2 no\n");
+ " qosruleadd en1 ip 192.168.0.5 192.168.0.10 s 5 no\n"
+ " qosruleadd lo0 udp 0.0.0.0 255.255.255.255 433 500 b 6 yes\n"
+ " qosruleadd wl2 tcp 192.168.0.1 192.168.0.200 169 169 d 2 no\n");
API_TShellKeywordAdd("qosruledel", __tshellNetQosRuleDel);
API_TShellFormatAdd("qosruledel", " [netifname] [rule sequence num]");
diff --git a/SylixOS/posix/include/px_pthread.h b/SylixOS/posix/include/px_pthread.h
index bbf2a4b..c337df6 100644
--- a/SylixOS/posix/include/px_pthread.h
+++ b/SylixOS/posix/include/px_pthread.h
@@ -169,7 +169,7 @@ LW_API int pthread_attr_destroy(pthread_attr_t *pattr);
LW_API int pthread_attr_setstack(pthread_attr_t *pattr, void *pvStackAddr, size_t stSize);
LW_API int pthread_attr_getstack(const pthread_attr_t *pattr, void **ppvStackAddr, size_t *pstSize);
LW_API int pthread_attr_setguardsize(pthread_attr_t *pattr, size_t stGuard);
-LW_API int pthread_attr_getguardsize(pthread_attr_t *pattr, size_t *pstGuard);
+LW_API int pthread_attr_getguardsize(const pthread_attr_t *pattr, size_t *pstGuard);
LW_API int pthread_attr_setstacksize(pthread_attr_t *pattr, size_t stSize);
LW_API int pthread_attr_getstacksize(const pthread_attr_t *pattr, size_t *pstSize);
LW_API int pthread_attr_setstackaddr(pthread_attr_t *pattr, void *pvStackAddr);
@@ -190,6 +190,8 @@ LW_API int pthread_attr_setname(pthread_attr_t *pattr, const char *pc
LW_API int pthread_attr_getname(const pthread_attr_t *pattr, char **ppcName);
#if LW_CFG_POSIXEX_EN > 0
+LW_API int pthread_attr_setinitonly_np(pthread_attr_t *pattr, int init);
+LW_API int pthread_attr_getinitonly_np(const pthread_attr_t *pattr, int *pinit);
LW_API int pthread_attr_get_np(pthread_t thread, pthread_attr_t *pattr);
LW_API int pthread_getattr_np(pthread_t thread, pthread_attr_t *pattr);
LW_API int pthread_setname_np(pthread_t thread, const char *name);
diff --git a/SylixOS/posix/include/px_pthread_np.h b/SylixOS/posix/include/px_pthread_np.h
index cf8f19b..2f7313c 100644
--- a/SylixOS/posix/include/px_pthread_np.h
+++ b/SylixOS/posix/include/px_pthread_np.h
@@ -43,6 +43,7 @@ extern "C" {
LW_API int pthread_null_attr_method_np(int method, int *old_method);
+LW_API int pthread_start_np(pthread_t thread);
LW_API int pthread_wakeup_np(pthread_t thread, int timeout_only);
LW_API int pthread_attr_get_np(pthread_t thread, pthread_attr_t *pattr);
diff --git a/SylixOS/posix/pthread/pthread.c b/SylixOS/posix/pthread/pthread.c
index 6e38619..0f1e7e3 100644
--- a/SylixOS/posix/pthread/pthread.c
+++ b/SylixOS/posix/pthread/pthread.c
@@ -181,11 +181,45 @@ int pthread_create (pthread_t *pthread,
*pthread = ulId; /* 保存线程句柄 */
}
- API_ThreadStart(ulId);
+ if (!(lwattr.THREADATTR_ulOption & LW_OPTION_THREAD_INIT)) {
+ API_ThreadStart(ulId);
+ }
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: pthread_start_np
+** 功能描述: 启动一个已经被初始化的 posix 线程.
+** 输 入 : thread 线程 id.
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_POSIXEX_EN > 0
+
+LW_API
+int pthread_start_np (pthread_t thread)
+{
+ ULONG ulError;
+
+ PX_ID_VERIFY(thread, pthread_t);
+
+ ulError = API_ThreadStart(thread);
+ switch (ulError) {
+
+ case ERROR_KERNEL_HANDLE_NULL:
+ case ERROR_THREAD_NULL:
+ errno = ESRCH;
+ return (ESRCH);
+
+ default:
+ return ((int)ulError);
+ }
+}
+
+#endif /* LW_CFG_POSIXEX_EN > 0 */
+/*********************************************************************************************************
** 函数名称: pthread_cancel
** 功能描述: cancel 一个 posix 线程.
** 输 入 : thread 线程 id.
diff --git a/SylixOS/posix/pthread/pthread_attr.c b/SylixOS/posix/pthread/pthread_attr.c
index d96e9a3..3476012 100644
--- a/SylixOS/posix/pthread/pthread_attr.c
+++ b/SylixOS/posix/pthread/pthread_attr.c
@@ -176,7 +176,7 @@ int pthread_attr_setguardsize (pthread_attr_t *pattr, size_t stGuard)
API 函数
*********************************************************************************************************/
LW_API
-int pthread_attr_getguardsize (pthread_attr_t *pattr, size_t *pstGuard)
+int pthread_attr_getguardsize (const pthread_attr_t *pattr, size_t *pstGuard)
{
if ((pattr == LW_NULL) || (pstGuard == LW_NULL)) {
errno = EINVAL;
@@ -593,6 +593,63 @@ int pthread_attr_getname (const pthread_attr_t *pattr, char **ppcName)
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: pthread_attr_setinitonly_np
+** 功能描述: 设置一个线程属性块是否仅初始化线程.
+** 输 入 : pattr 需要设置的 attr 指针.
+** init 是否仅初始化线程
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_POSIXEX_EN > 0
+
+LW_API
+int pthread_attr_setinitonly_np (pthread_attr_t *pattr, int init)
+{
+ if (pattr == LW_NULL) {
+ errno = EINVAL;
+ return (EINVAL);
+ }
+
+ if (init) {
+ pattr->PTHREADATTR_ulOption |= LW_OPTION_THREAD_INIT;
+ } else {
+ pattr->PTHREADATTR_ulOption &= ~LW_OPTION_THREAD_INIT;
+ }
+
+ return (ERROR_NONE);
+}
+
+/*********************************************************************************************************
+** 函数名称: pthread_attr_getinitonly_np
+** 功能描述: 获取一个线程属性块是否仅初始化线程.
+** 输 入 : pattr 需要设置的 attr 指针.
+** pinit 是否仅初始化线程
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+int pthread_attr_getinitonly_np (const pthread_attr_t *pattr, int *pinit)
+{
+ if ((pattr == LW_NULL) || !pinit) {
+ errno = EINVAL;
+ return (EINVAL);
+ }
+
+ if (pattr->PTHREADATTR_ulOption & LW_OPTION_THREAD_INIT) {
+ *pinit = 1;
+ } else {
+ *pinit = 0;
+ }
+
+ return (ERROR_NONE);
+}
+
+#endif /* LW_CFG_POSIXEX_EN > 0 */
+/*********************************************************************************************************
** 函数名称: pthread_attr_get_np
** 功能描述: 获取线程属性控制块 (FreeBSD 扩展接口)
** 输 入 : thread 线程 ID
diff --git a/SylixOS/posix/pthread/pthread_key.c b/SylixOS/posix/pthread/pthread_key.c
index f05c8b7..16f610a 100644
--- a/SylixOS/posix/pthread/pthread_key.c
+++ b/SylixOS/posix/pthread/pthread_key.c
@@ -288,6 +288,24 @@ __re_check:
__PX_UNLOCK(); /* 解锁 posix 库 */
}
/*********************************************************************************************************
+** 函数名称: _PthreadKeyCleanup
+** 功能描述: 删除所有与当前线程相关的内部数据节点.
+** 输 入 : pkey 键 (返回)
+** fdestructor 删除函数
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+** 注 意 : 进程回收内存空间之前会预先调用此函数.
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+
+VOID _PthreadKeyCleanup (PLW_CLASS_TCB ptcbDel)
+{
+ __pthreadDataDeleteByThread(ptcbDel->TCB_ulId, LW_NULL, ptcbDel);
+}
+
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
** 函数名称: pthread_key_create
** 功能描述: 创建一个数据键.
** 输 入 : pkey 键 (返回)
diff --git a/SylixOS/shell/ttinyShell/ttinyShellLib.c b/SylixOS/shell/ttinyShell/ttinyShellLib.c
index 5301fc6..9999986 100644
--- a/SylixOS/shell/ttinyShell/ttinyShellLib.c
+++ b/SylixOS/shell/ttinyShell/ttinyShellLib.c
@@ -91,6 +91,12 @@
#include "../SylixOS/shell/hashLib/hashHorner.h"
#include "../SylixOS/shell/ttinyVar/ttinyVarLib.h"
/*********************************************************************************************************
+ 内部进程相关函数声明
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+#include "../SylixOS/loader/include/loader_vppatch.h"
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
背景控制 (t_shell 线程中通过接收的命令字符串末尾判断)
*********************************************************************************************************/
#define __TTINY_SHELL_BG_ASYNC '&' /* 背景异步执行 */
@@ -841,7 +847,15 @@ INT __tshellRestartEx (LW_OBJECT_HANDLE ulThread, BOOL bNeedAuthen)
if (ulJoin) {
#if LW_CFG_SIGNAL_EN > 0
- kill(ulJoin, SIGKILL); /* 杀死等待的线程/进程 */
+#if LW_CFG_MODULELOADER_EN > 0
+ pid_t pid = vprocGetPidByThread(ulJoin);
+ if (pid > 0) {
+ kill(pid, SIGKILL); /* 杀死等待的进程 */
+ } else
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+ {
+ kill(ulJoin, SIGKILL); /* 杀死等待的线程 */
+ }
#else
API_ThreadDelete(&ulJoin, LW_NULL);
#endif /* LW_CFG_SIGNAL_EN > 0 */
diff --git a/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c b/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c
index c26be34..4e2430e 100644
--- a/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c
+++ b/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c
@@ -892,7 +892,7 @@ static INT __tshellSysCmdMems (INT iArgC, PCHAR ppcArgV[])
static INT __tshellSysCmdKill (INT iArgC, PCHAR ppcArgV[])
{
LW_OBJECT_HANDLE ulId = LW_OBJECT_HANDLE_INVALID;
- INT iSigNum = SIGTERM;
+ INT iSigNum = SIGKILL;
if (iArgC == 2) {
if (ppcArgV[1][0] < '0' ||
@@ -937,7 +937,7 @@ static INT __tshellSysCmdKill (INT iArgC, PCHAR ppcArgV[])
static INT __tshellSysCmdSigqueue (INT iArgC, PCHAR ppcArgV[])
{
LW_OBJECT_HANDLE ulId = LW_OBJECT_HANDLE_INVALID;
- INT iSigNum = SIGTERM;
+ INT iSigNum = SIGKILL;
union sigval sigvalue;
sigvalue.sival_int = 0;
diff --git a/SylixOS/system/signal/signal.c b/SylixOS/system/signal/signal.c
index 47fc3aa..ac617cc 100644
--- a/SylixOS/system/signal/signal.c
+++ b/SylixOS/system/signal/signal.c
@@ -834,8 +834,13 @@ INT kill (LW_OBJECT_HANDLE ulId, INT iSigNo)
#endif
#if LW_CFG_MODULELOADER_EN > 0
+ pid_t pid;
+
if (ulId <= LW_CFG_MAX_THREADS) { /* 进程号 */
+ pid = (pid_t)ulId;
ulId = vprocMainThread((pid_t)ulId);
+ } else {
+ pid = 0;
}
#endif /* LW_CFG_MODULELOADER_EN > 0 */
@@ -870,6 +875,12 @@ INT kill (LW_OBJECT_HANDLE ulId, INT iSigNo)
}
#endif /* LW_CFG_SMP_EN */
+#if LW_CFG_MODULELOADER_EN > 0
+ if ((iSigNo == SIGKILL) && (pid > 0)) {
+ vprocKillPrepare(pid, ulId); /* 进程 KILL 预处理 */
+ }
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
__KERNEL_ENTER(); /* 进入内核 */
if (_Thread_Invalid(usIndex)) {
__KERNEL_EXIT(); /* 退出内核 */
@@ -947,8 +958,13 @@ static INT __sigqueue (LW_OBJECT_HANDLE ulId, INT iSigNo, PVOID psigvalue)
sigvalue.sival_ptr = psigvalue;
#if LW_CFG_MODULELOADER_EN > 0
+ pid_t pid;
+
if (ulId <= LW_CFG_MAX_THREADS) { /* 进程号 */
+ pid = (pid_t)ulId;
ulId = vprocMainThread((pid_t)ulId);
+ } else {
+ pid = 0;
}
#endif /* LW_CFG_MODULELOADER_EN > 0 */
@@ -970,6 +986,12 @@ static INT __sigqueue (LW_OBJECT_HANDLE ulId, INT iSigNo, PVOID psigvalue)
}
#endif /* LW_CFG_SMP_EN */
+#if LW_CFG_MODULELOADER_EN > 0
+ if ((iSigNo == SIGKILL) && (pid > 0)) {
+ vprocKillPrepare(pid, ulId); /* 进程 KILL 预处理 */
+ }
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
__KERNEL_ENTER(); /* 进入内核 */
if (_Thread_Invalid(usIndex)) {
__KERNEL_EXIT(); /* 退出内核 */
diff --git a/SylixOS/system/signal/signalEvent.c b/SylixOS/system/signal/signalEvent.c
index aac3772..cf11c62 100644
--- a/SylixOS/system/signal/signalEvent.c
+++ b/SylixOS/system/signal/signalEvent.c
@@ -150,6 +150,9 @@ static INT _doSigEventInternal (LW_OBJECT_HANDLE ulId, PSIGNAL_EVENT_ARG psi
#if LW_CFG_SIGNALFD_EN > 0
LW_SEND_VAL sendval;
#endif
+#if LW_CFG_MODULELOADER_EN > 0
+ pid_t pid;
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
struct sigevent *psigevent = &psigea->SE_event.SE_sigevent;
struct siginfo *psiginfo = &psigea->SE_event.SE_siginfo;
@@ -170,7 +173,10 @@ static INT _doSigEventInternal (LW_OBJECT_HANDLE ulId, PSIGNAL_EVENT_ARG psi
#if LW_CFG_MODULELOADER_EN > 0
if (ulId <= LW_CFG_MAX_THREADS) { /* 进程号 */
+ pid = (pid_t)ulId;
ulId = vprocMainThread((pid_t)ulId);
+ } else {
+ pid = 0;
}
#endif /* LW_CFG_MODULELOADER_EN > 0 */
@@ -213,6 +219,12 @@ static INT _doSigEventInternal (LW_OBJECT_HANDLE ulId, PSIGNAL_EVENT_ARG psi
}
#endif /* LW_CFG_SMP_EN */
+#if LW_CFG_MODULELOADER_EN > 0
+ if ((psigevent->sigev_signo == SIGKILL) && (pid > 0)) {
+ vprocKillPrepare(pid, ulId); /* 进程 KILL 预处理 */
+ }
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
__KERNEL_ENTER(); /* 进入内核 */
if (_Thread_Invalid(usIndex)) {
__KERNEL_EXIT(); /* 退出内核 */
diff --git a/SylixOS/system/signal/signalLib.c b/SylixOS/system/signal/signalLib.c
index 85f4f04..1e010fb 100644
--- a/SylixOS/system/signal/signalLib.c
+++ b/SylixOS/system/signal/signalLib.c
@@ -115,20 +115,16 @@ static BOOL _sigPendRunSelf(VOID);
/*********************************************************************************************************
** 函数名称: __signalCnclHandle
** 功能描述: SIGCNCL 信号的服务函数
-** 输 入 : iSigNo 信号数值
+** 输 入 : ptcbCur 当前任务
+** iSigNo 信号数值
** psiginfo 信号信息
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static VOID __signalCnclHandle (INT iSigNo, struct siginfo *psiginfo)
+static VOID __signalCnclHandle (PLW_CLASS_TCB ptcbCur, INT iSigNo, struct siginfo *psiginfo)
{
- LW_OBJECT_HANDLE ulId;
- PLW_CLASS_TCB ptcbCur;
-
- LW_TCB_GET_CUR_SAFE(ptcbCur);
-
- ulId = ptcbCur->TCB_ulId;
+ LW_OBJECT_HANDLE ulId = ptcbCur->TCB_ulId;
if (ptcbCur->TCB_iCancelState == LW_THREAD_CANCEL_ENABLE &&
ptcbCur->TCB_iCancelType == LW_THREAD_CANCEL_DEFERRED &&
@@ -142,30 +138,19 @@ static VOID __signalCnclHandle (INT iSigNo, struct siginfo *psiginfo)
}
/*********************************************************************************************************
** 函数名称: __signalExitHandle
-** 功能描述: SIGCANCEL 信号的服务函数
-** 输 入 : iSigNo 信号数值
+** 功能描述: 需要进程退出的信号的服务函数
+** 输 入 : ptcbCur 当前任务
+** iSigNo 信号数值
** psiginfo 信号信息
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static VOID __signalExitHandle (INT iSigNo, struct siginfo *psiginfo)
+static VOID __signalExitHandle (PLW_CLASS_TCB ptcbCur, INT iSigNo, struct siginfo *psiginfo)
{
- LW_OBJECT_HANDLE ulId;
- PLW_CLASS_TCB ptcbCur;
+ LW_OBJECT_HANDLE ulId = ptcbCur->TCB_ulId;
#if LW_CFG_MODULELOADER_EN > 0
- pid_t pid = getpid();
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-
- LW_TCB_GET_CUR_SAFE(ptcbCur);
-
- ulId = ptcbCur->TCB_ulId;
-
-#if LW_CFG_MODULELOADER_EN > 0
- if ((pid > 0) && (iSigNo != SIGTERM)) {
- vprocExitModeSet(pid, LW_VPROC_EXIT_FORCE); /* 强制进程退出 */
- vprocSetImmediatelyTerm(pid); /* 立即退出模式 */
- }
+ pid_t pid = vprocGetPidByTcb(ptcbCur);
#endif /* LW_CFG_MODULELOADER_EN > 0 */
if ((iSigNo == SIGBUS) ||
@@ -173,28 +158,64 @@ static VOID __signalExitHandle (INT iSigNo, struct siginfo *psiginfo)
(iSigNo == SIGSEGV) ||
(iSigNo == SIGILL) ||
(iSigNo == SIGFPE) ||
- (iSigNo == SIGSYS)) {
+ (iSigNo == SIGSYS)) { /* 整个进程需要退出 */
#if LW_CFG_MODULELOADER_EN > 0
+ if (pid > 0) {
+ vprocExitModeSet(pid, LW_VPROC_EXIT_FORCE); /* 强制进程退出 */
+ vprocSetImmediatelyTerm(pid); /* 立即退出模式 */
+ }
__LW_FATAL_ERROR_HOOK(pid, ulId, psiginfo); /* 关键性异常 */
#else
__LW_FATAL_ERROR_HOOK(0, ulId, psiginfo); /* 关键性异常 */
#endif /* LW_CFG_MODULELOADER_EN > 0 */
_exit(psiginfo->si_int);
- } else { /* 非关键性异常 */
- API_ThreadDelete(&ulId, (PVOID)psiginfo->si_int); /* 删除自己 */
- } /* 如果在安全模式, 则退出安全 */
+ } else if (iSigNo != SIGTERM) { /* 仅删除当前线程 */
+ if (pid > 0 && vprocIsMainThread()) {
+ vprocExitModeSet(pid, LW_VPROC_EXIT_FORCE); /* 强制进程退出 */
+ vprocSetImmediatelyTerm(pid); /* 立即退出模式 */
+ }
+ }
+ /* 删除自己 */
+ API_ThreadDelete(&ulId, (PVOID)psiginfo->si_int); /* 如果在安全模式, 则退出安全 */
} /* 模式后, 自动被删除 */
/*********************************************************************************************************
+** 函数名称: __signalKillHandle
+** 功能描述: SIGKILL 信号的服务函数
+** 输 入 : ptcbCur 当前任务
+** iSigNo 信号数值
+** psiginfo 信号信息
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+
+static VOID __signalKillHandle (PLW_CLASS_TCB ptcbCur, INT iSigNo, struct siginfo *psiginfo)
+{
+ LW_OBJECT_HANDLE ulId = ptcbCur->TCB_ulId;
+ pid_t pid = vprocGetPidByTcb(ptcbCur);
+
+ if (pid > 0 && vprocIsMainThread()) {
+ vprocExitModeSet(pid, LW_VPROC_EXIT_FORCE); /* 强制进程退出 */
+ vprocSetImmediatelyTerm(pid); /* 立即退出模式 */
+ }
+
+ API_ThreadDelete(&ulId, (PVOID)psiginfo->si_int); /* 删除自己 */
+}
+
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
** 函数名称: __signalWaitHandle
** 功能描述: 回收子进程资源
-** 输 入 : iSigNo 信号数值
+** 输 入 : ptcbCur 当前任务
+** iSigNo 信号数值
** psiginfo 信号信息
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static VOID __signalWaitHandle (INT iSigNo, struct siginfo *psiginfo)
+static VOID __signalWaitHandle (PLW_CLASS_TCB ptcbCur, INT iSigNo, struct siginfo *psiginfo)
{
#if LW_CFG_MODULELOADER_EN > 0
reclaimchild(psiginfo->si_pid);
@@ -203,18 +224,19 @@ static VOID __signalWaitHandle (INT iSigNo, struct siginfo *psiginfo)
/*********************************************************************************************************
** 函数名称: __signalStopHandle
** 功能描述: SIGSTOP / SIGTSTP 信号的服务函数
-** 输 入 : iSigNo 信号数值
+** 输 入 : ptcbCur 当前任务
+** iSigNo 信号数值
** psiginfo 信号信息
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static VOID __signalStopHandle (INT iSigNo, struct siginfo *psiginfo)
+static VOID __signalStopHandle (PLW_CLASS_TCB ptcbCur, INT iSigNo, struct siginfo *psiginfo)
{
sigset_t sigsetMask;
#if LW_CFG_MODULELOADER_EN > 0
- LW_LD_VPROC *pvproc = __LW_VP_GET_CUR_PROC();
+ LW_LD_VPROC *pvproc = __LW_VP_GET_TCB_PROC(ptcbCur);
#endif /* LW_CFG_MODULELOADER_EN */
sigsetMask = ~__SIGNO_UNMASK;
@@ -238,12 +260,13 @@ static VOID __signalStopHandle (INT iSigNo, struct siginfo *psiginfo)
/*********************************************************************************************************
** 函数名称: __signalStkShowHandle
** 功能描述: 打印上下文服务函数
-** 输 入 : psigctlmsg 信号控制信息
+** 输 入 : ptcbCur 当前任务
+** psigctlmsg 信号控制信息
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static VOID __signalStkShowHandle (PLW_CLASS_SIGCTLMSG psigctlmsg)
+static VOID __signalStkShowHandle (PLW_CLASS_TCB ptcbCur, PLW_CLASS_SIGCTLMSG psigctlmsg)
{
#if LW_CFG_ABORT_CALLSTACK_INFO_EN > 0
API_BacktraceShow(STD_OUT, 100);
@@ -382,6 +405,10 @@ static VOID __sigMakeReady (PLW_CLASS_TCB ptcb,
return;
}
+ if (ptcb->TCB_usStatus & LW_THREAD_STATUS_INIT) { /* 线程仅被初始化, 则线程就绪 */
+ ptcb->TCB_usStatus &= ~LW_THREAD_STATUS_INIT; /* 去掉 init 标志 */
+ }
+
ppcb = _GetPcb(ptcb); /* 获得优先级控制块 */
if (ptcb->TCB_usStatus & LW_THREAD_STATUS_DELAY) { /* 存在于唤醒队列中 */
__DEL_FROM_WAKEUP_LINE(ptcb); /* 从等待链中删除 */
@@ -617,11 +644,13 @@ static VOID __sigRunHandle (PLW_CLASS_SIGCONTEXT psigctx,
PLW_CLASS_SIGCTLMSG psigctlmsg)
{
REGISTER struct sigaction *psigaction;
-
+ PLW_CLASS_TCB ptcbCur;
REGISTER VOIDFUNCPTR pfuncHandle;
PVOID pvCtx;
__KERNEL_ENTER(); /* 进入内核 */
+ LW_TCB_GET_CUR(ptcbCur); /* 获得当前 TCB */
+
psigaction = &psigctx->SIGCTX_sigaction[__sigindex(iSigNo)];
pfuncHandle = (VOIDFUNCPTR)psigaction->sa_handler; /* 获得信号执行函数句柄 */
@@ -630,70 +659,78 @@ static VOID __sigRunHandle (PLW_CLASS_SIGCONTEXT psigctx,
}
__KERNEL_EXIT(); /* 退出内核 */
- if ((pfuncHandle != SIG_IGN) &&
- (pfuncHandle != SIG_ERR) &&
- (pfuncHandle != SIG_DFL) &&
- (pfuncHandle != SIG_CATCH) &&
- (pfuncHandle != SIG_HOLD)) {
- pvCtx = (psigctlmsg)
- ? &psigctlmsg->SIGCTLMSG_archRegCtx
- : LW_NULL;
-
- if (psigaction->sa_flags & SA_SIGINFO) { /* 需要 siginfo_t 信息 */
- LW_SOFUNC_PREPARE(pfuncHandle);
- pfuncHandle(iSigNo, psiginfo, pvCtx); /* 执行信号句柄 */
-
- } else {
- LW_SOFUNC_PREPARE(pfuncHandle);
- pfuncHandle(iSigNo, pvCtx); /* XXX 是否传入 pvCtx 参数 ? */
- }
-
- if (__SIGNO_MUST_EXIT & __sigmask(iSigNo)) { /* 必须退出 */
- __signalExitHandle(iSigNo, psiginfo);
+#if LW_CFG_MODULELOADER_EN > 0 /* 进程 KILL 不执行安装句柄 */
+ if (iSigNo == SIGKILL && __LW_VP_GET_TCB_PROC(ptcbCur)) {
+ __signalKillHandle(ptcbCur, iSigNo, psiginfo); /* 立即退出 */
+
+ } else
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+ {
+ if ((pfuncHandle != SIG_IGN) &&
+ (pfuncHandle != SIG_ERR) &&
+ (pfuncHandle != SIG_DFL) &&
+ (pfuncHandle != SIG_CATCH) &&
+ (pfuncHandle != SIG_HOLD)) { /* 需要执行用户句柄 */
+ pvCtx = (psigctlmsg)
+ ? &psigctlmsg->SIGCTLMSG_archRegCtx
+ : LW_NULL;
+
+ if (psigaction->sa_flags & SA_SIGINFO) { /* 需要 siginfo_t 信息 */
+ LW_SOFUNC_PREPARE(pfuncHandle);
+ pfuncHandle(iSigNo, psiginfo, pvCtx); /* 执行信号句柄 */
+
+ } else {
+ LW_SOFUNC_PREPARE(pfuncHandle);
+ pfuncHandle(iSigNo, pvCtx); /* XXX 是否传入 pvCtx 参数 ? */
+ }
- } else if (iSigNo == SIGCNCL) { /* 线程取消信号 */
- __signalCnclHandle(iSigNo, psiginfo);
- }
-
- } else {
- switch (iSigNo) { /* 默认处理句柄 */
+ if (__SIGNO_MUST_EXIT & __sigmask(iSigNo)) { /* 必须退出 */
+ __signalExitHandle(ptcbCur, iSigNo, psiginfo);
+
+ } else if (iSigNo == SIGCNCL) { /* 线程取消信号 */
+ __signalCnclHandle(ptcbCur, iSigNo, psiginfo);
+ }
- case SIGINT:
- case SIGQUIT:
- case SIGFPE:
- case SIGKILL:
- case SIGBUS:
- case SIGTERM:
- case SIGABRT:
- case SIGILL:
- case SIGSEGV:
- case SIGSYS:
- __signalExitHandle(iSigNo, psiginfo);
- break;
+ } else { /* 其他处理 */
+ switch (iSigNo) { /* 默认处理句柄 */
- case SIGSTOP:
- case SIGTSTP:
- __signalStopHandle(iSigNo, psiginfo);
- break;
-
- case SIGCHLD:
- if ((psiginfo->si_code == CLD_EXITED) ||
- (psiginfo->si_code == CLD_KILLED) ||
- (psiginfo->si_code == CLD_DUMPED)) { /* 回收子进程资源 */
- __signalWaitHandle(iSigNo, psiginfo);
+ case SIGINT:
+ case SIGQUIT:
+ case SIGFPE:
+ case SIGKILL:
+ case SIGBUS:
+ case SIGTERM:
+ case SIGABRT:
+ case SIGILL:
+ case SIGSEGV:
+ case SIGSYS:
+ __signalExitHandle(ptcbCur, iSigNo, psiginfo);
+ break;
+
+ case SIGSTOP:
+ case SIGTSTP:
+ __signalStopHandle(ptcbCur, iSigNo, psiginfo);
+ break;
+
+ case SIGCHLD:
+ if ((psiginfo->si_code == CLD_EXITED) ||
+ (psiginfo->si_code == CLD_KILLED) ||
+ (psiginfo->si_code == CLD_DUMPED)) { /* 回收子进程资源 */
+ __signalWaitHandle(ptcbCur, iSigNo, psiginfo);
+ }
+ break;
+
+ case SIGCNCL:
+ __signalCnclHandle(ptcbCur, iSigNo, psiginfo);
+ break;
+
+ case SIGSTKSHOW:
+ __signalStkShowHandle(ptcbCur, psigctlmsg);
+ break;
+
+ default:
+ break;
}
- break;
-
- case SIGCNCL:
- __signalCnclHandle(iSigNo, psiginfo);
- break;
-
- case SIGSTKSHOW:
- __signalStkShowHandle(psigctlmsg);
- break;
-
- default:
- break;
}
}
}
diff --git a/SylixOS/vpmpdm/net/getifaddrs.c b/SylixOS/vpmpdm/net/getifaddrs.c
index d2fb188..276ff24 100644
--- a/SylixOS/vpmpdm/net/getifaddrs.c
+++ b/SylixOS/vpmpdm/net/getifaddrs.c
@@ -37,6 +37,7 @@ __RCSID("$NetBSD: getifaddrs.c,v 1.11.12.1 2009/05/03 13:17:52 bouyer Exp $");
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
+#include <net/if_hwaddr.h>
#include <net/if_types.h>
#include <netinet6/in6.h>
#include <netpacket/packet.h>
@@ -88,23 +89,23 @@ __init_in6 (struct sockaddr_in6 *in6)
}
static void
-__init_ll (struct sockaddr_ll *ll)
+__init_ll (struct sockaddr_ll *ll, u_short hatype, u_char alen)
{
bzero(ll, sizeof(struct sockaddr_ll));
ll->sll_len = sizeof(struct sockaddr_ll);
ll->sll_family = AF_PACKET;
- ll->sll_hatype = ARPHRD_ETHER;
- ll->sll_halen = IFHWADDRLEN;
+ ll->sll_hatype = hatype;
+ ll->sll_halen = alen;
}
static void
-__init_dl (struct sockaddr_dl *dl)
+__init_dl (struct sockaddr_dl *dl, u_char alen)
{
bzero(dl, sizeof(struct sockaddr_dl));
dl->sdl_len = sizeof(struct sockaddr_dl);
dl->sdl_family = AF_LINK;
dl->sdl_nlen = 4;
- dl->sdl_alen = IFHWADDRLEN;
+ dl->sdl_alen = alen;
}
static void
@@ -258,11 +259,16 @@ getifaddrs(struct ifaddrs **pif)
}
if (ioctl(s, SIOCGIFHWADDR, &req[i]) == 0) { /* get hwaddr */
+ u_short hatype;
+ u_char alen;
struct ifaddrs *ifaddr_ll;
struct ifaddrs *ifaddr_dl;
struct sockaddr_ll *ll;
struct sockaddr_dl *dl;
+ hatype = HALTYPE_FROM_SA(&req[i].ifr_hwaddr);
+ alen = HALALEN_FROM_SA(&req[i].ifr_hwaddr);
+
/* setup AF_PACKET */
ifaddr_ll = (struct ifaddrs *)malloc(IFADDR_SIZE);
if (ifaddr_ll == NULL) {
@@ -275,7 +281,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_ll->ifa_flags = ifaddr->ifa_flags;
ll = (struct sockaddr_ll *)ifaddr_ll->ifa_addr;
- __init_ll(ll);
+ __init_ll(ll, hatype, alen);
ll->sll_ifindex = netif_index;
memcpy(ll->sll_addr, req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);
@@ -296,7 +302,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_dl->ifa_flags = ifaddr->ifa_flags;
dl = (struct sockaddr_dl *)ifaddr_dl->ifa_addr;
- __init_dl(dl);
+ __init_dl(dl, alen);
dl->sdl_index = netif_index;
memcpy(LLADDR(dl), req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);