]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Add option to use custom ipinfo provider 473/head
authorfamfo <famfo@famfo.xyz>
Tue, 16 May 2023 10:41:58 +0000 (12:41 +0200)
committerfamfo <famfo@famfo.xyz>
Tue, 16 May 2023 10:41:58 +0000 (12:41 +0200)
man/mtr.8.in
ui/asn.c
ui/mtr.c
ui/mtr.h

index 04ef1f3c0490836c0aa9355648755332b3c4185f..84baac6fd245f2797ceb76220dd03f9415b24308 100644 (file)
@@ -56,6 +56,12 @@ mtr \- a network diagnostic tool
 .B \-\-aslookup\c
 ]
 [\c
+.BI \-\-ipinfo_provider4 \ DOMAIN\c
+]
+[\c
+.BI \-\-ipinfo_provider6 \ DOMAIN\c
+]
+[\c
 .BI \-i \ INTERVAL\c
 ]
 [\c
@@ -350,6 +356,14 @@ Example (columns to the right not shown for clarity):
 7. AS1850  www.isnic.is
 .fi
 .TP
+.B \-\-ipinfo_provider4 \fIDOMAIN
+Provider for IPv4 AS lookups.  Defaults to origin.asn.cymru.com.
+.fi
+.TP
+.B \-\-ipinfo_provider6 \fIDOMAIN
+Provider for IPv6 AS lookups.  Defaults to origin6.asn.cymru.com.
+.fi
+.TP
 .B \-i \fISECONDS\fR, \fB\-\-interval \fISECONDS
 Use this option to specify the positive number of seconds between ICMP
 ECHO requests.  The default value for this parameter is one second.  The
index 3f424e08c385f3a7bdf8dd59ed3f96f4aed5c164..718f4a030c3a823f595a32b7ca119b3271670834 100644 (file)
--- a/ui/asn.c
+++ b/ui/asn.c
@@ -65,7 +65,7 @@ static int iihash = 0;
 static char fmtinfo[32];
 
 /* items width: ASN, Route, Country, Registry, Allocated */
-static const int iiwidth[] = { 7, 19, 4, 8, 11 };       /* item len + space */
+static const int iiwidth[] = { 12, 19, 4, 8, 11 };       /* item len + space */
 
 typedef char *items_t[ITEMSMAX + 1];
 static items_t items_a;         /* without hash: items */
@@ -230,7 +230,7 @@ static char *get_ipinfo(
     if (ctl->af == AF_INET6) {
 #ifdef ENABLE_IPV6
         reverse_host6(addr, key, NAMELEN);
-        if (snprintf(lookup_key, NAMELEN, "%s.origin6.asn.cymru.com", key)
+        if (snprintf(lookup_key, NAMELEN, "%s.%s", key, ctl->ipinfo_provider6)
             >= NAMELEN)
             return NULL;
 #else
@@ -243,7 +243,7 @@ static char *get_ipinfo(
             (key, NAMELEN, "%d.%d.%d.%d", buff[3], buff[2], buff[1],
              buff[0]) >= NAMELEN)
             return NULL;
-        if (snprintf(lookup_key, NAMELEN, "%s.origin.asn.cymru.com", key)
+        if (snprintf(lookup_key, NAMELEN, "%s.%s", key, ctl->ipinfo_provider4)
             >= NAMELEN)
             return NULL;
     }
index 5a70f3130e3ab9d0a7d88c5e3be13c01cfacda25..7a339f0a9a8060b3285d4404bfe1dbdd5c246550 100644 (file)
--- a/ui/mtr.c
+++ b/ui/mtr.c
@@ -144,6 +144,10 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
     fputs(" -y, --ipinfo NUMBER              select IP information in output\n",
           out);       
     fputs(" -z, --aslookup                   display AS number\n", out);
+    fputs("     --ipinfo_provider4           providor for IPv4 AS lookups\n", out);
+#ifdef ENABLE_IPV6
+    fputs("     --ipinfo_provider6           providor for IPv6 AS lookups\n", out);
+#endif
 #endif       
     fputs(" -h, --help                       display this help and exit\n", out);
     fputs(" -v, --version                    output version information and exit\n", out);  
@@ -294,7 +298,11 @@ static void parse_arg(
        3/ update the help message (see usage() function).
      */
     enum {
-        OPT_DISPLAYMODE = CHAR_MAX + 1
+        OPT_DISPLAYMODE = CHAR_MAX + 1,
+        OPT_IPINFO4 = CHAR_MAX + 2,
+#ifdef ENABLE_IPV6
+        OPT_IPINFO6 = CHAR_MAX + 3,
+#endif /* ifdef ENABLE_IPV6 */
     };
     static const struct option long_options[] = {
         /* option name, has argument, NULL, short name */
@@ -331,6 +339,10 @@ static void parse_arg(
 #ifdef HAVE_IPINFO
         {"ipinfo", 1, NULL, 'y'},       /* IP info lookup */
         {"aslookup", 0, NULL, 'z'},     /* Do AS lookup (--ipinfo 0) */
+        {"ipinfo_provider4", 1, NULL, OPT_IPINFO4},
+#ifdef ENABLE_IPV6
+        {"ipinfo_provider6", 1, NULL, OPT_IPINFO6},
+#endif
 #endif
 
         {"interval", 1, NULL, 'i'},
@@ -610,6 +622,14 @@ static void parse_arg(
         case 'z':
             ctl->ipinfo_no = 0;
             break;
+        case OPT_IPINFO4:
+            ctl->ipinfo_provider4 = optarg;
+            break;
+#ifdef ENABLE_IPV6
+        case OPT_IPINFO6:
+            ctl->ipinfo_provider6 = optarg;
+            break;
+#endif
 #endif
 #ifdef SO_MARK
         case 'M':
@@ -734,6 +754,13 @@ int main(
     ctl.probe_timeout = 10 * 1000000;
     ctl.ipinfo_no = -1;
     ctl.ipinfo_max = -1;
+#ifdef HAVE_IPINFO
+    ctl.ipinfo_provider4 = "origin.asn.cymru.com";
+#ifdef ENABLE_IPV6
+    ctl.ipinfo_provider6 = "origin6.asn.cymru.com";
+#endif
+#endif
+
     xstrncpy(ctl.fld_active, "LS NABWV", 2 * MAXFLD);
 
     /*
index d9a3e0d3c2d32feddb78768056690f09fc10d836..0adff62d5b7d7ac0fdc38b79257f1a4ee931f4de 100644 (file)
--- a/ui/mtr.h
+++ b/ui/mtr.h
@@ -118,6 +118,12 @@ struct mtr_ctl {
         use_dns:1,
         show_ips:1,
         enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5;
+#ifdef HAVE_IPINFO
+#ifdef ENABLE_IPV6
+    char *ipinfo_provider6;
+#endif
+    char *ipinfo_provider4;
+#endif
 };
 
 /* dynamic field drawing */