summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-09-03 16:05:48 +0200
committerLennart Poettering <lennart@poettering.net>2024-09-11 17:00:03 +0200
commit8e1c3459217792fb6b66673c38603b2e8bfac6fb (patch)
tree15bab6e8fd0306ce581f3a9a2c8f080323e1dea5 /src/resolve
parentresolved: move resolved_dnssd_gperf_lookup() prototype definition to resolved... (diff)
downloadsystemd-8e1c3459217792fb6b66673c38603b2e8bfac6fb.tar.xz
systemd-8e1c3459217792fb6b66673c38603b2e8bfac6fb.zip
resolved: move dnssd parsers to resolved-dnssd.c
Let's keep only the parsers for the main config in resolved-conf.c
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/resolved-conf.c221
-rw-r--r--src/resolve/resolved-conf.h4
-rw-r--r--src/resolve/resolved-dnssd.c222
-rw-r--r--src/resolve/resolved-dnssd.h5
4 files changed, 227 insertions, 225 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index 65a5611d09..9d70d98d1d 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -209,227 +209,6 @@ int config_parse_search_domains(
return 0;
}
-int config_parse_dnssd_service_name(
- const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- static const Specifier specifier_table[] = {
- { 'a', specifier_architecture, NULL },
- { 'b', specifier_boot_id, NULL },
- { 'B', specifier_os_build_id, NULL },
- { 'H', specifier_hostname, NULL }, /* We will use specifier_dnssd_hostname(). */
- { 'm', specifier_machine_id, NULL },
- { 'o', specifier_os_id, NULL },
- { 'v', specifier_kernel_release, NULL },
- { 'w', specifier_os_version_id, NULL },
- { 'W', specifier_os_variant_id, NULL },
- {}
- };
- DnssdService *s = ASSERT_PTR(userdata);
- _cleanup_free_ char *name = NULL;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- if (isempty(rvalue)) {
- s->name_template = mfree(s->name_template);
- return 0;
- }
-
- r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, NULL, &name);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid service instance name template '%s', ignoring assignment: %m", rvalue);
- return 0;
- }
-
- if (!dns_service_name_is_valid(name)) {
- log_syntax(unit, LOG_WARNING, filename, line, 0,
- "Service instance name template '%s' renders to invalid name '%s'. Ignoring assignment.",
- rvalue, name);
- return 0;
- }
-
- return free_and_strdup_warn(&s->name_template, rvalue);
-}
-
-int config_parse_dnssd_service_type(
- const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- DnssdService *s = ASSERT_PTR(userdata);
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- if (isempty(rvalue)) {
- s->type = mfree(s->type);
- return 0;
- }
-
- if (!dnssd_srv_type_is_valid(rvalue)) {
- log_syntax(unit, LOG_WARNING, filename, line, 0, "Service type is invalid. Ignoring.");
- return 0;
- }
-
- r = free_and_strdup(&s->type, rvalue);
- if (r < 0)
- return log_oom();
-
- return 0;
-}
-
-int config_parse_dnssd_service_subtype(
- const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- DnssdService *s = ASSERT_PTR(userdata);
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- if (isempty(rvalue)) {
- s->subtype = mfree(s->subtype);
- return 0;
- }
-
- if (!dns_subtype_name_is_valid(rvalue)) {
- log_syntax(unit, LOG_WARNING, filename, line, 0, "Service subtype is invalid. Ignoring.");
- return 0;
- }
-
- return free_and_strdup_warn(&s->subtype, rvalue);
-}
-
-int config_parse_dnssd_txt(
- const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- _cleanup_(dnssd_txtdata_freep) DnssdTxtData *txt_data = NULL;
- DnssdService *s = ASSERT_PTR(userdata);
- DnsTxtItem *last = NULL;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- if (isempty(rvalue)) {
- /* Flush out collected items */
- s->txt_data_items = dnssd_txtdata_free_all(s->txt_data_items);
- return 0;
- }
-
- txt_data = new0(DnssdTxtData, 1);
- if (!txt_data)
- return log_oom();
-
- for (;;) {
- _cleanup_free_ char *word = NULL, *key = NULL, *value = NULL;
- _cleanup_free_ void *decoded = NULL;
- size_t length = 0;
- DnsTxtItem *i;
- int r;
-
- r = extract_first_word(&rvalue, &word, NULL,
- EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_RELAX);
- if (r == 0)
- break;
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
- return 0;
- }
-
- r = split_pair(word, "=", &key, &value);
- if (r == -ENOMEM)
- return log_oom();
- if (r == -EINVAL)
- key = TAKE_PTR(word);
-
- if (!ascii_is_valid(key)) {
- log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid key, ignoring: %s", key);
- continue;
- }
-
- switch (ltype) {
-
- case DNS_TXT_ITEM_DATA:
- if (value) {
- r = unbase64mem(value, &decoded, &length);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid base64 encoding, ignoring: %s", value);
- continue;
- }
- }
-
- r = dnssd_txt_item_new_from_data(key, decoded, length, &i);
- if (r < 0)
- return log_oom();
- break;
-
- case DNS_TXT_ITEM_TEXT:
- r = dnssd_txt_item_new_from_string(key, value, &i);
- if (r < 0)
- return log_oom();
- break;
-
- default:
- assert_not_reached();
- }
-
- LIST_INSERT_AFTER(items, txt_data->txts, last, i);
- last = i;
- }
-
- if (txt_data->txts) {
- LIST_PREPEND(items, s->txt_data_items, txt_data);
- TAKE_PTR(txt_data);
- }
-
- return 0;
-}
-
int config_parse_dns_stub_listener_extra(
const char *unit,
const char *filename,
diff --git a/src/resolve/resolved-conf.h b/src/resolve/resolved-conf.h
index 517254bcc0..ce280cb0a3 100644
--- a/src/resolve/resolved-conf.h
+++ b/src/resolve/resolved-conf.h
@@ -23,8 +23,4 @@ const struct ConfigPerfItem* resolved_gperf_lookup(const char *key, GPERF_LEN_TY
CONFIG_PARSER_PROTOTYPE(config_parse_dns_servers);
CONFIG_PARSER_PROTOTYPE(config_parse_search_domains);
CONFIG_PARSER_PROTOTYPE(config_parse_dns_stub_listener_mode);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_name);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_subtype);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_type);
-CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_txt);
CONFIG_PARSER_PROTOTYPE(config_parse_dns_stub_listener_extra);
diff --git a/src/resolve/resolved-dnssd.c b/src/resolve/resolved-dnssd.c
index 5f66e3c501..00fd725044 100644
--- a/src/resolve/resolved-dnssd.c
+++ b/src/resolve/resolved-dnssd.c
@@ -3,6 +3,7 @@
#include "conf-files.h"
#include "conf-parser.h"
#include "constants.h"
+#include "hexdecoct.h"
#include "path-util.h"
#include "resolved-conf.h"
#include "resolved-dns-rr.h"
@@ -402,3 +403,224 @@ int dnssd_signal_conflict(Manager *manager, const char *name) {
return 0;
}
+
+int config_parse_dnssd_service_name(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ static const Specifier specifier_table[] = {
+ { 'a', specifier_architecture, NULL },
+ { 'b', specifier_boot_id, NULL },
+ { 'B', specifier_os_build_id, NULL },
+ { 'H', specifier_hostname, NULL }, /* We will use specifier_dnssd_hostname(). */
+ { 'm', specifier_machine_id, NULL },
+ { 'o', specifier_os_id, NULL },
+ { 'v', specifier_kernel_release, NULL },
+ { 'w', specifier_os_version_id, NULL },
+ { 'W', specifier_os_variant_id, NULL },
+ {}
+ };
+ DnssdService *s = ASSERT_PTR(userdata);
+ _cleanup_free_ char *name = NULL;
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ s->name_template = mfree(s->name_template);
+ return 0;
+ }
+
+ r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, NULL, &name);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Invalid service instance name template '%s', ignoring assignment: %m", rvalue);
+ return 0;
+ }
+
+ if (!dns_service_name_is_valid(name)) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "Service instance name template '%s' renders to invalid name '%s'. Ignoring assignment.",
+ rvalue, name);
+ return 0;
+ }
+
+ return free_and_strdup_warn(&s->name_template, rvalue);
+}
+
+int config_parse_dnssd_service_type(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ DnssdService *s = ASSERT_PTR(userdata);
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ s->type = mfree(s->type);
+ return 0;
+ }
+
+ if (!dnssd_srv_type_is_valid(rvalue)) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0, "Service type is invalid. Ignoring.");
+ return 0;
+ }
+
+ r = free_and_strdup(&s->type, rvalue);
+ if (r < 0)
+ return log_oom();
+
+ return 0;
+}
+
+int config_parse_dnssd_service_subtype(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ DnssdService *s = ASSERT_PTR(userdata);
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ s->subtype = mfree(s->subtype);
+ return 0;
+ }
+
+ if (!dns_subtype_name_is_valid(rvalue)) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0, "Service subtype is invalid. Ignoring.");
+ return 0;
+ }
+
+ return free_and_strdup_warn(&s->subtype, rvalue);
+}
+
+int config_parse_dnssd_txt(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ _cleanup_(dnssd_txtdata_freep) DnssdTxtData *txt_data = NULL;
+ DnssdService *s = ASSERT_PTR(userdata);
+ DnsTxtItem *last = NULL;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ /* Flush out collected items */
+ s->txt_data_items = dnssd_txtdata_free_all(s->txt_data_items);
+ return 0;
+ }
+
+ txt_data = new0(DnssdTxtData, 1);
+ if (!txt_data)
+ return log_oom();
+
+ for (;;) {
+ _cleanup_free_ char *word = NULL, *key = NULL, *value = NULL;
+ _cleanup_free_ void *decoded = NULL;
+ size_t length = 0;
+ DnsTxtItem *i;
+ int r;
+
+ r = extract_first_word(&rvalue, &word, NULL,
+ EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_RELAX);
+ if (r == 0)
+ break;
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
+ return 0;
+ }
+
+ r = split_pair(word, "=", &key, &value);
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r == -EINVAL)
+ key = TAKE_PTR(word);
+
+ if (!ascii_is_valid(key)) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid key, ignoring: %s", key);
+ continue;
+ }
+
+ switch (ltype) {
+
+ case DNS_TXT_ITEM_DATA:
+ if (value) {
+ r = unbase64mem(value, &decoded, &length);
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Invalid base64 encoding, ignoring: %s", value);
+ continue;
+ }
+ }
+
+ r = dnssd_txt_item_new_from_data(key, decoded, length, &i);
+ if (r < 0)
+ return log_oom();
+ break;
+
+ case DNS_TXT_ITEM_TEXT:
+ r = dnssd_txt_item_new_from_string(key, value, &i);
+ if (r < 0)
+ return log_oom();
+ break;
+
+ default:
+ assert_not_reached();
+ }
+
+ LIST_INSERT_AFTER(items, txt_data->txts, last, i);
+ last = i;
+ }
+
+ if (txt_data->txts) {
+ LIST_PREPEND(items, s->txt_data_items, txt_data);
+ TAKE_PTR(txt_data);
+ }
+
+ return 0;
+}
diff --git a/src/resolve/resolved-dnssd.h b/src/resolve/resolved-dnssd.h
index 06ad1f9705..8aaa9da748 100644
--- a/src/resolve/resolved-dnssd.h
+++ b/src/resolve/resolved-dnssd.h
@@ -68,3 +68,8 @@ int dnssd_update_rrs(DnssdService *s);
int dnssd_signal_conflict(Manager *manager, const char *name);
const struct ConfigPerfItem* resolved_dnssd_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
+
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_name);
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_subtype);
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_type);
+CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_txt);