summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2021-07-27 22:56:52 +0200
committerRalf Baechle <ralf@linux-mips.org>2021-07-27 23:04:51 +0200
commitdf12c34a62cac85d237043d575e0f156f5f8a596 (patch)
tree1ee265db0619d179131f868a8e2145c853cb5f0e
parent3a3c8afc8a1b98c2d992d7d58d340dc3ce4ba927 (diff)
netromd: Rewrite the code to no longer use SOCK_PACKET.
This is deprecated since a very long time. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--netrom/netromd.c38
-rw-r--r--netrom/netromd.h1
2 files changed, 24 insertions, 15 deletions
diff --git a/netrom/netromd.c b/netrom/netromd.c
index f06e8e0..1e069f1 100644
--- a/netrom/netromd.c
+++ b/netrom/netromd.c
@@ -15,6 +15,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netpacket/packet.h>
#include <net/if.h>
@@ -36,7 +37,7 @@ struct port_struct port_list[20];
int port_count = FALSE;
int compliant = FALSE;
int logging = FALSE;
-int debug;
+int sock, debug;
ax25_address my_call;
ax25_address node_call;
@@ -54,6 +55,7 @@ static void terminate(int sig)
static int bcast_config_load_ports(void)
{
char buffer[255], port[32], *s;
+ struct ifreq ifr;
FILE *fp;
fp = fopen(CONF_NETROMD_FILE, "r");
@@ -88,6 +90,13 @@ static int bcast_config_load_ports(void)
port_list[port_count].port = strdup(port);
port_list[port_count].device = strdup(ax25_config_get_dev(port_list[port_count].port));
+ strncpy(ifr.ifr_name, port_list[port_count].device, sizeof(ifr.ifr_name));
+ if (ioctl(sock, SIOCGIFINDEX, &ifr)) {
+ fprintf(stderr, "netromd: SIOCGIFINDEX failed for device %s.\n", port_list[port_count].device);
+ return -1;
+ }
+ port_list[port_count].index = ifr.ifr_ifindex;
+
if (port_list[port_count].minimum_obs < 0 || port_list[port_count].minimum_obs > 6) {
fprintf(stderr, "netromd: invalid minimum obsolescence\n");
return -1;
@@ -122,8 +131,8 @@ static int bcast_config_load_ports(void)
int main(int argc, char **argv)
{
unsigned char buffer[512];
- int size, s, i;
- struct sockaddr sa;
+ int size, i;
+ struct sockaddr_ll sa;
socklen_t asize;
struct timeval timeout;
time_t timenow, timelast;
@@ -181,6 +190,12 @@ int main(int argc, char **argv)
signal(SIGTERM, terminate);
+ sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_AX25));
+ if (sock == -1) {
+ perror("netromd: socket");
+ return 1;
+ }
+
if (ax25_config_load_ports() == 0) {
fprintf(stderr, "netromd: no AX.25 ports defined\n");
return 1;
@@ -199,12 +214,6 @@ int main(int argc, char **argv)
ax25_aton_entry(nr_config_get_addr(NULL), (char *)&my_call);
ax25_aton_entry("NODES", (char *)&node_call);
- s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_AX25));
- if (s == -1) {
- perror("netromd: socket");
- return 1;
- }
-
if (!daemon_start(TRUE)) {
fprintf(stderr, "netromd: cannot become a daemon\n");
return 1;
@@ -217,19 +226,18 @@ int main(int argc, char **argv)
for (;;) {
FD_ZERO(&fdset);
- FD_SET(s, &fdset);
+ FD_SET(sock, &fdset);
timeout.tv_sec = 30;
timeout.tv_usec = 0;
- if (select(s + 1, &fdset, NULL, NULL, &timeout) == -1)
+ if (select(sock + 1, &fdset, NULL, NULL, &timeout) == -1)
continue; /* Signal received ? */
- if (FD_ISSET(s, &fdset)) {
+ if (FD_ISSET(sock, &fdset)) {
asize = sizeof(sa);
- size = recvfrom(s, buffer, sizeof(buffer), 0, &sa,
- &asize);
+ size = recvfrom(sock, buffer, sizeof(buffer), 0, (struct sockaddr *) &sa, &asize);
if (size == -1) {
if (logging) {
syslog(LOG_ERR, "recvfrom: %m");
@@ -242,7 +250,7 @@ int main(int argc, char **argv)
ax25_cmp((ax25_address *)(buffer + 8), &my_call) != 0 &&
buffer[16] == NETROM_PID && buffer[17] == NODES_SIG) {
for (i = 0; i < port_count; i++) {
- if (strcmp(port_list[i].device, sa.sa_data) == 0) {
+ if (port_list[i].index == sa.sll_ifindex) {
if (debug && logging)
syslog(LOG_DEBUG, "receiving NODES broadcast on port %s from %s\n", port_list[i].port, ax25_ntoa((ax25_address *)(buffer + 8)));
receive_nodes(buffer + 18, size - 18, (ax25_address *)(buffer + 8), i);
diff --git a/netrom/netromd.h b/netrom/netromd.h
index 61220d2..c0fc1f4 100644
--- a/netrom/netromd.h
+++ b/netrom/netromd.h
@@ -19,6 +19,7 @@
struct port_struct {
char *device;
char *port;
+ int index;
int minimum_obs;
int default_qual;
int worst_qual;