From: famfo Date: Tue, 16 May 2023 10:41:58 +0000 (+0200) Subject: Add option to use custom ipinfo provider X-Git-Tag: v0.96~26^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F473%2Fhead;p=thirdparty%2Fmtr.git Add option to use custom ipinfo provider --- diff --git a/man/mtr.8.in b/man/mtr.8.in index 04ef1f3..84baac6 100644 --- a/man/mtr.8.in +++ b/man/mtr.8.in @@ -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 diff --git a/ui/asn.c b/ui/asn.c index 3f424e0..718f4a0 100644 --- 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; } diff --git a/ui/mtr.c b/ui/mtr.c index 5a70f31..7a339f0 100644 --- 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); /* diff --git a/ui/mtr.h b/ui/mtr.h index d9a3e0d..0adff62 100644 --- 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 */