Rename utility functions to avoid partner namespace conflicts.

This commit is contained in:
Ben Pfaff committed 2008-09-04 13:53:27 -07:00
1 parent 412c3875c2
commit eb0341e711
23 files changed
+135 -138

No files matched your search

+8 -7
View File
@@ -97,12 +97,13 @@ main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
if (argc - optind < 1) {
fatal(0, "at least one vconn argument required; use --help for usage");
ofp_fatal(0, "at least one vconn argument required; "
"use --help for usage");
}
retval = vlog_server_listen(NULL, NULL);
if (retval) {
fatal(retval, "Could not listen for vlog connections");
ofp_fatal(retval, "Could not listen for vlog connections");
}
n_switches = n_listeners = 0;
@@ -119,18 +120,18 @@ main(int argc, char *argv[])
if (vconn_is_passive(vconn)) {
if (n_listeners >= MAX_LISTENERS) {
fatal(0, "max %d passive connections", n_listeners);
ofp_fatal(0, "max %d passive connections", n_listeners);
}
listeners[n_listeners++] = vconn;
} else {
if (n_switches >= MAX_SWITCHES) {
fatal(0, "max %d switch connections", n_switches);
ofp_fatal(0, "max %d switch connections", n_switches);
}
new_switch(&switches[n_switches++], vconn, name);
}
}
if (n_switches == 0 && n_listeners == 0) {
fatal(0, "no active or passive switch connections");
ofp_fatal(0, "no active or passive switch connections");
}
die_if_already_running();
@@ -280,8 +281,8 @@ parse_options(int argc, char *argv[])
} else {
max_idle = atoi(optarg);
if (max_idle < 1 || max_idle > 65535) {
fatal(0, "--max-idle argument must be between 1 and "
"65535 or the word 'permanent'");
ofp_fatal(0, "--max-idle argument must be between 1 and "
"65535 or the word 'permanent'");
}
}
break;
Submodule
+1
Submodule ext added at 5e70c38c78.
+4 -5
View File
@@ -91,11 +91,10 @@ char *xmemdup0(const char *, size_t);
char *xstrdup(const char *);
char *xasprintf(const char *format, ...) PRINTF_FORMAT(1, 2);
void fatal(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3) NO_RETURN;
void error(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
void debug(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
void debug_msg(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
void hex_dump(FILE *, const void *, size_t, uintptr_t offset, bool ascii);
void ofp_fatal(int err_no, const char *format, ...)
PRINTF_FORMAT(2, 3) NO_RETURN;
void ofp_error(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
void ofp_hex_dump(FILE *, const void *, size_t, uintptr_t offset, bool ascii);
#ifdef __cplusplus
}
+4 -4
View File
@@ -134,8 +134,8 @@ die_if_already_running(void)
pid_t pid = already_running();
if (pid) {
if (!force) {
fatal(0, "%s: already running as pid %ld",
get_pidfile(), (long int) pid);
ofp_fatal(0, "%s: already running as pid %ld",
get_pidfile(), (long int) pid);
} else {
VLOG_WARN("%s: %s already running as pid %ld",
get_pidfile(), program_name, (long int) pid);
@@ -204,7 +204,7 @@ daemonize(void)
char c = 0;
int fds[2];
if (pipe(fds) < 0) {
fatal(errno, "pipe failed");
ofp_fatal(errno, "pipe failed");
}
switch (fork()) {
@@ -227,7 +227,7 @@ daemonize(void)
case -1:
/* Error. */
fatal(errno, "could not fork");
ofp_fatal(errno, "could not fork");
break;
}
} else {
+2 -2
View File
@@ -108,11 +108,11 @@ fatal_signal_block()
sigaddset(&fatal_signal_set, sig_nr);
if (sigaction(sig_nr, NULL, &old_sa)) {
fatal(errno, "sigaction");
ofp_fatal(errno, "sigaction");
}
if (old_sa.sa_handler == SIG_DFL
&& signal(sig_nr, fatal_signal_handler) == SIG_ERR) {
fatal(errno, "signal");
ofp_fatal(errno, "signal");
}
}
atexit(atexit_handler);
+1 -1
View File
@@ -773,7 +773,7 @@ init_netdev(void)
fatal_signal_add_hook(restore_all_flags, NULL, true);
af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (af_inet_sock < 0) {
fatal(errno, "socket(AF_INET)");
ofp_fatal(errno, "socket(AF_INET)");
}
}
}
+5 -5
View File
@@ -96,7 +96,7 @@ ofp_packet_to_string(const void *data, size_t len, size_t total_len)
pcap = tmpfile();
if (!pcap) {
error(errno, "tmpfile");
ofp_error(errno, "tmpfile");
return xstrdup("<error>");
}
@@ -121,7 +121,7 @@ ofp_packet_to_string(const void *data, size_t len, size_t total_len)
fflush(pcap);
if (ferror(pcap)) {
error(errno, "error writing temporary file");
ofp_error(errno, "error writing temporary file");
}
rewind(pcap);
@@ -130,7 +130,7 @@ ofp_packet_to_string(const void *data, size_t len, size_t total_len)
tcpdump = popen(command, "r");
fclose(pcap);
if (!tcpdump) {
error(errno, "exec(\"%s\")", command);
ofp_error(errno, "exec(\"%s\")", command);
return xstrdup("<error>");
}
@@ -141,9 +141,9 @@ ofp_packet_to_string(const void *data, size_t len, size_t total_len)
status = pclose(tcpdump);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status))
error(0, "tcpdump exited with status %d", WEXITSTATUS(status));
ofp_error(0, "tcpdump exited with status %d", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
error(0, "tcpdump exited with signal %d", WTERMSIG(status));
ofp_error(0, "tcpdump exited with signal %d", WTERMSIG(status));
}
return ds_cstr(&ds);
}
+1 -1
View File
@@ -48,7 +48,7 @@ random_init(void)
struct timeval tv;
inited = true;
if (gettimeofday(&tv, NULL) < 0) {
fatal(errno, "gettimeofday");
ofp_fatal(errno, "gettimeofday");
}
srand(tv.tv_sec ^ tv.tv_usec);
}
+1 -1
View File
@@ -304,7 +304,7 @@ run_CONNECTING(struct rconn *rc)
VLOG_WARN("%s: connected", rc->name);
rc->n_successful_connections++;
if (vconn_is_passive(rc->vconn)) {
error(0, "%s: passive vconn not supported", rc->name);
ofp_error(0, "%s: passive vconn not supported", rc->name);
state_transition(rc, S_VOID);
} else {
state_transition(rc, S_ACTIVE);
+4 -4
View File
@@ -81,7 +81,7 @@ time_init(void)
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if (sigaction(SIGALRM, &sa, NULL)) {
fatal(errno, "sigaction(SIGALRM) failed");
ofp_fatal(errno, "sigaction(SIGALRM) failed");
}
/* Set up periodic timer. */
@@ -89,7 +89,7 @@ time_init(void)
itimer.it_interval.tv_usec = TIME_UPDATE_INTERVAL * 1000;
itimer.it_value = itimer.it_interval;
if (setitimer(ITIMER_REAL, &itimer, NULL)) {
fatal(errno, "setitimer failed");
ofp_fatal(errno, "setitimer failed");
}
}
@@ -216,7 +216,7 @@ block_sigalrm(sigset_t *oldsigs)
sigemptyset(&sigalrm);
sigaddset(&sigalrm, SIGALRM);
if (sigprocmask(SIG_BLOCK, &sigalrm, oldsigs)) {
fatal(errno, "sigprocmask");
ofp_fatal(errno, "sigprocmask");
}
}
@@ -224,6 +224,6 @@ static void
unblock_sigalrm(const sigset_t *oldsigs)
{
if (sigprocmask(SIG_SETMASK, oldsigs, NULL)) {
fatal(errno, "sigprocmask");
ofp_fatal(errno, "sigprocmask");
}
}
+7 -18
View File
@@ -43,7 +43,7 @@ const char *program_name;
static void
out_of_memory(void)
{
fatal(0, "virtual memory exhausted");
ofp_fatal(0, "virtual memory exhausted");
}
void *
@@ -119,7 +119,8 @@ xasprintf(const char *format, ...)
return s;
}
void fatal(int err_no, const char *format, ...)
void
ofp_fatal(int err_no, const char *format, ...)
{
va_list args;
@@ -134,20 +135,8 @@ void fatal(int err_no, const char *format, ...)
exit(EXIT_FAILURE);
}
void error(int err_no, const char *format, ...)
{
va_list args;
fprintf(stderr, "%s: ", program_name);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
if (err_no != 0)
fprintf(stderr, " (%s)", strerror(err_no));
putc('\n', stderr);
}
void debug(int err_no, const char *format, ...)
void
ofp_error(int err_no, const char *format, ...)
{
va_list args;
@@ -173,8 +162,8 @@ void set_program_name(const char *argv0)
* byte in 'buf'. If 'ascii' is true then the corresponding ASCII characters
* are also rendered alongside. */
void
hex_dump(FILE *stream, const void *buf_, size_t size,
uintptr_t ofs, bool ascii)
ofp_hex_dump(FILE *stream, const void *buf_, size_t size,
uintptr_t ofs, bool ascii)
{
const uint8_t *buf = buf_;
const size_t per_line = 16; /* Maximum bytes per line. */
+1 -1
View File
@@ -79,7 +79,7 @@ netlink_open(const char *name, char *suffix, struct vconn **vconnp)
subscribe = 1;
if (sscanf(suffix, "%d:%d", &dp_idx, &subscribe) < 1) {
error(0, "%s: syntax error", name);
ofp_error(0, "%s: syntax error", name);
return EAFNOSUPPORT;
}
+3 -3
View File
@@ -275,7 +275,7 @@ ssl_open(const char *name, char *suffix, struct vconn **vconnp)
host_name = strtok_r(suffix, "::", &save_ptr);
port_string = strtok_r(NULL, "::", &save_ptr);
if (!host_name) {
error(0, "%s: bad peer name format", name);
ofp_error(0, "%s: bad peer name format", name);
return EAFNOSUPPORT;
}
@@ -868,8 +868,8 @@ tmp_dh_callback(SSL *ssl, int is_export UNUSED, int keylength)
if (!dh->dh) {
dh->dh = dh->constructor();
if (!dh->dh) {
fatal(ENOMEM, "out of memory constructing "
"Diffie-Hellman parameters");
ofp_fatal(ENOMEM, "out of memory constructing "
"Diffie-Hellman parameters");
}
}
return dh->dh;
+1 -1
View File
@@ -88,7 +88,7 @@ tcp_open(const char *name, char *suffix, struct vconn **vconnp)
host_name = strtok_r(suffix, "::", &save_ptr);
port_string = strtok_r(NULL, "::", &save_ptr);
if (!host_name) {
error(0, "%s: bad peer name format", name);
ofp_error(0, "%s: bad peer name format", name);
return EAFNOSUPPORT;
}
+2 -2
View File
@@ -160,7 +160,7 @@ vconn_open(const char *name, struct vconn **vconnp)
*vconnp = NULL;
prefix_len = strcspn(name, ":");
if (prefix_len == strlen(name)) {
error(0, "`%s' not correct format for peer name", name);
ofp_error(0, "`%s' not correct format for peer name", name);
return EAFNOSUPPORT;
}
for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
@@ -180,7 +180,7 @@ vconn_open(const char *name, struct vconn **vconnp)
return retval;
}
}
error(0, "unknown peer type `%.*s'", (int) prefix_len, name);
ofp_error(0, "unknown peer type `%.*s'", (int) prefix_len, name);
return EAFNOSUPPORT;
}
+1 -1
View File
@@ -240,7 +240,7 @@ vlog_set_verbosity(const char *arg)
if (arg) {
char *msg = vlog_set_levels_from_string(arg);
if (msg) {
fatal(0, "processing \"%s\": %s", arg, msg);
ofp_fatal(0, "processing \"%s\": %s", arg, msg);
}
} else {
vlog_set_levels(VLM_ANY_MODULE, VLF_ANY_FACILITY, VLL_DBG);
+26 -23
View File
@@ -219,10 +219,10 @@ main(int argc, char *argv[])
struct vconn *listener;
retval = vconn_open(name, &listener);
if (retval && retval != EAGAIN) {
fatal(retval, "opening %s", name);
ofp_fatal(retval, "opening %s", name);
}
if (!vconn_is_passive(listener)) {
fatal(0, "%s is not a passive vconn", name);
ofp_fatal(0, "%s is not a passive vconn", name);
}
listeners[n_listeners++] = listener;
}
@@ -236,7 +236,7 @@ main(int argc, char *argv[])
/* Start listening for vlogconf requests. */
retval = vlog_server_listen(NULL, NULL);
if (retval) {
fatal(retval, "Could not listen for vlog connections");
ofp_fatal(retval, "Could not listen for vlog connections");
}
die_if_already_running();
@@ -256,7 +256,7 @@ main(int argc, char *argv[])
if (s.controller_name) {
retval = rconn_connect(remote_rconn, s.controller_name);
if (retval == EAFNOSUPPORT) {
fatal(0, "No support for %s vconn", s.controller_name);
ofp_fatal(0, "No support for %s vconn", s.controller_name);
}
}
switch_status_register_category(switch_status, "remote",
@@ -713,7 +713,7 @@ in_band_hook_create(const struct settings *s, struct switch_status *ss,
retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE,
&in_band->of_device);
if (retval) {
fatal(retval, "Could not open %s device", s->of_name);
ofp_fatal(retval, "Could not open %s device", s->of_name);
}
memcpy(in_band->mac, netdev_get_etheraddr(in_band->of_device),
ETH_ADDR_LEN);
@@ -1264,11 +1264,11 @@ discovery_init(const struct settings *s, struct switch_status *ss)
/* Bring ofX network device up. */
retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
if (retval) {
fatal(retval, "Could not open %s device", s->of_name);
ofp_fatal(retval, "Could not open %s device", s->of_name);
}
retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
if (retval) {
fatal(retval, "Could not bring %s device up", s->of_name);
ofp_fatal(retval, "Could not bring %s device up", s->of_name);
}
netdev_close(netdev);
@@ -1276,7 +1276,7 @@ discovery_init(const struct settings *s, struct switch_status *ss)
retval = dhclient_create(s->of_name, modify_dhcp_request,
validate_dhcp_offer, (void *) s, &dhcp);
if (retval) {
fatal(retval, "Failed to initialize DHCP client");
ofp_fatal(retval, "Failed to initialize DHCP client");
}
dhclient_init(dhcp, 0);
@@ -1426,15 +1426,15 @@ parse_options(int argc, char *argv[], struct settings *s)
} else if (!strcmp(optarg, "closed")) {
s->fail_mode = FAIL_CLOSED;
} else {
fatal(0,
"-f or --fail argument must be \"open\" or \"closed\"");
ofp_fatal(0, "-f or --fail argument must be \"open\" "
"or \"closed\"");
}
break;
case OPT_INACTIVITY_PROBE:
s->probe_interval = atoi(optarg);
if (s->probe_interval < 5) {
fatal(0, "--inactivity-probe argument must be at least 5");
ofp_fatal(0, "--inactivity-probe argument must be at least 5");
}
break;
@@ -1444,8 +1444,8 @@ parse_options(int argc, char *argv[], struct settings *s)
} else {
s->max_idle = atoi(optarg);
if (s->max_idle < 1 || s->max_idle > 65535) {
fatal(0, "--max-idle argument must be between 1 and "
"65535 or the word 'permanent'");
ofp_fatal(0, "--max-idle argument must be between 1 and "
"65535 or the word 'permanent'");
}
}
break;
@@ -1453,7 +1453,7 @@ parse_options(int argc, char *argv[], struct settings *s)
case OPT_MAX_BACKOFF:
s->max_backoff = atoi(optarg);
if (s->max_backoff < 1) {
fatal(0, "--max-backoff argument must be at least 1");
ofp_fatal(0, "--max-backoff argument must be at least 1");
} else if (s->max_backoff > 3600) {
s->max_backoff = 3600;
}
@@ -1463,7 +1463,7 @@ parse_options(int argc, char *argv[], struct settings *s)
if (optarg) {
s->rate_limit = atoi(optarg);
if (s->rate_limit < 1) {
fatal(0, "--rate-limit argument must be at least 1");
ofp_fatal(0, "--rate-limit argument must be at least 1");
}
} else {
s->rate_limit = 1000;
@@ -1473,7 +1473,7 @@ parse_options(int argc, char *argv[], struct settings *s)
case OPT_BURST_LIMIT:
s->burst_limit = atoi(optarg);
if (s->burst_limit < 1) {
fatal(0, "--burst-limit argument must be at least 1");
ofp_fatal(0, "--burst-limit argument must be at least 1");
}
break;
@@ -1491,8 +1491,9 @@ parse_options(int argc, char *argv[], struct settings *s)
case 'l':
if (s->n_listeners >= MAX_MGMT) {
fatal(0, "-l or --listen may be specified at most %d times",
MAX_MGMT);
ofp_fatal(0,
"-l or --listen may be specified at most %d times",
MAX_MGMT);
}
s->listener_names[s->n_listeners++] = optarg;
break;
@@ -1522,7 +1523,8 @@ parse_options(int argc, char *argv[], struct settings *s)
argc -= optind;
argv += optind;
if (argc < 1 || argc > 2) {
fatal(0, "need one or two non-option arguments; use --help for usage");
ofp_fatal(0, "need one or two non-option arguments; "
"use --help for usage");
}
/* Local and remote vconns. */
@@ -1530,7 +1532,8 @@ parse_options(int argc, char *argv[], struct settings *s)
if (strncmp(s->nl_name, "nl:", 3)
|| strlen(s->nl_name) < 4
|| s->nl_name[strspn(s->nl_name + 3, "0123456789") + 3]) {
fatal(0, "%s: argument is not of the form \"nl:DP_IDX\"", s->nl_name);
ofp_fatal(0, "%s: argument is not of the form \"nl:DP_IDX\"",
s->nl_name);
}
s->of_name = xasprintf("of%s", s->nl_name + 3);
s->controller_name = argc > 1 ? xstrdup(argv[1]) : NULL;
@@ -1545,7 +1548,7 @@ parse_options(int argc, char *argv[], struct settings *s)
size_t length = regerror(retval, &s->accept_controller_regex, NULL, 0);
char *buffer = xmalloc(length);
regerror(retval, &s->accept_controller_regex, buffer, length);
fatal(0, "%s: %s", accept_re, buffer);
ofp_fatal(0, "%s: %s", accept_re, buffer);
}
s->accept_controller_re = accept_re;
@@ -1559,12 +1562,12 @@ parse_options(int argc, char *argv[], struct settings *s)
retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
if (retval) {
fatal(retval, "Could not open %s device", s->of_name);
ofp_fatal(retval, "Could not open %s device", s->of_name);
}
retval = netdev_get_flags(netdev, &flags);
if (retval) {
fatal(retval, "Could not get flags for %s device", s->of_name);
ofp_fatal(retval, "Could not get flags for %s device", s->of_name);
}
s->in_band = (flags & NETDEV_UP) != 0;
+13 -12
View File
@@ -93,13 +93,13 @@ main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
if (argc - optind != 1) {
fatal(0, "missing controller argument; use --help for usage");
ofp_fatal(0, "missing controller argument; use --help for usage");
}
rconn = rconn_create(60, max_backoff);
error = rconn_connect(rconn, argv[optind]);
if (error == EAFNOSUPPORT) {
fatal(0, "no support for %s vconn", argv[optind]);
ofp_fatal(0, "no support for %s vconn", argv[optind]);
}
error = dp_new(&dp, dpid, rconn);
if (listen_vconn_name) {
@@ -108,15 +108,15 @@ main(int argc, char *argv[])
retval = vconn_open(listen_vconn_name, &listen_vconn);
if (retval && retval != EAGAIN) {
fatal(retval, "opening %s", listen_vconn_name);
ofp_fatal(retval, "opening %s", listen_vconn_name);
}
if (!vconn_is_passive(listen_vconn)) {
fatal(0, "%s is not a passive vconn", listen_vconn_name);
ofp_fatal(0, "%s is not a passive vconn", listen_vconn_name);
}
dp_add_listen_vconn(dp, listen_vconn);
}
if (error) {
fatal(error, "could not create datapath");
ofp_fatal(error, "could not create datapath");
}
if (port_list) {
add_ports(dp, port_list);
@@ -124,7 +124,7 @@ main(int argc, char *argv[])
error = vlog_server_listen(NULL, NULL);
if (error) {
fatal(error, "could not listen for vlog connections");
ofp_fatal(error, "could not listen for vlog connections");
}
die_if_already_running();
@@ -152,7 +152,7 @@ add_ports(struct datapath *dp, char *port_list)
port = strtok_r(NULL, ",,", &save_ptr)) {
int error = dp_add_port(dp, port);
if (error) {
fatal(error, "failed to add port %s", port);
ofp_fatal(error, "failed to add port %s", port);
}
}
}
@@ -201,12 +201,13 @@ parse_options(int argc, char *argv[])
case 'd':
if (strlen(optarg) != 12
|| strspn(optarg, "0123456789abcdefABCDEF") != 12) {
fatal(0, "argument to -d or --datapath-id must be "
"exactly 12 hex digits");
ofp_fatal(0, "argument to -d or --datapath-id must be "
"exactly 12 hex digits");
}
dpid = strtoll(optarg, NULL, 16);
if (!dpid) {
fatal(0, "argument to -d or --datapath-id must be nonzero");
ofp_fatal(0, "argument to -d or --datapath-id must "
"be nonzero");
}
break;
@@ -244,7 +245,7 @@ parse_options(int argc, char *argv[])
case OPT_MAX_BACKOFF:
max_backoff = atoi(optarg);
if (max_backoff < 1) {
fatal(0, "--max-backoff argument must be at least 1");
ofp_fatal(0, "--max-backoff argument must be at least 1");
} else if (max_backoff > 3600) {
max_backoff = 3600;
}
@@ -268,7 +269,7 @@ parse_options(int argc, char *argv[])
case 'l':
if (listen_vconn_name) {
fatal(0, "-l or --listen may be only specified once");
ofp_fatal(0, "-l or --listen may be only specified once");
}
listen_vconn_name = optarg;
break;
+5 -4
View File
@@ -75,13 +75,13 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (argc != 1) {
fatal(0, "exactly one non-option argument required; "
"use --help for help");
ofp_fatal(0, "exactly one non-option argument required; "
"use --help for help");
}
error = dhclient_create(argv[0], modify_dhcp_request, NULL, NULL, &cli);
if (error) {
fatal(error, "dhclient_create failed");
ofp_fatal(error, "dhclient_create failed");
}
dhclient_init(cli, request_ip.s_addr);
fatal_signal_add_hook(release, cli, true);
@@ -149,7 +149,8 @@ parse_options(int argc, char *argv[])
switch (c) {
case OPT_REQUEST_IP:
if (!inet_aton(optarg, &request_ip)) {
fatal(0, "--request-ip argument is not a valid IP address");
ofp_fatal(0,
"--request-ip argument is not a valid IP address");
}
break;
+29 -27
View File
@@ -100,24 +100,24 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (argc < 1)
fatal(0, "missing command name; use --help for help");
ofp_fatal(0, "missing command name; use --help for help");
for (p = all_commands; p->name != NULL; p++) {
if (!strcmp(p->name, argv[0])) {
int n_arg = argc - 1;
if (n_arg < p->min_args)
fatal(0, "'%s' command requires at least %d arguments",
p->name, p->min_args);
ofp_fatal(0, "'%s' command requires at least %d arguments",
p->name, p->min_args);
else if (n_arg > p->max_args)
fatal(0, "'%s' command takes at most %d arguments",
p->name, p->max_args);
ofp_fatal(0, "'%s' command takes at most %d arguments",
p->name, p->max_args);
else {
p->handler(argc, argv);
exit(0);
}
}
}
fatal(0, "unknown command '%s'; use --help for help", argv[0]);
ofp_fatal(0, "unknown command '%s'; use --help for help", argv[0]);
return 0;
}
@@ -148,8 +148,8 @@ parse_options(int argc, char *argv[])
case 't':
timeout = strtoul(optarg, NULL, 10);
if (timeout <= 0) {
fatal(0, "value %s on -t or --timeout is not at least 1",
optarg);
ofp_fatal(0, "value %s on -t or --timeout is not at least 1",
optarg);
} else {
time_alarm(timeout);
}
@@ -264,7 +264,7 @@ static void open_nl_vconn(const char *name, bool subscribe, struct dpif *dpif)
if (strncmp(name, "nl:", 3)
|| strlen(name) < 4
|| name[strspn(name + 3, "0123456789") + 3]) {
fatal(0, "%s: argument is not of the form \"nl:DP_ID\"", name);
ofp_fatal(0, "%s: argument is not of the form \"nl:DP_ID\"", name);
}
run(dpif_open(atoi(name + 3), subscribe, dpif), "opening datapath");
}
@@ -297,8 +297,8 @@ static void add_del_ports(int argc UNUSED, char *argv[],
for (i = 2; i < argc; i++) {
int retval = function(&dp, argv[i]);
if (retval) {
error(retval, "failed to %s %s %s %s",
operation, argv[i], preposition, argv[1]);
ofp_error(retval, "failed to %s %s %s %s",
operation, argv[i], preposition, argv[1]);
failure = true;
}
}
@@ -457,7 +457,7 @@ str_to_int(const char *str)
errno = 0;
value = strtoul(str, &tail, 0);
if (errno == EINVAL || errno == ERANGE || *tail) {
fatal(0, "invalid numeric format %s", str);
ofp_fatal(0, "invalid numeric format %s", str);
}
return value;
}
@@ -467,7 +467,7 @@ str_to_mac(const char *str, uint8_t mac[6])
{
if (sscanf(str, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6) {
fatal(0, "invalid mac address %s", str);
ofp_fatal(0, "invalid mac address %s", str);
}
}
@@ -483,7 +483,7 @@ str_to_ip(const char *str_, uint32_t *ip)
name = strtok_r(str, "//", &save_ptr);
retval = name ? lookup_ip(name, &in_addr) : EINVAL;
if (retval) {
fatal(0, "%s: could not convert to IP address", str);
ofp_fatal(0, "%s: could not convert to IP address", str);
}
*ip = in_addr.s_addr;
@@ -506,13 +506,15 @@ str_to_ip(const char *str_, uint32_t *ip)
/* Verify that the rest of the bits are 1-bits. */
for (; i < 32; i++) {
if (!(nm & (1u << i))) {
fatal(0, "%s: %s is not a valid netmask", str, netmask);
ofp_fatal(0, "%s: %s is not a valid netmask",
str, netmask);
}
}
} else {
int prefix = atoi(netmask);
if (prefix <= 0 || prefix > 32) {
fatal(0, "%s: network prefix bits not between 1 and 32", str);
ofp_fatal(0, "%s: network prefix bits not between 1 and 32",
str);
}
n_wild = 32 - prefix;
}
@@ -579,7 +581,7 @@ str_to_action(char *str, struct ofp_action *action, int *n_actions)
} else if (strspn(act, "0123456789") == strlen(act)) {
port = str_to_int(act);
} else {
fatal(0, "Unknown action: %s", act);
ofp_fatal(0, "Unknown action: %s", act);
}
if (port != OFPP_MAX) {
@@ -680,13 +682,13 @@ str_to_flow(char *string, struct ofp_match *match,
if (action) {
char *act_str = strstr(string, "action");
if (!act_str) {
fatal(0, "must specify an action");
ofp_fatal(0, "must specify an action");
}
*(act_str-1) = '\0';
act_str = strchr(act_str, '=');
if (!act_str) {
fatal(0, "must specify an action");
ofp_fatal(0, "must specify an action");
}
act_str++;
@@ -712,7 +714,7 @@ str_to_flow(char *string, struct ofp_match *match,
value = strtok(NULL, ", \t\r\n");
if (!value) {
fatal(0, "field %s missing value", name);
ofp_fatal(0, "field %s missing value", name);
}
if (table_idx && !strcmp(name, "table")) {
@@ -742,7 +744,7 @@ str_to_flow(char *string, struct ofp_match *match,
}
}
} else {
fatal(0, "unknown keyword %s", name);
ofp_fatal(0, "unknown keyword %s", name);
}
}
}
@@ -814,7 +816,7 @@ static void do_add_flows(int argc, char *argv[])
file = fopen(argv[2], "r");
if (file == NULL) {
fatal(errno, "%s: open", argv[2]);
ofp_fatal(errno, "%s: open", argv[2]);
}
run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
@@ -904,7 +906,7 @@ do_probe(int argc, char *argv[])
run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
if (reply->size != request->size) {
fatal(0, "reply does not match request");
ofp_fatal(0, "reply does not match request");
}
ofpbuf_delete(reply);
vconn_close(vconn);
@@ -955,7 +957,7 @@ do_mod_port(int argc, char *argv[])
}
}
if (port_idx == n_ports) {
fatal(0, "couldn't find monitored port: %s", argv[2]);
ofp_fatal(0, "couldn't find monitored port: %s", argv[2]);
}
opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
@@ -979,7 +981,7 @@ do_mod_port(int argc, char *argv[])
opm->mask |= htonl(OFPPFL_NO_FLOOD);
opm->desc.flags |= htonl(OFPPFL_NO_FLOOD);
} else {
fatal(0, "unknown mod-port command '%s'", argv[3]);
ofp_fatal(0, "unknown mod-port command '%s'", argv[3]);
}
send_openflow_buffer(vconn, request);
@@ -998,7 +1000,7 @@ do_ping(int argc, char *argv[])
payload = argc > 2 ? atoi(argv[2]) : 64;
if (payload > max_payload) {
fatal(0, "payload must be between 0 and %zu bytes", max_payload);
ofp_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
}
run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
@@ -1048,7 +1050,7 @@ do_benchmark(int argc, char *argv[])
payload_size = atoi(argv[2]);
if (payload_size > max_payload) {
fatal(0, "payload must be between 0 and %zu bytes", max_payload);
ofp_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
}
message_size = sizeof(struct ofp_header) + payload_size;
+12 -12
View File
@@ -98,8 +98,8 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (argc < 1) {
fatal(0, "need at least one non-option argument; "
"use --help for usage");
ofp_fatal(0, "need at least one non-option argument; "
"use --help for usage");
}
ifaces = xmalloc(argc * sizeof *ifaces);
@@ -110,7 +110,7 @@ main(int argc, char *argv[])
}
}
if (!n_ifaces) {
fatal(0, "failed to initialize any DHCP clients");
ofp_fatal(0, "failed to initialize any DHCP clients");
}
for (i = 0; i < n_ifaces; i++) {
@@ -125,12 +125,12 @@ main(int argc, char *argv[])
size_t length = regerror(retval, &accept_controller_regex, NULL, 0);
char *buffer = xmalloc(length);
regerror(retval, &accept_controller_regex, buffer, length);
fatal(0, "%s: %s", accept_controller_re, buffer);
ofp_fatal(0, "%s: %s", accept_controller_re, buffer);
}
retval = vlog_server_listen(NULL, NULL);
if (retval) {
fatal(retval, "Could not listen for vlog connections");
ofp_fatal(retval, "Could not listen for vlog connections");
}
die_if_already_running();
@@ -230,12 +230,12 @@ iface_init(struct iface *iface, const char *netdev_name)
retval = netdev_open(iface->name, NETDEV_ETH_TYPE_NONE, &netdev);
if (retval) {
error(retval, "Could not open %s device", iface->name);
ofp_error(retval, "Could not open %s device", iface->name);
return false;
}
retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
if (retval) {
error(retval, "Could not bring %s device up", iface->name);
ofp_error(retval, "Could not bring %s device up", iface->name);
return false;
}
netdev_close(netdev);
@@ -244,7 +244,7 @@ iface_init(struct iface *iface, const char *netdev_name)
retval = dhclient_create(iface->name, modify_dhcp_request,
validate_dhcp_offer, NULL, &iface->dhcp);
if (retval) {
error(retval, "%s: failed to initialize DHCP client", iface->name);
ofp_error(retval, "%s: failed to initialize DHCP client", iface->name);
return false;
}
@@ -352,8 +352,8 @@ parse_options(int argc, char *argv[])
case 't':
timeout = strtoul(optarg, NULL, 10);
if (timeout <= 0) {
fatal(0, "value %s on -t or --timeout is not at least 1",
optarg);
ofp_fatal(0, "value %s on -t or --timeout is not at least 1",
optarg);
} else {
time_alarm(timeout);
}
@@ -381,8 +381,8 @@ parse_options(int argc, char *argv[])
free(short_options);
if ((exit_without_bind + exit_after_bind + !detach_after_bind) > 1) {
fatal(0, "--exit-without-bind, --exit-after-bind, and --no-detach "
"are mutually exclusive");
ofp_fatal(0, "--exit-without-bind, --exit-after-bind, and --no-detach "
"are mutually exclusive");
}
if (detach_after_bind) {
set_detach();
+3 -3
View File
@@ -70,8 +70,8 @@ main(int argc, char *argv[])
argv += optind;
if (argc < 1) {
if (!force) {
fatal(0, "need at least one non-option argument; "
"use --help for usage");
ofp_fatal(0, "need at least one non-option argument; "
"use --help for usage");
}
}
@@ -202,7 +202,7 @@ parse_options(int argc, char *argv[])
goto got_name;
}
}
fatal(0, "unknown signal \"%s\"", optarg);
ofp_fatal(0, "unknown signal \"%s\"", optarg);
got_name: ;
}
break;
+1 -1
View File
@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
break;
}
if (!strchr("ath", option) && n_clients == 0) {
fatal(0, "no targets specified (use --help for help)");
ofp_fatal(0, "no targets specified (use --help for help)");
} else {
++n_actions;
}