diff options
author | neilbrown <neilbrown> | 2003-05-21 06:25:15 +0000 |
---|---|---|
committer | neilbrown <neilbrown> | 2003-05-21 06:25:15 +0000 |
commit | 1275be70ca6cd6c4bec07a3381f7b510086c5526 (patch) | |
tree | abf376a1065ae319906ab108bc59095d9a9fe13d /support/export/client.c | |
parent | 827f2a0c8c7606ad0245bfa4b9c81075f0de18c7 (diff) | |
download | nfs-utils-1275be70ca6cd6c4bec07a3381f7b510086c5526.tar.gz nfs-utils-1275be70ca6cd6c4bec07a3381f7b510086c5526.tar.xz nfs-utils-1275be70ca6cd6c4bec07a3381f7b510086c5526.zip |
Support new kernel upcalls for export cache management.
Diffstat (limited to 'support/export/client.c')
-rw-r--r-- | support/export/client.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/support/export/client.c b/support/export/client.c index 6d5d306..3db21ae 100644 --- a/support/export/client.c +++ b/support/export/client.c @@ -230,6 +230,104 @@ client_find(struct hostent *hp) } /* + * Find client name given an IP address + * This is found by gathering all known names that match that IP address, + * sorting them and joining them with '+' + * + */ +static char *add_name(char *old, char *add); + +char * +client_compose(struct in_addr addr) +{ + struct hostent *he = NULL; + char *name = NULL; + int i; + + if (clientlist[MCL_WILDCARD] || clientlist[MCL_NETGROUP]) + he = get_reliable_hostbyaddr((const char*)&addr, sizeof(addr), AF_INET); + if (he == NULL) + he = get_hostent((const char*)&addr, sizeof(addr), AF_INET); + + for (i = 0 ; i < MCL_MAXTYPES; i++) { + nfs_client *clp; + for (clp = clientlist[i]; clp ; clp = clp->m_next) { + if (!client_check(clp, he)) + continue; + name = add_name(name, clp->m_hostname); + } + } + return name; +} + +int +client_member(char *client, char *name) +{ + /* check if "client" (a ',' separated list of names) + * contains 'name' as a member + */ + int l = strlen(name); + while (*client) { + if (strncmp(client, name, l) == 0 && + (client[l] == ',' || client[l] == '\0')) + return 1; + client = strchr(client, ','); + if (client == NULL) + return 0; + client++; + } + return 0; +} + + +int +name_cmp(char *a, char *b) +{ + /* compare strings a and b, but only upto ',' in a */ + while (*a && *b && *a != ',' && *a == *b) + a++, b++; + if (!*b && (!*a || !a == ',') ) + return 0; + if (!*b) return 1; + if (!*a || *a == ',') return -1; + return *a - *b; +} + +static char * +add_name(char *old, char *add) +{ + int len = strlen(add)+2; + char *new; + char *cp; + if (old) len += strlen(old); + + new = malloc(len); + if (!new) { + free(old); + return NULL; + } + cp = old; + while (cp && *cp && name_cmp(cp, add) < 0) { + /* step cp forward over a name */ + char *e = strchr(cp, ','); + if (e) + cp = e+1; + else + cp = cp + strlen(cp); + } + strncpy(new, old, cp-old); + new[cp-old] = 0; + if (cp != old && !*cp) + strcat(new, ","); + strcat(new, add); + if (cp && *cp) { + strcat(new, ","); + strcat(new, cp); + } + return new; +} + +/* * Match a host (given its hostent record) to a client record. This * is usually called from mountd. */ |