Пример #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_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;
}