Skip to content

Commit c40f502

Browse files
committed
CFE-3046: Only add unique IPv4 interfaces to sys.interfaces
Previously, when an interface had multiple IPv4 addresses set, the parsing of these addresses would add the interface to the sys.interfaces and sys.hardware variables multiple times, resulting in the interface showing up as a duplicate in the list. This fix makes sure that an interface is only added once for every interface type, regardless of how many IPv4 addresses the interface contains. Changelog: Fixed an issue causing duplicate entries in sys.interfaces, and sys.hardware. Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
1 parent b66d8ec commit c40f502

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)