From 188d43f98d19d61c4b32ad14372c32a5354d7cef Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 10 Sep 2020 01:44:10 -0400 Subject: [PATCH] Improve error reporting, CLI code reuse Changes: * Move network interface configuration logic from bin/pattyd.c to bin/if.c; implement a more robust state machine * Move KISS TNC configuration code from bin/pattyd.c to bin/kiss.c * Ensure configuration file name, line number, and erroneous part of an expression are clearly indicated upon failure Other changes: * Improve bin/Makefile to rebuild objects when accompanying header files change * Refer to HEADERS_SUBDIR, not HEADER_SUBDIR, in Makefiles --- bin/Makefile | 12 +- bin/ax25dump.c | 33 ++-- bin/if.c | 134 +++++++++++++++++ bin/kiss.c | 39 +++++ bin/pattyd.c | 315 +++++++++++++-------------------------- include/patty/ax25/if.h | 1 + include/patty/bin/if.h | 17 +++ include/patty/bin/kiss.h | 13 ++ src/Makefile | 8 +- 9 files changed, 340 insertions(+), 232 deletions(-) create mode 100644 bin/if.c create mode 100644 bin/kiss.c create mode 100644 include/patty/bin/if.h create mode 100644 include/patty/bin/kiss.h diff --git a/bin/Makefile b/bin/Makefile index 53d2171..bae4526 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -3,6 +3,7 @@ include ../mk/build.mk CC = $(CROSS)cc INCLUDE_PATH = ../include +HEADERS_SUBDIR = patty/bin CFLAGS += -I$(INCLUDE_PATH) LDFLAGS = -L../src -lpatty @@ -10,7 +11,10 @@ LDFLAGS = -L../src -lpatty PROGRAMS = pattyd ax25dump MANPAGES = pattyd.8 -OBJS = pattyd.o ax25dump.o +HEADERS = kiss.h if.h +HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADERS_SUBDIR)/, $(HEADERS)) + +OBJS = pattyd.o ax25dump.o kiss.o if.o all: $(PROGRAMS) @@ -19,13 +23,13 @@ install: $(PROGRAMS) $(MANPAGES) $(INSTALL) -c -m 0644 pattyd.8 $(MANDIR)/man8 $(INSTALL) -c -m 0755 $(PROGRAMS) $(PREFIX)/bin -pattyd: pattyd.o +pattyd: pattyd.o kiss.o if.o $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) -ax25dump: ax25dump.o +ax25dump: ax25dump.o kiss.o $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) -$(OBJS): %.o: %.c +$(OBJS): %.o: %.c $(HEADERS_BUILD) $(CC) $(CFLAGS) -c $< clean: diff --git a/bin/ax25dump.c b/bin/ax25dump.c index afa4cba..a3ad8a5 100644 --- a/bin/ax25dump.c +++ b/bin/ax25dump.c @@ -14,6 +14,8 @@ #include #include +#include + static void usage(int argc, char **argv, const char *message, ...) { if (message != NULL) { va_list args; @@ -25,7 +27,8 @@ static void usage(int argc, char **argv, const char *message, ...) { } fprintf(stderr, "usage: %s /var/run/patty/patty.sock ifname\n" - " %s file.cap\n", argv[0], argv[0]); + " %s /dev/ttyXYZ [tioargs ...]\n" + " %s file.cap\n", argv[0], argv[0], argv[0]); exit(EX_USAGE); } @@ -36,7 +39,8 @@ int main(int argc, char **argv) { uint8_t buf[4096]; ssize_t readlen; - patty_kiss_tnc_info info; + patty_bin_kiss_data data; + patty_kiss_tnc_info *info = &data.info; patty_kiss_tnc *raw; struct stat st; @@ -51,6 +55,8 @@ int main(int argc, char **argv) { goto error_stat; } + memset(&data, '\0', sizeof(data)); + if ((st.st_mode & S_IFMT) == S_IFSOCK) { patty_client_setsockopt_if ifreq; @@ -58,7 +64,7 @@ int main(int argc, char **argv) { usage(argc, argv, "No interface name provided"); } - info.flags = PATTY_KISS_TNC_FD; + info->flags = PATTY_KISS_TNC_FD; if ((client = patty_client_new(argv[1])) == NULL) { fprintf(stderr, "%s: %s: %s: %s\n", @@ -67,7 +73,7 @@ int main(int argc, char **argv) { goto error_client_new; } - if ((info.fd = patty_client_socket(client, PATTY_AX25_PROTO_NONE, PATTY_AX25_SOCK_RAW)) < 0) { + if ((info->fd = patty_client_socket(client, PATTY_AX25_PROTO_NONE, PATTY_AX25_SOCK_RAW)) < 0) { fprintf(stderr, "%s: %s: %s\n", argv[0], "patty_client_socket()", strerror(errno)); @@ -78,20 +84,24 @@ int main(int argc, char **argv) { ifreq.state = PATTY_AX25_SOCK_PROMISC; - if (patty_client_setsockopt(client, info.fd, PATTY_AX25_SOCK_IF, &ifreq, sizeof(ifreq)) < 0) { + if (patty_client_setsockopt(client, info->fd, PATTY_AX25_SOCK_IF, &ifreq, sizeof(ifreq)) < 0) { fprintf(stderr, "%s: %s: %s\n", argv[0], "patty_client_setsockopt()", strerror(errno)); goto error_client_setsockopt; } } else { - info.flags = PATTY_KISS_TNC_DEVICE; - info.device = argv[1]; + if (patty_bin_kiss_config(&data, argc - 1, argv + 1) < 0) { + fprintf(stderr, "%s: %s: %s\n", + argv[0], argv[1], data.err); + + goto error_kiss_config; + } } - if ((raw = patty_kiss_tnc_new(&info)) == NULL) { + if ((raw = patty_kiss_tnc_new(info)) == NULL) { fprintf(stderr, "%s: fd %d: %s: %s\n", - argv[0], info.fd, "patty_kiss_tnc_new()", strerror(errno)); + argv[0], info->fd, "patty_kiss_tnc_new()", strerror(errno)); goto error_kiss_tnc_new; } @@ -157,7 +167,7 @@ error_ax25_frame_decode_address: patty_kiss_tnc_destroy(raw); if ((st.st_mode & S_IFMT) == S_IFSOCK) { - patty_client_close(client, info.fd); + patty_client_close(client, info->fd); patty_client_destroy(client); } @@ -168,9 +178,10 @@ error_io: patty_kiss_tnc_destroy(raw); error_kiss_tnc_new: +error_kiss_config: error_client_setsockopt: error_client_socket: - if ((st.st_mode & S_IFMT) == S_IFSOCK) patty_client_close(client, info.fd); + if ((st.st_mode & S_IFMT) == S_IFSOCK) patty_client_close(client, info->fd); error_client_new: if ((st.st_mode & S_IFMT) == S_IFSOCK) patty_client_destroy(client); diff --git a/bin/if.c b/bin/if.c new file mode 100644 index 0000000..7f35657 --- /dev/null +++ b/bin/if.c @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include + +#include + +enum mode { + MODE_NONE, + MODE_IFNAME, + MODE_IFOPTS, + MODE_IFADDR, + MODE_KISS, + MODE_BAUD, + MODE_FLOW +}; + +static int eprintf(patty_bin_if_data *data, const char *format, ...) { + int ret; + va_list args; + + va_start(args, format); + + ret = vsnprintf(data->err, sizeof(data->err)-1, format, args); + + va_end(args); + + return ret; +} + +int patty_bin_if_config(patty_bin_if_data *data, int argc, char **argv) { + enum mode mode = MODE_NONE; + patty_kiss_tnc_info *info = &data->info; + + int i; + + for (i=0; iname = argv[i]; + + mode = MODE_IFOPTS; + + break; + + case MODE_IFOPTS: + if (strcmp(argv[i], "ax25") == 0) { + mode = MODE_IFADDR; + } else if (strcmp(argv[i], "kiss") == 0) { + mode = MODE_KISS; + } else if (strcmp(argv[i], "baud") == 0) { + mode = MODE_BAUD; + } else if (strcmp(argv[i], "flow") == 0) { + mode = MODE_FLOW; + } else { + eprintf(data, "Invalid parameter '%s'", argv[i]); + + goto error_invalid; + } + + break; + + case MODE_IFADDR: + if (patty_ax25_pton(argv[i], &data->addr) < 0) { + eprintf(data, "Invalid AX.25 address '%s': %s", + argv[i], strerror(errno)); + + goto error_invalid; + } + + mode = MODE_IFOPTS; + + break; + + case MODE_KISS: + data->type = PATTY_AX25_IF_KISS_TNC; + info->flags |= PATTY_KISS_TNC_DEVICE; + info->device = argv[i]; + + mode = MODE_IFOPTS; + + break; + + case MODE_BAUD: + if (!(argv[i][0] >= '0' && argv[i][0] <= '9')) { + eprintf(data, "Invalid baud rate '%s'", argv[i]); + + goto error_invalid; + } + + info->flags |= PATTY_KISS_TNC_BAUD; + info->baud = atoi(argv[i]); + + mode = MODE_IFOPTS; + + break; + + case MODE_FLOW: + if (strcmp(argv[i], "crtscts") == 0) { + info->flags |= PATTY_KISS_TNC_FLOW; + info->flow = PATTY_KISS_TNC_FLOW_CRTSCTS; + } else if (strcmp(argv[i], "xonxoff") == 0) { + info->flags |= PATTY_KISS_TNC_FLOW; + info->flow = PATTY_KISS_TNC_FLOW_XONXOFF; + } else { + eprintf(data, "Invalid flow control '%s'", argv[i]); + + goto error_invalid; + } + + mode = MODE_IFOPTS; + + break; + } + } + + return 0; + +error_invalid: + return -1; +} diff --git a/bin/kiss.c b/bin/kiss.c new file mode 100644 index 0000000..eb23a84 --- /dev/null +++ b/bin/kiss.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#include + +int patty_bin_kiss_config(patty_bin_kiss_data *data, int argc, char **argv) { + int i; + + patty_kiss_tnc_info *info = &data->info; + + info->flags |= PATTY_KISS_TNC_DEVICE; + info->device = argv[0]; + + for (i=1; iflags |= PATTY_KISS_TNC_FLOW; + info->flow = PATTY_KISS_TNC_FLOW_CRTSCTS; + } else if (strcmp(argv[i], "xonxoff") == 0) { + info->flags |= PATTY_KISS_TNC_FLOW; + info->flow = PATTY_KISS_TNC_FLOW_XONXOFF; + } else if (argv[i][0] >= '0' && argv[i][0] <= '9') { + int baud = atoi(argv[i]); + + info->flags |= PATTY_KISS_TNC_BAUD; + info->baud = baud; + } else { + snprintf(data->err, sizeof(data->err)-1, + "Invalid KISS TNC device parameter '%s'", argv[i]); + + goto error_invalid_device_setting; + } + } + + return 0; + +error_invalid_device_setting: + return -1; +} diff --git a/bin/pattyd.c b/bin/pattyd.c index ea6b647..fdeae3d 100644 --- a/bin/pattyd.c +++ b/bin/pattyd.c @@ -12,6 +12,9 @@ #include #include +#include +#include + #define DEFAULT_CONFIG_FILE "/etc/patty/pattyd.conf" #define DEFAULT_IFNAME "kiss0" @@ -32,19 +35,25 @@ static int usage(int argc, char **argv, const char *message, ...) { return EX_USAGE; } -static int handle_sock(patty_daemon *daemon, +struct context { + char *config_file; + patty_daemon *daemon; +}; + +static int handle_sock(struct context *ctx, int lineno, int argc, char **argv) { if (argc != 2) { - fprintf(stderr, "Invalid arguments for 'sock' on line %d\n", lineno); + fprintf(stderr, "%s: line %d: Invalid arguments for 'sock'\n", + ctx->config_file, lineno); goto error_invalid_args; } - if (patty_daemon_set_sock_path(daemon, argv[1]) < 0) { - fprintf(stderr, "Line %d: unable to set socket path to %s: %s", - lineno, argv[1], strerror(errno)); + if (patty_daemon_set_sock_path(ctx->daemon, argv[1]) < 0) { + fprintf(stderr, "%s: line %d: Unable to set socket path to %s: %s\n", + ctx->config_file, lineno, argv[1], strerror(errno)); goto error_set_sock_path; } @@ -56,19 +65,20 @@ error_invalid_args: return -1; } -static int handle_pid(patty_daemon *daemon, +static int handle_pid(struct context *ctx, int lineno, int argc, char **argv) { if (argc != 2) { - fprintf(stderr, "Invalid arguments for 'sock' on line %d\n", lineno); + fprintf(stderr, "%s: line %d: Invalid arguments for 'sock'\n", + ctx->config_file, lineno); goto error_invalid_args; } - if (patty_daemon_set_pidfile(daemon, argv[1]) < 0) { - fprintf(stderr, "Line %d: Unable to set pidfile to %s: %s", - lineno, argv[1], strerror(errno)); + if (patty_daemon_set_pidfile(ctx->daemon, argv[1]) < 0) { + fprintf(stderr, "%s: line %d: Unable to set pidfile to %s: %s\n", + ctx->config_file, lineno, argv[1], strerror(errno)); goto error_set_pidfile; } @@ -81,161 +91,57 @@ error_invalid_args: } struct if_context { - patty_daemon *daemon; - patty_ax25_addr addr; - patty_kiss_tnc_info info; + char *config_file; + enum patty_ax25_if_type type; + patty_ax25_addr addr; + patty_kiss_tnc_info info; }; -static int handle_if_ax25(struct if_context *ctx, - int lineno, - char *opt, - char *value) { - if (patty_ax25_pton(value, &ctx->addr) < 0) { - fprintf(stderr, "Line %d: Invalid interface address '%s'\n", - lineno, value); - - goto error_pton; - } - - return 0; - -error_pton: - return -1; -} - -static int handle_if_kiss(struct if_context *ctx, - int lineno, - char *opt, - char *value) { - ctx->info.flags |= PATTY_KISS_TNC_DEVICE; - ctx->info.device = value; - - return 0; -} - -static int handle_if_baud(struct if_context *ctx, - int lineno, - char *opt, - char *value) { - ctx->info.flags |= PATTY_KISS_TNC_BAUD; - ctx->info.baud = atoi(value); - - return 0; -} - -static int handle_if_flow(struct if_context *ctx, - int lineno, - char *opt, - char *value) { - if (strcmp(value, "xonxoff") == 0) { - ctx->info.flow = PATTY_KISS_TNC_FLOW_XONXOFF; - } else if (strcmp(value, "crtscts") == 0) { - ctx->info.flow = PATTY_KISS_TNC_FLOW_CRTSCTS; - } else { - fprintf(stderr, "Line %d: Invalid flow control '%s'\n", - lineno, value); - - goto error_invalid_flow; - } - - ctx->info.flags |= PATTY_KISS_TNC_FLOW; - - return 0; - -error_invalid_flow: - return -1; -} - -struct if_opt_handler { - char *name; - int (*func)(struct if_context *, int, char *, char *); -}; - -static struct if_opt_handler if_opt_handlers[] = { - { "ax25", handle_if_ax25 }, - { "kiss", handle_if_kiss }, - { "baud", handle_if_baud }, - { "flow", handle_if_flow }, - { NULL, NULL } -}; - -static int handle_if_opt(struct if_context *ctx, - int lineno, - char *opt, - char *value) { - int i; - - for (i=0; if_opt_handlers[i].name; i++) { - if (strcmp(opt, if_opt_handlers[i].name) == 0) { - return if_opt_handlers[i].func(ctx, lineno, opt, value); - } - } - - fprintf(stderr, "Line %d: Invalid interface option '%s'\n", - lineno, opt); - - return -1; -} - -static int handle_if(patty_daemon *daemon, +static int handle_if(struct context *ctx, int lineno, int argc, char **argv) { - char *name; - struct if_context ctx; + patty_bin_if_data data; patty_ax25_if *iface; - int i; + memset(&data, '\0', sizeof(data)); if (argc < 2) { - fprintf(stderr, "Line %d: No interface name provided\n", lineno); + fprintf(stderr, "%s: line %d: No interface name provided\n", + ctx->config_file, lineno); - goto error_no_ifname; + goto error_invalid; + } else if (argc < 3) { + fprintf(stderr, "%s: line %d: No interface options provided\n", + ctx->config_file, lineno); + + goto error_invalid; } - if (argc < 3) { - fprintf(stderr, "Line %d: No interface options provided\n", lineno); + if (patty_bin_if_config(&data, argc, argv) < 0) { + fprintf(stderr, "%s: line %d: %s\n", + ctx->config_file, lineno, data.err); - goto error_no_options; - } - - if (argc % 2 != 0) { - fprintf(stderr, "Line %d: Invalid number of values provided\n", lineno); - - goto error_invalid_values; - } - - memset(&ctx, '\0', sizeof(ctx)); - ctx.daemon = daemon; - - name = argv[1]; - - for (i=2; itnc); char *pty; if (isatty(fd) && (pty = ptsname(fd)) != NULL) { - printf("if %s pty %s\n", name, pty); + printf("if %s pty %s\n", data.name, pty); } } - if (patty_daemon_if_add(daemon, iface) < 0) { - fprintf(stderr, "Line %d: Unable to create interface %s: %s\n", - lineno, name, strerror(errno)); + if (patty_daemon_if_add(ctx->daemon, iface) < 0) { + fprintf(stderr, "%s: line %d: Unable to create interface %s: %s\n", + ctx->config_file, lineno, data.name, strerror(errno)); goto error_daemon_if_add; } @@ -246,58 +152,56 @@ error_daemon_if_add: patty_ax25_if_destroy(iface); error_if_new: -error_handle_if_opt: -error_invalid_values: -error_no_options: -error_no_ifname: +error_invalid: return -1; } -static int handle_route(patty_daemon *daemon, +static int handle_route(struct context *ctx, int lineno, int argc, char **argv) { if (argc < 2) { - fprintf(stderr, "Line %d: Invalid route declaration\n", lineno); + fprintf(stderr, "%s: line %d: Invalid route declaration\n", + ctx->config_file, lineno); goto error_invalid_route; } if (strcmp(argv[1], "default") == 0) { if (argc != 4 || strcmp(argv[2], "if") != 0) { - fprintf(stderr, "Line %d: Invalid default route declaration\n", - lineno); + fprintf(stderr, "%s: line %d: Invalid default route declaration\n", + ctx->config_file, lineno); goto error_invalid_route; } - if (patty_daemon_route_add_default(daemon, argv[3]) < 0) { - fprintf(stderr, "Line %d: Unable to add default route for interface %s: %s\n", - lineno, argv[3], strerror(errno)); + if (patty_daemon_route_add_default(ctx->daemon, argv[3]) < 0) { + fprintf(stderr, "%s: line %d: Unable to add default route for interface %s: %s", + ctx->config_file, lineno, argv[3], strerror(errno)); goto error_daemon_route_add; } } else if (strcmp(argv[1], "station") == 0) { if (argc < 7 || strcmp(argv[3], "if") != 0 || strcmp(argv[5], "path") != 0) { - fprintf(stderr, "Line %d: Invalid station route declaration\n", - lineno); + fprintf(stderr, "%s: line %d: Invalid station route declaration\n", + ctx->config_file, lineno); goto error_invalid_route; } - if (patty_daemon_route_add(daemon, + if (patty_daemon_route_add(ctx->daemon, argv[4], argv[2], (const char **)&argv[6], argc - 6) < 0) { - fprintf(stderr, "Line %d: Unable to add route for interface %s: %s\n", - lineno, argv[4], strerror(errno)); + fprintf(stderr, "%s: line %d: Unable to add route for interface %s: %s\n", + ctx->config_file, lineno, argv[4], strerror(errno)); goto error_daemon_route_add; } } else { - fprintf(stderr, "Line %d: Invalid route type '%s'\n", - lineno, argv[1]); + fprintf(stderr, "%s: line %d: Invalid route type '%s'", + ctx->config_file, lineno, argv[1]); goto error_invalid_route; } @@ -311,7 +215,7 @@ error_invalid_route: struct config_handler { const char *name; - int (*func)(patty_daemon *, int, int, char **); + int (*func)(struct context *, int, int, char **); }; struct config_handler handlers[] = { @@ -324,8 +228,8 @@ struct config_handler handlers[] = { static int handle_config_line(patty_conf_file *file, patty_list *line, - void *ctx) { - patty_daemon *daemon = ctx; + void *c) { + struct context *ctx = c; patty_list_item *item = line->first; int argc = (int)line->length, @@ -359,13 +263,14 @@ static int handle_config_line(patty_conf_file *file, for (i=0; handlers[i].name; i++) { if (strcmp(argv[0], handlers[i].name) == 0) { - ret = handlers[i].func(daemon, lineno, argc, argv); + ret = handlers[i].func(ctx, lineno, argc, argv); goto done; } } - fprintf(stderr, "Unknown configuration value '%s'\n", argv[0]); + fprintf(stderr, "%s: line %d: Unknown configuration value '%s'", + ctx->config_file, lineno, argv[0]); done: free(argv); @@ -376,39 +281,16 @@ error_malloc_argv: return -1; } -static int handle_simple_config(patty_daemon *daemon, - int argc, - char *argv0, - char **argv) { +static int handle_standalone(patty_daemon *daemon, + int argc, + char *argv0, + char **argv) { patty_ax25_if *iface; patty_ax25_addr addr; - patty_kiss_tnc_info info = { - .flags = PATTY_KISS_TNC_DEVICE, - .device = argv[2] - }; + patty_bin_kiss_data data; - int i; - - for (i=3; i= '0' && argv[i][0] <= '9') { - int baud = atoi(argv[i]); - - info.flags |= PATTY_KISS_TNC_BAUD; - info.baud = baud; - } else { - fprintf(stderr, "%s: Invalid device setting '%s'\n", - argv0, argv[i]); - - goto error_invalid_device_setting; - } - } + memset(&data, '\0', sizeof(data)); if (patty_daemon_set_sock_path(daemon, argv[0]) < 0) { fprintf(stderr, "%s: Unable to set socket path to %s: %s\n", @@ -424,9 +306,16 @@ static int handle_simple_config(patty_daemon *daemon, goto error_invalid_callsign; } + if (patty_bin_kiss_config(&data, argc - 2, argv + 2) < 0) { + fprintf(stderr, "%s: %s: %s\n", + argv0, argv[2], data.err); + + goto error_kiss_config; + } + if ((iface = patty_ax25_if_new(PATTY_AX25_IF_KISS_TNC, DEFAULT_IFNAME, - &info, + &data.info, &addr)) == NULL) { fprintf(stderr, "%s: Unable to create network interface %s: %s\n", argv0, DEFAULT_IFNAME, strerror(errno)); @@ -460,8 +349,8 @@ static int handle_simple_config(patty_daemon *daemon, error_daemon_route_add_default: error_daemon_if_add: error_if_new: +error_kiss_config: error_invalid_callsign: -error_invalid_device_setting: error_set_sock_path: return -1; } @@ -485,13 +374,13 @@ int main(int argc, char **argv) { { NULL, no_argument, NULL, 0 } }; - char *config_file = DEFAULT_CONFIG_FILE; - - patty_daemon *daemon; + struct context ctx = { + .config_file = DEFAULT_CONFIG_FILE + }; memset(flags, '\0', sizeof(flags)); - if ((daemon = patty_daemon_new()) == NULL) { + if ((ctx.daemon = patty_daemon_new()) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], "patty_daemon_new()", strerror(errno)); @@ -505,7 +394,7 @@ int main(int argc, char **argv) { goto error_invalid_args; case 'c': - config_file = optarg; + ctx.config_file = optarg; break; case 's': @@ -523,45 +412,45 @@ int main(int argc, char **argv) { goto error_config; } else if (argc - optind < 2) { - ret = usage(argc, argv, "No device path provided"); - - goto error_config; - } else if (argc - optind < 3) { ret = usage(argc, argv, "No callsign provided"); goto error_config; - } + } else if (argc - optind < 3) { + ret = usage(argc, argv, "No device path provided"); - if (handle_simple_config(daemon, - argc - optind, - argv[0], - argv + optind) < 0) { goto error_config; } - } else if (patty_conf_read(config_file, handle_config_line, daemon) < 0) { + + if (handle_standalone(ctx.daemon, + argc - optind, + argv[0], + argv + optind) < 0) { + goto error_config; + } + } else if (patty_conf_read(ctx.config_file, handle_config_line, &ctx) < 0) { if (errno) { fprintf(stderr, "%s: %s: %s: %s\n", - argv[0], "patty_conf_read()", config_file, strerror(errno)); + argv[0], "patty_conf_read()", ctx.config_file, strerror(errno)); } goto error_config; } - if (patty_daemon_run(daemon) < 0) { + if (patty_daemon_run(ctx.daemon) < 0) { fprintf(stderr, "%s: %s: %s\n", argv[0], "patty_daemon_run()", strerror(errno)); goto error_daemon_run; } - patty_daemon_destroy(daemon); + patty_daemon_destroy(ctx.daemon); return 0; error_daemon_run: error_config: error_invalid_args: - patty_daemon_destroy(daemon); + patty_daemon_destroy(ctx.daemon); error_daemon_new: return ret; diff --git a/include/patty/ax25/if.h b/include/patty/ax25/if.h index cfbdfe9..14e1095 100644 --- a/include/patty/ax25/if.h +++ b/include/patty/ax25/if.h @@ -13,6 +13,7 @@ #define PATTY_AX25_IF_DEFAULT_MRU 4096 enum patty_ax25_if_type { + PATTY_AX25_IF_UNKNOWN, PATTY_AX25_IF_KISS_TNC, PATTY_AX25_IF_HDLC }; diff --git a/include/patty/bin/if.h b/include/patty/bin/if.h new file mode 100644 index 0000000..6a145bb --- /dev/null +++ b/include/patty/bin/if.h @@ -0,0 +1,17 @@ +#ifndef _PATTY_BIN_IF_H +#define _PATTY_BIN_IF_H + +#include + +typedef struct _patty_bin_if_data { + char *name; + char err[256]; + + enum patty_ax25_if_type type; + patty_ax25_addr addr; + patty_kiss_tnc_info info; +} patty_bin_if_data; + +int patty_bin_if_config(patty_bin_if_data *data, int argc, char **argv); + +#endif /* _PATTY_BIN_IF_H */ diff --git a/include/patty/bin/kiss.h b/include/patty/bin/kiss.h new file mode 100644 index 0000000..5502bd6 --- /dev/null +++ b/include/patty/bin/kiss.h @@ -0,0 +1,13 @@ +#ifndef _PATTY_BIN_KISS_H +#define _PATTY_BIN_KISS_H + +#include + +typedef struct _patty_bin_kiss_data { + char err[256]; + patty_kiss_tnc_info info; +} patty_bin_kiss_data; + +int patty_bin_kiss_config(patty_bin_kiss_data *data, int argc, char **argv); + +#endif /* _PATTY_BIN_KISS_H */ diff --git a/src/Makefile b/src/Makefile index b167923..1774b1d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ include ../mk/build.mk INCLUDE_PATH = ../include -HEADER_SUBDIR = patty +HEADERS_SUBDIR = patty CC = $(CROSS)cc CFLAGS = $(CGFLAGS) -fPIC -Wall -O2 -I$(INCLUDE_PATH) @@ -21,7 +21,7 @@ VERSION = $(VERSION_MAJOR).$(VERSION_MINOR) LIBNAME = patty -HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADER_SUBDIR)/, $(HEADERS)) +HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADERS_SUBDIR)/, $(HEADERS)) all: $(STATIC) $(SONAME_FULL) $(SONAME) $(SONAME_SHORT) @@ -46,8 +46,8 @@ install: $(SONAME_FULL) $(STATIC) $(INSTALL) -c -m 0755 $(SONAME_FULL) $(PREFIX)/lib $(LN) -s -f $(SONAME_FULL) $(PREFIX)/lib/$(SONAME) $(LN) -s -f $(SONAME_FULL) $(PREFIX)/lib/$(SONAME_SHORT) - $(INSTALL) -d -m 0755 $(PREFIX)/include/$(HEADER_SUBDIR) - $(INSTALL) -c -m 0644 $(HEADERS_BUILD) $(PREFIX)/include/$(HEADER_SUBDIR) + $(INSTALL) -d -m 0755 $(PREFIX)/include/$(HEADERS_SUBDIR) + $(INSTALL) -c -m 0644 $(HEADERS_BUILD) $(PREFIX)/include/$(HEADERS_SUBDIR) clean: $(RM) -f $(SONAME_SHORT) $(SONAME) $(SONAME_FULL) $(STATIC) $(OBJS)