From 5f5d1604492ae15967f9d86f41fbeeedcae0ae2b Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 8 Jul 1999 06:44:55 +0200 Subject: Import ax25-tools 0.0.3 from tarball --- netrom/Makefile.am | 17 ++++--- netrom/Makefile.in | 24 +++++----- netrom/netromd.c | 4 +- netrom/netromr.c | 136 +++++++++++++++++++++++++++++++++++++++++------------ netrom/nodesave.8 | 12 ++++- netrom/nodesave.c | 103 +++++++++++++++++++++++++++++++--------- netrom/nrattach.c | 1 + netrom/nrparms.c | 4 +- netrom/nrports | 7 --- netrom/nrports.5 | 56 ---------------------- 10 files changed, 221 insertions(+), 143 deletions(-) delete mode 100644 netrom/nrports delete mode 100644 netrom/nrports.5 (limited to 'netrom') diff --git a/netrom/Makefile.am b/netrom/Makefile.am index c5845b8..0678996 100644 --- a/netrom/Makefile.am +++ b/netrom/Makefile.am @@ -1,12 +1,11 @@ -etcfiles = nrbroadcast nrports -etcdir = $(sysconfdir)/ax25 +etcfiles = nrbroadcast installconf: - $(mkinstalldirs) $(DESTDIR)$(etcdir) + $(mkinstalldirs) $(DESTDIR)$(AX25_SYSCONFDIR) @list='$(etcfiles)'; for p in $$list; do \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(etcdir)/$$p"; \ - $(INSTALL_DATA) $$p $(DESTDIR)$(etcdir)/$$p; \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(AX25_SYSCONFDIR)/$$p"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(AX25_SYSCONFDIR)/$$p; \ done @@ -14,7 +13,7 @@ sbin_PROGRAMS = netromd nodesave nrattach nrparms nrsdrv LDADD = $(AX25_LIB) -man_MANS = netrom.4 nrports.5 nrbroadcast.5 netromd.8 nodesave.8 \ +man_MANS = netrom.4 nrbroadcast.5 netromd.8 nodesave.8 \ nrattach.8 nrparms.8 nrsdrv.8 EXTRA_DIST = $(man_MANS) $(etcfiles) @@ -26,3 +25,9 @@ netromd_SOURCES = \ netromt.c +INCLUDES = -DAX25_SYSCONFDIR=\""$(AX25_SYSCONFDIR)"\" \ + -DAX25_LOCALSTATEDIR=\""$(AX25_LOCALSTATEDIR)"\" + +AX25_SYSCONFDIR=${sysconfdir}/ax25/ +AX25_LOCALSTATEDIR=${localstatedir}/ax25/ + diff --git a/netrom/Makefile.in b/netrom/Makefile.in index 810c407..e909d4e 100644 --- a/netrom/Makefile.in +++ b/netrom/Makefile.in @@ -68,20 +68,25 @@ UTIL_LIB = @UTIL_LIB@ VERSION = @VERSION@ Z_LIB = @Z_LIB@ -etcfiles = nrbroadcast nrports -etcdir = $(sysconfdir)/ax25 +etcfiles = nrbroadcast sbin_PROGRAMS = netromd nodesave nrattach nrparms nrsdrv LDADD = $(AX25_LIB) -man_MANS = netrom.4 nrports.5 nrbroadcast.5 netromd.8 nodesave.8 nrattach.8 nrparms.8 nrsdrv.8 +man_MANS = netrom.4 nrbroadcast.5 netromd.8 nodesave.8 nrattach.8 nrparms.8 nrsdrv.8 EXTRA_DIST = $(man_MANS) $(etcfiles) netromd_SOURCES = netromd.c netromd.h netromr.c netromt.c + +INCLUDES = -DAX25_SYSCONFDIR=\""$(AX25_SYSCONFDIR)"\" -DAX25_LOCALSTATEDIR=\""$(AX25_LOCALSTATEDIR)"\" + + +AX25_SYSCONFDIR = ${sysconfdir}/ax25/ +AX25_LOCALSTATEDIR = ${localstatedir}/ax25/ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -364,13 +369,6 @@ distdir: $(DISTFILES) || cp -p $$d/$$file $(distdir)/$$file || :; \ fi; \ done -netromd.o: netromd.c ../config.h ../pathnames.h netromd.h -netromr.o: netromr.c ../config.h ../pathnames.h netromd.h -netromt.o: netromt.c ../config.h ../pathnames.h netromd.h -nodesave.o: nodesave.c ../config.h -nrattach.o: nrattach.c ../config.h ../pathnames.h -nrparms.o: nrparms.c ../config.h -nrsdrv.o: nrsdrv.c ../config.h ../pathnames.h info-am: info: info-am @@ -447,10 +445,10 @@ mostlyclean distclean maintainer-clean installconf: - $(mkinstalldirs) $(DESTDIR)$(etcdir) + $(mkinstalldirs) $(DESTDIR)$(AX25_SYSCONFDIR) @list='$(etcfiles)'; for p in $$list; do \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(etcdir)/$$p"; \ - $(INSTALL_DATA) $$p $(DESTDIR)$(etcdir)/$$p; \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(AX25_SYSCONFDIR)/$$p"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(AX25_SYSCONFDIR)/$$p; \ done # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/netrom/netromd.c b/netrom/netromd.c index 5fab52d..15fc0e4 100644 --- a/netrom/netromd.c +++ b/netrom/netromd.c @@ -44,8 +44,8 @@ struct port_struct port_list[20]; int port_count = FALSE; int compliant = FALSE; -int debug = FALSE; int logging = FALSE; +int debug = 0; ax25_address my_call; ax25_address node_call; @@ -147,7 +147,7 @@ int main(int argc, char **argv) compliant = TRUE; break; case 'd': - debug = TRUE; + debug++; break; case 'i': timelast = 0; diff --git a/netrom/netromr.c b/netrom/netromr.c index 90e775a..3ba7c33 100644 --- a/netrom/netromr.c +++ b/netrom/netromr.c @@ -1,7 +1,8 @@ #include #include -#include #include +#include +#include #include #include @@ -37,6 +38,28 @@ extern int compliant; +static int validcallsign(ax25_address *a) +{ + char c; + int n, end = 0; + + for (n = 0; n < 6; n++) { + c = (a->ax25_call[n] >> 1) & 0x7F; + + if (!end && (isupper(c) || isdigit(c))) + continue; + + if (c == ' ') { + end = 1; + continue; + } + + return FALSE; + } + + return TRUE; +} + static int validmnemonic(char *mnemonic) { if (compliant) { @@ -50,6 +73,73 @@ static int validmnemonic(char *mnemonic) return FALSE; } +static int add_node(int s, unsigned char *buffer, struct nr_route_struct *nr_node, int quality, int index) +{ + ax25_address best_neighbour; + int best_quality; + char *p; + + memcpy(&nr_node->callsign, buffer + 0, CALLSIGN_LEN); + memcpy(nr_node->mnemonic, buffer + 7, MNEMONIC_LEN); + memcpy(&best_neighbour, buffer + 13, CALLSIGN_LEN); + + best_quality = buffer[20]; + + nr_node->mnemonic[MNEMONIC_LEN] = '\0'; + if ((p = strchr(nr_node->mnemonic, ' ')) != NULL) + *p = '\0'; + + if (!validcallsign(&nr_node->callsign)) { + if (debug && logging) + syslog(LOG_DEBUG, "netromr: add_node: invalid node callsign - %s", ax25_ntoa(&nr_node->callsign)); + return -1; + } + + if (!validmnemonic(nr_node->mnemonic)) { + if (debug && logging) + syslog(LOG_DEBUG, "netromr: add_node: invalid mnemonic - %s", nr_node->mnemonic); + return -1; + } + + if (!validcallsign(&best_neighbour)) { + if (debug && logging) + syslog(LOG_DEBUG, "netromr: add_node: invalid best neighbour callsign - %s", &best_neighbour); + return -1; + } + + if (ax25_cmp(&my_call, &best_neighbour) == 0) { + if (debug && logging) + syslog(LOG_DEBUG, "netromr: add_node: route to me"); + return FALSE; + } + + if (best_quality < port_list[index].worst_qual) { + if (debug && logging) + syslog(LOG_DEBUG, "netromr: add_node: quality less than worst_qual"); + return FALSE; + } + + nr_node->quality = ((quality * best_quality) + 128) / 256; + + /* log this only when logging verbosely */ + if (debug > 1 && logging) { + syslog(LOG_DEBUG, "Node update: %s:%s", + ax25_ntoa(&nr_node->callsign), nr_node->mnemonic); + syslog(LOG_DEBUG, "Neighbour: %s device: %s", + ax25_ntoa(&nr_node->neighbour), nr_node->device); + syslog(LOG_DEBUG, "Quality: %d obs: %d ndigis: %d", + nr_node->quality, nr_node->obs_count, nr_node->ndigis); + } + + if (ioctl(s, SIOCADDRT, nr_node) == -1) { + if (logging) + syslog(LOG_ERR, "netromr: SIOCADDRT: %m"); + return -1; + } + + return TRUE; +} + void receive_nodes(unsigned char *buffer, int length, ax25_address *neighbour, int index) { struct nr_route_struct nr_node; @@ -59,8 +149,14 @@ void receive_nodes(unsigned char *buffer, int length, ax25_address *neighbour, i int quality, obs_count, qual, lock; char *addr, *callsign, *device; + if (!validcallsign(neighbour)) { + if (debug && logging) + syslog(LOG_DEBUG, "rejecting frame, invalid neighbour callsign - %s\n", ax25_ntoa(neighbour)); + return; + } + nr_node.type = NETROM_NODE; - /*nr_node.ndigis = 0;*/ + nr_node.ndigis = 0; sprintf(neigh_buffer, "%s/obsolescence_count_initialiser", PROC_NR_SYSCTL_DIR); @@ -140,35 +236,13 @@ void receive_nodes(unsigned char *buffer, int length, ax25_address *neighbour, i length -= MNEMONIC_LEN; while (length >= ROUTE_LEN) { - /* - * Ensure that a) the route is not via me, and - * b) it is better than my minimum acceptable quality - */ - if (ax25_cmp(&my_call, (ax25_address *)(buffer + 13)) != 0 && - buffer[20] > port_list[index].worst_qual) { - memcpy(&nr_node.callsign, buffer + 0, CALLSIGN_LEN); - memcpy(nr_node.mnemonic, buffer + 7, MNEMONIC_LEN); - nr_node.mnemonic[MNEMONIC_LEN] = '\0'; - - if ((p = strchr(nr_node.mnemonic, ' ')) != NULL) - *p = '\0'; - - if (!validmnemonic(nr_node.mnemonic)) { - if (debug && logging) - syslog(LOG_DEBUG, "rejecting route, invalid mnemonic - %s\n", nr_node.mnemonic); - } else { - nr_node.neighbour = *neighbour; - strcpy(nr_node.device, port_list[index].device); - nr_node.quality = ((quality * buffer[20]) + 128) / 256; - nr_node.obs_count = obs_count; - - if (ioctl(s, SIOCADDRT, &nr_node) == -1) { - if (logging) - syslog(LOG_ERR, "netromr: SIOCADDRT: %m"); - close(s); - return; - } - } + nr_node.neighbour = *neighbour; + strcpy(nr_node.device, port_list[index].device); + nr_node.obs_count = obs_count; + + if (add_node(s, buffer, &nr_node, quality, index) == -1) { + close(s); + return; } buffer += ROUTE_LEN; diff --git a/netrom/nodesave.8 b/netrom/nodesave.8 index 626778b..a1339ac 100644 --- a/netrom/nodesave.8 +++ b/netrom/nodesave.8 @@ -1,8 +1,8 @@ -.TH NODESAVE 8 "21 May 1996" Linux "Linux System Managers Manual" +.TH NODESAVE 8 "4 July 1999" Linux "Linux System Managers Manual" .SH NAME nodesave \- Saves NET/ROM routing information .SH SYNOPSIS -.B nodesave [filename] +.B nodesave [-p path] [-v] [filename] .SH DESCRIPTION .LP .B Nodesave @@ -16,6 +16,14 @@ Typically .B nodesave would be used when taking a system off-air so that the NET/ROM routing may be quickly restored when the system is brought back on-line. +.SH OPTIONS +.TP 10 +.BI "\-p path" +Set the path to the nrparms binary. This only affects the output of the +program. Default is /usr/sbin. +.TP 10 +.BI "\-v" +Display the version. .SH FILES .nf /proc/net/nr_neigh diff --git a/netrom/nodesave.c b/netrom/nodesave.c index a677422..7737fff 100644 --- a/netrom/nodesave.c +++ b/netrom/nodesave.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include @@ -15,23 +17,55 @@ #endif #include +#include #include +static char *Nrparms = "/usr/sbin/nrparms"; +static char *Usage = "Usage: nodesave [-p ] [-v] []\n"; + int main(int argc, char **argv) { FILE *fp = stdout; struct proc_nr_nodes *nodes, *nop; struct proc_nr_neigh *neighs, *nep; + char buf[256]; + int s; if (ax25_config_load_ports() == 0) { fprintf(stderr, "nodesave: no AX.25 port data configured\n"); return 1; } - if (argc > 1) { - if ((fp = fopen(argv[1], "w")) == NULL) { - fprintf(stderr, "nodesave: cannot open file %s\n", argv[1]); + if (nr_config_load_ports() == 0) { + fprintf(stderr, "nodesave: no NET/ROM port data configured\n"); + return 1; + } + + while ((s = getopt(argc, argv, "p:v")) != -1) { + switch (s) { + case 'p': + sprintf(buf, "%s/nrparms", optarg); + Nrparms = strdup(buf); + break; + case 'v': + printf("nodesave: %s\n", VERSION); + return 0; + case ':': + case '?': + fputs(Usage, stderr); + return 1; + } + } + + if ((argc - optind) > 1) { + fputs(Usage, stderr); + return 1; + } + + if ((argc - optind) == 1) { + if ((fp = fopen(argv[optind], "w")) == NULL) { + fprintf(stderr, "nodesave: cannot open file %s\n", argv[optind]); return 1; } } @@ -53,8 +87,10 @@ int main(int argc, char **argv) for (nep = neighs; nep != NULL; nep = nep->next) { if (nep->lock) { - fprintf(fp, "nrparms -routes \"%s\" %s + %d\n", - ax25_config_get_name(nep->dev), + fprintf(fp, "%s -routes ", Nrparms); + sprintf(buf, "\"%s\"", ax25_config_get_name(nep->dev)); + fprintf(fp, "%-8s %-9s + %d\n", + buf, nep->call, nep->qual); } @@ -63,33 +99,51 @@ int main(int argc, char **argv) fprintf(fp, "#\n# Nodes:\n#\n"); for (nop = nodes; nop != NULL; nop = nop->next) { - if ((nep = find_neigh(nop->addr1, neighs)) != NULL) { - fprintf(fp, "nrparms -nodes %s + \"%s\" %d %d \"%s\" %s\n", - nop->call, - nop->alias, + /* + * nop->n == 0 indicates a local node with no routes. + */ + if (nop->n > 0 && (nep = find_neigh(nop->addr1, neighs)) != NULL) { + fprintf(fp, "%s -nodes %-9s + ", + Nrparms, + nop->call); + sprintf(buf, "\"%s\"", nop->alias); + fprintf(fp, "%-8s %-3d %d ", + buf, nop->qual1, - nop->obs1, - ax25_config_get_name(nep->dev), + nop->obs1); + sprintf(buf, "\"%s\"", ax25_config_get_name(nep->dev)); + fprintf(fp, "%-8s %s\n", + buf, nep->call); } if (nop->n > 1 && (nep = find_neigh(nop->addr2, neighs)) != NULL) { - fprintf(fp, "nrparms -nodes %s + \"%s\" %d %d \"%s\" %s\n", - nop->call, - nop->alias, + fprintf(fp, "%s -nodes %-9s + ", + Nrparms, + nop->call); + sprintf(buf, "\"%s\"", nop->alias); + fprintf(fp, "%-8s %-3d %d ", + buf, nop->qual2, - nop->obs2, - ax25_config_get_name(nep->dev), + nop->obs2); + sprintf(buf, "\"%s\"", ax25_config_get_name(nep->dev)); + fprintf(fp, "%-8s %s\n", + buf, nep->call); } if (nop->n > 2 && (nep = find_neigh(nop->addr3, neighs)) != NULL) { - fprintf(fp, "nrparms -nodes %s + \"%s\" %d %d \"%s\" %s\n", - nop->call, - nop->alias, + fprintf(fp, "%s -nodes %-9s + ", + Nrparms, + nop->call); + sprintf(buf, "\"%s\"", nop->alias); + fprintf(fp, "%-8s %-3d %d ", + buf, nop->qual3, - nop->obs3, - ax25_config_get_name(nep->dev), + nop->obs3); + sprintf(buf, "\"%s\"", ax25_config_get_name(nep->dev)); + fprintf(fp, "%-8s %s\n", + buf, nep->call); } } @@ -99,8 +153,11 @@ int main(int argc, char **argv) fclose(fp); - if (argc > 1) { - chmod(argv[1], S_IEXEC); + if ((argc - optind) == 1) { + if (chmod(argv[optind], 0755) == -1) { + perror("nodesave: chmod"); + return 1; + } } return 0; diff --git a/netrom/nrattach.c b/netrom/nrattach.c index ecbbd56..c3a9e63 100644 --- a/netrom/nrattach.c +++ b/netrom/nrattach.c @@ -33,6 +33,7 @@ #include #endif +#include #include #include "../pathnames.h" diff --git a/netrom/nrparms.c b/netrom/nrparms.c index bc5803b..48895b9 100644 --- a/netrom/nrparms.c +++ b/netrom/nrparms.c @@ -37,7 +37,6 @@ void nodes(int s, char *nodecall, char *op, char *ident, int quality, int count, { struct nr_route_struct nr_node; char *p, *q, *dev; - int i; if (ax25_config_load_ports() == 0) { fprintf(stderr, "nrparms: nodes: no AX.25 ports configured\n"); @@ -144,7 +143,7 @@ void routes(int s, char *port, char *nodecall, char *rest[]) } nr_neigh.type = NETROM_NEIGH; - /*nr_neigh.ndigis = 0; + nr_neigh.ndigis = 0; for (i = 0; i < AX25_MAX_DIGIS && rest[i][0] != '-' && rest[i][0] != '+'; i++) { if (ax25_aton_entry(rest[i], nr_neigh.digipeaters[i].ax25_call) != 0) { @@ -154,7 +153,6 @@ void routes(int s, char *port, char *nodecall, char *rest[]) } nr_neigh.ndigis++; } - */ op = rest[i + 0]; quality = atoi(rest[i + 1]); diff --git a/netrom/nrports b/netrom/nrports deleted file mode 100644 index 4faa359..0000000 --- a/netrom/nrports +++ /dev/null @@ -1,7 +0,0 @@ -# /etc/ax25/nrports -# -# The format of this file is: -# -# name callsign alias paclen description -# -netrom OH2BNS-10 #LNODE 235 Switch Port diff --git a/netrom/nrports.5 b/netrom/nrports.5 deleted file mode 100644 index 3449113..0000000 --- a/netrom/nrports.5 +++ /dev/null @@ -1,56 +0,0 @@ -.TH NRPORTS 5 "2 August 1996" Linux "Linux Programmer's Manual" -.SH NAME -nrports \- NET/ROM port configuration file. -.SH DESCRIPTION -.LP -.B Nrports -is an ASCII file that contains information about each of the NET/ROM -ports that are to be used. When dealing with an NET/ROM utility such as -.B call, -it takes an optional argument that is the port name. This port name is a -reference to the line within -.B nrports, -which has the same name. The information on each line contains -enough information to bind the command to a particular NET/ROM -interface, this binding is done by matching the callsign on the line in -.B nrports -with the callsign of the port set by -.B ifconfig. -.LP -The -.B nrports -file may contain comments that begin with a # in the first column, or a port -description in the following format, each field being delimited by white space: -.sp -.RS -name callsign alias paclen description -.RE -.sp -The field descriptions are: -.sp -.RS -.TP 14 -.B name -this is the unique NET/ROM port identifier. -.TP 14 -.B callsign -the callsign of the NET/ROM interface to bind to. -.TP 14 -.B alias -this is the alias of the NET/ROM port. -.TP 14 -.B paclen -is the default packet size for this interface. -.TP 14 -.B description -a free format description of this interface, this field extends to the end -of the line. It may contain spaces. -.RE -.SH FILES -.LP -/etc/ax25/nrports -.SH "SEE ALSO" -.BR call (1), -.BR netrom (4), -.BR ifconfig (8), -.BR nrparms (8). -- cgit v1.2.3