[systemd-devel] [PATCH] Set mac address in link initialization

Dave Reisner d at falconindy.com
Wed Jun 4 12:42:46 PDT 2014


On Wed, Jun 04, 2014 at 09:33:12PM +0200, Tom Gundersen wrote:
> On Wed, Jun 4, 2014 at 7:48 PM, Dave Reisner <dreisner at archlinux.org> wrote:
> > 505f8da7325 left link->mac uninitialized, causing MACAddress based
> > [Match] sections to fail to match anything.
> >
> > https://bugs.freedesktop.org/show_bug.cgi?id=79638
> 
> Thanks for the report and the patch.
> 
> I'd much prefer if we got these potentially dynamic properties only
> from one source though (i.e., from rtnl), as we are not guaranteed any
> ordering between udev and rtnl events. In this particular case it
> seems like there can not be a problem, but I'd rather be consistent.

Fair enough.

> I pushed an alternative fix. Could you have a look to see if it looks ok to you?
> 

Works for me. Thanks!

> > ---
> >  src/network/networkd-link.c | 12 +++++++++++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
> > index 6e6fb83..f3bab9f 100644
> > --- a/src/network/networkd-link.c
> > +++ b/src/network/networkd-link.c
> > @@ -1683,8 +1683,18 @@ int link_initialized(Link *link, struct udev_device *device) {
> >          if (link->state != LINK_STATE_INITIALIZING)
> >                  return 0;
> >
> > -        if (device)
> > +        if (device) {
> > +                const char *mac_address = udev_device_get_sysattr_value(
> > +                                device, "address");
> > +
> > +                if (mac_address) {
> > +                        struct ether_addr *hwaddr = ether_aton(mac_address);
> > +                        if (hwaddr)
> > +                                memcpy(&link->mac, hwaddr, sizeof(struct ether_addr));
> > +                }
> > +
> >                  link->udev_device = udev_device_ref(device);
> > +        }
> >
> >          log_debug_link(link, "udev initialized link");
> >
> > --
> > 2.0.0
> >
> > _______________________________________________
> > systemd-devel mailing list
> > systemd-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list