diff options
-rw-r--r-- | cmake/checks.cmake | 5 | ||||
-rw-r--r-- | src/compat.h | 22 | ||||
-rw-r--r-- | src/config.y | 1 | ||||
-rw-r--r-- | src/fastd.h | 15 | ||||
-rw-r--r-- | src/fastd_config.h.in | 3 | ||||
-rw-r--r-- | src/log.c | 2 | ||||
-rw-r--r-- | src/peer.c | 7 | ||||
-rw-r--r-- | src/receive.c | 2 | ||||
-rw-r--r-- | src/send.c | 2 | ||||
-rw-r--r-- | src/socket.c | 2 | ||||
-rw-r--r-- | src/status.c | 1 | ||||
-rw-r--r-- | src/types.h | 1 |
12 files changed, 23 insertions, 40 deletions
diff --git a/cmake/checks.cmake b/cmake/checks.cmake index f9f0399..62d52ff 100644 --- a/cmake/checks.cmake +++ b/cmake/checks.cmake @@ -54,11 +54,6 @@ if(NOT DARWIN) endif(NOT DARWIN) -set(CMAKE_EXTRA_INCLUDE_FILES "netinet/if_ether.h") -check_type_size("struct ethhdr" SIZEOF_ETHHDR) -string(COMPARE NOTEQUAL "${SIZEOF_ETHHDR}" "" HAVE_ETHHDR) - - set(CMAKE_REQUIRED_INCLUDES "sys/types.h") if(NOT DARWIN) 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 @@ -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); @@ -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; @@ -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; |