mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +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
|
virNetworkObjListPtr
|
||||||
virNetworkObjListNew(void)
|
virNetworkObjListNew(void)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,28 @@ struct _virNetworkObj {
|
|||||||
virNetworkObjPtr
|
virNetworkObjPtr
|
||||||
virNetworkObjNew(void);
|
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
|
void
|
||||||
virNetworkObjEndAPI(virNetworkObjPtr *net);
|
virNetworkObjEndAPI(virNetworkObjPtr *net);
|
||||||
|
|
||||||
|
@ -942,6 +942,7 @@ virNetworkObjDeleteConfig;
|
|||||||
virNetworkObjEndAPI;
|
virNetworkObjEndAPI;
|
||||||
virNetworkObjFindByName;
|
virNetworkObjFindByName;
|
||||||
virNetworkObjFindByUUID;
|
virNetworkObjFindByUUID;
|
||||||
|
virNetworkObjGetMacMap;
|
||||||
virNetworkObjGetPersistentDef;
|
virNetworkObjGetPersistentDef;
|
||||||
virNetworkObjListExport;
|
virNetworkObjListExport;
|
||||||
virNetworkObjListForEach;
|
virNetworkObjListForEach;
|
||||||
@ -951,12 +952,16 @@ virNetworkObjListNumOfNetworks;
|
|||||||
virNetworkObjListPrune;
|
virNetworkObjListPrune;
|
||||||
virNetworkObjLoadAllConfigs;
|
virNetworkObjLoadAllConfigs;
|
||||||
virNetworkObjLoadAllState;
|
virNetworkObjLoadAllState;
|
||||||
|
virNetworkObjMacMgrAdd;
|
||||||
|
virNetworkObjMacMgrDel;
|
||||||
virNetworkObjNew;
|
virNetworkObjNew;
|
||||||
virNetworkObjRemoveInactive;
|
virNetworkObjRemoveInactive;
|
||||||
virNetworkObjReplacePersistentDef;
|
virNetworkObjReplacePersistentDef;
|
||||||
virNetworkObjSaveStatus;
|
virNetworkObjSaveStatus;
|
||||||
virNetworkObjSetDefTransient;
|
virNetworkObjSetDefTransient;
|
||||||
|
virNetworkObjSetMacMap;
|
||||||
virNetworkObjTaint;
|
virNetworkObjTaint;
|
||||||
|
virNetworkObjUnrefMacMap;
|
||||||
virNetworkObjUnsetDefTransient;
|
virNetworkObjUnsetDefTransient;
|
||||||
virNetworkObjUpdate;
|
virNetworkObjUpdate;
|
||||||
virNetworkObjUpdateAssignDef;
|
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 *
|
static char *
|
||||||
networkBridgeDummyNicName(const char *brname)
|
networkBridgeDummyNicName(const char *brname)
|
||||||
{
|
{
|
||||||
@ -493,6 +431,7 @@ networkUpdateState(virNetworkObjPtr obj,
|
|||||||
{
|
{
|
||||||
virNetworkDriverStatePtr driver = opaque;
|
virNetworkDriverStatePtr driver = opaque;
|
||||||
dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
|
dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
|
||||||
|
virMacMapPtr macmap;
|
||||||
char *macMapFile = NULL;
|
char *macMapFile = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -515,9 +454,11 @@ networkUpdateState(virNetworkObjPtr obj,
|
|||||||
obj->def->bridge)))
|
obj->def->bridge)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(obj->macmap = virMacMapNew(macMapFile)))
|
if (!(macmap = virMacMapNew(macMapFile)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
virNetworkObjSetMacMap(obj, macmap);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||||
@ -2321,6 +2262,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
|
|||||||
virNetworkIPDefPtr ipdef;
|
virNetworkIPDefPtr ipdef;
|
||||||
virNetDevIPRoutePtr routedef;
|
virNetDevIPRoutePtr routedef;
|
||||||
char *macTapIfName = NULL;
|
char *macTapIfName = NULL;
|
||||||
|
virMacMapPtr macmap;
|
||||||
char *macMapFile = NULL;
|
char *macMapFile = NULL;
|
||||||
int tapfd = -1;
|
int tapfd = -1;
|
||||||
|
|
||||||
@ -2371,9 +2313,11 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
|
|||||||
|
|
||||||
if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
|
if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
|
||||||
obj->def->bridge)) ||
|
obj->def->bridge)) ||
|
||||||
!(obj->macmap = virMacMapNew(macMapFile)))
|
!(macmap = virMacMapNew(macMapFile)))
|
||||||
goto err1;
|
goto err1;
|
||||||
|
|
||||||
|
virNetworkObjSetMacMap(obj, macmap);
|
||||||
|
|
||||||
/* Set bridge options */
|
/* Set bridge options */
|
||||||
|
|
||||||
/* delay is configured in seconds, but virNetDevBridgeSetSTPDelay
|
/* delay is configured in seconds, but virNetDevBridgeSetSTPDelay
|
||||||
@ -2536,8 +2480,7 @@ networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver,
|
|||||||
if (obj->def->bandwidth)
|
if (obj->def->bandwidth)
|
||||||
virNetDevBandwidthClear(obj->def->bridge);
|
virNetDevBandwidthClear(obj->def->bridge);
|
||||||
|
|
||||||
if (!virObjectUnref(obj->macmap))
|
virNetworkObjUnrefMacMap(obj);
|
||||||
obj->macmap = NULL;
|
|
||||||
|
|
||||||
if (obj->radvdPid > 0) {
|
if (obj->radvdPid > 0) {
|
||||||
char *radvdpidbase;
|
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;
|
goto error;
|
||||||
|
|
||||||
if (virNetDevVPortProfileCheckComplete(virtport, true) < 0)
|
if (virNetDevVPortProfileCheckComplete(virtport, true) < 0)
|
||||||
@ -5075,7 +5019,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
networkMacMgrDel(driver, obj, dom->name, &iface->mac);
|
virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &iface->mac);
|
||||||
|
|
||||||
if (iface->data.network.actual) {
|
if (iface->data.network.actual) {
|
||||||
netdef->connections--;
|
netdef->connections--;
|
||||||
|
Loading…
Reference in New Issue
Block a user