int device_get_sysnum_unsigned(sd_device *device, unsigned *ret);
int device_get_property_bool(sd_device *device, const char *key);
int device_get_property_int(sd_device *device, const char *key, int *ret);
+int device_get_ifname(sd_device *device, const char **ret);
int device_get_sysattr_int(sd_device *device, const char *sysattr, int *ret_value);
int device_get_sysattr_unsigned_full(sd_device *device, const char *sysattr, unsigned base, unsigned *ret_value);
static inline int device_get_sysattr_unsigned(sd_device *device, const char *sysattr, unsigned *ret_value) {
return 0;
}
+int device_get_ifname(sd_device *device, const char **ret) {
+ int r;
+
+ assert_return(device, -EINVAL);
+
+ /* First, check if the device is a network interface. */
+ r = sd_device_get_ifindex(device, NULL);
+ if (r < 0)
+ return r;
+
+ /* The sysname and ifname may be different, as '!' in sysname are replaced with '/'.
+ * For network interfaces, we can use INTERFACE property. */
+ return sd_device_get_property_value(device, "INTERFACE", ret);
+}
+
_public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
int r;
else {
ASSERT_GT(ifindex, 0);
+ const char *ifname;
+ ASSERT_OK(device_get_ifname(d, &ifname));
+ ASSERT_NOT_NULL(endswith(syspath, ifname));
+ if (strchr(sysname, '/'))
+ ASSERT_FALSE(streq(ifname, sysname));
+ else
+ ASSERT_STREQ(ifname, sysname);
+
r = sd_device_new_from_ifindex(&dev, ifindex);
if (r < 0) {
ASSERT_ERROR(r, ENODEV);