summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2020-07-27 14:12:14 (GMT)
committer Hanhui <hanhui@acoinfo.com>2020-07-27 14:12:14 (GMT)
commit9539d97b3ccd7e52c41cc47f3baae898f86b51a0 (patch)
tree7093463ebcf2c5b7607589c146b4e67a4b58c523 /SylixOS
parente8e6fece0d82f05c0dffaa5e0b2055049805c504 (diff)
downloadlibsylixos-9539d97b3ccd7e52c41cc47f3baae898f86b51a0.zip
libsylixos-9539d97b3ccd7e52c41cc47f3baae898f86b51a0.tar.gz
libsylixos-9539d97b3ccd7e52c41cc47f3baae898f86b51a0.tar.bz2
Add net interface default gateway ioctl command.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/include/net/if.h4
-rw-r--r--SylixOS/net/lwip/lwip_ifctl.c22
-rw-r--r--SylixOS/net/lwip/lwip_socket.c2
3 files changed, 28 insertions, 0 deletions
diff --git a/SylixOS/include/net/if.h b/SylixOS/include/net/if.h
index 9b43cd9..9bf2627 100644
--- a/SylixOS/include/net/if.h
+++ b/SylixOS/include/net/if.h
@@ -117,6 +117,7 @@ struct ifreq {
struct sockaddr ifru_dstaddr;
struct sockaddr ifru_broadaddr;
struct sockaddr ifru_netmask;
+ struct sockaddr ifru_gateway;
struct sockaddr ifru_hwaddr;
short ifru_flags;
int ifru_ifindex;
@@ -133,6 +134,7 @@ struct ifreq {
#define ifr_addr ifr_ifru.ifru_addr
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
#define ifr_netmask ifr_ifru.ifru_netmask
+#define ifr_gateway ifr_ifru.ifru_gateway
#define ifr_broadaddr ifr_ifru.ifru_broadaddr
#define ifr_hwaddr ifr_ifru.ifru_hwaddr
#define ifr_flags ifr_ifru.ifru_flags
@@ -172,12 +174,14 @@ struct ifconf {
#define SIOCSIFADDR _IOW('i', 12, struct ifreq)
#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq)
+#define SIOCSIFDGWADDR _IOW('i', 15, struct ifreq)
#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq)
#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq)
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq)
#define SIOCGIFADDR _IOWR('i', 33, struct ifreq)
#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq)
+#define SIOCGIFDGWADDR _IOWR('i', 16, struct ifreq)
#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq)
#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq)
#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq)
diff --git a/SylixOS/net/lwip/lwip_ifctl.c b/SylixOS/net/lwip/lwip_ifctl.c
index 6e19657..fba2134 100644
--- a/SylixOS/net/lwip/lwip_ifctl.c
+++ b/SylixOS/net/lwip/lwip_ifctl.c
@@ -357,6 +357,7 @@ static INT __ifSubIoctl4 (INT iCmd, PVOID pvArg)
case SIOCGIFADDR: /* 获取地址操作 */
case SIOCGIFNETMASK:
+ case SIOCGIFDGWADDR:
case SIOCGIFDSTADDR:
case SIOCGIFBRDADDR:
psockaddrin = (struct sockaddr_in *)&(pifreq->ifr_addr);
@@ -367,6 +368,7 @@ static INT __ifSubIoctl4 (INT iCmd, PVOID pvArg)
case SIOCSIFADDR: /* 设置地址操作 */
case SIOCSIFNETMASK:
+ case SIOCSIFDGWADDR:
case SIOCSIFDSTADDR:
case SIOCSIFBRDADDR:
psockaddrin = (struct sockaddr_in *)&(pifreq->ifr_addr);
@@ -388,6 +390,11 @@ static INT __ifSubIoctl4 (INT iCmd, PVOID pvArg)
iRet = ERROR_NONE;
break;
+ case SIOCGIFDGWADDR: /* 默认网关地址 */
+ psockaddrin->sin_addr.s_addr = netif_ip4_gw(pnetif)->addr;
+ iRet = ERROR_NONE;
+ break;
+
case SIOCGIFDSTADDR: /* 获取网卡目标地址 */
if ((pnetif->flags & NETIF_FLAG_BROADCAST) == 0) {
psockaddrin->sin_addr.s_addr = netif_ip4_gw(pnetif)->addr;
@@ -433,6 +440,19 @@ static INT __ifSubIoctl4 (INT iCmd, PVOID pvArg)
}
break;
+ case SIOCSIFDGWADDR: /* 设置默认网关地址 */
+ if (psockaddrin->sin_family == AF_INET) {
+ ip4_addr_t ipaddr;
+ ipaddr.addr = psockaddrin->sin_addr.s_addr;
+ LOCK_TCPIP_CORE(); /* 必须 lock 协议栈 */
+ netif_set_gw(pnetif, &ipaddr);
+ UNLOCK_TCPIP_CORE();
+ iRet = ERROR_NONE;
+ } else {
+ _ErrorHandle(EAFNOSUPPORT);
+ }
+ break;
+
case SIOCSIFDSTADDR: /* 设置网卡目标地址 */
if ((pnetif->flags & NETIF_FLAG_BROADCAST) == 0) {
ip4_addr_t ipaddr;
@@ -811,10 +831,12 @@ INT __ifIoctlInet (INT iCmd, PVOID pvArg)
case SIOCGIFADDR: /* ipv4 操作 */
case SIOCGIFNETMASK:
+ case SIOCGIFDGWADDR:
case SIOCGIFDSTADDR:
case SIOCGIFBRDADDR:
case SIOCSIFADDR:
case SIOCSIFNETMASK:
+ case SIOCSIFDGWADDR:
case SIOCSIFDSTADDR:
case SIOCSIFBRDADDR:
LWIP_IF_LIST_LOCK(LW_FALSE); /* 进入临界区 */
diff --git a/SylixOS/net/lwip/lwip_socket.c b/SylixOS/net/lwip/lwip_socket.c
index c88b5f3..32bb4fe 100644
--- a/SylixOS/net/lwip/lwip_socket.c
+++ b/SylixOS/net/lwip/lwip_socket.c
@@ -630,11 +630,13 @@ static INT __socketIoctl (SOCKET_T *psock, INT iCmd, PVOID pvArg)
case SIOCGIFCONF:
case SIOCSIFADDR:
case SIOCSIFNETMASK:
+ case SIOCSIFDGWADDR:
case SIOCSIFDSTADDR:
case SIOCSIFBRDADDR:
case SIOCSIFFLAGS:
case SIOCGIFADDR:
case SIOCGIFNETMASK:
+ case SIOCGIFDGWADDR:
case SIOCGIFDSTADDR:
case SIOCGIFBRDADDR:
case SIOCGIFFLAGS: