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@xxxxxxxxxx> --- src/conf/virnetworkobj.c | 97 ++++++++++++++++++++++++++++++++++++++++++ src/conf/virnetworkobj.h | 26 ++++++++++++ src/libvirt_private.syms | 6 +++ src/network/bridge_driver.c | 101 ++++++++------------------------------------ 4 files changed, 147 insertions(+), 83 deletions(-) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 88e42b5..562fb91 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -107,6 +107,103 @@ 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; +} + + +char * +virNetworkObjMacMgrFileName(const char *dnsmasqStateDir, + const char *bridge) +{ + char *filename; + + ignore_value(virAsprintf(&filename, "%s/%s.macs", dnsmasqStateDir, bridge)); + + return filename; +} + + +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 = virNetworkObjMacMgrFileName(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 = virNetworkObjMacMgrFileName(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) { diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h index 8090c2e..da12848 100644 --- a/src/conf/virnetworkobj.h +++ b/src/conf/virnetworkobj.h @@ -50,6 +50,32 @@ struct _virNetworkObj { virNetworkObjPtr virNetworkObjNew(void); +virMacMapPtr +virNetworkObjGetMacMap(virNetworkObjPtr obj); + +void +virNetworkObjSetMacMap(virNetworkObjPtr obj, + virMacMapPtr macmap); + +void +virNetworkObjUnrefMacMap(virNetworkObjPtr obj); + +char * +virNetworkObjMacMgrFileName(const char *dnsmasqStateDir, + const char *bridge); + +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); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d361454..1907afe 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -931,6 +931,7 @@ virNetworkObjFindByName; virNetworkObjFindByNameLocked; virNetworkObjFindByUUID; virNetworkObjFindByUUIDLocked; +virNetworkObjGetMacMap; virNetworkObjGetPersistentDef; virNetworkObjListExport; virNetworkObjListForEach; @@ -940,12 +941,17 @@ virNetworkObjListNumOfNetworks; virNetworkObjListPrune; virNetworkObjLoadAllConfigs; virNetworkObjLoadAllState; +virNetworkObjMacMgrAdd; +virNetworkObjMacMgrDel; +virNetworkObjMacMgrFileName; virNetworkObjNew; virNetworkObjRemoveInactive; virNetworkObjReplacePersistentDef; virNetworkObjSaveStatus; virNetworkObjSetDefTransient; +virNetworkObjSetMacMap; virNetworkObjTaint; +virNetworkObjUnrefMacMap; virNetworkObjUnsetDefTransient; virNetworkObjUpdate; virNetworkObjUpdateAssignDef; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d888391..d8d3782 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -322,18 +322,6 @@ networkRadvdConfigFileName(virNetworkDriverStatePtr driver, } -static char * -networkMacMgrFileName(virNetworkDriverStatePtr driver, - const char *bridge) -{ - char *filename; - - ignore_value(virAsprintf(&filename, "%s/%s.macs", - driver->dnsmasqStateDir, bridge)); - return filename; -} - - /* do needed cleanup steps and remove the network from the list */ static int networkRemoveInactive(virNetworkDriverStatePtr driver, @@ -375,7 +363,8 @@ networkRemoveInactive(virNetworkDriverStatePtr driver, if (!(statusfile = virNetworkConfigFile(driver->stateDir, def->name))) goto cleanup; - if (!(macMapFile = networkMacMgrFileName(driver, def->bridge))) + if (!(macMapFile = virNetworkObjMacMgrFileName(driver->dnsmasqStateDir, + def->bridge))) goto cleanup; /* dnsmasq */ @@ -412,68 +401,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 = networkMacMgrFileName(driver, 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 = networkMacMgrFileName(driver, 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) { @@ -505,6 +432,7 @@ networkUpdateState(virNetworkObjPtr obj, { virNetworkDriverStatePtr driver = opaque; dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver); + virMacMapPtr macmap; char *macMapFile = NULL; int ret = -1; @@ -523,12 +451,15 @@ networkUpdateState(virNetworkObjPtr obj, if (!(obj->def->bridge && virNetDevExists(obj->def->bridge) == 1)) obj->active = 0; - if (!(macMapFile = networkMacMgrFileName(driver, obj->def->bridge))) + if (!(macMapFile = virNetworkObjMacMgrFileName(driver->dnsmasqStateDir, + 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: @@ -2332,6 +2263,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver, virNetworkIPDefPtr ipdef; virNetDevIPRoutePtr routedef; char *macTapIfName = NULL; + virMacMapPtr macmap; char *macMapFile = NULL; int tapfd = -1; @@ -2380,10 +2312,13 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver, } } - if (!(macMapFile = networkMacMgrFileName(driver, obj->def->bridge)) || - !(obj->macmap = virMacMapNew(macMapFile))) + if (!(macMapFile = virNetworkObjMacMgrFileName(driver->dnsmasqStateDir, + obj->def->bridge)) || + !(macmap = virMacMapNew(macMapFile))) goto err1; + virNetworkObjSetMacMap(obj, macmap); + /* Set bridge options */ /* delay is configured in seconds, but virNetDevBridgeSetSTPDelay @@ -2546,8 +2481,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; @@ -4663,7 +4597,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) @@ -5085,7 +5020,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--; -- 2.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list