Commit Graph

382 Commits (49eaca0c42a15e1053355af4c96a4bee11cd4be3)

Author SHA1 Message Date
Peter Lieven 6bdcd5b676 examples: add nfs-io example
this simple example tool allows to
- creat and unlink files
- mkdir and rmdir directories
- stat

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 14:50:09 +01:00
Peter Lieven 9126c9c036 add uid and gid URL param to specify alternate uid and/or gid
This allows to connect with an alternate uid or gid than that
of the current user.

Example:
 examples/nfs-ls nfs://10.0.0.1/export?uid=1000&gid=33

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 14:03:26 +01:00
Peter Lieven 1c8b4547ce add tcp-syncnt URL param to adjust TCP_SYNCNT sockopt
This allows indirect support for a configurable connect timeout.

Linux uses a exponential backoff for SYN retries starting
with 1 second.

This means for a value n for TCP_SYNCNT, the connect will
effectively timeout after 2^(n+1)-1 seconds.

Example:
 examples/nfs-ls nfs://10.0.0.1/export?tcp-syncnt=1

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 14:03:18 +01:00
Peter Lieven d2ec73c75a add URL parsing functions
this adds the following 4 functions. see libnfs.h for details.

struct nfs_url *nfs_parse_url_full(struct nfs_context *nfs, char *url);
struct nfs_url *nfs_parse_url_dir(struct nfs_context *nfs, char *url);
struct nfs_url *nfs_parse_url_incomplete(struct nfs_context *nfs, char *url);
void nfs_destroy_url(struct nfs_url *url);

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 14:03:00 +01:00
Peter Lieven 1f3f0d5853 libnfs_zdr_opaque: make valgrind happy
valgrind complains about unitialized memory

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 12:46:31 +01:00
Peter Lieven fadbf8cf56 nfs_creat1_cb: fix memleak
data is not freed in case of a failure.

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-17 11:50:00 +01:00
Peter Lieven b554c8e8d2 libnfs_authunix_create: make valgrind happy
valgrind complains about uninitialized memory.

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-17 11:47:59 +01:00
Ronnie Sahlberg ed09b5676f Initial support for NSM 2013-11-05 17:37:16 -08:00
Ronnie Sahlberg 558aefc736 New version 1.8
Fix nasty memory leak
2013-10-30 18:17:49 -07:00
Ronnie Sahlberg 751770fd43 Dont leak every single buffer we read from the socket. 2013-10-30 18:15:03 -07:00
Ronnie Sahlberg 8733f38d23 Add an async helper function to connect an rpc context to a program/version 2013-10-26 13:16:09 -07:00
Ronnie Sahlberg 3b943d2f68 Add a mechanism to control what the next XID value on a session will be.
This makes it possible for multiple processes/contexts to use the same
target and (with some synchronization) avoid XID collissions across processes/contexts.
2013-10-26 07:44:29 -07:00
Ronnie Sahlberg 6fda9871a0 Mix in the pid in the top 16 bits for the initial xid.
This helps for users which rapidly fork a lot of processes that then
immediately create a new context (I am looking at you dbench)
to awoid having lots of processes starting and using overlapping xid values.
2013-10-25 16:16:43 -07:00
Ronnie Sahlberg e7f3a78172 Don't clamp write3 max to 32k
We use our own XDR and RPC layer nowadays and do not have
any external dependencies to XDR or RPC.

As such we no longer need to clamp the write size to max 32kb
since we never link to the system rpc/xdr libraries.
(and thus dont have to clamp in case the system library is broken for
pdu's > 32k)

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2013-10-23 19:18:41 -07:00
Volker Lendecke cd67ec7d6b Fix typos 2013-10-23 19:13:00 -07:00
Ronnie Sahlberg b93082da2b Make xid be a uint32_t and not either unsigned long or unsigned int 2013-10-21 19:15:11 -07:00
Ronnie Sahlberg 31820d2727 New version 1.7
- Allow nested eventloops so that a sync function can be called from a callback.
 - Fix a bug in unmarshalling a uint64.
 - Add PATHCONF support.
 - WIN32/64 updates
 - AROS updates
2013-10-20 16:31:32 -07:00
Ronnie Sahlberg dd97d43aad Reset the receive buffer processing the received PDU.
This allows us to have recursive eventloops and do synchronous
rpc calls from a callback.
2013-10-20 13:16:45 -07:00
Ronnie Sahlberg c81e7d8921 Make sure the the value is unsigned before we OR it into the uint64_t
or else the sign might be extended.
2013-10-20 12:41:56 -07:00
Ronnie Sahlberg 7e66b28947 Merge branch 'master' of github.com:sahlberg/libnfs 2013-05-30 17:59:24 -07:00
Ronnie Sahlberg 4e019b25b5 On Windows, use 65534/65534 instead of 65535/65535 for the default uid/gid 2013-05-30 17:58:29 -07:00
Memphiz 292e2d9097 [win32] - add projects for examples to the solution and make them compile (all compile but nfsclient-bcast) 2013-05-29 18:41:31 +02:00
Ronnie Sahlberg c5e346e15c More AROS fixes. AROS compiles and works again. 2013-05-28 22:49:19 -07:00
Ronnie Sahlberg 0556ee05e1 Aros fixes 2013-05-28 22:41:54 -07:00
Ronnie Sahlberg 265276038a AROS fixes 2013-05-28 22:13:08 -07:00
Ronnie Sahlberg c022471e52 Add configure test for arpa/inet.h 2013-05-28 21:25:08 -07:00
Ronnie Sahlberg 833d5b9da1 Include ifdef cleanup 2013-05-28 21:20:00 -07:00
Ronnie Sahlberg bff8fe460d Some more configure checks for headers 2013-05-28 17:54:12 -07:00
Ronnie Sahlberg 7057e733c1 Add configure checks for sys/socket.h 2013-05-28 17:43:47 -07:00
Ronnie Sahlberg 728970051c Add configure checks for whether netinet/in.h is available or not 2013-05-28 17:38:37 -07:00
Ronnie Sahlberg cb5b8be2eb Try making the initial port used a little more random 2013-05-28 17:22:28 -07:00
Ronnie Sahlberg 67a9f57e67 WIN32 fixes 2013-05-28 16:15:16 -07:00
Ronnie Sahlberg a60caa0945 New version 1.6
Add AROS/Amiga support
Chose initial XID value better to reduce probability for collissions
Fix bug in the initial default credentials and use getgid() instead of -1
2013-05-27 21:35:26 -07:00
Ronnie Sahlberg 43e0e7a7e6 On unix systems, when creating the default authentication token
use getgid() as the group instead of -1.
Recent linux knfsd do not allow grp==-1

On windows there are no uid/gids in the traditional sense so there I still specify a default credential of uid==gid==-1 :
	rpc->auth = authunix_create("LibNFS", 65535, 65535, 0, NULL);

This is I think the sanest/safest thing to do since most servers will have
special handing of -1 meaning 'nobody' or similar.
This should work on many/most servers and give the user the minimum available
access allowed for 'nobody'.

I think on windows (or AROS for that matter) applications will probably have
to invoke and set the credentials themself explicitely.
Those apps probably, unfortunately, also need to have a configuration
setting to select which uid/gid to use when talking to the server.
(or they could hardcode it)

rpc_set_auth(rpc, libnfs_authunix_create("hostname", uid, gid, 0, NULL))
should do the trick if they call immediately after creating the rpc/nfs context.

But dont set it to 0,0 root/root for uid/gid.
First of all, most servers have root-squash so they will re-map this uid/gid
to 'nobody' internally.
But, if the user uses a server that does not do root-squash, then setting this to 0,0 would mean that your app now access the nfs share as root   which is probably not what you want.
2013-05-25 06:24:15 -07:00
Ronnie Sahlberg 0c1a9d7a6b Fix a bug when returning the filehandle in creat() and return the filehandle
of the object we created and not the filehandle of the parent directory
2013-04-15 21:37:03 -07:00
Ronnie Sahlberg 73f4ae7cca Allow nfs_lookuppath_async to have path[0]=='\0' this happens when we
want to create an object straight under the root directory of what we
mounted.
As always, the actual object to create is then a string starting after the \0 byte
2013-04-15 20:42:44 -07:00
Ronnie Sahlberg 4945f30750 we can always include netinet/in.h all platforms have it 2013-04-14 10:34:33 -07:00
Ronnie Sahlberg 108c622a95 more include cleanups it starts to look almost decent now 2013-04-14 10:32:01 -07:00
Ronnie Sahlberg 00748f36c5 more header include cleanups 2013-04-14 10:11:48 -07:00
Ronnie Sahlberg 2142af5d47 WIN32: More ifdef cleanups 2013-04-14 09:02:23 -07:00
Ronnie Sahlberg 622489d36e WIN32: get rid of some ifdefs 2013-04-14 08:50:38 -07:00
Ronnie Sahlberg 099be710b6 SOCKET: Use recv/send for all socket io on all platforms
instead of only on windows and aros  and read/write on the others
2013-04-14 08:43:59 -07:00
Ronnie Sahlberg 9a9126c3d9 AROS: add inet_pton emulation and make sure we use recv/send and not read/write 2013-04-13 07:40:46 -07:00
Ronnie Sahlberg 2cdf4fcb07 AROS: it is called IoctlSocket/CloseSocket and WaitSelect on AROS.
Additionally add a aros_init_socket() function to open the bsd socket library and set up networking
2013-04-12 06:12:58 -07:00
Ronnie Sahlberg e77d093c37 AROS: getting closer to link. only a handful of missing symbols now 2013-04-11 18:37:05 -07:00
Ronnie Sahlberg d7c6e9aaa9 Initial AROS support.
The test app doesnt link yet since we are missing a bunch of symbols

but it is a start
2013-04-10 20:28:40 -07:00
Steve Cai a27561934c randomize the initial rpc xid to avoid reply cache collision 2013-02-25 16:40:29 -08:00
Ronnie Sahlberg 8afcdc959f New version 1.5
- Switch to our own builtin RPC/XDR replacement
- Android support
2012-12-03 06:38:18 -08:00
Ronnie Sahlberg e803ae5760 Rearrange the header files.
Move the headers we install to ./include/nfsc
and start including nfsc/libnfs-zdr.h  from all the other header files.
2012-11-28 20:21:53 -08:00
Cory Fields 252aa90dc8 [droid] Support building for android
These are the changes necessary to build for android. Working status is yet
untested.
2012-11-28 12:04:10 -05:00
Ronnie Sahlberg f816bf4c76 Merge branch 'zdr'
Manually fixyp some merge conflicts in :
	lib/init.c
	lib/pdu.c
	lib/socket.c
	nfs/Makefile.am
	nfs/nfs.x
	nlm/Makefile.am
2012-11-27 18:22:27 -08:00
Ronnie Sahlberg aab6538bbd Implement 'rejected_reply' and switch to RFC5531 definitions
Switch to using fields and names from RFC5531. that is the standard
for RPC.
2012-11-26 19:42:10 -08:00
Ronnie Sahlberg dedc4675ba New version 1.4
- Add trackig of freed context and assert on using a context after it has been
  freed.
- Windows x64 support and fixes.
- Switch to using our own version of xdr_int64() since the one in libtirpc
  crashes on some platforms.
- Fix memory leak in an error path for addrinfo.
- Fix bug dereferencing a null pointer in the mount callback on error.
2012-11-25 07:57:40 -08:00
Ronnie Sahlberg 5f08d03e16 ZDR_ARRAYS: The sub-unmarshaller returns TRUE FALSE if there was an error, not TRUE 2012-11-24 09:01:00 -08:00
Ronnie Sahlberg f3a7507806 Add an assert to track if we try to use an rpc_context after it has been destroyed 2012-11-24 08:18:54 -08:00
Ronnie Sahlberg 2811861b96 Dont leak addrinfo in error path 2012-11-24 08:14:12 -08:00
Ronnie Sahlberg 9b6d106414 MOUNT: when processing the mount response, check status before dereferencing data pointer
If status is non-zero in the mount callback, then the datapointer might be NULL
so we should not dereference it into an exports pointer before we have checked the status.

This would otherwise cause crashes.
2012-11-24 08:13:46 -08:00
Rudi Ihle 456c0b147a Fixed errno processing for connect() on Windows. 2012-11-24 08:12:45 -08:00
Rudi Ihle 2521374f70 Modified mechanism to assign privileged ports and enable it for Windows as well 2012-11-24 08:12:31 -08:00
Ronnie Sahlberg 4a2b08768a Add an assert to track if we try to use an rpc_context after it has been destroyed 2012-11-21 17:10:05 -08:00
Ronnie Sahlberg be7f59339e Dont leak addrinfo in error path 2012-11-17 10:14:19 -08:00
Ronnie Sahlberg 5ac848e908 MOUNT: when processing the mount response, check status before dereferencing data pointer
If status is non-zero in the mount callback, then the datapointer might be NULL
so we should not dereference it into an exports pointer before we have checked the status.

This would otherwise cause crashes.
2012-11-04 15:55:05 -08:00
Rudi Ihle f96b24fada Fixed errno processing for connect() on Windows. 2012-09-18 08:33:41 +02:00
Rudi Ihle ac559609a3 Modified mechanism to assign privileged ports and enable it for Windows as well 2012-09-18 08:32:40 +02:00
Ronnie Sahlberg b14062764e ZDR: we need to include both arpa/inet.h and time.h 2012-07-05 21:17:45 +10:00
Ronnie Sahlberg 442b829a05 Dont just cast *enum_t to *uint32_t
go via a temporary variable in case these scalars are different size
2012-07-05 21:13:04 +10:00
Ronnie Sahlberg 67ba2239cb Get rid of AUTH completely and replace all uses with 'struct AUTH' 2012-07-05 10:23:19 +10:00
Ronnie Sahlberg 45670bd0d6 fix compiler warnings 2012-07-05 07:37:37 +10:00
Ronnie Sahlberg 020f172895 fix compiler warning 2012-07-05 07:35:04 +10:00
Ronnie Sahlberg d14e28387f squelch compiler warnings in socket.c about integer sizes 2012-07-05 07:21:48 +10:00
Ronnie Sahlberg 574095b960 Change a size variable from uint64 to uint32 to squelch a warning 2012-07-05 07:12:11 +10:00
Ronnie Sahlberg 10a0ceaaa3 librpc_rpc_call_body() should return TRUE is successful 2012-07-05 07:09:00 +10:00
Ronnie Sahlberg 242b81cfbf setpos returns a boolean, set it to always return TRUE 2012-07-05 07:06:33 +10:00
Ronnie Sahlberg 763cd6e3e2 ZDR: New builtin replacement for RPC/XDR called ZDR
This patch switches libnfs over to use precompiled rpcgen files
and using ZDR.  ZDR is a trivial reimplementation of XDR that is built in
into libnfs.

This removes the dependencies of rpc/xdr completely and allow us to build on any
system, even systems where rpcgen and librpc/libxdr are not generally available.
2012-07-04 16:53:12 +10:00
Ronnie Sahlberg 6916a66546 NLM: initial support for NLM 2012-03-10 20:46:03 +11:00
Ronnie Sahlberg fa3c25beee NFSACL: Add support for SETACL3 2012-03-08 21:25:21 +11:00
Ronnie Sahlberg 47e5a2c740 new version 1.3 2012-03-03 19:04:58 +11:00
Ronnie Sahlberg 8e25581668 change rpc_nfs_symlink_async to take a full SYMLINK3args as parameter 2012-01-14 08:18:19 +11:00
Ronnie Sahlberg 16104b27bd make low level readlink_async function take READLINK3args as argument 2012-01-14 08:11:09 +11:00
Ronnie Sahlberg 7edc9026db make mkdir_async take a full MKDIR3args argument 2012-01-12 16:02:32 +11:00
Ronnie Sahlberg c985c015f2 change crate_async low level function to take a full RATE3args structure as argument instead of just name and mode 2012-01-12 15:31:49 +11:00
Ronnie Sahlberg 8724c83390 Add function to get root filehandle from a nfs context 2012-01-11 07:04:01 +11:00
Ronnie Sahlberg e6cac86f77 Try to rotate the ports we assign when root better so we dont reuse
a port htat is in time-wait too frequently
2012-01-03 07:25:25 +11:00
Ronnie Sahlberg 59f298f5bf Improve an error message to show the errno value 2012-01-03 07:18:56 +11:00
Ronnie Sahlberg 5c6b1176c2 PMAP: allow to ask for tcp/udp port, dont assume users only ever want the tcp port 2011-12-31 14:24:20 +11:00
Ronnie Sahlberg 345422a2e3 New version 1.2 2011-12-06 18:02:34 +11:00
Ronnie Sahlberg d7ec001f1a Set IFREG from file type, dont assume mode bits contain it
Needed for HaneWin which does not set S_IFMT in the modebits returned
2011-12-05 13:54:21 +11:00
Ronnie Sahlberg 183451cff5 Remove all [s]size_t / off_t and replace with [u]int64_t making libnfs 64-bit pure 2011-11-27 14:49:08 +11:00
Ronnie Sahlberg 1ec6b50aef Add MKNOD command support
Add support for raw nfs3 mknod  and sync and async posixlike api
2011-11-27 14:08:24 +11:00
Ronnie Sahlberg 86ef491004 New version 1.1 2011-11-27 11:20:57 +11:00
Ronnie Sahlberg 14a062eb59 Everytime we use rpc_connect_async() internally, make sure we clear the ->connect_cb so that we dont have a callback function and "private data" being invoked long after the "private data" structure has been free()d. 2011-10-09 19:47:07 +11:00
Ronnie Sahlberg a3d44462cb Sync API: Once the sync nfs_mount() functions is finished we have to clear rpc->connect_cb.
Otherwise we get a crash once the connect_cb callback is invoked the second time.
2011-10-09 19:10:18 +11:00
Ronnie Sahlberg b990de23c6 Only call the "connect callback" if the callback is set to non-NULL 2011-10-09 19:00:24 +11:00
Ronnie Sahlberg 8704724f83 Change remaining "struct AUTH *" to "AUTH *" 2011-10-09 15:22:05 +11:00
Memphiz fa33813ed4 [fix] - fix improper definition of struct AUTH from osx (caution - API change - not clear if typedef is there on all plattforms...) 2011-10-08 18:10:06 +02:00
Ronnie Sahlberg acf31bb24d Bump version to 1.0.0 2011-10-04 18:30:15 +11:00
Ronnie Sahlberg d678b73e4d Fragment reassembly. Add reassembly of fragmented RPC PDUs 2011-10-04 12:31:56 +11:00
Ronnie Sahlberg 1744ef9011 Autoreconnect: autoreconnect was completely broken. Reimplement it so that it reconnects properly on session failure. 2011-10-04 11:25:10 +11:00
Ronnie Sahlberg fb69c64c02 READDIRPLUS emulation: Some embedded servers do not support READDIRPLUS,
so try to trap this and emulate it with READDIR + a LOOKUP loop to get the attributes.
Since we are fully async we can do all the lookups in concurrently so it should not be that very exopensive compared to the cheaper READDIRPLUS call.
2011-10-03 10:55:42 +11:00
Memphiz fcc42bfe85 [win32] - completed win32 port 2011-09-12 19:53:33 +02:00
Ronnie Sahlberg 4e9dcb7665 remove debug message 2011-09-12 22:20:56 +10:00
Ronnie Sahlberg 07fd0cbc65 when creating a socket, spin over a number of low-numbered ports
and try to bind to a system port in case the user is root or the
binary has the CAP_NET_BIND_SERVICE capability

this removes the need to use 'insecure' on the server
2011-09-12 22:14:26 +10:00
Ronnie Sahlberg 18c27b73ff Large-Writes: just like for large-reads, chop large writes up into the smallest
of 32kb and what the server responded as the max write size and send them out in parallell to the server.

32kb is a common limitation in XDR libraries so even if the server says IT can handle writes larget than that, our XDR library might not.
2011-09-11 22:13:28 +10:00
Ronnie Sahlberg 83aa785d92 Add a call to find the queue-length so we can see how many I/O we have in flight from the application layer. 2011-09-11 21:32:48 +10:00
unknown 4b0e8df9a9 [fix] - fix connect for win32 - return values are inverted 2011-09-03 15:31:56 +10:00
unknown 99c14c9b81 [add] - implement set_non_blocking for socket 2011-09-03 15:30:01 +10:00
Memphiz a8a1b85846 [win32] - make it compile on win32 2011-09-03 15:08:48 +10:00
Ronnie Sahlberg 4b1097cde2 remove old libnfs.def and update the buildscript to the new name libnfs-win32.def 2011-09-03 14:53:10 +10:00
Memphiz 7f7993883c [add] - win32 compat stuff 2011-09-03 14:51:54 +10:00
Ronnie Sahlberg db4ea5dd80 Revert "Rename libnfs.def to libnfs-win32.def"
This reverts commit a3d6cf111e.
2011-09-03 14:51:48 +10:00
Ronnie Sahlberg ea98629aef memset() is posix, bzero() is not change bzero into memset 2011-09-03 14:11:22 +10:00
Ronnie Sahlberg a3d6cf111e Rename libnfs.def to libnfs-win32.def 2011-09-03 13:29:39 +10:00
Ronnie Sahlberg 565369e0b2 remove some includes that dont exist on windows 2011-09-03 11:30:10 +10:00
Ronnie Sahlberg bb4e9ed6a8 cast to char * to avoid compiler warnings for get/setsockopt 2011-09-03 11:25:50 +10:00
Ronnie Sahlberg 4ed97718b3 Merge branch 'master' into win32-3 2011-09-03 11:11:36 +10:00
Ronnie Sahlberg 42f43e48cc cast the pointer to char * for all calls to bzero 2011-09-03 11:08:58 +10:00
Ronnie Sahlberg 41d82d7d82 Merge branch 'win32' into win32-3 2011-09-03 10:57:42 +10:00
Ronnie Sahlberg 0804e67d7a using READDIRPLUS3 we get some extra fields for the direentry structure for free, such as type, mode, size, timestamps 2011-09-02 20:45:30 +10:00
Ronnie Sahlberg f390f18157 nfs_opendir() switch to using READDIRPLUS3 instead of READDIR3 when reading directories. 2011-09-02 20:27:01 +10:00
Ronnie Sahlberg 647d2ea11c add support for opensolaris 2011-09-01 19:48:42 +10:00
Ronnie Sahlberg 427d71c0a7 Win32: add a libnfs.def file so we can build libraries/dlls 2011-08-30 15:54:29 +10:00
Ronnie Sahlberg b85c7de2f7 use vsnprintf() on all platforms, dont special case win32 for vsnprintf and all other platforms use vasprintf 2011-08-29 19:59:36 +10:00
Ronnie Sahlberg 2606f9bb3d Win32: add workaround for lack of vasprintf() and use vsnprintf() on windows on a fixed size buffer 2011-08-29 18:00:09 +10:00
Ronnie Sahlberg 0ad9a1f134 WIN32: win32 does not have poll()
add trivial replacement function
2011-08-28 19:48:01 +10:00
Ronnie Sahlberg f4442bec27 wondows dont have vasprintf()
disable for now  and reimplement later
2011-08-28 19:45:00 +10:00
Ronnie Sahlberg 6874f61e24 Win32: more win32 adaptations 2011-08-28 19:43:33 +10:00
Ronnie Sahlberg fb6510bb68 VC10 dont like ';;' 2011-08-28 19:30:10 +10:00
Ronnie Sahlberg d8143ff7d7 Win32: the stat structure on win32 does not have blocks or blocksize 2011-08-28 19:29:08 +10:00
Ronnie Sahlberg 93e9306f80 replace index/rindex with modern equivalents 2011-08-28 19:27:57 +10:00
Ronnie Sahlberg a671a46510 replace index/rindex with modern equivalents 2011-08-28 19:27:23 +10:00
Ronnie Sahlberg 9896c7155c nfs_set_auth() is a void and does not return anything 2011-08-28 19:26:07 +10:00
Ronnie Sahlberg be337389bf nfs_set_auth() is a void and does not return anything 2011-08-28 19:25:20 +10:00
Ronnie Sahlberg eecdc4f3cd Win32 changes, include files we need when compiling under win32
and some socket ops are slightly different
2011-08-28 19:24:18 +10:00
Ronnie Sahlberg 11ef53a2e6 callit_cb() : dont return a value from avoid function 2011-08-28 19:00:04 +10:00
Ronnie Sahlberg b3740e09de callit_cb() : dont return a value from avoid function 2011-08-28 18:59:13 +10:00
Ronnie Sahlberg 963c2f83be Initialize the rootfh handle when creating the nfs context or else
we will try to free a wild pointer if the mount failed
and we proceed to call nfs_destroy_context();
2011-07-31 10:59:46 +10:00
Ronnie Sahlberg b077fdeb65 Add automatic reconnect after TCP session failure for the sync interface.
Once a NFS TCP connection has been idle for a very long time, say
10-15 minutes, it is common that NFS servers will tear down the TCP connection.
So add code to re-connect to the NFS server and re-issue any i/o that might have been in flight (unlikely unless the server has hung)

While it is sufficient to just reconnect to tcp port 2049, it was much simplet to just utilize the nfs_mount() function.
This means that instead of just reconnecting TCP port 2049, we do a full blown
nfs mount via portmapper and mountd protocols.
2011-07-31 10:49:47 +10:00
Ronnie Sahlberg 8c27363e21 since UDP is unreliable, send the CALLIT broadcasts 3 times, one second apart when probing for local NFS servers 2011-07-16 17:30:44 +10:00
Ronnie Sahlberg e5964ef905 break out the loop for sending a NFSd probe bcast on every interface into a separate function 2011-07-16 17:27:12 +10:00
Memphiz 41a6209bef [fix] - fix allocation of if list for osx
- removed one unneeded header in examples/nfsclient-bcast.c which was breaking build under osx
2011-07-11 19:16:13 +02:00
Ronnie Sahlberg 9a96dd46d2 We have to include config.h when testing for precense of sockaddr sa_len 2011-07-10 08:50:36 +10:00
Ronnie Sahlberg 1be803ce7f On OSX and other systems where we have sockaddr_in, SIOCGIFCONF returns a packed list of ifreq structures, so we can not just index them as (struct ifreq *)[i]
Instead we have to compute the offset into the buffer for where the next record starts (this offset might or might not be sizeof(struct ifreq)
2011-07-10 08:39:54 +10:00
Trent Nelson 56320c681f Fix out-of-tree (VPATH) builds 2011-07-06 16:38:38 -04:00
Ronnie Sahlberg 1ad6f93185 when ioctl() for getting the broadcast address fails, continue the loop to the next entry instead of exiting out 2011-07-04 08:46:19 +10:00
Memphiz b989ca9c36 - fixed missing include for osx 2011-07-03 15:25:48 +02:00
Ronnie Sahlberg f7f931c7e3 add back a check for sa_len in sockaddr structure. 2011-07-03 07:41:15 +10:00
Ronnie Sahlberg 1b9917b886 With broadcast PDUs we can receive multiple replies so must make sure we
delete the previuous unmarshalling buffer when we start over and
process the second pdu to the initial call.

Or else we will leak memory very slowly when processing broadcast RPC replies
2011-07-02 12:16:37 +10:00
Ronnie Sahlberg 2e4db0d145 Merge remote branch 't-nelson/automake' 2011-07-02 11:10:36 +10:00
Ronnie Sahlberg 552c766578 add example for sync interface to probe for all local servers 2011-07-02 10:30:16 +10:00
Trent Nelson fc01d2a961 Fix compile error on solaris.
Include sys/filio.h explicitly as solaris doesn't define BSD_COMP and
thus doesn't pull this header via sys/ioctl.h. Needed for FIONREAD.
2011-06-29 14:15:23 -04:00
Trent Nelson 2842ff15c8 Handle versioning the libtool way. 2011-06-29 14:15:22 -04:00
Trent Nelson 6c437065d3 Rewrite build system using automake
Initial commit, only linux tested so far.
2011-06-29 14:15:16 -04:00
Ronnie Sahlberg 7ff2f3a01d when destroying a udp rpc context, free any udp_dest data we may have 2011-06-26 18:58:54 +10:00
Ronnie Sahlberg c481da67f2 add function to extract the sockaddr from which we received the current rpc pdu
(useful when parsing replies from broadcast rpc calls)
2011-06-26 18:45:38 +10:00
Ronnie Sahlberg 5bf60dc601 add function to set the target for UDP rpc calls.
including doing broadcast calls
2011-06-26 18:42:53 +10:00
Ronnie Sahlberg 485bc9b9a7 add function to bind a udp rpc context to a local port/address 2011-06-26 18:40:00 +10:00
Ronnie Sahlberg 070287e516 Dont allow a tcp _connect to a UDP context 2011-06-26 18:32:06 +10:00
Ronnie Sahlberg 0268794fe3 add capability to read UDP datagrams from the socket and pass them to the parser 2011-06-26 18:30:26 +10:00
Ronnie Sahlberg 5911f3e8ab for UDP sockets, we ONLY wait for pollin events
since upd sockets are always writeable.
they just silently drop packets when congested
2011-06-26 18:26:34 +10:00
Ronnie Sahlberg a669857d0d add support for sending and receiving udp pdu 2011-06-26 18:24:24 +10:00
Ronnie Sahlberg a19924120d in allocate pdu, if context is udp, dont allocate space for a record marker 2011-06-26 17:30:00 +10:00
Ronnie Sahlberg 9e00b8c663 add function to request a UDP context
(private use only since we dont want applications to use UDP)
2011-06-26 17:27:40 +10:00
Ronnie Sahlberg 7ed9d87a5b redo the previous patch to instead initialize max_offset correctly before we invoke the chunks.
this is the correct way to fix this bug.
2011-06-25 12:23:52 +10:00
Ronnie Sahlberg 215228a23d handle the case where we try a multi-read that is completely beyond the end of file.
when a multi-read was completely beyond the end of file, this caused us to invoke the callback with a 'read-count' of <0  which the callback would treat as a failure.
This would then cause the callback to treat the data pointer as an error string and try to use it for nfs_set_error().
Since the data pointer was actually a real binary databuffer and not an error string this would cause the NFS error string to look like it contained garbage data.

In this case, where the multi-read fails to read any data at all since it if fully beyond end of file,  make sure to invoke the callback with a read-count of 0
2011-06-25 12:13:11 +10:00
Ronnie Sahlberg 739df145d6 fix crash in mount/export
need to check that status is OK before we start dereferencing the 'export' pointers or else we will segv.
this could happen if trying to pull the list of exports from a host that does not have mountd running, or if we can not connect at all to the host.
2011-06-25 11:06:53 +10:00
Ronnie Sahlberg 1e8994af0f Add a very subtle bug in nfs_set_error()
when nfs_set_error is called with error_string being the result of a lower layer
problem so it is passed as "rpc_get_error()"

This meant that since free that nfs->rpc->error_string before we reference it a few lines further down in the vasprintf(..., error_string,
adn memory corruption triggers.

Valgrind found this, Valgrind rules!
2011-06-21 18:33:50 +10:00
Ronnie Sahlberg e4a5ba42b8 When doping chunked multi-reads of a blob bigger than the max readsize,
a read can sometimes span beyond the end of file.

In which case individual smal read chunks beyond the end of file will return OK, 0 bytes of data and EOF==1

For this case, trap when len==0 and ignore these chunks.
Do not update the read-count if / when len is 0.
2011-06-21 06:07:29 +10:00
Ronnie Sahlberg e8cab72a79 From Paul van der Zwan
Set the directory bit in st_mode properly.
2011-06-20 01:02:48 +10:00
Ronnie Sahlberg cdb19ec164 Redo the buffer handling for input buffers and make sure we only read one PDU at a time 2011-06-20 00:56:47 +10:00
Ronnie Sahlberg e210bd2af8 remove the need for an explicit rpc context for the highlevel function mount_getexports() 2011-06-19 23:20:35 +10:00
Ronnie Sahlberg df5af25fd2 add a sync function to get the export list from a server and add an example of how to use this functio n to nfsclient-sync 2011-06-19 22:31:34 +10:00
Ronnie Sahlberg 7f0242ca9a Add a high-level async function to read the export list 2011-06-19 14:54:17 +10:00
Ronnie Sahlberg 1896d37bfa get rid of all remaining printfs from the library
add a helper function nfs_set_error() to use instead of the printfs
2011-06-19 09:38:20 +10:00
Ronnie Sahlberg 5f9d02f839 get rid of compiler warning 2011-06-19 09:05:20 +10:00
Ronnie Sahlberg cbbf9d3e81 remove all printf's and replace them with rpc_set_error()
also change all error return codes to always return -1
2011-06-19 09:03:04 +10:00
Ronnie Sahlberg 921f877be4 Add support in read/pread to be aware of the Maximum Read size that the server
suggested.

When a read/pread operation that is 'oversize' is issued, the read/pread command will internally chop this up into smaller chunsk and send then concurrently to the server.
As replies come back from the server we add the data to a reassembly buffer
and as soon as all replies have been received we invoke the callback and pass the reassembly buffer back to the application.
2011-06-19 08:43:28 +10:00
Ronnie Sahlberg e2ba5764d4 Remove the _sync postfix for the synchronous functions 2011-06-18 15:07:53 +10:00
Memphis 98f5fee87d - linux, osx, and ios need rpc/rpc.h includede before rpc/xdr.h
- fixed some missing includes for bzero, malloc and free
2011-06-01 18:06:15 +02:00
Ronnie Sahlberg ea214e4566 Use HAVE_SOCK_SIN_LEN and set ->sin_len
for legacy unixens (AIX)
so that we will compile and run on those systems with a "weird"
sockaddr_in definition.
2011-06-01 21:31:40 +10:00
Ronnie Sahlberg 17ef62fad7 Read the max read/write sizes supported when connecting to NFS
and store in the nfs context.
Privide accessor functions to read the max sizes.
2011-06-01 00:08:29 +10:00
Ronnie Sahlberg 912f7ad5b0 Use getsockopt to extract better failure condition when tcp layer receives a failure 2011-02-07 22:11:12 +11:00
Ronnie Sahlberg 84004dbf9b initial libnfs checkin 2011-02-06 15:45:09 +11:00