X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Frmtcall.c;fp=utils%2Fstatd%2Frmtcall.c;h=a45705b02433aa900e2be558e11fa6f151f4c5bf;hp=474bbb4242b3a254ddb5af426abb53b130b9356c;hb=f73e7b9f69835d483cee95e6a20b6307b9d16b77;hpb=b51ebed58a610b3104e9f218d609715cd468b0ea diff --git a/utils/statd/rmtcall.c b/utils/statd/rmtcall.c index 474bbb4..a45705b 100644 --- a/utils/statd/rmtcall.c +++ b/utils/statd/rmtcall.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include "sm_inter.h" #include "statd.h" #include "notlist.h" @@ -90,7 +92,50 @@ statd_get_socket(int port) out_success: return sockfd; } - +/* + * Using the NL_ADDR(lp), reset (if needed) the hostname + * that will be put in the SM_NOTIFY to the hostname + * that is associated with the network interface + * that was monitored + */ +static void +reset_my_name(notify_list *lp) +{ + struct ifaddrs *ifa = NULL, *ifap; + struct in_addr netaddr, tmp; + struct sockaddr_in *sin, *nsin; + struct hostent *hp; + + netaddr.s_addr = inet_netof(NL_ADDR(lp)); + if (getifaddrs(&ifa) >= 0) { + for (ifap = ifa; ifap != NULL; ifap = ifap->ifa_next) { + if (!(ifap->ifa_flags & IFF_UP)) + continue; + + note(N_DEBUG, "ifa_name %s\n", ifap->ifa_name); + if (ifap->ifa_addr == NULL) + continue; + if (ifap->ifa_addr->sa_family != AF_INET) + continue; + + sin = (struct sockaddr_in *)ifap->ifa_addr; + nsin = (struct sockaddr_in *)ifap->ifa_netmask; + tmp.s_addr = sin->sin_addr.s_addr & nsin->sin_addr.s_addr; + if (memcmp(&tmp.s_addr, &netaddr.s_addr, sizeof(netaddr.s_addr))) + continue; + hp = gethostbyaddr((char *)&sin->sin_addr, + sizeof(sin->sin_addr), AF_INET); + if (hp == NULL) + continue; + if (strcmp(NL_MY_NAME(lp), hp->h_name)) { + free(NL_MY_NAME(lp)); + NL_MY_NAME(lp)= strdup(hp->h_name); + note(N_DEBUG, "NL_MY_NAME %s\n", NL_MY_NAME(lp)); + } + } + } + return; +} /* * Try to resolve host name for notify/callback request * @@ -300,6 +345,7 @@ process_entry(int sockfd, notify_list *lp) { struct sockaddr_in sin; struct status new_status; + stat_chge new_stat; xdrproc_t func; void *objp; u_int32_t proc, vers, prog; @@ -326,9 +372,19 @@ process_entry(int sockfd, notify_list *lp) /* Use source address for notify replies */ sin.sin_addr = lp->addr; + /* + * Unless a static hostname has been defined + * set the NL_MY_NAME(lp) hostname to the + * one associated with the network interface + */ + if (!(run_mode & STATIC_HOSTNAME)) + reset_my_name(lp); func = (xdrproc_t) xdr_stat_chge; - objp = &SM_stat_chge; + new_stat.state = MY_STATE; + new_stat.mon_name = NL_MY_NAME(lp); + + objp = &new_stat; break; case NOTIFY_CALLBACK: prog = NL_MY_PROG(lp);