aboutsummaryrefslogtreecommitdiff
path: root/networking/arp.c
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /networking/arp.c
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.bz2
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.zip
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/arp.c')
-rw-r--r--networking/arp.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/networking/arp.c b/networking/arp.c
index 71bfe3cbf..6519f8156 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -116,7 +116,7 @@ static int arp_del(char **args)
116 /* Resolve the host name. */ 116 /* Resolve the host name. */
117 host = *args; 117 host = *args;
118 if (ap->input(host, &sa) < 0) { 118 if (ap->input(host, &sa) < 0) {
119 bb_herror_msg_and_die("%s", host); 119 bb_simple_herror_msg_and_die(host);
120 } 120 }
121 121
122 /* If a host has more than one address, use the correct one! */ 122 /* If a host has more than one address, use the correct one! */
@@ -149,7 +149,7 @@ static int arp_del(char **args)
149#ifdef HAVE_ATF_DONTPUB 149#ifdef HAVE_ATF_DONTPUB
150 req.arp_flags |= ATF_DONTPUB; 150 req.arp_flags |= ATF_DONTPUB;
151#else 151#else
152 bb_error_msg("feature ATF_DONTPUB is not supported"); 152 bb_simple_error_msg("feature ATF_DONTPUB is not supported");
153#endif 153#endif
154 args++; 154 args++;
155 break; 155 break;
@@ -157,7 +157,7 @@ static int arp_del(char **args)
157#ifdef HAVE_ATF_MAGIC 157#ifdef HAVE_ATF_MAGIC
158 req.arp_flags |= ATF_MAGIC; 158 req.arp_flags |= ATF_MAGIC;
159#else 159#else
160 bb_error_msg("feature ATF_MAGIC is not supported"); 160 bb_simple_error_msg("feature ATF_MAGIC is not supported");
161#endif 161#endif
162 args++; 162 args++;
163 break; 163 break;
@@ -173,7 +173,7 @@ static int arp_del(char **args)
173 if (strcmp(*args, "255.255.255.255") != 0) { 173 if (strcmp(*args, "255.255.255.255") != 0) {
174 host = *args; 174 host = *args;
175 if (ap->input(host, &sa) < 0) { 175 if (ap->input(host, &sa) < 0) {
176 bb_herror_msg_and_die("%s", host); 176 bb_simple_herror_msg_and_die(host);
177 } 177 }
178 memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr)); 178 memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr));
179 req.arp_flags |= ATF_NETMASK; 179 req.arp_flags |= ATF_NETMASK;
@@ -195,7 +195,7 @@ static int arp_del(char **args)
195 /* Call the kernel. */ 195 /* Call the kernel. */
196 if (flags & 2) { 196 if (flags & 2) {
197 if (option_mask32 & ARP_OPT_v) 197 if (option_mask32 & ARP_OPT_v)
198 bb_error_msg("SIOCDARP(nopub)"); 198 bb_simple_error_msg("SIOCDARP(nopub)");
199 err = ioctl(sockfd, SIOCDARP, &req); 199 err = ioctl(sockfd, SIOCDARP, &req);
200 if (err < 0) { 200 if (err < 0) {
201 if (errno == ENXIO) { 201 if (errno == ENXIO) {
@@ -204,20 +204,20 @@ static int arp_del(char **args)
204 printf("No ARP entry for %s\n", host); 204 printf("No ARP entry for %s\n", host);
205 return -1; 205 return -1;
206 } 206 }
207 bb_perror_msg_and_die("SIOCDARP(priv)"); 207 bb_simple_perror_msg_and_die("SIOCDARP(priv)");
208 } 208 }
209 } 209 }
210 if ((flags & 1) && err) { 210 if ((flags & 1) && err) {
211 nopub: 211 nopub:
212 req.arp_flags |= ATF_PUBL; 212 req.arp_flags |= ATF_PUBL;
213 if (option_mask32 & ARP_OPT_v) 213 if (option_mask32 & ARP_OPT_v)
214 bb_error_msg("SIOCDARP(pub)"); 214 bb_simple_error_msg("SIOCDARP(pub)");
215 if (ioctl(sockfd, SIOCDARP, &req) < 0) { 215 if (ioctl(sockfd, SIOCDARP, &req) < 0) {
216 if (errno == ENXIO) { 216 if (errno == ENXIO) {
217 printf("No ARP entry for %s\n", host); 217 printf("No ARP entry for %s\n", host);
218 return -1; 218 return -1;
219 } 219 }
220 bb_perror_msg_and_die("SIOCDARP(pub)"); 220 bb_simple_perror_msg_and_die("SIOCDARP(pub)");
221 } 221 }
222 } 222 }
223 return 0; 223 return 0;
@@ -233,7 +233,7 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa)
233 ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr, 233 ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr,
234 "can't get HW-Address for '%s'", ifname); 234 "can't get HW-Address for '%s'", ifname);
235 if (hw_set && (ifr.ifr_hwaddr.sa_family != hw->type)) { 235 if (hw_set && (ifr.ifr_hwaddr.sa_family != hw->type)) {
236 bb_error_msg_and_die("protocol type mismatch"); 236 bb_simple_error_msg_and_die("protocol type mismatch");
237 } 237 }
238 memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); 238 memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr));
239 239
@@ -261,20 +261,20 @@ static int arp_set(char **args)
261 261
262 host = *args++; 262 host = *args++;
263 if (ap->input(host, &sa) < 0) { 263 if (ap->input(host, &sa) < 0) {
264 bb_herror_msg_and_die("%s", host); 264 bb_simple_herror_msg_and_die(host);
265 } 265 }
266 /* If a host has more than one address, use the correct one! */ 266 /* If a host has more than one address, use the correct one! */
267 memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr)); 267 memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr));
268 268
269 /* Fetch the hardware address. */ 269 /* Fetch the hardware address. */
270 if (*args == NULL) { 270 if (*args == NULL) {
271 bb_error_msg_and_die("need hardware address"); 271 bb_simple_error_msg_and_die("need hardware address");
272 } 272 }
273 if (option_mask32 & ARP_OPT_D) { 273 if (option_mask32 & ARP_OPT_D) {
274 arp_getdevhw(*args++, &req.arp_ha); 274 arp_getdevhw(*args++, &req.arp_ha);
275 } else { 275 } else {
276 if (hw->input(*args++, &req.arp_ha) < 0) { 276 if (hw->input(*args++, &req.arp_ha) < 0) {
277 bb_error_msg_and_die("invalid hardware address"); 277 bb_simple_error_msg_and_die("invalid hardware address");
278 } 278 }
279 } 279 }
280 280
@@ -302,7 +302,7 @@ static int arp_set(char **args)
302#ifdef HAVE_ATF_DONTPUB 302#ifdef HAVE_ATF_DONTPUB
303 flags |= ATF_DONTPUB; 303 flags |= ATF_DONTPUB;
304#else 304#else
305 bb_error_msg("feature ATF_DONTPUB is not supported"); 305 bb_simple_error_msg("feature ATF_DONTPUB is not supported");
306#endif 306#endif
307 args++; 307 args++;
308 break; 308 break;
@@ -310,7 +310,7 @@ static int arp_set(char **args)
310#ifdef HAVE_ATF_MAGIC 310#ifdef HAVE_ATF_MAGIC
311 flags |= ATF_MAGIC; 311 flags |= ATF_MAGIC;
312#else 312#else
313 bb_error_msg("feature ATF_MAGIC is not supported"); 313 bb_simple_error_msg("feature ATF_MAGIC is not supported");
314#endif 314#endif
315 args++; 315 args++;
316 break; 316 break;
@@ -326,7 +326,7 @@ static int arp_set(char **args)
326 if (strcmp(*args, "255.255.255.255") != 0) { 326 if (strcmp(*args, "255.255.255.255") != 0) {
327 host = *args; 327 host = *args;
328 if (ap->input(host, &sa) < 0) { 328 if (ap->input(host, &sa) < 0) {
329 bb_herror_msg_and_die("%s", host); 329 bb_simple_herror_msg_and_die(host);
330 } 330 }
331 memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr)); 331 memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr));
332 flags |= ATF_NETMASK; 332 flags |= ATF_NETMASK;
@@ -346,7 +346,7 @@ static int arp_set(char **args)
346 346
347 /* Call the kernel. */ 347 /* Call the kernel. */
348 if (option_mask32 & ARP_OPT_v) 348 if (option_mask32 & ARP_OPT_v)
349 bb_error_msg("SIOCSARP()"); 349 bb_simple_error_msg("SIOCSARP()");
350 xioctl(sockfd, SIOCSARP, &req); 350 xioctl(sockfd, SIOCSARP, &req);
351 return 0; 351 return 0;
352} 352}
@@ -422,7 +422,7 @@ static int arp_show(char *name)
422 if (name != NULL) { 422 if (name != NULL) {
423 /* Resolve the host name. */ 423 /* Resolve the host name. */
424 if (ap->input(name, &sa) < 0) { 424 if (ap->input(name, &sa) < 0) {
425 bb_herror_msg_and_die("%s", name); 425 bb_simple_herror_msg_and_die(name);
426 } 426 }
427 host = xstrdup(ap->sprint(&sa, 1)); 427 host = xstrdup(ap->sprint(&sa, 1));
428 } 428 }
@@ -530,7 +530,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
530 /* Now see what we have to do here... */ 530 /* Now see what we have to do here... */
531 if (opts & (ARP_OPT_d | ARP_OPT_s)) { 531 if (opts & (ARP_OPT_d | ARP_OPT_s)) {
532 if (argv[0] == NULL) 532 if (argv[0] == NULL)
533 bb_error_msg_and_die("need host name"); 533 bb_simple_error_msg_and_die("need host name");
534 if (opts & ARP_OPT_s) 534 if (opts & ARP_OPT_s)
535 return arp_set(argv); 535 return arp_set(argv);
536 return arp_del(argv); 536 return arp_del(argv);