I know this forum is not for hacking or discussion of custom f/w for DLink products, and fixing a bug perhaps falls into a gray area, so if I'm not supposed to write about this here please let me know - I don't want to break any forum rules.
First of all, this is how I edited and tested the changes:
Whenever an interface comes up it raises the UPDATERESOLV event. This launches the script /etc/events/UPDATERESOLVE.sh, which in turn removes the DNS routes, launches UPDATERESOLV.php and adds the routes back again (via scripts created by UPDATERESOLV.php).
However /etc is on a read-only file system, so first I copied the files to /var which is a ramdisk (and flagged them as executable):
cp /etc/events/UPDATERESOLV* /var
chmod 755 /var/UPDATERESOLV*
Execute the script and check the result:
/var/UPDATERESOLV.sh
cat /etc/resolv.conf
Now how to easily edit and run the script? Fortunately the DIR-645 has a USB port. Just plug in a memory stick (FAT32) and it is automatically mounted as /var/tmp/storage/SanDisk_Cruzer_A1071 (or a similar name). It is the first time I've plugged in a memory stick, and I was surprised to see it automatically pop up on my Mac as a network drive called DIR-645 without me having to do anything. I think I already installed the SharePoint Plus utility that must have done that for me.
Now just copy the files to the memory stick:
cp /var/UPDATERESOLV* /var/tmp/storage/SanDisk_Cruzer_A1071
Then open them on my Mac using XCode (free in the AppStore) and edit them.
First change the path in the UPDATERESOLV.sh script from /etc/events/UPDATERESOLV.php to /var/UPDATERESOLV.php.
Then make the changes in the php file itself. Odd cut down version of PHP - it does not allow things like parenthesis in an if statement to group logical operators...
Then copy the files back to /var and run it again until all is working as it should.
cp /var/tmp/storage/SanDisk_Cruzer_A1071/UPDATERESOLV* /var
/var/UPDATERESOLV.sh
Of course when the connection is restarted the original scripts run and not my version. To replace those read-only files I have to now build a new firmware.bin file (by editing the same file there) and upgrade the router. I'll have time on the weekend to do that. How? Just Google firmware-mod-kit and you will find all the info and tools described there (one has to use the newer version of the scripts with -ng in the name).