From: Guus Sliepen Date: Mon, 21 Apr 2014 18:11:47 +0000 (+0200) Subject: Move definition of sockaddr_t to its own header, remove length_t. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=8f8d796e645653f5620322f3f1f37552c01db86e;p=meshlink Move definition of sockaddr_t to its own header, remove length_t. This reduces the horrible interdependencies of the header files, most notably that of net.h. --- diff --git a/src/net.h b/src/net.h index 4d2d48aa..dab40cbb 100644 --- a/src/net.h +++ b/src/net.h @@ -23,6 +23,7 @@ #include "cipher.h" #include "digest.h" #include "event.h" +#include "sockaddr.h" #ifdef ENABLE_JUMBOGRAMS #define MTU 9018 /* 9000 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */ @@ -38,40 +39,12 @@ #define MAXSOCKETS 8 /* Probably overkill... */ -typedef short length_t; - -#define AF_UNKNOWN 255 - -struct sockaddr_unknown { - uint16_t family; - uint16_t pad1; - uint32_t pad2; - char *address; - char *port; -}; - -typedef union sockaddr_t { - struct sockaddr sa; - struct sockaddr_in in; - struct sockaddr_in6 in6; - struct sockaddr_unknown unknown; -#ifdef HAVE_STRUCT_SOCKADDR_STORAGE - struct sockaddr_storage storage; -#endif -} sockaddr_t; - -#ifdef SA_LEN -#define SALEN(s) SA_LEN(&s) -#else -#define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6)) -#endif - typedef struct vpn_packet_t { struct { unsigned int probe:1; unsigned int tcp:1; }; - length_t len; /* the actual number of bytes in the `data' field */ + uint16_t len; /* the actual number of bytes in the `data' field */ uint8_t data[MAXSIZE]; } vpn_packet_t; diff --git a/src/net_packet.c b/src/net_packet.c index 5631a939..41e2521d 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -163,7 +163,7 @@ void send_mtu_probe(node_t *n) { send_mtu_probe_handler(n); } -static void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) { +static void mtu_probe_h(node_t *n, vpn_packet_t *packet, uint16_t len) { logger(DEBUG_TRAFFIC, LOG_INFO, "Got MTU probe length %d from %s (%s)", packet->len, n->name, n->hostname); if(!packet->data[0]) { @@ -230,7 +230,7 @@ static void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) { } } -static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) { +static uint16_t compress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) { if(level == 0) { memcpy(dest, source, len); return len; @@ -251,7 +251,7 @@ static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t l return -1; } -static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) { +static uint16_t uncompress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) { if(level == 0) { memcpy(dest, source, len); return len; @@ -535,7 +535,7 @@ bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t } if(type & PKT_COMPRESSED) { - length_t ulen = uncompress_packet(inpkt.data, (const uint8_t *)data, len, from->incompression); + uint16_t ulen = uncompress_packet(inpkt.data, (const uint8_t *)data, len, from->incompression); if(ulen < 0) { return false; } else { diff --git a/src/node.h b/src/node.h index 84abcab6..68f6578c 100644 --- a/src/node.h +++ b/src/node.h @@ -20,11 +20,9 @@ #ifndef __TINC_NODE_H__ #define __TINC_NODE_H__ -#include "splay_tree.h" -#include "cipher.h" -#include "connection.h" -#include "digest.h" #include "event.h" +#include "sockaddr.h" +#include "sptps.h" typedef struct node_status_t { unsigned int unused_active:1; /* 1 if active (not used for nodes) */ @@ -51,7 +49,7 @@ typedef struct node_t { time_t last_state_change; time_t last_req_key; - ecdsa_t *ecdsa; /* His public ECDSA key */ + struct ecdsa_t *ecdsa; /* His public ECDSA key */ sptps_t sptps; int incompression; /* Compressionlevel, 0 = no compression */ @@ -73,9 +71,9 @@ typedef struct node_t { uint32_t prev_received; unsigned char* late; /* Bitfield marking late packets */ - length_t mtu; /* Maximum size of packets to send to this node */ - length_t minmtu; /* Probed minimum MTU */ - length_t maxmtu; /* Probed maximum MTU */ + uint16_t mtu; /* Maximum size of packets to send to this node */ + uint16_t minmtu; /* Probed minimum MTU */ + uint16_t maxmtu; /* Probed maximum MTU */ int mtuprobes; /* Number of probes */ timeout_t mtutimeout; /* Probe event */ struct timeval probe_time; /* Time the last probe was sent or received */ diff --git a/src/route.c b/src/route.c index a8516d07..450baf90 100644 --- a/src/route.c +++ b/src/route.c @@ -43,7 +43,7 @@ static bool ratelimit(int frequency) { return false; } -static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) { +static bool checklength(node_t *source, vpn_packet_t *packet, uint16_t length) { if(packet->len < length) { logger(DEBUG_TRAFFIC, LOG_WARNING, "Got too short packet from %s (%s)", source->name, source->hostname); return false; diff --git a/src/sockaddr.h b/src/sockaddr.h new file mode 100644 index 00000000..255dc830 --- /dev/null +++ b/src/sockaddr.h @@ -0,0 +1,30 @@ +#ifndef SOCKADDR_H +#define SOCKADDR_H + +#define AF_UNKNOWN 255 + +#ifdef SA_LEN +#define SALEN(s) SA_LEN(&s) +#else +#define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6)) +#endif + +struct sockaddr_unknown { + uint16_t family; + uint16_t pad1; + uint32_t pad2; + char *address; + char *port; +}; + +typedef union sockaddr_t { + struct sockaddr sa; + struct sockaddr_in in; + struct sockaddr_in6 in6; + struct sockaddr_unknown unknown; +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE + struct sockaddr_storage storage; +#endif +} sockaddr_t; + +#endif // SOCKADDR_H