From 98d8145661e4da09eb0f9c40a3cb96590a373115 Mon Sep 17 00:00:00 2001 From: SummerGift Date: Sat, 23 Dec 2017 11:57:30 +0800 Subject: [PATCH 1/3] [nfs] : fix bug in nfs when enable ipv6 --- components/dfs/filesystems/nfs/rpc/clnt_generic.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/dfs/filesystems/nfs/rpc/clnt_generic.c b/components/dfs/filesystems/nfs/rpc/clnt_generic.c index dcc2eb2097..683b2fe42e 100644 --- a/components/dfs/filesystems/nfs/rpc/clnt_generic.c +++ b/components/dfs/filesystems/nfs/rpc/clnt_generic.c @@ -62,7 +62,15 @@ CLIENT *clnt_create (const char *hostname, const unsigned long prog, memset((char*)&sin,0,sizeof(sin)); sin.sin_family = h->h_addrtype; sin.sin_port = 0; - memmove((char *) &sin.sin_addr, h->h_addr, h->h_length); + + if (h->h_addrtype == AF_INET) + { + memmove((char *) &sin.sin_addr, h->h_addr, sizeof(sin.sin_addr)); + } + else + { + return NULL; + } sock = -1; if (strcmp(proto, "udp") == 0) From e8ec10d5e7b969d8534c7459c9f3f9d885ec5524 Mon Sep 17 00:00:00 2001 From: SummerGift Date: Sat, 23 Dec 2017 16:54:24 +0800 Subject: [PATCH 2/3] [nfs] : upgrade from gethostbyname to getaddrinfo --- .../dfs/filesystems/nfs/rpc/clnt_generic.c | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/components/dfs/filesystems/nfs/rpc/clnt_generic.c b/components/dfs/filesystems/nfs/rpc/clnt_generic.c index 683b2fe42e..a6c223317d 100644 --- a/components/dfs/filesystems/nfs/rpc/clnt_generic.c +++ b/components/dfs/filesystems/nfs/rpc/clnt_generic.c @@ -45,39 +45,29 @@ CLIENT *clnt_create (const char *hostname, const unsigned long prog, const unsigned long vers, const char *proto) { int sock; - struct hostent *h; - struct sockaddr_in sin; + struct sockaddr_in server; + struct addrinfo hint, *res = NULL; struct timeval tv; CLIENT *client; - - h = (struct hostent *)gethostbyname(hostname); - if (h == NULL) { - rt_kprintf("unknown host\n"); - return (NULL); - } - if (h->h_addrtype != AF_INET) { - rt_kprintf("unknow inet\n"); - return (NULL); - } - memset((char*)&sin,0,sizeof(sin)); - sin.sin_family = h->h_addrtype; - sin.sin_port = 0; + int ret; - if (h->h_addrtype == AF_INET) - { - memmove((char *) &sin.sin_addr, h->h_addr, sizeof(sin.sin_addr)); - } - else - { - return NULL; - } + memset(&hint, 0, sizeof(hint)); + ret = getaddrinfo(hostname, NULL, &hint, &res); + if (ret != 0) + { + rt_kprintf("getaddrinfo err: %d '%s'\n", ret, hostname); + return NULL; + } + + memcpy(&server, res->ai_addr, sizeof(struct sockaddr_in)); + freeaddrinfo(res); sock = -1; if (strcmp(proto, "udp") == 0) { tv.tv_sec = 5; tv.tv_usec = 0; - client = clntudp_create(&sin, prog, vers, tv, &sock); + client = clntudp_create(&server, prog, vers, tv, &sock); if (client == NULL) return NULL; tv.tv_sec = 1; clnt_control(client, CLSET_TIMEOUT, (char*)&tv); From 3b548038e190958215585866f3b5e5119c2e209b Mon Sep 17 00:00:00 2001 From: SummerGift Date: Sat, 23 Dec 2017 17:00:08 +0800 Subject: [PATCH 3/3] [nfs] : optimize code format --- .../dfs/filesystems/nfs/rpc/clnt_generic.c | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/components/dfs/filesystems/nfs/rpc/clnt_generic.c b/components/dfs/filesystems/nfs/rpc/clnt_generic.c index a6c223317d..a3de64a2f0 100644 --- a/components/dfs/filesystems/nfs/rpc/clnt_generic.c +++ b/components/dfs/filesystems/nfs/rpc/clnt_generic.c @@ -1,4 +1,4 @@ -/* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */ +/* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape @@ -41,17 +41,17 @@ static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI"; * returns client handle. Default options are set, which the user can * change using the rpc equivalent of ioctl()'s. */ -CLIENT *clnt_create (const char *hostname, const unsigned long prog, - const unsigned long vers, const char *proto) +CLIENT *clnt_create(const char *hostname, const unsigned long prog, + const unsigned long vers, const char *proto) { - int sock; - struct sockaddr_in server; - struct addrinfo hint, *res = NULL; - struct timeval tv; - CLIENT *client; - int ret; - - memset(&hint, 0, sizeof(hint)); + int sock; + struct sockaddr_in server; + struct addrinfo hint, *res = NULL; + struct timeval tv; + CLIENT *client; + int ret; + + memset(&hint, 0, sizeof(hint)); ret = getaddrinfo(hostname, NULL, &hint, &res); if (ret != 0) { @@ -62,26 +62,26 @@ CLIENT *clnt_create (const char *hostname, const unsigned long prog, memcpy(&server, res->ai_addr, sizeof(struct sockaddr_in)); freeaddrinfo(res); - sock = -1; - if (strcmp(proto, "udp") == 0) - { - tv.tv_sec = 5; - tv.tv_usec = 0; - client = clntudp_create(&server, prog, vers, tv, &sock); - if (client == NULL) return NULL; - tv.tv_sec = 1; - clnt_control(client, CLSET_TIMEOUT, (char*)&tv); - } - else - { - rt_kprintf("unknow protocol\n"); - return NULL; - } + sock = -1; + if (strcmp(proto, "udp") == 0) + { + tv.tv_sec = 5; + tv.tv_usec = 0; + client = clntudp_create(&server, prog, vers, tv, &sock); + if (client == NULL) return NULL; + tv.tv_sec = 1; + clnt_control(client, CLSET_TIMEOUT, (char *)&tv); + } + else + { + rt_kprintf("unknow protocol\n"); + return NULL; + } - return (client); + return (client); } void clnt_perror(CLIENT *rpch, const char *s) { - rt_kprintf("rpc client error:%s\n", s); + rt_kprintf("rpc client error:%s\n", s); }