25 #include <sys/types.h> 29 #include <sys/ioctl.h> 31 #include <linux/ethtool.h> 32 #include <linux/sockios.h> 34 #include <uuid/uuid.h> 40 static const char netvsc_uuid[] =
"f8615163-df3e-46c5-913f-f2d2f965ed0e";
131 if (uuid_parse ((
char *) s, addr->
guid) == 0)
146 uuid_unparse (addr->
guid, tmp);
147 return format (s,
"%s", tmp);
160 memset (&ifr, 0,
sizeof (ifr));
164 dir = opendir ((
char *) dev_net_dir);
172 while ((e = readdir (dir)))
175 if (strncmp (e->d_name,
"lower_", 6))
178 strncpy (ifr.ifr_name, e->d_name + 6, IFNAMSIZ);
186 if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0)
189 else if (!(ifr.ifr_flags & IFF_UP))
191 ifr.ifr_flags |= IFF_UP;
193 if (ioctl (fd, SIOCSIFFLAGS, &ifr) < 0)
208 static int uio_new_id_needed = 1;
217 s =
format (0,
"%v/driver%c", dev_dir_name, 0);
223 if (!driver_name || strcmp (
"hv_netvsc", (
char *) driver_name) != 0)
226 s =
format (s,
"%v/net%c", dev_dir_name, 0);
227 dir = opendir ((
char *) s);
233 while ((e = readdir (dir)))
235 if (e->d_name[0] ==
'.')
238 ifname = strdup (e->d_name);
246 "VMBUS device %U eth not found",
252 memset (&ifr, 0,
sizeof (ifr));
253 strncpy (ifr.ifr_name, ifname, IFNAMSIZ);
256 fd = socket (PF_INET, SOCK_DGRAM, 0);
263 if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0)
271 if (ifr.ifr_flags & IFF_UP)
274 "Skipping VMBUS device %U as host interface %s is up",
288 if (uio_new_id_needed)
290 uio_new_id_needed = 0;
303 s =
format (s,
"%/driver_override%c", dev_dir_name, 0);
304 if (access ((
char *) s, F_OK) == 0)
312 s =
format (s,
"%v/driver/unbind%c", dev_dir_name, 0);
345 if (!
unformat (&input,
"/sys/bus/vmbus/devices/%U",
364 return uuid_compare (a1->
guid, a2->
guid);
vlib_vmbus_addr_t * vlib_vmbus_get_addr(vlib_vmbus_dev_handle_t h)
uword vlib_vmbus_get_private_data(vlib_vmbus_dev_handle_t h)
static int vmbus_addr_cmp(void *v1, void *v2)
clib_error_t * linux_vmbus_init(vlib_main_t *vm)
clib_error_t * vlib_vmbus_bind_to_uio(vlib_vmbus_addr_t *addr)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static const char uio_drv_name[]
clib_error_t * clib_sysfs_write(char *file_name, char *fmt,...)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
clib_error_t * vmbus_bus_init(vlib_main_t *vm)
vlib_vmbus_dev_handle_t handle
#define VLIB_INIT_FUNCTION(x)
linux_vmbus_main_t linux_vmbus_main
#define clib_error_return(e, args...)
static uword unformat_vlib_vmbus_addr(unformat_input_t *input, va_list *args)
#define vlib_call_init_function(vm, x)
static const char sysfs_vmbus_drv_path[]
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define clib_error_return_unix(e, args...)
static const char sysfs_vmbus_dev_path[]
static linux_vmbus_device_t * linux_vmbus_get_device(vlib_vmbus_dev_handle_t h)
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * vlib_vmbus_raise_lower(int fd, const char *upper_name)
u32 vlib_vmbus_dev_handle_t
static u8 * format_vlib_vmbus_addr(u8 *s, va_list *va)
static const char sysfs_class_net_path[]
vlib_vmbus_addr_t * vlib_vmbus_get_all_dev_addrs()
clib_error_t * foreach_directory_file(char *dir_name, clib_error_t *(*f)(void *arg, u8 *path_name, u8 *file_name), void *arg, int scan_dirs)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
static clib_error_t * scan_vmbus_addr(void *arg, u8 *dev_dir_name, u8 *ignored)
static const char netvsc_uuid[]
linux_vmbus_device_t * linux_vmbus_devices
void vlib_vmbus_set_private_data(vlib_vmbus_dev_handle_t h, uword private_data)
u8 * clib_sysfs_link_to_name(char *link)