1 Upstream-Status: Backport
3 From a55a8fd83be9d91bd2adb73eebac8833a51b626f Mon Sep 17 00:00:00 2001
4 From: Stephen Hemminger <stephen@networkplumber.org>
5 Date: Thu, 28 Feb 2013 08:51:46 -0800
6 Subject: [PATCH] fix dependency on sizeof(__u64) == sizeof(unsigned long
9 Some platforms like ppc64 have unsigned long long as 128 bits, and
10 the printf format string would cause errors. Resolve this by using
11 unsigned long long where necessary (or unsigned long).
13 ip/ipntable.c | 74 +++++++++++++++++++++---------------------------------
14 ip/tcp_metrics.c | 13 +++++-----
15 2 files changed, 35 insertions(+), 52 deletions(-)
17 diff --git a/ip/ipntable.c b/ip/ipntable.c
18 index 56ad001..a1a3c26 100644
21 @@ -431,8 +431,8 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
22 fprintf(fp, "thresh3 %u ", thresh3);
24 if (tb[NDTA_GC_INTERVAL]) {
25 - __u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
26 - fprintf(fp, "gc_int %llu ", (unsigned long long) gc_int);
27 + unsigned long long gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
28 + fprintf(fp, "gc_int %llu ", gc_int);
32 @@ -484,19 +484,16 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
33 fprintf(fp, "refcnt %u ", refcnt);
35 if (tpb[NDTPA_REACHABLE_TIME]) {
36 - __u64 reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
37 - fprintf(fp, "reachable %llu ",
38 - (unsigned long long) reachable);
39 + unsigned long long reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
40 + fprintf(fp, "reachable %llu ", reachable);
42 if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
43 - __u64 breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
44 - fprintf(fp, "base_reachable %llu ",
45 - (unsigned long long) breachable);
46 + unsigned long long breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
47 + fprintf(fp, "base_reachable %llu ", breachable);
49 if (tpb[NDTPA_RETRANS_TIME]) {
50 - __u64 retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
51 - fprintf(fp, "retrans %llu ",
52 - (unsigned long long) retrans);
53 + unsigned long long retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
54 + fprintf(fp, "retrans %llu ", retrans);
57 fprintf(fp, "%s", _SL_);
58 @@ -504,14 +501,12 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
61 if (tpb[NDTPA_GC_STALETIME]) {
62 - __u64 gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
63 - fprintf(fp, "gc_stale %llu ",
64 - (unsigned long long) gc_stale);
65 + unsigned long long gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
66 + fprintf(fp, "gc_stale %llu ", gc_stale);
68 if (tpb[NDTPA_DELAY_PROBE_TIME]) {
69 - __u64 delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
70 - fprintf(fp, "delay_probe %llu ",
71 - (unsigned long long) delay_probe);
72 + unsigned long long delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
73 + fprintf(fp, "delay_probe %llu ", delay_probe);
75 if (tpb[NDTPA_QUEUE_LEN]) {
76 __u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
77 @@ -540,23 +535,20 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
80 if (tpb[NDTPA_ANYCAST_DELAY]) {
81 - __u64 anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
82 - fprintf(fp, "anycast_delay %llu ",
83 - (unsigned long long) anycast_delay);
84 + unsigned long long anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
85 + fprintf(fp, "anycast_delay %llu ", anycast_delay);
87 if (tpb[NDTPA_PROXY_DELAY]) {
88 - __u64 proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
89 - fprintf(fp, "proxy_delay %llu ",
90 - (unsigned long long) proxy_delay);
91 + unsigned long long proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
92 + fprintf(fp, "proxy_delay %llu ", proxy_delay);
94 if (tpb[NDTPA_PROXY_QLEN]) {
95 __u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
96 fprintf(fp, "proxy_queue %u ", pqueue);
98 if (tpb[NDTPA_LOCKTIME]) {
99 - __u64 locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
100 - fprintf(fp, "locktime %llu ",
101 - (unsigned long long) locktime);
102 + unsigned long long locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
103 + fprintf(fp, "locktime %llu ", locktime);
106 fprintf(fp, "%s", _SL_);
107 @@ -568,38 +560,28 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
109 fprintf(fp, "stats ");
111 - fprintf(fp, "allocs %llu ",
112 - (unsigned long long) ndts->ndts_allocs);
113 - fprintf(fp, "destroys %llu ",
114 - (unsigned long long) ndts->ndts_destroys);
115 - fprintf(fp, "hash_grows %llu ",
116 - (unsigned long long) ndts->ndts_hash_grows);
117 + fprintf(fp, "allocs %llu ", ndts->ndts_allocs);
118 + fprintf(fp, "destroys %llu ", ndts->ndts_destroys);
119 + fprintf(fp, "hash_grows %llu ", ndts->ndts_hash_grows);
121 fprintf(fp, "%s", _SL_);
124 - fprintf(fp, "res_failed %llu ",
125 - (unsigned long long) ndts->ndts_res_failed);
126 - fprintf(fp, "lookups %llu ",
127 - (unsigned long long) ndts->ndts_lookups);
128 - fprintf(fp, "hits %llu ",
129 - (unsigned long long) ndts->ndts_hits);
130 + fprintf(fp, "res_failed %llu ", ndts->ndts_res_failed);
131 + fprintf(fp, "lookups %llu ", ndts->ndts_lookups);
132 + fprintf(fp, "hits %llu ", ndts->ndts_hits);
134 fprintf(fp, "%s", _SL_);
137 - fprintf(fp, "rcv_probes_mcast %llu ",
138 - (unsigned long long) ndts->ndts_rcv_probes_mcast);
139 - fprintf(fp, "rcv_probes_ucast %llu ",
140 - (unsigned long long) ndts->ndts_rcv_probes_ucast);
141 + fprintf(fp, "rcv_probes_mcast %llu ", ndts->ndts_rcv_probes_mcast);
142 + fprintf(fp, "rcv_probes_ucast %llu ", ndts->ndts_rcv_probes_ucast);
144 fprintf(fp, "%s", _SL_);
147 - fprintf(fp, "periodic_gc_runs %llu ",
148 - (unsigned long long) ndts->ndts_periodic_gc_runs);
149 - fprintf(fp, "forced_gc_runs %llu ",
150 - (unsigned long long) ndts->ndts_forced_gc_runs);
151 + fprintf(fp, "periodic_gc_runs %llu ", ndts->ndts_periodic_gc_runs);
152 + fprintf(fp, "forced_gc_runs %llu ", ndts->ndts_forced_gc_runs);
154 fprintf(fp, "%s", _SL_);
156 diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
157 index a01e1fb..c6be3c9 100644
158 --- a/ip/tcp_metrics.c
159 +++ b/ip/tcp_metrics.c
160 @@ -166,7 +166,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
162 a = attrs[TCP_METRICS_ATTR_AGE];
164 - __u64 val = rta_getattr_u64(a);
165 + unsigned long long val = rta_getattr_u64(a);
167 fprintf(fp, " age %llu.%03llusec",
168 val / 1000, val % 1000);
169 @@ -189,7 +189,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
170 parse_rtattr_nested(m, TCP_METRIC_MAX + 1, a);
172 for (i = 0; i < TCP_METRIC_MAX + 1; i++) {
178 @@ -198,19 +198,20 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
179 fprintf(fp, " %s ", metric_name[i]);
181 fprintf(fp, " metric_%d ", i);
183 val = rta_getattr_u32(a);
186 - fprintf(fp, "%lluus", (val * 1000ULL) >> 3);
187 + fprintf(fp, "%luus", (val * 1000UL) >> 3);
189 case TCP_METRIC_RTTVAR:
190 - fprintf(fp, "%lluus", (val * 1000ULL) >> 2);
191 + fprintf(fp, "%luus", (val * 1000UL) >> 2);
193 case TCP_METRIC_SSTHRESH:
194 case TCP_METRIC_CWND:
195 case TCP_METRIC_REORDERING:
197 - fprintf(fp, "%u", val);
198 + fprintf(fp, "%lu", val);
202 @@ -223,7 +224,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
203 a = attrs[TCP_METRICS_ATTR_FOPEN_SYN_DROPS];
205 __u16 syn_loss = rta_getattr_u16(a);
207 + unsigned long long ts;
209 a = attrs[TCP_METRICS_ATTR_FOPEN_SYN_DROP_TS];
210 ts = a ? rta_getattr_u64(a) : 0;