diff options
author | Nate Straz <nstraz@redhat.com> | 2006-08-03 14:48:40 +0000 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2008-09-23 09:37:46 -0400 |
commit | d1b5e0346ac271397d4d1df2417c3378f46ef4cb (patch) | |
tree | c2a2dde809428605f4cafaa604483feec1f49df8 /btimed.c | |
parent | c750cf3977831da3646bbfa0085147c27f4422ce (diff) | |
download | qarsh-d1b5e0346ac271397d4d1df2417c3378f46ef4cb.tar.gz qarsh-d1b5e0346ac271397d4d1df2417c3378f46ef4cb.tar.xz qarsh-d1b5e0346ac271397d4d1df2417c3378f46ef4cb.zip |
Add cookies to the heartbeat packet for added safety.v1.10-1
Two factors forced this change.
1. ports were being re-used so quickly that we could get lingering
packets from past hosts when getting the btime for a new host.
2. We can't control which IP a btime response is sent from if a system
has more than one interface. Adding a cookie allows us to know that
a response came from whom we sent it.
Diffstat (limited to 'btimed.c')
-rw-r--r-- | btimed.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -22,9 +22,11 @@ main(int argc, char **argv) { int sd; char inmsg[BTIME_MSGLEN]; - char outmsg[BTIME_MSGLEN]; + char btimeonly[BTIME_MSGLEN]; + char cookiemsg[BTIME_MSGLEN]; + char *outmsg; struct sockaddr_in cli_addr; - int cli_addr_len; + socklen_t cli_addr_len; ssize_t nbytes; unsigned int local_btime; @@ -37,13 +39,14 @@ main(int argc, char **argv) alarm(30); /* Generate the standard btime message */ - memset(outmsg, 0, BTIME_MSGLEN); + memset(btimeonly, 0, BTIME_MSGLEN); local_btime = get_btime(); - sprintf(outmsg, "%u\n", local_btime); + sprintf(btimeonly, "%u\n", local_btime); syslog(LOG_INFO, "started with btime = %u", local_btime); for (;;) { memset(&cli_addr, 0, sizeof cli_addr); + memset(inmsg, 0, BTIME_MSGLEN); cli_addr_len = sizeof cli_addr; nbytes = recvfrom(sd, &inmsg, BTIME_MSGLEN, MSG_WAITALL, (struct sockaddr *)&cli_addr, &cli_addr_len); @@ -55,8 +58,18 @@ main(int argc, char **argv) syslog(LOG_INFO, "exitting"); exit(0); } + if (inmsg[0] == 'B' && inmsg[1] == 'T' ) { + /* New style heartbeat with cookie */ + /* Copy cookie to message and append timestamp */ + memset(cookiemsg, 0, BTIME_MSGLEN); + memcpy(cookiemsg, inmsg, COOKIE_LEN); + strcpy(cookiemsg + COOKIE_LEN, btimeonly); + outmsg = cookiemsg; + } else { + outmsg = btimeonly; + } - sendto(sd, &outmsg, BTIME_MSGLEN, MSG_DONTWAIT, + sendto(sd, outmsg, BTIME_MSGLEN, MSG_DONTWAIT, (struct sockaddr *)&cli_addr, cli_addr_len); /* We want to exit after 30 seconds of inactivity */ alarm(30); |