Event Loops

01 Sep 2008 • 2 min read

Well, support for multiple instances in dhcpcd is coming along nicely, but I've had to pretty much re-write the entire state handling code. The existing code was wait for data or timeout. Then drop into case statements depending on if we timed out and what our current state is.The new code is now based around an event loop, where we register functions to call when we get data or a time has passed. We pass all functions an interface structure, which now holds the state and options (previously the state held the interface and options). This handling lease expiry times a lot easier - we simply set 3 timeout per interface (renew, rebind, expire) and let the event loop do its job.This new structure should also make it easier to add DHCPv6 support - it should just be a matter of registering new functions to listen on IPv6 connected sockets and then selecting a DHCPv6 server over a DHCPv4 one. As this new code is quite a big change and I think I'm making life easier for DHCPv6 later on we'll probably skip 4.1 and move straight onto 5.0, adding DHCPv6 support in 5.1.Hopefully I'll commit this to git over the next few days - I just need to ensure that cable link events correctly move to the right state. The only thing that will be known to be broken in the first commit to git will probably be rebinding the interface on the command line as I'll probably need to move to using a control socket. We'll need one for dynamically adding and removing interfaces anyway.