mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
network: Move macmap mgmt from bridge_driver to virnetworkobj
In preparation for having a private virNetworkObj - let's create/move some API's that handle the obj->macmap. The API's will be renamed to have a virNetworkObj prefix to follow conventions and the arguments slightly modified to accept what's necessary to complete their task. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
070b6f7f55
commit
f4adeae09d
@ -107,6 +107,91 @@ virNetworkObjEndAPI(virNetworkObjPtr *net)
|
||||
}
|
||||
|
||||
|
||||
virMacMapPtr
|
||||
virNetworkObjGetMacMap(virNetworkObjPtr obj)
|
||||
{
|
||||
return obj->macmap;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virNetworkObjSetMacMap(virNetworkObjPtr obj,
|
||||
virMacMapPtr macmap)
|
||||
{
|
||||
obj->macmap = macmap;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virNetworkObjUnrefMacMap(virNetworkObjPtr obj)
|
||||
{
|
||||
if (!virObjectUnref(obj->macmap))
|
||||
obj->macmap = NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virNetworkObjMacMgrAdd(virNetworkObjPtr obj,
|
||||
const char *dnsmasqStateDir,
|
||||
const char *domain,
|
||||
const virMacAddr *mac)
|
||||
{
|
||||
char macStr[VIR_MAC_STRING_BUFLEN];
|
||||
char *file = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!obj->macmap)
|
||||
return 0;
|
||||
|
||||
virMacAddrFormat(mac, macStr);
|
||||
|
||||
if (!(file = virMacMapFileName(dnsmasqStateDir, obj->def->bridge)))
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapAdd(obj->macmap, domain, macStr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapWriteFile(obj->macmap, file) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virNetworkObjMacMgrDel(virNetworkObjPtr obj,
|
||||
const char *dnsmasqStateDir,
|
||||
const char *domain,
|
||||
const virMacAddr *mac)
|
||||
{
|
||||
char macStr[VIR_MAC_STRING_BUFLEN];
|
||||
char *file = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!obj->macmap)
|
||||
return 0;
|
||||
|
||||
virMacAddrFormat(mac, macStr);
|
||||
|
||||
if (!(file = virMacMapFileName(dnsmasqStateDir, obj->def->bridge)))
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapRemove(obj->macmap, domain, macStr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapWriteFile(obj->macmap, file) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
virNetworkObjListPtr
|
||||
virNetworkObjListNew(void)
|
||||
{
|
||||
|
@ -50,6 +50,28 @@ struct _virNetworkObj {
|
||||
virNetworkObjPtr
|
||||
virNetworkObjNew(void);
|
||||
|
||||
virMacMapPtr
|
||||
virNetworkObjGetMacMap(virNetworkObjPtr obj);
|
||||
|
||||
void
|
||||
virNetworkObjSetMacMap(virNetworkObjPtr obj,
|
||||
virMacMapPtr macmap);
|
||||
|
||||
void
|
||||
virNetworkObjUnrefMacMap(virNetworkObjPtr obj);
|
||||
|
||||
int
|
||||
virNetworkObjMacMgrAdd(virNetworkObjPtr obj,
|
||||
const char *dnsmasqStateDir,
|
||||
const char *domain,
|
||||
const virMacAddr *mac);
|
||||
|
||||
int
|
||||
virNetworkObjMacMgrDel(virNetworkObjPtr obj,
|
||||
const char *dnsmasqStateDir,
|
||||
const char *domain,
|
||||
const virMacAddr *mac);
|
||||
|
||||
void
|
||||
virNetworkObjEndAPI(virNetworkObjPtr *net);
|
||||
|
||||
|
@ -942,6 +942,7 @@ virNetworkObjDeleteConfig;
|
||||
virNetworkObjEndAPI;
|
||||
virNetworkObjFindByName;
|
||||
virNetworkObjFindByUUID;
|
||||
virNetworkObjGetMacMap;
|
||||
virNetworkObjGetPersistentDef;
|
||||
virNetworkObjListExport;
|
||||
virNetworkObjListForEach;
|
||||
@ -951,12 +952,16 @@ virNetworkObjListNumOfNetworks;
|
||||
virNetworkObjListPrune;
|
||||
virNetworkObjLoadAllConfigs;
|
||||
virNetworkObjLoadAllState;
|
||||
virNetworkObjMacMgrAdd;
|
||||
virNetworkObjMacMgrDel;
|
||||
virNetworkObjNew;
|
||||
virNetworkObjRemoveInactive;
|
||||
virNetworkObjReplacePersistentDef;
|
||||
virNetworkObjSaveStatus;
|
||||
virNetworkObjSetDefTransient;
|
||||
virNetworkObjSetMacMap;
|
||||
virNetworkObjTaint;
|
||||
virNetworkObjUnrefMacMap;
|
||||
virNetworkObjUnsetDefTransient;
|
||||
virNetworkObjUpdate;
|
||||
virNetworkObjUpdateAssignDef;
|
||||
|
@ -400,68 +400,6 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
networkMacMgrAdd(virNetworkDriverStatePtr driver,
|
||||
virNetworkObjPtr obj,
|
||||
const char *domain,
|
||||
const virMacAddr *mac)
|
||||
{
|
||||
char macStr[VIR_MAC_STRING_BUFLEN];
|
||||
char *file = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!obj->macmap)
|
||||
return 0;
|
||||
|
||||
virMacAddrFormat(mac, macStr);
|
||||
|
||||
if (!(file = virMacMapFileName(driver->dnsmasqStateDir, obj->def->bridge)))
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapAdd(obj->macmap, domain, macStr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapWriteFile(obj->macmap, file) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
networkMacMgrDel(virNetworkDriverStatePtr driver,
|
||||
virNetworkObjPtr obj,
|
||||
const char *domain,
|
||||
const virMacAddr *mac)
|
||||
{
|
||||
char macStr[VIR_MAC_STRING_BUFLEN];
|
||||
char *file = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!obj->macmap)
|
||||
return 0;
|
||||
|
||||
virMacAddrFormat(mac, macStr);
|
||||
|
||||
if (!(file = virMacMapFileName(driver->dnsmasqStateDir, obj->def->bridge)))
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapRemove(obj->macmap, domain, macStr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virMacMapWriteFile(obj->macmap, file) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
networkBridgeDummyNicName(const char *brname)
|
||||
{
|
||||
@ -493,6 +431,7 @@ networkUpdateState(virNetworkObjPtr obj,
|
||||
{
|
||||
virNetworkDriverStatePtr driver = opaque;
|
||||
dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
|
||||
virMacMapPtr macmap;
|
||||
char *macMapFile = NULL;
|
||||
int ret = -1;
|
||||
|
||||
@ -515,9 +454,11 @@ networkUpdateState(virNetworkObjPtr obj,
|
||||
obj->def->bridge)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(obj->macmap = virMacMapNew(macMapFile)))
|
||||
if (!(macmap = virMacMapNew(macMapFile)))
|
||||
goto cleanup;
|
||||
|
||||
virNetworkObjSetMacMap(obj, macmap);
|
||||
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
@ -2321,6 +2262,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
|
||||
virNetworkIPDefPtr ipdef;
|
||||
virNetDevIPRoutePtr routedef;
|
||||
char *macTapIfName = NULL;
|
||||
virMacMapPtr macmap;
|
||||
char *macMapFile = NULL;
|
||||
int tapfd = -1;
|
||||
|
||||
@ -2371,9 +2313,11 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
|
||||
|
||||
if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
|
||||
obj->def->bridge)) ||
|
||||
!(obj->macmap = virMacMapNew(macMapFile)))
|
||||
!(macmap = virMacMapNew(macMapFile)))
|
||||
goto err1;
|
||||
|
||||
virNetworkObjSetMacMap(obj, macmap);
|
||||
|
||||
/* Set bridge options */
|
||||
|
||||
/* delay is configured in seconds, but virNetDevBridgeSetSTPDelay
|
||||
@ -2536,8 +2480,7 @@ networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver,
|
||||
if (obj->def->bandwidth)
|
||||
virNetDevBandwidthClear(obj->def->bridge);
|
||||
|
||||
if (!virObjectUnref(obj->macmap))
|
||||
obj->macmap = NULL;
|
||||
virNetworkObjUnrefMacMap(obj);
|
||||
|
||||
if (obj->radvdPid > 0) {
|
||||
char *radvdpidbase;
|
||||
@ -4653,7 +4596,8 @@ networkAllocateActualDevice(virDomainDefPtr dom,
|
||||
}
|
||||
}
|
||||
|
||||
if (networkMacMgrAdd(driver, obj, dom->name, &iface->mac) < 0)
|
||||
if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir,
|
||||
dom->name, &iface->mac) < 0)
|
||||
goto error;
|
||||
|
||||
if (virNetDevVPortProfileCheckComplete(virtport, true) < 0)
|
||||
@ -5075,7 +5019,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
|
||||
}
|
||||
|
||||
success:
|
||||
networkMacMgrDel(driver, obj, dom->name, &iface->mac);
|
||||
virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &iface->mac);
|
||||
|
||||
if (iface->data.network.actual) {
|
||||
netdef->connections--;
|
||||
|
Loading…
Reference in New Issue
Block a user