X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Frmtcall.c;h=816a6f368fa208d12313de3f1721d297401cf42a;hp=7684b3b51eb142b3c7f18e760868cd0575521729;hb=fc023f58a146bca6e67b26878ff35f2368b19f58;hpb=c481a5416e5b937541205da23cde15cdabf106c1 diff --git a/utils/statd/rmtcall.c b/utils/statd/rmtcall.c index 7684b3b..816a6f3 100644 --- a/utils/statd/rmtcall.c +++ b/utils/statd/rmtcall.c @@ -46,6 +46,10 @@ #include "log.h" #include "ha-callout.h" +#if SIZEOF_SOCKLEN_T - 0 == 0 +#define socklen_t int +#endif + #define MAXMSGSIZE (2048 / sizeof(unsigned int)) static unsigned long xid = 0; /* RPC XID counter */ @@ -55,7 +59,7 @@ static int sockfd = -1; /* notify socket */ * Initialize callback socket */ int -statd_get_socket(int port) +statd_get_socket(void) { struct sockaddr_in sin; @@ -72,139 +76,14 @@ statd_get_socket(int port) memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; - /* - * If a local hostname is given (-n option to statd), bind to the address - * specified. This is required to support clients that ignore the mon_name in - * the statd protocol but use the source address from the request packet. - */ - if (MY_NAME) { - struct hostent *hp = gethostbyname(MY_NAME); - if (hp) - sin.sin_addr = *(struct in_addr *) hp->h_addr; - } - if (port != 0) { - sin.sin_port = htons(port); - if (bind(sockfd, &sin, sizeof(sin)) == 0) - goto out_success; - note(N_CRIT, "statd: failed to bind to outgoing port, %d\n" - " falling back on randomly chosen port\n", port); - } + if (bindresvport(sockfd, &sin) < 0) { dprintf(N_WARNING, "process_hosts: can't bind to reserved port\n"); } -out_success: return sockfd; } -#ifdef HAVE_IFADDRS_H -/* - * 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; -} -#endif /* HAVE_IFADDRS_H */ -/* - * Try to resolve host name for notify/callback request - * - * When compiled with RESTRICTED_STATD defined, we expect all - * host names to be dotted quads. See monitor.c for details. --okir - */ -#ifdef RESTRICTED_STATD -static int -try_to_resolve(notify_list *lp) -{ - char *hname; - - if (NL_TYPE(lp) == NOTIFY_REBOOT) - hname = NL_MON_NAME(lp); - else - hname = NL_MY_NAME(lp); - if (!inet_aton(hname, &(NL_ADDR(lp)))) { - note(N_ERROR, "%s is not an dotted-quad address", hname); - NL_TIMES(lp) = 0; - return 0; - } - - /* XXX: In order to handle multi-homed hosts, we could do - * a reverse lookup, a forward lookup, and cycle through - * all the addresses. - */ - return 1; -} -#else -static int -try_to_resolve(notify_list *lp) -{ - struct hostent *hp; - char *hname; - - if (NL_TYPE(lp) == NOTIFY_REBOOT) - hname = NL_MON_NAME(lp); - else - hname = NL_MY_NAME(lp); - - dprintf(N_DEBUG, "Trying to resolve %s.", hname); - if (!(hp = gethostbyname(hname))) { - herror("gethostbyname"); - NL_TIMES(lp) -= 1; - return 0; - } - - if (hp->h_addrtype != AF_INET) { - note(N_ERROR, "%s is not an AF_INET address", hname); - NL_TIMES(lp) = 0; - return 0; - } - - /* FIXME: should try all addresses for multi-homed hosts in - * alternation because one interface might be down/unreachable. */ - NL_ADDR(lp) = *(struct in_addr *) hp->h_addr; - - dprintf(N_DEBUG, "address of %s is %s", hname, inet_ntoa(NL_ADDR(lp))); - return 1; -} -#endif - static unsigned long xmit_call(int sockfd, struct sockaddr_in *sin, u_int32_t prog, u_int32_t vers, u_int32_t proc, @@ -278,7 +157,7 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) struct rpc_msg mesg; notify_list *lp = NULL; XDR xdr, *xdrs = &xdr; - int alen = sizeof(*sin); + socklen_t alen = sizeof(*sin); /* Receive message */ if ((msglen = recvfrom(sockfd, msgbuf, sizeof(msgbuf), 0, @@ -352,14 +231,11 @@ 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; /* __u32 proc, vers, prog; */ - if (lp->addr.s_addr == INADDR_ANY && !try_to_resolve(lp)) - return NL_TIMES(lp); if (NL_TIMES(lp) == 0) { note(N_DEBUG, "Cannot notify %s, giving up.\n", inet_ntoa(NL_ADDR(lp))); @@ -371,54 +247,24 @@ process_entry(int sockfd, notify_list *lp) sin.sin_port = lp->port; /* LH - moved address into switch */ - switch (NL_TYPE(lp)) { - case NOTIFY_REBOOT: - prog = SM_PROG; - vers = SM_VERS; - proc = SM_NOTIFY; - - /* 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 - */ -#ifdef HAVE_IFADDRS_H - if (!(run_mode & STATIC_HOSTNAME)) - reset_my_name(lp); -#endif /* HAVE_IFADDRS_H */ - func = (xdrproc_t) xdr_stat_chge; - new_stat.state = MY_STATE; - new_stat.mon_name = NL_MY_NAME(lp); + prog = NL_MY_PROG(lp); + vers = NL_MY_VERS(lp); + proc = NL_MY_PROC(lp); - objp = &new_stat; - break; - case NOTIFY_CALLBACK: - prog = NL_MY_PROG(lp); - vers = NL_MY_VERS(lp); - proc = NL_MY_PROC(lp); - - /* __FORCE__ loopback for callbacks to lockd ... */ - /* Just in case we somehow ignored it thus far */ - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - - func = (xdrproc_t) xdr_status; - objp = &new_status; - new_status.mon_name = NL_MON_NAME(lp); - new_status.state = NL_STATE(lp); - memcpy(new_status.priv, NL_PRIV(lp), SM_PRIV_SIZE); - break; - default: - note(N_ERROR, "notify_host: unknown notify type %d", - NL_TYPE(lp)); - return 0; - } + /* __FORCE__ loopback for callbacks to lockd ... */ + /* Just in case we somehow ignored it thus far */ + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + func = (xdrproc_t) xdr_status; + objp = &new_status; + new_status.mon_name = NL_MON_NAME(lp); + new_status.state = NL_STATE(lp); + memcpy(new_status.priv, NL_PRIV(lp), SM_PRIV_SIZE); lp->xid = xmit_call(sockfd, &sin, prog, vers, proc, func, objp); if (!lp->xid) { - note(N_WARNING, "notify_host: failed to notify %s\n", - inet_ntoa(lp->addr)); + note(N_WARNING, "notify_host: failed to notify port %d\n", + ntohs(lp->port)); } NL_TIMES(lp) -= 1; @@ -451,12 +297,7 @@ process_reply(FD_SET_TYPE *rfds) return 1; } note(N_WARNING, "recv_rply: [%s] service %d not registered", - inet_ntoa(lp->addr), - NL_TYPE(lp) == NOTIFY_REBOOT? SM_PROG : NL_MY_PROG(lp)); - } else if (NL_TYPE(lp) == NOTIFY_REBOOT) { - dprintf(N_DEBUG, "Notification of %s succeeded.", - NL_MON_NAME(lp)); - xunlink(SM_BAK_DIR, NL_MON_NAME(lp), 0); + inet_ntoa(lp->addr), NL_MY_PROG(lp)); } else { dprintf(N_DEBUG, "Callback to %s (for %d) succeeded.", NL_MY_NAME(lp), NL_MON_NAME(lp)); @@ -477,7 +318,7 @@ process_notify_list(void) time_t now; int fd; - if ((fd = statd_get_socket(0)) < 0) + if ((fd = statd_get_socket()) < 0) return 0; while ((entry = notify) != NULL && NL_WHEN(entry) < time(&now)) { @@ -485,21 +326,13 @@ process_notify_list(void) NL_WHEN(entry) = time(NULL) + NOTIFY_TIMEOUT; nlist_remove(¬ify, entry); nlist_insert_timer(¬ify, entry); - } else if (NL_TYPE(entry) == NOTIFY_CALLBACK) { + } else { note(N_ERROR, "Can't callback %s (%d,%d), giving up.", NL_MY_NAME(entry), NL_MY_PROG(entry), NL_MY_VERS(entry)); nlist_free(¬ify, entry); - } else { - note(N_ERROR, - "Can't notify %s, giving up.", - NL_MON_NAME(entry)); - /* PRC: do the HA callout */ - ha_callout("del-client", NL_MON_NAME(entry), NL_MY_NAME(entry), -1); - xunlink(SM_BAK_DIR, NL_MON_NAME(entry), 0); - nlist_free(¬ify, entry); } }