summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2020-09-29 13:29:58 (GMT)
committer Hanhui <hanhui@acoinfo.com>2020-09-29 13:29:58 (GMT)
commitbfa6247b5a16fe4a7772a2d05d6f29b515b99f78 (patch)
tree9cb404e38dc04c08590a06f949df15e6f41d535a /SylixOS
parent6bdb7542d4add740326d0ca005124def7c4d014c (diff)
downloadlibsylixos-bfa6247b5a16fe4a7772a2d05d6f29b515b99f78.zip
libsylixos-bfa6247b5a16fe4a7772a2d05d6f29b515b99f78.tar.gz
libsylixos-bfa6247b5a16fe4a7772a2d05d6f29b515b99f78.tar.bz2
Add net interface DNS setting support.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/include/network/lwip/netif.h4
-rw-r--r--SylixOS/include/network/lwip/netifapi.h4
-rw-r--r--SylixOS/net/lwip/lwip_shell.c30
-rw-r--r--SylixOS/net/lwip/src/api/netifapi.c27
-rw-r--r--SylixOS/net/lwip/src/core/netif.c38
5 files changed, 98 insertions, 5 deletions
diff --git a/SylixOS/include/network/lwip/netif.h b/SylixOS/include/network/lwip/netif.h
index 95c753d..be686c1 100644
--- a/SylixOS/include/network/lwip/netif.h
+++ b/SylixOS/include/network/lwip/netif.h
@@ -484,6 +484,10 @@ struct netif *netif_find(const char *name);
void netif_set_default(struct netif *netif);
+#if defined(SYLIXOS) && LW_CFG_LWIP_DNS_SWITCH > 0 /* SylixOS Add netif dns server set */
+void netif_dns_setserver(struct netif *netif, u8_t numdns, const ip_addr_t *dnsserver);
+#endif /* SYLIXOS && LW_CFG_LWIP_DNS_SWITCH */
+
#if LWIP_IPV4
void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
diff --git a/SylixOS/include/network/lwip/netifapi.h b/SylixOS/include/network/lwip/netifapi.h
index 5fbafdb..d080995 100644
--- a/SylixOS/include/network/lwip/netifapi.h
+++ b/SylixOS/include/network/lwip/netifapi.h
@@ -92,6 +92,10 @@ err_t netifapi_netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask, const ip4_addr_t *gw);
#endif /* LWIP_IPV4*/
+#if defined(SYLIXOS) && LW_CFG_LWIP_DNS_SWITCH > 0 /* SylixOS Add netif dns server set */
+err_t netifapi_netif_set_dns(struct netif *netif, u8_t numdns, const ip_addr_t *dnsserver);
+#endif /* SYLIXOS && LW_CFG_LWIP_DNS_SWITCH */
+
err_t netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
netifapi_errt_fn errtfunc);
diff --git a/SylixOS/net/lwip/lwip_shell.c b/SylixOS/net/lwip/lwip_shell.c
index 2271ce6..eaaebc3 100644
--- a/SylixOS/net/lwip/lwip_shell.c
+++ b/SylixOS/net/lwip/lwip_shell.c
@@ -706,14 +706,33 @@ static INT __tshellIfconfig (INT iArgC, PCHAR *ppcArgV)
fprintf(stderr, "can not find net interface.\n");
return (-ERROR_TSHELL_EPARAM);
}
- for (iIndex = 2; iIndex < (iArgC - 1); iIndex += 2) { /* 连续设置参数 */
- if (inet_aton(ppcArgV[iIndex + 1], &inaddr) == 0) { /* 获得 IP 地址 */
+
+ if (lib_strcmp(ppcArgV[2], "dns") == 0 && iArgC > 4) { /* 设置网卡 DNS */
+ INT iDnsIndex = 0;
+
+ sscanf(ppcArgV[3], "%d", &iDnsIndex);
+ if (iDnsIndex >= DNS_MAX_SERVERS) {
+ LWIP_IF_LIST_UNLOCK();
+ fprintf(stderr, "arguments error!\n");
+ return (-ERROR_TSHELL_EPARAM);
+ }
+ if (ipaddr_aton(ppcArgV[4], &ipaddr) == 0) { /* 获得 IP 地址 */
+ LWIP_IF_LIST_UNLOCK();
fprintf(stderr, "address error.\n");
return (-ERROR_TSHELL_EPARAM);
}
- ip_2_ip4(&ipaddr)->addr = inaddr.s_addr;
- IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V4);
- __netIfSet(netif, ppcArgV[iIndex], ip_2_ip4(&ipaddr)); /* 设置网络接口 */
+ netifapi_netif_set_dns(netif, (u8_t)iDnsIndex, &ipaddr);/* 设置 DNS */
+
+ } else {
+ for (iIndex = 2; iIndex < (iArgC - 1); iIndex += 2) { /* 连续设置参数 */
+ if (inet_aton(ppcArgV[iIndex + 1], &inaddr) == 0) { /* 获得 IP 地址 */
+ fprintf(stderr, "address error.\n");
+ return (-ERROR_TSHELL_EPARAM);
+ }
+ ip_2_ip4(&ipaddr)->addr = inaddr.s_addr;
+ IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V4); /* 设置网络接口 */
+ __netIfSet(netif, ppcArgV[iIndex], ip_2_ip4(&ipaddr));
+ }
}
LWIP_IF_LIST_UNLOCK();
}
@@ -1573,6 +1592,7 @@ VOID __tshellNetInit (VOID)
"ifconfig en1 inet 192.168.0.3\n"
"ifconfig en1 netmask 255.255.255.0\n"
"ifconfig en1 gateway 192.168.0.1\n"
+ "ifconfig en1 dns 0 192.168.0.2\n"
"ifconfig dns 0 192.168.0.2\n");
API_TShellKeywordAdd("ifup", __tshellIfUp);
diff --git a/SylixOS/net/lwip/src/api/netifapi.c b/SylixOS/net/lwip/src/api/netifapi.c
index 728bf82..f60c993 100644
--- a/SylixOS/net/lwip/src/api/netifapi.c
+++ b/SylixOS/net/lwip/src/api/netifapi.c
@@ -405,6 +405,33 @@ netifapi_netif_set_addr(struct netif *netif,
}
#endif /* LWIP_IPV4 */
+#if defined(SYLIXOS) && LW_CFG_LWIP_DNS_SWITCH > 0 /* SylixOS Add netif dns server set */
+/**
+ * @ingroup dns
+ * Initialize one of the DNS servers.
+ *
+ * @param netif the network interface
+ * @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
+ * @param dnsserver IP address of the DNS server to set
+ */
+err_t
+netifapi_netif_set_dns(struct netif *netif, u8_t numdns, const ip_addr_t *dnsserver)
+{
+ err_t err;
+
+#if LWIP_TCPIP_CORE_LOCKING
+ err = ERR_OK;
+ LOCK_TCPIP_CORE();
+ netif_dns_setserver(netif, numdns, dnsserver);
+ UNLOCK_TCPIP_CORE();
+#else
+ err = ERR_VAL;
+#endif /* LWIP_TCPIP_CORE_LOCKING */
+
+ return err;
+}
+#endif /* SYLIXOS && LW_CFG_LWIP_DNS_SWITCH */
+
/**
* call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
* way by running that function inside the tcpip_thread context.
diff --git a/SylixOS/net/lwip/src/core/netif.c b/SylixOS/net/lwip/src/core/netif.c
index 279e174..ecfd78c 100644
--- a/SylixOS/net/lwip/src/core/netif.c
+++ b/SylixOS/net/lwip/src/core/netif.c
@@ -463,6 +463,13 @@ netif_add(struct netif *netif,
/* SylixOS Changed pull netif_invoke_ext_callback() here */
netif_invoke_ext_callback(netif, LWIP_NSC_NETIF_ADDED, NULL);
+ /* SylixOS Add init state notify */
+ {
+ netif_ext_callback_args_t arg;
+ arg.status_changed.state = (netif->flags & NETIF_FLAG_UP) ? 1 : 0;
+ netif_invoke_ext_callback(netif, LWIP_NSC_STATUS_CHANGED, &arg);
+ }
+
/* SylixOS Changed push netif_set_addr() here */
#if LWIP_IPV4
netif_set_addr(netif, ipaddr, netmask, gw);
@@ -865,6 +872,37 @@ netif_remove(struct netif *netif)
LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
}
+#if defined(SYLIXOS) && LW_CFG_LWIP_DNS_SWITCH > 0 /* SylixOS Add netif dns server set */
+/**
+ * @ingroup dns
+ * Initialize one of the DNS servers.
+ *
+ * @param netif the network interface
+ * @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
+ * @param dnsserver IP address of the DNS server to set
+ */
+void
+netif_dns_setserver(struct netif *netif, u8_t numdns, const ip_addr_t *dnsserver)
+{
+ if (netif && numdns < DNS_MAX_SERVERS) {
+ if (dnsserver != NULL) {
+ netif->dns_save[numdns] = (*dnsserver);
+ } else {
+ netif->dns_save[numdns] = *IP_ADDR_ANY;
+ }
+ }
+
+ if (netif_default == netif) {
+ int i;
+ for (i = 0; i < DNS_MAX_SERVERS; i++) {
+ if (!ip_addr_isany_val(netif->dns_save[i])) {
+ dns_setserver(i, &netif->dns_save[i]);
+ }
+ }
+ }
+}
+#endif /* SYLIXOS && LW_CFG_LWIP_DNS_SWITCH */
+
/**
* @ingroup netif
* Set a network interface as the default network interface