X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Frmtcall.c;h=f6798f9b29b9e5623dd9617dd529b09b8b5cad34;hp=3d9e7cc01ea9858dbd6d21014591506d0d3d7440;hb=8d926d3defedf7bb82c2f3f9fd1746fb0d0b968a;hpb=8d2c2fe749658654b3ffc6ff25daba6e9b27294f diff --git a/utils/statd/rmtcall.c b/utils/statd/rmtcall.c index 3d9e7cc..f6798f9 100644 --- a/utils/statd/rmtcall.c +++ b/utils/statd/rmtcall.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ #include "statd.h" #include "notlist.h" #include "log.h" +#include "ha-callout.h" #define MAXMSGSIZE (2048 / sizeof(unsigned int)) @@ -46,8 +48,8 @@ static int sockfd = -1; /* notify socket */ /* * Initialize callback socket */ -static int -get_socket(void) +int +statd_get_socket(int port) { struct sockaddr_in sin; @@ -55,7 +57,7 @@ get_socket(void) return sockfd; if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - log(L_CRIT, "Can't create socket: %m"); + note(N_CRIT, "Can't create socket: %m"); return -1; } @@ -63,8 +65,19 @@ get_socket(void) memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; + sin.sin_port = port; + /* + * 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 (bindresvport(sockfd, &sin) < 0) { - dprintf(L_WARNING, + dprintf(N_WARNING, "process_hosts: can't bind to reserved port\n"); } @@ -88,7 +101,7 @@ try_to_resolve(notify_list *lp) else hname = NL_MY_NAME(lp); if (!inet_aton(hname, &(NL_ADDR(lp)))) { - log(L_ERROR, "%s is not an dotted-quad address", hname); + note(N_ERROR, "%s is not an dotted-quad address", hname); NL_TIMES(lp) = 0; return 0; } @@ -111,7 +124,7 @@ try_to_resolve(notify_list *lp) else hname = NL_MY_NAME(lp); - dprintf(L_DEBUG, "Trying to resolve %s.", hname); + dprintf(N_DEBUG, "Trying to resolve %s.", hname); if (!(hp = gethostbyname(hname))) { herror("gethostbyname"); NL_TIMES(lp) -= 1; @@ -119,7 +132,7 @@ try_to_resolve(notify_list *lp) } if (hp->h_addrtype != AF_INET) { - log(L_ERROR, "%s is not an AF_INET address", hname); + note(N_ERROR, "%s is not an AF_INET address", hname); NL_TIMES(lp) = 0; return 0; } @@ -128,7 +141,7 @@ try_to_resolve(notify_list *lp) * alternation because one interface might be down/unreachable. */ NL_ADDR(lp) = *(struct in_addr *) hp->h_addr; - dprintf(L_DEBUG, "address of %s is %s", hname, inet_ntoa(NL_ADDR(lp))); + dprintf(N_DEBUG, "address of %s is %s", hname, inet_ntoa(NL_ADDR(lp))); return 1; } #endif @@ -179,7 +192,7 @@ xmit_call(int sockfd, struct sockaddr_in *sin, /* Encode the RPC header part and payload */ if (!xdr_callmsg(xdrs, &mesg) || !func(xdrs, obj)) { - dprintf(L_WARNING, "xmit_mesg: can't encode RPC message!\n"); + dprintf(N_WARNING, "xmit_mesg: can't encode RPC message!\n"); xdr_destroy(xdrs); return 0; } @@ -189,9 +202,9 @@ xmit_call(int sockfd, struct sockaddr_in *sin, if ((err = sendto(sockfd, msgbuf, msglen, 0, (struct sockaddr *) sin, sizeof(*sin))) < 0) { - dprintf(L_WARNING, "xmit_mesg: sendto failed: %m"); + dprintf(N_WARNING, "xmit_mesg: sendto failed: %m"); } else if (err != msglen) { - dprintf(L_WARNING, "xmit_mesg: short write: %m\n"); + dprintf(N_WARNING, "xmit_mesg: short write: %m\n"); } xdr_destroy(xdrs); @@ -211,7 +224,7 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) /* Receive message */ if ((msglen = recvfrom(sockfd, msgbuf, sizeof(msgbuf), 0, (struct sockaddr *) sin, &alen)) < 0) { - dprintf(L_WARNING, "recv_rply: recvfrom failed: %m"); + dprintf(N_WARNING, "recv_rply: recvfrom failed: %m"); return NULL; } @@ -223,18 +236,18 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) mesg.rm_reply.rp_acpt.ar_results.proc = (xdrproc_t) xdr_void; if (!xdr_replymsg(xdrs, &mesg)) { - log(L_WARNING, "recv_rply: can't decode RPC message!\n"); + note(N_WARNING, "recv_rply: can't decode RPC message!\n"); goto done; } if (mesg.rm_reply.rp_stat != 0) { - log(L_WARNING, "recv_rply: [%s] RPC status %d\n", + note(N_WARNING, "recv_rply: [%s] RPC status %d\n", inet_ntoa(sin->sin_addr), mesg.rm_reply.rp_stat); goto done; } if (mesg.rm_reply.rp_acpt.ar_stat != 0) { - log(L_WARNING, "recv_rply: [%s] RPC status %d\n", + note(N_WARNING, "recv_rply: [%s] RPC status %d\n", inet_ntoa(sin->sin_addr), mesg.rm_reply.rp_acpt.ar_stat); goto done; @@ -251,13 +264,13 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) strncpy (addr, inet_ntoa(lp->addr), sizeof (addr) - 1); addr [sizeof (addr) - 1] = '\0'; - dprintf(L_WARNING, "address mismatch: " + dprintf(N_WARNING, "address mismatch: " "expected %s, got %s\n", addr, inet_ntoa(sin->sin_addr)); } if (lp->port == 0) { if (!xdr_u_long(xdrs, portp)) { - log(L_WARNING, "recv_rply: [%s] " + note(N_WARNING, "recv_rply: [%s] " "can't decode reply body!\n", inet_ntoa(sin->sin_addr)); lp = NULL; @@ -288,7 +301,7 @@ process_entry(int sockfd, notify_list *lp) if (lp->addr.s_addr == INADDR_ANY && !try_to_resolve(lp)) return NL_TIMES(lp); if (NL_TIMES(lp) == 0) { - log(L_DEBUG, "Cannot notify %s, giving up.\n", + note(N_DEBUG, "Cannot notify %s, giving up.\n", inet_ntoa(NL_ADDR(lp))); return 0; } @@ -326,14 +339,14 @@ process_entry(int sockfd, notify_list *lp) memcpy(new_status.priv, NL_PRIV(lp), SM_PRIV_SIZE); break; default: - log(L_ERROR, "notify_host: unknown notify type %d", + note(N_ERROR, "notify_host: unknown notify type %d", NL_TYPE(lp)); return 0; } lp->xid = xmit_call(sockfd, &sin, prog, vers, proc, func, objp); if (!lp->xid) { - log(L_WARNING, "notify_host: failed to notify %s\n", + note(N_WARNING, "notify_host: failed to notify %s\n", inet_ntoa(lp->addr)); } NL_TIMES(lp) -= 1; @@ -366,15 +379,15 @@ process_reply(FD_SET_TYPE *rfds) nlist_insert_timer(¬ify, lp); return 1; } - log(L_WARNING, "recv_rply: [%s] service %d not registered", + 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(L_DEBUG, "Notification of %s succeeded.", + dprintf(N_DEBUG, "Notification of %s succeeded.", NL_MON_NAME(lp)); xunlink(SM_BAK_DIR, NL_MON_NAME(lp), 0); } else { - dprintf(L_DEBUG, "Callback to %s (for %d) succeeded.", + dprintf(N_DEBUG, "Callback to %s (for %d) succeeded.", NL_MY_NAME(lp), NL_MON_NAME(lp)); } nlist_free(¬ify, lp); @@ -393,7 +406,7 @@ process_notify_list(void) time_t now; int fd; - if ((fd = get_socket()) < 0) + if ((fd = statd_get_socket(0)) < 0) return 0; while ((entry = notify) != NULL && NL_WHEN(entry) < time(&now)) { @@ -402,16 +415,18 @@ process_notify_list(void) nlist_remove(¬ify, entry); nlist_insert_timer(¬ify, entry); } else if (NL_TYPE(entry) == NOTIFY_CALLBACK) { - log(L_ERROR, + 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 { - log(L_ERROR, + 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); }