- Remove checks for specific OS's, instead check for #defines/#includes.
- Use uint??_t where appropriate.
- Mask handling functions use void pointers to get rid of silly casts.
dnl Process this file with autoconf to produce a configure script.
-dnl $Id: configure.in,v 1.13.2.44 2002/04/19 14:06:40 guus Exp $
+dnl $Id: configure.in,v 1.13.2.45 2002/06/08 12:57:09 guus Exp $
AC_INIT(src/tincd.c)
AM_INIT_AUTOMAKE(tinc, 1.0-cvs)
dnl Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h limits.h sys/ioctl.h syslog.h unistd.h \
-sys/time.h malloc.h strings.h sys/file.h])
+AC_CHECK_HEADERS([fcntl.h limits.h malloc.h stdint.h strings.h syslog.h unistd.h \
+net/ethernet.h net/if.h netinet/ip.h netinet/tcp.h \
+sys/file.h sys/ioctl.h sys/param.h sys/time.h])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_FUNC_MEMCMP
AC_FUNC_ALLOCA
AC_TYPE_SIGNAL
-AC_CHECK_FUNCS([ftime socket select strtol strerror flock unsetenv \
-asprintf putenv strdup fcloseall daemon strsignal get_current_dir_name])
+AC_CHECK_FUNCS([asprintf daemon fcloseall flock ftime get_current_dir_name \
+putenv select strdup strerror strsignal strtol unsetenv])
jm_FUNC_MALLOC
jm_FUNC_REALLOC
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: conf.c,v 1.9.4.55 2002/04/09 11:42:48 guus Exp $
+ $Id: conf.c,v 1.9.4.56 2002/06/08 12:57:09 guus Exp $
*/
#include "config.h"
/* Teach newbies what subnets are... */
- if(((subnet->type == SUBNET_IPV4) && maskcheck((char *)&subnet->net.ipv4.address, subnet->net.ipv4.prefixlength, sizeof(ipv4_t)))
- || ((subnet->type == SUBNET_IPV6) && maskcheck((char *)&subnet->net.ipv6.address, subnet->net.ipv6.prefixlength, sizeof(ipv6_t))))
+ if(((subnet->type == SUBNET_IPV4) && maskcheck(&subnet->net.ipv4.address, subnet->net.ipv4.prefixlength, sizeof(ipv4_t)))
+ || ((subnet->type == SUBNET_IPV6) && maskcheck(&subnet->net.ipv6.address, subnet->net.ipv6.prefixlength, sizeof(ipv6_t))))
{
syslog(LOG_ERR, _("Network address and prefix length do not match for configuration variable %s in %s line %d"),
cfg->variable, cfg->file, cfg->line);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: graph.c,v 1.1.2.11 2002/03/24 16:28:27 guus Exp $
+ $Id: graph.c,v 1.1.2.12 2002/06/08 12:57:09 guus Exp $
*/
/* We need to generate two trees from the graph:
#include <syslog.h>
#include "config.h"
#include <string.h>
-#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <netinet/in.h>
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.c,v 1.35.4.171 2002/05/01 09:15:58 guus Exp $
+ $Id: net.c,v 1.35.4.172 2002/06/08 12:57:09 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
-#ifdef HAVE_LINUX
+#ifdef HAVE_NETINET_IP_H
#include <netinet/ip.h>
+#endif
+#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#include <stdio.h>
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.h,v 1.9.4.49 2002/03/27 15:01:36 guus Exp $
+ $Id: net.h,v 1.9.4.50 2002/06/08 12:57:09 guus Exp $
*/
#ifndef __TINC_NET_H__
#include <netinet/in.h>
#include <sys/time.h>
+#ifdef HAVE_STDINT_H
+ #include <stdint.h>
+#endif
+
#include "config.h"
#ifdef ENABLE_JUMBOGRAMS
typedef struct mac_t
{
- unsigned char x[6];
+ uint8_t x[6];
} mac_t;
typedef struct ipv4_t
{
- unsigned char x[4];
+ uint8_t x[4];
} ipv4_t;
typedef struct ip_mask_t {
typedef struct ipv6_t
{
- unsigned short x[8];
+ uint16_t x[8];
} ipv6_t;
typedef unsigned short port_t;
typedef struct vpn_packet_t {
length_t len; /* the actual number of bytes in the `data' field */
int priority; /* priority or TOS */
- unsigned int seqno; /* 32 bits sequence number (network byte order of course) */
- unsigned char data[MAXSIZE];
+ uint32_t seqno; /* 32 bits sequence number (network byte order of course) */
+ uint8_t data[MAXSIZE];
} vpn_packet_t;
typedef struct queue_element_t {
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_packet.c,v 1.1.2.14 2002/04/18 20:09:05 zarq Exp $
+ $Id: net_packet.c,v 1.1.2.15 2002/06/08 12:57:09 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
-#ifdef HAVE_LINUX
+#ifdef HAVE_NETINET_IP_H
#include <netinet/ip.h>
+#endif
+#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#include <stdio.h>
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_setup.c,v 1.1.2.16 2002/06/02 16:06:33 guus Exp $
+ $Id: net_setup.c,v 1.1.2.17 2002/06/08 12:57:10 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
-#ifdef HAVE_LINUX
+#ifdef HAVE_NETINET_IP_H
#include <netinet/ip.h>
+#endif
+#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#include <stdio.h>
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_socket.c,v 1.1.2.12 2002/04/18 20:09:05 zarq Exp $
+ $Id: net_socket.c,v 1.1.2.13 2002/06/08 12:57:10 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
-#ifdef HAVE_LINUX
+#ifdef HAVE_NETINET_IP_H
#include <netinet/ip.h>
+#endif
+#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#include <stdio.h>
/* Optimize TCP settings */
-#ifdef HAVE_LINUX
+#if defined(SOL_TCP) && defined(TCP_NODELAY)
option = 1;
setsockopt(c->socket, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
+#endif
+#if defined(SOL_IP) && defined(IP_TOS)
option = IPTOS_LOWDELAY;
setsockopt(c->socket, SOL_IP, IP_TOS, &option, sizeof(option));
#endif
/* Optimize TCP settings */
-#ifdef HAVE_LINUX
+#if defined(SOL_TCP) && defined(TCP_NODELAY)
option = 1;
setsockopt(c->socket, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
+#endif
+#if defined(SOL_IP) && defined(IP_TOS)
option = IPTOS_LOWDELAY;
setsockopt(c->socket, SOL_IP, IP_TOS, &option, sizeof(option));
#endif
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: netutl.c,v 1.12.4.37 2002/06/07 11:14:05 wsl Exp $
+ $Id: netutl.c,v 1.12.4.38 2002/06/08 12:57:10 guus Exp $
*/
#include "config.h"
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
-#ifndef HAVE_NETBSD
+#ifndef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <string.h>
exit(0);
}
-#ifdef HAVE_LINUX
if((scopeid = strchr(address, '%')))
*scopeid = '\0'; /* Descope. */
-#endif
*addrstr = xstrdup(address);
*portstr = xstrdup(port);
/* Subnet mask handling */
-int maskcmp(char *a, char *b, int masklen, int len)
+int maskcmp(void *va, void *vb, int masklen, int len)
{
int i, m, result;
+ char *a = va;
+ char *b = vb;
cp
for(m = masklen, i = 0; m >= 8; m -= 8, i++)
if((result = a[i] - b[i]))
return 0;
}
-void mask(char *a, int masklen, int len)
+void mask(void *va, int masklen, int len)
{
int i;
+ char *a = va;
cp
i = masklen / 8;
masklen %= 8;
a[i] = 0;
}
-void maskcpy(char *a, char *b, int masklen, int len)
+void maskcpy(void *va, void *vb, int masklen, int len)
{
int i, m;
+ char *a = va;
+ char *b = vb;
cp
for(m = masklen, i = 0; m >= 8; m -= 8, i++)
a[i] = b[i];
a[i] = 0;
}
-int maskcheck(char *a, int masklen, int len)
+int maskcheck(void *va, int masklen, int len)
{
int i;
+ char *a = va;
cp
i = masklen / 8;
masklen %= 8;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: netutl.h,v 1.2.4.11 2002/03/17 15:59:29 guus Exp $
+ $Id: netutl.h,v 1.2.4.12 2002/06/08 12:57:10 guus Exp $
*/
#ifndef __TINC_NETUTL_H__
extern int hostnames;
-extern char *hostlookup(unsigned long);
extern struct addrinfo *str2addrinfo(char *, char *, int);
extern sockaddr_t str2sockaddr(char *, char *);
extern void sockaddr2str(sockaddr_t *, char **, char **);
extern char *sockaddr2hostname(sockaddr_t *);
extern int sockaddrcmp(sockaddr_t *, sockaddr_t *);
extern void sockaddrunmap(sockaddr_t *);
-extern int maskcmp(char *, char *, int, int);
-extern void maskcpy(char *, char *, int, int);
-extern void mask(char *, int, int);
-extern int maskcheck(char *, int, int);
+extern int maskcmp(void *, void *, int, int);
+extern void maskcpy(void *, void *, int, int);
+extern void mask(void *, int, int);
+extern int maskcheck(void *, int, int);
#endif /* __TINC_NETUTL_H__ */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: node.h,v 1.1.2.13 2002/03/19 22:48:25 guus Exp $
+ $Id: node.h,v 1.1.2.14 2002/06/08 12:57:10 guus Exp $
*/
#ifndef __TINC_NODE_H__
#define __TINC_NODE_H__
+#ifdef HAVE_STDINT_H
+ #include <stdint.h>
+#endif
+
#include <avl_tree.h>
#include "subnet.h"
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
- unsigned int sent_seqno; /* Sequence number last sent to this node */
- unsigned int received_seqno; /* Sequence number last received from this node */
+ uint32_t sent_seqno; /* Sequence number last sent to this node */
+ uint32_t received_seqno; /* Sequence number last received from this node */
} node_t;
extern struct node_t *myself;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: route.c,v 1.1.2.39 2002/06/05 00:25:55 guus Exp $
+ $Id: route.c,v 1.1.2.40 2002/06/08 12:57:10 guus Exp $
*/
#include "config.h"
-#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) || defined(HAVE_NETBSD)
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/socket.h>
#include <netinet/in.h>
-#if defined(HAVE_SOLARIS) || defined(HAVE_OPENBSD) || defined(HAVE_NETBSD)
+#ifdef HAVE_NET_IF_H
#include <net/if.h>
- #define ETHER_ADDR_LEN 6
-#else
+#endif
+#ifdef HAVE_NET_ETHERNET_H
#include <net/ethernet.h>
#endif
#include <netinet/ip6.h>
#include <xalloc.h>
#include <syslog.h>
#include <string.h>
-#ifndef HAVE_NETBSD
+#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include "system.h"
+#ifndef ETHER_ADDR_LEN
+ #define ETHER_ADDR_LEN 6
+#endif
+
int routing_mode = RMODE_ROUTER;
int priorityinheritance = 0;
int macexpire = 600;
if(debug_lvl >= DEBUG_TRAFFIC)
{
syslog(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
- ntohs(*(short unsigned int *)&packet->data[38]),
- ntohs(*(short unsigned int *)&packet->data[40]),
- ntohs(*(short unsigned int *)&packet->data[42]),
- ntohs(*(short unsigned int *)&packet->data[44]),
- ntohs(*(short unsigned int *)&packet->data[46]),
- ntohs(*(short unsigned int *)&packet->data[48]),
- ntohs(*(short unsigned int *)&packet->data[50]),
- ntohs(*(short unsigned int *)&packet->data[52]));
+ ntohs(*(uint16_t *)&packet->data[38]),
+ ntohs(*(uint16_t *)&packet->data[40]),
+ ntohs(*(uint16_t *)&packet->data[42]),
+ ntohs(*(uint16_t *)&packet->data[44]),
+ ntohs(*(uint16_t *)&packet->data[46]),
+ ntohs(*(uint16_t *)&packet->data[48]),
+ ntohs(*(uint16_t *)&packet->data[50]),
+ ntohs(*(uint16_t *)&packet->data[52]));
}
return NULL;
return subnet->owner;
}
-unsigned short int inet_checksum(unsigned short int *data, int len, unsigned short int prevsum)
+uint16_t inet_checksum(uint16_t *data, int len, uint16_t prevsum)
{
- unsigned long int checksum = prevsum ^ 0xFFFF;
+ uint32_t checksum = prevsum ^ 0xFFFF;
while(len--)
checksum += ntohs(*data++);
struct nd_neighbor_solicit *ns;
struct nd_opt_hdr *opt;
subnet_t *subnet;
- short unsigned int checksum;
+ uint16_t checksum;
struct {
struct in6_addr ip6_src; /* source address */
/* Generate checksum */
- checksum = inet_checksum((unsigned short int *)&pseudo, sizeof(pseudo)/2, ~0);
- checksum = inet_checksum((unsigned short int *)ns, sizeof(*ns)/2 + 4, checksum);
+ checksum = inet_checksum((uint16_t *)&pseudo, sizeof(pseudo)/2, ~0);
+ checksum = inet_checksum((uint16_t *)ns, sizeof(*ns)/2 + 4, checksum);
if(checksum)
{
/* Generate checksum */
- checksum = inet_checksum((unsigned short int *)&pseudo, sizeof(pseudo)/2, ~0);
- checksum = inet_checksum((unsigned short int *)ns, sizeof(*ns)/2 + 4, checksum);
+ checksum = inet_checksum((uint16_t *)&pseudo, sizeof(pseudo)/2, ~0);
+ checksum = inet_checksum((uint16_t *)ns, sizeof(*ns)/2 + 4, checksum);
ns->nd_ns_hdr.icmp6_cksum = htons(checksum);
{
struct ether_arp *arp;
subnet_t *subnet;
- unsigned char ipbuf[4];
+ uint8_t ipbuf[4];
cp
/* First, snatch the source address from the ARP packet */
if(ntohs(arp->arp_hrd) != ARPHRD_ETHER ||
ntohs(arp->arp_pro) != ETHERTYPE_IP ||
- (int) (arp->arp_hln) != ETHER_ADDR_LEN ||
- (int) (arp->arp_pln) != 4 ||
+ arp->arp_hln != ETHER_ADDR_LEN ||
+ arp->arp_pln != 4 ||
ntohs(arp->arp_op) != ARPOP_REQUEST )
{
if(debug_lvl > DEBUG_TRAFFIC)
void route_outgoing(vpn_packet_t *packet)
{
- unsigned short int type;
+ uint16_t type;
node_t *n = NULL;
cp
/* FIXME: multicast? */
switch(routing_mode)
{
case RMODE_ROUTER:
- type = ntohs(*((unsigned short*)(&packet->data[12])));
+ type = ntohs(*((uint16_t *)(&packet->data[12])));
switch(type)
{
case 0x0800:
case RMODE_ROUTER:
{
node_t *n = NULL;
- unsigned short int type;
+ uint16_t type;
- type = ntohs(*((unsigned short*)(&packet->data[12])));
+ type = ntohs(*((uint16_t *)(&packet->data[12])));
switch(type)
{
case 0x0800:
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: subnet.c,v 1.1.2.35 2002/04/26 18:13:00 zarq Exp $
+ $Id: subnet.c,v 1.1.2.36 2002/06/08 12:57:10 guus Exp $
*/
#include "config.h"
{
int i, l;
subnet_t *subnet;
- unsigned short int x[8];
+ uint16_t x[8];
cp
subnet = new_subnet();
cp
break;
}
- if (!maskcmp((char *)address, (char *)&p->net.ipv4.address, p->net.ipv4.prefixlength, sizeof(ipv4_t)))
+ if (!maskcmp(address, &p->net.ipv4.address, p->net.ipv4.prefixlength, sizeof(ipv4_t)))
break;
else
{
/* Otherwise, see if there is a bigger enclosing subnet */
subnet.net.ipv4.prefixlength = p->net.ipv4.prefixlength - 1;
- maskcpy((char *)&subnet.net.ipv4.address, (char *)&p->net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(ipv4_t));
+ maskcpy(&subnet.net.ipv4.address, &p->net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(ipv4_t));
}
}
} while (p);
if(p->type != SUBNET_IPV6)
return NULL;
- if (!maskcmp((char *)address, (char *)&p->net.ipv6.address, p->net.ipv6.prefixlength, sizeof(ipv6_t)))
+ if (!maskcmp(address, &p->net.ipv6.address, p->net.ipv6.prefixlength, sizeof(ipv6_t)))
break;
else
{
/* Otherwise, see if there is a bigger enclosing subnet */
subnet.net.ipv6.prefixlength = p->net.ipv6.prefixlength - 1;
- maskcpy((char *)&subnet.net.ipv6.address, (char *)&p->net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(ipv6_t));
+ maskcpy(&subnet.net.ipv6.address, &p->net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(ipv6_t));
}
}
} while (p);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: tincd.c,v 1.10.4.58 2002/03/11 11:23:04 guus Exp $
+ $Id: tincd.c,v 1.10.4.59 2002/06/08 12:57:10 guus Exp $
*/
#include "config.h"
if(show_help)
usage(0);
-#ifdef HAVE_SOLARIS
+#ifndef LOG_PERROR
openlog("tinc", LOG_CONS, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */
#else
openlog("tinc", LOG_PERROR, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */