summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/hostated/check_icmp.c159
-rw-r--r--usr.sbin/hoststated/check_icmp.c159
-rw-r--r--usr.sbin/relayd/check_icmp.c159
3 files changed, 288 insertions, 189 deletions
diff --git a/usr.sbin/hostated/check_icmp.c b/usr.sbin/hostated/check_icmp.c
index df92b444af9..4d93a652345 100644
--- a/usr.sbin/hostated/check_icmp.c
+++ b/usr.sbin/hostated/check_icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_icmp.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_icmp.c,v 1.2 2006/12/16 11:59:12 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -49,16 +49,16 @@ int check_icmp(struct host *host, int s, int s6, int timeout)
int check_icmp6(struct host *host, int s, int timeout)
{
- struct sockaddr *to;
- struct icmp6_hdr *icp;
- int ident;
- ssize_t i;
- int cc;
- int datalen = (64 - 8);
- u_char packet[datalen];
- fd_set fdset;
- socklen_t len;
- struct timeval tv;
+ struct sockaddr *to;
+ struct icmp6_hdr *icp;
+ int ident;
+ ssize_t i;
+ int cc;
+ int datalen = (64 - 8);
+ u_char packet[datalen];
+ fd_set fdset;
+ socklen_t len;
+ struct timeval tv;
to = (struct sockaddr *)&host->ss;
ident = getpid() & 0xFFFF;
@@ -81,35 +81,35 @@ int check_icmp6(struct host *host, int s, int timeout)
return (HOST_UNKNOWN);
}
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = timeout % 1000;
- FD_ZERO(&fdset);
- FD_SET(s, &fdset);
- switch (select(s + 1, &fdset, NULL, NULL, &tv)) {
- case -1:
- if (errno == EINTR) {
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = timeout % 1000;
+ FD_ZERO(&fdset);
+ FD_SET(s, &fdset);
+ switch (select(s + 1, &fdset, NULL, NULL, &tv)) {
+ case -1:
+ if (errno == EINTR) {
log_warnx("check_icmp6: interrupted");
return (HOST_UNKNOWN);
} else
fatal("check_icmp6: select");
- case 0:
- log_debug("check_icmp6: timeout");
- return (HOST_DOWN);
- default:
- bzero(&packet, sizeof(packet));
- i = recvfrom(s, packet, cc, 0, to, &len);
- if (i < 0 || i != cc) {
- log_warn("check_icmp6: did not receive valid ping");
- return (HOST_DOWN);
- }
- icp = (struct icmp6_hdr *)(packet);
- if (icp->icmp6_id != ident) {
- log_warnx("check_icmp6: did not receive valid ident");
- return (HOST_DOWN);
- }
- break;
- }
- return (HOST_UP);
+ case 0:
+ log_debug("check_icmp6: timeout");
+ return (HOST_DOWN);
+ default:
+ bzero(&packet, sizeof(packet));
+ i = recvfrom(s, packet, cc, 0, to, &len);
+ if (i < 0 || i != cc) {
+ log_warn("check_icmp6: did not receive valid ping");
+ return (HOST_DOWN);
+ }
+ icp = (struct icmp6_hdr *)(packet);
+ if (icp->icmp6_id != ident) {
+ log_warnx("check_icmp6: did not receive valid ident");
+ return (HOST_DOWN);
+ }
+ break;
+ }
+ return (HOST_UP);
}
int check_icmp4(struct host *host, int s, int timeout)
@@ -179,34 +179,67 @@ int check_icmp4(struct host *host, int s, int timeout)
return (HOST_UP);
}
-/* from ping.c */
+/* in_cksum from ping.c --
+ * Checksum routine for Internet Protocol family headers (C Version)
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Muuss.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
int
in_cksum(u_short *addr, int len)
{
- int nleft = len;
- u_short *w = addr;
- int sum = 0;
- u_short answer = 0;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum), we add
- * sequential 16 bit words to it, and at the end, fold back all the
- * carry bits from the top 16 bits into the lower 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if (nleft == 1) {
- *(u_char *)(&answer) = *(u_char *)w ;
- sum += answer;
- }
-
- /* add back carry outs from top 16 bits to low 16 bits */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return(answer);
+ int nleft = len;
+ u_short *w = addr;
+ int sum = 0;
+ u_short answer = 0;
+
+ /*
+ * Our algorithm is simple, using a 32 bit accumulator (sum), we add
+ * sequential 16 bit words to it, and at the end, fold back all the
+ * carry bits from the top 16 bits into the lower 16 bits.
+ */
+ while (nleft > 1) {
+ sum += *w++;
+ nleft -= 2;
+ }
+
+ /* mop up an odd byte, if necessary */
+ if (nleft == 1) {
+ *(u_char *)(&answer) = *(u_char *)w ;
+ sum += answer;
+ }
+
+ /* add back carry outs from top 16 bits to low 16 bits */
+ sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
+ sum += (sum >> 16); /* add carry */
+ answer = ~sum; /* truncate to 16 bits */
+
+ return (answer);
}
diff --git a/usr.sbin/hoststated/check_icmp.c b/usr.sbin/hoststated/check_icmp.c
index df92b444af9..4d93a652345 100644
--- a/usr.sbin/hoststated/check_icmp.c
+++ b/usr.sbin/hoststated/check_icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_icmp.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_icmp.c,v 1.2 2006/12/16 11:59:12 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -49,16 +49,16 @@ int check_icmp(struct host *host, int s, int s6, int timeout)
int check_icmp6(struct host *host, int s, int timeout)
{
- struct sockaddr *to;
- struct icmp6_hdr *icp;
- int ident;
- ssize_t i;
- int cc;
- int datalen = (64 - 8);
- u_char packet[datalen];
- fd_set fdset;
- socklen_t len;
- struct timeval tv;
+ struct sockaddr *to;
+ struct icmp6_hdr *icp;
+ int ident;
+ ssize_t i;
+ int cc;
+ int datalen = (64 - 8);
+ u_char packet[datalen];
+ fd_set fdset;
+ socklen_t len;
+ struct timeval tv;
to = (struct sockaddr *)&host->ss;
ident = getpid() & 0xFFFF;
@@ -81,35 +81,35 @@ int check_icmp6(struct host *host, int s, int timeout)
return (HOST_UNKNOWN);
}
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = timeout % 1000;
- FD_ZERO(&fdset);
- FD_SET(s, &fdset);
- switch (select(s + 1, &fdset, NULL, NULL, &tv)) {
- case -1:
- if (errno == EINTR) {
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = timeout % 1000;
+ FD_ZERO(&fdset);
+ FD_SET(s, &fdset);
+ switch (select(s + 1, &fdset, NULL, NULL, &tv)) {
+ case -1:
+ if (errno == EINTR) {
log_warnx("check_icmp6: interrupted");
return (HOST_UNKNOWN);
} else
fatal("check_icmp6: select");
- case 0:
- log_debug("check_icmp6: timeout");
- return (HOST_DOWN);
- default:
- bzero(&packet, sizeof(packet));
- i = recvfrom(s, packet, cc, 0, to, &len);
- if (i < 0 || i != cc) {
- log_warn("check_icmp6: did not receive valid ping");
- return (HOST_DOWN);
- }
- icp = (struct icmp6_hdr *)(packet);
- if (icp->icmp6_id != ident) {
- log_warnx("check_icmp6: did not receive valid ident");
- return (HOST_DOWN);
- }
- break;
- }
- return (HOST_UP);
+ case 0:
+ log_debug("check_icmp6: timeout");
+ return (HOST_DOWN);
+ default:
+ bzero(&packet, sizeof(packet));
+ i = recvfrom(s, packet, cc, 0, to, &len);
+ if (i < 0 || i != cc) {
+ log_warn("check_icmp6: did not receive valid ping");
+ return (HOST_DOWN);
+ }
+ icp = (struct icmp6_hdr *)(packet);
+ if (icp->icmp6_id != ident) {
+ log_warnx("check_icmp6: did not receive valid ident");
+ return (HOST_DOWN);
+ }
+ break;
+ }
+ return (HOST_UP);
}
int check_icmp4(struct host *host, int s, int timeout)
@@ -179,34 +179,67 @@ int check_icmp4(struct host *host, int s, int timeout)
return (HOST_UP);
}
-/* from ping.c */
+/* in_cksum from ping.c --
+ * Checksum routine for Internet Protocol family headers (C Version)
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Muuss.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
int
in_cksum(u_short *addr, int len)
{
- int nleft = len;
- u_short *w = addr;
- int sum = 0;
- u_short answer = 0;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum), we add
- * sequential 16 bit words to it, and at the end, fold back all the
- * carry bits from the top 16 bits into the lower 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if (nleft == 1) {
- *(u_char *)(&answer) = *(u_char *)w ;
- sum += answer;
- }
-
- /* add back carry outs from top 16 bits to low 16 bits */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return(answer);
+ int nleft = len;
+ u_short *w = addr;
+ int sum = 0;
+ u_short answer = 0;
+
+ /*
+ * Our algorithm is simple, using a 32 bit accumulator (sum), we add
+ * sequential 16 bit words to it, and at the end, fold back all the
+ * carry bits from the top 16 bits into the lower 16 bits.
+ */
+ while (nleft > 1) {
+ sum += *w++;
+ nleft -= 2;
+ }
+
+ /* mop up an odd byte, if necessary */
+ if (nleft == 1) {
+ *(u_char *)(&answer) = *(u_char *)w ;
+ sum += answer;
+ }
+
+ /* add back carry outs from top 16 bits to low 16 bits */
+ sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
+ sum += (sum >> 16); /* add carry */
+ answer = ~sum; /* truncate to 16 bits */
+
+ return (answer);
}
diff --git a/usr.sbin/relayd/check_icmp.c b/usr.sbin/relayd/check_icmp.c
index df92b444af9..4d93a652345 100644
--- a/usr.sbin/relayd/check_icmp.c
+++ b/usr.sbin/relayd/check_icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_icmp.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_icmp.c,v 1.2 2006/12/16 11:59:12 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -49,16 +49,16 @@ int check_icmp(struct host *host, int s, int s6, int timeout)
int check_icmp6(struct host *host, int s, int timeout)
{
- struct sockaddr *to;
- struct icmp6_hdr *icp;
- int ident;
- ssize_t i;
- int cc;
- int datalen = (64 - 8);
- u_char packet[datalen];
- fd_set fdset;
- socklen_t len;
- struct timeval tv;
+ struct sockaddr *to;
+ struct icmp6_hdr *icp;
+ int ident;
+ ssize_t i;
+ int cc;
+ int datalen = (64 - 8);
+ u_char packet[datalen];
+ fd_set fdset;
+ socklen_t len;
+ struct timeval tv;
to = (struct sockaddr *)&host->ss;
ident = getpid() & 0xFFFF;
@@ -81,35 +81,35 @@ int check_icmp6(struct host *host, int s, int timeout)
return (HOST_UNKNOWN);
}
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = timeout % 1000;
- FD_ZERO(&fdset);
- FD_SET(s, &fdset);
- switch (select(s + 1, &fdset, NULL, NULL, &tv)) {
- case -1:
- if (errno == EINTR) {
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = timeout % 1000;
+ FD_ZERO(&fdset);
+ FD_SET(s, &fdset);
+ switch (select(s + 1, &fdset, NULL, NULL, &tv)) {
+ case -1:
+ if (errno == EINTR) {
log_warnx("check_icmp6: interrupted");
return (HOST_UNKNOWN);
} else
fatal("check_icmp6: select");
- case 0:
- log_debug("check_icmp6: timeout");
- return (HOST_DOWN);
- default:
- bzero(&packet, sizeof(packet));
- i = recvfrom(s, packet, cc, 0, to, &len);
- if (i < 0 || i != cc) {
- log_warn("check_icmp6: did not receive valid ping");
- return (HOST_DOWN);
- }
- icp = (struct icmp6_hdr *)(packet);
- if (icp->icmp6_id != ident) {
- log_warnx("check_icmp6: did not receive valid ident");
- return (HOST_DOWN);
- }
- break;
- }
- return (HOST_UP);
+ case 0:
+ log_debug("check_icmp6: timeout");
+ return (HOST_DOWN);
+ default:
+ bzero(&packet, sizeof(packet));
+ i = recvfrom(s, packet, cc, 0, to, &len);
+ if (i < 0 || i != cc) {
+ log_warn("check_icmp6: did not receive valid ping");
+ return (HOST_DOWN);
+ }
+ icp = (struct icmp6_hdr *)(packet);
+ if (icp->icmp6_id != ident) {
+ log_warnx("check_icmp6: did not receive valid ident");
+ return (HOST_DOWN);
+ }
+ break;
+ }
+ return (HOST_UP);
}
int check_icmp4(struct host *host, int s, int timeout)
@@ -179,34 +179,67 @@ int check_icmp4(struct host *host, int s, int timeout)
return (HOST_UP);
}
-/* from ping.c */
+/* in_cksum from ping.c --
+ * Checksum routine for Internet Protocol family headers (C Version)
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Muuss.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
int
in_cksum(u_short *addr, int len)
{
- int nleft = len;
- u_short *w = addr;
- int sum = 0;
- u_short answer = 0;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum), we add
- * sequential 16 bit words to it, and at the end, fold back all the
- * carry bits from the top 16 bits into the lower 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if (nleft == 1) {
- *(u_char *)(&answer) = *(u_char *)w ;
- sum += answer;
- }
-
- /* add back carry outs from top 16 bits to low 16 bits */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return(answer);
+ int nleft = len;
+ u_short *w = addr;
+ int sum = 0;
+ u_short answer = 0;
+
+ /*
+ * Our algorithm is simple, using a 32 bit accumulator (sum), we add
+ * sequential 16 bit words to it, and at the end, fold back all the
+ * carry bits from the top 16 bits into the lower 16 bits.
+ */
+ while (nleft > 1) {
+ sum += *w++;
+ nleft -= 2;
+ }
+
+ /* mop up an odd byte, if necessary */
+ if (nleft == 1) {
+ *(u_char *)(&answer) = *(u_char *)w ;
+ sum += answer;
+ }
+
+ /* add back carry outs from top 16 bits to low 16 bits */
+ sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
+ sum += (sum >> 16); /* add carry */
+ answer = ~sum; /* truncate to 16 bits */
+
+ return (answer);
}