[systemd-devel] [PATCH] sd-ipv4ll: generate predictable addresses

Lennart Poettering lennart at poettering.net
Tue Mar 18 16:59:44 PDT 2014


On Tue, 18.03.14 20:29, Umut Tezduyar Lindskog (umut.tezduyar at axis.com) wrote:


> +int net_get_unique_predictable_data(struct udev_device *device, uint64_t *result) {
> +        size_t l, sz = 0;
> +        const char *name;
> +        int r;
> +        uint8_t *v;
> +
> +        /* fetch some persistent data unique (on this machine) to this device */
> +        name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
> +        if (!name) {
> +                name = udev_device_get_property_value(device, "ID_NET_NAME_SLOT");
> +                if (!name) {
> +                        name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
> +                        if (!name) {
> +                                name = udev_device_get_property_value(device, "ID_NET_NAME_MAC");
> +                                if (!name)
> +                                        return -ENOENT;
> +                        }
> +                }
> +        }

To make this a bit nicer I have now added code a new FOREACH_STRING()
macro, working like this:

    const char *field, *name = NULL;

    FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
            name = udev_device_get_property_value(device, field);
            if (name)
                    break;
    }

    if (!name)
            return -ENOENT;

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list