ref: 46b8a0ac0052c5a0f760ea7ea7e7261fe160f1ce
parent: acb49987e671033834c1d3e3d19f7f0e4e689333
author: cinap_lenrek <[email protected]>
date: Tue Aug 26 21:12:42 EDT 2014
ipconfig: fix readipifc() memory leaks in recvra6 and sendra6 processes to avoid continuously leaking memory in recvra6 and sendra6 processes, pass the previous Ipifc* pointer to readipifc().
--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -453,11 +453,8 @@
}
static int
-recvra6on(char *net, int conn)
+recvra6on(Ipifc *ifc)
{
- Ipifc* ifc;
-
- ifc = readipifc(net, nil, conn);
if (ifc == nil)
return 0;
else if (ifc->sendra6 > 0)
@@ -663,6 +660,7 @@
{
int fd, cfd, n, sendrscnt, sleepfor;
uchar buf[4096];
+ Ipifc *ifc = nil;
/* TODO: why not v6allroutersL? */
fd = dialicmp(v6allnodesL, ICMP6_RA, &cfd);
@@ -695,10 +693,18 @@
alarm(sleepfor);
n = read(fd, buf, sizeof buf);
alarm(0);
+
+ ifc = readipifc(conf.mpoint, ifc, myifc);
+ if (ifc == nil) {
+ ralog("recvra6: can't read router params on %s",
+ conf.mpoint);
+ continue;
+ }
+
if (n <= 0) {
if (sendrscnt > 0) {
sendrscnt--;
- if (recvra6on(conf.mpoint, myifc) == IsHostRecv)
+ if (recvra6on(ifc) == IsHostRecv)
sendrs(fd);
sleepfor = V6rsintvl + nrand(100);
}
@@ -713,7 +719,7 @@
sleepfor = 0;
sendrscnt = -1; /* got at least initial ra; no whining */
- switch (recvra6on(conf.mpoint, myifc)) {
+ switch (recvra6on(ifc)) {
case IsRouter:
recvrarouter(buf, n);
break;
@@ -724,10 +730,6 @@
ralog("recvra6: recvra off, quitting on %s", conf.dev);
close(fd);
exits(0);
- default:
- ralog("recvra6: unable to read router status on %s",
- conf.dev);
- break;
}
}
}
@@ -783,12 +785,11 @@
}
void
-sendra(int fd, uchar *dst, int rlt)
+sendra(int fd, uchar *dst, int rlt, Ipifc *ifc)
{
int pktsz, preflen;
char abuf[1024], tmp[40];
uchar buf[1024], macaddr[6], src[IPaddrlen];
- Ipifc *ifc = nil;
Iplifc *lifc, *nlifc;
Lladdropt *llao;
Prefixopt *prfo;
@@ -818,7 +819,6 @@
pktsz = sizeof *ra;
/* include all global unicast prefixes on interface in prefix options */
- ifc = readipifc(conf.mpoint, ifc, myifc);
for (lifc = (ifc? ifc->lifc: nil); lifc; lifc = nlifc) {
nlifc = lifc->next;
prfo = (Prefixopt *)(buf + pktsz);
@@ -904,12 +904,13 @@
if (ifc == nil) {
ralog("sendra6: can't read router params on %s",
conf.mpoint);
+ sleep(1000);
continue;
}
if (ifc->sendra6 <= 0)
if (nquitmsgs > 0) {
- sendra(fd, v6allnodesL, 0);
+ sendra(fd, v6allnodesL, 0, ifc);
nquitmsgs--;
sleepfor = Minv6interradelay + jitter();
continue;
@@ -938,9 +939,9 @@
}
sleepfor = randint(ifc->rp.minraint, ifc->rp.maxraint);
if (dstknown > 0)
- sendra(fd, dst, 1);
+ sendra(fd, dst, 1, ifc);
else
- sendra(fd, v6allnodesL, 1);
+ sendra(fd, v6allnodesL, 1, ifc);
}
}