mirror of
https://github.com/markqvist/tncattach.git
synced 2024-09-27 07:36:42 -04:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bb4b1917d5 | ||
|
54b4ae14f8 | ||
|
d9b3d2b6ae | ||
|
bb9ff10158 | ||
|
5129dda626 | ||
|
b4a80a1e7a | ||
|
8944821ba8 | ||
|
ef700b3244 | ||
|
015f8a73fb | ||
|
5bdc5d5ccc | ||
|
de83bc9f21 | ||
|
671ea5dda0 | ||
|
07eeed45f5 | ||
|
c2beeee944 | ||
|
eae91f349b | ||
|
b996f38689 | ||
|
d3ff2f207a | ||
|
26f1e48b19 | ||
|
5c8ddcd992 | ||
|
dada2f3775 | ||
|
41086b2e0c | ||
|
1c7b30b995 | ||
|
30207d6691 | ||
|
b438e5fb5a | ||
|
e7a831b41d |
@ -7,3 +7,9 @@
|
||||
#define MTU_MIN 74
|
||||
#define MTU_MAX 1522
|
||||
#define MTU_DEFAULT 329
|
||||
|
||||
#define TXQUEUELEN 10
|
||||
|
||||
// ARP timings, in seconds
|
||||
#define ARP_BASE_REACHABLE_TIME 300
|
||||
#define ARP_RETRANS_TIME 5
|
28
README.md
28
README.md
@ -6,7 +6,7 @@ Attach KISS TNC devices as network interfaces in Linux. This program allows you
|
||||
|
||||
Currently it is recommended to compile and install __tncattach__ from source with the below commands.
|
||||
|
||||
If that is not possible for you, precompiled __amd64__ and __armhf__ (Raspberry Pi and similar) binaries have been provided in the releases section. You can [download the latest release here](https://github.com/markqvist/tncattach/releases/tag/0.1.3).
|
||||
If that is not possible for you, precompiled __amd64__ and __armhf__ (Raspberry Pi and similar) binaries have been provided in the releases section. You can [download the latest release here](https://github.com/markqvist/tncattach/releases).
|
||||
|
||||
```sh
|
||||
# If you don't already have a compiler installed
|
||||
@ -34,14 +34,17 @@ Usage: tncattach [OPTION...] port baudrate
|
||||
|
||||
Attach TNC devices as system network interfaces
|
||||
|
||||
-d, --daemon Run tncattach as a daemon
|
||||
-m, --mtu=MTU Specify interface MTU
|
||||
-e, --ethernet Create a full ethernet device
|
||||
-i, --ipv4=IP_ADDRESS Configure an IPv4 address on interface
|
||||
-m, --mtu=MTU Specify interface MTU
|
||||
-n, --noipv6 Filter IPv6 traffic from reaching TNC
|
||||
--noup Only create interface, don't bring it up
|
||||
-s, --id=CALLSIGN Station identification data
|
||||
-T, --kisstcp Use KISS over TCP instead of serial port
|
||||
-H, --tcphost=TCP_HOST Host to connect to when using KISS over TCP
|
||||
-P, --tcpport=TCP_PORT TCP port when using KISS over TCP
|
||||
-t, --interval=SECONDS Maximum interval between station identifications
|
||||
-s, --id=CALLSIGN Station identification data
|
||||
-d, --daemon Run tncattach as a daemon
|
||||
-v, --verbose Enable verbose output
|
||||
-?, --help Give this help list
|
||||
--usage Give a short usage message
|
||||
@ -50,6 +53,8 @@ Attach TNC devices as system network interfaces
|
||||
|
||||
The program supports attaching TNCs as point-to-point tunnel devices, or generic ethernet devices. The ethernet mode is suitable for point-to-multipoint setups, and can be enabled with the corresponding command line switch. If you only need point-to-point links, it is advisable to just use the standard point-to-point mode, since it doesn't incur the ethernet header overhead on each packet.
|
||||
|
||||
If you want to connect to a virtual KISS TNC over a TCP connection, you can use the -T option, along with the -H and -P options to specify the host and port.
|
||||
|
||||
Additionally, it is worth noting that __tncattach__ can filter out IPv6 packets from reaching the TNC. Most operating systems attempts to autoconfigure IPv6 when an interface is brought up, which results in a substantial amount of IPv6 traffic generated by router solicitations and similar, which is usually unwanted for packet radio links and similar.
|
||||
|
||||
If you intend to use __tncattach__ on a system with mDNS services enabled (avahi-daemon, for example), you may want to consider modifying your mDNS setup to exclude TNC interfaces, or turning it off entirely, since it will generate a lot of traffic that might be unwanted.
|
||||
@ -75,6 +80,13 @@ Create an ethernet device with a USB-connected TNC, set the MTU, filter IPv6 tra
|
||||
sudo tncattach /dev/ttyUSB0 115200 --ethernet --mtu 576 --noipv6 --ipv4 10.92.0.10/24
|
||||
```
|
||||
|
||||
Create an ethernet device with a TCP-connected TNC, set the MTU, filter IPv6 traffic, and set an IPv4 address:
|
||||
|
||||
```sh
|
||||
# Attach interface
|
||||
sudo tncattach -T -H localhost -P 8001 --ethernet --mtu 576 --noipv6 --ipv4 10.92.0.10/24
|
||||
```
|
||||
|
||||
You can interact with the interface like any other using the __ip__ or __ifconfig__ utilities:
|
||||
|
||||
```sh
|
||||
@ -111,6 +123,7 @@ tnc0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 400
|
||||
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
||||
|
||||
```
|
||||
|
||||
## Worth Knowing on Raspbian
|
||||
|
||||
On some versions of Raspbian (and probably other operating systems), the DHCP client daemon _dhcpcd_ interferes with TNC interfaces, by overriding their MTU and trying to auto-configure link-local addresses. You probably don't want this, and it can be disabled by editing the __/etc/dhcpcd.conf__ file, adding a statement telling _dhcpcd_ to ignore your TNC interface:
|
||||
@ -121,3 +134,10 @@ On some versions of Raspbian (and probably other operating systems), the DHCP cl
|
||||
|
||||
denyinterfaces tnc0
|
||||
```
|
||||
|
||||
## Support tncattach development
|
||||
You can help support the continued development of open, free and private communications systems by donating via one of the following channels:
|
||||
|
||||
- Ethereum: 0x81F7B979fEa6134bA9FD5c701b3501A2e61E897a
|
||||
- Bitcoin: 3CPmacGm34qYvR6XWLVEJmi2aNe3PZqUuq
|
||||
- Ko-Fi: https://ko-fi.com/markqvist
|
||||
|
61
TAP.c
61
TAP.c
@ -46,7 +46,7 @@ int open_tap(void) {
|
||||
|
||||
int inet = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (inet == -1) {
|
||||
perror("Could not open AF_INET socket\r\n");
|
||||
perror("Could not open AF_INET socket");
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
@ -64,6 +64,65 @@ int open_tap(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Configure TX queue length
|
||||
if (ioctl(inet, SIOCGIFTXQLEN, &ifr) < 0) {
|
||||
perror("Could not get interface flags from kernel");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
ifr.ifr_qlen = TXQUEUELEN;
|
||||
if (ioctl(inet, SIOCSIFTXQLEN, &ifr) < 0) {
|
||||
perror("Could not set interface TX queue length");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Configure ARP characteristics
|
||||
char path_buf[256];
|
||||
if (device_type == IF_TAP) {
|
||||
snprintf(path_buf, sizeof(path_buf), "/proc/sys/net/ipv4/neigh/%s/base_reachable_time_ms", ifr.ifr_name);
|
||||
int arp_fd = open(path_buf, O_WRONLY);
|
||||
if (arp_fd < 0) {
|
||||
perror("Could not open proc entry for ARP parameters");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
if (dprintf(arp_fd, "%d", ARP_BASE_REACHABLE_TIME*1000) <= 0) {
|
||||
perror("Could not configure interface ARP parameter base_reachable_time_ms");
|
||||
close(inet);
|
||||
close(arp_fd);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
close(arp_fd);
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(path_buf, sizeof(path_buf), "/proc/sys/net/ipv4/neigh/%s/retrans_time_ms", ifr.ifr_name);
|
||||
arp_fd = open(path_buf, O_WRONLY);
|
||||
if (arp_fd < 0) {
|
||||
perror("Could not open proc entry for ARP parameters");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
if (dprintf(arp_fd, "%d", ARP_RETRANS_TIME*1000) <= 0) {
|
||||
perror("Could not configure interface ARP parameter retrans_time_ms");
|
||||
close(inet);
|
||||
close(arp_fd);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
close(arp_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bring up if requested
|
||||
if (!noup) {
|
||||
if (ioctl(inet, SIOCGIFFLAGS, &ifr) < 0) {
|
||||
perror("Could not get interface flags from kernel");
|
||||
|
37
TCP.c
Normal file
37
TCP.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include "TCP.h"
|
||||
|
||||
int open_tcp(char* ip, int port) {
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sockfd < 0) {
|
||||
perror("Could not open AF_INET socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct hostent *server;
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
server = gethostbyname(ip);
|
||||
|
||||
if (server == NULL) {
|
||||
perror("Error resolving host");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
|
||||
memcpy(server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length);
|
||||
serv_addr.sin_port = htons(port);
|
||||
|
||||
if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
|
||||
perror("Could not connect TCP socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
int close_tcp(int fd) {
|
||||
return close(fd);
|
||||
}
|
9
TCP.h
Normal file
9
TCP.h
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
int open_tcp(char* ip, int port);
|
||||
int close_tcp(int fd);
|
25
makefile
25
makefile
@ -1,26 +1,35 @@
|
||||
.DEFAULT_GOAL := all
|
||||
.PHONY: all clean install uninstall tncattach
|
||||
|
||||
compiler = gcc
|
||||
flags = -std=gnu11 -lm
|
||||
RM ?= rm
|
||||
INSTALL ?= install
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -std=gnu11 -static-libgcc
|
||||
LDFLAGS ?=
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
all: tncattach
|
||||
rebuild: clean all
|
||||
|
||||
clean:
|
||||
@echo "Cleaning tncattach build..."
|
||||
@rm -f tncattach
|
||||
$(RM) -f tncattach
|
||||
|
||||
tncattach:
|
||||
@echo "Making tncattach..."
|
||||
@echo "Compiling with: ${compiler}"
|
||||
${compiler} ${flags} tncattach.c Serial.c KISS.c TAP.c -o tncattach -Wall
|
||||
@echo "Compiling with: $(CC)"
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) tncattach.c Serial.c TCP.c KISS.c TAP.c -o tncattach
|
||||
|
||||
install:
|
||||
@echo "Installing tncattach..."
|
||||
chmod a+x tncattach
|
||||
cp ./tncattach /usr/local/sbin/
|
||||
$(INSTALL) -d $(DESTDIR)/$(PREFIX)/bin
|
||||
$(INSTALL) -Dm755 tncattach $(DESTDIR)/$(PREFIX)/bin/tncattach
|
||||
@echo "Installing man page..."
|
||||
gzip -9 tncattach.8
|
||||
$(INSTALL) -d $(DESTDIR)/$(PREFIX)/share/man/man8
|
||||
$(INSTALL) -Dm644 tncattach.8.gz $(DESTDIR)/$(PREFIX)/share/man/man8/tncattach.8.gz
|
||||
|
||||
uninstall:
|
||||
@echo "Uninstalling tncattach"
|
||||
rm /usr/local/sbin/tncattach
|
||||
$(RM) $(DESTDIR)/$(PREFIX)/bin/tncattach
|
||||
$(RM) $(DESTDIR)/$(PREFIX)/share/man/man8/tncattach.8.gz
|
||||
|
165
tncattach.8
Normal file
165
tncattach.8
Normal file
@ -0,0 +1,165 @@
|
||||
.TH tncattach 8 "September 12, 2020"
|
||||
|
||||
.SH NAME
|
||||
.
|
||||
.
|
||||
tncattach \- Attach TNC devices as system network interfaces
|
||||
|
||||
.SH SYNOPSIS
|
||||
.
|
||||
.
|
||||
\f[B]tncattach\f[R] [OPTION...] port baudrate
|
||||
|
||||
.SH DESCRIPTION
|
||||
Attach KISS TNC devices as network interfaces in Linux. This program allows you to attach TNCs or any KISS-compatible device as a network interface. This program does not need any kernel modules, and has no external dependencies outside the standard Linux and GNU C libraries.
|
||||
|
||||
.SH OPTIONS
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-m, \-\-mtu=MTU
|
||||
.
|
||||
Specify interface MTU
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-e, \-\-ethernet
|
||||
Create a full ethernet device
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-i, \-\-ipv4=IP_ADDRESS
|
||||
Configure an IPv4 address on interface
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-n, \-\-noipv6
|
||||
Filter IPv6 traffic from reaching TNC
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-\-noup
|
||||
Only create interface, don't bring it up
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-T, \-\-kisstcp
|
||||
Use KISS over TCP instead of serial port
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-H, \-\-tcphost=TCP_HOST
|
||||
Host to connect to when using KISS over TCP
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-P, \-\-tcpport=TCP_PORT
|
||||
TCP port when using KISS over TCP
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-t, \-\-interval=SECONDS
|
||||
Maximum interval between station identifications
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.B \-s, \-\-id=CALLSIGN
|
||||
Station identification data
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-d, \-\-daemon
|
||||
Run tncattach as a daemon
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-v, \-\-verbose
|
||||
Enable verbose output
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-?, \-\-help
|
||||
Show help
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-\-usage
|
||||
Give a short usage message
|
||||
.
|
||||
.
|
||||
.TP
|
||||
.BI \-V, \-\-version
|
||||
Print program version
|
||||
.
|
||||
.
|
||||
|
||||
.SH USAGE
|
||||
The program supports attaching TNCs as point-to-point tunnel devices, or generic ethernet devices. The ethernet mode is suitable for point-to-multipoint setups, and can be enabled with the corresponding command line switch. If you only need point-to-point links, it is advisable to just use the standard point-to-point mode, since it doesn't incur the ethernet header overhead on each packet.
|
||||
.P
|
||||
If you want to connect to a virtual KISS TNC over a TCP connection, you can use the -T option, along with the -H and -P options to specify the host and port.
|
||||
.P
|
||||
Additionally, it is worth noting that tncattach can filter out IPv6 packets from reaching the TNC. Most operating systems attempts to autoconfigure IPv6 when an interface is brought up, which results in a substantial amount of IPv6 traffic generated by router solicitations and similar, which is usually unwanted for packet radio links and similar.
|
||||
.P
|
||||
If you intend to use tncattach on a system with mDNS services enabled (avahi-daemon, for example), you may want to consider modifying your mDNS setup to exclude TNC interfaces, or turning it off entirely, since it will generate a lot of traffic that might be unwanted.
|
||||
|
||||
.SH STATION IDENTIFICATION
|
||||
|
||||
You can configure tncattach to automatically transmit station identification beacons according to a given interval, by using the --id and --interval options. Identification will be transmitted as raw data frames with whatever content has been specified in the --id option. Useful for amateur radio use, or other areas where station identification is necessary.
|
||||
.P
|
||||
Identification beacons will be transmitted when:
|
||||
.P
|
||||
.IP
|
||||
There is outgoing data to send, and the specified interval has elapsed.
|
||||
.IP
|
||||
The specified interval elapses, and data has been sent since the last ID beacon.
|
||||
.IP
|
||||
The program exits, if any data frames have been transmitted since the last ID beacon.
|
||||
.P
|
||||
The above methodology should comply with station identification rules for amateur radio in most parts of the world, and complies with US Part 97 rules.
|
||||
|
||||
.SH EXAMPLES
|
||||
.
|
||||
Create an ethernet device with a USB-connected TNC, set the MTU, filter IPv6 traffic, and set an IPv4 address:
|
||||
.IP
|
||||
sudo tncattach /dev/ttyUSB0 115200 --ethernet --mtu 576 --noipv6 --ipv4 10.92.0.10/24
|
||||
.P
|
||||
Create an ethernet device with a TCP-connected TNC, set the MTU, filter IPv6 traffic, and set an IPv4 address:
|
||||
.IP
|
||||
sudo tncattach -T -H localhost -P 8001 --ethernet --mtu 576 --noipv6 --ipv4 10.92.0.10/24
|
||||
.P
|
||||
You can interact with the interface like any other using the ip or ifconfig utilities.
|
||||
.p
|
||||
Check interface is running:
|
||||
.P
|
||||
# ifconfig
|
||||
.br
|
||||
tnc0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 400
|
||||
.br
|
||||
inet 10.93.0.1 netmask 255.255.255.255 destination 10.93.0.2
|
||||
.br
|
||||
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
|
||||
.br
|
||||
RX packets 0 bytes 0 (0.0 B)
|
||||
.br
|
||||
RX errors 0 dropped 0 overruns 0 frame 0
|
||||
.br
|
||||
TX packets 0 bytes 0 (0.0 B)
|
||||
.br
|
||||
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
||||
.P
|
||||
.SH WORTH KNOWING ON RASPBIAN
|
||||
On some versions of Raspbian (and probably other operating systems), the DHCP client daemon dhcpcd interferes with TNC interfaces, by overriding their MTU and trying to auto-configure link-local addresses. You probably don't want this, and it can be disabled by editing the /etc/dhcpcd.conf file, adding a statement telling dhcpcd to ignore your TNC interface:
|
||||
.P
|
||||
# Add the following statement somewhere at the beginning
|
||||
.br
|
||||
# of /etc/dhcpcd.conf to prevent dhcpcd from changing MTU
|
||||
.br
|
||||
denyinterfaces tnc0
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
rnodeconfigutil(8)
|
||||
|
||||
.SH AUTHOR
|
||||
|
||||
Mark Qvist
|
86
tncattach.c
86
tncattach.c
@ -9,6 +9,7 @@
|
||||
#include "Constants.h"
|
||||
#include "Serial.h"
|
||||
#include "KISS.h"
|
||||
#include "TCP.h"
|
||||
#include "TAP.h"
|
||||
|
||||
#define BAUDRATE_DEFAULT 0
|
||||
@ -34,8 +35,13 @@ bool noup = false;
|
||||
bool daemonize = false;
|
||||
bool set_ipv4 = false;
|
||||
bool set_netmask = false;
|
||||
bool kiss_over_tcp = false;
|
||||
char* ipv4_addr;
|
||||
char* netmask;
|
||||
|
||||
char* tcp_host;
|
||||
int tcp_port;
|
||||
|
||||
int mtu;
|
||||
int device_type = IF_TUN;
|
||||
|
||||
@ -45,7 +51,11 @@ time_t last_id = 0;
|
||||
bool tx_since_last_id = false;
|
||||
|
||||
void cleanup(void) {
|
||||
if (kiss_over_tcp) {
|
||||
close_tcp(attached_tnc);
|
||||
} else {
|
||||
close_port(attached_tnc);
|
||||
}
|
||||
close_tap(attached_if);
|
||||
}
|
||||
|
||||
@ -251,20 +261,23 @@ void read_loop(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const char *argp_program_version = "tncattach 0.1.6";
|
||||
const char *argp_program_version = "tncattach 0.1.9";
|
||||
const char *argp_program_bug_address = "<mark@unsigned.io>";
|
||||
static char doc[] = "\r\nAttach TNC devices as system network interfaces\vTo attach the TNC connected to /dev/ttyUSB0 as an ethernet device with an MTU of 512 bytes and assign an IPv4 address, while filtering IPv6 traffic, use:\r\n\r\n\ttncattach /dev/ttyUSB0 115200 -m 512 -e --noipv6 --ipv4 10.0.0.1/24\r\n\r\nStation identification can be performed automatically to comply with Part 97 rules. See the README for a complete description. Use the --id and --interval options, which should commonly be set to your callsign, and 600 seconds.";
|
||||
static char args_doc[] = "port baudrate";
|
||||
static struct argp_option options[] = {
|
||||
{ "mtu", 'm', "MTU", 0, "Specify interface MTU"},
|
||||
{ "daemon", 'd', 0, 0, "Run tncattach as a daemon"},
|
||||
{ "ethernet", 'e', 0, 0, "Create a full ethernet device"},
|
||||
{ "ipv4", 'i', "IP_ADDRESS", 0, "Configure an IPv4 address on interface"},
|
||||
{ "noipv6", 'n', 0, 0, "Filter IPv6 traffic from reaching TNC"},
|
||||
{ "noup", 1, 0, 0, "Only create interface, don't bring it up"},
|
||||
{ "interval", 't', "SECONDS", 0, "Maximum interval between station identifications"},
|
||||
{ "id", 's', "CALLSIGN", 0, "Station identification data"},
|
||||
{ "verbose", 'v', 0, 0, "Enable verbose output"},
|
||||
{ "mtu", 'm', "MTU", 0, "Specify interface MTU", 1},
|
||||
{ "ethernet", 'e', 0, 0, "Create a full ethernet device", 2},
|
||||
{ "ipv4", 'i', "IP_ADDRESS", 0, "Configure an IPv4 address on interface", 3},
|
||||
{ "noipv6", 'n', 0, 0, "Filter IPv6 traffic from reaching TNC", 4},
|
||||
{ "noup", 1, 0, 0, "Only create interface, don't bring it up", 5},
|
||||
{ "kisstcp", 'T', 0, 0, "Use KISS over TCP instead of serial port", 6},
|
||||
{ "tcphost", 'H', "TCP_HOST", 0, "Host to connect to when using KISS over TCP", 7},
|
||||
{ "tcpport", 'P', "TCP_PORT", 0, "TCP port when using KISS over TCP", 8},
|
||||
{ "interval", 't', "SECONDS", 0, "Maximum interval between station identifications", 9},
|
||||
{ "id", 's', "CALLSIGN", 0, "Station identification data", 10},
|
||||
{ "daemon", 'd', 0, 0, "Run tncattach as a daemon", 11},
|
||||
{ "verbose", 'v', 0, 0, "Enable verbose output", 12},
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -276,6 +289,7 @@ struct arguments {
|
||||
bool valid_id;
|
||||
int id_interval;
|
||||
int baudrate;
|
||||
int tcpport;
|
||||
int mtu;
|
||||
bool tap;
|
||||
bool daemon;
|
||||
@ -284,6 +298,9 @@ struct arguments {
|
||||
bool set_netmask;
|
||||
bool noipv6;
|
||||
bool noup;
|
||||
bool kiss_over_tcp;
|
||||
bool set_tcp_host;
|
||||
bool set_tcp_port;
|
||||
};
|
||||
|
||||
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
@ -459,6 +476,21 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
arguments->verbose = false;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
arguments->kiss_over_tcp = true;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
arguments->set_tcp_host = true;
|
||||
tcp_host = (char*)malloc(strlen(arg)+1);
|
||||
strcpy(tcp_host, arg);
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
arguments->set_tcp_port = true;
|
||||
tcp_port = atoi(arg);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
arguments->noup = true;
|
||||
break;
|
||||
@ -473,7 +505,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
|
||||
case ARGP_KEY_END:
|
||||
// Check if there's too few text arguments
|
||||
if (state->arg_num < N_ARGS) argp_usage(state);
|
||||
if (!arguments->kiss_over_tcp && state->arg_num < N_ARGS) argp_usage(state);
|
||||
|
||||
// Check if text arguments were given when
|
||||
// KISS over TCP was specified
|
||||
if (arguments->kiss_over_tcp && state->arg_num != 0) argp_usage(state);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -527,9 +564,21 @@ int main(int argc, char **argv) {
|
||||
arguments.noup = false;
|
||||
arguments.id_interval = -1;
|
||||
arguments.valid_id = false;
|
||||
arguments.kiss_over_tcp = false;
|
||||
|
||||
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
||||
|
||||
if (arguments.kiss_over_tcp) kiss_over_tcp = true;
|
||||
|
||||
if (!kiss_over_tcp) {
|
||||
arguments.baudrate = atoi(arguments.args[1]);
|
||||
} else {
|
||||
if (!(arguments.set_tcp_host && arguments.set_tcp_port)) {
|
||||
if (!arguments.set_tcp_host) printf("Error: KISS over TCP was requested, but no host was specified\r\n");
|
||||
if (!arguments.set_tcp_port) printf("Error: KISS over TCP was requested, but no port was specified\r\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.daemon) daemonize = true;
|
||||
if (arguments.verbose) verbose = true;
|
||||
@ -557,19 +606,30 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
attached_if = open_tap();
|
||||
|
||||
if (!arguments.kiss_over_tcp) {
|
||||
attached_tnc = open_port(arguments.args[0]);
|
||||
if (setup_port(attached_tnc, arguments.baudrate)) {
|
||||
if (!setup_port(attached_tnc, arguments.baudrate)) {
|
||||
printf("Error during serial port setup");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
attached_tnc = open_tcp(tcp_host, tcp_port);
|
||||
}
|
||||
|
||||
printf("TNC interface configured as %s\r\n", if_name);
|
||||
|
||||
fds[IF_FD_INDEX].fd = attached_if;
|
||||
fds[IF_FD_INDEX].events = POLLIN;
|
||||
fds[TNC_FD_INDEX].fd = attached_tnc;
|
||||
fds[TNC_FD_INDEX].events = POLLIN;
|
||||
|
||||
if (daemonize) {
|
||||
become_daemon();
|
||||
syslog(LOG_NOTICE, "tncattach daemon running");
|
||||
}
|
||||
|
||||
read_loop();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user