]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix #574: unbound-checkconf reports fatal error if interface names
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Mon, 29 Nov 2021 13:59:39 +0000 (14:59 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Mon, 29 Nov 2021 13:59:39 +0000 (14:59 +0100)
  are used as value for interfaces:

doc/Changelog
smallapp/unbound-checkconf.c

index 63ab8def28bcf85c8a93defb469f6a150e9be598..a8b304d91244b74b6b02d0f5176e45dd7590321b 100644 (file)
@@ -2,6 +2,8 @@
        - Merge PR #570 from rex4539: Fix typos.
        - Fix for #570: regen aclocal.m4, fix configure.ac for spelling.
        - Fix to make python module opt_list use opt_list_in.
+       - Fix #574: unbound-checkconf reports fatal error if interface names
+         are used as value for interfaces:
 
 15 November 2021: Tom
        - Improve EDNS option handling, now also works for synthesised
index 52c15238c652a4d388e2bfc0e29f39425e067238..b88d010daf984136198ba93a2684e485b4ce9254 100644 (file)
@@ -334,19 +334,62 @@ interfacechecks(struct config_file* cfg)
        int d;
        struct sockaddr_storage a;
        socklen_t alen;
-       int i, j;
+       int i, j, i2, j2;
+       char*** resif = NULL;
+       int* num_resif = 0;
+
+       if(cfg->num_ifs != 0) {
+               resif = (char***)calloc(cfg->num_ifs, sizeof(char**));
+               num_resif = (int*)calloc(cfg->num_ifs, sizeof(int*));
+       }
        for(i=0; i<cfg->num_ifs; i++) {
-               if(!extstrtoaddr(cfg->ifs[i], &a, &alen)) {
-                       fatal_exit("cannot parse interface specified as '%s'",
-                               cfg->ifs[i]);
-               }
-               for(j=0; j<cfg->num_ifs; j++) {
-                       if(i!=j && strcmp(cfg->ifs[i], cfg->ifs[j])==0)
+               /* search for duplicates in IP or ifname arguments */
+               for(i2=0; i2<i; i2++) {
+                       if(strcmp(cfg->ifs[i], cfg->ifs[i2]) == 0) {
                                fatal_exit("interface: %s present twice, "
                                        "cannot bind same ports twice.",
                                        cfg->ifs[i]);
+                       }
+               }
+               if(!resolve_interface_names(&cfg->ifs[i], 1, NULL, &resif[i],
+                       &num_resif[i])) {
+                       fatal_exit("could not resolve interface names, for %s",
+                               cfg->ifs[i]);
+               }
+               /* search for duplicates in the returned addresses */
+               for(j=0; j<num_resif[i]; j++) {
+                       if(!extstrtoaddr(resif[i][j], &a, &alen)) {
+                               if(strcmp(cfg->ifs[i], resif[i][j]) != 0)
+                                       fatal_exit("cannot parse interface address '%s' from the interace specified as '%s'",
+                                               resif[i][j], cfg->ifs[i]);
+                               else
+                                       fatal_exit("cannot parse interface specified as '%s'",
+                                               cfg->ifs[i]);
+                       }
+                       for(i2=0; i2<i; i2++) {
+                               for(j2=0; j2<num_resif[i2]; j2++) {
+                                       if(strcmp(resif[i][j], resif[i2][j2])
+                                               == 0) {
+                                               char info1[1024], info2[1024];
+                                               if(strcmp(cfg->ifs[i], resif[i][j]) != 0)
+                                                       snprintf(info1, sizeof(info1), "address %s from interface: %s", resif[i][j], cfg->ifs[i]);
+                                               else    snprintf(info1, sizeof(info1), "interface: %s", cfg->ifs[i]);
+                                               if(strcmp(cfg->ifs[i2], resif[i2][j2]) != 0)
+                                                       snprintf(info2, sizeof(info2), "address %s from interface: %s", resif[i2][j2], cfg->ifs[i2]);
+                                               else    snprintf(info2, sizeof(info2), "interface: %s", cfg->ifs[i2]);
+                                               fatal_exit("%s present twice, cannot bind the same ports twice. The first entry is %s and the second is %s", resif[i][j], info2, info1);
+                                       }
+                               }
+                       }
                }
        }
+
+       for(i=0; i<cfg->num_ifs; i++) {
+               config_del_strarray(resif[i], num_resif[i]);
+       }
+       free(resif);
+       free(num_resif);
+
        for(i=0; i<cfg->num_out_ifs; i++) {
                if(!ipstrtoaddr(cfg->out_ifs[i], UNBOUND_DNS_PORT, &a, &alen) &&
                   !netblockstrtoaddr(cfg->out_ifs[i], UNBOUND_DNS_PORT, &a, &alen, &d)) {