2012-08-11 17:44:27 +00:00
|
|
|
/*
|
2013-10-05 19:41:44 +00:00
|
|
|
* Copyright (C) 2009-2013 Red Hat, Inc.
|
2012-08-11 17:44:27 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-08-11 17:44:27 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-08-11 17:44:27 +00:00
|
|
|
#include "virnetdevvlan.h"
|
2019-04-01 14:28:05 +00:00
|
|
|
#include "viralloc.h"
|
2012-08-11 17:44:27 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
void
|
|
|
|
virNetDevVlanClear(virNetDevVlanPtr vlan)
|
|
|
|
{
|
|
|
|
VIR_FREE(vlan->tag);
|
|
|
|
vlan->nTags = 0;
|
2013-05-23 17:12:10 +00:00
|
|
|
vlan->nativeMode = 0;
|
|
|
|
vlan->nativeTag = 0;
|
2012-08-11 17:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
virNetDevVlanFree(virNetDevVlanPtr vlan)
|
|
|
|
{
|
|
|
|
if (vlan)
|
|
|
|
virNetDevVlanClear(vlan);
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(vlan);
|
2012-08-11 17:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-10-05 19:41:44 +00:00
|
|
|
virNetDevVlanEqual(const virNetDevVlan *a, const virNetDevVlan *b)
|
2012-08-11 17:44:27 +00:00
|
|
|
{
|
|
|
|
int ai, bi;
|
|
|
|
|
|
|
|
if (!(a || b))
|
|
|
|
return true;
|
|
|
|
if (!a || !b)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->trunk != b->trunk ||
|
2013-05-23 17:12:10 +00:00
|
|
|
a->nTags != b->nTags ||
|
|
|
|
a->nativeMode != b->nativeMode ||
|
|
|
|
a->nativeTag != b->nativeTag) {
|
2012-08-11 17:44:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ai = 0; ai < a->nTags; ai++) {
|
|
|
|
for (bi = 0; bi < b->nTags; bi++) {
|
|
|
|
if (a->tag[ai] == b->tag[bi])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bi >= b->nTags) {
|
|
|
|
/* no matches for a->tag[ai] anywhere in b->tag */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* virNetDevVlanCopy - copy from src into (already existing) dst.
|
|
|
|
* If src is NULL, dst will have nTags set to 0.
|
|
|
|
* dst is assumed to be empty on entry.
|
|
|
|
*/
|
|
|
|
int
|
2013-10-05 19:41:44 +00:00
|
|
|
virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlan *src)
|
2012-08-11 17:44:27 +00:00
|
|
|
{
|
|
|
|
if (!src || src->nTags == 0)
|
|
|
|
return 0;
|
|
|
|
|
2020-10-05 17:08:12 +00:00
|
|
|
dst->tag = g_new0(unsigned int, src->nTags);
|
2012-08-11 17:44:27 +00:00
|
|
|
dst->trunk = src->trunk;
|
|
|
|
dst->nTags = src->nTags;
|
2013-05-23 17:12:10 +00:00
|
|
|
dst->nativeMode = src->nativeMode;
|
|
|
|
dst->nativeTag = src->nativeTag;
|
2012-08-11 17:44:27 +00:00
|
|
|
memcpy(dst->tag, src->tag, src->nTags * sizeof(*src->tag));
|
|
|
|
return 0;
|
|
|
|
}
|