summaryrefslogtreecommitdiff
path: root/usr.sbin/mrouted
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:32:54 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:32:54 +0000
commit86ffccf24f66032a89d70a32b3609584c0db7345 (patch)
tree2ae97fac6ea5be57cc953baf8612e8f683da0172 /usr.sbin/mrouted
parentce9fea47562d4f179d45680d6aec00ede2877141 (diff)
When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
Diffstat (limited to 'usr.sbin/mrouted')
-rw-r--r--usr.sbin/mrouted/cfparse.y2
-rw-r--r--usr.sbin/mrouted/config.c2
-rw-r--r--usr.sbin/mrouted/igmp.c4
-rw-r--r--usr.sbin/mrouted/kern.c30
-rw-r--r--usr.sbin/mrouted/main.c10
-rw-r--r--usr.sbin/mrouted/prune.c8
-rw-r--r--usr.sbin/mrouted/rsrr.c10
-rw-r--r--usr.sbin/mrouted/vif.c18
8 files changed, 42 insertions, 42 deletions
diff --git a/usr.sbin/mrouted/cfparse.y b/usr.sbin/mrouted/cfparse.y
index 9269812d323..0b8af93ea21 100644
--- a/usr.sbin/mrouted/cfparse.y
+++ b/usr.sbin/mrouted/cfparse.y
@@ -142,7 +142,7 @@ stmt : error
inet_fmt($2, s1));
strlcpy(ffr.ifr_name, ifname, sizeof(ffr.ifr_name));
- if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0)
+ if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr) == -1)
fatal("ioctl SIOCGIFFLAGS on %s",ffr.ifr_name);
if (ffr.ifr_flags & IFF_LOOPBACK)
fatal("Tunnel local address %s is a loopback interface",
diff --git a/usr.sbin/mrouted/config.c b/usr.sbin/mrouted/config.c
index 20f193fd761..9ba913f577f 100644
--- a/usr.sbin/mrouted/config.c
+++ b/usr.sbin/mrouted/config.c
@@ -27,7 +27,7 @@ config_vifs_from_kernel(void)
u_int32_t addr, mask, subnet;
short flags;
- if (getifaddrs(&ifap) < 0)
+ if (getifaddrs(&ifap) == -1)
logit(LOG_ERR, errno, "getifaddrs");
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
diff --git a/usr.sbin/mrouted/igmp.c b/usr.sbin/mrouted/igmp.c
index 46a652e6c5f..a6e5a55f299 100644
--- a/usr.sbin/mrouted/igmp.c
+++ b/usr.sbin/mrouted/igmp.c
@@ -43,7 +43,7 @@ init_igmp(void)
recv_buf = malloc(RECV_BUF_SIZE);
send_buf = malloc(RECV_BUF_SIZE);
- if ((igmp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP)) < 0)
+ if ((igmp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP)) == -1)
logit(LOG_ERR, errno, "IGMP socket");
k_hdr_include(TRUE); /* include IP header when sending */
@@ -331,7 +331,7 @@ send_igmp(u_int32_t src, u_int32_t dst, int type, int code,
sdst.sin_len = sizeof(sdst);
sdst.sin_addr.s_addr = dst;
if (sendto(igmp_socket, send_buf, ntohs(ip->ip_len), 0,
- (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
+ (struct sockaddr *)&sdst, sizeof(sdst)) == -1) {
if (errno == ENETDOWN)
check_vif_state();
else
diff --git a/usr.sbin/mrouted/kern.c b/usr.sbin/mrouted/kern.c
index 89171d2b19b..2c0154d3276 100644
--- a/usr.sbin/mrouted/kern.c
+++ b/usr.sbin/mrouted/kern.c
@@ -16,7 +16,7 @@
void k_set_rcvbuf(int bufsize)
{
if (setsockopt(igmp_socket, SOL_SOCKET, SO_RCVBUF,
- (char *)&bufsize, sizeof(bufsize)) < 0)
+ (char *)&bufsize, sizeof(bufsize)) == -1)
logit(LOG_ERR, errno, "setsockopt SO_RCVBUF %u", bufsize);
}
@@ -25,7 +25,7 @@ void k_hdr_include(int bool)
{
#ifdef IP_HDRINCL
if (setsockopt(igmp_socket, IPPROTO_IP, IP_HDRINCL,
- (char *)&bool, sizeof(bool)) < 0)
+ (char *)&bool, sizeof(bool)) == -1)
logit(LOG_ERR, errno, "setsockopt IP_HDRINCL %u", bool);
#endif
}
@@ -37,7 +37,7 @@ void k_set_ttl(int t)
ttl = t;
if (setsockopt(igmp_socket, IPPROTO_IP, IP_MULTICAST_TTL,
- (char *)&ttl, sizeof(ttl)) < 0)
+ (char *)&ttl, sizeof(ttl)) == -1)
logit(LOG_ERR, errno, "setsockopt IP_MULTICAST_TTL %u", ttl);
}
@@ -48,7 +48,7 @@ void k_set_loop(int l)
loop = l;
if (setsockopt(igmp_socket, IPPROTO_IP, IP_MULTICAST_LOOP,
- (char *)&loop, sizeof(loop)) < 0)
+ (char *)&loop, sizeof(loop)) == -1)
logit(LOG_ERR, errno, "setsockopt IP_MULTICAST_LOOP %u", loop);
}
@@ -59,7 +59,7 @@ void k_set_if(u_int32_t ifa)
adr.s_addr = ifa;
if (setsockopt(igmp_socket, IPPROTO_IP, IP_MULTICAST_IF,
- (char *)&adr, sizeof(adr)) < 0)
+ (char *)&adr, sizeof(adr)) == -1)
logit(LOG_ERR, errno, "setsockopt IP_MULTICAST_IF %s",
inet_fmt(ifa, s1));
}
@@ -73,7 +73,7 @@ void k_join(u_int32_t grp, u_int32_t ifa)
mreq.imr_interface.s_addr = ifa;
if (setsockopt(igmp_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
- (char *)&mreq, sizeof(mreq)) < 0)
+ (char *)&mreq, sizeof(mreq)) == -1)
logit(LOG_WARNING, errno, "can't join group %s on interface %s",
inet_fmt(grp, s1), inet_fmt(ifa, s2));
}
@@ -87,7 +87,7 @@ void k_leave(u_int32_t grp, u_int32_t ifa)
mreq.imr_interface.s_addr = ifa;
if (setsockopt(igmp_socket, IPPROTO_IP, IP_DROP_MEMBERSHIP,
- (char *)&mreq, sizeof(mreq)) < 0)
+ (char *)&mreq, sizeof(mreq)) == -1)
logit(LOG_WARNING, errno, "can't leave group %s on interface %s",
inet_fmt(grp, s1), inet_fmt(ifa, s2));
}
@@ -97,12 +97,12 @@ void k_init_dvmrp(void)
{
#ifdef OLD_KERNEL
if (setsockopt(igmp_socket, IPPROTO_IP, MRT_INIT,
- (char *)NULL, 0) < 0)
+ (char *)NULL, 0) == -1)
#else
int v=1;
if (setsockopt(igmp_socket, IPPROTO_IP, MRT_INIT,
- (char *)&v, sizeof(int)) < 0)
+ (char *)&v, sizeof(int)) == -1)
#endif
logit(LOG_ERR, errno, "can't enable Multicast routing in kernel");
}
@@ -111,7 +111,7 @@ void k_init_dvmrp(void)
void k_stop_dvmrp(void)
{
if (setsockopt(igmp_socket, IPPROTO_IP, MRT_DONE,
- (char *)NULL, 0) < 0)
+ (char *)NULL, 0) == -1)
logit(LOG_WARNING, errno, "can't disable Multicast routing in kernel");
}
@@ -128,7 +128,7 @@ void k_add_vif(vifi_t vifi, struct uvif *v)
vc.vifc_rmt_addr.s_addr = v->uv_rmt_addr;
if (setsockopt(igmp_socket, IPPROTO_IP, MRT_ADD_VIF,
- (char *)&vc, sizeof(vc)) < 0)
+ (char *)&vc, sizeof(vc)) == -1)
logit(LOG_ERR, errno, "setsockopt MRT_ADD_VIF");
}
@@ -136,7 +136,7 @@ void k_add_vif(vifi_t vifi, struct uvif *v)
void k_del_vif(vifi_t vifi)
{
if (setsockopt(igmp_socket, IPPROTO_IP, MRT_DEL_VIF,
- (char *)&vifi, sizeof(vifi)) < 0)
+ (char *)&vifi, sizeof(vifi)) == -1)
logit(LOG_ERR, errno, "setsockopt MRT_DEL_VIF");
}
@@ -164,7 +164,7 @@ void k_add_rg(u_int32_t origin, struct gtable *g)
/* write to kernel space */
if (setsockopt(igmp_socket, IPPROTO_IP, MRT_ADD_MFC,
- (char *)&mc, sizeof(mc)) < 0) {
+ (char *)&mc, sizeof(mc)) == -1) {
#ifdef DEBUG_MFC
md_logit(MD_ADD_FAIL, origin, g->gt_mcastgrp);
#endif
@@ -193,7 +193,7 @@ int k_del_rg(u_int32_t origin, struct gtable *g)
/* write to kernel space */
if ((retval = setsockopt(igmp_socket, IPPROTO_IP, MRT_DEL_MFC,
- (char *)&mc, sizeof(mc))) < 0) {
+ (char *)&mc, sizeof(mc))) == -1) {
#ifdef DEBUG_MFC
md_logit(MD_DEL_FAIL, origin, g->gt_mcastgrp);
#endif
@@ -215,7 +215,7 @@ int k_get_version(void)
int len = sizeof(vers);
if (getsockopt(igmp_socket, IPPROTO_IP, MRT_VERSION,
- (char *)&vers, &len) < 0)
+ (char *)&vers, &len) == -1)
logit(LOG_ERR, errno,
"getsockopt MRT_VERSION: perhaps your kernel is too old");
diff --git a/usr.sbin/mrouted/main.c b/usr.sbin/mrouted/main.c
index 2d3334b3ac8..4c83bc95e93 100644
--- a/usr.sbin/mrouted/main.c
+++ b/usr.sbin/mrouted/main.c
@@ -142,7 +142,7 @@ usage: fprintf(stderr,
(void)close(t);
}
#else
- if (setsid() < 0)
+ if (setsid() == -1)
perror("setsid");
#endif
}
@@ -250,7 +250,7 @@ usage: fprintf(stderr,
*/
dummy = 0;
for(;;) {
- if ((n = poll(pfd, nhandlers + 1, -1)) < 0) {
+ if ((n = poll(pfd, nhandlers + 1, -1)) == -1) {
if (errno != EINTR) /* SIGALRM is expected */
logit(LOG_WARNING, errno, "poll failed");
continue;
@@ -259,13 +259,13 @@ usage: fprintf(stderr,
if (pfd[0].revents & POLLIN) {
recvlen = recvfrom(igmp_socket, recv_buf, RECV_BUF_SIZE,
0, NULL, &dummy);
- if (recvlen < 0) {
+ if (recvlen == -1) {
if (errno != EINTR) logit(LOG_ERR, errno, "recvfrom");
continue;
}
(void)sigemptyset(&mask);
(void)sigaddset(&mask, SIGALRM);
- if (sigprocmask(SIG_BLOCK, &mask, &omask) < 0)
+ if (sigprocmask(SIG_BLOCK, &mask, &omask) == -1)
logit(LOG_ERR, errno, "sigprocmask");
accept_igmp(recvlen);
(void)sigprocmask(SIG_SETMASK, &omask, NULL);
@@ -488,7 +488,7 @@ restart(int i)
*/
(void)sigemptyset(&mask);
(void)sigaddset(&mask, SIGALRM);
- if (sigprocmask(SIG_BLOCK, &mask, &omask) < 0)
+ if (sigprocmask(SIG_BLOCK, &mask, &omask) == -1)
logit(LOG_ERR, errno, "sigprocmask");
free_all_prunes();
free_all_routes();
diff --git a/usr.sbin/mrouted/prune.c b/usr.sbin/mrouted/prune.c
index e51d3de6ce8..8bc1f7c397c 100644
--- a/usr.sbin/mrouted/prune.c
+++ b/usr.sbin/mrouted/prune.c
@@ -1469,7 +1469,7 @@ age_table_entry(void)
stnp = &gt->gt_srctbl;
while ((st = *stnp) != NULL) {
sg_req.src.s_addr = st->st_origin;
- if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) < 0) {
+ if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) == -1) {
logit(LOG_WARNING, errno, "%s (%s %s)",
"age_table_entry: SIOCGETSGCNT failing for",
inet_fmt(st->st_origin, s1),
@@ -1901,7 +1901,7 @@ accept_mtrace(u_int32_t src, u_int32_t dst, u_int32_t group,
* obtain # of packets out on interface
*/
v_req.vifi = vifi;
- if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) >= 0)
+ if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) == 0)
resp->tr_vifout = htonl(v_req.ocount);
/*
@@ -1918,7 +1918,7 @@ accept_mtrace(u_int32_t src, u_int32_t dst, u_int32_t group,
if (gt && gt->gt_mcastgrp == group) {
sg_req.src.s_addr = qry->tr_src;
sg_req.grp.s_addr = group;
- if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) >= 0)
+ if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) == 0)
resp->tr_pktcnt = htonl(sg_req.pktcnt);
if (VIFM_ISSET(vifi, gt->gt_scope))
@@ -1950,7 +1950,7 @@ accept_mtrace(u_int32_t src, u_int32_t dst, u_int32_t group,
} else {
/* get # of packets in on interface */
v_req.vifi = rt->rt_parent;
- if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) >= 0)
+ if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) == 0)
resp->tr_vifin = htonl(v_req.icount);
MASK_TO_VAL(rt->rt_originmask, resp->tr_smask);
diff --git a/usr.sbin/mrouted/rsrr.c b/usr.sbin/mrouted/rsrr.c
index 4bf8183ff8a..3cf659de420 100644
--- a/usr.sbin/mrouted/rsrr.c
+++ b/usr.sbin/mrouted/rsrr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rsrr.c,v 1.15 2017/01/21 11:32:04 guenther Exp $ */
+/* $OpenBSD: rsrr.c,v 1.16 2019/06/28 13:32:48 deraadt Exp $ */
/* $NetBSD: rsrr.c,v 1.3 1995/12/10 10:07:14 mycroft Exp $ */
/*
@@ -85,7 +85,7 @@ rsrr_init(void)
{
struct sockaddr_un serv_addr;
- if ((rsrr_socket = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
+ if ((rsrr_socket = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
logit(LOG_ERR, errno, "Can't create RSRR socket");
unlink(RSRR_SERV_PATH);
@@ -93,7 +93,7 @@ rsrr_init(void)
serv_addr.sun_family = AF_UNIX;
strlcpy(serv_addr.sun_path, RSRR_SERV_PATH, sizeof serv_addr.sun_path);
- if (bind(rsrr_socket, (struct sockaddr *)&serv_addr, sizeof serv_addr) < 0)
+ if (bind(rsrr_socket, (struct sockaddr *)&serv_addr, sizeof serv_addr) == -1)
logit(LOG_ERR, errno, "Can't bind RSRR socket");
if (register_input_handler(rsrr_socket,rsrr_read) < 0)
@@ -110,7 +110,7 @@ rsrr_read(int f)
bzero((char *) &client_addr, sizeof(client_addr));
rsrr_recvlen = recvfrom(rsrr_socket, rsrr_recv_buf, sizeof(rsrr_recv_buf),
0, (struct sockaddr *)&client_addr, &client_length);
- if (rsrr_recvlen < 0) {
+ if (rsrr_recvlen == -1) {
if (errno != EINTR)
logit(LOG_ERR, errno, "RSRR recvfrom");
return;
@@ -370,7 +370,7 @@ rsrr_send(int sendlen)
(struct sockaddr *)&client_addr, client_length);
/* Check for errors. */
- if (error < 0) {
+ if (error == -1) {
logit(LOG_WARNING, errno, "Failed send on RSRR socket");
} else if (error != sendlen) {
logit(LOG_WARNING, 0,
diff --git a/usr.sbin/mrouted/vif.c b/usr.sbin/mrouted/vif.c
index be1baf52299..c228a88c494 100644
--- a/usr.sbin/mrouted/vif.c
+++ b/usr.sbin/mrouted/vif.c
@@ -71,7 +71,7 @@ init_vifs(void)
* the kernel and the contents of the configuration file.
* (Open a UDP socket for ioctl use in the config procedures.)
*/
- if ((udp_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ if ((udp_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
logit(LOG_ERR, errno, "UDP socket");
logit(LOG_INFO,0,"Getting vifs from kernel interfaces");
config_vifs_from_kernel();
@@ -169,7 +169,7 @@ check_vif_state(void)
if (v->uv_flags & VIFF_DISABLED) continue;
strncpy(ifr.ifr_name, v->uv_name, IFNAMSIZ);
- if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0)
+ if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) == -1)
logit(LOG_ERR, errno,
"ioctl SIOCGIFFLAGS for %s", ifr.ifr_name);
@@ -702,9 +702,9 @@ accept_neighbor_request(u_int32_t src, u_int32_t dst)
addr.sin_len = sizeof addr;
addr.sin_addr.s_addr = dst;
addr.sin_port = htons(2000); /* any port over 1024 will do... */
- if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0
- || connect(udp, (struct sockaddr *) &addr, sizeof(addr)) < 0
- || getsockname(udp, (struct sockaddr *) &addr, &addrlen) < 0) {
+ if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) == -1
+ || connect(udp, (struct sockaddr *) &addr, sizeof(addr)) == -1
+ || getsockname(udp, (struct sockaddr *) &addr, &addrlen) == -1) {
logit(LOG_WARNING, errno, "Determining local address");
close(udp);
return;
@@ -787,9 +787,9 @@ accept_neighbor_request2(u_int32_t src, u_int32_t dst)
addr.sin_len = sizeof addr;
addr.sin_addr.s_addr = dst;
addr.sin_port = htons(2000); /* any port over 1024 will do... */
- if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0
- || connect(udp, (struct sockaddr *) &addr, sizeof(addr)) < 0
- || getsockname(udp, (struct sockaddr *) &addr, &addrlen) < 0) {
+ if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) == -1
+ || connect(udp, (struct sockaddr *) &addr, sizeof(addr)) == -1
+ || getsockname(udp, (struct sockaddr *) &addr, &addrlen) == -1) {
logit(LOG_WARNING, errno, "Determining local address");
close(udp);
return;
@@ -1332,7 +1332,7 @@ dump_vifs(FILE *fp)
}
}
v_req.vifi = vifi;
- if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) < 0) {
+ if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) == -1) {
logit(LOG_WARNING, 0,
"SIOCGETVIFCNT fails");
}