diff mbox series

dnsmasq: 'ipset' config sections

Message ID 20201023050237.1531857-1-mezin.alexander@gmail.com
State Accepted
Headers show
Series dnsmasq: 'ipset' config sections | expand

Commit Message

Aleksandr Mezin Oct. 23, 2020, 5:02 a.m. UTC
Allow configuring ipsets with dedicated config sections:

    config ipset
        list name 'ss_rules_dst_forward'
        list name 'ss_rules6_dst_forward'
        list domain 't.me'
        list domain 'telegram.org'

instead of current, rather inconvenient syntax:

    config dnsmasq
        ...
        list ipset '/t.me/telegram.org/ss_rules_dst_forward,ss_rules6_dst_forward'

Current syntax will still continue to work though.

With this change, a LuCI GUI for DNS ipsets should be easy to implement.

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
---
 .../services/dnsmasq/files/dnsmasq.init       | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Aleksandr Mezin Nov. 9, 2020, 10:54 a.m. UTC | #1
Is something wrong with this patch? Should I CC someone to get the
patch reviewed? I'm unable to figure out who is the maintainer of
dnsmasq package

On Fri, Oct 23, 2020 at 11:03 AM Aleksandr Mezin
<mezin.alexander@gmail.com> wrote:
>
> Allow configuring ipsets with dedicated config sections:
>
>     config ipset
>         list name 'ss_rules_dst_forward'
>         list name 'ss_rules6_dst_forward'
>         list domain 't.me'
>         list domain 'telegram.org'
>
> instead of current, rather inconvenient syntax:
>
>     config dnsmasq
>         ...
>         list ipset '/t.me/telegram.org/ss_rules_dst_forward,ss_rules6_dst_forward'
>
> Current syntax will still continue to work though.
>
> With this change, a LuCI GUI for DNS ipsets should be easy to implement.
>
> Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
> ---
>  .../services/dnsmasq/files/dnsmasq.init       | 27 +++++++++++++++++++
>  1 file changed, 27 insertions(+)
>
> diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
> index 0fa3074f92..fff8f8f793 100644
> --- a/package/network/services/dnsmasq/files/dnsmasq.init
> +++ b/package/network/services/dnsmasq/files/dnsmasq.init
> @@ -769,6 +769,29 @@ dhcp_relay_add() {
>         fi
>  }
>
> +dnsmasq_ipset_add() {
> +       local cfg="$1"
> +       local ipsets domains
> +
> +       add_ipset() {
> +               ipsets="${ipsets:+$ipsets,}$1"
> +       }
> +
> +       add_domain() {
> +               # leading '/' is expected
> +               domains="$domains/$1"
> +       }
> +
> +       config_list_foreach "$cfg" "name" add_ipset
> +       config_list_foreach "$cfg" "domain" add_domain
> +
> +       if [ -z "$ipsets" ] || [ -z "$domains" ]; then
> +               return 0
> +       fi
> +
> +       xappend "--ipset=$domains/$ipsets"
> +}
> +
>  dnsmasq_start()
>  {
>         local cfg="$1"
> @@ -1056,6 +1079,10 @@ dnsmasq_start()
>         config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
>         echo >> $CONFIGFILE_TMP
>
> +       echo >> $CONFIGFILE_TMP
> +       config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
> +       echo >> $CONFIGFILE_TMP
> +
>         echo >> $CONFIGFILE_TMP
>         mv -f $CONFIGFILE_TMP $CONFIGFILE
>         mv -f $HOSTFILE_TMP $HOSTFILE
> --
> 2.29.0
>
Hans Dedecker Nov. 11, 2020, 7:50 p.m. UTC | #2
Hi,

On Mon, Nov 9, 2020 at 11:55 AM Aleksandr Mezin
<mezin.alexander@gmail.com> wrote:
>
> Is something wrong with this patch? Should I CC someone to get the
> patch reviewed? I'm unable to figure out who is the maintainer of
> dnsmasq package
Nothing wrong the patch as it looks fine; it just takes some time
before somebody finds time to review and test a patch.
I just applied the patch to master; thx

Hans
>
> On Fri, Oct 23, 2020 at 11:03 AM Aleksandr Mezin
> <mezin.alexander@gmail.com> wrote:
> >
> > Allow configuring ipsets with dedicated config sections:
> >
> >     config ipset
> >         list name 'ss_rules_dst_forward'
> >         list name 'ss_rules6_dst_forward'
> >         list domain 't.me'
> >         list domain 'telegram.org'
> >
> > instead of current, rather inconvenient syntax:
> >
> >     config dnsmasq
> >         ...
> >         list ipset '/t.me/telegram.org/ss_rules_dst_forward,ss_rules6_dst_forward'
> >
> > Current syntax will still continue to work though.
> >
> > With this change, a LuCI GUI for DNS ipsets should be easy to implement.
> >
> > Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
> > ---
> >  .../services/dnsmasq/files/dnsmasq.init       | 27 +++++++++++++++++++
> >  1 file changed, 27 insertions(+)
> >
> > diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
> > index 0fa3074f92..fff8f8f793 100644
> > --- a/package/network/services/dnsmasq/files/dnsmasq.init
> > +++ b/package/network/services/dnsmasq/files/dnsmasq.init
> > @@ -769,6 +769,29 @@ dhcp_relay_add() {
> >         fi
> >  }
> >
> > +dnsmasq_ipset_add() {
> > +       local cfg="$1"
> > +       local ipsets domains
> > +
> > +       add_ipset() {
> > +               ipsets="${ipsets:+$ipsets,}$1"
> > +       }
> > +
> > +       add_domain() {
> > +               # leading '/' is expected
> > +               domains="$domains/$1"
> > +       }
> > +
> > +       config_list_foreach "$cfg" "name" add_ipset
> > +       config_list_foreach "$cfg" "domain" add_domain
> > +
> > +       if [ -z "$ipsets" ] || [ -z "$domains" ]; then
> > +               return 0
> > +       fi
> > +
> > +       xappend "--ipset=$domains/$ipsets"
> > +}
> > +
> >  dnsmasq_start()
> >  {
> >         local cfg="$1"
> > @@ -1056,6 +1079,10 @@ dnsmasq_start()
> >         config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
> >         echo >> $CONFIGFILE_TMP
> >
> > +       echo >> $CONFIGFILE_TMP
> > +       config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
> > +       echo >> $CONFIGFILE_TMP
> > +
> >         echo >> $CONFIGFILE_TMP
> >         mv -f $CONFIGFILE_TMP $CONFIGFILE
> >         mv -f $HOSTFILE_TMP $HOSTFILE
> > --
> > 2.29.0
> >
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Aleksandr Mezin Nov. 11, 2020, 8:09 p.m. UTC | #3
On Thu, Nov 12, 2020 at 1:50 AM Hans Dedecker <dedeckeh@gmail.com> wrote:
> Nothing wrong the patch as it looks fine; it just takes some time
> before somebody finds time to review and test a patch.
> I just applied the patch to master; thx

Thank you. A few months ago, I tried to send the same patch as a pull
request on Github [1], and got no comments. So I decided to resubmit
it through the mailing list, and to be more annoying if nobody
responds.

[1] https://github.com/openwrt/openwrt/pull/3020
Aleksandr Mezin Nov. 12, 2020, 12:52 p.m. UTC | #4
By the way, this new config syntax should be documented somewhere, I guess?

On Thu, Nov 12, 2020 at 1:50 AM Hans Dedecker <dedeckeh@gmail.com> wrote:
>
> Hi,
>
> On Mon, Nov 9, 2020 at 11:55 AM Aleksandr Mezin
> <mezin.alexander@gmail.com> wrote:
> >
> > Is something wrong with this patch? Should I CC someone to get the
> > patch reviewed? I'm unable to figure out who is the maintainer of
> > dnsmasq package
> Nothing wrong the patch as it looks fine; it just takes some time
> before somebody finds time to review and test a patch.
> I just applied the patch to master; thx
>
> Hans
> >
> > On Fri, Oct 23, 2020 at 11:03 AM Aleksandr Mezin
> > <mezin.alexander@gmail.com> wrote:
> > >
> > > Allow configuring ipsets with dedicated config sections:
> > >
> > >     config ipset
> > >         list name 'ss_rules_dst_forward'
> > >         list name 'ss_rules6_dst_forward'
> > >         list domain 't.me'
> > >         list domain 'telegram.org'
> > >
> > > instead of current, rather inconvenient syntax:
> > >
> > >     config dnsmasq
> > >         ...
> > >         list ipset '/t.me/telegram.org/ss_rules_dst_forward,ss_rules6_dst_forward'
> > >
> > > Current syntax will still continue to work though.
> > >
> > > With this change, a LuCI GUI for DNS ipsets should be easy to implement.
> > >
> > > Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
> > > ---
> > >  .../services/dnsmasq/files/dnsmasq.init       | 27 +++++++++++++++++++
> > >  1 file changed, 27 insertions(+)
> > >
> > > diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
> > > index 0fa3074f92..fff8f8f793 100644
> > > --- a/package/network/services/dnsmasq/files/dnsmasq.init
> > > +++ b/package/network/services/dnsmasq/files/dnsmasq.init
> > > @@ -769,6 +769,29 @@ dhcp_relay_add() {
> > >         fi
> > >  }
> > >
> > > +dnsmasq_ipset_add() {
> > > +       local cfg="$1"
> > > +       local ipsets domains
> > > +
> > > +       add_ipset() {
> > > +               ipsets="${ipsets:+$ipsets,}$1"
> > > +       }
> > > +
> > > +       add_domain() {
> > > +               # leading '/' is expected
> > > +               domains="$domains/$1"
> > > +       }
> > > +
> > > +       config_list_foreach "$cfg" "name" add_ipset
> > > +       config_list_foreach "$cfg" "domain" add_domain
> > > +
> > > +       if [ -z "$ipsets" ] || [ -z "$domains" ]; then
> > > +               return 0
> > > +       fi
> > > +
> > > +       xappend "--ipset=$domains/$ipsets"
> > > +}
> > > +
> > >  dnsmasq_start()
> > >  {
> > >         local cfg="$1"
> > > @@ -1056,6 +1079,10 @@ dnsmasq_start()
> > >         config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
> > >         echo >> $CONFIGFILE_TMP
> > >
> > > +       echo >> $CONFIGFILE_TMP
> > > +       config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
> > > +       echo >> $CONFIGFILE_TMP
> > > +
> > >         echo >> $CONFIGFILE_TMP
> > >         mv -f $CONFIGFILE_TMP $CONFIGFILE
> > >         mv -f $HOSTFILE_TMP $HOSTFILE
> > > --
> > > 2.29.0
> > >
> >
> > _______________________________________________
> > openwrt-devel mailing list
> > openwrt-devel@lists.openwrt.org
> > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Hans Dedecker Nov. 12, 2020, 4:59 p.m. UTC | #5
On Thu, Nov 12, 2020 at 1:52 PM Aleksandr Mezin
<mezin.alexander@gmail.com> wrote:
>
> By the way, this new config syntax should be documented somewhere, I guess?
It would be very helpful if the new config syntax is documented in
https://openwrt.org/docs/guide-user/base-system/dhcp

Hans
>
> On Thu, Nov 12, 2020 at 1:50 AM Hans Dedecker <dedeckeh@gmail.com> wrote:
> >
> > Hi,
> >
> > On Mon, Nov 9, 2020 at 11:55 AM Aleksandr Mezin
> > <mezin.alexander@gmail.com> wrote:
> > >
> > > Is something wrong with this patch? Should I CC someone to get the
> > > patch reviewed? I'm unable to figure out who is the maintainer of
> > > dnsmasq package
> > Nothing wrong the patch as it looks fine; it just takes some time
> > before somebody finds time to review and test a patch.
> > I just applied the patch to master; thx
> >
> > Hans
> > >
> > > On Fri, Oct 23, 2020 at 11:03 AM Aleksandr Mezin
> > > <mezin.alexander@gmail.com> wrote:
> > > >
> > > > Allow configuring ipsets with dedicated config sections:
> > > >
> > > >     config ipset
> > > >         list name 'ss_rules_dst_forward'
> > > >         list name 'ss_rules6_dst_forward'
> > > >         list domain 't.me'
> > > >         list domain 'telegram.org'
> > > >
> > > > instead of current, rather inconvenient syntax:
> > > >
> > > >     config dnsmasq
> > > >         ...
> > > >         list ipset '/t.me/telegram.org/ss_rules_dst_forward,ss_rules6_dst_forward'
> > > >
> > > > Current syntax will still continue to work though.
> > > >
> > > > With this change, a LuCI GUI for DNS ipsets should be easy to implement.
> > > >
> > > > Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
> > > > ---
> > > >  .../services/dnsmasq/files/dnsmasq.init       | 27 +++++++++++++++++++
> > > >  1 file changed, 27 insertions(+)
> > > >
> > > > diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
> > > > index 0fa3074f92..fff8f8f793 100644
> > > > --- a/package/network/services/dnsmasq/files/dnsmasq.init
> > > > +++ b/package/network/services/dnsmasq/files/dnsmasq.init
> > > > @@ -769,6 +769,29 @@ dhcp_relay_add() {
> > > >         fi
> > > >  }
> > > >
> > > > +dnsmasq_ipset_add() {
> > > > +       local cfg="$1"
> > > > +       local ipsets domains
> > > > +
> > > > +       add_ipset() {
> > > > +               ipsets="${ipsets:+$ipsets,}$1"
> > > > +       }
> > > > +
> > > > +       add_domain() {
> > > > +               # leading '/' is expected
> > > > +               domains="$domains/$1"
> > > > +       }
> > > > +
> > > > +       config_list_foreach "$cfg" "name" add_ipset
> > > > +       config_list_foreach "$cfg" "domain" add_domain
> > > > +
> > > > +       if [ -z "$ipsets" ] || [ -z "$domains" ]; then
> > > > +               return 0
> > > > +       fi
> > > > +
> > > > +       xappend "--ipset=$domains/$ipsets"
> > > > +}
> > > > +
> > > >  dnsmasq_start()
> > > >  {
> > > >         local cfg="$1"
> > > > @@ -1056,6 +1079,10 @@ dnsmasq_start()
> > > >         config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
> > > >         echo >> $CONFIGFILE_TMP
> > > >
> > > > +       echo >> $CONFIGFILE_TMP
> > > > +       config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
> > > > +       echo >> $CONFIGFILE_TMP
> > > > +
> > > >         echo >> $CONFIGFILE_TMP
> > > >         mv -f $CONFIGFILE_TMP $CONFIGFILE
> > > >         mv -f $HOSTFILE_TMP $HOSTFILE
> > > > --
> > > > 2.29.0
> > > >
> > >
> > > _______________________________________________
> > > openwrt-devel mailing list
> > > openwrt-devel@lists.openwrt.org
> > > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
diff mbox series

Patch

diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index 0fa3074f92..fff8f8f793 100644
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -769,6 +769,29 @@  dhcp_relay_add() {
 	fi
 }
 
+dnsmasq_ipset_add() {
+	local cfg="$1"
+	local ipsets domains
+
+	add_ipset() {
+		ipsets="${ipsets:+$ipsets,}$1"
+	}
+
+	add_domain() {
+		# leading '/' is expected
+		domains="$domains/$1"
+	}
+
+	config_list_foreach "$cfg" "name" add_ipset
+	config_list_foreach "$cfg" "domain" add_domain
+
+	if [ -z "$ipsets" ] || [ -z "$domains" ]; then
+		return 0
+	fi
+
+	xappend "--ipset=$domains/$ipsets"
+}
+
 dnsmasq_start()
 {
 	local cfg="$1"
@@ -1056,6 +1079,10 @@  dnsmasq_start()
 	config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
 	echo >> $CONFIGFILE_TMP
 
+	echo >> $CONFIGFILE_TMP
+	config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
+	echo >> $CONFIGFILE_TMP
+
 	echo >> $CONFIGFILE_TMP
 	mv -f $CONFIGFILE_TMP $CONFIGFILE
 	mv -f $HOSTFILE_TMP $HOSTFILE