]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
move -T parsing to its own function
authorMark Andrews <marka@isc.org>
Wed, 6 Jun 2018 03:26:59 +0000 (13:26 +1000)
committerMark Andrews <marka@isc.org>
Wed, 6 Jun 2018 05:21:09 +0000 (15:21 +1000)
(cherry picked from commit b491ceeb504dbc2d7285033ebf92736d7ba29095)

bin/named/main.c

index fa1753e32dda061552519b5b8c8dcda2515c401f..e0cc07857916bd570c9355e1fa512a86717f4040 100644 (file)
@@ -424,6 +424,84 @@ set_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
                *ret = 0;
 }
 
+static void
+parse_T_opt(char *option) {
+       const char *p;
+       char *last = NULL;
+       /*
+        * force the server to behave (or misbehave) in
+        * specified ways for testing purposes.
+        *
+        * clienttest: make clients single shot with their
+        *             own memory context.
+        * delay=xxxx: delay client responses by xxxx ms to
+        *             simulate remote servers.
+        * dscp=x:     check that dscp values are as
+        *             expected and assert otherwise.
+        */
+       if (!strcmp(option, "clienttest")) {
+               ns_g_clienttest = ISC_TRUE;
+       } else if (!strcmp(option, "dropedns")) {
+               ns_g_dropedns = ISC_TRUE;
+       } else if (!strcmp(option, "fixedlocal")) {
+               ns_g_fixedlocal = ISC_TRUE;
+       } else if (!strcmp(option, "keepstderr")) {
+               ns_g_keepstderr = ISC_TRUE;
+       } else if (!strcmp(option, "noaa")) {
+               ns_g_noaa = ISC_TRUE;
+       } else if (!strcmp(option, "noedns")) {
+               ns_g_noedns = ISC_TRUE;
+       } else if (!strcmp(option, "nonearest")) {
+               ns_g_nonearest = ISC_TRUE;
+       } else if (!strcmp(option, "nosoa")) {
+               ns_g_nosoa = ISC_TRUE;
+       } else if (!strcmp(option, "nosyslog")) {
+               ns_g_nosyslog = ISC_TRUE;
+       } else if (!strcmp(option, "notcp")) {
+               ns_g_notcp = ISC_TRUE;
+       } else if (!strcmp(option, "maxudp512")) {
+               maxudp = 512;
+       } else if (!strcmp(option, "maxudp1460")) {
+               maxudp = 1460;
+       } else if (!strncmp(option, "maxudp=", 7)) {
+               maxudp = atoi(option + 7);
+       } else if (!strncmp(option, "mkeytimers=", 11)) {
+               p = strtok_r(option + 11, "/", &last);
+               if (p == NULL) {
+                       ns_main_earlyfatal("bad mkeytimer");
+               }
+
+               dns_zone_mkey_hour = atoi(p);
+               if (dns_zone_mkey_hour == 0) {
+                       ns_main_earlyfatal("bad mkeytimer");
+               }
+
+               p = strtok_r(NULL, "/", &last);
+               if (p == NULL) {
+                       dns_zone_mkey_day = (24 * dns_zone_mkey_hour);
+                       dns_zone_mkey_month = (30 * dns_zone_mkey_day);
+                       return;
+               }
+
+               dns_zone_mkey_day = atoi(p);
+               if (dns_zone_mkey_day < dns_zone_mkey_hour)
+                       ns_main_earlyfatal("bad mkeytimer");
+
+               p = strtok_r(NULL, "/", &last);
+               if (p == NULL) {
+                       dns_zone_mkey_month = (30 * dns_zone_mkey_day);
+                       return;
+               }
+
+               dns_zone_mkey_month = atoi(p);
+               if (dns_zone_mkey_month < dns_zone_mkey_day) {
+                       ns_main_earlyfatal("bad mkeytimer");
+               }
+       } else {
+               fprintf(stderr, "unknown -T flag '%s\n", option);
+       }
+}
+
 static void
 parse_command_line(int argc, char *argv[]) {
        int ch;
@@ -532,76 +610,7 @@ parse_command_line(int argc, char *argv[]) {
                        ns_g_chrootdir = isc_commandline_argument;
                        break;
                case 'T':       /* NOT DOCUMENTED */
-                       /*
-                        * clienttest: make clients single shot with their
-                        *             own memory context.
-                        */
-                       if (!strcmp(isc_commandline_argument, "clienttest"))
-                               ns_g_clienttest = ISC_TRUE;
-                       else if (!strcmp(isc_commandline_argument, "nosoa"))
-                               ns_g_nosoa = ISC_TRUE;
-                       else if (!strcmp(isc_commandline_argument, "noaa"))
-                               ns_g_noaa = ISC_TRUE;
-                       else if (!strcmp(isc_commandline_argument, "maxudp512"))
-                               maxudp = 512;
-                       else if (!strcmp(isc_commandline_argument, "maxudp1460"))
-                               maxudp = 1460;
-                       else if (!strcmp(isc_commandline_argument, "dropedns"))
-                               ns_g_dropedns = ISC_TRUE;
-                       else if (!strcmp(isc_commandline_argument, "noedns"))
-                               ns_g_noedns = ISC_TRUE;
-                       else if (!strncmp(isc_commandline_argument,
-                                         "maxudp=", 7))
-                               maxudp = atoi(isc_commandline_argument + 7);
-                       else if (!strcmp(isc_commandline_argument, "nosyslog"))
-                               ns_g_nosyslog = ISC_TRUE;
-                       else if (!strcmp(isc_commandline_argument, "nonearest"))
-                               ns_g_nonearest = ISC_TRUE;
-                       else if (!strncmp(isc_commandline_argument,
-                                         "mkeytimers=", 11))
-                       {
-                               p = strtok(isc_commandline_argument + 11, "/");
-                               if (p == NULL)
-                                       ns_main_earlyfatal("bad mkeytimer");
-                               dns_zone_mkey_hour = atoi(p);
-                               if (dns_zone_mkey_hour == 0)
-                                       ns_main_earlyfatal("bad mkeytimer");
-
-                               p = strtok(NULL, "/");
-                               if (p == NULL) {
-                                       dns_zone_mkey_day =
-                                               (24 * dns_zone_mkey_hour);
-                                       dns_zone_mkey_month =
-                                               (30 * dns_zone_mkey_day);
-                                       break;
-                               }
-                               dns_zone_mkey_day = atoi(p);
-                               if (dns_zone_mkey_day < dns_zone_mkey_hour)
-                                       ns_main_earlyfatal("bad mkeytimer");
-
-                               p = strtok(NULL, "/");
-                               if (p == NULL) {
-                                       dns_zone_mkey_month =
-                                               (30 * dns_zone_mkey_day);
-                                       break;
-                               }
-                               dns_zone_mkey_month = atoi(p);
-                               if (dns_zone_mkey_month < dns_zone_mkey_day)
-                                       ns_main_earlyfatal("bad mkeytimer");
-                       } else if (!strcmp(isc_commandline_argument, "notcp")) {
-                               ns_g_notcp = ISC_TRUE;
-                       } else if (!strcmp(isc_commandline_argument,
-                                          "keepstderr"))
-                       {
-                               ns_g_keepstderr = ISC_TRUE;
-                       } else if (!strcmp(isc_commandline_argument,
-                                          "fixedlocal"))
-                       {
-                               ns_g_fixedlocal = ISC_TRUE;
-                       } else {
-                               fprintf(stderr, "unknown -T flag '%s\n",
-                                       isc_commandline_argument);
-                       }
+                       parse_T_opt(isc_commandline_argument);
                        break;
                case 'U':
                        ns_g_udpdisp = parse_int(isc_commandline_argument,