| 514 | } |
| 515 | |
| 516 | static int |
| 517 | tun_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) |
| 518 | { |
| 519 | struct tuntap_driver *drv; |
| 520 | struct cdev *dev; |
| 521 | int err, i, tunflags, unit; |
| 522 | |
| 523 | tunflags = 0; |
| 524 | /* The name here tells us exactly what we're creating */ |
| 525 | err = tuntap_name2info(name, &unit, &tunflags); |
| 526 | if (err != 0) |
| 527 | return (err); |
| 528 | |
| 529 | drv = tuntap_driver_from_flags(tunflags); |
| 530 | if (drv == NULL) |
| 531 | return (ENXIO); |
| 532 | |
| 533 | if (unit != -1) { |
| 534 | /* If this unit number is still available that's okay. */ |
| 535 | if (alloc_unr_specific(drv->unrhdr, unit) == -1) |
| 536 | return (EEXIST); |
| 537 | } else { |
| 538 | unit = alloc_unr(drv->unrhdr); |
| 539 | } |
| 540 | |
| 541 | snprintf(name, IFNAMSIZ, "%s%d", drv->cdevsw.d_name, unit); |
| 542 | |
| 543 | /* find any existing device, or allocate new unit number */ |
| 544 | dev = NULL; |
| 545 | i = clone_create(&drv->clones, &drv->cdevsw, &unit, &dev, 0); |
| 546 | /* No preexisting struct cdev *, create one */ |
| 547 | if (i != 0) |
| 548 | i = tun_create_device(drv, unit, NULL, &dev, name); |
| 549 | if (i == 0) |
| 550 | tuncreate(dev); |
| 551 | |
| 552 | return (i); |
| 553 | } |
| 554 | |
| 555 | static void |
| 556 | tunclone(void *arg, struct ucred *cred, char *name, int namelen, |
nothing calls this directly
no test coverage detected