~ubuntu-branches/ubuntu/natty/libvirt/natty-security

« back to all changes in this revision

Viewing changes to src/conf/nwfilter_conf.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-02-23 09:05:46 UTC
  • mfrom: (1.2.8 upstream) (3.4.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110223090546-4pwmrrt7h51hr3l3
Tags: 0.8.8-1ubuntu1
* Resynchronize and merge from Debian unstable. Remaining changes:
  - debian/patches:
    * 9000-delayed_iff_up_bridge.patch
    * 9001-dont_clobber_existing_bridges.patch
    * 9002-better_default_uri_virsh.patch
    * 9003-better-default-arch.patch
    * 9004-libvirtd-group-name.patch
    * 9005-increase-unix-socket-timeout.patch
    * 9006-default-config-test-case.patch
    * 9007-fix-daemon-conf-ftbfs.patch
    * 9011-move-ebtables-script.patch
    * 9014-skip-nodeinfotest.patch
    * 9020-lp545795.patch
    * 9021-fix-uint64_t.patch
  - debian/patches/series:
    * Disable qemu-disable-network.diff.patch
  - debian/control:
    * set ubuntu maintainer
    * Build-Depends:
      - swap libxen to libxen3, qemu to qemu-kvm, and open-iscsi to
        open-iscsi-utils in Build-Depends
      - remove virtualbox Build-Depends
      - add libxml2 and libapparmor-dev Build-Depends
    * convert Vcs-Git to Xs-Debian-Vcs-Git
    * libvirt-bin Depends: move netcat-openbsd, bridge-utils, dnsmasq-base
      (>= 2.46-1), and iptables from Recommends to Depends
    * libvirt-bin Recommends: move qemu to Suggests
    * libvirt-bin Suggests: add apparmor
    * libvirt0 Recommands: move lvm2 to Suggests
  - keep debian/libvirt-bin.apport
  - keep debian/libvirt-bin.cron.daily
  - debian/libvirt-bin.dirs:
    * add apparmor, cron.daily, and apport dirs
  - debian/libvirt-bin.examples:
    * add debian/libvirt-suspendonreboot
  - debian/libvirt-bin.install:
    * add /etc/apparmor.d files
    * add apport hook
  - debian/libvirt-bin.manpages:
    * add debian/libvirt-migrate-qemu-disks.1
  - debian/libvirt-bin.postinst:
    * replace libvirt groupname with libvirtd
    * add each admin user to libvirtd group
    * call apparmor_parser on usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
    * call 'libvirt-migrate-qemu-disks -a' after
      libvirt-bin has started if migrating from
      older than 0.8.3-1ubuntu1
  - debian/libvirt-bin.postrm:
    * replace libvirt groupname with libvirtd
    * remove usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
  - keep added files under debian/:
    * libvirt-bin.upstart
    * libvirt-migrate-qemu-disks
    * libvirt-migrate-qemu-disks.1
    * libvirt-suspendonreboot
    * apparmor profiles
  - debian/README.Debian:
    * add 'Apparmor Profile' section
    * add 'Disk migration' section
  - debian/rules:
    * don't build with vbox since virtualbox-ose is in universe
    * add --with-apparmor to DEB_CONFIGURE_EXTRA_FLAGS
    * set DEB_DH_INSTALLINIT_ARGS to '--upstart-only'
    * set DEB_MAKE_CHECK_TARGET to 'check'
    * remove unneeded binary-install/libvirt-bin:: and clean::
      sections (they only deal with sysvinit stuff)
    * add build/libvirt-bin:: section to install
      - apparmor files
      - apport hooks
      - libvirt-migrate-qemu-disks
* The following Ubuntu packaging changes occurred during the divergence
  between Debian and Ubuntu. These changes are not new, but included here
  for completeness: (0.8.5-0ubuntu1 - 0.8.5-0ubuntu5):
  - Have upstart job source /etc/default/libvirt-bin.  This is only a
    temporary fix until upstart provides proper default override support
    through /etc/init/libvirt-bin.override (or any other mechanism).
    (LP: 708172)
  - debian/apparmor/usr.sbin.libvirtd: use PUx instead of Ux for executables
    (LP: 573315)
  - Rebuild with python 2.7 as the python default.
  - debian/libvirt-bin.cron.daily: use shell globbing to enumerate xml files.
    Based on patch thanks to Henryk Plötz (LP: 655176)
* Dropped the following patches included/fixed upstream:
  - 9010-dont-disable-ipv6.patch
  - 9022-build-cleanup-declaration-of-xen-tests.patch
  - 9023-vah-require-uuid.patch
  - 9009-autodetect-nc-params.patch
    * rolled into Debian's
      Autodetect-if-the-remote-nc-command-supports-the-q-o.patch
* Updated the following patches:
  - 9011-move-ebtables-script.patch:
    * LOCALSTATEDIR is defined in configmake.h
  - 9000-9006: added DEP-3 tags
  - 9002-better_default_uri_virsh.patch: updated (context changed)
* New patches:
  - 9022-drop-booton-when-kernel-specified.patch (LP: #720426)
  - 9023-fix-lxc-console-hangup.patch (LP: #668369)
  - 9024-skip-broken-commandtest.patch
* debian/patches/series:
  - don't apply Disable-CHECKSUM-rule.patch: our iptables can do this
  - don't apply Debian-specific Debianize-libvirt-guests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
299
299
 
300
300
 
301
301
void
302
 
virNWFilterPoolObjFree(virNWFilterPoolObjPtr obj) {
 
302
virNWFilterObjFree(virNWFilterObjPtr obj)
 
303
{
303
304
    if (!obj)
304
305
        return;
305
306
 
315
316
 
316
317
 
317
318
void
318
 
virNWFilterPoolObjListFree(virNWFilterPoolObjListPtr pools)
 
319
virNWFilterObjListFree(virNWFilterObjListPtr nwfilters)
319
320
{
320
321
    unsigned int i;
321
 
    for (i = 0 ; i < pools->count ; i++)
322
 
        virNWFilterPoolObjFree(pools->objs[i]);
323
 
    VIR_FREE(pools->objs);
324
 
    pools->count = 0;
 
322
    for (i = 0 ; i < nwfilters->count ; i++)
 
323
        virNWFilterObjFree(nwfilters->objs[i]);
 
324
    VIR_FREE(nwfilters->objs);
 
325
    nwfilters->count = 0;
325
326
}
326
327
 
327
328
 
382
383
 
383
384
 
384
385
void
385
 
virNWFilterPoolObjRemove(virNWFilterPoolObjListPtr pools,
386
 
                         virNWFilterPoolObjPtr pool)
 
386
virNWFilterObjRemove(virNWFilterObjListPtr nwfilters,
 
387
                     virNWFilterObjPtr nwfilter)
387
388
{
388
389
    unsigned int i;
389
390
 
390
 
    virNWFilterPoolObjUnlock(pool);
391
 
 
392
 
    for (i = 0 ; i < pools->count ; i++) {
393
 
        virNWFilterPoolObjLock(pools->objs[i]);
394
 
        if (pools->objs[i] == pool) {
395
 
            virNWFilterPoolObjUnlock(pools->objs[i]);
396
 
            virNWFilterPoolObjFree(pools->objs[i]);
397
 
 
398
 
            if (i < (pools->count - 1))
399
 
                memmove(pools->objs + i, pools->objs + i + 1,
400
 
                        sizeof(*(pools->objs)) * (pools->count - (i + 1)));
401
 
 
402
 
            if (VIR_REALLOC_N(pools->objs, pools->count - 1) < 0) {
 
391
    virNWFilterObjUnlock(nwfilter);
 
392
 
 
393
    for (i = 0 ; i < nwfilters->count ; i++) {
 
394
        virNWFilterObjLock(nwfilters->objs[i]);
 
395
        if (nwfilters->objs[i] == nwfilter) {
 
396
            virNWFilterObjUnlock(nwfilters->objs[i]);
 
397
            virNWFilterObjFree(nwfilters->objs[i]);
 
398
 
 
399
            if (i < (nwfilters->count - 1))
 
400
                memmove(nwfilters->objs + i, nwfilters->objs + i + 1,
 
401
                        sizeof(*(nwfilters->objs)) * (nwfilters->count - (i + 1)));
 
402
 
 
403
            if (VIR_REALLOC_N(nwfilters->objs, nwfilters->count - 1) < 0) {
403
404
                ; /* Failure to reduce memory allocation isn't fatal */
404
405
            }
405
 
            pools->count--;
 
406
            nwfilters->count--;
406
407
 
407
408
            break;
408
409
        }
409
 
        virNWFilterPoolObjUnlock(pools->objs[i]);
 
410
        virNWFilterObjUnlock(nwfilters->objs[i]);
410
411
    }
411
412
}
412
413
 
427
428
typedef struct _virXMLAttr2Struct virXMLAttr2Struct;
428
429
struct _virXMLAttr2Struct
429
430
{
430
 
    const char *name;           // attribute name
 
431
    const char *name;           /* attribute name */
431
432
    enum attrDatatype datatype;
432
 
    int dataIdx;                // offset of the hasXYZ boolean
433
 
    valueValidator validator;   // beyond-standard checkers
434
 
    valueFormatter formatter;   // beyond-standard formatter
 
433
    int dataIdx;                /* offset of the hasXYZ boolean */
 
434
    valueValidator validator;   /* beyond-standard checkers */
 
435
    valueFormatter formatter;   /* beyond-standard formatter */
435
436
    size_t maxstrlen;
436
437
};
437
438
 
1493
1494
 
1494
1495
                        case DATATYPE_STRING:
1495
1496
                            if (!validator) {
1496
 
                                // not supported
 
1497
                                /* not supported */
1497
1498
                                rc = -1;
1498
1499
                                break;
1499
1500
                            }
1998
1999
    if (STRNEQ((const char *)root->name, "filter")) {
1999
2000
        virNWFilterReportError(VIR_ERR_XML_ERROR,
2000
2001
                               "%s",
2001
 
                               _("unknown root element for nw filter pool"));
 
2002
                               _("unknown root element for nw filter"));
2002
2003
        goto cleanup;
2003
2004
    }
2004
2005
 
2089
2090
}
2090
2091
 
2091
2092
 
2092
 
virNWFilterPoolObjPtr
2093
 
virNWFilterPoolObjFindByUUID(virNWFilterPoolObjListPtr pools,
2094
 
                             const unsigned char *uuid)
 
2093
virNWFilterObjPtr
 
2094
virNWFilterObjFindByUUID(virNWFilterObjListPtr nwfilters,
 
2095
                         const unsigned char *uuid)
2095
2096
{
2096
2097
    unsigned int i;
2097
2098
 
2098
 
    for (i = 0 ; i < pools->count ; i++) {
2099
 
        virNWFilterPoolObjLock(pools->objs[i]);
2100
 
        if (!memcmp(pools->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
2101
 
            return pools->objs[i];
2102
 
        virNWFilterPoolObjUnlock(pools->objs[i]);
 
2099
    for (i = 0 ; i < nwfilters->count ; i++) {
 
2100
        virNWFilterObjLock(nwfilters->objs[i]);
 
2101
        if (!memcmp(nwfilters->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
 
2102
            return nwfilters->objs[i];
 
2103
        virNWFilterObjUnlock(nwfilters->objs[i]);
2103
2104
    }
2104
2105
 
2105
2106
    return NULL;
2106
2107
}
2107
2108
 
2108
2109
 
2109
 
virNWFilterPoolObjPtr
2110
 
virNWFilterPoolObjFindByName(virNWFilterPoolObjListPtr pools,
2111
 
                             const char *name)
 
2110
virNWFilterObjPtr
 
2111
virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters, const char *name)
2112
2112
{
2113
2113
    unsigned int i;
2114
2114
 
2115
 
    for (i = 0 ; i < pools->count ; i++) {
2116
 
        virNWFilterPoolObjLock(pools->objs[i]);
2117
 
        if (STREQ(pools->objs[i]->def->name, name))
2118
 
            return pools->objs[i];
2119
 
        virNWFilterPoolObjUnlock(pools->objs[i]);
 
2115
    for (i = 0 ; i < nwfilters->count ; i++) {
 
2116
        virNWFilterObjLock(nwfilters->objs[i]);
 
2117
        if (STREQ(nwfilters->objs[i]->def->name, name))
 
2118
            return nwfilters->objs[i];
 
2119
        virNWFilterObjUnlock(nwfilters->objs[i]);
2120
2120
    }
2121
2121
 
2122
2122
    return NULL;
2197
2197
 
2198
2198
static int
2199
2199
_virNWFilterDefLoopDetect(virConnectPtr conn,
2200
 
                          virNWFilterPoolObjListPtr pools,
 
2200
                          virNWFilterObjListPtr nwfilters,
2201
2201
                          virNWFilterDefPtr def,
2202
2202
                          const char *filtername)
2203
2203
{
2204
2204
    int rc = 0;
2205
2205
    int i;
2206
2206
    virNWFilterEntryPtr entry;
2207
 
    virNWFilterPoolObjPtr obj;
 
2207
    virNWFilterObjPtr obj;
2208
2208
 
2209
2209
    if (!def)
2210
2210
        return 0;
2218
2218
                break;
2219
2219
            }
2220
2220
 
2221
 
            obj = virNWFilterPoolObjFindByName(pools,
2222
 
                                               entry->include->filterref);
 
2221
            obj = virNWFilterObjFindByName(nwfilters,
 
2222
                                           entry->include->filterref);
2223
2223
            if (obj) {
2224
 
                rc = _virNWFilterDefLoopDetect(conn,
2225
 
                                               pools,
 
2224
                rc = _virNWFilterDefLoopDetect(conn, nwfilters,
2226
2225
                                               obj->def, filtername);
2227
2226
 
2228
 
                virNWFilterPoolObjUnlock(obj);
 
2227
                virNWFilterObjUnlock(obj);
2229
2228
                if (rc)
2230
2229
                   break;
2231
2230
            }
2239
2238
/*
2240
2239
 * virNWFilterDefLoopDetect:
2241
2240
 * @conn: pointer to virConnect object
2242
 
 * @pools : the pools to search
 
2241
 * @nwfilters : the nwfilters to search
2243
2242
 * @def : the filter definiton that may add a loop and is to be tested
2244
2243
 *
2245
2244
 * Detect a loop introduced through the filters being able to
2249
2248
 */
2250
2249
static int
2251
2250
virNWFilterDefLoopDetect(virConnectPtr conn,
2252
 
                         virNWFilterPoolObjListPtr pools,
 
2251
                         virNWFilterObjListPtr nwfilters,
2253
2252
                         virNWFilterDefPtr def)
2254
2253
{
2255
 
    return _virNWFilterDefLoopDetect(conn, pools, def, def->name);
 
2254
    return _virNWFilterDefLoopDetect(conn, nwfilters, def, def->name);
2256
2255
}
2257
2256
 
2258
2257
int nCallbackDriver;
2315
2314
    err = cb.err;
2316
2315
 
2317
2316
    if (err) {
2318
 
        cb.step = STEP_TEAR_NEW; // rollback
 
2317
        cb.step = STEP_TEAR_NEW; /* rollback */
2319
2318
        cb.err = 0;
2320
2319
 
2321
2320
        for (i = 0; i < nCallbackDriver; i++)
2323
2322
                                                 virNWFilterDomainFWUpdateCB,
2324
2323
                                                 &cb);
2325
2324
    } else {
2326
 
        cb.step = STEP_TEAR_OLD; // switch over
 
2325
        cb.step = STEP_TEAR_OLD; /* switch over */
2327
2326
 
2328
2327
        for (i = 0; i < nCallbackDriver; i++)
2329
2328
            callbackDrvArray[i]->vmFilterRebuild(conn,
2339
2338
 
2340
2339
int
2341
2340
virNWFilterTestUnassignDef(virConnectPtr conn,
2342
 
                           virNWFilterPoolObjPtr pool)
 
2341
                           virNWFilterObjPtr nwfilter)
2343
2342
{
2344
2343
    int rc = 0;
2345
2344
 
2346
2345
    virNWFilterLockFilterUpdates();
2347
2346
 
2348
 
    pool->wantRemoved = 1;
2349
 
    // trigger the update on VMs referencing the filter
 
2347
    nwfilter->wantRemoved = 1;
 
2348
    /* trigger the update on VMs referencing the filter */
2350
2349
    if (virNWFilterTriggerVMFilterRebuild(conn))
2351
2350
        rc = 1;
2352
2351
 
2353
 
    pool->wantRemoved = 0;
 
2352
    nwfilter->wantRemoved = 0;
2354
2353
    virNWFilterUnlockFilterUpdates();
2355
2354
    return rc;
2356
2355
}
2357
2356
 
2358
2357
 
2359
 
virNWFilterPoolObjPtr
2360
 
virNWFilterPoolObjAssignDef(virConnectPtr conn,
2361
 
                            virNWFilterPoolObjListPtr pools,
2362
 
                            virNWFilterDefPtr def)
 
2358
virNWFilterObjPtr
 
2359
virNWFilterObjAssignDef(virConnectPtr conn,
 
2360
                        virNWFilterObjListPtr nwfilters,
 
2361
                        virNWFilterDefPtr def)
2363
2362
{
2364
 
    virNWFilterPoolObjPtr pool;
2365
 
 
2366
 
    pool = virNWFilterPoolObjFindByUUID(pools, def->uuid);
2367
 
 
2368
 
    if (pool) {
2369
 
        if (!STREQ(def->name, pool->def->name)) {
2370
 
            virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
2371
 
                               _("filter with same UUID but different name "
2372
 
                                 "('%s') already exists"),
2373
 
                               pool->def->name);
2374
 
            virNWFilterPoolObjUnlock(pool);
 
2363
    virNWFilterObjPtr nwfilter;
 
2364
 
 
2365
    nwfilter = virNWFilterObjFindByUUID(nwfilters, def->uuid);
 
2366
 
 
2367
    if (nwfilter) {
 
2368
        if (!STREQ(def->name, nwfilter->def->name)) {
 
2369
            virNWFilterReportError(VIR_ERR_OPERATION_FAILED,
 
2370
                                   _("filter with same UUID but different name "
 
2371
                                     "('%s') already exists"),
 
2372
                                   nwfilter->def->name);
 
2373
            virNWFilterObjUnlock(nwfilter);
2375
2374
            return NULL;
2376
2375
        }
2377
 
        virNWFilterPoolObjUnlock(pool);
 
2376
        virNWFilterObjUnlock(nwfilter);
2378
2377
    }
2379
2378
 
2380
 
    if (virNWFilterDefLoopDetect(conn, pools, def)) {
2381
 
        virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
 
2379
    if (virNWFilterDefLoopDetect(conn, nwfilters, def)) {
 
2380
        virNWFilterReportError(VIR_ERR_OPERATION_FAILED,
2382
2381
                              "%s", _("filter would introduce a loop"));
2383
2382
        return NULL;
2384
2383
    }
2385
2384
 
2386
 
    if ((pool = virNWFilterPoolObjFindByName(pools, def->name))) {
 
2385
    if ((nwfilter = virNWFilterObjFindByName(nwfilters, def->name))) {
2387
2386
        virNWFilterLockFilterUpdates();
2388
 
        pool->newDef = def;
2389
 
        // trigger the update on VMs referencing the filter
 
2387
        nwfilter->newDef = def;
 
2388
        /* trigger the update on VMs referencing the filter */
2390
2389
        if (virNWFilterTriggerVMFilterRebuild(conn)) {
2391
 
            pool->newDef = NULL;
 
2390
            nwfilter->newDef = NULL;
2392
2391
            virNWFilterUnlockFilterUpdates();
2393
 
            virNWFilterPoolObjUnlock(pool);
 
2392
            virNWFilterObjUnlock(nwfilter);
2394
2393
            return NULL;
2395
2394
        }
2396
2395
 
2397
 
        virNWFilterDefFree(pool->def);
2398
 
        pool->def = def;
2399
 
        pool->newDef = NULL;
 
2396
        virNWFilterDefFree(nwfilter->def);
 
2397
        nwfilter->def = def;
 
2398
        nwfilter->newDef = NULL;
2400
2399
        virNWFilterUnlockFilterUpdates();
2401
 
        return pool;
 
2400
        return nwfilter;
2402
2401
    }
2403
2402
 
2404
 
    if (VIR_ALLOC(pool) < 0) {
 
2403
    if (VIR_ALLOC(nwfilter) < 0) {
2405
2404
        virReportOOMError();
2406
2405
        return NULL;
2407
2406
    }
2408
2407
 
2409
 
    if (virMutexInitRecursive(&pool->lock) < 0) {
 
2408
    if (virMutexInitRecursive(&nwfilter->lock) < 0) {
2410
2409
        virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
2411
2410
                              "%s", _("cannot initialize mutex"));
2412
 
        VIR_FREE(pool);
 
2411
        VIR_FREE(nwfilter);
2413
2412
        return NULL;
2414
2413
    }
2415
 
    virNWFilterPoolObjLock(pool);
2416
 
    pool->active = 0;
2417
 
    pool->def = def;
 
2414
    virNWFilterObjLock(nwfilter);
 
2415
    nwfilter->active = 0;
 
2416
    nwfilter->def = def;
2418
2417
 
2419
 
    if (VIR_REALLOC_N(pools->objs, pools->count+1) < 0) {
2420
 
        pool->def = NULL;
2421
 
        virNWFilterPoolObjUnlock(pool);
2422
 
        virNWFilterPoolObjFree(pool);
 
2418
    if (VIR_REALLOC_N(nwfilters->objs, nwfilters->count + 1) < 0) {
 
2419
        nwfilter->def = NULL;
 
2420
        virNWFilterObjUnlock(nwfilter);
 
2421
        virNWFilterObjFree(nwfilter);
2423
2422
        virReportOOMError();
2424
2423
        return NULL;
2425
2424
    }
2426
 
    pools->objs[pools->count++] = pool;
 
2425
    nwfilters->objs[nwfilters->count++] = nwfilter;
2427
2426
 
2428
 
    return pool;
 
2427
    return nwfilter;
2429
2428
}
2430
2429
 
2431
2430
 
2432
 
static virNWFilterPoolObjPtr
2433
 
virNWFilterPoolObjLoad(virConnectPtr conn,
2434
 
                       virNWFilterPoolObjListPtr pools,
2435
 
                       const char *file,
2436
 
                       const char *path)
 
2431
static virNWFilterObjPtr
 
2432
virNWFilterObjLoad(virConnectPtr conn,
 
2433
                   virNWFilterObjListPtr nwfilters,
 
2434
                   const char *file,
 
2435
                   const char *path)
2437
2436
{
2438
2437
    virNWFilterDefPtr def;
2439
 
    virNWFilterPoolObjPtr pool;
 
2438
    virNWFilterObjPtr nwfilter;
2440
2439
 
2441
2440
    if (!(def = virNWFilterDefParseFile(conn, path))) {
2442
2441
        return NULL;
2443
2442
    }
2444
2443
 
2445
2444
    if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
2446
 
        virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
2447
 
            _("network filter pool config filename '%s' does not match pool name '%s'"),
 
2445
        virNWFilterReportError(VIR_ERR_XML_ERROR,
 
2446
            _("network filter config filename '%s' does not match name '%s'"),
2448
2447
            path, def->name);
2449
2448
        virNWFilterDefFree(def);
2450
2449
        return NULL;
2451
2450
    }
2452
2451
 
2453
 
    if (!(pool = virNWFilterPoolObjAssignDef(conn, pools, def))) {
 
2452
    if (!(nwfilter = virNWFilterObjAssignDef(conn, nwfilters, def))) {
2454
2453
        virNWFilterDefFree(def);
2455
2454
        return NULL;
2456
2455
    }
2457
2456
 
2458
 
    VIR_FREE(pool->configFile); // for driver reload
2459
 
    pool->configFile = strdup(path);
2460
 
    if (pool->configFile == NULL) {
 
2457
    VIR_FREE(nwfilter->configFile); /* for driver reload */
 
2458
    nwfilter->configFile = strdup(path);
 
2459
    if (nwfilter->configFile == NULL) {
2461
2460
        virReportOOMError();
2462
2461
        virNWFilterDefFree(def);
2463
2462
        return NULL;
2464
2463
    }
2465
2464
 
2466
 
    return pool;
 
2465
    return nwfilter;
2467
2466
}
2468
2467
 
2469
2468
 
2470
2469
int
2471
 
virNWFilterPoolLoadAllConfigs(virConnectPtr conn,
2472
 
                              virNWFilterPoolObjListPtr pools,
2473
 
                              const char *configDir)
 
2470
virNWFilterLoadAllConfigs(virConnectPtr conn,
 
2471
                          virNWFilterObjListPtr nwfilters,
 
2472
                          const char *configDir)
2474
2473
{
2475
2474
    DIR *dir;
2476
2475
    struct dirent *entry;
2486
2485
 
2487
2486
    while ((entry = readdir(dir))) {
2488
2487
        char path[PATH_MAX];
2489
 
        virNWFilterPoolObjPtr pool;
 
2488
        virNWFilterObjPtr nwfilter;
2490
2489
 
2491
2490
        if (entry->d_name[0] == '.')
2492
2491
            continue;
2502
2501
            continue;
2503
2502
        }
2504
2503
 
2505
 
        pool = virNWFilterPoolObjLoad(conn, pools, entry->d_name, path);
2506
 
        if (pool)
2507
 
            virNWFilterPoolObjUnlock(pool);
 
2504
        nwfilter = virNWFilterObjLoad(conn, nwfilters, entry->d_name, path);
 
2505
        if (nwfilter)
 
2506
            virNWFilterObjUnlock(nwfilter);
2508
2507
    }
2509
2508
 
2510
2509
    closedir(dir);
2514
2513
 
2515
2514
 
2516
2515
int
2517
 
virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
2518
 
                          virNWFilterPoolObjPtr pool,
2519
 
                          virNWFilterDefPtr def)
 
2516
virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
 
2517
                      virNWFilterObjPtr nwfilter,
 
2518
                      virNWFilterDefPtr def)
2520
2519
{
2521
2520
    char *xml;
2522
2521
    int fd = -1, ret = -1;
2523
2522
    ssize_t towrite;
2524
2523
 
2525
 
    if (!pool->configFile) {
 
2524
    if (!nwfilter->configFile) {
2526
2525
        int err;
2527
2526
        char path[PATH_MAX];
2528
2527
 
2539
2538
                                  "%s", _("cannot construct config file path"));
2540
2539
            return -1;
2541
2540
        }
2542
 
        if (!(pool->configFile = strdup(path))) {
 
2541
        if (!(nwfilter->configFile = strdup(path))) {
2543
2542
            virReportOOMError();
2544
2543
            return -1;
2545
2544
        }
2551
2550
        return -1;
2552
2551
    }
2553
2552
 
2554
 
    if ((fd = open(pool->configFile,
 
2553
    if ((fd = open(nwfilter->configFile,
2555
2554
                   O_WRONLY | O_CREAT | O_TRUNC,
2556
2555
                   S_IRUSR | S_IWUSR )) < 0) {
2557
2556
        virReportSystemError(errno,
2558
2557
                             _("cannot create config file %s"),
2559
 
                             pool->configFile);
 
2558
                             nwfilter->configFile);
2560
2559
        goto cleanup;
2561
2560
    }
2562
2561
 
2564
2563
    if (safewrite(fd, xml, towrite) != towrite) {
2565
2564
        virReportSystemError(errno,
2566
2565
                             _("cannot write config file %s"),
2567
 
                             pool->configFile);
 
2566
                             nwfilter->configFile);
2568
2567
        goto cleanup;
2569
2568
    }
2570
2569
 
2571
2570
    if (VIR_CLOSE(fd) < 0) {
2572
2571
        virReportSystemError(errno,
2573
2572
                             _("cannot save config file %s"),
2574
 
                             pool->configFile);
 
2573
                             nwfilter->configFile);
2575
2574
        goto cleanup;
2576
2575
    }
2577
2576
 
2587
2586
 
2588
2587
 
2589
2588
int
2590
 
virNWFilterPoolObjDeleteDef(virNWFilterPoolObjPtr pool)
 
2589
virNWFilterObjDeleteDef(virNWFilterObjPtr nwfilter)
2591
2590
{
2592
 
    if (!pool->configFile) {
 
2591
    if (!nwfilter->configFile) {
2593
2592
        virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
2594
 
                               _("no config file for %s"), pool->def->name);
 
2593
                               _("no config file for %s"), nwfilter->def->name);
2595
2594
        return -1;
2596
2595
    }
2597
2596
 
2598
 
    if (unlink(pool->configFile) < 0) {
 
2597
    if (unlink(nwfilter->configFile) < 0) {
2599
2598
        virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
2600
2599
                               _("cannot remove config for %s"),
2601
 
                               pool->def->name);
 
2600
                               nwfilter->def->name);
2602
2601
        return -1;
2603
2602
    }
2604
2603
 
2686
2685
                   asHex = true;
2687
2686
               case DATATYPE_IPMASK:
2688
2687
               case DATATYPE_IPV6MASK:
2689
 
                   // display all masks in CIDR format
 
2688
                   /* display all masks in CIDR format */
2690
2689
               case DATATYPE_UINT8:
2691
2690
                   virBufferVSprintf(buf, asHex ? "0x%x" : "%d",
2692
2691
                                     item->u.u8);
2900
2899
}
2901
2900
 
2902
2901
 
2903
 
void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj)
 
2902
void virNWFilterObjLock(virNWFilterObjPtr obj)
2904
2903
{
2905
2904
    virMutexLock(&obj->lock);
2906
2905
}
2907
2906
 
2908
 
void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj)
 
2907
void virNWFilterObjUnlock(virNWFilterObjPtr obj)
2909
2908
{
2910
2909
    virMutexUnlock(&obj->lock);
2911
2910
}