Пример #1
0
static int manager_udev_fn(sd_event_source *source,
			   int fd,
			   uint32_t mask,
			   void *data)
{
	_cleanup_udev_device_ struct udev_device *d = NULL;
	struct manager *m = data;
	const char *action, *ifname;
	unsigned int ifindex;
	struct link *l;

	d = udev_monitor_receive_device(m->udev_mon);
	if (!d)
		return 0;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return 0;

	l = manager_find_link(m, ifindex);

	action = udev_device_get_action(d);
	if (action && !strcmp(action, "remove")) {
		if (l)
			link_free(l);
	} else if (l) {
		ifname = udev_device_get_property_value(d, "INTERFACE");
		if (action && !strcmp(action, "move")) {
			if (ifname)
				link_renamed(l, ifname);
		}

#ifdef RELY_UDEV
		if (udev_device_has_tag(d, "miracle") && !lazy_managed)
			link_set_managed(l, true);
		else
			link_set_managed(l, false);
#else
		if ((!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed) {
			link_set_managed(l, true);
		} else {
			log_debug("ignored device: %s", ifname);
		}
#endif
	} else {
		manager_add_udev_link(m, d);
	}

	return 0;
}
Пример #2
0
static void manager_read_links(struct manager *m)
{
	_cleanup_udev_enumerate_ struct udev_enumerate *e = NULL;
	struct udev_list_entry *l;
	struct udev_device *d;
	int r;

	e = udev_enumerate_new(m->udev);
	if (!e)
		goto error;

	r = udev_enumerate_add_match_subsystem(e, "net");
	if (r < 0)
		goto error;

	r = udev_enumerate_add_match_property(e, "DEVTYPE", "wlan");
	if (r < 0)
		goto error;

	r = udev_enumerate_add_match_is_initialized(e);
	if (r < 0)
		goto error;

	r = udev_enumerate_scan_devices(e);
	if (r < 0)
		goto error;

	udev_list_entry_foreach(l, udev_enumerate_get_list_entry(e)) {
		d = udev_device_new_from_syspath(m->udev,
						 udev_list_entry_get_name(l));
		if (!d)
			goto error;

		manager_add_udev_link(m, d);
		udev_device_unref(d);
	}
Пример #3
0
static void manager_add_udev_link(struct manager *m,
				  struct udev_device *d)
{
	struct link *l;
	unsigned int ifindex;
	const char *ifname;
	int r;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return;

	ifname = udev_device_get_property_value(d, "INTERFACE");
	if (!ifname)
		return;

	if (interface_name && strcmp(interface_name, ifname)) {
		return;
	}

	/* ignore dynamic p2p interfaces */
	if (shl_startswith(ifname, "p2p-"))
		return;

	r = link_new(m, ifindex, ifname, &l);
	if (r < 0)
		return;

	link_set_friendly_name(l, m->friendly_name);

#ifdef RELY_UDEV
	if (udev_device_has_tag(d, "miracle")) {
#else
	if (!interface_name || !strcmp(interface_name, ifname)) {
#endif
		link_set_managed(l, true);
	} else {
		log_debug("ignored device: %s", ifname);
	}
}

static int manager_udev_fn(sd_event_source *source,
			   int fd,
			   uint32_t mask,
			   void *data)
{
	_cleanup_udev_device_ struct udev_device *d = NULL;
	struct manager *m = data;
	const char *action, *ifname;
	unsigned int ifindex;
	struct link *l;

	d = udev_monitor_receive_device(m->udev_mon);
	if (!d)
		return 0;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return 0;

	l = manager_find_link(m, ifindex);

	action = udev_device_get_action(d);
	if (action && !strcmp(action, "remove")) {
		if (l)
			link_free(l);
	} else if (l) {
		ifname = udev_device_get_property_value(d, "INTERFACE");
		if (action && !strcmp(action, "move")) {
			if (ifname)
				link_renamed(l, ifname);
		}

#ifdef RELY_UDEV
		if (udev_device_has_tag(d, "miracle"))
			link_set_managed(l, true);
		else
			link_set_managed(l, false);
#else
		if (!interface_name || !strcmp(interface_name, ifname)) {
			link_set_managed(l, true);
		} else {
			log_debug("ignored device: %s", ifname);
		}
#endif
	} else {
		manager_add_udev_link(m, d);
	}

	return 0;
}