1
/*********************************************************
2
* Copyright (C) 2009 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
20
* @file compareNicInfo.c
22
* Comparison routines for NicInfo types. Handy for caching, unit testing.
24
* @todo Each byte of a MAC address is assumed to be represented by two
25
* characters. So, as far as these routines are concerned, 0:1:2:3:4:5
26
* != 00:01:02:03:04:05. Is this a problem?
34
#include "guestInfoLib.h"
38
* Common comparison prefix routine.
40
#define RETURN_EARLY_CMP_PTRS(a, b) do { \
43
} else if ((!(a) && (b)) || ((a) && !(b))) { \
50
******************************************************************************
51
* GuestInfo_IsEqual_DhcpConfigInfo -- */ /**
53
* Compares a pair of DhcpConfigInfos.
55
* @param[in] a DhcpConfigInfo number 1. May be NULL.
56
* @param[in] b DhcpConfigInfo number 2. May be NULL.
58
* @retval TRUE DhcpConfigInfos are equivalent.
59
* @retval FALSE DhcpConfigInfos differ.
61
******************************************************************************
65
GuestInfo_IsEqual_DhcpConfigInfo(const DhcpConfigInfo *a,
66
const DhcpConfigInfo *b)
68
RETURN_EARLY_CMP_PTRS(a, b);
70
return a->enabled == b->enabled &&
71
strcmp(a->dhcpSettings, b->dhcpSettings) == 0;
76
******************************************************************************
77
* GuestInfo_IsEqual_DnsConfigInfo -- */ /**
79
* Compares a pair of DnsConfigInfos.
81
* @param[in] a DnsConfigInfo number 1. May be NULL.
82
* @param[in] b DnsConfigInfo number 2. May be NULL.
84
* @retval TRUE DnsConfigInfos are equivalent.
85
* @retval FALSE DnsConfigInfos differ.
87
******************************************************************************
91
GuestInfo_IsEqual_DnsConfigInfo(const DnsConfigInfo *a,
92
const DnsConfigInfo *b)
97
RETURN_EARLY_CMP_PTRS(a, b);
99
if (!GuestInfo_IsEqual_DnsHostname(a->hostName, b->hostName) ||
100
!GuestInfo_IsEqual_DnsHostname(a->domainName, b->domainName) ||
101
a->serverList.serverList_len != b->serverList.serverList_len ||
102
a->searchSuffixes.searchSuffixes_len != b->searchSuffixes.searchSuffixes_len) {
107
* Since the lists' lengths match, search in b for each item in a. We'll
108
* assume that we don't have any duplicates in a s.t. unique(a) is a proper
111
* Bail if we can't find an entry.
114
XDRUTIL_FOREACH(ai, a, serverList) {
115
TypedIpAddress *aServer = XDRUTIL_GETITEM(a, serverList, ai);
117
XDRUTIL_FOREACH(bi, b, serverList) {
118
TypedIpAddress *bServer = XDRUTIL_GETITEM(b, serverList, bi);
120
if (GuestInfo_IsEqual_TypedIpAddress(aServer, bServer)) {
125
if (bi == b->serverList.serverList_len) {
126
/* Exhausted b's list, didn't find aServer. */
131
XDRUTIL_FOREACH(ai, a, searchSuffixes) {
132
DnsHostname *aSuffix = XDRUTIL_GETITEM(a, searchSuffixes, ai);
134
XDRUTIL_FOREACH(bi, b, searchSuffixes) {
135
DnsHostname *bSuffix = XDRUTIL_GETITEM(b, searchSuffixes, bi);
137
if (GuestInfo_IsEqual_DnsHostname(aSuffix, bSuffix)) {
142
if (bi == b->searchSuffixes.searchSuffixes_len) {
143
/* Exhausted b's list, didn't find aSuffix. */
153
******************************************************************************
154
* GuestInfo_IsEqual_DnsHostname -- */ /**
156
* Compares a pair of DnsHostnames.
158
* @param[in] a DnsHostname number 1. May be NULL.
159
* @param[in] b DnsHostname number 2. May be NULL.
161
* @retval TRUE DnsHostnames are equivalent.
162
* @retval FALSE DnsHostnames differ.
164
******************************************************************************
168
GuestInfo_IsEqual_DnsHostname(const DnsHostname *a,
169
const DnsHostname *b)
171
RETURN_EARLY_CMP_PTRS(a, b);
172
return strcasecmp(*a, *b) == 0 ? TRUE : FALSE;
177
******************************************************************************
178
* GuestInfo_IsEqual_GuestNicV3 -- */ /**
180
* Compares two GuestNicV3s.
182
* @param[in] a GuestNicV3 number 1. May be NULL.
183
* @param[in] b GuestNicV3 number 2. May be NULL.
185
* @retval TRUE GuestNicV3s are equivalent.
186
* @retval FALSE GuestNicV3s differ.
188
******************************************************************************
192
GuestInfo_IsEqual_GuestNicV3(const GuestNicV3 *a,
198
RETURN_EARLY_CMP_PTRS(a, b);
200
/* Not optional fields. */
201
ASSERT(a->macAddress);
202
ASSERT(b->macAddress);
204
if (strcasecmp(a->macAddress, b->macAddress) != 0) {
209
* Compare the IP lists.
212
if (a->ips.ips_len != b->ips.ips_len) {
216
XDRUTIL_FOREACH(ai, a, ips) {
217
IpAddressEntry *aEntry = XDRUTIL_GETITEM(a, ips, ai);
219
XDRUTIL_FOREACH(bi, b, ips) {
220
IpAddressEntry *bEntry = XDRUTIL_GETITEM(b, ips, bi);
222
if (GuestInfo_IsEqual_IpAddressEntry(aEntry, bEntry)) {
227
if (bi == b->ips.ips_len) {
228
/* Exhausted b's list, didn't find aEntry. */
234
GuestInfo_IsEqual_DnsConfigInfo(a->dnsConfigInfo, b->dnsConfigInfo) &&
235
GuestInfo_IsEqual_WinsConfigInfo(a->winsConfigInfo, b->winsConfigInfo) &&
236
GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov4, b->dhcpConfigInfov4) &&
237
GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov6, b->dhcpConfigInfov6);
242
******************************************************************************
243
* GuestInfo_IsEqual_InetCidrRouteEntry -- */ /**
245
* Compares two InetCidrRouteEntrys.
247
* @param[in] a InetCidrRouteEntry number 1. May be NULL.
248
* @param[in] b InetCidrRouteEntry number 2. May be NULL.
249
* @param[in] aInfo a's NicInfo container. If a != NULL, may NOT be NULL.
250
* @param[in] bInfo b's NicInfo container. If b != NULL, may NOT be NULL.
252
* @retval TRUE InetCidrRouteEntrys are equivalent.
253
* @retval FALSE InetCidrRouteEntrys differ.
255
******************************************************************************
259
GuestInfo_IsEqual_InetCidrRouteEntry(const InetCidrRouteEntry *a,
260
const InetCidrRouteEntry *b,
261
const NicInfoV3 *aInfo,
262
const NicInfoV3 *bInfo)
264
RETURN_EARLY_CMP_PTRS(a, b);
270
GuestInfo_IsEqual_TypedIpAddress(&a->inetCidrRouteDest,
271
&b->inetCidrRouteDest) &&
272
a->inetCidrRoutePfxLen == b->inetCidrRoutePfxLen &&
273
GuestInfo_IsEqual_TypedIpAddress(a->inetCidrRouteNextHop,
274
b->inetCidrRouteNextHop) &&
275
strcasecmp(aInfo->nics.nics_val[a->inetCidrRouteIfIndex].macAddress,
276
bInfo->nics.nics_val[b->inetCidrRouteIfIndex].macAddress) == 0 &&
277
a->inetCidrRouteType == b->inetCidrRouteType &&
278
a->inetCidrRouteMetric == b->inetCidrRouteMetric;
283
******************************************************************************
284
* GuestInfo_IsEqual_IpAddressEntry -- */ /**
286
* Compares two IpAddressEntrys.
288
* @param[in] a IpAddressEntry number 1. May be NULL.
289
* @param[in] b IpAddressEntry number 2. May be NULL.
291
* @retval TRUE IpAddressEntrys are equivalent.
292
* @retval FALSE IpAddressEntrys differ.
294
******************************************************************************
298
GuestInfo_IsEqual_IpAddressEntry(const IpAddressEntry *a,
299
const IpAddressEntry *b)
301
RETURN_EARLY_CMP_PTRS(a, b);
304
GuestInfo_IsEqual_TypedIpAddress(&a->ipAddressAddr, &b->ipAddressAddr) &&
305
a->ipAddressPrefixLength == b->ipAddressPrefixLength &&
306
((a->ipAddressOrigin == NULL && b->ipAddressOrigin == NULL) ||
307
(a->ipAddressOrigin != NULL && b->ipAddressOrigin != NULL &&
308
*a->ipAddressOrigin == *b->ipAddressOrigin)) &&
309
((a->ipAddressStatus == NULL && b->ipAddressStatus == NULL) ||
310
(a->ipAddressStatus != NULL && b->ipAddressStatus != NULL &&
311
*a->ipAddressStatus == *b->ipAddressStatus));
316
******************************************************************************
317
* GuestInfo_IsEqual_NicInfoV3 -- */ /**
319
* Compares two NicInfoV3s.
321
* @param[in] a NicInfoV3 number 1. May be NULL.
322
* @param[in] b NicInfoV3 number 2. May be NULL.
324
* @retval TRUE NicInfoV3s are equivalent.
325
* @retval FALSE NicInfoV3s differ.
327
******************************************************************************
331
GuestInfo_IsEqual_NicInfoV3(const NicInfoV3 *a,
337
RETURN_EARLY_CMP_PTRS(a, b);
340
* Compare the NIC lists.
343
if (a->nics.nics_len != b->nics.nics_len) {
347
XDRUTIL_FOREACH(ai, a, nics) {
348
GuestNicV3 *eachNic = XDRUTIL_GETITEM(a, nics, ai);
349
GuestNicV3 *cmpNic = GuestInfo_Util_FindNicByMac(b, eachNic->macAddress);
351
if (cmpNic == NULL ||
352
!GuestInfo_IsEqual_GuestNicV3(eachNic, cmpNic)) {
361
if (a->routes.routes_len != b->routes.routes_len) {
365
XDRUTIL_FOREACH(ai, a, routes) {
366
InetCidrRouteEntry *aRoute = XDRUTIL_GETITEM(a, routes, ai);
368
XDRUTIL_FOREACH(bi, b, routes) {
369
InetCidrRouteEntry *bRoute = XDRUTIL_GETITEM(b, routes, bi);
371
if (GuestInfo_IsEqual_InetCidrRouteEntry(aRoute, bRoute, a, b)) {
376
if (bi == b->routes.routes_len) {
377
/* Exhausted b's list, didn't find aRoute. */
383
* Compare the stack settings:
391
GuestInfo_IsEqual_DnsConfigInfo(a->dnsConfigInfo, b->dnsConfigInfo) &&
392
GuestInfo_IsEqual_WinsConfigInfo(a->winsConfigInfo, b->winsConfigInfo) &&
393
GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov4, b->dhcpConfigInfov4) &&
394
GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov6, b->dhcpConfigInfov6);
399
******************************************************************************
400
* GuestInfo_IsEqual_TypedIpAddress -- */ /**
402
* Compares two TypedIpAddresses.
404
* @param[in] a TypedIpAddress number 1. May be NULL.
405
* @param[in] b TypedIpAddress number 2. May be NULL.
407
* @retval TRUE TypedIpAddresses are equivalent.
408
* @retval FALSE TypedIpAddresses differ.
410
******************************************************************************
414
GuestInfo_IsEqual_TypedIpAddress(const TypedIpAddress *a,
415
const TypedIpAddress *b)
417
RETURN_EARLY_CMP_PTRS(a, b);
419
if (a->ipAddressAddrType != b->ipAddressAddrType ||
420
memcmp(a->ipAddressAddr.InetAddress_val,
421
b->ipAddressAddr.InetAddress_val,
422
a->ipAddressAddr.InetAddress_len)) {
431
******************************************************************************
432
* GuestInfo_IsEqual_WinsConfigInfo -- */ /**
434
* Compares a pair of WinsConfigInfos.
436
* @param[in] a WinsConfigInfo number 1. May be NULL.
437
* @param[in] b WinsConfigInfo number 2. May be NULL.
439
* @retval TRUE WinsConfigInfos are equivalent.
440
* @retval FALSE WinsConfigInfos differ.
442
******************************************************************************
446
GuestInfo_IsEqual_WinsConfigInfo(const WinsConfigInfo *a,
447
const WinsConfigInfo *b)
449
RETURN_EARLY_CMP_PTRS(a, b);
451
return GuestInfo_IsEqual_TypedIpAddress(&a->primary, &b->primary) &&
452
GuestInfo_IsEqual_TypedIpAddress(&a->secondary, &b->secondary);