command line IPv6 support for exportfs
Subsystems (2)
cover command line IPv6 support for exportfs
Though /etc/exports can contain IPv6 literals as client names, the exportfs command doesn't allow an IPv6 literal when adding or removing a temporary export.
exportfs [-u] client:/path
If "client" is an IPv6 presentation address, it contains colons. The problem is that exportfs already uses a colon to separate the client identifier from the export pathname.
To escape colons in the client name, adopt the same mechanism that is used for mount.nfs. Users wrap IPv6 literals in square brackets.
exportfs has to be a little more complicated than mount.nfs, however. It must still be able to distinguish hostname wildcards that use brackets, and be able to deal with network address prefixes.
With this patch series,
[abc]-machine.example.org:/export
192.168.76.16:/share
[2604:8800:100:81fc:82ee:73ff:fe43:d64f]:/export/home
[fe80::]/64:/var/tmp
are now all accepted by exportfs.
---
Chuck Lever (2):
exportfs: Refactor exportfs() and unexportfs()
exportfs: Support raw IPv6 addresses with "client:/path"
utils/exportfs/exportfs.c | 134 ++++++++++++++++++++++++++++++++++++------- utils/exportfs/exportfs.man | 16 +++++ 2 files changed, 127 insertions(+), 23 deletions(-)
Signature · 1 line
Chuck Lever
PATCH 1/2 exportfs: Refactor exportfs() and unexportfs()
Separate parsing the "client:/path" argument from the actual processing.
--- utils/exportfs/exportfs.c | 74 +++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 23 deletions(-)
utils/exportfs/exportfs.c +51 -23
@@ -299,23 +299,13 @@ export_all(int verbose)static void -exportfs (char *arg,char *options,int verbose) +exportfs_parsed (char *hname,char *path,char *options,int verbose) {struct exportent *eep;nfs_export *exp =NULL ;struct addrinfo *ai =NULL ; -char *path; -char *hname = arg;int htype; -if ((path =strchr (arg,':' )) !=NULL ) - *path++ ='\0' ; - -if (!path || *path !='/' ) { -xlog (L_ERROR ,"Invalid exporting option: %s" , arg); -return ; - } -if ((htype =client_gettype (hname)) ==MCL_FQDN ) { ai =host_addrinfo (hname);if (ai !=NULL ) {
@@ -345,24 +335,38 @@ out:freeaddrinfo (ai); } +static int exportfs_legacy (char *arg,char *options,int verbose) +{ +char *path; + +if ((path =strchr (arg,':' )) !=NULL ) + *path++ ='\0' ; + +if (!path || *path !='/' ) +return 1 ; + +exportfs_parsed (arg, path, options, verbose); +return 0 ; +} +static void -unexportfs (char *arg,int verbose) +exportfs (char *arg,char *options,int verbose) +{ +int failed; + + failed =exportfs_legacy (arg, options, verbose); +if (failed) +xlog (L_ERROR ,"Invalid export syntax: %s" , arg); +} + +static void +unexportfs_parsed (char *hname,char *path,int verbose) {nfs_export *exp;struct addrinfo *ai =NULL ; -char *path; -char *hname = arg;int htype;int success =0 ; -if ((path =strchr (arg,':' )) !=NULL ) - *path++ ='\0' ; - -if (!path || *path !='/' ) { -xlog (L_ERROR ,"Invalid unexporting option: %s" , arg); -return ; - } -if ((htype =client_gettype (hname)) ==MCL_FQDN ) { ai =host_addrinfo (hname);if (ai)
@@ -403,11 +407,35 @@ unexportfs(char *arg, int verbose) success =1 ; }if (!success) -xlog (L_ERROR ,"Could not find '%s:%s' to unexport." , arg, path); +xlog (L_ERROR ,"Could not find '%s:%s' to unexport." , hname, path);freeaddrinfo (ai); } +static int unexportfs_legacy (char *arg,int verbose) +{ +char *path; + +if ((path =strchr (arg,':' )) !=NULL ) + *path++ ='\0' ; + +if (!path || *path !='/' ) +return 1 ; + +unexportfs_parsed (arg, path, verbose); +return 0 ; +} + +static void +unexportfs (char *arg,int verbose) +{ +int failed; + + failed =unexportfs_legacy (arg, verbose); +if (failed) +xlog (L_ERROR ,"Invalid export syntax: %s" , arg); +} +static int can_test (void ) {char buf[1024 ];
PATCH 2/2 exportfs: Support raw IPv6 addresses with "client:/path"
In reply to Chuck LeverWrap IPv6 presentation addresses in square brackets. This echoes the same syntax used when specifying IPv6 server addresses with the mount.nfs command.
--- utils/exportfs/exportfs.c | 64 ++++++++++++++++++++++++++++++++++++++++++- utils/exportfs/exportfs.man | 16 +++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-)
utils/exportfs/exportfs.c +62 -2
@@ -349,12 +349,42 @@ static int exportfs_legacy(char *arg, char *options, int verbose)return 0 ; } +static int exportfs_ipv6 (char *arg,char *options,int verbose) +{ +char *path, *c, hname[NI_MAXHOST +strlen ("/128" )]; + + arg++; + c =strchr (arg,']' ); +if (c ==NULL ) +return 1 ; +strncpy (hname, arg, c - arg); + +/* no colon means this is a wildcarded DNS hostname */ +if (strchr (hname,':' ) ==NULL ) +return exportfs_legacy (--arg, options, verbose); + + path =strstr (c,":/" ); +if (path ==NULL ) +return 1 ; + *path++ ='\0' ; + +/* if there's anything between the closing brace and the +* path separator, it's probably a prefix length */ +strcat (hname, ++c); + +exportfs_parsed (hname, path, options, verbose); +return 0 ; +} +static void exportfs (char *arg,char *options,int verbose) {int failed; - failed =exportfs_legacy (arg, options, verbose); +if (*arg =='[' ) + failed =exportfs_ipv6 (arg, options, verbose); +else + failed =exportfs_legacy (arg, options, verbose);if (failed)xlog (L_ERROR ,"Invalid export syntax: %s" , arg); }
@@ -426,12 +456,42 @@ static int unexportfs_legacy(char *arg, int verbose)return 0 ; } +static int unexportfs_ipv6 (char *arg,int verbose) +{ +char *path, *c, hname[NI_MAXHOST +strlen ("/128" )]; + + arg++; + c =strchr (arg,']' ); +if (c ==NULL ) +return 1 ; +strncpy (hname, arg, c - arg); + +/* no colon means this is a wildcarded DNS hostname */ +if (strchr (hname,':' ) ==NULL ) +return unexportfs_legacy (--arg, verbose); + + path =strstr (c,":/" ); +if (path ==NULL ) +return 1 ; + *path++ ='\0' ; + +/* if there's anything between the closing brace and the +* path separator, it's probably a prefix length */ +strcat (hname, ++c); + +unexportfs_parsed (hname, path, verbose); +return 0 ; +} +static void unexportfs (char *arg,int verbose) {int failed; - failed =unexportfs_legacy (arg, verbose); +if (*arg =='[' ) + failed =unexportfs_ipv6 (arg, verbose); +else + failed =unexportfs_legacy (arg, verbose);if (failed)xlog (L_ERROR ,"Invalid export syntax: %s" , arg); }
utils/exportfs/exportfs.man +16 -0
@@ -159,6 +159,14 @@ along with the client or clients who are permitted to access it. See .B exports(5) for a description of supported options and access list formats. +.PP +IPv6 presentation addresses contain colons, which are already used +to separate the "host" and "path" command line arguments. +When specifying a client using a raw IPv6 address, +enclose the address in square brackets. +For IPv6 network addresses, place the prefix just after the closing +bracket. +.PP To export a directory to the world, simply specify .IR :/path . .PP
@@ -244,6 +252,14 @@ and files under .nf .B "# exportfs -au .fi +.PP +To export the +.I /usr/tmp +directory to IPv6 link-local clients: +.PP +.nf +.B "# exportfs [fe80::]/64:/usr/tmp +.fi .SH USAGE NOTES Exporting to IP networks or DNS and NIS domains does not enable clients from these groups to access NFS immediately.
Quoted 28 lines · Chuck Lever
Though
/etc/exportscan contain IPv6 literals as client names, the exportfs command doesn't allow an IPv6 literal when adding or removing a temporary export.exportfs [-u] client:/path
If "client" is an IPv6 presentation address, it contains colons. The problem is that exportfs already uses a colon to separate the client identifier from the export pathname.
To escape colons in the client name, adopt the same mechanism that is used for mount.nfs. Users wrap IPv6 literals in square brackets.
exportfs has to be a little more complicated than mount.nfs, however. It must still be able to distinguish hostname wildcards that use brackets, and be able to deal with network address prefixes.
With this patch series,
[abc]-machine.example.org:/export
192.168.76.16:/share
[2604:8800:100:81fc:82ee:73ff:fe43:d64f]:/export/home
[fe80::]/64:/var/tmp
Quoted 7 lines
are now all accepted by exportfs.
---
Chuck Lever (2):
exportfs: Refactorexportfs()andunexportfs()
exportfs: Support raw IPv6 addresses with "client:/path"
Both were committed...
steved.
Quoted 6 lines
utils/exportfs/exportfs.c | 134 ++++++++++++++++++++++++++++++++++++------- utils/exportfs/exportfs.man | 16 +++++ 2 files changed, 127 insertions(+), 23 deletions(-)