Annotation of embedaddon/iperf/src/iperf_error.c, revision 1.1.1.3
1.1 misho 1: /*
1.1.1.3 ! misho 2: * iperf, Copyright (c) 2014-2022, The Regents of the University of
1.1 misho 3: * California, through Lawrence Berkeley National Laboratory (subject
4: * to receipt of any required approvals from the U.S. Dept. of
5: * Energy). All rights reserved.
6: *
7: * If you have questions about your rights to use or distribute this
8: * software, please contact Berkeley Lab's Technology Transfer
9: * Department at TTD@lbl.gov.
10: *
11: * NOTICE. This software is owned by the U.S. Department of Energy.
12: * As such, the U.S. Government has been granted for itself and others
13: * acting on its behalf a paid-up, nonexclusive, irrevocable,
14: * worldwide license in the Software to reproduce, prepare derivative
15: * works, and perform publicly and display publicly. Beginning five
16: * (5) years after the date permission to assert copyright is obtained
17: * from the U.S. Department of Energy, and subject to any subsequent
18: * five (5) year renewals, the U.S. Government is granted for itself
19: * and others acting on its behalf a paid-up, nonexclusive,
20: * irrevocable, worldwide license in the Software to reproduce,
21: * prepare derivative works, distribute copies to the public, perform
22: * publicly and display publicly, and to permit others to do so.
23: *
24: * This code is distributed under a BSD style license, see the LICENSE
25: * file for complete information.
26: */
27: #include <stdio.h>
28: #include <errno.h>
29: #include <netdb.h>
30: #include <string.h>
31: #include <stdlib.h>
32: #include <stdarg.h>
33: #include "iperf.h"
34: #include "iperf_api.h"
35:
1.1.1.2 misho 36: int gerror;
37:
38: char iperf_timestrerr[100];
39:
1.1 misho 40: /* Do a printf to stderr. */
41: void
42: iperf_err(struct iperf_test *test, const char *format, ...)
43: {
44: va_list argp;
45: char str[1000];
1.1.1.2 misho 46: time_t now;
47: struct tm *ltm = NULL;
48: char *ct = NULL;
49:
50: /* Timestamp if requested */
51: if (test != NULL && test->timestamps) {
52: time(&now);
53: ltm = localtime(&now);
54: strftime(iperf_timestrerr, sizeof(iperf_timestrerr), test->timestamp_format, ltm);
55: ct = iperf_timestrerr;
56: }
1.1 misho 57:
58: va_start(argp, format);
59: vsnprintf(str, sizeof(str), format, argp);
60: if (test != NULL && test->json_output && test->json_top != NULL)
61: cJSON_AddStringToObject(test->json_top, "error", str);
1.1.1.3 ! misho 62: else {
1.1.1.2 misho 63: if (test && test->outfile && test->outfile != stdout) {
64: if (ct) {
65: fprintf(test->outfile, "%s", ct);
66: }
1.1 misho 67: fprintf(test->outfile, "iperf3: %s\n", str);
68: }
69: else {
1.1.1.2 misho 70: if (ct) {
71: fprintf(stderr, "%s", ct);
72: }
1.1 misho 73: fprintf(stderr, "iperf3: %s\n", str);
74: }
1.1.1.3 ! misho 75: }
1.1 misho 76: va_end(argp);
77: }
78:
79: /* Do a printf to stderr or log file as appropriate, then exit. */
80: void
81: iperf_errexit(struct iperf_test *test, const char *format, ...)
82: {
83: va_list argp;
84: char str[1000];
1.1.1.2 misho 85: time_t now;
86: struct tm *ltm = NULL;
87: char *ct = NULL;
88:
89: /* Timestamp if requested */
90: if (test != NULL && test->timestamps) {
91: time(&now);
92: ltm = localtime(&now);
93: strftime(iperf_timestrerr, sizeof(iperf_timestrerr), "%c ", ltm);
94: ct = iperf_timestrerr;
95: }
1.1 misho 96:
97: va_start(argp, format);
98: vsnprintf(str, sizeof(str), format, argp);
1.1.1.3 ! misho 99: if (test != NULL && test->json_output) {
! 100: if (test->json_top != NULL) {
! 101: cJSON_AddStringToObject(test->json_top, "error", str);
! 102: }
1.1 misho 103: iperf_json_finish(test);
104: } else
1.1.1.2 misho 105: if (test && test->outfile && test->outfile != stdout) {
106: if (ct) {
107: fprintf(test->outfile, "%s", ct);
108: }
1.1 misho 109: fprintf(test->outfile, "iperf3: %s\n", str);
110: }
111: else {
1.1.1.2 misho 112: if (ct) {
113: fprintf(stderr, "%s", ct);
114: }
1.1 misho 115: fprintf(stderr, "iperf3: %s\n", str);
116: }
117: va_end(argp);
118: if (test)
119: iperf_delete_pidfile(test);
120: exit(1);
121: }
122:
123: int i_errno;
124:
125: char *
1.1.1.2 misho 126: iperf_strerror(int int_errno)
1.1 misho 127: {
128: static char errstr[256];
129: int len, perr, herr;
130: perr = herr = 0;
131:
132: len = sizeof(errstr);
133: memset(errstr, 0, len);
134:
1.1.1.2 misho 135: switch (int_errno) {
1.1 misho 136: case IENONE:
137: snprintf(errstr, len, "no error");
138: break;
139: case IESERVCLIENT:
140: snprintf(errstr, len, "cannot be both server and client");
141: break;
142: case IENOROLE:
143: snprintf(errstr, len, "must either be a client (-c) or server (-s)");
144: break;
145: case IESERVERONLY:
146: snprintf(errstr, len, "some option you are trying to set is server only");
147: break;
148: case IECLIENTONLY:
149: snprintf(errstr, len, "some option you are trying to set is client only");
150: break;
151: case IEDURATION:
152: snprintf(errstr, len, "test duration too long (maximum = %d seconds)", MAX_TIME);
153: break;
154: case IENUMSTREAMS:
155: snprintf(errstr, len, "number of parallel streams too large (maximum = %d)", MAX_STREAMS);
156: break;
157: case IEBLOCKSIZE:
158: snprintf(errstr, len, "block size too large (maximum = %d bytes)", MAX_BLOCKSIZE);
159: break;
160: case IEBUFSIZE:
161: snprintf(errstr, len, "socket buffer size too large (maximum = %d bytes)", MAX_TCP_BUFFER);
162: break;
163: case IEINTERVAL:
164: snprintf(errstr, len, "invalid report interval (min = %g, max = %g seconds)", MIN_INTERVAL, MAX_INTERVAL);
165: break;
1.1.1.2 misho 166: case IEBIND: /* UNUSED */
1.1 misho 167: snprintf(errstr, len, "--bind must be specified to use --cport");
168: break;
169: case IEUDPBLOCKSIZE:
1.1.1.2 misho 170: snprintf(errstr, len, "block size invalid (minimum = %d bytes, maximum = %d bytes)", MIN_UDP_BLOCKSIZE, MAX_UDP_BLOCKSIZE);
171: break;
172: case IEBADTOS:
173: snprintf(errstr, len, "bad TOS value (must be between 0 and 255 inclusive)");
174: break;
175: case IESETCLIENTAUTH:
176: snprintf(errstr, len, "you must specify a username, password, and path to a valid RSA public key");
1.1 misho 177: break;
1.1.1.2 misho 178: case IESETSERVERAUTH:
179: snprintf(errstr, len, "you must specify a path to a valid RSA private key and a user credential file");
180: break;
181: case IEBADFORMAT:
182: snprintf(errstr, len, "bad format specifier (valid formats are in the set [kmgtKMGT])");
183: break;
184: case IEBADPORT:
185: snprintf(errstr, len, "port number must be between 1 and 65535 inclusive");
1.1 misho 186: break;
187: case IEMSS:
188: snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS);
189: break;
190: case IENOSENDFILE:
191: snprintf(errstr, len, "this OS does not support sendfile");
192: break;
193: case IEOMIT:
194: snprintf(errstr, len, "bogus value for --omit");
195: break;
196: case IEUNIMP:
197: snprintf(errstr, len, "an option you are trying to set is not implemented yet");
198: break;
199: case IEFILE:
200: snprintf(errstr, len, "unable to open -F file");
201: perr = 1;
202: break;
203: case IEBURST:
204: snprintf(errstr, len, "invalid burst count (maximum = %d)", MAX_BURST);
205: break;
206: case IEENDCONDITIONS:
207: snprintf(errstr, len, "only one test end condition (-t, -n, -k) may be specified");
208: break;
209: case IELOGFILE:
210: snprintf(errstr, len, "unable to open log file");
211: perr = 1;
212: break;
213: case IENOSCTP:
214: snprintf(errstr, len, "no SCTP support available");
215: break;
216: case IENEWTEST:
217: snprintf(errstr, len, "unable to create a new test");
218: perr = 1;
219: break;
220: case IEINITTEST:
221: snprintf(errstr, len, "test initialization failed");
222: perr = 1;
223: break;
1.1.1.2 misho 224: case IEAUTHTEST:
225: snprintf(errstr, len, "test authorization failed");
226: break;
1.1 misho 227: case IELISTEN:
228: snprintf(errstr, len, "unable to start listener for connections");
1.1.1.2 misho 229: herr = 1;
1.1 misho 230: perr = 1;
231: break;
232: case IECONNECT:
1.1.1.3 ! misho 233: snprintf(errstr, len, "unable to connect to server - server may have stopped running or use a different port, firewall issue, etc.");
1.1 misho 234: perr = 1;
1.1.1.2 misho 235: herr = 1;
1.1 misho 236: break;
237: case IEACCEPT:
238: snprintf(errstr, len, "unable to accept connection from client");
239: herr = 1;
240: perr = 1;
241: break;
242: case IESENDCOOKIE:
243: snprintf(errstr, len, "unable to send cookie to server");
244: perr = 1;
245: break;
246: case IERECVCOOKIE:
247: snprintf(errstr, len, "unable to receive cookie at server");
248: perr = 1;
249: break;
250: case IECTRLWRITE:
251: snprintf(errstr, len, "unable to write to the control socket");
252: perr = 1;
253: break;
254: case IECTRLREAD:
255: snprintf(errstr, len, "unable to read from the control socket");
256: perr = 1;
257: break;
258: case IECTRLCLOSE:
259: snprintf(errstr, len, "control socket has closed unexpectedly");
260: break;
261: case IEMESSAGE:
1.1.1.3 ! misho 262: snprintf(errstr, len, "received an unknown control message (ensure other side is iperf3 and not iperf)");
1.1 misho 263: break;
264: case IESENDMESSAGE:
1.1.1.3 ! misho 265: snprintf(errstr, len, "unable to send control message - port may not be available, the other side may have stopped running, etc.");
1.1 misho 266: perr = 1;
267: break;
268: case IERECVMESSAGE:
1.1.1.3 ! misho 269: snprintf(errstr, len, "unable to receive control message - port may not be available, the other side may have stopped running, etc.");
1.1 misho 270: perr = 1;
271: break;
272: case IESENDPARAMS:
273: snprintf(errstr, len, "unable to send parameters to server");
274: perr = 1;
275: break;
276: case IERECVPARAMS:
277: snprintf(errstr, len, "unable to receive parameters from client");
278: perr = 1;
279: break;
280: case IEPACKAGERESULTS:
281: snprintf(errstr, len, "unable to package results");
282: perr = 1;
283: break;
284: case IESENDRESULTS:
285: snprintf(errstr, len, "unable to send results");
286: perr = 1;
287: break;
288: case IERECVRESULTS:
289: snprintf(errstr, len, "unable to receive results");
290: perr = 1;
291: break;
292: case IESELECT:
293: snprintf(errstr, len, "select failed");
294: perr = 1;
295: break;
296: case IECLIENTTERM:
297: snprintf(errstr, len, "the client has terminated");
298: break;
299: case IESERVERTERM:
300: snprintf(errstr, len, "the server has terminated");
301: break;
302: case IEACCESSDENIED:
303: snprintf(errstr, len, "the server is busy running a test. try again later");
304: break;
305: case IESETNODELAY:
306: snprintf(errstr, len, "unable to set TCP/SCTP NODELAY");
307: perr = 1;
308: break;
309: case IESETMSS:
310: snprintf(errstr, len, "unable to set TCP/SCTP MSS");
311: perr = 1;
312: break;
313: case IESETBUF:
314: snprintf(errstr, len, "unable to set socket buffer size");
315: perr = 1;
316: break;
317: case IESETTOS:
318: snprintf(errstr, len, "unable to set IP TOS");
319: perr = 1;
320: break;
321: case IESETCOS:
322: snprintf(errstr, len, "unable to set IPv6 traffic class");
323: perr = 1;
324: break;
325: case IESETFLOW:
326: snprintf(errstr, len, "unable to set IPv6 flow label");
327: break;
328: case IEREUSEADDR:
329: snprintf(errstr, len, "unable to reuse address on socket");
330: perr = 1;
331: break;
332: case IENONBLOCKING:
333: snprintf(errstr, len, "unable to set socket to non-blocking");
334: perr = 1;
335: break;
336: case IESETWINDOWSIZE:
337: snprintf(errstr, len, "unable to set socket window size");
338: perr = 1;
339: break;
340: case IEPROTOCOL:
341: snprintf(errstr, len, "protocol does not exist");
342: break;
343: case IEAFFINITY:
344: snprintf(errstr, len, "unable to set CPU affinity");
345: perr = 1;
346: break;
1.1.1.3 ! misho 347: case IERCVTIMEOUT:
! 348: snprintf(errstr, len, "receive timeout value is incorrect or not in range");
! 349: perr = 1;
! 350: break;
! 351: case IESNDTIMEOUT:
! 352: snprintf(errstr, len, "send timeout value is incorrect or not in range");
! 353: perr = 1;
! 354: break;
! 355: case IEUDPFILETRANSFER:
! 356: snprintf(errstr, len, "cannot transfer file using UDP");
! 357: break;
! 358: case IERVRSONLYRCVTIMEOUT:
! 359: snprintf(errstr, len, "client receive timeout is valid only in receiving mode");
! 360: perr = 1;
! 361: break;
1.1 misho 362: case IEDAEMON:
363: snprintf(errstr, len, "unable to become a daemon");
364: perr = 1;
365: break;
366: case IECREATESTREAM:
367: snprintf(errstr, len, "unable to create a new stream");
368: herr = 1;
369: perr = 1;
370: break;
371: case IEINITSTREAM:
372: snprintf(errstr, len, "unable to initialize stream");
373: herr = 1;
374: perr = 1;
375: break;
376: case IESTREAMLISTEN:
377: snprintf(errstr, len, "unable to start stream listener");
1.1.1.2 misho 378: herr = 1;
1.1 misho 379: perr = 1;
380: break;
381: case IESTREAMCONNECT:
382: snprintf(errstr, len, "unable to connect stream");
383: herr = 1;
384: perr = 1;
385: break;
386: case IESTREAMACCEPT:
387: snprintf(errstr, len, "unable to accept stream connection");
388: perr = 1;
389: break;
390: case IESTREAMWRITE:
391: snprintf(errstr, len, "unable to write to stream socket");
392: perr = 1;
393: break;
394: case IESTREAMREAD:
395: snprintf(errstr, len, "unable to read from stream socket");
396: perr = 1;
397: break;
398: case IESTREAMCLOSE:
399: snprintf(errstr, len, "stream socket has closed unexpectedly");
400: break;
401: case IESTREAMID:
402: snprintf(errstr, len, "stream has an invalid id");
403: break;
404: case IENEWTIMER:
405: snprintf(errstr, len, "unable to create new timer");
406: perr = 1;
407: break;
408: case IEUPDATETIMER:
409: snprintf(errstr, len, "unable to update timer");
410: perr = 1;
411: break;
412: case IESETCONGESTION:
1.1.1.3 ! misho 413: snprintf(errstr, len, "unable to set TCP_CONGESTION: "
1.1 misho 414: "Supplied congestion control algorithm not supported on this host");
415: break;
416: case IEPIDFILE:
417: snprintf(errstr, len, "unable to write PID file");
418: perr = 1;
419: break;
420: case IEV6ONLY:
421: snprintf(errstr, len, "Unable to set/reset IPV6_V6ONLY");
422: perr = 1;
423: break;
424: case IESETSCTPDISABLEFRAG:
425: snprintf(errstr, len, "unable to set SCTP_DISABLE_FRAGMENTS");
426: perr = 1;
427: break;
428: case IESETSCTPNSTREAM:
429: snprintf(errstr, len, "unable to set SCTP_INIT num of SCTP streams\n");
430: perr = 1;
431: break;
432: case IESETPACING:
433: snprintf(errstr, len, "unable to set socket pacing");
434: perr = 1;
435: break;
1.1.1.2 misho 436: case IESETBUF2:
437: snprintf(errstr, len, "socket buffer size not set correctly");
438: break;
439: case IEREVERSEBIDIR:
440: snprintf(errstr, len, "cannot be both reverse and bidirectional");
441: break;
442: case IETOTALRATE:
443: snprintf(errstr, len, "total required bandwidth is larger than server limit");
444: break;
1.1.1.3 ! misho 445: case IESKEWTHRESHOLD:
! 446: snprintf(errstr, len, "skew threshold must be a positive number");
! 447: break;
! 448: case IEIDLETIMEOUT:
! 449: snprintf(errstr, len, "idle timeout parameter is not positive or larger than allowed limit");
! 450: break;
! 451: case IEBINDDEV:
! 452: snprintf(errstr, len, "Unable to bind-to-device (check perror, maybe permissions?)");
! 453: break;
! 454: case IEBINDDEVNOSUPPORT:
! 455: snprintf(errstr, len, "`<ip>%%<dev>` is not supported as system does not support bind to device");
! 456: break;
! 457: case IEHOSTDEV:
! 458: snprintf(errstr, len, "host device name (ip%%<dev>) is supported (and required) only for IPv6 link-local address");
! 459: break;
! 460: case IENOMSG:
! 461: snprintf(errstr, len, "idle timeout for receiving data");
! 462: break;
! 463: case IESETDONTFRAGMENT:
! 464: snprintf(errstr, len, "unable to set IP Do-Not-Fragment flag");
! 465: break;
! 466: case IESETUSERTIMEOUT:
! 467: snprintf(errstr, len, "unable to set TCP USER_TIMEOUT");
! 468: perr = 1;
! 469: break;
1.1.1.2 misho 470: default:
471: snprintf(errstr, len, "int_errno=%d", int_errno);
472: perr = 1;
473: break;
1.1 misho 474: }
475:
1.1.1.2 misho 476: /* Append the result of strerror() or gai_strerror() if appropriate */
1.1 misho 477: if (herr || perr)
478: strncat(errstr, ": ", len - strlen(errstr) - 1);
1.1.1.2 misho 479: if (errno && perr)
1.1 misho 480: strncat(errstr, strerror(errno), len - strlen(errstr) - 1);
1.1.1.2 misho 481: else if (herr && gerror) {
482: strncat(errstr, gai_strerror(gerror), len - strlen(errstr) - 1);
483: gerror = 0;
1.1 misho 484: }
485:
486: return errstr;
487: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>