https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235920

--- Comment #4 from Zhenlei Huang <z...@freebsd.org> ---
(In reply to Oleg Ginzburg from comment #0)
If `ifconfig create` with an unit number, then cloner will check whether the
number is available or not ( via alloc_unr_specific() ).

```
static int
tun_clone_create(struct if_clone *ifc, char *name, size_t len,
    struct ifc_data *ifd, struct ifnet **ifpp)
{
        struct tuntap_driver *drv;
        struct cdev *dev;
        int err, i, tunflags, unit;

        tunflags = 0;
        /* The name here tells us exactly what we're creating */
        err = tuntap_name2info(name, &unit, &tunflags);
        if (err != 0)
                return (err);

        drv = tuntap_driver_from_flags(tunflags);
        if (drv == NULL)
                return (ENXIO);

        if (unit != -1) {
                /* If this unit number is still available that's okay. */
                if (alloc_unr_specific(drv->unrhdr, unit) == -1)
                        return (EEXIST);
        } else {
                unit = alloc_unr(drv->unrhdr);
        }

        snprintf(name, IFNAMSIZ, "%s%d", drv->cdevsw.d_name, unit);

        /* find any existing device, or allocate new unit number */
        dev = NULL;
        i = clone_create(&drv->clones, &drv->cdevsw, &unit, &dev, 0);
        /* No preexisting struct cdev *, create one */
        if (i != 0)
                i = tun_create_device(drv, unit, NULL, &dev, name);
        if (i == 0) {
                tuncreate(dev);
                struct tuntap_softc *tp = dev->si_drv1;
                *ifpp = tp->tun_ifp;
        }

        return (i);
}
```

When an interface is renamed, its unit number is not `freed` and thus lead this
problem.

Other interfaces such as if_bridge are also affected.

```
# ifconfig bridge0 create name br0
# ifconfig bridge0 create
ifconfig: interface bridge0 already exists
```

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to