From 22366f2d0cc6497affa458a40338d7c217f0f286 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 25 Jun 2020 23:36:13 -0400 Subject: [PATCH] Need some shit for managing routing tables --- include/patty/ax25.h | 2 +- include/patty/ax25/route.h | 3 +++ include/patty/ax25/server.h | 3 +++ src/route.c | 11 +++++++++++ src/server.c | 5 +++++ src/testserver.c | 11 +++++++++++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/patty/ax25.h b/include/patty/ax25.h index e7fcf41..25db698 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -28,11 +28,11 @@ typedef struct _patty_ax25_if patty_ax25_if; #include #include #include -#include #include #include #include #include +#include int patty_ax25_pton(const char *callsign, uint8_t ssid, diff --git a/include/patty/ax25/route.h b/include/patty/ax25/route.h index d8d28b6..ee21f19 100644 --- a/include/patty/ax25/route.h +++ b/include/patty/ax25/route.h @@ -32,4 +32,7 @@ patty_ax25_route *patty_ax25_route_table_find(patty_ax25_route_table *table, int patty_ax25_route_table_add(patty_ax25_route_table *table, patty_ax25_route *route); +int patty_ax25_route_table_delete(patty_ax25_route_table *route, + patty_ax25_addr *dest); + #endif /* _PATTY_AX25_ROUTE_H */ diff --git a/include/patty/ax25/server.h b/include/patty/ax25/server.h index 21137f6..3f98bdd 100644 --- a/include/patty/ax25/server.h +++ b/include/patty/ax25/server.h @@ -23,6 +23,9 @@ int patty_ax25_server_each_if(patty_ax25_server *server, int (*callback)(patty_ax25_if *, void *), void *ctx); +int patty_ax25_server_add_route(patty_ax25_server *server, + patty_ax25_route *route); + int patty_ax25_server_run(patty_ax25_server *server); #endif /* _PATTY_AX25_SERVER_H */ diff --git a/src/route.c b/src/route.c index 12f2157..dbbef74 100644 --- a/src/route.c +++ b/src/route.c @@ -101,3 +101,14 @@ error_dict_set_with_hash: error_exists: return -1; } + +int patty_ax25_route_table_delete(patty_ax25_route_table *route, + patty_ax25_addr *dest) { + uint32_t hash; + + patty_hash_init(&hash); + patty_ax25_addr_hash(&hash, dest); + patty_hash_end(&hash); + + return patty_dict_delete_with_hash(route, hash); +} diff --git a/src/server.c b/src/server.c index 87db24a..29f40c8 100644 --- a/src/server.c +++ b/src/server.c @@ -425,6 +425,11 @@ error_list_start: return -1; } +int patty_ax25_server_add_route(patty_ax25_server *server, + patty_ax25_route *route) { + return patty_ax25_route_table_add(server->routes, route); +} + static int server_socket(patty_ax25_server *server, int client) { patty_ax25_call_socket_request request; diff --git a/src/testserver.c b/src/testserver.c index abb3548..37bed1e 100644 --- a/src/testserver.c +++ b/src/testserver.c @@ -25,6 +25,7 @@ static void usage(int argc, char **argv, const char *message, ...) { int main(int argc, char **argv) { patty_ax25_server *server; patty_ax25_if *iface; + patty_ax25_route *route; if (argc != 2) { usage(argc, argv, "No TNC device or KISS dump file provided"); @@ -46,6 +47,14 @@ int main(int argc, char **argv) { goto error_server_add_if; } + if ((route = patty_ax25_route_new_default(iface)) == NULL) { + goto error_route_new_default; + } + + if (patty_ax25_server_add_route(server, route) < 0) { + goto error_server_add_route; + } + if (patty_ax25_server_run(server) < 0) { fprintf(stderr, "%s: %s: %s: %s\n", argv[0], argv[1], "patty_ax25_server_run()", strerror(errno)); @@ -58,6 +67,8 @@ int main(int argc, char **argv) { return 0; error_server_run: +error_server_add_route: +error_route_new_default: error_server_add_if: error_if_addr_add: error_if_new: