From: Daniel Salzman Date: Fri, 13 Jun 2025 05:29:04 +0000 (+0200) Subject: utils: add class aliases INTERNET and CHAOS X-Git-Tag: v3.5.0~61^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82df13121e684fc1b4142ea8bc7438c4291d4f22;p=thirdparty%2Fknot-dns.git utils: add class aliases INTERNET and CHAOS --- diff --git a/src/libknot/descriptor.c b/src/libknot/descriptor.c index 61b16cf6ca..dcd0eda264 100644 --- a/src/libknot/descriptor.c +++ b/src/libknot/descriptor.c @@ -11,13 +11,13 @@ #include "libknot/descriptor.h" /*! - * \brief Table with DNS classes. + * \brief Table with supported DNS classes. */ -static const char* dns_classes[] = { - [KNOT_CLASS_IN] = "IN", - [KNOT_CLASS_CH] = "CH", - [KNOT_CLASS_NONE] = "NONE", - [KNOT_CLASS_ANY] = "ANY" +static const char* dns_classes[][2] = { + [KNOT_CLASS_IN] = { "IN", "INTERNET" }, + [KNOT_CLASS_CH] = { "CH", "CHAOS" }, + [KNOT_CLASS_NONE] = { "NONE" }, + [KNOT_CLASS_ANY] = { "ANY" }, }; /*! @@ -265,8 +265,8 @@ int knot_rrclass_to_string(const uint16_t rrclass, int ret; - if (rrclass <= KNOT_CLASS_ANY && dns_classes[rrclass] != NULL) { - ret = snprintf(out, out_len, "%s", dns_classes[rrclass]); + if (rrclass <= KNOT_CLASS_ANY && dns_classes[rrclass][0] != NULL) { + ret = snprintf(out, out_len, "%s", dns_classes[rrclass][0]); } else { ret = snprintf(out, out_len, "CLASS%u", rrclass); } @@ -291,8 +291,9 @@ int knot_rrclass_from_string(const char *name, uint16_t *num) // Try to find the name in classes table. for (i = 0; i <= KNOT_CLASS_ANY; i++) { - if (dns_classes[i] != NULL && - strcasecmp(dns_classes[i], name) == 0) { + const char **row = dns_classes[i]; + if ((row[0] != NULL && strcasecmp(row[0], name) == 0) || + (row[1] != NULL && strcasecmp(row[1], name) == 0)) { *num = i; return 0; } diff --git a/tests/libknot/test_descriptor.c b/tests/libknot/test_descriptor.c index a71e48fada..7c10fd63fa 100644 --- a/tests/libknot/test_descriptor.c +++ b/tests/libknot/test_descriptor.c @@ -167,6 +167,9 @@ int main(int argc, char *argv[]) ret = knot_rrclass_from_string("In", &num); ok(ret != -1, "get In num ret"); ok(num == 1, "get In num"); + ret = knot_rrclass_from_string("Internet", &num); + ok(ret != -1, "get In num ret"); + ok(num == 1, "get In num"); // 22. ANY ret = knot_rrclass_from_string("ANY", &num);