mtr/backport-reset-address-family.patch
liyunqing 1b07d88645 fix changing source failed
(cherry picked from commit 2911b40a691876ef5f33e1ae26c6823145cce979)
2022-08-11 19:28:03 +08:00

345 lines
11 KiB
Diff

From a0b00e233f2d613b6e8dc453fe192d51c4cd548b Mon Sep 17 00:00:00 2001
From: Aaron Lipinski <kris.lipinski@gmail.com>
Date: Sun, 4 Apr 2021 08:02:38 +1200
Subject: [PATCH 1/4] reset ctl address family at net_reopen
---
ui/net.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/net.c b/ui/net.c
index 6b06d29..60d33e0 100644
--- a/ui/net.c
+++ b/ui/net.c
@@ -764,7 +764,7 @@ void net_reopen(
net_reset(ctl);
- remotesockaddr->sa_family = sourcesockaddr->sa_family = hostent->h_addrtype;
+ ctl->af = remotesockaddr->sa_family = sourcesockaddr->sa_family = hostent->h_addrtype;
remoteaddress = sockaddr_addr_offset(remotesockaddr);
memcpy(remoteaddress, hostent->h_addr, sockaddr_addr_size(remotesockaddr));
inet_ntop(remotesockaddr->sa_family, remoteaddress, remoteaddr, sizeof(remoteaddr));
--
2.27.0
From a0a91e4962716bf86d6edae157e3449627a270f7 Mon Sep 17 00:00:00 2001
From: Aaron Lipinski <kris.lipinski@gmail.com>
Date: Sun, 4 Apr 2021 10:08:00 +1200
Subject: [PATCH 2/4] accept only value used in structure
---
ui/dns.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ui/dns.c b/ui/dns.c
index 7dc8885..642590e 100644
--- a/ui/dns.c
+++ b/ui/dns.c
@@ -114,12 +114,12 @@ static struct dns_results *findip(
}
static void set_sockaddr_ip(
- struct mtr_ctl *ctl,
+ sa_family_t family,
struct sockaddr_storage *sa,
ip_t * ip)
{
memset(sa, 0, sizeof(struct sockaddr_storage));
- sa->ss_family = ctl->af;
+ sa->ss_family = family;
memcpy(sockaddr_addr_offset(sa), ip, sockaddr_addr_size(sa));
}
@@ -174,7 +174,7 @@ void dns_open(
buf[strlen(buf) - 1] = 0; /* chomp newline. */
longipstr(buf, &host, ctl->af);
- set_sockaddr_ip(ctl, &sa, &host);
+ set_sockaddr_ip(ctl->af, &sa, &host);
salen = (ctl->af == AF_INET) ? sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6);
--
2.27.0
From fd60554d3b71954af66641b47a9a24a1105f6a04 Mon Sep 17 00:00:00 2001
From: Aaron Lipinski <kris.lipinski@gmail.com>
Date: Sun, 4 Apr 2021 10:14:52 +1200
Subject: [PATCH 3/4] accept only value used in structure
---
ui/curses.c | 10 +++++-----
ui/dns.c | 10 +++++-----
ui/dns.h | 2 +-
ui/gtk.c | 4 ++--
ui/raw.c | 2 +-
ui/report.c | 8 ++++----
ui/split.c | 4 ++--
7 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/ui/curses.c b/ui/curses.c
index ca5e8fe..207b272 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -436,11 +436,11 @@ static void mtr_curses_hosts(
#endif
if (name != NULL) {
if (ctl->show_ips)
- printw("%s (%s)", name, strlongip(ctl, addr));
+ printw("%s (%s)", name, strlongip(ctl->af, addr));
else
printw("%s", name);
} else {
- printw("%s", strlongip(ctl, addr));
+ printw("%s", strlongip(ctl->af, addr));
}
attroff(A_BOLD);
@@ -489,11 +489,11 @@ static void mtr_curses_hosts(
#endif
if (name != NULL) {
if (ctl->show_ips)
- printw("%s (%s)", name, strlongip(ctl, addrs));
+ printw("%s (%s)", name, strlongip(ctl->af, addrs));
else
printw("%s", name);
} else {
- printw("%s", strlongip(ctl, addrs));
+ printw("%s", strlongip(ctl->af, addrs));
}
for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
printw("\n [MPLS: Lbl %lu TC %u S %u TTL %u]",
@@ -653,7 +653,7 @@ static void mtr_curses_graph(
printw("%s", fmt_ipinfo(ctl, addr));
#endif
name = dns_lookup(ctl, addr);
- printw("%s", name ? name : strlongip(ctl, addr));
+ printw("%s", name ? name : strlongip(ctl->af, addr));
} else {
attron(A_BOLD);
printw("(%s)", host_error_to_string(err));
diff --git a/ui/dns.c b/ui/dns.c
index 642590e..a38113b 100644
--- a/ui/dns.c
+++ b/ui/dns.c
@@ -52,13 +52,13 @@ struct dns_results {
static struct dns_results *results;
char *strlongip(
- struct mtr_ctl *ctl,
+ sa_family_t family,
ip_t * ip)
{
#ifdef ENABLE_IPV6
static char addrstr[INET6_ADDRSTRLEN];
- return (char *) inet_ntop(ctl->af, ip, addrstr, sizeof addrstr);
+ return (char *) inet_ntop(family, ip, addrstr, sizeof addrstr);
#else
return inet_ntoa(*ip);
#endif
@@ -182,7 +182,7 @@ void dns_open(
hostname, sizeof(hostname), NULL, 0, 0);
if (rv == 0) {
snprintf(result, sizeof(result),
- "%s %s\n", strlongip(ctl, &host), hostname);
+ "%s %s\n", strlongip(ctl->af, &host), hostname);
rv = write(fromdns[1], result, strlen(result));
if (rv < 0)
@@ -270,7 +270,7 @@ char *dns_lookup2(
r->name = NULL;
r->next = results;
results = r;
- snprintf(buf, sizeof(buf), "%s\n", strlongip(ctl, ip));
+ snprintf(buf, sizeof(buf), "%s\n", strlongip(ctl->af, ip));
rv = write(todns[1], buf, strlen(buf));
if (rv < 0)
error(0, errno, "couldn't write to resolver process");
@@ -288,7 +288,7 @@ char *dns_lookup(
if (!ctl->dns || !ctl->use_dns)
return NULL;
t = dns_lookup2(ctl, ip);
- return t ? t : strlongip(ctl, ip);
+ return t ? t : strlongip(ctl->af, ip);
}
/* XXX check if necessary/exported. */
diff --git a/ui/dns.h b/ui/dns.h
index c04d184..6668335 100644
--- a/ui/dns.h
+++ b/ui/dns.h
@@ -44,7 +44,7 @@ extern char *dns_lookup2(
extern struct hostent *dns_forward(
const char *name);
extern char *strlongip(
- struct mtr_ctl *ctl,
+ sa_family_t family,
ip_t * ip);
extern void addr2ip6arpa(
diff --git a/ui/gtk.c b/ui/gtk.c
index 0fd8339..e23abf2 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -512,11 +512,11 @@ static void update_tree_row(
if ((name = dns_lookup(ctl, addr))) {
if (ctl->show_ips) {
snprintf(str, sizeof(str), "%s (%s)", name,
- strlongip(ctl, addr));
+ strlongip(ctl->af, addr));
name = str;
}
} else
- name = strlongip(ctl, addr);
+ name = strlongip(ctl->af, addr);
}
gtk_list_store_set(ReportStore, iter,
diff --git a/ui/raw.c b/ui/raw.c
index 0735131..85e87e8 100644
--- a/ui/raw.c
+++ b/ui/raw.c
@@ -70,7 +70,7 @@ void raw_rawhost(
ip_t *ip_addr,
struct mplslen *mpls)
{
- printf("h %d %s\n", host, strlongip(ctl, ip_addr));
+ printf("h %d %s\n", host, strlongip(ctl->af, ip_addr));
if (ctl->enablempls) {
int k;
for (k = 0; k < mpls->labels; k++)
diff --git a/ui/report.c b/ui/report.c
index b39f186..c540717 100644
--- a/ui/report.c
+++ b/ui/report.c
@@ -65,10 +65,10 @@ static size_t snprint_addr(
struct hostent *host =
ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;
if (!host)
- return snprintf(dst, dst_len, "%s", strlongip(ctl, addr));
+ return snprintf(dst, dst_len, "%s", strlongip(ctl->af, addr));
else if (ctl->dns && ctl->show_ips)
return snprintf(dst, dst_len, "%s (%s)", host->h_name,
- strlongip(ctl, addr));
+ strlongip(ctl->af, addr));
else
return snprintf(dst, dst_len, "%s", host->h_name);
} else
@@ -235,7 +235,7 @@ void report_close(
}
if (z == 1) {
- printf(" | `|-- %s\n", strlongip(ctl, addr2));
+ printf(" | `|-- %s\n", strlongip(ctl->af, addr2));
for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
printf
(" | +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
@@ -243,7 +243,7 @@ void report_close(
mplss->ttl[k]);
}
} else {
- printf(" | |-- %s\n", strlongip(ctl, addr2));
+ printf(" | |-- %s\n", strlongip(ctl->af, addr2));
for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
printf
(" | +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
diff --git a/ui/split.c b/ui/split.c
index d300404..1755452 100644
--- a/ui/split.c
+++ b/ui/split.c
@@ -95,10 +95,10 @@ void split_redraw(
if (addrcmp(addr, &ctl->unspec_addr, ctl->af)) {
char str[256], *name;
if (!(name = dns_lookup(ctl, addr)))
- name = strlongip(ctl, addr);
+ name = strlongip(ctl->af, addr);
if (ctl->show_ips) {
snprintf(str, sizeof(str), "%s %s", name,
- strlongip(ctl, addr));
+ strlongip(ctl->af, addr));
name = str;
}
/* May be we should test name's length */
--
2.27.0
From 02ded71c1cad62b5717a2f998f0f3288f8f48622 Mon Sep 17 00:00:00 2001
From: Aaron Lipinski <kris.lipinski@gmail.com>
Date: Sun, 4 Apr 2021 10:19:29 +1200
Subject: [PATCH 4/4] accept only value used in structure
---
ui/dns.c | 10 +++++-----
ui/dns.h | 2 +-
ui/mtr.c | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/ui/dns.c b/ui/dns.c
index a38113b..94af8b7 100644
--- a/ui/dns.c
+++ b/ui/dns.c
@@ -124,7 +124,7 @@ static void set_sockaddr_ip(
}
void dns_open(
- struct mtr_ctl *ctl)
+ sa_family_t family)
{
int pid;
@@ -173,16 +173,16 @@ void dns_open(
buf[strlen(buf) - 1] = 0; /* chomp newline. */
- longipstr(buf, &host, ctl->af);
- set_sockaddr_ip(ctl->af, &sa, &host);
- salen = (ctl->af == AF_INET) ? sizeof(struct sockaddr_in) :
+ longipstr(buf, &host, family);
+ set_sockaddr_ip(family, &sa, &host);
+ salen = (family == AF_INET) ? sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6);
rv = getnameinfo((struct sockaddr *) &sa, salen,
hostname, sizeof(hostname), NULL, 0, 0);
if (rv == 0) {
snprintf(result, sizeof(result),
- "%s %s\n", strlongip(ctl->af, &host), hostname);
+ "%s %s\n", strlongip(family, &host), hostname);
rv = write(fromdns[1], result, strlen(result));
if (rv < 0)
diff --git a/ui/dns.h b/ui/dns.h
index 6668335..b15d6ad 100644
--- a/ui/dns.h
+++ b/ui/dns.h
@@ -23,7 +23,7 @@
/* Prototypes for dns.c */
extern void dns_open(
- struct mtr_ctl *ctl);
+ sa_family_t family);
extern int dns_waitfd(
void);
extern void dns_ack(
diff --git a/ui/mtr.c b/ui/mtr.c
index b33a136..b959919 100644
--- a/ui/mtr.c
+++ b/ui/mtr.c
@@ -858,7 +858,7 @@ int main(
}
lock(stdout);
- dns_open(&ctl);
+ dns_open(ctl.af);
display_open(&ctl);
display_loop(&ctl);
--
2.27.0