- flags = IFF_TAP | IFF_NO_PI;
-
- if ((dev_net_tun_fd = open ("/dev/net/tun", O_RDWR)) < 0)
- {
- vlib_cli_output (vm, "Couldn't open /dev/net/tun");
- return 0;
- }
-
- memset (&ifr, 0, sizeof (ifr));
- strncpy(ifr.ifr_name, (char *) intfc_name, sizeof (ifr.ifr_name)-1);
- ifr.ifr_flags = flags;
- if (ioctl (dev_net_tun_fd, TUNSETIFF, (void *)&ifr) < 0)
- {
- vlib_cli_output (vm, "Error setting flags on '%s'", intfc_name);
- goto error;
- }
-
- /* Open a provisioning socket */
- if ((dev_tap_fd = socket(PF_PACKET, SOCK_RAW,
- htons(ETH_P_ALL))) < 0 )
- {
- vlib_cli_output (vm, "Couldn't open provisioning socket");
- goto error;
- }
-
- /* Find the interface index. */
- {
- struct ifreq ifr;
- struct sockaddr_ll sll;
-
- memset (&ifr, 0, sizeof(ifr));
- strncpy (ifr.ifr_name, (char *) intfc_name, sizeof (ifr.ifr_name)-1);
- if (ioctl (dev_tap_fd, SIOCGIFINDEX, &ifr) < 0 )
- {
- vlib_cli_output (vm, "Couldn't get if_index");
- goto error;
- }
-
- /* Bind the provisioning socket to the interface. */
- memset(&sll, 0, sizeof(sll));
- sll.sll_family = AF_PACKET;
- sll.sll_ifindex = ifr.ifr_ifindex;
- sll.sll_protocol = htons(ETH_P_ALL);
-
- if (bind(dev_tap_fd, (struct sockaddr*) &sll, sizeof(sll)) < 0)
- {
- vlib_cli_output (vm, "Couldn't bind provisioning socket");
- goto error;
- }
- }
-
- /* non-blocking I/O on /dev/tapX */
- {
- int one = 1;
- if (ioctl (dev_net_tun_fd, FIONBIO, &one) < 0)
- {
- vlib_cli_output (0, "Couldn't set device non-blocking flag");
- goto error;
- }
- }
- ifr.ifr_mtu = tm->mtu_bytes;
- if (ioctl (dev_tap_fd, SIOCSIFMTU, &ifr) < 0)
- {
- vlib_cli_output (0, "Couldn't set device MTU");
- goto error;
- }
-
- /* get flags, modify to bring up interface... */
- if (ioctl (dev_tap_fd, SIOCGIFFLAGS, &ifr) < 0)
- {
- vlib_cli_output (0, "Couldn't get interface flags");
- goto error;
- }
-
- ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
-
- if (ioctl (dev_tap_fd, SIOCSIFFLAGS, &ifr) < 0)
- {
- vlib_cli_output (0, "Couldn't set intfc admin state up");
- goto error;
- }
-
- if (ioctl (dev_tap_fd, SIOCGIFHWADDR, &ifr) < 0)
- {
- vlib_cli_output (0, "Couldn't get intfc MAC address");
- goto error;
- }
-
- ti = tapcli_get_new_tapif();
- ti->per_interface_next_index = ~0;
-