Said functions return an ssize_t. Comparing (size_t < 0) isn't going to
give good results. The type change in ra_output() deserves its own
commit.
Also, use the same type and the same name for both return values; "i" is
too generic.
ra_input()/rs_input() take an int, but I don't think we need to change
their signatures (no actual risk of overflow).
Last hunk: I don't think we want a failed send to be counted as
a successful one.
Compile-tested only for now. Thoughts? ok?
Index: rtadvd.c
===================================================================
RCS file: /d/cvs/src/usr.sbin/rtadvd/rtadvd.c,v
retrieving revision 1.83
diff -u -p -p -u -r1.83 rtadvd.c
--- rtadvd.c 20 Jan 2017 23:29:58 -0000 1.83
+++ rtadvd.c 4 Apr 2017 07:56:09 -0000
@@ -463,7 +463,7 @@ rtsock_cb(int fd, short event, void *arg
void
sock_cb(int fd, short event, void *arg)
{
- int i;
+ ssize_t len;
int *hlimp = NULL;
struct icmp6_hdr *icp;
int ifindex = 0;
@@ -478,7 +478,7 @@ sock_cb(int fd, short event, void *arg)
* receive options.
*/
rcvmhdr.msg_controllen = rcvcmsgbuflen;
- if ((i = recvmsg(sock, &rcvmhdr, 0)) < 0)
+ if ((len = recvmsg(sock, &rcvmhdr, 0)) < 0)
return;
/* extract optional information via Advanced API */
@@ -516,8 +516,8 @@ sock_cb(int fd, short event, void *arg)
return;
}
- if (i < sizeof(struct icmp6_hdr)) {
- log_warnx("packet size(%d) is too short", i);
+ if (len < sizeof(struct icmp6_hdr)) {
+ log_warnx("packet size(%zd) is too short", len);
return;
}
@@ -548,15 +548,14 @@ sock_cb(int fd, short event, void *arg)
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
return;
}
- if (i < sizeof(struct nd_router_solicit)) {
- log_info("RS from %s on %s does not have enough "
- "length (len = %d)",
+ if (len < sizeof(struct nd_router_solicit)) {
+ log_info("RS from %s on %s too short (len = %zd)",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
- if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
+ if_indextoname(pi->ipi6_ifindex, ifnamebuf), len);
return;
}
- rs_input(i, (struct nd_router_solicit *)icp, pi, &from);
+ rs_input(len, (struct nd_router_solicit *)icp, pi, &from);
break;
case ND_ROUTER_ADVERT:
/*
@@ -581,15 +580,14 @@ sock_cb(int fd, short event, void *arg)
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
return;
}
- if (i < sizeof(struct nd_router_advert)) {
- log_info("RA from %s on %s does not have enough "
- "length (len = %d)",
+ if (len < sizeof(struct nd_router_advert)) {
+ log_info("RA from %s on %s too short (len = %zd)",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
- if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
+ if_indextoname(pi->ipi6_ifindex, ifnamebuf), len);
return;
}
- ra_input(i, (struct nd_router_advert *)icp, pi, &from);
+ ra_input(len, (struct nd_router_advert *)icp, pi, &from);
break;
default:
/*
@@ -1218,7 +1216,7 @@ ra_output(struct rainfo *rainfo)
{
struct cmsghdr *cm;
struct in6_pktinfo *pi;
- size_t len;
+ ssize_t len;
if ((iflist[rainfo->ifindex]->ifm_flags & IFF_UP) == 0) {
log_debug("%s is not up, skip sending RA", rainfo->ifname);
@@ -1255,9 +1253,10 @@ ra_output(struct rainfo *rainfo)
rainfo->ifname, rainfo->waiting);
len = sendmsg(sock, &sndmhdr, 0);
-
- if (len < 0)
+ if (len < 0) {
log_warn("sendmsg on %s", rainfo->ifname);
+ return;
+ }
/* update counter */
if (rainfo->initcounter < MAX_INITIAL_RTR_ADVERTISEMENTS)
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE