mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-02 19:31:18 +00:00
600462834f
In many files there are header comments that contain an Author: statement, supposedly reflecting who originally wrote the code. In a large collaborative project like libvirt, any non-trivial file will have been modified by a large number of different contributors. IOW, the Author: comments are quickly out of date, omitting people who have made significant contribitions. In some places Author: lines have been added despite the person merely being responsible for creating the file by moving existing code out of another file. IOW, the Author: lines give an incorrect record of authorship. With this all in mind, the comments are useless as a means to identify who to talk to about code in a particular file. Contributors will always be better off using 'git log' and 'git blame' if they need to find the author of a particular bit of code. This commit thus deletes all Author: comments from the source and adds a rule to prevent them reappearing. The Copyright headers are similarly misleading and inaccurate, however, we cannot delete these as they have legal meaning, despite being largely inaccurate. In addition only the copyright holder is permitted to change their respective copyright statement. Reviewed-by: Erik Skultety <eskultet@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
173 lines
5.5 KiB
C
173 lines
5.5 KiB
C
/*
|
|
* Copyright (C) 2009-2014 Red Hat, Inc.
|
|
*
|
|
* 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
|
|
* License along with this library. If not, see
|
|
* <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "netdev_vlan_conf.h"
|
|
#include "virerror.h"
|
|
#include "viralloc.h"
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
VIR_ENUM_IMPL(virNativeVlanMode, VIR_NATIVE_VLAN_MODE_LAST,
|
|
"default", "tagged", "untagged")
|
|
|
|
int
|
|
virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr def)
|
|
{
|
|
int ret = -1;
|
|
xmlNodePtr save = ctxt->node;
|
|
char *trunk = NULL;
|
|
char *nativeMode = NULL;
|
|
xmlNodePtr *tagNodes = NULL;
|
|
int nTags;
|
|
size_t i;
|
|
|
|
ctxt->node = node;
|
|
|
|
nTags = virXPathNodeSet("./tag", ctxt, &tagNodes);
|
|
if (nTags < 0)
|
|
goto cleanup;
|
|
|
|
if (nTags == 0) {
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
_("missing tag id - each <vlan> must have "
|
|
"at least one <tag id='n'/> subelement"));
|
|
goto cleanup;
|
|
}
|
|
|
|
if (VIR_ALLOC_N(def->tag, nTags) < 0)
|
|
goto cleanup;
|
|
|
|
def->nativeMode = 0;
|
|
def->nativeTag = 0;
|
|
for (i = 0; i < nTags; i++) {
|
|
unsigned long id;
|
|
|
|
ctxt->node = tagNodes[i];
|
|
if (virXPathULong("string(./@id)", ctxt, &id) < 0) {
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
_("missing or invalid vlan tag id attribute"));
|
|
goto cleanup;
|
|
}
|
|
if (id > 4095) {
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
_("vlan tag id %lu too large (maximum 4095)"), id);
|
|
goto cleanup;
|
|
}
|
|
if ((nativeMode = virXPathString("string(./@nativeMode)", ctxt))) {
|
|
if (def->nativeMode != 0) {
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
_("duplicate native vlan setting"));
|
|
goto cleanup;
|
|
}
|
|
if ((def->nativeMode
|
|
= virNativeVlanModeTypeFromString(nativeMode)) <= 0) {
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
_("Invalid \"nativeMode='%s'\" "
|
|
"in vlan <tag> element"),
|
|
nativeMode);
|
|
goto cleanup;
|
|
}
|
|
VIR_FREE(nativeMode);
|
|
def->nativeTag = id;
|
|
}
|
|
def->tag[i] = id;
|
|
}
|
|
|
|
def->nTags = nTags;
|
|
|
|
/* now that we know how many tags there are, look for an explicit
|
|
* trunk setting.
|
|
*/
|
|
if (nTags > 1)
|
|
def->trunk = true;
|
|
|
|
ctxt->node = node;
|
|
if ((trunk = virXPathString("string(./@trunk)", ctxt)) != NULL) {
|
|
def->trunk = STRCASEEQ(trunk, "yes");
|
|
if (!def->trunk) {
|
|
if (nTags > 1) {
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
_("invalid \"trunk='%s'\" in <vlan> - trunk='yes' "
|
|
"is required for more than one vlan tag"), trunk);
|
|
goto cleanup;
|
|
}
|
|
if (def->nativeMode != 0) {
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
_("invalid configuration in <vlan> - \"trunk='no'\" is "
|
|
"not allowed with a native vlan id"));
|
|
goto cleanup;
|
|
}
|
|
/* allow (but discard) "trunk='no' if there is a single tag */
|
|
if (STRCASENEQ(trunk, "no")) {
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
_("invalid \"trunk='%s'\" in <vlan> "
|
|
"- must be yes or no"), trunk);
|
|
goto cleanup;
|
|
}
|
|
}
|
|
}
|
|
|
|
ret = 0;
|
|
cleanup:
|
|
ctxt->node = save;
|
|
VIR_FREE(tagNodes);
|
|
VIR_FREE(trunk);
|
|
VIR_FREE(nativeMode);
|
|
if (ret < 0)
|
|
virNetDevVlanClear(def);
|
|
return ret;
|
|
}
|
|
|
|
int
|
|
virNetDevVlanFormat(const virNetDevVlan *def, virBufferPtr buf)
|
|
{
|
|
size_t i;
|
|
|
|
if (!(def && def->nTags))
|
|
return 0;
|
|
|
|
if (!def->tag) {
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
_("missing vlan tag data"));
|
|
return -1;
|
|
}
|
|
|
|
virBufferAsprintf(buf, "<vlan%s>\n", def->trunk ? " trunk='yes'" : "");
|
|
virBufferAdjustIndent(buf, 2);
|
|
for (i = 0; i < def->nTags; i++) {
|
|
if (def->nativeMode != VIR_NATIVE_VLAN_MODE_DEFAULT &&
|
|
def->nativeTag == def->tag[i]) {
|
|
/* check the nativeMode in case we get <tag id='0'/>*/
|
|
const char *mode = virNativeVlanModeTypeToString(def->nativeMode);
|
|
if (!mode) {
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
_("Bad value for nativeMode"));
|
|
}
|
|
virBufferAsprintf(buf, "<tag id='%u' nativeMode='%s'/>\n",
|
|
def->tag[i], mode);
|
|
} else {
|
|
virBufferAsprintf(buf, "<tag id='%u'/>\n", def->tag[i]);
|
|
}
|
|
}
|
|
virBufferAdjustIndent(buf, -2);
|
|
virBufferAddLit(buf, "</vlan>\n");
|
|
return 0;
|
|
}
|