Had I known implementing DNSSEC support would have been so tricky, I wouldn't have tried...
First, there's the (expected) clock issues. I initially wanted to go with the method of relying on a file's timestamp, as it seemed the simplest code-wise. There's one catch however: how does dnsmasq knows it can create the initial file safely? It's likely that the first time dnsmasq starts and the file doesn't exist yet, the clock hasn't been set yet. So, you'd get stuck without NTP access. Scratch that idea.
I then decided to go with the same method as used by Tomato. That brings a different issue: since dnsmasq will not enable dnssec timestamp validation until it gets told to refresh its configuration, that means that every time dnsmasq gets restarted (due to a configuration change), it will stop processing timestamps again. So, that wouldn't work either. (
@lancethepants - that might be worth checking if that's an issue with Tomato too).
I went with a more intelligent solution: if ntp hasn't been set yet (ntp_ready isn't set to 1), then the config file gets the option to wait until a config refresh. If dnsmasq however gets configured with ntp_ready is set, then don't use any special trick and start immediately to handle timestamp checks. Which exposed another issue: so early during boot, ntp_ready is still set to 1 from the previous boot. (
@john9527 , I wonder if that wouldn't create other NTP-related issues...). Easily fixed, I now clear ntp_ready at boot time, along with other temporary nvram settings.
Another issue then: the firmware is already causing dnsmasq to reloads its config files 1-2 times during boot, as various services update it. So once again, dnsmasq is starting prematurely to support time checks... Had to change the reload_dnsmasq() function so it only issues a SIGHUP if ntp_ready is set to 1.
So after a whole evening of plugging issues left and right, I *seem* to have a functional setup.
Bottom line: never say "oh, it's easy, here's the code from Tomato/DD-WRT/OpenWRT". That was an entire night spent just on a feature which, at a first glance, is half useless since I was having a hard time just finding a DNS zone that DID support dnssec. Even heavyweights such as google.com and microsoft.com don't.