Skip to content

Improving integration with the OpenWrt UCI framework #151

@languagegame

Description

@languagegame

Great program.

Here are some ideas to make the program more integrated/dynamic with the rest of Openwrt. Some of these ideas may be easier to implement than others, so this is more a wishlist

1) Append option confdir to the selected dnsmasq instance for ad blocking (if such option does not already exist)
During the current setup process, the code pulls dnsmasq configuration using /etc/init.d/dnsmasq info and then parses it for things like the list of dnsmasq instances, confdir folders and names.
Here is an alternate way that likely requires much less code and would have some other benefits. Use /etc/config/dhcp itself to parse the configuration of dnsmasq. This would require that the confdir option be set explicitly for the selected dnsmasq instance for adblocking, as I don't believe Openwrt sets this option by default on the initial installation. So the setup code would parse /etc/config/dhcp for the list of dndmsasq instances, and once the user selects the instance(s) for ad blocking, the setup program would append an option with the confdir like:
uci set dhcp.@dnsmasq[0].confdir='/tmp/dnsmasq.adblock-lean.d'
uci commit
This has many possible advantages:

  • The user doesn't have to run adblock-lean setup again if they change the confdir later in /etc/config/dhcp
  • Fewer configuration values for adblock-lean are needed. The program now can just use DNSMASQ_INDEX to get the confdir later. It does not need to store DNSMASQ_INSTANCE or DNSMASQ_CONF_D, so two less configuration values needed.
  • Eliminates a bunch of JSON parsing code from adblock-lean, as the current code has to parse through the JSON output from /etc/init.d/dnsmasq info` whereas now the dnsmasq configuration can all be simply read from the UCI configuration
  • Avoids possible race condition. By having adblock-lean read the dnsmasq configuration from the Openwrt UCI system, adblock-lean could potentially download and store the blocklists in the right conf-dir even before dnsmasq is initialized

If there is a concern about appending another option to the dhcp configuration file in the Openwrt UCI Configuration System, adblock-lean is already appending an option for addnmount to enable blocklist decompression. So it would be adding 2 options to dhcp instead of just addnmount.
If there is a concern about changing the default confdir folder for the selected instance of dnsmasq, the default folder is already rather arbitrary so might as well be declared explicitly

2) Allow user to select multiple dnsmasq instances for adblocking.
I have multiple dnsmasq instances running on Openwrt (think kid safe parental control vs. non kid safe). I want both instances to use the same blocklist for ad blocking. This only requires two lines of configuraiton for each instance. So the suggestion would be to have the user select one or more dnsmasq instances in the setup process, and then adblock-lean's setup program would append two options to /etc/config/dhcp for each instance. For example:
uci add_list dhcp.@dnsmasq[0].addnmount='/bin/busybox'
uci add_list dhcp.@dnsmasq[0].addnmount='/tmp/dnsmasq.adblock-lean.d'
uci add_list dhcp.@dnsmasq[1].addnmount='/bin/busybox'
uci add_list dhcp.@dnsmasq[1].addnmount='/tmp/dnsmasq.adblock-lean.d'
This allows both instances to use the same blocklist by adblock-lean

3) Use the Openwrt UCI system for adblock-lean configuration instead of a proprietary INI file.
Given that most of Openwrt's configuration uses the UCI system, it would be nice for adblock-lean to also use this format for the configuration file. This would allow users to use the standard uci commands to easily get/set/delete configuration for adblock-lean in the same way as the rest of the Openwrt configuration (and many other Openwrt packages). For example, adding a new blocklist would be just:
uci add_list adblock-lean.adblock.blocklist_urls='https://raw.githubusercontent.com/hagezi/dns-blocklists/main/wildcard/pro-onlydomains.txt'
uci commit
My guess is this is not easy to change in adblock lean, but if so, a uci configuration file could be generated in /etc/config/adblock-lean as follows:

config adblock
option whitelist_mode '0'
# support multiple lists
list blocklist_urls 'https://raw.githubusercontent.com/hagezi/dns-blocklists/main/wildcard/pro-onlydomains.txt'
list blocklist_urls 'https://raw.githubusercontent.com/hagezi/dns-blocklists/main/wildcard/tif-onlydomains.txt'
list blocklist_ipv4_urls ''
list allowlist_urls ''
list dnsmasq_blocklist_urls ''
list dnsmasq_blocklist_ipv4_urls ''
list dnsmasq_allowlist_urls ''
option local_allowlist_path '/etc/adblock-lean/allowlist'
option local_blocklist_path '/etc/adblock-lean/blocklist'
list test_domains 'google.com'. #support multiple test domains as a list
list test_domains 'microsoft.com'
list test_domains 'amazon.com'
option list_part_failed_action 'SKIP'
option max_download_retries '3'
option min_good_line_count '340000'
option min_blocklist_part_line_count '1'
option min_blocklist_ipv4_part_line_count '1'
option min_allowlist_part_line_count '1'
option max_file_part_size_KB '24000'
option max_blocklist_file_size_KB '29000'
option deduplication '1'
option use_compression '1'
option unload_blocklist_before_update 'auto'
option boot_start_delay_s '10'
option MAX_PARALLEL_JOBS 'auto'
option custom_script ''
option cron_schedule '0 5 * * *'
# support multiple dnsmasq instances for ad blocking as a list
list DNSMASQ_INDEX '0'
list DNSMASQ_INDEX '1'

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions