Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 #323

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open

IPv6 #323

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
7a4e188
Address to sockaddr
timriker Mar 1, 2023
1e03965
serverAddr now Address()
timriker Mar 1, 2023
abfe02f
astyle
timriker Mar 1, 2023
4ce4d29
ws
timriker Mar 3, 2023
1ab4db3
taddr is Address
timriker Apr 1, 2023
823de9b
uaddr is Address
timriker Apr 1, 2023
c51406a
compiles with IPv6, still running IPv4
timriker Apr 2, 2023
cecd70f
avoid more getHostByAddress
timriker Apr 2, 2023
aa103b5
avoid more getHostByAddress
timriker Apr 2, 2023
efeb817
apply timestamp early
timriker Apr 2, 2023
7c8b5f5
log address on ADD/REMOVE
timriker Apr 2, 2023
8ffcef6
logDebugMessage
timriker Apr 2, 2023
86da8d5
logDebugMessage
timriker Apr 2, 2023
b054081
tabs in logDebugMessage
timriker Apr 2, 2023
0daf196
unknown gameType
timriker Apr 2, 2023
fc62dce
\t
timriker Apr 2, 2023
cd78dd8
logDebugMessage might add timestamp. Multi calls for one line won't work
timriker Apr 2, 2023
a44ed56
shorten log
timriker Apr 2, 2023
d972407
style
timriker Apr 2, 2023
8ff1a98
work around no bundle in bzfs
timriker Apr 2, 2023
b39f9de
try serverAddr family
timriker Apr 2, 2023
5b1ffc3
save some spaces
timriker Apr 2, 2023
12cb528
disable frequent warning in bzadmin
timriker Apr 2, 2023
9dda21d
udp socket family
timriker Apr 2, 2023
53a5688
larger size
timriker Apr 2, 2023
18fa469
don't setInterface()
timriker Apr 2, 2023
0ecda1a
socket family
timriker Apr 2, 2023
0e2d4ba
response
timriker Apr 2, 2023
67c700e
response
timriker Apr 2, 2023
abbab01
use Address pack/unpack
timriker Apr 2, 2023
76fe597
larger serverping packets with v6
timriker Apr 2, 2023
3a82f83
response, nerror, socket family
timriker Apr 2, 2023
da7b4c5
log instead of assert
timriker Apr 2, 2023
14779d0
log in bzadmin, needs non-blocking, need to try other ips
timriker Apr 2, 2023
384abf7
ares_getaddrinfo
timriker Apr 3, 2023
ee6ca52
style
timriker Apr 3, 2023
4160aa4
named var
timriker Apr 3, 2023
26e965d
warn, not assert
timriker Apr 3, 2023
1bba482
remove struct
timriker Apr 3, 2023
c718c59
pack server addr
timriker Apr 3, 2023
d2d5505
show downlink local ip and port
timriker Apr 3, 2023
181ad3c
send fmt and msg if called with no bundle
timriker Apr 4, 2023
a35af5f
ws
timriker Apr 4, 2023
d2c790a
need \n on logDebugMessage()s
timriker Apr 4, 2023
adb367d
needed cmdline options
timriker Apr 4, 2023
cbe973f
add udp to bzadmin
timriker Apr 4, 2023
5812037
UDEBUG to logDebugMessage 5
timriker Apr 4, 2023
a926d43
\n on log
timriker Apr 4, 2023
8cc2e7b
\n on logDebugMessage()s
timriker Apr 4, 2023
f6d1f1f
match initial udp on ip4
timriker Apr 4, 2023
4b91f9a
still not working
timriker Apr 4, 2023
45991be
logic, can't use isMyUaddr before match
timriker Apr 5, 2023
138918c
start on masks
timriker Apr 5, 2023
2535155
just CIDR for IP
timriker Apr 5, 2023
d049626
log and continue on Address() failure
timriker Apr 5, 2023
5a06850
canonical iptextport
timriker Apr 6, 2023
b2e227b
default to IPv6
timriker Apr 6, 2023
6cc1080
style
timriker Apr 6, 2023
e4a4df4
add some cross-family address compares. use Address for validate() an…
timriker Apr 6, 2023
159b48d
\t in multiline log
timriker Apr 6, 2023
811aa6c
simplify serverlist
timriker Apr 8, 2023
b7f80af
style
timriker Apr 8, 2023
801a72b
no need for index and name if index is name
timriker Apr 8, 2023
b0e216f
lookup IPs too
timriker Apr 8, 2023
24976f7
chop off port in menu
timriker Apr 8, 2023
dbf4fbb
don't add port if default
timriker Apr 8, 2023
4fca3e9
isMapped(), contains() support for v4 in v6
timriker Apr 9, 2023
5ef3c2a
inAny() and isPrivate() for ipv6
timriker Apr 9, 2023
fce44a6
comments
timriker Apr 9, 2023
9d9bac9
IPV6_V6ONLY = false
timriker Apr 9, 2023
9ab1baa
no more getIPAddress()
timriker Apr 9, 2023
f436836
ipv6 cidr?
timriker Apr 9, 2023
1cc34fd
ipv6 cidr
timriker Apr 9, 2023
b1633e9
contains() fixes and optimizations. IPv6 cidr check tests working
timriker Apr 10, 2023
ff05318
missed log edit
timriker Apr 10, 2023
19d8bca
try on newer servers
timriker Apr 13, 2023
419f958
[v6]:port
timriker Apr 14, 2023
4faa049
size_t missed commit
timriker Apr 14, 2023
9fdf909
joinNamePort() and handle port 0
timriker Apr 14, 2023
7981b91
default port on names, show requesting before return
timriker Apr 14, 2023
acb4313
make v4inv6 look like v4
timriker Apr 15, 2023
8729d90
handle wildcard bans by converting on load
timriker Apr 15, 2023
2bb0963
bzfs man page -i updates
timriker Apr 15, 2023
bcf55ab
tone down debug
timriker Apr 15, 2023
daf4dcf
unify debug output
timriker Apr 15, 2023
1819c1e
some bcast debugging
timriker Apr 17, 2023
fb8ee7a
style
timriker Apr 17, 2023
adf03a1
Start fixing some Windows build issues.
blast007 May 13, 2023
ecc5c62
Fix the build on Windows and fix a NAT64 check
blast007 May 26, 2023
4a85a90
Fix Address::isPrivate on Windows and use the same logic on all platf…
blast007 May 30, 2023
fb6441d
c_str()
timriker Jul 25, 2023
d59f53e
missing Makefile.am?
timriker Jul 25, 2023
8561ed5
InAddr no longer used
timriker Jul 25, 2023
d5278e8
Add a definition for s6_addr16 on macOS.
blast007 Jul 26, 2023
5c4dd2c
Fix the premake5 build on macOS
blast007 Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Xcode/BZFlag.xcodeproj/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXTRA_DIST = \
project.pbxproj

MAINTAINERCLEANFILES = \
Makefile.in
2 changes: 1 addition & 1 deletion data/l10n/bzflag_es.po
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ msgstr "<** Código de paquete UDP %x tamaño %x\n"
msgid "Fallback to normal TCP receive"
msgstr "Retraso en recepción TCP normal"

msgid "Communication error joining game [No immediate respose]."
msgid "Communication error joining game [No immediate response]."
msgstr "Error de comunicación al unirse a la partida [No hay respuesta inmediata]."

msgid "Server forced disconnection."
Expand Down
2 changes: 1 addition & 1 deletion data/l10n/bzflag_ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ msgstr "<** UDP Kod paketa %x dlina %x\n"
msgid "Fallback to normal TCP receive"
msgstr "Vozvrat k obychnomu priyomu TCP"

msgid "Communication error joining game [No immediate respose]."
msgid "Communication error joining game [No immediate response]."
msgstr "Oshibka ustanovki svyazi s igroj [net nemedlennogo otveta]"

msgid "Server forced disconnection."
Expand Down
2 changes: 1 addition & 1 deletion data/l10n/bzflag_sk.po
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ msgstr "<** UDP kod paketu %x Dlzka %x\n"
msgid "Fallback to normal TCP receive"
msgstr "Navrat k obycajnemu prijmu TCP"

msgid "Communication error joining game [No immediate respose]."
msgid "Communication error joining game [No immediate response]."
msgstr "Chyba komunikacie pri pripajani sa k hre [Ziadna bezprostredna odpoved]."

msgid "Server forced disconnection."
Expand Down
2 changes: 1 addition & 1 deletion data/l10n/bzflag_xx.po
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ msgstr ""
msgid "Fallback to normal TCP receive"
msgstr ""

msgid "Communication error joining game [No immediate respose]."
msgid "Communication error joining game [No immediate response]."
msgstr ""

msgid "Server forced disconnection."
Expand Down
38 changes: 16 additions & 22 deletions include/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,50 @@
#include "Pack.h"
#include "Protocol.h"

typedef struct in_addr InAddr; // shorthand

// helpers
char *sockaddr2iptext(const struct sockaddr *sa);
char *sockaddr2iptextport(const struct sockaddr *sa);
bool splitNamePort(std::string nameport, std::string &name, int &port);
std::string joinNamePort(std::string name, int port);

class Address
{
public:
Address();
Address(const std::string&);
Address(const Address&);
Address(const InAddr&); // input in nbo
Address(const struct sockaddr_in&); // input in nbo
Address(const Address *);
Address(const struct sockaddr_in6*); // input in nbo
~Address();
Address& operator=(const Address&);

operator InAddr() const;
bool operator==(const Address&) const;
bool operator!=(const Address&) const;
bool operator<(Address const&) const;
bool isMapped() const;
bool isAny() const;
bool isPrivate() const;
sockaddr *getAddr();
sockaddr_in *getAddr_in();
sockaddr_in6 *getAddr_in6();
/* return port in network order */
in_port_t getNPort() const;
std::string getIpText();
std::string getIpTextPort();

std::string getDotNotation() const;
uint8_t getIPVersion() const;

void* pack(void*) const;
const void* unpack(const void*);

static Address getHostAddress(const std::string &hostname = std::string(""));
static std::string getHostByAddress(InAddr);
static const std::string getHostName(const std::string &hostname = std::string(""));

private:
std::vector <InAddr> addr;
struct sockaddr_in6 addr;
std::string iptext;
std::string iptextport;
};

// FIXME - enum maybe? put into namespace or class cage?
Expand All @@ -78,21 +87,6 @@ const PlayerId AdminPlayers = 252;
const PlayerId FirstTeam = 251;
const PlayerId LastRealPlayer = FirstTeam - NumTeams;

class ServerId
{
public:
void* pack(void*) const;
const void* unpack(const void*);

bool operator==(const ServerId&) const;
bool operator!=(const ServerId&) const;

public:
// host and port in network byte order
struct sockaddr_in addr;
int16_t number; // local player number
};

#endif // BZF_INET_ADDR_H

// Local Variables: ***
Expand Down
21 changes: 12 additions & 9 deletions include/AresHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class AresHandler
{
index = i;
}
void queryHostname(const struct sockaddr *clientAddr);
void queryHost(const char *hostName);
void queryHostname(const sockaddr *);
void queryHost(const char *hostName, const char *service);
const char *getHostname();
ResolutionStatus getHostAddress(struct in_addr *clientAddr);
ResolutionStatus getHostAddress(in_addr *);
ResolutionStatus getHostAddr(sockaddr_in6 *);
void setFd(fd_set *read_set, fd_set *write_set, int &maxFile);
void process(fd_set *read_set, fd_set *write_set);
ResolutionStatus getStatus()
Expand All @@ -55,23 +56,25 @@ class AresHandler
};
private:
#if ARES_VERSION_MAJOR >= 1 && ARES_VERSION_MINOR >= 5
static void staticCallback(void *arg, int statusCallback, int timeouts,
struct hostent *hostent);
static void staticHostCallback(void *arg, int statusCallback, int timeouts, hostent *);
#else
static void staticCallback(void *arg, int statusCallback,
struct hostent *hostent);
static void staticHostCallback(void *arg, int statusCallback, hostent *);
#endif
void callback(int status, struct hostent *hostent);
void callback(int status, hostent *);

static void staticAddrInfoCallback(void *arg, int callbackStatus, int, ares_addrinfo *result);
void callback(int callbackStatus, ares_addrinfo *result);

int index;

std::string hostName;
in_addr hostAddress;
sockaddr_in6 hostAddr;
ares_channel aresChannel;
ResolutionStatus status;
bool aresFailed;

static bool globallyInited;

};

#endif
Expand Down
26 changes: 15 additions & 11 deletions include/NetHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class NetHandler
a player Index, a unique pointer to a player
the file descriptor for the TCP connection with the user.
*/
NetHandler(PlayerInfo *_info, const struct sockaddr_in &_clientAddr,
NetHandler(PlayerInfo *_info, const struct sockaddr_in6 &_clientAddr,
int _playerIndex, int _fd);

NetHandler(const struct sockaddr_in &_clientAddr, int _fd);
NetHandler(const struct sockaddr_in6 &_clientAddr, int _fd);

/** The default destructor
free all internal resources, and close the tcp connection
Expand All @@ -90,7 +90,7 @@ class NetHandler
InitHandlers needs the addr structure filled to point to the local port
needed for udp communications
*/
static bool initHandlers(struct sockaddr_in addr);
static bool initHandlers(Address addr);
static void destroyHandlers();

/// General function to support the select statement
Expand All @@ -117,7 +117,7 @@ class NetHandler

udpLinkRequest report if the received message is a valid udpLinkRequest
*/
static int udpReceive(char *buffer, struct sockaddr_in *uaddr,
static int udpReceive(char *buffer, struct sockaddr_in6 *uaddr,
bool &udpLinkRequest);

/**
Expand Down Expand Up @@ -152,8 +152,7 @@ class NetHandler
int sizeOfIP();
void* packAdminInfo(void *buf);
static int whoIsAtIP(const std::string& IP);
in_addr getIPAddress();
const char* getHostname();
const char* getHostname();
bool reverseDNSDone();

size_t getTcpReadSize ()
Expand Down Expand Up @@ -181,9 +180,14 @@ class NetHandler
{
return fd;
}
const struct sockaddr *getUADDR ( void )
Address *getTaddr ( void )
{
return (const struct sockaddr *)&uaddr;
return &taddr;
}

Address *getUaddr ( void )
{
return &uaddr;
}

// Returns the time that the connection was accepted
Expand All @@ -208,7 +212,7 @@ class NetHandler
private:
int send(const void *buffer, size_t length);
void udpSend(const void *b, size_t l);
bool isMyUdpAddrPort(struct sockaddr_in uaddr);
bool isMyUaddr(const Address uaddr);
#ifdef NETWORK_STATS
void countMessage(uint16_t code, int len, int direction);
void dumpMessageStats();
Expand All @@ -222,8 +226,8 @@ class NetHandler
std::shared_ptr<AresHandler> ares;

PlayerInfo* info;
struct sockaddr_in taddr;
struct sockaddr_in uaddr;
Address taddr;
Address uaddr;
int playerIndex;
int fd; // socket file descriptor

Expand Down
10 changes: 4 additions & 6 deletions include/Ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PingPacket
PingPacket();
~PingPacket();

bool read(int fd, struct sockaddr_in*);
bool write(int fd, const struct sockaddr_in*) const;
bool read(int fd, struct sockaddr_in6*);
bool write(int fd, const struct sockaddr_in6*) const;
void* pack(void*, const char* version) const;
const void* unpack(const void*, char* version);

Expand All @@ -48,12 +48,10 @@ class PingPacket
bool readFromFile(std::istream& in);
static void repackHexPlayerCounts(char*, int* counts);

static bool isRequest(int fd, struct sockaddr_in*);
static bool sendRequest(int fd, const struct sockaddr_in*);
static bool isRequest(int fd, struct sockaddr_in6*);
static bool sendRequest(int fd, const struct sockaddr_in6*);

public:
ServerId serverId;
Address sourceAddr;
uint16_t gameOptions;
uint16_t gameType;
uint16_t maxShots;
Expand Down
1 change: 0 additions & 1 deletion include/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ const uint16_t MsgLagPing = 0x7069; // 'pi'

typedef uint8_t PlayerId;
const int PlayerIdPLen = sizeof(PlayerId);
const int ServerIdPLen = 8;

// 54 bytes
const int PlayerUpdatePLenMax =
Expand Down
2 changes: 0 additions & 2 deletions include/ServerItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class ServerItem
bool readFromFile(std::istream& in, int subrevision); // serialize in
void setUpdateTime(); // set last updated to now
int getPlayerCount() const;
void splitAddrTitle(std::string& addr, std::string& title) const;
std::string getAddrName() const;
time_t getAgeMinutes() const;
time_t getAgeSeconds() const;
std::string getAgeString() const; // nifty formated age string
Expand Down
3 changes: 1 addition & 2 deletions include/ServerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ServerList : cURLManager

private:
void readServerList();
void addToListWithLookup(ServerItem&);
void addCacheToList();
void _shutDown();

Expand All @@ -64,7 +63,7 @@ class ServerList : cURLManager
std::vector<ServerItem> servers;
ServerListCache* serverCache;
int pingBcastSocket;
struct sockaddr_in pingBcastAddr;
struct sockaddr_in6 pingBcastAddr;
StartupInfo *startupInfo;
};

Expand Down
6 changes: 3 additions & 3 deletions include/ServerListCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ class ServerListCache

/** search for some address in the cache. this is a wrapper that
* allows access to the maps find method */
SRV_STR_MAP::iterator find(const std::string &ServerAddress);
SRV_STR_MAP::iterator find(const std::string &namePort);

/** add an entry to the cache list */
void insert(const std::string &serverAddress, const ServerItem &info);
void insert(const std::string &namePort, const ServerItem &info);

/** is given server in cache and marked as favorite? */
bool isFavorite(const std::string &serverAddress) const;
bool isFavorite(const std::string &namePort) const;

private:
/** the full path of the file the cache is stored in **/
Expand Down
4 changes: 4 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ extern int debugLevel;
# include <inttypes.h>
#endif

#ifndef in_port_t
# define in_port_t uint16_t
#endif

#ifdef HAVE_STDINT_H
# include <stdint.h>
#else
Expand Down
6 changes: 3 additions & 3 deletions include/multicast.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
* -1 if failed
*/
int openBroadcast(int port, const char* service,
struct sockaddr_in* addr);
struct sockaddr_in6* addr);
int closeBroadcast(int fd);
int sendBroadcast(int fd, const void* buffer,
int bufferLength, const struct sockaddr_in*);
int bufferLength, const struct sockaddr_in6*);
int recvBroadcast(int fd, void* buffer,
int bufferLength, struct sockaddr_in*);
int bufferLength, struct sockaddr_in6*);

#endif // __MULTICAST_H__

Expand Down
12 changes: 12 additions & 0 deletions include/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ extern "C" {

}

# ifndef s6_addr16
# define s6_addr16 u.Word
# endif

#else // !defined(_WIN32)

// unistd has close(). It is poor encapsulation the close() is called from
Expand Down Expand Up @@ -113,13 +117,21 @@ extern "C" {
void bzfherror(const char* msg);
}

# if defined(__APPLE__) && !defined(s6_addr16)
# define s6_addr16 __u6_addr.__u6_addr16
# endif

#endif /* defined(_WIN32) */

// Can this happen?
#if !defined(INADDR_NONE)
# define INADDR_NONE ((in_addr_t)0xffffffff)
#endif

// Identifiers for IP address family that will be passed between server and client as a uint8_t
#define BZF_INET 4
#define BZF_INET6 6

// for all platforms
extern "C" {
void nerror(const char* msg);
Expand Down
2 changes: 2 additions & 0 deletions man/bzfs.6.in
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ than the first 50 lines of \fIfile\fR to the player.
Server will listen for and respond to ``pings'' (sent via broadcast)
on the given interface. Clients use this to find active servers on the
network. This is the TCP/UDP/IP address the server will listen on.
Default is \fI::\fR which should accept IPv4 and IPv6 clients. Use
\fB-i 0.0.0.0\fR to support only IPv4 clients.
.TP
.B \-j
Allows jumping.
Expand Down
Loading
Loading