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
This commit is contained in:
XANTRONIX Development 2020-09-10 01:44:10 -04:00 committed by XANTRONIX Industrial
parent 4c2f92af22
commit 188d43f98d
9 changed files with 340 additions and 232 deletions

View file

@ -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:

View file

@ -14,6 +14,8 @@
#include <patty/ax25.h>
#include <patty/print.h>
#include <patty/bin/kiss.h>
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);

134
bin/if.c Normal file
View file

@ -0,0 +1,134 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <patty/bin/if.h>
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; i<argc; i++) {
switch (mode) {
case MODE_NONE:
if (strcmp(argv[i], "if") != 0) {
eprintf(data, "Unexpected start of expression '%s'",
argv[i]);
goto error_invalid;
} else {
mode = MODE_IFNAME;
}
break;
case MODE_IFNAME:
data->name = 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;
}

39
bin/kiss.c Normal file
View file

@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <patty/bin/kiss.h>
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; i<argc; i++) {
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 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;
}

View file

@ -12,6 +12,9 @@
#include <patty/daemon.h>
#include <patty/conf.h>
#include <patty/bin/if.h>
#include <patty/bin/kiss.h>
#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; i<argc; i+=2) {
char *opt = argv[i],
*value = argv[i+1];
if (handle_if_opt(&ctx, lineno, opt, value) < 0) {
goto error_handle_if_opt;
}
goto error_invalid;
}
if ((iface = patty_ax25_if_new(PATTY_AX25_IF_KISS_TNC,
name,
&ctx.info,
&ctx.addr)) == NULL) {
data.name,
&data.info,
&data.addr)) == NULL) {
goto error_if_new;
} else {
int fd = patty_kiss_tnc_fd(iface->tnc);
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<argc; i++) {
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 if (argv[i][0] >= '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;

View file

@ -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
};

17
include/patty/bin/if.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef _PATTY_BIN_IF_H
#define _PATTY_BIN_IF_H
#include <patty/ax25.h>
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 */

13
include/patty/bin/kiss.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef _PATTY_BIN_KISS_H
#define _PATTY_BIN_KISS_H
#include <patty/kiss.h>
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 */

View file

@ -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)