~ubuntu-branches/ubuntu/jaunty/libvirt/jaunty-updates

« back to all changes in this revision

Viewing changes to src/bridge.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2009-01-08 23:01:16 UTC
  • mfrom: (1.1.8 upstream) (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090108230116-niu4xzgypapywhmx
Tags: 0.5.1-4ubuntu1
* Merge with Debian experimental.
  - debian/control:
    + Don't build-depend on QEmu.
    + Add "XS-Debian-" prefix to Debian's Vcs headers.
    + Bump bridge-utils, dnsmasq-base, netcat-openbsd, and iptables
      to Depends of libvirt-bin.
    + s/interract/interact/g
    + Add versioned Conflicts/Replaces to libvirt0 for libvirt0-dbg,
      since we used to ship them as such.
  - Rename libvirt group to libvirtd.
  - 0005-delayed_iff_up_bridge.patch: Don't try to bring up the bridge
    before at least one interface has been added to it.
  - dont_clobber_existing_bridges.patch: Assign the name of the virtual
    bridge dynamically to avoid interfering with existing bridges.
  - better_default_uri_virsh.patch: Default to qemu:///system if the
    user has write access to the libvirt socket, otherwise
    qemu:///session.
  - We call libxen-dev libxen3-dev, so change all references.
* Included (but did not enable) opennebula patch (since it's not in
  the archive yet).

Show diffs side-by-side

added added

removed removed

Lines of Context:
276
276
#endif
277
277
 
278
278
/**
 
279
 * ifGetMtu
 
280
 * @ctl: bridge control pointer
 
281
 * @ifname: interface name get MTU for
 
282
 *
 
283
 * This function gets the @mtu value set for a given interface @ifname.
 
284
 *
 
285
 * Returns the MTU value in case of success.
 
286
 * On error, returns -1 and sets errno accordingly
 
287
 */
 
288
static int ifGetMtu(brControl *ctl, const char *ifname)
 
289
{
 
290
    struct ifreq ifr;
 
291
    int len;
 
292
 
 
293
    if (!ctl || !ifname) {
 
294
        errno = EINVAL;
 
295
        return -1;
 
296
    }
 
297
 
 
298
    if ((len = strlen(ifname)) >=  BR_IFNAME_MAXLEN) {
 
299
        errno = EINVAL;
 
300
        return -1;
 
301
    }
 
302
 
 
303
    memset(&ifr, 0, sizeof(struct ifreq));
 
304
 
 
305
    strncpy(ifr.ifr_name, ifname, len);
 
306
    ifr.ifr_name[len] = '\0';
 
307
 
 
308
    if (ioctl(ctl->fd, SIOCGIFMTU, &ifr))
 
309
        return -1;
 
310
 
 
311
    return ifr.ifr_mtu;
 
312
 
 
313
}
 
314
 
 
315
/**
 
316
 * ifSetMtu:
 
317
 * @ctl: bridge control pointer
 
318
 * @ifname: interface name to set MTU for
 
319
 * @mtu: MTU value
 
320
 *
 
321
 * This function sets the @mtu for a given interface @ifname.  Typically
 
322
 * used on a tap device to set up for Jumbo Frames.
 
323
 *
 
324
 * Returns 0 in case of success or an errno code in case of failure.
 
325
 */
 
326
static int ifSetMtu(brControl *ctl, const char *ifname, int mtu)
 
327
{
 
328
    struct ifreq ifr;
 
329
    int len;
 
330
 
 
331
    if (!ctl || !ifname)
 
332
        return EINVAL;
 
333
 
 
334
    if ((len = strlen(ifname)) >=  BR_IFNAME_MAXLEN)
 
335
        return EINVAL;
 
336
 
 
337
    memset(&ifr, 0, sizeof(struct ifreq));
 
338
 
 
339
    strncpy(ifr.ifr_name, ifname, len);
 
340
    ifr.ifr_name[len] = '\0';
 
341
    ifr.ifr_mtu = mtu;
 
342
 
 
343
    return ioctl(ctl->fd, SIOCSIFMTU, &ifr) == 0 ? 0 : errno;
 
344
}
 
345
 
 
346
/**
 
347
 * brSetInterfaceMtu
 
348
 * @ctl: bridge control pointer
 
349
 * @bridge: name of the bridge interface
 
350
 * @ifname: name of the interface whose MTU we want to set
 
351
 *
 
352
 * Sets the interface mtu to the same MTU of the bridge
 
353
 *
 
354
 * Returns 0 in case of success or an errno code in case of failure.
 
355
 */
 
356
static int brSetInterfaceMtu(brControl *ctl,
 
357
                             const char *bridge,
 
358
                             const char *ifname)
 
359
{
 
360
    int mtu = ifGetMtu(ctl, bridge);
 
361
 
 
362
    if (mtu < 0)
 
363
        return errno;
 
364
 
 
365
    return ifSetMtu(ctl, ifname, mtu);
 
366
}
 
367
 
 
368
/**
279
369
 * brAddTap:
280
370
 * @ctl: bridge control pointer
281
371
 * @bridge: the bridge name
334
424
        }
335
425
 
336
426
        if (ioctl(fd, TUNSETIFF, &try) == 0) {
 
427
            /* We need to set the interface MTU before adding it
 
428
             * to the bridge, because the bridge will have its
 
429
             * MTU adjusted automatically when we add the new interface.
 
430
             */
 
431
            if ((errno = brSetInterfaceMtu(ctl, bridge, try.ifr_name)))
 
432
                goto error;
337
433
            if ((errno = brAddInterface(ctl, bridge, try.ifr_name)))
338
434
                goto error;
339
435
            if ((errno = brSetInterfaceUp(ctl, try.ifr_name, 1)))