Skip to content

Commit cf525f3

Browse files
authored
Merge pull request #3943 from oleorhagen/CFE-3046
CFE-3046: Only add unique IPv4 interfaces to sys.interfaces
2 parents b66d8ec + c40f502 commit cf525f3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libenv/unix_iface.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,12 @@ void GetInterfacesInfo(EvalContext *ctx)
410410
/* If interface name appears a second time in a row then it has more
411411
than one IP addresses (linux: ip addr add $IP dev $IF).
412412
But the variable is already added so don't set it again. */
413+
bool add_mac_addr = false;
413414
if (strcmp(last_name, ifp->ifr_name) != 0)
414415
{
415416
strcpy(last_name, ifp->ifr_name);
416417
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "interface", last_name, CF_DATA_TYPE_STRING, "source=agent");
418+
add_mac_addr = true;
417419
}
418420

419421
snprintf(workbuf, sizeof(workbuf), "net_iface_%s", CanonifyName(ifp->ifr_name));
@@ -549,8 +551,12 @@ void GetInterfacesInfo(EvalContext *ctx)
549551
}
550552
}
551553

552-
// Set the hardware/mac address array
553-
GetMacAddress(ctx, fd, &ifr, ifp, &interfaces, &hardware);
554+
/* [CFE-3046] Only add unique interfaces to sys interfaces and hardware */
555+
if (add_mac_addr)
556+
{
557+
// Set the hardware/mac address array
558+
GetMacAddress(ctx, fd, &ifr, ifp, &interfaces, &hardware);
559+
}
554560
}
555561
}
556562

0 commit comments

Comments
 (0)