dual stack linking

pull/14/head
Tom Early 6 years ago
parent fdedb6f1df
commit 29ca01c683

@ -53,3 +53,10 @@ void CKRBase::SigHandler(int sig)
break; break;
} }
} }
void CKRBase::AddFDSet(int &max, int newfd, fd_set *set)
{
if (newfd > max)
max = newfd;
FD_SET(newfd, set);
}

@ -20,6 +20,7 @@
// base class for all modems // base class for all modems
#include <sys/select.h>
#include <atomic> #include <atomic>
class CKRBase class CKRBase
@ -31,4 +32,5 @@ public:
protected: protected:
static std::atomic<bool> keep_running; static std::atomic<bool> keep_running;
static void SigHandler(int sig); static void SigHandler(int sig);
void AddFDSet(int &max, int newfd, fd_set *set);
}; };

@ -52,7 +52,7 @@ modem : qnmodem
qngateway : QnetGateway.o KRBase.o aprs.o UnixDgramSocket.o UnixPacketSock.o TCPReaderWriterClient.o QnetConfigure.o QnetDB.o CacheManager.o DStarDecode.o $(IRCOBJS) qngateway : QnetGateway.o KRBase.o aprs.o UnixDgramSocket.o UnixPacketSock.o TCPReaderWriterClient.o QnetConfigure.o QnetDB.o CacheManager.o DStarDecode.o $(IRCOBJS)
g++ -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread g++ -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread
qnlink : QnetLink.o KRBase.o DPlusAuthenticator.o TCPReaderWriterClient.o UnixPacketSock.o QnetConfigure.o QnetDB.o qnlink : QnetLink.o KRBase.o DPlusAuthenticator.o TCPReaderWriterClient.o UnixPacketSock.o UDPSocket.o QnetConfigure.o QnetDB.o
g++ -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread g++ -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread
qnrelay : QnetRelay.o KRBase.o UnixPacketSock.o QnetConfigure.o qnrelay : QnetRelay.o KRBase.o UnixPacketSock.o QnetConfigure.o

@ -1798,13 +1798,6 @@ void CQnetGateway::ProcessModem(const ssize_t recvlen, SDSVT &dsvt)
} }
} }
void CQnetGateway::AddFDSet(int &max, int newfd, fd_set *set)
{
if (newfd > max)
max = newfd;
FD_SET(newfd, set);
}
/* run the main loop for QnetGateway */ /* run the main loop for QnetGateway */
void CQnetGateway::Process() void CQnetGateway::Process()
{ {

@ -167,7 +167,6 @@ private:
unsigned int dtmf_counter[3]; unsigned int dtmf_counter[3];
bool VoicePacketIsSync(const unsigned char *text); bool VoicePacketIsSync(const unsigned char *text);
void AddFDSet(int &max, int newfd, fd_set *set);
int open_port(const SPORTIP *pip, int family); int open_port(const SPORTIP *pip, int family);
void calcPFCS(unsigned char *packet, int len); void calcPFCS(unsigned char *packet, int len);
void GetIRCDataThread(const int i); void GetIRCDataThread(const int i);

File diff suppressed because it is too large Load Diff

@ -29,7 +29,8 @@
#include "SEcho.h" #include "SEcho.h"
#include "Random.h" #include "Random.h"
#include "UnixPacketSock.h" #include "UnixPacketSock.h"
#include "SockAddress.h" #include "UDPSocket.h"
#include "UDPSocket.h"
#include "Timer.h" #include "Timer.h"
#include "QnetDB.h" #include "QnetDB.h"
#include "KRBase.h" #include "KRBase.h"
@ -98,11 +99,17 @@ private:
void PlayAudioNotifyThread(char *msg); void PlayAudioNotifyThread(char *msg);
void AudioNotifyThread(SECHO &edata); void AudioNotifyThread(SECHO &edata);
void RptrAckThread(char *arg); void RptrAckThread(char *arg);
void ProcessXRF(unsigned char *buf, const int length);
void ProcessDCS(unsigned char *buf, const int length);
void ProcessREF(unsigned char *buf, const int length);
void REFWrite(const void *buf, const size_t size, const CSockAddress &addr);
void DCSWrite(const void *buf, const size_t size, const CSockAddress &addr);
void XRFWrite(const void *buf, const size_t size, const CSockAddress &addr);
/* configuration data */ /* configuration data */
std::string login_call, owner, to_g2_external_ip, my_g2_link_ip, gwys, qnvoice_file, announce_dir; std::string login_call, owner, to_g2_external_ip, gwys, qnvoice_file, announce_dir;
bool only_admin_login, only_link_unlink, qso_details, log_debug, bool_rptr_ack, announce; bool only_admin_login, only_link_unlink, qso_details, log_debug, bool_rptr_ack, announce;
bool dplus_authorize, dplus_reflectors, dplus_repeaters, dplus_priority; bool dplus_authorize, dplus_reflectors, dplus_repeaters, dplus_priority, uses_ipv6;
unsigned short rmt_xrf_port, rmt_ref_port, rmt_dcs_port, my_g2_link_port, to_g2_external_port; unsigned short rmt_xrf_port, rmt_ref_port, rmt_dcs_port, my_g2_link_port, to_g2_external_port;
int delay_between, delay_before; int delay_between, delay_before;
std::string link_at_startup[3]; std::string link_at_startup[3];
@ -140,17 +147,14 @@ private:
STRACING tracing[3]; STRACING tracing[3];
// input from remote // input from remote
int xrf_g2_sock, ref_g2_sock, dcs_g2_sock; //int xrf_g2_sock, ref_g2_sock, dcs_g2_sock;
CUDPSocket XRFSock4, XRFSock6, DCSSock4, DCSSock6, REFSock4, REFSock6;
CSockAddress fromDst4; CSockAddress fromDst4;
// unix sockets to gateway // unix sockets to gateway
std::string togate; std::string togate;
CUnixPacketClient ToGate; CUnixPacketClient ToGate;
// input from our own local repeater
struct sockaddr_in fromRptr;
fd_set fdset;
struct timeval tv; struct timeval tv;
// Used to validate incoming donglers // Used to validate incoming donglers
@ -175,4 +179,35 @@ private:
CRandom Random; CRandom Random;
CQnetDB qnDB; CQnetDB qnDB;
std::vector<unsigned long> speak; std::vector<unsigned long> speak;
// used for processing loop
time_t tnow;
unsigned char dcs_seq[3] = { 0x00, 0x00, 0x00 };
struct {
char mycall[9];
char sfx[5];
unsigned int dcs_rptr_seq;
} rptr_2_dcs[3] = {
{" ", " ", 0},
{" ", " ", 0},
{" ", " ", 0}
};
struct {
char mycall[9];
char sfx[5];
unsigned int dcs_rptr_seq;
} ref_2_dcs[3] = {
{" ", " ", 0},
{" ", " ", 0},
{" ", " ", 0}
};
struct {
char mycall[9];
char sfx[5];
unsigned int dcs_rptr_seq;
} xrf_2_dcs[3] = {
{" ", " ", 0},
{" ", " ", 0},
{" ", " ", 0}
};
}; };

@ -145,7 +145,7 @@ public:
} }
} }
const char *GetAddress() const char *GetAddress() const
{ {
if (straddr[0]) if (straddr[0])
return straddr; return straddr;
@ -214,7 +214,22 @@ public:
memset(straddr, 0, INET6_ADDRSTRLEN); memset(straddr, 0, INET6_ADDRSTRLEN);
} }
operator const char *() const { return GetAddress(); }
friend std::ostream &operator<<(std::ostream &stream, const CSockAddress &addr)
{
const char *sz = addr;
if (AF_INET6 == addr.GetFamily())
stream << "[" << sz << "]";
else
stream << sz;
auto port = addr.GetPort();
if (port)
stream << ":" << port;
return stream;
}
private: private:
struct sockaddr_storage addr; struct sockaddr_storage addr;
char straddr[INET6_ADDRSTRLEN]; mutable char straddr[INET6_ADDRSTRLEN];
}; };

@ -0,0 +1,112 @@
//
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
//
// xlxd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// xlxd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include "UDPSocket.h"
////////////////////////////////////////////////////////////////////////////////////////
// constructor
CUDPSocket::CUDPSocket() : m_fd(-1) {}
////////////////////////////////////////////////////////////////////////////////////////
// destructor
CUDPSocket::~CUDPSocket()
{
Close();
}
////////////////////////////////////////////////////////////////////////////////////////
// open & close
bool CUDPSocket::Open(const CSockAddress &addr)
{
// create socket
m_fd = socket(addr.GetFamily(), SOCK_DGRAM, 0);
if (0 > m_fd) {
std::cerr << "Cannot create socket on " << addr << ", " << strerror(errno) << std::endl;
return true;
}
if (0 > fcntl(m_fd, F_SETFL, O_NONBLOCK)) {
std::cerr << "cannot set socket " << addr << " to non-blocking: " << strerror(errno) << std::endl;
close(m_fd);
m_fd = -1;
return true;
}
const int reuse = 1;
if (0 > setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int))) {
std::cerr << "Cannot set the UDP socket option on " << m_addr << ", err: " << strerror(errno) << std::endl;
close(m_fd);
m_fd = -1;
return true;
}
// initialize sockaddr struct
m_addr = addr;
if (0 != bind(m_fd, m_addr.GetCPointer(), m_addr.GetSize())) {
std::cerr << "bind failed on " << m_addr << ", " << strerror(errno) << std::endl;
close(m_fd);
m_fd = -1;
return true;
}
return false;
}
void CUDPSocket::Close(void)
{
if ( m_fd >= 0 ) {
close(m_fd);
m_fd = -1;
}
}
////////////////////////////////////////////////////////////////////////////////////////
// read
size_t CUDPSocket::Read(unsigned char *buf, const size_t size, CSockAddress &Ip)
{
if ( 0 > m_fd )
return 0;
unsigned int len = sizeof(struct sockaddr_storage);
auto rval = recvfrom(m_fd, buf, size, 0, Ip.GetPointer(), &len);
if (0 > rval)
std::cerr << "Receive error on port " << m_addr << ": " << strerror(errno) << std::endl;
return rval;
}
void CUDPSocket::Write(const void *Buffer, const size_t size, const CSockAddress &Ip) const
{
sendto(m_fd, Buffer, size, 0, Ip.GetCPointer(), Ip.GetSize());
}

@ -0,0 +1,50 @@
#pragma once
//
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
//
// xlxd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// xlxd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#include "SockAddress.h"
#define UDP_BUFFER_LENMAX 1024
class CUDPSocket
{
public:
// constructor
CUDPSocket();
// destructor
~CUDPSocket();
// open & close
bool Open(const CSockAddress &addr);
void Close(void);
int GetSocket(void) const { return m_fd; }
unsigned short GetPort() const { return m_addr.GetPort(); }
// read
size_t Read(unsigned char *buf, const size_t size, CSockAddress &addr);
// write
void Write(const void *buf, const size_t size, const CSockAddress &addr) const;
protected:
// data
int m_fd;
CSockAddress m_addr;
};
Loading…
Cancel
Save

Powered by TurnKey Linux.