Allow overriding of ubus service name.

Same as for the dbus, allow specifying ubus service name (namespace) on
the command line as an optional argument to --enable-ubus option.

Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
This commit is contained in:
Oldřich Jedlička
2020-03-20 22:18:57 +01:00
committed by Simon Kelley
parent b43585c34b
commit d162bee356
5 changed files with 20 additions and 6 deletions

View File

@@ -366,10 +366,13 @@ been built with DBus support. If the service name is given, dnsmasq
provides service at that name, rather than the default which is provides service at that name, rather than the default which is
.B uk.org.thekelleys.dnsmasq .B uk.org.thekelleys.dnsmasq
.TP .TP
.B --enable-ubus .B --enable-ubus[=<service-name>]
Enable dnsmasq UBus interface. It sends notifications via UBus on Enable dnsmasq UBus interface. It sends notifications via UBus on
DHCPACK and DHCPRELEASE events. Furthermore it offers metrics. DHCPACK and DHCPRELEASE events. Furthermore it offers metrics.
Requires that dnsmasq has been built with UBus support. Requires that dnsmasq has been built with UBus support. If the service
name is given, dnsmasq provides service at that namespace, rather than
the default which is
.B dnsmasq
.TP .TP
.B \-o, --strict-order .B \-o, --strict-order
By default, dnsmasq will send queries to any of the upstream servers By default, dnsmasq will send queries to any of the upstream servers

View File

@@ -50,6 +50,7 @@
#define RANDFILE "/dev/urandom" #define RANDFILE "/dev/urandom"
#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */ #define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq" #define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
#define DNSMASQ_UBUS_NAME "dnsmasq" /* Default - may be overridden by config */
#define AUTH_TTL 600 /* default TTL for auth DNS */ #define AUTH_TTL 600 /* default TTL for auth DNS */
#define SOA_REFRESH 1200 /* SOA refresh default */ #define SOA_REFRESH 1200 /* SOA refresh default */
#define SOA_RETRY 180 /* SOA retry default */ #define SOA_RETRY 180 /* SOA retry default */

View File

@@ -1063,6 +1063,7 @@ extern struct daemon {
unsigned int duid_enterprise, duid_config_len; unsigned int duid_enterprise, duid_config_len;
unsigned char *duid_config; unsigned char *duid_config;
char *dbus_name; char *dbus_name;
char *ubus_name;
char *dump_file; char *dump_file;
int dump_mask; int dump_mask;
unsigned long soa_sn, soa_refresh, soa_retry, soa_expiry; unsigned long soa_sn, soa_refresh, soa_retry, soa_expiry;

View File

@@ -238,7 +238,7 @@ static const struct myoption opts[] =
{ "caa-record", 1, 0 , LOPT_CAA }, { "caa-record", 1, 0 , LOPT_CAA },
{ "dns-rr", 1, 0, LOPT_RR }, { "dns-rr", 1, 0, LOPT_RR },
{ "enable-dbus", 2, 0, '1' }, { "enable-dbus", 2, 0, '1' },
{ "enable-ubus", 0, 0, LOPT_UBUS }, { "enable-ubus", 2, 0, LOPT_UBUS },
{ "bootp-dynamic", 2, 0, '3' }, { "bootp-dynamic", 2, 0, '3' },
{ "dhcp-mac", 1, 0, '4' }, { "dhcp-mac", 1, 0, '4' },
{ "no-ping", 0, 0, '5' }, { "no-ping", 0, 0, '5' },
@@ -428,7 +428,7 @@ static struct {
{ 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL }, { 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL },
{ 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE }, { 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE },
{ '1', ARG_ONE, "[=<busname>]", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL }, { '1', ARG_ONE, "[=<busname>]", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL },
{ LOPT_UBUS, OPT_UBUS, NULL, gettext_noop("Enable the UBus interface."), NULL }, { LOPT_UBUS, ARG_ONE, "[=<busname>]", gettext_noop("Enable the UBus interface."), NULL },
{ '2', ARG_DUP, "<interface>", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL }, { '2', ARG_DUP, "<interface>", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL },
{ '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL }, { '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL },
{ '4', ARG_DUP, "set:<tag>,<mac address>", gettext_noop("Map MAC address (with wildcards) to option set."), NULL }, { '4', ARG_DUP, "set:<tag>,<mac address>", gettext_noop("Map MAC address (with wildcards) to option set."), NULL },
@@ -1882,6 +1882,14 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
daemon->dbus_name = DNSMASQ_SERVICE; daemon->dbus_name = DNSMASQ_SERVICE;
break; break;
case LOPT_UBUS: /* --enable-ubus */
set_option_bool(OPT_UBUS);
if (arg)
daemon->ubus_name = opt_string_alloc(arg);
else
daemon->ubus_name = DNSMASQ_UBUS_NAME;
break;
case '8': /* --log-facility */ case '8': /* --log-facility */
/* may be a filename */ /* may be a filename */
if (strchr(arg, '/') || strcmp (arg, "-") == 0) if (strchr(arg, '/') || strcmp (arg, "-") == 0)

View File

@@ -38,7 +38,7 @@ static struct ubus_object_type ubus_object_type =
UBUS_OBJECT_TYPE("dnsmasq", ubus_object_methods); UBUS_OBJECT_TYPE("dnsmasq", ubus_object_methods);
static struct ubus_object ubus_object = { static struct ubus_object ubus_object = {
.name = "dnsmasq", .name = NULL,
.type = &ubus_object_type, .type = &ubus_object_type,
.methods = ubus_object_methods, .methods = ubus_object_methods,
.n_methods = ARRAY_SIZE(ubus_object_methods), .n_methods = ARRAY_SIZE(ubus_object_methods),
@@ -94,6 +94,7 @@ void ubus_init()
return; return;
} }
ubus_object.name = daemon->ubus_name;
ret = ubus_add_object(ubus, &ubus_object); ret = ubus_add_object(ubus, &ubus_object);
if (ret) if (ret)
{ {