Page MenuHomeFreeBSD

net: invoke ifnet_arrival_event handlers before linking in
Needs ReviewPublic

Authored by glebius on Fri, Dec 5, 4:50 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 8, 8:33 PM
Unknown Object (File)
Mon, Dec 8, 7:22 AM
Unknown Object (File)
Mon, Dec 8, 7:20 AM

Details

Reviewers
None
Group Reviewers
network
Summary

Otherwise there is a race window when interface is already visible, but
not all of the protocols have completed their attach.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 69072
Build 65955: arc lint + arc unit

Event Timeline

zlei added inline comments.
sys/net/if.c
938

The original ifnet_arrival_event reads, "the interface is attached and global visible". But after this change, "the interface is attached but is not guaranteed to be global visible".

There are consumers,

sys/net/rtsock.c:EVENTHANDLER_DEFINE(ifnet_arrival_event, rts_handle_ifnet_arrival, NULL, 0);
...
sys/netlink/route/iface.c:	EVENTHANDLER_DEREGISTER(ifnet_arrival_event, ifattach_event);

rely on the former behavior, so that netlink clients or tsock clients can see global visible ifnet.

I'm not sure what's the best approach, but maybe a new EVENTHANDLER is wanted to attach IPv4 and IPv6 stacks to an interface ?

sys/net/if.c
938

The original ifnet_arrival_event reads, "the interface is attached and global visible". But after this change, "the interface is attached but is not guaranteed to be global visible".

That's a good observation, thanks.

There are consumers,

sys/net/rtsock.c:EVENTHANDLER_DEFINE(ifnet_arrival_event, rts_handle_ifnet_arrival, NULL, 0);

...

sys/netlink/route/iface.c: EVENTHANDLER_DEREGISTER(ifnet_arrival_event, ifattach_event);

These two do not actually work with the global glue, they don't need the interface to be fully linked in. However, they do announce the interface arrival to the userland. Hypothetically there could be a race with the application seeing the announcement and immediately doing an ioctl/netlink call, that reaches kernel faster than other eventhandlers do their work.

I'm not sure what's the best approach, but maybe a new EVENTHANDLER is wanted to attach IPv4 and IPv6 stacks to an interface ?

I'd rather create a second event handler that would be called after a complete attach of the interface. The rtsock and the netlink would be its only consumers for now. What do you think?