/*
* network.c -- Provide common network functions for NFS mount/umount
*
* Copyright (C) 2007 Oracle. All rights reserved.
* Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 0211-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <ctype.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>
#include <rpc/pmap_clnt.h>
#include "sockaddr.h"
#include "xcommon.h"
#include "mount.h"
#include "nls.h"
#include "nfs_mount.h"
#include "mount_constants.h"
#include "nfsrpc.h"
#include "parse_opt.h"
#include "network.h"
#include "conffile.h"
#include "nfslib.h"
#define PMAP_TIMEOUT (10)
#define CONNECT_TIMEOUT (20)
#define MOUNT_TIMEOUT (30)
#define STATD_TIMEOUT (10)
#define SAFE_SOCKADDR(x) (struct sockaddr *)(char *)(x)
extern int nfs_mount_data_version;
extern char *progname;
extern int verbose;
static const char *nfs_mnt_pgmtbl[] = {
"mount",
"mountd",
NULL,
};
static const char *nfs_nfs_pgmtbl[] = {
"nfs",
"nfsprog",
NULL,
};
static const char *nfs_transport_opttbl[] = {
"udp",
"tcp",
"rdma",
"proto",
NULL,
};
static const char *nfs_version_opttbl[] = {
"v2",
"v3",
"v4",
"vers",
"nfsvers",
"v4.0",
"v4.1",
"v4.2",
NULL,
};
static const unsigned long nfs_to_mnt[] = {
0,
0,
1,
3,
};
static const unsigned long mnt_to_nfs[] = {
0,
2,
2,
3,
};
/*
* Map an NFS version into the corresponding Mountd version
*/
unsigned long nfsvers_to_mnt(const unsigned long vers)
{
if (vers <= 3)
return nfs_to_mnt[vers];
return 0;
}
/*
* Map a Mountd version into the corresponding NFS version
*/
static unsigned long mntvers_to_nfs(const unsigned long vers)
{
if (vers <= 3)
return mnt_to_nfs[vers];
return 0;
}
static const unsigned int probe_udp_only[] = {
IPPROTO_UDP,
0,
};
static const unsigned int probe_udp_first[] = {
IPPROTO_UDP,
IPPROTO_TCP,
0,
};
static const unsigned int probe_tcp_first[] = {
IPPROTO_TCP,
IPPROTO_UDP,
0,
};
static const unsigned long probe_nfs2_only[] = {
2,
0,
};
static const unsigned long probe_nfs3_only[] = {
3,
0,
};
static const unsigned long probe_mnt1_first[] = {
1,
2,
0,
};
static const unsigned long probe_mnt3_only[] = {
3,
0,
};
static const unsigned int *nfs_default_proto(void);
#ifdef MOUNT_CONFIG
static const unsigned int *nfs_default_proto()
{
extern unsigned long config_default_proto;
/*
* If the default proto has been set and
* its not TCP, start with UDP
*/
if (config_default_proto && config_default_proto != IPPROTO_TCP)
return probe_udp_first;
return probe_tcp_first;
}
#else
static const unsigned int *nfs_default_proto()
{
return probe_tcp_first;
}
#endif /* MOUNT_CONFIG */
/**
* nfs_lookup - resolve hostname to an IPv4 or IPv6 socket address
* @hostname: pointer to C string containing DNS hostname to resolve
* @family: address family hint
* @sap: pointer to buffer to fill with socket address
* @len: IN: size of buffer to fill; OUT: size of socket address
*
* Returns 1 and places a socket address at @sap if successful;
* otherwise zero.
*/
int nfs_lookup(const char *hostname, const sa_family_t family,
struct sockaddr *sap, socklen_t *salen)
{
struct addrinfo *gai_results;
struct addrinfo gai_hint = {
.ai_family = family,
};
socklen_t len = *salen;
int error, ret = 0;
*salen = 0;
error = getaddrinfo(hostname, NULL, &gai_hint, &gai_results);
switch (error) {
case 0:
break;
case EAI_SYSTEM:
nfs_error(_("%s: DNS resolution failed for %s: %s"),
progname, hostname, strerror(errno));
return ret;
default:
nfs_error(_("%s: DNS resolution failed for %s: %s"),
progname, hostname, gai_strerror(error));
return ret;
}
switch (gai_results->ai_addr->sa_family) {
case AF_INET:
case AF_INET6:
if (len >= gai_results->ai_addrlen) {
*salen = gai_results->ai_addrlen;
memcpy(sap, gai_results->ai_addr, *salen);
ret = 1;
}
break;
default:
/* things are really broken if we get here, so warn */
nfs_error(_("%s: unrecognized DNS resolution results for %s"),
progname, hostname);
break;
}
freeaddrinfo(gai_results);
return ret;
}
/**
* nfs_gethostbyname - resolve a hostname to an IPv4 address
* @hostname: pointer to a C string containing a DNS hostname
* @sin: returns an IPv4 address
*
* Returns 1 if successful, otherwise zero.
*/
int nfs_gethostbyname(const char *hostname, struct sockaddr_in *sin)
{
socklen_t len = sizeof(*sin);
return nfs_lookup(hostname, AF_INET, (struct sockaddr *)sin, &len);
}
/**
* nfs_string_to_sockaddr - convert string address to sockaddr
* @address: pointer to presentation format address to convert
* @sap: pointer to socket address buffer to fill in
* @salen: IN: length of address buffer
* OUT: length of converted socket address
*
* Convert a presentation format address string to a socket address.
* Similar to nfs_lookup(), but the DNS query is squelched, and it
* won't make any noise if the getaddrinfo() call fails.
*
* Returns 1 and fills in @sap and @salen if successful; otherwise zero.
*
* See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
* on presenting IPv6 addresses as text strings.
*/
int nfs_string_to_sockaddr(const char *address, struct sockaddr *sap,
socklen_t *salen)
{
struct addrinfo *gai_results;
struct addrinfo gai_hint = {
.ai_flags = AI_NUMERICHOST,
};
socklen_t len = *salen;
int ret = 0;
*salen = 0;
if (getaddrinfo(address, NULL, &gai_hint, &gai_results) == 0) {
switch (gai_results->ai_addr->sa_family) {
case AF_INET:
case AF_INET6:
if (len >= gai_results->ai_addrlen) {
*salen = gai_results->ai_addrlen;
memcpy(sap, gai_results->ai_addr, *salen);
ret = 1;
}
break;
}
freeaddrinfo(gai_results);
}
return ret;
}
/**
* nfs_present_sockaddr - convert sockaddr to string
* @sap: pointer to socket address to convert
* @salen: length of socket address
* @buf: pointer to buffer to fill in
* @buflen: length of buffer
*
* Convert the passed-in sockaddr-style address to presentation format.
* The presentation format address is placed in @buf and is
* '\0'-terminated.
*
* Returns 1 if successful; otherwise zero.
*
* See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
* on presenting IPv6 addresses as text strings.
*/
int nfs_present_sockaddr(const struct sockaddr *sap, const socklen_t salen,
char *buf, const size_t buflen)
{
#ifdef HAVE_GETNAMEINFO
int result;
result = getnameinfo(sap, salen, buf, buflen,
NULL, 0, NI_NUMERICHOST);
if (!result)
return 1;
nfs_error(_("%s: invalid server address: %s"), progname,
gai_strerror(result));
return 0;
#else /* HAVE_GETNAMEINFO */
char *addr;
if (sap->sa_family == AF_INET) {
addr = inet_ntoa(((struct sockaddr_in *)sap)->sin_addr);
if (addr && strlen(addr) < buflen) {
strcpy(buf, addr);
return 1;
}
}
nfs_error(_("%s: invalid server address"), progname);
return 0;
#endif /* HAVE_GETNAMEINFO */
}
/*
* Attempt to connect a socket, but time out after "timeout" seconds.
*
* On error return, caller clo
没有合适的资源?快使用搜索试试~ 我知道了~
nfs-utils-1.3.0.rar_nfs-utils
共347个文件
c:113个
h:62个
in:36个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 90 浏览量
2022-09-23
00:12:15
上传
评论
收藏 762KB RAR 举报
温馨提示
nfs source code for linux
资源详情
资源评论
资源推荐
收起资源包目录
nfs-utils-1.3.0.rar_nfs-utils (347个子文件)
rpcgen.new.1 10KB
configure.ac 15KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 535B
Makefile.am 464B
Makefile.am 431B
Makefile.am 423B
Makefile.am 422B
Makefile.am 376B
Makefile.am 330B
Makefile.am 330B
Makefile.am 317B
Makefile.am 309B
Makefile.am 306B
Makefile.am 304B
Makefile.am 303B
Makefile.am 276B
Makefile.am 231B
Makefile.am 217B
Makefile.am 202B
Makefile.am 183B
Makefile.am 159B
Makefile.am 135B
Makefile.am 134B
Makefile.am 123B
Makefile.am 121B
Makefile.am 119B
Makefile.am 108B
network.c 43KB
krb5_util.c 37KB
gssd_proc.c 36KB
cache.c 33KB
getport.c 31KB
nfsstat.c 28KB
rpc_main.c 26KB
file.c 26KB
stropts.c 26KB
rpc_svcout.c 25KB
nfsmount.c 23KB
idmapd.c 22KB
mountd.c 21KB
conffile.c 21KB
exports.c 20KB
exportfs.c 19KB
sm-notify.c 18KB
client.c 16KB
rpc_cout.c 16KB
fstab.c 15KB
svcgssd_proc.c 14KB
mount.c 14KB
rpc_socket.c 14KB
rpc_parse.c 14KB
rpc.c 14KB
svc_create.c 13KB
parse_opt.c 13KB
statd.c 12KB
device-discovery.c 12KB
nfs4mount.c 12KB
nfsdcltrack.c 12KB
rpc_hout.c 12KB
dm-device.c 11KB
nsm_client.c 11KB
configfile.c 11KB
mount_libmount.c 10KB
monitor.c 10KB
device-process.c 10KB
sqlite.c 10KB
hostname.c 9KB
context_lucid.c 9KB
gss_util.c 9KB
nfssvc.c 9KB
rpc_scan.c 9KB
nfsd.c 9KB
rpc_util.c 9KB
error.c 9KB
context_mit.c 8KB
hostname.c 8KB
export.c 8KB
context_heimdal.c 8KB
rpcdebug.c 8KB
from_local.c 7KB
nfsumount.c 7KB
cacheio.c 7KB
rpc_sample.c 7KB
showmount.c 7KB
auth.c 7KB
rpc_clntout.c 7KB
nfsidmap.c 6KB
tcpwrapper.c 6KB
rmtcall.c 6KB
gssd_main_loop.c 6KB
共 347 条
- 1
- 2
- 3
- 4
我虽横行却不霸道
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0