diff options
Diffstat (limited to 'ax25rtd')
-rw-r--r-- | ax25rtd/Makefile.am | 4 | ||||
-rw-r--r-- | ax25rtd/Makefile.in | 114 | ||||
-rw-r--r-- | ax25rtd/ax25rtctl.c | 400 | ||||
-rw-r--r-- | ax25rtd/ax25rtd.c | 96 | ||||
-rw-r--r-- | ax25rtd/ax25rtd.h | 2 | ||||
-rw-r--r-- | ax25rtd/cache_ctl.c | 184 | ||||
-rw-r--r-- | ax25rtd/cache_dump.c | 96 | ||||
-rw-r--r-- | ax25rtd/config.c | 491 | ||||
-rw-r--r-- | ax25rtd/listener.c | 332 |
9 files changed, 839 insertions, 880 deletions
diff --git a/ax25rtd/Makefile.am b/ax25rtd/Makefile.am index 6e87903..e9edc41 100644 --- a/ax25rtd/Makefile.am +++ b/ax25rtd/Makefile.am @@ -25,8 +25,8 @@ ax25rtd_SOURCES = \ config.c \ listener.c -AX25_SYSCONFDIR=$(sysconfdir)/ax25/ -AX25_LOCALSTATEDIR=$(localstatedir)/ax25/ +AX25_SYSCONFDIR=$(sysconfdir)/ax25 +AX25_LOCALSTATEDIR=$(localstatedir)/ax25 INCLUDES = -DAX25_SYSCONFDIR=\""$(AX25_SYSCONFDIR)"\" \ -DAX25_LOCALSTATEDIR=\""$(AX25_LOCALSTATEDIR)"\" diff --git a/ax25rtd/Makefile.in b/ax25rtd/Makefile.in index 7a5c71b..51ef919 100644 --- a/ax25rtd/Makefile.in +++ b/ax25rtd/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation @@ -64,15 +64,17 @@ AWK = @AWK@ AX25_LIB = @AX25_LIB@ CC = @CC@ DLLTOOL = @DLLTOOL@ -LD = @LD@ +ECHO = @ECHO@ +EXEEXT = @EXEEXT@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ NCURSES_LIB = @NCURSES_LIB@ -NM = @NM@ OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ +STRIP = @STRIP@ VERSION = @VERSION@ etcfiles = ax25rtd.conf @@ -89,14 +91,15 @@ doc_DATA = TODO.ax25rtd README.ax25rtd ax25rtd_SOURCES = ax25rtd.c ax25rtd.h cache_ctl.c cache_dump.c config.c listener.c -AX25_SYSCONFDIR = $(sysconfdir)/ax25/ -AX25_LOCALSTATEDIR = $(localstatedir)/ax25/ +AX25_SYSCONFDIR = $(sysconfdir)/ax25 +AX25_LOCALSTATEDIR = $(localstatedir)/ax25 INCLUDES = -DAX25_SYSCONFDIR=\""$(AX25_SYSCONFDIR)"\" -DAX25_LOCALSTATEDIR=\""$(AX25_LOCALSTATEDIR)"\" mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = +sbin_PROGRAMS = ax25rtd$(EXEEXT) ax25rtctl$(EXEEXT) PROGRAMS = $(sbin_PROGRAMS) @@ -104,13 +107,13 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I.. CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -ax25rtd_OBJECTS = ax25rtd.o cache_ctl.o cache_dump.o config.o \ -listener.o +ax25rtd_OBJECTS = ax25rtd.$(OBJEXT) cache_ctl.$(OBJEXT) \ +cache_dump.$(OBJEXT) config.$(OBJEXT) listener.$(OBJEXT) ax25rtd_LDADD = $(LDADD) ax25rtd_DEPENDENCIES = ax25rtd_LDFLAGS = ax25rtctl_SOURCES = ax25rtctl.c -ax25rtctl_OBJECTS = ax25rtctl.o +ax25rtctl_OBJECTS = ax25rtctl.$(OBJEXT) ax25rtctl_LDADD = $(LDADD) ax25rtctl_DEPENDENCIES = ax25rtctl_LDFLAGS = @@ -128,16 +131,18 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best +DEP_FILES = .deps/ax25rtctl.P .deps/ax25rtd.P .deps/cache_ctl.P \ +.deps/cache_dump.P .deps/config.P .deps/listener.P SOURCES = $(ax25rtd_SOURCES) ax25rtctl.c -OBJECTS = $(ax25rtd_OBJECTS) ax25rtctl.o +OBJECTS = $(ax25rtd_OBJECTS) ax25rtctl.$(OBJEXT) all: all-redirect .SUFFIXES: -.SUFFIXES: .S .c .lo .o .s +.SUFFIXES: .S .c .lo .o .obj .s $(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps ax25rtd/Makefile + cd $(top_srcdir) && $(AUTOMAKE) --gnu ax25rtd/Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) cd $(top_builddir) \ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status @@ -167,8 +172,10 @@ uninstall-sbinPROGRAMS: rm -f $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ done -.c.o: - $(COMPILE) -c $< +# FIXME: We should only use cygpath when building on Windows, +# and only if it is available. +.c.obj: + $(COMPILE) -c `cygpath -w $<` .s.o: $(COMPILE) -c $< @@ -178,6 +185,7 @@ uninstall-sbinPROGRAMS: mostlyclean-compile: -rm -f *.o core *.core + -rm -f *.$(OBJEXT) clean-compile: @@ -186,9 +194,6 @@ distclean-compile: maintainer-clean-compile: -.c.lo: - $(LIBTOOL) --mode=compile $(COMPILE) -c $< - .s.lo: $(LIBTOOL) --mode=compile $(COMPILE) -c $< @@ -205,12 +210,12 @@ distclean-libtool: maintainer-clean-libtool: -ax25rtd: $(ax25rtd_OBJECTS) $(ax25rtd_DEPENDENCIES) - @rm -f ax25rtd +ax25rtd$(EXEEXT): $(ax25rtd_OBJECTS) $(ax25rtd_DEPENDENCIES) + @rm -f ax25rtd$(EXEEXT) $(LINK) $(ax25rtd_LDFLAGS) $(ax25rtd_OBJECTS) $(ax25rtd_LDADD) $(LIBS) -ax25rtctl: $(ax25rtctl_OBJECTS) $(ax25rtctl_DEPENDENCIES) - @rm -f ax25rtctl +ax25rtctl$(EXEEXT): $(ax25rtctl_OBJECTS) $(ax25rtctl_DEPENDENCIES) + @rm -f ax25rtctl$(EXEEXT) $(LINK) $(ax25rtctl_LDFLAGS) $(ax25rtctl_OBJECTS) $(ax25rtctl_LDADD) $(LIBS) install-docDATA: $(doc_DATA) @@ -266,6 +271,11 @@ distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) subdir = ax25rtd distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu ax25rtd/Makefile @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ @@ -276,13 +286,38 @@ distdir: $(DISTFILES) || cp -p $$d/$$file $(distdir)/$$file || :; \ fi; \ done -ax25rtctl.o: ax25rtctl.c ../config.h ../pathnames.h -ax25rtd.o: ax25rtd.c ../config.h ../pathnames.h ax25rtd.h -cache_ctl.o: cache_ctl.c ../config.h ax25rtd.h -cache_dump.o: cache_dump.c ../config.h ax25rtd.h -config.o: config.c ../config.h ../pathnames.h ax25rtd.h -listener.o: listener.c ../config.h ../pathnames.h ax25rtd.h +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp info-am: info: info-am dvi-am: @@ -320,27 +355,27 @@ distclean-generic: maintainer-clean-generic: mostlyclean-am: mostlyclean-sbinPROGRAMS mostlyclean-compile \ - mostlyclean-libtool mostlyclean-tags \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ mostlyclean-generic mostlyclean: mostlyclean-am clean-am: clean-sbinPROGRAMS clean-compile clean-libtool clean-tags \ - clean-generic mostlyclean-am + clean-depend clean-generic mostlyclean-am clean: clean-am distclean-am: distclean-sbinPROGRAMS distclean-compile \ - distclean-libtool distclean-tags distclean-generic \ - clean-am + distclean-libtool distclean-tags distclean-depend \ + distclean-generic clean-am -rm -f libtool distclean: distclean-am maintainer-clean-am: maintainer-clean-sbinPROGRAMS \ maintainer-clean-compile maintainer-clean-libtool \ - maintainer-clean-tags maintainer-clean-generic \ - distclean-am + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean-am @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." @@ -352,12 +387,13 @@ install-sbinPROGRAMS mostlyclean-compile distclean-compile \ clean-compile maintainer-clean-compile mostlyclean-libtool \ distclean-libtool clean-libtool maintainer-clean-libtool \ uninstall-docDATA install-docDATA tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ -check-am installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean +clean-tags maintainer-clean-tags distdir mostlyclean-depend \ +distclean-depend clean-depend maintainer-clean-depend info-am info \ +dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ +install-exec install-data-am install-data install-am install \ +uninstall-am uninstall all-redirect all-am all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean installconf: diff --git a/ax25rtd/ax25rtctl.c b/ax25rtd/ax25rtctl.c index 48ac48f..222ee61 100644 --- a/ax25rtd/ax25rtctl.c +++ b/ax25rtd/ax25rtctl.c @@ -1,4 +1,4 @@ -/* $Id: ax25rtctl.c,v 1.1.1.1 2001/04/10 01:58:38 csmall Exp $ +/* $Id: ax25rtctl.c,v 1.2 2001/09/12 13:18:43 terry Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * @@ -17,7 +17,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ - + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -32,38 +32,40 @@ #include <config.h> #include "../pathnames.h" -static const struct option lopts[] = { - {"add", 1, 0, 'a'}, - {"del", 1, 0, 'd'}, - {"list", 1, 0, 'l'}, - {"expire", 1, 0, 'e'}, - {"save", 0, 0, 's'}, - {"reload", 0, 0, 'r'}, - {"shutdown", 0, 0, 'q'}, - {"Version", 0, 0, 'V'}, - {"help", 0, 0, 'h'}, - {"debug", 0, 0, 'x'}, - {"version", 0, 0, 'v'}, - {NULL, 0, 0, 0 } +static const struct option lopts[] = { + {"add", 1, 0, 'a'}, + {"del", 1, 0, 'd'}, + {"list", 1, 0, 'l'}, + {"expire", 1, 0, 'e'}, + {"save", 0, 0, 's'}, + {"reload", 0, 0, 'r'}, + {"shutdown", 0, 0, 'q'}, + {"Version", 0, 0, 'V'}, + {"help", 0, 0, 'h'}, + {"debug", 0, 0, 'x'}, + {"version", 0, 0, 'v'}, + {NULL, 0, 0, 0} }; - + static const char *sopts = "a:d:l:e:srqvVh"; static void usage(void) { - fprintf(stderr,"usage:\n"); - fprintf(stderr,"ax25rtctl -a|--add ax25 <callsign> <dev> <time> [digipeater]\n"); - fprintf(stderr," -a|--add ip <ip> <dev> <time> <call> <ipmode>\n"); - fprintf(stderr," -d|--del ax25 <callsign> <dev>\n"); - fprintf(stderr," -d|--del ip <ip>\n"); - fprintf(stderr," -l|--list ax25|ip\n"); - fprintf(stderr," -e|--expire <minutes>\n"); - fprintf(stderr," -s|--save\n"); - fprintf(stderr," -r|--reload\n"); - fprintf(stderr," -q|--shutdown\n"); - fprintf(stderr," -V|--Version\n"); - fprintf(stderr," -h|--help\n"); - fprintf(stderr," -v|--version\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, + "ax25rtctl -a|--add ax25 <callsign> <dev> <time> [digipeater]\n"); + fprintf(stderr, + " -a|--add ip <ip> <dev> <time> <call> <ipmode>\n"); + fprintf(stderr, " -d|--del ax25 <callsign> <dev>\n"); + fprintf(stderr, " -d|--del ip <ip>\n"); + fprintf(stderr, " -l|--list ax25|ip\n"); + fprintf(stderr, " -e|--expire <minutes>\n"); + fprintf(stderr, " -s|--save\n"); + fprintf(stderr, " -r|--reload\n"); + fprintf(stderr, " -q|--shutdown\n"); + fprintf(stderr, " -V|--Version\n"); + fprintf(stderr, " -h|--help\n"); + fprintf(stderr, " -v|--version\n"); exit(1); } @@ -71,24 +73,23 @@ static int open_socket(void) { int sock, addrlen; struct sockaddr_un addr; - + sock = socket(AF_UNIX, SOCK_STREAM, 0); - if (sock < 0) - { + if (sock < 0) { perror("ax25rtctl socket"); exit(1); } - + addr.sun_family = AF_UNIX; strcpy(addr.sun_path, DATA_AX25ROUTED_CTL_SOCK); - addrlen = strlen(DATA_AX25ROUTED_CTL_SOCK) + sizeof(addr.sun_family); + addrlen = + strlen(DATA_AX25ROUTED_CTL_SOCK) + sizeof(addr.sun_family); - if (connect(sock, (struct sockaddr *) &addr, addrlen) < 0) - { + if (connect(sock, (struct sockaddr *) &addr, addrlen) < 0) { perror("ax25rtctl connect"); exit(1); } - + return sock; } @@ -99,24 +100,23 @@ static int wsock(int sock, char *s) static char *get_next_arg(char **p) { - char *p2; + char *p2; - if (p == NULL || *p == NULL) - return NULL; + if (p == NULL || *p == NULL) + return NULL; - p2 = *p; - for (; *p2 && *p2 == ' '; p2++) ; - if (!*p2) - return NULL; + p2 = *p; + for (; *p2 && *p2 == ' '; p2++); + if (!*p2) + return NULL; - *p = strchr(p2, ' '); - if (*p != NULL) - { - **p = '\0'; - (*p)++; - } + *p = strchr(p2, ' '); + if (*p != NULL) { + **p = '\0'; + (*p)++; + } - return p2; + return p2; } static void list_ax25(void) @@ -124,72 +124,66 @@ static void list_ax25(void) int sock, len, offs; char buf[512], *b, *s, *digi, *call, *dev, *ct; time_t t; - + sock = open_socket(); - + wsock(sock, "list ax25\n"); - + offs = 0; - + printf("Callsign Port Last update Path\n"); /* DB0PRA-15 scc3 Tue Aug 6 16:35:38 1996 */ - while(1) - { - len = read(sock, buf+offs, sizeof(buf)-offs-1); - if (len <= 0) - { + while (1) { + len = read(sock, buf + offs, sizeof(buf) - offs - 1); + if (len <= 0) { close(sock); return; } - buf[len+offs] = '\0'; + buf[len + offs] = '\0'; s = buf; - for (s = buf; (b = strchr(s, '\n')) != NULL; s = b+1) - { + for (s = buf; (b = strchr(s, '\n')) != NULL; s = b + 1) { *b = '\0'; - if (s[0] == '.') - { + if (s[0] == '.') { close(sock); return; } - + call = get_next_arg(&s); - dev = get_next_arg(&s); - t = strtol(get_next_arg(&s), NULL, 16); + dev = get_next_arg(&s); + t = strtol(get_next_arg(&s), NULL, 16); - if (t == 0) - { + if (t == 0) { ct = "(permanent)"; ct = strdup(ct); } else { ct = strdup(ctime(&t)); - ct[strlen(ct)-6] = '\0'; + ct[strlen(ct) - 6] = '\0'; } - + printf("%-9s %-6s %s", call, dev, ct); free(ct); - while ( (digi = get_next_arg(&s)) != NULL) + while ((digi = get_next_arg(&s)) != NULL) printf(" %s", digi); printf("\n"); } - - if (b == NULL && s != NULL) - { + + if (b == NULL && s != NULL) { offs = strlen(s); if (offs) memcpy(buf, s, offs); } } - close(sock); + close(sock); } static void list_ip(void) @@ -197,64 +191,59 @@ static void list_ip(void) int sock, len, offs; char buf[512], *b, *s, *ip, *call, *dev, *ct, *mode; time_t t; - + sock = open_socket(); - + wsock(sock, "list ip\n"); - + offs = 0; printf("IP Address Port Callsign Mode Last update\n"); /* 255.255.255.255 scc3 DB0PRA-15 v Thu Jan 7 06:54:19 1971 */ - while(1) - { - len = read(sock, buf+offs, sizeof(buf)-offs-1); - if (len <= 0) - { + while (1) { + len = read(sock, buf + offs, sizeof(buf) - offs - 1); + if (len <= 0) { close(sock); return; } - buf[len+offs] = '\0'; + buf[len + offs] = '\0'; s = buf; - for (s = buf; (b = strchr(s, '\n')) != NULL; s = b+1) - { + for (s = buf; (b = strchr(s, '\n')) != NULL; s = b + 1) { *b = '\0'; - if (s[0] == '.') - { + if (s[0] == '.') { close(sock); return; } - - ip = get_next_arg(&s); - dev = get_next_arg(&s); - t = strtol(get_next_arg(&s), NULL, 16); + + ip = get_next_arg(&s); + dev = get_next_arg(&s); + t = strtol(get_next_arg(&s), NULL, 16); call = get_next_arg(&s); mode = get_next_arg(&s); - if (t == 0) - { + if (t == 0) { ct = "(permanent)"; } else { - ct = ctime(&t); - ct[strlen(ct)-6] = '\0'; + ct = ctime(&t); + ct[strlen(ct) - 6] = '\0'; } - - printf("%-15s %-6s %-9s %-4s %s\n", ip, dev, call, mode, ct); + + printf("%-15s %-6s %-9s %-4s %s\n", ip, dev, call, + mode, ct); } - - if (b == NULL && s != NULL) - { + + if (b == NULL && s != NULL) { offs = strlen(s); if (offs) memcpy(buf, s, offs); } } - close(sock); + close(sock); } static void Version(void) @@ -262,7 +251,7 @@ static void Version(void) int sock; char buf[256]; - printf("ax25rtctl $Revision: 1.1.1.1 $\n"); + printf("ax25rtctl $Revision: 1.2 $\n"); sock = open_socket(); wsock(sock, "version\n"); read(sock, buf, sizeof(buf)); @@ -280,39 +269,34 @@ static void debug(void) sock = open_socket(); - while (1) - { + while (1) { FD_ZERO(&fd_set); FD_SET(0, &fd_set); FD_SET(sock, &fd_set); - + FD_ZERO(&fd_set2); FD_SET(sock, &fd_set2); - + tv.tv_sec = 0; tv.tv_usec = 0; - if (select(sock+1, &fd_set, NULL, &fd_set2, &tv) < 0) - { + if (select(sock + 1, &fd_set, NULL, &fd_set2, &tv) < 0) { perror("socket gone"); exit(1); } - + if (FD_ISSET(sock, &fd_set2)) exit(0); - - if (FD_ISSET(0, &fd_set)) - { + + if (FD_ISSET(0, &fd_set)) { n = read(0, buf, sizeof(buf)); - if (n) - { + if (n) { k = write(sock, buf, n); if (k <= 0) exit(0); } } - - if (FD_ISSET(sock, &fd_set)) - { + + if (FD_ISSET(sock, &fd_set)) { n = read(sock, buf, sizeof(buf)); if (n) write(0, buf, n); @@ -326,111 +310,105 @@ int main(int argc, char **argv) unsigned char buf[256]; int opt_ind = 0; long when; - + cmd = getopt_long(argc, argv, sopts, lopts, &opt_ind); - switch (cmd) - { - case 'a': - if (!strcmp(optarg, "ax25")) - { - if (argc < optind+3) - usage(); - - len = sprintf(buf, "add ax25"); - for (k = optind; k < argc; k++) - len += sprintf(buf+len, " %s", argv[k]); - sprintf(buf+len, "\n"); - - sock = open_socket(); - wsock(sock, buf); - close(sock); - } else - if (!strcmp(optarg, "ip")) - { - if (argc < optind+5) - usage(); - - len = sprintf(buf, "add ip"); - for (k = optind; k < argc; k++) - len += sprintf(buf+len, " %s", argv[k]); - sprintf(buf+len, "\n"); - - sock = open_socket(); - wsock(sock, buf); - close(sock); - } else + switch (cmd) { + case 'a': + if (!strcmp(optarg, "ax25")) { + if (argc < optind + 3) usage(); - return 0; - case 'd': - if (!strcmp(optarg, "ax25")) - { - if (argc < optind+2) - usage(); - - sprintf(buf, "del ax25 %s %s\n", argv[optind], argv[optind+1]); - - sock = open_socket(); - wsock(sock, buf); - close(sock); - } else - if (!strcmp(optarg, "ip")) - { - if (argc < optind+1) - usage(); - sprintf(buf, "del ip %s\n", argv[optind]); + len = sprintf(buf, "add ax25"); + for (k = optind; k < argc; k++) + len += sprintf(buf + len, " %s", argv[k]); + sprintf(buf + len, "\n"); - sock = open_socket(); - wsock(sock, buf); - close(sock); - } else - usage(); - return 0; - case 'l': - if (!strcmp(optarg, "ax25")) - list_ax25(); - else if (!strcmp(optarg, "ip")) - list_ip(); - else - usage(); - return 0; - case 'e': - when = atoi(optarg); - if (when <= 0) - usage(); sock = open_socket(); - sprintf(buf, "expire %ld\n", when); wsock(sock, buf); close(sock); - return 0; - case 's': + } else if (!strcmp(optarg, "ip")) { + if (argc < optind + 5) + usage(); + + len = sprintf(buf, "add ip"); + for (k = optind; k < argc; k++) + len += sprintf(buf + len, " %s", argv[k]); + sprintf(buf + len, "\n"); + sock = open_socket(); - wsock(sock, "save\n"); + wsock(sock, buf); close(sock); - return 0; - case 'r': + } else + usage(); + return 0; + case 'd': + if (!strcmp(optarg, "ax25")) { + if (argc < optind + 2) + usage(); + + sprintf(buf, "del ax25 %s %s\n", argv[optind], + argv[optind + 1]); + sock = open_socket(); - wsock(sock, "reload\n"); + wsock(sock, buf); close(sock); - return 0; - case 'q': + } else if (!strcmp(optarg, "ip")) { + if (argc < optind + 1) + usage(); + + sprintf(buf, "del ip %s\n", argv[optind]); + sock = open_socket(); - wsock(sock, "shutdown\n"); + wsock(sock, buf); close(sock); - return 0; - case 'V': - Version(); - return 0; - case 'v': - printf("ax25rtctl: %s\n", VERSION); - return 0; - case 'x': - debug(); - case ':': - case 'h': - case '?': - default: + } else + usage(); + return 0; + case 'l': + if (!strcmp(optarg, "ax25")) + list_ax25(); + else if (!strcmp(optarg, "ip")) + list_ip(); + else + usage(); + return 0; + case 'e': + when = atoi(optarg); + if (when <= 0) usage(); + sock = open_socket(); + sprintf(buf, "expire %ld\n", when); + wsock(sock, buf); + close(sock); + return 0; + case 's': + sock = open_socket(); + wsock(sock, "save\n"); + close(sock); + return 0; + case 'r': + sock = open_socket(); + wsock(sock, "reload\n"); + close(sock); + return 0; + case 'q': + sock = open_socket(); + wsock(sock, "shutdown\n"); + close(sock); + return 0; + case 'V': + Version(); + return 0; + case 'v': + printf("ax25rtctl: %s\n", VERSION); + return 0; + case 'x': + debug(); + case ':': + case 'h': + case '?': + default: + usage(); } usage(); return 1; diff --git a/ax25rtd/ax25rtd.c b/ax25rtd/ax25rtd.c index 651d380..7aaa17f 100644 --- a/ax25rtd/ax25rtd.c +++ b/ax25rtd/ax25rtd.c @@ -1,4 +1,4 @@ -/* $Id: ax25rtd.c,v 1.1.1.1 2001/04/10 01:58:38 csmall Exp $ +/* $Id: ax25rtd.c,v 1.2 2001/09/12 13:18:43 terry Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * @@ -17,7 +17,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ - + /* * This daemon tries to learn AX.25, ARP, IP route entries by listening * to the AX.25 traffic. It caches up to 256 entries (in "FIFO" mode) @@ -63,36 +63,36 @@ #include "../pathnames.h" #include "ax25rtd.h" -const char *Version = "ax25rtd $Revision: 1.1.1.1 $"; +const char *Version = "ax25rtd $Revision: 1.2 $"; config *Config = NULL; int reload = 0; -ip_rt_entry * ip_routes = NULL; -int ip_routes_cnt = 0; -int ip_maxroutes = IP_MAXROUTES; +ip_rt_entry *ip_routes = NULL; +int ip_routes_cnt = 0; +int ip_maxroutes = IP_MAXROUTES; -ax25_rt_entry * ax25_routes = NULL; -int ax25_routes_cnt = 0; -int ax25_maxroutes = AX25_MAXROUTES; +ax25_rt_entry *ax25_routes = NULL; +int ax25_routes_cnt = 0; +int ax25_maxroutes = AX25_MAXROUTES; -char ip_encaps_dev[32] = ""; +char ip_encaps_dev[32] = ""; config *dev_get_config(char *dev) { config *config; - + for (config = Config; config; config = config->next) if (!strcmp(config->dev, dev)) return config; - + return port_get_config(dev); } config *port_get_config(char *port) { config *config; - + for (config = Config; config; config = config->next) if (!strcmp(config->port, port)) return config; @@ -102,7 +102,7 @@ config *port_get_config(char *port) void sig_reload(int d) { reload = 1; - signal(SIGHUP, sig_reload); + signal(SIGHUP, sig_reload); } void sig_debug(int d) @@ -113,7 +113,7 @@ void sig_debug(int d) dump_ip_routes(2, 0); fprintf(stderr, "ax25-routes:\n"); dump_ax25_routes(2, 0); - signal(SIGUSR1, sig_debug); + signal(SIGUSR1, sig_debug); } void sig_term(int d) @@ -146,64 +146,59 @@ int main(int argc, char **argv) load_config(); load_cache(); - + if (fork()) return 0; - if ((s = socket(AF_INET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) - { + if ((s = socket(AF_INET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) { perror("AX.25 socket"); return 1; } - - if ((cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { + + if ((cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { perror("Control socket"); return 1; } - + unlink(DATA_AX25ROUTED_CTL_SOCK); cntrl_addr.sun_family = AF_UNIX; strcpy(cntrl_addr.sun_path, DATA_AX25ROUTED_CTL_SOCK); - cntrl_len = sizeof(cntrl_addr.sun_family) + strlen(DATA_AX25ROUTED_CTL_SOCK); + cntrl_len = + sizeof(cntrl_addr.sun_family) + + strlen(DATA_AX25ROUTED_CTL_SOCK); - if (bind(cntrl_s, (struct sockaddr *)&cntrl_addr, cntrl_len) < 0) - { + if (bind(cntrl_s, (struct sockaddr *) &cntrl_addr, cntrl_len) < 0) { perror("bind Control socket"); daemon_shutdown(1); } chmod(DATA_AX25ROUTED_CTL_SOCK, 0600); listen(cntrl_s, 1); - + signal(SIGUSR1, sig_debug); - signal(SIGHUP, sig_reload); + signal(SIGHUP, sig_reload); signal(SIGTERM, sig_term); - + cntrl_fd = -1; - - for (;;) - { + + for (;;) { fd_max = 0; FD_ZERO(&fd_set); FD_ZERO(&fd_set2); FD_MAX(s); - if (cntrl_fd > 0) - { + if (cntrl_fd > 0) { FD_MAX(cntrl_fd); FD_SET(cntrl_fd, &fd_set2); } else { FD_MAX(cntrl_s); } - if (select(fd_max+1, &fd_set, NULL, &fd_set2, NULL) < 0) - { + if (select(fd_max + 1, &fd_set, NULL, &fd_set2, NULL) < 0) { if (errno == EINTR) /* woops! */ continue; - if (!FD_ISSET(cntrl_fd, &fd_set2)) - { + if (!FD_ISSET(cntrl_fd, &fd_set2)) { perror("select"); save_cache(); daemon_shutdown(1); @@ -213,14 +208,11 @@ int main(int argc, char **argv) continue; } } - - if (cntrl_fd > 0) - { - if (FD_ISSET(cntrl_fd, &fd_set)) - { + + if (cntrl_fd > 0) { + if (FD_ISSET(cntrl_fd, &fd_set)) { size = read(cntrl_fd, buf, sizeof(buf)); - if (size > 0) - { + if (size > 0) { buf[size] = '\0'; interpret_command(cntrl_fd, buf); } else { @@ -228,11 +220,11 @@ int main(int argc, char **argv) cntrl_fd = -1; } } - } else - if (FD_ISSET(cntrl_s, &fd_set)) - { - if ((cntrl_fd=accept(cntrl_s, (struct sockaddr *) &cntrl_addr, &cntrl_len)) < 0) - { + } else if (FD_ISSET(cntrl_s, &fd_set)) { + if ((cntrl_fd = + accept(cntrl_s, + (struct sockaddr *) &cntrl_addr, + &cntrl_len)) < 0) { perror("accept Control"); save_cache(); daemon_shutdown(1); @@ -241,10 +233,10 @@ int main(int argc, char **argv) if (reload) reload_config(); - + if (FD_ISSET(s, &fd_set)) ax25_receive(s); } - - return 0; /* what ?! */ + + return 0; /* what ?! */ } diff --git a/ax25rtd/ax25rtd.h b/ax25rtd/ax25rtd.h index 1dc96ee..afebc71 100644 --- a/ax25rtd/ax25rtd.h +++ b/ax25rtd/ax25rtd.h @@ -1,4 +1,4 @@ -/* $Id: ax25rtd.h,v 1.1.1.1 2001/04/10 01:58:39 csmall Exp $ +/* $Id: ax25rtd.h,v 1.1 2001/04/10 01:58:39 csmall Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * diff --git a/ax25rtd/cache_ctl.c b/ax25rtd/cache_ctl.c index decce70..1f435b5 100644 --- a/ax25rtd/cache_ctl.c +++ b/ax25rtd/cache_ctl.c @@ -1,4 +1,4 @@ -/* $Id: cache_ctl.c,v 1.1.1.1 2001/04/10 01:58:39 csmall Exp $ +/* $Id: cache_ctl.c,v 1.2 2001/09/12 13:18:43 terry Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * @@ -18,7 +18,7 @@ * */ -#include <stdlib.h> +#include <stdlib.h> #include <string.h> #include <time.h> #include <sys/socket.h> @@ -37,75 +37,69 @@ /* (later: haven't I seen this statement elsewere? hmm...) */ -int update_ip_route(config *config, unsigned long ip, int ipmode, ax25_address *call, time_t timestamp) +int update_ip_route(config * config, unsigned long ip, int ipmode, + ax25_address * call, time_t timestamp) { ip_rt_entry *bp = ip_routes; ip_rt_entry *bp_prev = ip_routes; char *iface; int action = 0; - + if (((ip ^ config->ip) & config->netmask) != 0) return 0; - + iface = config->dev; - - while (bp) - { - if (bp->ip == ip) - { + + while (bp) { + if (bp->ip == ip) { if (bp->timestamp == 0 && timestamp != 0) return 0; - if (strcmp(bp->iface, iface)) - { + if (strcmp(bp->iface, iface)) { action |= NEW_ROUTE; strcpy(bp->iface, iface); } - - if (memcmp(&bp->call, call, AXLEN)) - { + + if (memcmp(&bp->call, call, AXLEN)) { action |= NEW_ARP; memcpy(&bp->call, call, AXLEN); - } + } - if (ipmode != bp->ipmode) - { + if (ipmode != bp->ipmode) { action |= NEW_IPMODE; bp->ipmode = ipmode; } - + bp->timestamp = timestamp; - if (bp != ip_routes) - { + if (bp != ip_routes) { if (bp->next) bp->next->prev = bp->prev; if (bp->prev) bp->prev->next = bp->next; - bp->next = ip_routes; - bp->prev = NULL; + bp->next = ip_routes; + bp->prev = NULL; ip_routes->prev = bp; - ip_routes = bp; + ip_routes = bp; } - + return action; } bp_prev = bp; bp = bp->next; } - - if (ip_routes_cnt >= ip_maxroutes) - { + + if (ip_routes_cnt >= ip_maxroutes) { if (bp_prev == NULL) /* error */ return 0; - + bp_prev->prev->next = NULL; free(bp_prev); ip_routes_cnt--; } - + bp = (ip_rt_entry *) malloc(sizeof(ip_rt_entry)); if (bp == NULL) return 0; @@ -118,67 +112,67 @@ int update_ip_route(config *config, unsigned long ip, int ipmode, ax25_address * bp->timestamp = timestamp; strcpy(bp->iface, iface); - memcpy(&bp->call, call, AXLEN); + memcpy(&bp->call, call, AXLEN); - if (ip_routes == NULL) - { + if (ip_routes == NULL) { ip_routes = bp; bp->next = bp->prev = NULL; return action; } - - bp->next = ip_routes; - bp->prev = NULL; + + bp->next = ip_routes; + bp->prev = NULL; ip_routes->prev = bp; - ip_routes = bp; + ip_routes = bp; return action; } -ax25_rt_entry *update_ax25_route(config *config, ax25_address *call, int ndigi, ax25_address *digi, time_t timestamp) +ax25_rt_entry *update_ax25_route(config * config, ax25_address * call, + int ndigi, ax25_address * digi, + time_t timestamp) { ax25_rt_entry *bp = ax25_routes; ax25_rt_entry *bp_prev = ax25_routes; unsigned char *iface = config->dev; int action = 0; - - while (bp) - { - if (!memcmp(call, &bp->call, AXLEN) ) - { + + while (bp) { + if (!memcmp(call, &bp->call, AXLEN)) { if (bp->timestamp == 0 && timestamp != 0) return NULL; - if (strcmp(bp->iface, iface)) - { - del_kernel_ax25_route(bp->iface, &bp->call); - action |= NEW_ROUTE; - strcpy(bp->iface, iface); - } - - if (ndigi != bp->ndigi || memcmp(bp->digipeater, digi, bp->ndigi*AXLEN)) - { + if (strcmp(bp->iface, iface)) { + del_kernel_ax25_route(bp->iface, + &bp->call); + action |= NEW_ROUTE; + strcpy(bp->iface, iface); + } + + if (ndigi != bp->ndigi + || memcmp(bp->digipeater, digi, + bp->ndigi * AXLEN)) { action |= NEW_ROUTE; - memcpy(bp->digipeater, digi, ndigi*AXLEN); + memcpy(bp->digipeater, digi, + ndigi * AXLEN); bp->ndigi = ndigi; } - + bp->timestamp = timestamp; - if (bp != ax25_routes) - { + if (bp != ax25_routes) { if (bp->next) bp->next->prev = bp->prev; if (bp->prev) bp->prev->next = bp->next; - - bp->next = ax25_routes; - bp->prev = NULL; + + bp->next = ax25_routes; + bp->prev = NULL; ax25_routes->prev = bp; ax25_routes = bp; } - + if (action) return bp; else @@ -188,17 +182,16 @@ ax25_rt_entry *update_ax25_route(config *config, ax25_address *call, int ndigi, bp_prev = bp; bp = bp->next; } - - if (ax25_routes_cnt >= ax25_maxroutes) - { + + if (ax25_routes_cnt >= ax25_maxroutes) { if (bp_prev == NULL) /* error */ return NULL; - + bp_prev->prev->next = NULL; free(bp_prev); ax25_routes_cnt--; } - + bp = (ax25_rt_entry *) malloc(sizeof(ax25_rt_entry)); if (bp == NULL) return NULL; @@ -210,33 +203,32 @@ ax25_rt_entry *update_ax25_route(config *config, ax25_address *call, int ndigi, bp->call = *call; if (ndigi) - memcpy(bp->digipeater, digi, ndigi*AXLEN); + memcpy(bp->digipeater, digi, ndigi * AXLEN); bp->ndigi = ndigi; - if (ax25_routes == NULL) - { + if (ax25_routes == NULL) { ax25_routes = bp; bp->next = bp->prev = NULL; return bp; } - - bp->next = ax25_routes; - bp->prev = NULL; + + bp->next = ax25_routes; + bp->prev = NULL; ax25_routes->prev = bp; ax25_routes = bp; return bp; } -ip_rt_entry * remove_ip_route(ip_rt_entry *bp) +ip_rt_entry *remove_ip_route(ip_rt_entry * bp) { ip_rt_entry *bp2; - + bp2 = bp->next; if (bp2) bp2->prev = bp->prev; - if (bp->prev) + if (bp->prev) bp->prev->next = bp2; if (bp == ip_routes) ip_routes = bp2; @@ -248,7 +240,7 @@ ip_rt_entry * remove_ip_route(ip_rt_entry *bp) return bp2; } -ax25_rt_entry * remove_ax25_route(ax25_rt_entry *bp) +ax25_rt_entry *remove_ax25_route(ax25_rt_entry * bp) { ax25_rt_entry *bp2; ip_rt_entry *iprt; @@ -260,7 +252,7 @@ ax25_rt_entry * remove_ax25_route(ax25_rt_entry *bp) bp->prev->next = bp2; if (bp == ax25_routes) ax25_routes = bp2; - + for (iprt = ip_routes; iprt; iprt = iprt->next) if (!memcmp(&iprt->call, &bp->call, AXLEN)) remove_ip_route(iprt); @@ -275,17 +267,16 @@ ax25_rt_entry * remove_ax25_route(ax25_rt_entry *bp) int del_ip_route(unsigned long ip) { ip_rt_entry *bp; - + if (ip == 0) return 1; - for (bp=ip_routes; bp; bp = bp->next) - if (bp->ip == ip) - { + for (bp = ip_routes; bp; bp = bp->next) + if (bp->ip == ip) { remove_ip_route(bp); return 0; } - + return 1; } @@ -293,27 +284,26 @@ int invalidate_ip_route(unsigned long ip) { ip_rt_entry *bp; - for (bp=ip_routes; bp; bp = bp->next) - if (bp->ip == ip) - { + for (bp = ip_routes; bp; bp = bp->next) + if (bp->ip == ip) { bp->invalid = 1; return 1; } - + return 0; } -int del_ax25_route(config * config, ax25_address *call) +int del_ax25_route(config * config, ax25_address * call) { ax25_rt_entry *bp; - - for (bp=ax25_routes; bp; bp = bp->next) - if (!memcmp(call, &bp->call, AXLEN) && !strcmp(config->dev, bp->iface)) - { + + for (bp = ax25_routes; bp; bp = bp->next) + if (!memcmp(call, &bp->call, AXLEN) + && !strcmp(config->dev, bp->iface)) { remove_ax25_route(bp); return 0; } - + return 1; } @@ -322,9 +312,9 @@ void expire_ax25_route(time_t when) { ax25_rt_entry *bp; time_t now = time(NULL); - - for (bp = ax25_routes; bp; ) - if (bp->timestamp != 0 && bp->timestamp+when <= now) + + for (bp = ax25_routes; bp;) + if (bp->timestamp != 0 && bp->timestamp + when <= now) bp = remove_ax25_route(bp); else bp = bp->next; @@ -334,9 +324,9 @@ void expire_ip_route(time_t when) { ip_rt_entry *bp; time_t now = time(NULL); - - for (bp = ip_routes; bp; ) - if (bp->timestamp != 0 && bp->timestamp+when <= now) + + for (bp = ip_routes; bp;) + if (bp->timestamp != 0 && bp->timestamp + when <= now) bp = remove_ip_route(bp); else bp = bp->next; diff --git a/ax25rtd/cache_dump.c b/ax25rtd/cache_dump.c index 0a2fd46..64cb8dd 100644 --- a/ax25rtd/cache_dump.c +++ b/ax25rtd/cache_dump.c @@ -1,4 +1,4 @@ -/* $Id: cache_dump.c,v 1.1.1.1 2001/04/10 01:58:39 csmall Exp $ +/* $Id: cache_dump.c,v 1.2 2001/09/12 13:18:43 terry Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * @@ -17,7 +17,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ - + #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -49,12 +49,10 @@ void dump_ip_routes(int fd, int cmd) unsigned long ip; int len; - for (bp = ip_routes; bp; bp = bp->next) - { + for (bp = ip_routes; bp; bp = bp->next) { ip = htonl(bp->ip); - if (cmd) - { + if (cmd) { len = sprintf(buf, "add ip "); dev = bp->iface; } else { @@ -66,24 +64,28 @@ void dump_ip_routes(int fd, int cmd) dev = bp->iface; } - len += sprintf(buf+len, "%d.%d.%d.%d", - (int) ((ip & 0xFF000000) >> 24), - (int) ((ip & 0x00FF0000) >> 16), - (int) ((ip & 0x0000FF00) >> 8), - (int) (ip & 0x000000FF)); - - len += sprintf(buf+len, " %-4s %8.8lx %-9s ", dev, bp->timestamp, ax25_ntoa(&bp->call)); + len += sprintf(buf + len, "%d.%d.%d.%d", + (int) ((ip & 0xFF000000) >> 24), + (int) ((ip & 0x00FF0000) >> 16), + (int) ((ip & 0x0000FF00) >> 8), + (int) (ip & 0x000000FF)); + + len += + sprintf(buf + len, " %-4s %8.8lx %-9s ", dev, + bp->timestamp, ax25_ntoa(&bp->call)); if (bp->invalid) - len += sprintf(buf+len, "X\n"); + len += sprintf(buf + len, "X\n"); else - len += sprintf(buf+len, "%c\n", bp->ipmode? 'v':'d'); + len += + sprintf(buf + len, "%c\n", + bp->ipmode ? 'v' : 'd'); write(fd, buf, len); } - + if (!cmd) write(fd, ".\n", 2); - + } void dump_ax25_routes(int fd, int cmd) @@ -93,10 +95,8 @@ void dump_ax25_routes(int fd, int cmd) char buf[256], *dev; int k, len; - for (bp = ax25_routes; bp; bp = bp->next) - { - if (cmd) - { + for (bp = ax25_routes; bp; bp = bp->next) { + if (cmd) { len = sprintf(buf, "add ax25 "); dev = bp->iface; } else { @@ -107,15 +107,19 @@ void dump_ax25_routes(int fd, int cmd) else dev = bp->iface; } - - len += sprintf(buf+len, "%-9s %-4s %8.8lx", ax25_ntoa(&bp->call), dev, bp->timestamp); - + + len += + sprintf(buf + len, "%-9s %-4s %8.8lx", + ax25_ntoa(&bp->call), dev, bp->timestamp); + for (k = 0; k < bp->ndigi; k++) - len += sprintf(buf+len, " %s", ax25_ntoa(&bp->digipeater[k])); - len += sprintf(buf+len, "\n"); + len += + sprintf(buf + len, " %s", + ax25_ntoa(&bp->digipeater[k])); + len += sprintf(buf + len, "\n"); write(fd, buf, len); } - + if (!cmd) write(fd, ".\n", 2); } @@ -126,26 +130,38 @@ void dump_config(int fd) int k; fprintf(stderr, "config:\n"); - for (config = Config; config; config = config->next) - { + for (config = Config; config; config = config->next) { fprintf(stderr, "Device = %s\n", config->dev); fprintf(stderr, "Port = %s\n", config->port); - fprintf(stderr, "ax25_add_route = %d\n", config->ax25_add_route); - fprintf(stderr, "ax25_for_me = %d\n", config->ax25_for_me); - fprintf(stderr, "ax25_add_default = %d\n", config->ax25_add_default); - fprintf(stderr, "ip_add_route = %d\n", config->ip_add_route); - fprintf(stderr, "ip_add_arp = %d\n", config->ip_add_arp); - fprintf(stderr, "ip_adjust_mode = %d\n", config->ip_adjust_mode); - fprintf(stderr, "netmask = %8.8lx\n", config->netmask); + fprintf(stderr, "ax25_add_route = %d\n", + config->ax25_add_route); + fprintf(stderr, "ax25_for_me = %d\n", + config->ax25_for_me); + fprintf(stderr, "ax25_add_default = %d\n", + config->ax25_add_default); + fprintf(stderr, "ip_add_route = %d\n", + config->ip_add_route); + fprintf(stderr, "ip_add_arp = %d\n", + config->ip_add_arp); + fprintf(stderr, "ip_adjust_mode = %d\n", + config->ip_adjust_mode); + fprintf(stderr, "netmask = %8.8lx\n", + config->netmask); fprintf(stderr, "ip = %8.8lx\n", config->ip); - fprintf(stderr, "nmycalls = %d\n", config->nmycalls); + fprintf(stderr, "nmycalls = %d\n", + config->nmycalls); fprintf(stderr, "calls ="); for (k = 0; k < config->nmycalls; k++) - fprintf(stderr, " %s", ax25_ntoa(&config->mycalls[k])); + fprintf(stderr, " %s", + ax25_ntoa(&config->mycalls[k])); fprintf(stderr, "\n"); fprintf(stderr, "ax25_default_path="); - for (k = 0; k < config->ax25_default_path.fsa_ax25.sax25_ndigis; k++) - fprintf(stderr, " %s", ax25_ntoa(&config->ax25_default_path.fsa_digipeater[k])); + for (k = 0; + k < config->ax25_default_path.fsa_ax25.sax25_ndigis; + k++) + fprintf(stderr, " %s", + ax25_ntoa(&config->ax25_default_path. + fsa_digipeater[k])); fprintf(stderr, "\n.\n"); } } diff --git a/ax25rtd/config.c b/ax25rtd/config.c index 549e687..4d63b51 100644 --- a/ax25rtd/config.c +++ b/ax25rtd/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.1.1.1 2001/04/10 01:58:40 csmall Exp $ +/* $Id: config.c,v 1.2 2001/09/12 13:18:43 terry Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * @@ -17,13 +17,13 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ - + #include <stdio.h> -#include <stdlib.h> +#include <stdlib.h> #include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <ctype.h> +#include <fcntl.h> +#include <string.h> +#include <ctype.h> #include <errno.h> #include <time.h> #include <sys/ioctl.h> @@ -45,13 +45,13 @@ #include "../pathnames.h" #include "ax25rtd.h" - + ax25_address *asc2ax(char *call) { static ax25_address callsign; - - ax25_aton_entry(call, (char *)&callsign); - + + ax25_aton_entry(call, (char *) &callsign); + return &callsign; } @@ -66,49 +66,46 @@ static long asc2ip(char *s) } -char * prepare_cmdline(char *buf) +char *prepare_cmdline(char *buf) { char *p; - for (p = buf; *p; p++) - { - if (*p == '\t') *p = ' '; + for (p = buf; *p; p++) { + if (*p == '\t') + *p = ' '; *p = tolower(*p); - - if (*p == '\n') - { + + if (*p == '\n') { *p = '\0'; break; } - - if (*p == '#') - { + + if (*p == '#') { *p = '\0'; break; } } - + return buf; } -char * get_next_arg(char **p) +char *get_next_arg(char **p) { char *p2; - + if (p == NULL || *p == NULL) return NULL; p2 = *p; - for (; *p2 && *p2 == ' '; p2++) ; + for (; *p2 && *p2 == ' '; p2++); if (!*p2) return NULL; - + *p = strchr(p2, ' '); - if (*p != NULL) - { + if (*p != NULL) { **p = '\0'; (*p)++; } - + return p2; } @@ -128,7 +125,7 @@ static int yesno(char *arg) return 0; if (!strcmp(arg, "yes") || !strcmp(arg, "1")) return 1; - if (!strcmp(arg, "no") || !strcmp(arg, "0")) + if (!strcmp(arg, "no") || !strcmp(arg, "0")) return 0; return -1; } @@ -136,7 +133,7 @@ static int yesno(char *arg) static ax25_address *get_mycall(char *port) { char *addr; - + if ((addr = ax25_config_get_addr(port)) == NULL) return NULL; @@ -149,36 +146,35 @@ void load_ports(void) config *config, *cfg, *ncfg; char buf[1024]; struct ifconf ifc; - struct ifreq ifr, *ifrp; + struct ifreq ifr, *ifrp; int k, fd; - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - { + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { fprintf(stderr, "Unable to open socket\n"); exit(1); } - - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = buf; - if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) - { - fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno)); - return; - } + + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) { + fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno)); + return; + } ifrp = ifc.ifc_req; - for (k = ifc.ifc_len / sizeof(struct ifreq); k > 0; k--, ifrp++) - { - strcpy(ifr.ifr_name, ifrp->ifr_name); - if (strcmp(ifr.ifr_name, "lo") == 0) continue; - - if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) - { - fprintf(stderr, "SIOCGIFFLAGS: %s\n", strerror(errno)); + for (k = ifc.ifc_len / sizeof(struct ifreq); k > 0; k--, ifrp++) { + strcpy(ifr.ifr_name, ifrp->ifr_name); + if (strcmp(ifr.ifr_name, "lo") == 0) + continue; + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + fprintf(stderr, "SIOCGIFFLAGS: %s\n", + strerror(errno)); exit(1); - } + } - if (!(ifr.ifr_flags & IFF_UP)) continue; + if (!(ifr.ifr_flags & IFF_UP)) + continue; ioctl(fd, SIOCGIFHWADDR, &ifr); @@ -186,14 +182,19 @@ void load_ports(void) continue; for (config = Config; config; config = config->next) - if (!memcmp(&config->mycalls[0], ifr.ifr_hwaddr.sa_data, AXLEN) && !*config->dev) - { + if (!memcmp + (&config->mycalls[0], ifr.ifr_hwaddr.sa_data, + AXLEN) && !*config->dev) { strcpy(config->dev, ifr.ifr_name); ioctl(fd, SIOCGIFADDR, &ifr); - config->ip = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr; + config->ip = + ((struct sockaddr_in *) &ifr. + ifr_addr)->sin_addr.s_addr; strcpy(ifr.ifr_name, config->dev); ioctl(fd, SIOCGIFNETMASK, &ifr); - config->netmask = ((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr; + config->netmask = + ((struct sockaddr_in *) &ifr. + ifr_netmask)->sin_addr.s_addr; break; } } @@ -201,12 +202,9 @@ void load_ports(void) config = cfg = Config; - while(config) - { - if (!*config->dev) - { - if (config == Config) - { + while (config) { + if (!*config->dev) { + if (config == Config) { Config = config->next; cfg = Config; } else @@ -230,33 +228,39 @@ void load_listeners(void) FILE *fp; ax25_address *axcall; - + fp = fopen(PROC_AX25_FILE, "r"); - - if (fp == NULL) - { + + if (fp == NULL) { fprintf(stderr, "No AX.25 in kernel. Tss, tss...\n"); exit(1); } - - while (fgets(buf, sizeof(buf)-1, fp) != NULL) - { + + while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { k = sscanf(buf, "%s %s %s %s", dummy, device, call, dcall); - if (k == 4 && !strcmp(dcall, "*")) - { + if (k == 4 && !strcmp(dcall, "*")) { axcall = asc2ax(call); if (!strcmp("*", device)) { - for (config = Config; config; config = config->next) { - if (call_is_mycall(config, axcall) || config->nmycalls > AX25_MAXCALLS) + for (config = Config; config; + config = config->next) { + if (call_is_mycall(config, axcall) + || config->nmycalls > + AX25_MAXCALLS) continue; - memcpy(&config->mycalls[config->nmycalls++], axcall, AXLEN); + memcpy(&config-> + mycalls[config->nmycalls++], + axcall, AXLEN); } } else { config = dev_get_config(device); - if (config == NULL || call_is_mycall(config, axcall) || config->nmycalls > AX25_MAXCALLS) + if (config == NULL + || call_is_mycall(config, axcall) + || config->nmycalls > AX25_MAXCALLS) continue; - memcpy(&config->mycalls[config->nmycalls++], axcall, AXLEN); + memcpy(&config-> + mycalls[config->nmycalls++], axcall, + AXLEN); } } } @@ -269,19 +273,18 @@ void load_config() char buf[1024], *p, *cmd, *arg; config *config, *cfg; ax25_address *axcall; - + config = NULL; - + fp = fopen(CONF_AX25ROUTED_FILE, "r"); - - if (fp == NULL) - { - fprintf(stderr, "config file %s not found\n", CONF_AX25ROUTED_FILE); + + if (fp == NULL) { + fprintf(stderr, "config file %s not found\n", + CONF_AX25ROUTED_FILE); exit(1); } - - while(fgets(buf, sizeof(buf)-1, fp) != NULL) - { + + while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { p = prepare_cmdline(buf); if (!*p) continue; @@ -290,50 +293,46 @@ void load_config() if (cmd == NULL) continue; arg = get_next_arg(&p); - - if (*cmd == '[') - { + + if (*cmd == '[') { cmd++; p = strrchr(cmd, ']'); - if (p == NULL) - { - fprintf(stderr, "syntax error: [%s\n", cmd); + if (p == NULL) { + fprintf(stderr, "syntax error: [%s\n", + cmd); continue; } *p = '\0'; - + axcall = get_mycall(cmd); if (axcall == NULL) continue; - - cfg = (struct config_ *) malloc(sizeof(struct config_)); - if (cfg == NULL) - { + + cfg = + (struct config_ *) + malloc(sizeof(struct config_)); + if (cfg == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } memset(cfg, 0, sizeof(struct config_)); - + if (config) config->next = cfg; else Config = cfg; - + cfg->next = NULL; config = cfg; strcpy(config->port, cmd); memcpy(&config->mycalls[0], axcall, AXLEN); config->nmycalls = 1; - } else - if (config && !strcmp(cmd, "ax25-learn-routes")) - { - /* ax25-learn-routes no|yes: learn digipeater path */ - if (arg) - { + } else if (config && !strcmp(cmd, "ax25-learn-routes")) { + /* ax25-learn-routes no|yes: learn digipeater path */ + if (arg) { int k = yesno(arg); - if (k == -1) - { + if (k == -1) { invalid_arg(cmd, arg); continue; } else { @@ -341,16 +340,12 @@ void load_config() } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "ax25-learn-only-mine")) - { - /* ax25-learn-only-mine no|yes: learn only if addressed to me */ - if (arg) - { + } else if (config && !strcmp(cmd, "ax25-learn-only-mine")) { + /* ax25-learn-only-mine no|yes: learn only if addressed to me */ + if (arg) { int k = yesno(arg); - if (k == -1) - { + if (k == -1) { invalid_arg(cmd, arg); continue; } else { @@ -358,50 +353,46 @@ void load_config() } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "ax25-add-path")) - { - /* ax25-add-path [no|<digis>]: add digis if digi-less frame rvd */ + } else if (config && !strcmp(cmd, "ax25-add-path")) { + /* ax25-add-path [no|<digis>]: add digis if digi-less frame rvd */ int k = 0; if (!arg || (arg && yesno(arg) == 0)) continue; config->ax25_add_default = 1; - while (arg && k < AX25_MAX_DIGIS) - { - memcpy(&config->ax25_default_path.fsa_digipeater[k], asc2ax(arg), AXLEN); + while (arg && k < AX25_MAX_DIGIS) { + memcpy(&config->ax25_default_path. + fsa_digipeater[k], asc2ax(arg), + AXLEN); arg = get_next_arg(&p); k++; } - config->ax25_default_path.fsa_ax25.sax25_ndigis = k; - } else - if (config && !strcmp(cmd, "ax25-more-mycalls")) - { - /* ax25-more-mycalls call1 call2: frames to this calls are for "me", too. */ - if (arg) - { - while(arg && config->nmycalls < AX25_MAXCALLS) - { + config->ax25_default_path.fsa_ax25.sax25_ndigis = + k; + } else if (config && !strcmp(cmd, "ax25-more-mycalls")) { + /* ax25-more-mycalls call1 call2: frames to this calls are for "me", too. */ + if (arg) { + while (arg + && config->nmycalls < + AX25_MAXCALLS) { axcall = asc2ax(arg); if (call_is_mycall(config, axcall)) { arg = get_next_arg(&p); continue; } - memcpy(&config->mycalls[config->nmycalls++], axcall, AXLEN); + memcpy(&config-> + mycalls[config->nmycalls++], + axcall, AXLEN); arg = get_next_arg(&p); } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "ip-learn-routes")) - { - /* ip-learn-routes no|yes: learn ip routes */ - if (arg) - { + } else if (config && !strcmp(cmd, "ip-learn-routes")) { + /* ip-learn-routes no|yes: learn ip routes */ + if (arg) { int k = yesno(arg); - - if (k == -1) - { + + if (k == -1) { invalid_arg(cmd, arg); continue; } else { @@ -409,16 +400,12 @@ void load_config() } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "irtt")) - { - /* irtt <irtt>: new routes will get this IRTT in msec */ - if (arg) - { + } else if (config && !strcmp(cmd, "irtt")) { + /* irtt <irtt>: new routes will get this IRTT in msec */ + if (arg) { int k = atoi(arg); - - if (k == 0) - { + + if (k == 0) { invalid_arg(cmd, arg); continue; } else { @@ -426,16 +413,12 @@ void load_config() } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "dg-mtu")) - { - /* dg-mtu <mtu>: MTU for datagram mode routes (unused) */ - if (arg) - { + } else if (config && !strcmp(cmd, "dg-mtu")) { + /* dg-mtu <mtu>: MTU for datagram mode routes (unused) */ + if (arg) { int k = atoi(arg); - - if (k == 0) - { + + if (k == 0) { invalid_arg(cmd, arg); continue; } else { @@ -443,33 +426,25 @@ void load_config() } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "vc-mtu")) - { + } else if (config && !strcmp(cmd, "vc-mtu")) { /* vc-mtu <mtu>: MTU for virtual connect mode routes (unused) */ - if (arg) - { - int k = atoi(arg); + if (arg) { + int k = atoi(arg); - if (k == 0) - { - invalid_arg(cmd, arg); - continue; - } else { - config->vc_mtu = k; + if (k == 0) { + invalid_arg(cmd, arg); + continue; + } else { + config->vc_mtu = k; } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "ip-adjust-mode")) - { - /* ip-adjust-mode no|yes: adjust ip-mode? (dg or vc) */ - if (arg) - { + } else if (config && !strcmp(cmd, "ip-adjust-mode")) { + /* ip-adjust-mode no|yes: adjust ip-mode? (dg or vc) */ + if (arg) { int k = yesno(arg); - - if (k == -1) - { + + if (k == -1) { invalid_arg(cmd, arg); continue; } else { @@ -477,16 +452,12 @@ void load_config() } } else missing_arg(cmd); - } else - if (config && !strcmp(cmd, "arp-add")) - { - /* arp-add no|yes: adjust arp table? */ - if (arg) - { + } else if (config && !strcmp(cmd, "arp-add")) { + /* arp-add no|yes: adjust arp table? */ + if (arg) { int k = yesno(arg); - - if (k == -1) - { + + if (k == -1) { invalid_arg(cmd, arg); continue; } else { @@ -494,44 +465,38 @@ void load_config() } } else missing_arg(cmd); - } else - if (!strcmp(cmd, "ip-encaps-dev")) { + } else if (!strcmp(cmd, "ip-encaps-dev")) { if (arg) strcpy(ip_encaps_dev, arg); else missing_arg(cmd); - } else - if (!strcmp(cmd, "ax25-maxroutes")) - { + } else if (!strcmp(cmd, "ax25-maxroutes")) { if (arg) ax25_maxroutes = atoi(arg); else missing_arg(cmd); - } else - if (!strcmp(cmd, "ip-maxroutes")) - { + } else if (!strcmp(cmd, "ip-maxroutes")) { if (arg) ax25_maxroutes = atoi(arg); else missing_arg(cmd); - + } else fprintf(stderr, "invalid command %s\n", cmd); } fclose(fp); - + load_ports(); load_listeners(); - + reload = 0; } void reload_config(void) { config *cfg, *config = Config; - - while(config) - { + + while (config) { cfg = config->next; free(config); config = cfg; @@ -584,65 +549,68 @@ void interpret_command(int fd, unsigned char *buf) long ip; p = prepare_cmdline(buf); - - if (!*p) return; - + + if (!*p) + return; + cmd = get_next_arg(&p); arg = get_next_arg(&p); - - if (!strcmp(cmd, "add")) - { + + if (!strcmp(cmd, "add")) { if (arg == NULL) return; if ((arg2 = get_next_arg(&p)) == NULL) return; - if ( (dev = get_next_arg(&p)) == NULL) + if ((dev = get_next_arg(&p)) == NULL) return; - if ( (time = get_next_arg(&p)) == NULL) + if ((time = get_next_arg(&p)) == NULL) return; - if ( (config = dev_get_config(dev)) == NULL) + if ((config = dev_get_config(dev)) == NULL) return; sscanf(time, "%lx", &stamp); - if (!strcmp(arg, "ax25")) - { + if (!strcmp(arg, "ax25")) { ndigi = 0; arg = get_next_arg(&p); - while (arg != NULL) - { - memcpy(&digipeater[ndigi++], asc2ax(arg), AXLEN); + while (arg != NULL) { + memcpy(&digipeater[ndigi++], asc2ax(arg), + AXLEN); if (ndigi == AX25_MAX_DIGIS) break; arg = get_next_arg(&p); } - ax25rt = update_ax25_route(config, asc2ax(arg2), ndigi, digipeater, stamp); + ax25rt = + update_ax25_route(config, asc2ax(arg2), ndigi, + digipeater, stamp); if (ax25rt != NULL) set_ax25_route(config, ax25rt); - } else - if (!strcmp(arg, "ip")) - { + } else if (!strcmp(arg, "ip")) { ip = asc2ip(arg2); - + if ((arg2 = get_next_arg(&p)) == NULL) return; if ((arg = get_next_arg(&p)) == NULL) return; - + if (*arg == 'x') return; - + ipmode = (*arg == 'v'); - if ((config = dev_get_config(ip_encaps_dev)) == NULL) { - printf("no config for %s\n", ip_encaps_dev); + if ((config = + dev_get_config(ip_encaps_dev)) == NULL) { + printf("no config for %s\n", + ip_encaps_dev); return; } - action = update_ip_route(config, ip, ipmode, asc2ax(arg2), stamp); + action = + update_ip_route(config, ip, ipmode, + asc2ax(arg2), stamp); if (action & NEW_ROUTE) if (set_route(config, ip)) @@ -651,68 +619,57 @@ void interpret_command(int fd, unsigned char *buf) if (action & NEW_ARP) if (set_arp(config, ip, asc2ax(arg2))) return; - + if (action & NEW_IPMODE) - if (set_ipmode(config, asc2ax(arg2), ipmode)) + if (set_ipmode + (config, asc2ax(arg2), ipmode)) return; } - } else if (!strcmp(cmd, "del")) - { + } else if (!strcmp(cmd, "del")) { if (arg == NULL) return; arg2 = get_next_arg(&p); if (arg2 == NULL) return; - - if (!strcmp(arg, "ax25")) - { + + if (!strcmp(arg, "ax25")) { arg = get_next_arg(&p); - if (arg == NULL || (config = dev_get_config(arg)) == NULL) + if (arg == NULL + || (config = dev_get_config(arg)) == NULL) return; del_ax25_route(config, asc2ax(arg2)); - } else - if (!strcmp(arg, "ip")) - { + } else if (!strcmp(arg, "ip")) { del_ip_route(asc2ip(arg2)); } - } else if (!strcmp(cmd, "expire")) - { + } else if (!strcmp(cmd, "expire")) { if (arg == NULL) return; sscanf(arg, "%ld", &stamp); - if (stamp != 0) - { - stamp*=60; + if (stamp != 0) { + stamp *= 60; expire_ax25_route(stamp); expire_ip_route(stamp); } - } else if (!strcmp(cmd, "reload")) - { + } else if (!strcmp(cmd, "reload")) { reload_config(); - } else if (!strcmp(cmd, "list")) - { + } else if (!strcmp(cmd, "list")) { if (arg == NULL) return; - + if (!strcmp(arg, "ax25")) dump_ax25_routes(fd, 0); - else - if (!strcmp(arg, "ip")) + else if (!strcmp(arg, "ip")) dump_ip_routes(fd, 0); - } else if (!strcmp(cmd, "shutdown")) - { + } else if (!strcmp(cmd, "shutdown")) { save_cache(); daemon_shutdown(0); - } else if (!strcmp(cmd, "save")) - { + } else if (!strcmp(cmd, "save")) { save_cache(); - } else if (!strcmp(cmd, "version")) - { + } else if (!strcmp(cmd, "version")) { char buf[256]; sprintf(buf, "%s\n", Version); write(fd, buf, strlen(buf)); - } else if (!strcmp(cmd, "quit")) - { + } else if (!strcmp(cmd, "quit")) { close(fd); } } @@ -721,28 +678,28 @@ void load_cache(void) { FILE *fp; char buf[512]; - + fp = fopen(DATA_AX25ROUTED_AXRT_FILE, "r"); - if (fp != NULL) - { - while(fgets(buf, sizeof(buf), fp) != NULL) + if (fp != NULL) { + while (fgets(buf, sizeof(buf), fp) != NULL) interpret_command(2, buf); fclose(fp); - } else perror("open AX.25 route cache file"); - + } else + perror("open AX.25 route cache file"); + fp = fopen(DATA_AX25ROUTED_IPRT_FILE, "r"); - if (fp != NULL) - { - while(fgets(buf, sizeof(buf), fp) != NULL) + if (fp != NULL) { + while (fgets(buf, sizeof(buf), fp) != NULL) interpret_command(2, buf); fclose(fp); - } else perror("open IP route cache file"); + } else + perror("open IP route cache file"); } void save_cache(void) { int fd; - + fd = creat(DATA_AX25ROUTED_AXRT_FILE, 0664); dump_ax25_routes(fd, 1); close(fd); diff --git a/ax25rtd/listener.c b/ax25rtd/listener.c index 0cb7fe8..d3bd698 100644 --- a/ax25rtd/listener.c +++ b/ax25rtd/listener.c @@ -1,4 +1,4 @@ -/* $Id: listener.c,v 1.1.1.1 2001/04/10 01:58:42 csmall Exp $ +/* $Id: listener.c,v 1.3 2001/11/27 04:57:43 csmall Exp $ * * Copyright (c) 1996 Jörg Reuter (jreuter@poboxes.com) * @@ -17,7 +17,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ - + /* TODO: Should add partial path to ax25_route if we are one of the * digipeaters. */ @@ -27,7 +27,7 @@ #include <stdio.h> #include <string.h> -#include <unistd.h> +#include <unistd.h> #include <signal.h> #include <sys/ioctl.h> #ifdef TIME_WITH_SYS_TIME @@ -54,29 +54,29 @@ static unsigned long get_from_arp(unsigned char *data, int size) { if (size < 16) return 0; - + return ntohl(0); } static unsigned long get_from_ip(unsigned char *data, int size) { unsigned long adr; - - if ((*data & 0xf)*4 < IPLEN) + + if ((*data & 0xf) * 4 < IPLEN) return 0; - adr = data[12] << 24; /* NETWORK byte order */ + adr = data[12] << 24; /* NETWORK byte order */ adr += data[13] << 16; - adr += data[14] << 8; + adr += data[14] << 8; adr += data[15]; return ntohl(adr); /* HOST byte order */ } -int call_is_mycall(config *config, ax25_address *call) +int call_is_mycall(config * config, ax25_address * call) { int k; - + for (k = 0; k < config->nmycalls; k++) if (!memcmp(call, &config->mycalls[k], AXLEN)) return 1; @@ -89,30 +89,32 @@ int call_is_mycall(config *config, ax25_address *call) static int check_ax25_addr(unsigned char *buf) { - int k; - unsigned char c; - - /* must start with at least one capital letter or digit */ - for (k=0; k < 6; k++) { - c = buf[k] >> 1; - if (c == ' ') break; - if ((c < 'A' || c > 'Z') && (c < '0' || c > '9')) - return 1; - } - - /* NULL address is invalid */ - if (k == 0) - return 1; - - /* remaining fields must consist of spaces only */ - for (k++; k < 6; k++) - if (buf[k] >> 1 != ' ') - return 1; - - return 0; + int k; + unsigned char c; + + /* must start with at least one capital letter or digit */ + for (k = 0; k < 6; k++) { + c = buf[k] >> 1; + if (c == ' ') + break; + if ((c < 'A' || c > 'Z') && (c < '0' || c > '9')) + return 1; + } + + /* NULL address is invalid */ + if (k == 0) + return 1; + + /* remaining fields must consist of spaces only */ + for (k++; k < 6; k++) + if (buf[k] >> 1 != ' ') + return 1; + + return 0; } -static inline void invert_digipeater_path(ax25_address *digipeater, int ndigi) +static inline void invert_digipeater_path(ax25_address * digipeater, + int ndigi) { int k, m; ax25_address fdigi; @@ -120,43 +122,42 @@ static inline void invert_digipeater_path(ax25_address *digipeater, int ndigi) if (ndigi == 0) return; - for (m = 0,k = ndigi-1; k > m; k--, m++) { + for (m = 0, k = ndigi - 1; k > m; k--, m++) { memcpy(&fdigi, &digipeater[m], AXLEN); memcpy(&digipeater[m], &digipeater[k], AXLEN); memcpy(&digipeater[k], &fdigi, AXLEN); } } -int set_arp(config *config, long ip, ax25_address *call) +int set_arp(config * config, long ip, ax25_address * call) { - struct sockaddr_in *isa; + struct sockaddr_in *isa; struct sockaddr_ax25 *asa; struct arpreq arp; - int fds; - + int fds; + if (!config->ip_add_arp) return 0; - + fds = socket(AF_INET, SOCK_DGRAM, 0); memset((char *) &arp, 0, sizeof(arp)); - isa = (struct sockaddr_in *) &arp.arp_pa; + isa = (struct sockaddr_in *) &arp.arp_pa; asa = (struct sockaddr_ax25 *) &arp.arp_ha; - + isa->sin_family = AF_INET; isa->sin_port = 0; isa->sin_addr.s_addr = ip; asa->sax25_family = AF_AX25; asa->sax25_ndigis = 0; - asa->sax25_call = *call; + asa->sax25_call = *call; arp.arp_flags = ATF_PERM | ATF_COM; strcpy(arp.arp_dev, config->dev); - - if (ioctl(fds, SIOCSARP, &arp) < 0) - { + + if (ioctl(fds, SIOCSARP, &arp) < 0) { invalidate_ip_route(ip); perror("routspy: SIOCSARP"); close(fds); @@ -166,42 +167,37 @@ int set_arp(config *config, long ip, ax25_address *call) return 0; } -int set_route(config *config, long ip) +int set_route(config * config, long ip) { struct rtentry rt; struct sockaddr_in *isa; - char origdev[16], buf[1024]; + char origdev[16], buf[1024]; /* modif f5lct */ - long gwr; + long gwr; /* fin modif f5lct */ long ipr; int fds; FILE *fp; - + fp = fopen(PROC_IP_ROUTE_FILE, "r"); - if (fp == NULL) - { + if (fp == NULL) { invalidate_ip_route(ip); return 1; } - fgets(buf, sizeof(buf)-1, fp); /* discard header */ - while (fgets(buf, sizeof(buf)-1, fp) != NULL) - { + fgets(buf, sizeof(buf) - 1, fp); /* discard header */ + while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { /* modif f5lct */ - /* sscanf(buf, "%s %lx", origdev, &ipr); */ + /* sscanf(buf, "%s %lx", origdev, &ipr); */ sscanf(buf, "%s %lx %lx", origdev, &ipr, &gwr); - if (ipr == ip && gwr == 00000000 ) + if (ipr == ip && gwr == 00000000) /* fin modif f5lct */ { - if (dev_get_config(origdev) == NULL) - { + if (dev_get_config(origdev) == NULL) { invalidate_ip_route(ip); fclose(fp); return 1; - } - else - { + } else { del_kernel_ip_route(origdev, ip); } } @@ -217,25 +213,23 @@ int set_route(config *config, long ip) memset((char *) &rt, 0, sizeof(rt)); isa = (struct sockaddr_in *) &rt.rt_dst; - + isa->sin_family = AF_INET; isa->sin_port = 0; isa->sin_addr.s_addr = ip; - + rt.rt_flags = RTF_UP | RTF_HOST; rt.rt_dev = config->dev; - if (config->tcp_irtt != 0) - { + if (config->tcp_irtt != 0) { rt.rt_irtt = config->tcp_irtt; rt.rt_flags |= RTF_IRTT; } isa = (struct sockaddr_in *) &rt.rt_genmask; isa->sin_addr.s_addr = 0xffffffff; - - if (ioctl(fds, SIOCADDRT, &rt) < 0) - { + + if (ioctl(fds, SIOCADDRT, &rt) < 0) { invalidate_ip_route(ip); perror("ax25rtd: IP SIOCADDRT"); close(fds); @@ -261,15 +255,14 @@ int del_kernel_ip_route(char *dev, long ip) memset((char *) &rt, 0, sizeof(struct rtentry)); isa = (struct sockaddr_in *) &rt.rt_dst; - + isa->sin_family = AF_INET; isa->sin_addr.s_addr = ip; - rt.rt_flags = RTF_UP | RTF_HOST; + rt.rt_flags = RTF_UP | RTF_HOST; rt.rt_dev = dev; - if (ioctl(fds, SIOCDELRT, &rt) < 0) - { + if (ioctl(fds, SIOCDELRT, &rt) < 0) { perror("ax25rtd: IP SIOCDELRT"); close(fds); return 1; @@ -278,77 +271,74 @@ int del_kernel_ip_route(char *dev, long ip) return 0; } -int set_ax25_route(config *config, ax25_rt_entry *rt) +int set_ax25_route(config * config, ax25_rt_entry * rt) { struct ax25_routes_struct ax25_route; int fds, k; - + if (!config->ax25_add_route) return 0; - ax25_route.port_addr = config->mycalls[0]; - ax25_route.dest_addr = rt->call; + ax25_route.port_addr = config->mycalls[0]; + ax25_route.dest_addr = rt->call; ax25_route.digi_count = rt->ndigi; for (k = 0; k < rt->ndigi; k++) ax25_route.digi_addr[k] = rt->digipeater[k]; fds = socket(AF_AX25, SOCK_SEQPACKET, 0); - - if (ioctl(fds, SIOCADDRT, &ax25_route) < 0) - { + + if (ioctl(fds, SIOCADDRT, &ax25_route) < 0) { perror("ax25rtd: AX.25 SIOCADDRT"); close(fds); return 1; } - + close(fds); return 0; } -int del_kernel_ax25_route(char *dev, ax25_address *call) +int del_kernel_ax25_route(char *dev, ax25_address * call) { struct ax25_routes_struct ax25_route; int fds; config *config; - + config = dev_get_config(dev); if (config == NULL || !config->ax25_add_route) return 0; - ax25_route.port_addr = config->mycalls[0]; - ax25_route.dest_addr = *call; + ax25_route.port_addr = config->mycalls[0]; + ax25_route.dest_addr = *call; fds = socket(AF_AX25, SOCK_SEQPACKET, 0); - - if (ioctl(fds, SIOCDELRT, &ax25_route) < 0) - { + + if (ioctl(fds, SIOCDELRT, &ax25_route) < 0) { perror("ax25rtd: AX.25 SIOCDELRT"); close(fds); return 1; } - + close(fds); return 0; } -int set_ipmode(config *config, ax25_address *call, int ipmode) +int set_ipmode(config * config, ax25_address * call, int ipmode) { struct ax25_route_opt_struct ax25_opt; int fds; - + if (!config->ip_adjust_mode) return 0; - + ax25_opt.port_addr = config->mycalls[0]; ax25_opt.dest_addr = *call; - ax25_opt.cmd = AX25_SET_RT_IPMODE; - ax25_opt.arg = ipmode? 'V':'D'; - + ax25_opt.cmd = AX25_SET_RT_IPMODE; + ax25_opt.arg = ipmode ? 'V' : 'D'; + fds = socket(AF_AX25, SOCK_SEQPACKET, 0); - - if (ioctl(fds, SIOCAX25OPTRT, &ax25_opt) < 0) - { + + if (ioctl(fds, SIOCAX25OPTRT, &ax25_opt) < 0) { perror("ax25rtd: SIOCAX25OPTRT"); close(fds); return 1; @@ -356,7 +346,7 @@ int set_ipmode(config *config, ax25_address *call, int ipmode) close(fds); return 0; - + } /* Yes, the code *IS* ugly... */ @@ -373,11 +363,10 @@ void ax25_receive(int sock) int size, asize, action, ipmode, ctl, pid, ndigi, kdigi, mine; time_t stamp; config *config; - ax25_rt_entry * ax25rt; + ax25_rt_entry *ax25rt; asize = sizeof(sa); - if ((size = recvfrom(sock, buf, sizeof(buf), 0, &sa, &asize)) < 0) - { + if ((size = recvfrom(sock, buf, sizeof(buf), 0, &sa, &asize)) < 0) { perror("recvfrom"); save_cache(); daemon_shutdown(1); @@ -388,7 +377,7 @@ void ax25_receive(int sock) pid = ctl = 0; config = dev_get_config(sa.sa_data); - + if (config == NULL) return; @@ -398,16 +387,16 @@ void ax25_receive(int sock) * KISS data? */ - if ((*data & 0x0f) != 0) + if ((*data & 0x0f) != 0) return; - + SKIP(1); /* valid frame? */ - - if (size < (2*AXLEN+1)) + + if (size < (2 * AXLEN + 1)) return; - + /* * Get destination callsign */ @@ -418,33 +407,32 @@ void ax25_receive(int sock) memcpy(&destcall, data, AXLEN); destcall.ax25_call[6] &= 0x1e; SKIP(AXLEN); - + mine = call_is_mycall(config, &destcall); - + /* * Get Source callsign */ - + if (check_ax25_addr(data)) return; memcpy(&srccall, data, AXLEN); srccall.ax25_call[6] &= 0x1e; SKIP(ALEN); - + /* * How long is our control field? */ - + extseq = ~(*data) & SSSID_SPARE; - + /* * Extract digipeaters */ ndigi = 0; - while (((*data) & HDLCAEB) != HDLCAEB) - { + while (((*data) & HDLCAEB) != HDLCAEB) { SKIP(1); if (size <= 0 || check_ax25_addr(data)) return; @@ -453,23 +441,22 @@ void ax25_receive(int sock) memcpy(&digipeater[ndigi++], data, AXLEN); else return; - + SKIP(ALEN); } - + SKIP(1); - if (size <= 0) + if (size <= 0) return; - + /* * Get type of frame */ if ((*data & LAPB_S) == LAPB_I) ctl = LAPB_I; - else - { + else { ctl = *data; if (extseq == 0) ctl &= ~LAPB_PF; @@ -479,68 +466,72 @@ void ax25_receive(int sock) * Check if info frame and get PID */ - if (ctl == LAPB_I || ctl == LAPB_UI) - { - SKIP(extseq? 2:1); + if (ctl == LAPB_I || ctl == LAPB_UI) { + SKIP(extseq ? 2 : 1); if (size <= 0) return; /* Get PID */ - + pid = *data; - if (pid == PID_SEGMENT) - { + if (pid == PID_SEGMENT) { SKIP(1); if (size <= 0) return; pid = 0; - - if (*data && SEG_FIRST) - { + + if (*data && SEG_FIRST) { pid = *data; - SKIP(1); + SKIP(1); if (size <= 0) return; - } + } } - } - + } + /* * See if it is fully digipeated (TODO: or if we are the next digipeater) */ - for (kdigi = 0; kdigi < ndigi; kdigi++) - { - if ((digipeater[kdigi].ax25_call[6] & AX25_REPEATED) != AX25_REPEATED) + for (kdigi = 0; kdigi < ndigi; kdigi++) { + if ((digipeater[kdigi].ax25_call[6] & AX25_REPEATED) != + AX25_REPEATED) return; - + digipeater[kdigi].ax25_call[6] &= 0x1e; } invert_digipeater_path(digipeater, ndigi); - + /* * Are we allowed to add it to our routing table? */ - if (mine || !config->ax25_for_me) - { - if (!mine && ndigi == 0 && config->ax25_add_default) - { - ndigi = config->ax25_default_path.fsa_ax25.sax25_ndigis; + if (mine || !config->ax25_for_me) { + if (!mine && ndigi == 0 && config->ax25_add_default) { + ndigi = + config->ax25_default_path.fsa_ax25. + sax25_ndigis; for (kdigi = 0; kdigi < ndigi; kdigi++) - if (!memcmp(&srccall, &config->ax25_default_path.fsa_digipeater[kdigi], AXLEN)) + if (!memcmp + (&srccall, + &config->ax25_default_path. + fsa_digipeater[kdigi], AXLEN)) break; if (ndigi == kdigi) - memcpy(digipeater, config->ax25_default_path.fsa_digipeater, ndigi*AXLEN); + memcpy(digipeater, + config->ax25_default_path. + fsa_digipeater, ndigi * AXLEN); else ndigi = 0; } - ax25rt = update_ax25_route(config, &srccall, ndigi, digipeater, stamp); - + ax25rt = + update_ax25_route(config, &srccall, ndigi, digipeater, + stamp); + if (ax25rt != NULL) set_ax25_route(config, ax25rt); } @@ -548,39 +539,38 @@ void ax25_receive(int sock) /* * Now see if it carries IP traffic */ - - switch(pid) - { - case PID_ARP: - SKIP(1); - if (size > 0) - ip = get_from_arp(data, size); - break; - case PID_IP: - if (!mine) - return; - SKIP(1); - if (size > 0) - ip = get_from_ip(data, size); - break; - default: + switch (pid) { + case PID_ARP: + SKIP(1); + if (size > 0) + ip = get_from_arp(data, size); + break; + case PID_IP: + if (!mine) return; + + SKIP(1); + if (size > 0) + ip = get_from_ip(data, size); + break; + default: + return; } - + /* * And adjust routes/arp/ipmode if we are allowed to... */ ipmode = (ctl == LAPB_I); - if (ip != 0) - { - if ((config = dev_get_config(ip_encaps_dev)) == NULL) - return; + if (ip != 0) { + if ((config = dev_get_config(ip_encaps_dev)) == NULL) + return; + + action = + update_ip_route(config, ip, ipmode, &srccall, stamp); - action = update_ip_route(config, ip, ipmode, &srccall, stamp); - if (action & NEW_ROUTE) if (set_route(config, ip)) return; @@ -588,7 +578,7 @@ void ax25_receive(int sock) if (action & NEW_ARP) if (set_arp(config, ip, &srccall)) return; - + if (action & NEW_IPMODE) if (set_ipmode(config, &srccall, ipmode)) return; |