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);
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 - 1);
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)
205 struct stat s = { 0 };
206 if (stat (path, &s) == -1)
209 return S_ISDIR (s.st_mode);
218 static int uio_new_id_needed = 1;
227 s =
format (0,
"%v/driver%c", dev_dir_name, 0);
233 if (!driver_name || strcmp (
"hv_netvsc", (
char *) driver_name) != 0)
240 s =
format (s,
"%v/net%c", dev_dir_name, 0);
241 dir = opendir ((
char *) s);
247 while ((e = readdir (dir)))
249 if (e->d_name[0] ==
'.')
252 ifname = strdup (e->d_name);
260 "VMBUS device %U eth not found",
267 strncpy (ifr.ifr_name, ifname, IFNAMSIZ - 1);
270 fd = socket (PF_INET, SOCK_DGRAM, 0);
277 if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0)
285 if (ifr.ifr_flags & IFF_UP)
288 "Skipping VMBUS device %U as host interface %s is up",
295 if (uio_new_id_needed)
307 uio_new_id_needed = 0;
319 s =
format (s,
"%/driver_override%c", dev_dir_name, 0);
320 if (access ((
char *) s, F_OK) == 0)
328 s =
format (s,
"%v/driver/unbind%c", dev_dir_name, 0);
361 if (!
unformat (&input,
"/sys/bus/vmbus/devices/%U",
380 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_export u8 * clib_sysfs_link_to_name(char *link)
clib_error_t * vlib_vmbus_bind_to_uio(vlib_vmbus_addr_t *addr)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static const char uio_drv_name[]
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
clib_error_t * vmbus_bus_init(vlib_main_t *vm)
__clib_export clib_error_t * clib_sysfs_write(char *file_name, char *fmt,...)
vlib_vmbus_dev_handle_t handle
#define VLIB_INIT_FUNCTION(x)
linux_vmbus_main_t linux_vmbus_main
static int directory_exists(char *path)
description fragment has unexpected format
#define clib_error_return(e, args...)
static uword unformat_vlib_vmbus_addr(unformat_input_t *input, va_list *args)
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)