[feature requests] dnsmasq safe-mode + TFTP

Issue #263 resolved
rs232 created an issue

After so many attempt on the dnsmasq mailing-list to raise awareness on how sensitive dnsmasq is to config (e.g. 1 typo and your process would simply abort with an error code) I’m giving up trying to push again this message. They don’t see the value in changing the current setup, I don’t see how this could ever be thought as a default-behavior. The only think I managed to achieve throughout the years was to have them introducing the tftp-no-fail command that allows the tftp part of config only to fail without aborting the whole dnsmasq process (e.g. because the root folder of TFTP becomes unavailable or something).

Now what I suggest we do within FT is to have a new option; let’s call it “safe-mode“. When safe-mode is set we ask the firmware to check after 1 minute the Save button was pressed on dnsmasq config-page if the dnsmasq-process is ractually unning or not. If not, restart the process excluding the content of custom-config. This latter is specifically where typos can be introduced. This action should be good enough to restore the basis services like name resolution, DHCP, etc.

This specifically would make it safer to apply custom configuration while operating remotely.


A second modification would be to add the 2 options for TFTP to the GUI e.g.:

[x] TFTP enabled

[ ___________________] TFTP root folder

making perhaps the tftp-no-fail implicitly when the tftp-enabled is set.

Comments (5)

  1. pedro repo owner

    Now what I suggest we do within FT is to have a new option; let’s call it “safe-mode“. When safe-mode is set we ask the firmware to check after 1 minute the Save button was pressed on dnsmasq config-page if the dnsmasq-process is ractually unning or not. If not, restart the process excluding the content of custom-config. This latter is specifically where typos can be introduced. This action should be good enough to restore the basis services like name resolution, DHCP, etc

    dnsmasq is restarted even now every 0,5 sec if it died, but of course without omitting custom config, except if “debug_norestart” in nvram contains word “dnsmasq”: https://bitbucket.org/pedro311/freshtomato-arm/src/f7dec3df55c2825419bb2a723331ab565f6726a6/release/src-rt-6.x.4708/router/rc/services.c#lines-648

    So it could be improved, ie. after 5th failed restart - omit custom configuration.

    A second modification would be to add the 2 options for TFTP to the GUI e.g.:

    [x] TFTP enabled

    So you want to add “enable-tftp” to command line option (if checked), with corresponding “tftp-root“ and “tftp-no-fail”?

  2. rs232 reporter

    Safe-mode:

    TL;DR: How about simply parse the logfile and look for “syntax error” or whatever the logs say when a typo is spotted? We could:

    a) preferred

    concept:
    dnsmasq --test -C /etc/dnsmasq.custom
    
    practical example:
    dnsmasq --test -C /etc/dnsmasq.custom >/dev/null 2>&1 || $(unlink custom dnsmasq config  and start the process without it)
    

    just after the save and act if OK is not seen → remove custom config file from next start

    b) (and/or) just, 2 seconds after the save was pressed, tail the logfile since the last dnsmasq restart. e.g.

     grep -n "Restarting dnsmasq" /var/log/messages | cut -f1 -d: | tail -1 | xargs -I num tail -n +num /var/log/messages
    

    and look for the syntax error message e.g..

    grep -n "Restarting dnsmasq" /var/log/messages | cut -f1 -d: | tail -1 | xargs -I num tail -n +num /var/log/messages | grep -q 'yntax' && echo 1 || echo 0
    

    So anything different from 0 would mean → exclude the custom config
    And yes… there’s also a dependency on the logging being enabled… that’s why option a looks much more straight forward.

    Long description:
    There are multiple factors in dnsmasq. The 0.5sec is indeed one factor but that control it’s a simple “runs or not”. In adblock v2 we have a routine called safe_dnsmasq_restart that monitors specifically the ownership of the dnsmasq process after a number of seconds.
    - root = not yet ready (or issue if this is taking too long; say 30 sec+)
    - nobody = fully started and operational
    So implementing a similar approach could be good. That said I’m concerned we shouldn’t interfere with this adblock routine (which triggers the adblock file trimming. The trimming can happen multiple time until the process changes ownership to nobody within 30 seconds. So it’s perhaps a bit more complex to have everything tight up together.

    TFTP:

    For TFTP, precisely as you described. I’m just not sure if this should go on the advanced/dhcpdns page or rather be a new menu entry next to e.g. FTP. Regardless of where this goes at GUI level there’s a second issue to be addressed: if dnsmasq is disabled we can’t just enable TFTP if you get what I mean. On a second thought having everything under the advanced/dhcpdns page we could grey-out “enable TFTP” at javascritp level if the “enable internal DNS” is not set. That I guess would work out from a user experience perspective..

  3. rs232 reporter

    About TFTP this is what I currently use in my custom-config:

    enable-tftp
    tftp-no-fail
    tftp-root=/mnt/sda1/TFTP
    dhcp-boot=pxelinux.0,,192.168.1.1

    So I would divide the TFTP in 3 specific options:

    Enable TFTP

    enable-tftp
    tftp-no-fail

    TFTP root path

    tftp-root=/mnt/sda1/xxxxxxx

    PXE support:

    dhcp-boot=pxelinux.0,,192.168.1.1

    This last one needs to be verified in multi bridge environment. e.g. can/should the command be repeated for each bridge e.g.

    dhcp-boot=pxelinux.0,,192.168.1.1

    dhcp-boot=pxelinux.0,,192.168.2.1

  4. rs232 reporter

    Ok from what I can tell an individual dhcp-boot directive is needed for each brx. So perhaps this can be achieved as follow:

    [ ] Enable TFTP (conditionally display the next 2 option)

    [_________________] TFTP root path

    [ ] Enable PXE support (conditionally displays the next options, one for each enabled bridge)

    [ ] LAN0

    [ ] LAN1

    ...

    I think we now have all the info needed for both dnsmasq config check and TFTP Server implementation.

    I see this fitting rather well under a new paragraph (just above “Dnsmasq Custom configuration” per se) e.g.

    TFTP Server


    The reason to be above custom config is because this latter affects everything related to DNS/DHCP/TFTP.

    A very final note: I would NOT change the advanced-dhcpdns.asp (as this would also break the wiki link) page name but we could indeed change the menu name only in the tomato.js e.g.

    from DHCP/DNS to DHCP/DNS/TFTP , assuming it fits into the menu of course.

  5. Log in to comment