summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-06-25 01:03:23 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-06-25 01:03:23 +0200
commit9ac7f3588dda7d175e04878e7b871a88306d13bf (patch)
tree00846bf23da618f6fb43da1b24c8b877dd6df60f /src
parentfc5e06a19c090d98620a735e33b57aee7c43107d (diff)
downloadfastd-9ac7f3588dda7d175e04878e7b871a88306d13bf.tar
fastd-9ac7f3588dda7d175e04878e7b871a88306d13bf.zip
Don't depend on net/if_ether.h
Instead of adding compatiblity code to make this work with musl, just duplicate the needed definitions in fastd.
Diffstat (limited to 'src')
-rw-r--r--src/compat.h22
-rw-r--r--src/config.y1
-rw-r--r--src/fastd.h15
-rw-r--r--src/fastd_config.h.in3
-rw-r--r--src/log.c2
-rw-r--r--src/peer.c7
-rw-r--r--src/receive.c2
-rw-r--r--src/send.c2
-rw-r--r--src/socket.c2
-rw-r--r--src/status.c1
-rw-r--r--src/types.h1
11 files changed, 23 insertions, 35 deletions
diff --git a/src/compat.h b/src/compat.h
index 991c268..29c9253 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -39,32 +39,10 @@
#include <unistd.h>
#include <sys/types.h>
-#include <sys/queue.h>
#include <sys/socket.h>
-#include <net/if.h>
-#include <net/if_arp.h>
#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#ifndef ETH_ALEN
-/** The length of a MAC address */
-#define ETH_ALEN 6
-#endif
-
-#ifndef ETH_HLEN
-/** The length of the standard ethernet header */
-#define ETH_HLEN 14
-#endif
-
-#ifndef HAVE_ETHHDR
-/** An ethernet header */
-struct ethhdr {
- uint8_t h_dest[ETH_ALEN]; /**< The destination MAC address field */
- uint8_t h_source[ETH_ALEN]; /**< The source MAC address field */
- uint16_t h_proto; /**< The EtherType/length field */
-} __attribute__((packed));
-#endif
#if defined(USE_FREEBIND) && !defined(IP_FREEBIND)
/** Compatiblity define for systems supporting, but not defining IP_FREEBIND */
diff --git a/src/config.y b/src/config.y
index 3cffa17..196f862 100644
--- a/src/config.y
+++ b/src/config.y
@@ -33,6 +33,7 @@
%code requires {
#include <src/fastd.h>
#include <arpa/inet.h>
+ #include <net/if.h>
}
%union {
diff --git a/src/fastd.h b/src/fastd.h
index a16244a..cc88282 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -59,7 +59,14 @@
/** An ethernet address */
struct __attribute__((__packed__)) fastd_eth_addr {
- uint8_t data[ETH_ALEN]; /**< The bytes of the address */
+ uint8_t data[6]; /**< The bytes of the address */
+};
+
+/** An ethernet header */
+struct __attribute__((packed)) fastd_eth_header {
+ fastd_eth_addr_t dest; /**< The destination MAC address field */
+ fastd_eth_addr_t source; /**< The source MAC address field */
+ uint16_t proto; /**< The EtherType/length field */
};
@@ -422,7 +429,7 @@ static inline size_t fastd_max_payload(uint16_t mtu) {
switch (conf.mode) {
case MODE_TAP:
case MODE_MULTITAP:
- return mtu+ETH_HLEN;
+ return mtu + sizeof(fastd_eth_header_t);
case MODE_TUN:
return mtu;
default:
@@ -434,14 +441,14 @@ static inline size_t fastd_max_payload(uint16_t mtu) {
/** Returns the source address of an ethernet packet */
static inline fastd_eth_addr_t fastd_buffer_source_address(const fastd_buffer_t buffer) {
fastd_eth_addr_t ret;
- memcpy(&ret, buffer.data+offsetof(struct ethhdr, h_source), ETH_ALEN);
+ memcpy(&ret, buffer.data + offsetof(fastd_eth_header_t, source), sizeof(fastd_eth_addr_t));
return ret;
}
/** Returns the destination address of an ethernet packet */
static inline fastd_eth_addr_t fastd_buffer_dest_address(const fastd_buffer_t buffer) {
fastd_eth_addr_t ret;
- memcpy(&ret, buffer.data+offsetof(struct ethhdr, h_dest), ETH_ALEN);
+ memcpy(&ret, buffer.data + offsetof(fastd_eth_header_t, dest), sizeof(fastd_eth_addr_t));
return ret;
}
diff --git a/src/fastd_config.h.in b/src/fastd_config.h.in
index 6a55930..5f9c868 100644
--- a/src/fastd_config.h.in
+++ b/src/fastd_config.h.in
@@ -35,9 +35,6 @@
/** Defined if the platform supports the AI_ADDRCONFIG flag to getaddrinfo() */
#cmakedefine HAVE_AI_ADDRCONFIG
-/** Defined if the platform defines the \e ethhdr struct */
-#cmakedefine HAVE_ETHHDR
-
/** Defined if the platform defines get_current_dir_name() */
#cmakedefine HAVE_GET_CURRENT_DIR_NAME
diff --git a/src/log.c b/src/log.c
index 7b68f48..bd38821 100644
--- a/src/log.c
+++ b/src/log.c
@@ -74,7 +74,7 @@ size_t fastd_snprint_peer_address(char *buffer, size_t size, const fastd_peer_ad
if (!bind_address && hide)
return snprintf_safe(buffer, size, "[hidden]:%u", ntohs(address->in6.sin6_port));
if (inet_ntop(AF_INET6, &address->in6.sin6_addr, addr_buf, sizeof(addr_buf))) {
- char ifname_buf[IF_NAMESIZE];
+ char ifname_buf[IFNAMSIZ];
if (!iface && IN6_IS_ADDR_LINKLOCAL(&address->in6.sin6_addr))
iface = if_indextoname(address->in6.sin6_scope_id, ifname_buf);
diff --git a/src/peer.c b/src/peer.c
index b174b9b..363bdd7 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -34,13 +34,14 @@
#include "poll.h"
#include <arpa/inet.h>
+#include <net/if.h>
#include <sys/wait.h>
/** Adds peer-specific fields to \e env */
void fastd_peer_set_shell_env(fastd_shell_env_t *env, const fastd_peer_t *peer, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *peer_addr) {
- /* both INET6_ADDRSTRLEN and IFNAMESIZE already include space for the zero termination, so there is no need to add space for the '%' here. */
- char buf[INET6_ADDRSTRLEN+IF_NAMESIZE];
+ /* both INET6_ADDRSTRLEN and IFNAMSIZ already include space for the zero termination, so there is no need to add space for the '%' here. */
+ char buf[INET6_ADDRSTRLEN+IFNAMSIZ];
fastd_shell_env_set(env, "PEER_NAME", peer ? peer->name : NULL);
@@ -890,7 +891,7 @@ bool fastd_peer_set_established(fastd_peer_t *peer) {
/** Compares two MAC addresses */
static inline int eth_addr_cmp(const fastd_eth_addr_t *addr1, const fastd_eth_addr_t *addr2) {
- return memcmp(addr1->data, addr2->data, ETH_ALEN);
+ return memcmp(addr1->data, addr2->data, sizeof(fastd_eth_addr_t));
}
/** Compares two fastd_peer_eth_addr_t entries by their MAC addresses */
diff --git a/src/receive.c b/src/receive.c
index 338edea..1a34523 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -289,7 +289,7 @@ void fastd_receive(fastd_socket_t *sock) {
/** Handles a received and decrypted payload packet */
void fastd_handle_receive(fastd_peer_t *peer, fastd_buffer_t buffer, bool reordered) {
if (conf.mode == MODE_TAP) {
- if (buffer.len < ETH_HLEN) {
+ if (buffer.len < sizeof(fastd_eth_header_t)) {
pr_debug("received truncated packet");
fastd_buffer_free(buffer);
return;
diff --git a/src/send.c b/src/send.c
index f0ba2f7..a178358 100644
--- a/src/send.c
+++ b/src/send.c
@@ -209,7 +209,7 @@ static inline bool send_data_tap_single(fastd_buffer_t buffer, fastd_peer_t *sou
if (conf.mode != MODE_TAP)
return false;
- if (buffer.len < ETH_HLEN) {
+ if (buffer.len < sizeof(fastd_eth_header_t)) {
pr_debug("truncated ethernet packet");
fastd_buffer_free(buffer);
return true;
diff --git a/src/socket.c b/src/socket.c
index 325ff30..89759f0 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -32,6 +32,8 @@
#include "fastd.h"
#include "poll.h"
+#include <net/if.h>
+
/**
Creates a new socket bound to a specific address
diff --git a/src/status.c b/src/status.c
index a868d7c..988b46f 100644
--- a/src/status.c
+++ b/src/status.c
@@ -39,6 +39,7 @@
#include "peer.h"
#include <json-c/json.h>
+#include <net/if.h>
#include <sys/un.h>
diff --git a/src/types.h b/src/types.h
index 488f8f9..d2f5dc9 100644
--- a/src/types.h
+++ b/src/types.h
@@ -99,6 +99,7 @@ typedef struct fastd_iface fastd_iface_t;
typedef struct fastd_socket fastd_socket_t;
typedef struct fastd_peer_group fastd_peer_group_t;
typedef struct fastd_eth_addr fastd_eth_addr_t;
+typedef struct fastd_eth_header fastd_eth_header_t;
typedef struct fastd_peer fastd_peer_t;
typedef struct fastd_peer_eth_addr fastd_peer_eth_addr_t;
typedef struct fastd_remote fastd_remote_t;