- netdev_init(&netdev->netdev, netdev_dev);
- netdev->netdev_fd = -1;
- netdev->tap_fd = -1;
-
- if (!strcmp(netdev_dev_get_type(netdev_dev), "tap")) {
- static const char tap_dev[] = "/dev/net/tun";
- struct ifreq ifr;
-
- /* Open tap device. */
- netdev->tap_fd = open(tap_dev, O_RDWR);
- if (netdev->tap_fd < 0) {
- error = errno;
- VLOG_WARN("opening \"%s\" failed: %s", tap_dev, strerror(error));
- goto error;
- }
-
- /* Create tap device. */
- ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
- strncpy(ifr.ifr_name, netdev_dev_get_name(netdev_dev),
- sizeof ifr.ifr_name);
- if (ioctl(netdev->tap_fd, TUNSETIFF, &ifr) == -1) {
- VLOG_WARN("%s: creating tap device failed: %s",
- netdev_dev_get_name(netdev_dev),
- strerror(errno));
- error = errno;
- goto error;
- }
-
- /* Make non-blocking. */
- error = set_nonblocking(netdev->tap_fd);
- if (error) {
- goto error;
- }
- }