X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fdevices%2Ftap%2Ftap.c;h=94a91e5509abf6e8f8480601124148506e236387;hb=bd50ed18de83493b119e67897a5fa9ba9c7e763e;hp=aa9182a58f7eff0e00e0d72be92ade28d0a984ff;hpb=d4a547144ffc0f68538d5a89ce7d41cd739a33d2;p=vpp.git diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c index aa9182a58f7..94a91e5509a 100644 --- a/src/vnet/devices/tap/tap.c +++ b/src/vnet/devices/tap/tap.c @@ -751,6 +751,12 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; vnet_hw_interface_set_flags (vnm, vif->hw_if_index, VNET_HW_INTERFACE_FLAG_LINK_UP); + /* + * Host tun/tap driver link carrier state is "up" at creation. The + * driver never changes this unless the backend (VPP) changes it using + * TUNSETCARRIER ioctl(). See tap_set_carrier(). + */ + vif->host_carrier_up = 1; vif->cxq_vring = NULL; goto done; @@ -987,6 +993,41 @@ tap_dump_ifs (tap_interface_details_t ** out_tapids) return 0; } +/* + * Set host tap/tun interface carrier state so it will appear to host + * applications that the interface's link state changed. + * + * If the kernel we're building against does not have support for the + * TUNSETCARRIER ioctl command, do nothing. + */ +int +tap_set_carrier (u32 hw_if_index, u32 carrier_up) +{ + int ret = 0; +#ifdef TUNSETCARRIER + vnet_main_t *vnm = vnet_get_main (); + vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); + virtio_main_t *mm = &virtio_main; + virtio_if_t *vif; + int *fd; + + vif = pool_elt_at_index (mm->interfaces, hi->dev_instance); + vec_foreach (fd, vif->tap_fds) + { + ret = ioctl (*fd, TUNSETCARRIER, &carrier_up); + if (ret < 0) + { + clib_warning ("ioctl (TUNSETCARRIER) returned %d", ret); + break; + } + } + if (!ret) + vif->host_carrier_up = (carrier_up != 0); +#endif + + return ret; +} + static clib_error_t * tap_mtu_config (vlib_main_t * vm, unformat_input_t * input) {