diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-10-19 17:12:49 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-10-19 17:12:49 +0200 |
commit | c03f985b99f365d97c450a785dc75523d386020b (patch) | |
tree | c103a6ca7976bf24c47568823a13fc8f4a6661a4 /src | |
parent | 7982387d5fea3dbc4825e0b1eaccd0a2af0eb061 (diff) | |
download | fastd-c03f985b99f365d97c450a785dc75523d386020b.tar fastd-c03f985b99f365d97c450a785dc75523d386020b.zip |
Get rid of packet.h
Diffstat (limited to 'src')
-rw-r--r-- | src/handshake.c | 17 | ||||
-rw-r--r-- | src/handshake.h | 6 | ||||
-rw-r--r-- | src/packet.h | 48 | ||||
-rw-r--r-- | src/protocol_ec25519_fhmqvc.c | 8 | ||||
-rw-r--r-- | src/receive.c | 1 | ||||
-rw-r--r-- | src/send.c | 1 | ||||
-rw-r--r-- | src/types.h | 9 |
7 files changed, 27 insertions, 63 deletions
diff --git a/src/handshake.c b/src/handshake.c index 8447b3f..47da0e4 100644 --- a/src/handshake.c +++ b/src/handshake.c @@ -25,7 +25,6 @@ #include "handshake.h" -#include "packet.h" #include "peer.h" @@ -90,7 +89,7 @@ fastd_buffer_t fastd_handshake_new_init(fastd_context_t *ctx, size_t tail_space) size_t method_list_len; uint8_t *method_list = create_method_list(ctx, &method_list_len); - fastd_buffer_t buffer = fastd_buffer_alloc(ctx, sizeof(fastd_packet_t), 0, + fastd_buffer_t buffer = fastd_buffer_alloc(ctx, sizeof(fastd_handshake_packet_t), 0, 2*5 + /* handshake type, mode */ 6 + /* MTU */ 4+version_len + /* version name */ @@ -99,7 +98,7 @@ fastd_buffer_t fastd_handshake_new_init(fastd_context_t *ctx, size_t tail_space) 4+method_list_len + /* supported method name list */ tail_space ); - fastd_packet_t *request = buffer.data; + fastd_handshake_packet_t *request = buffer.data; request->rsv1 = 0; request->rsv2 = 0; @@ -141,13 +140,13 @@ fastd_buffer_t fastd_handshake_new_reply(fastd_context_t *ctx, const fastd_hands extra_size = 6 + /* MTU */ 4+version_len; /* version name */ - fastd_buffer_t buffer = fastd_buffer_alloc(ctx, sizeof(fastd_packet_t), 1, + fastd_buffer_t buffer = fastd_buffer_alloc(ctx, sizeof(fastd_handshake_packet_t), 1, 2*5 + /* handshake type, reply code */ 4+method_len + /* method name */ extra_size + tail_space ); - fastd_packet_t *request = buffer.data; + fastd_handshake_packet_t *request = buffer.data; request->rsv1 = 0; request->rsv2 = 0; @@ -179,13 +178,13 @@ static fastd_string_stack_t* parse_string_list(const uint8_t *data, size_t len) } void fastd_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, fastd_buffer_t buffer) { - if (buffer.len < sizeof(fastd_packet_t)) { + if (buffer.len < sizeof(fastd_handshake_packet_t)) { pr_warn(ctx, "received a short handshake from %I", remote_addr); goto end_free; } fastd_handshake_t handshake = { .buffer = buffer }; - fastd_packet_t *packet = buffer.data; + fastd_handshake_packet_t *packet = buffer.data; uint8_t *ptr = packet->tlv_data; while (true) { @@ -290,8 +289,8 @@ void fastd_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fa send_reply: if (reply_code) { - fastd_buffer_t reply_buffer = fastd_buffer_alloc(ctx, sizeof(fastd_packet_t), 0, 3*5 /* enough space for handshake type, reply code and error detail */); - fastd_packet_t *reply = reply_buffer.data; + fastd_buffer_t reply_buffer = fastd_buffer_alloc(ctx, sizeof(fastd_handshake_packet_t), 0, 3*5 /* enough space for handshake type, reply code and error detail */); + fastd_handshake_packet_t *reply = reply_buffer.data; reply->rsv1 = 0; reply->rsv2 = 0; diff --git a/src/handshake.h b/src/handshake.h index 6415d5e..2fae1ad 100644 --- a/src/handshake.h +++ b/src/handshake.h @@ -58,6 +58,12 @@ typedef enum fastd_reply_code { } fastd_reply_code_t; +typedef struct __attribute__((__packed__)) fastd_handshake_packet { + uint8_t rsv1; + uint16_t rsv2; + uint8_t tlv_data[]; +} fastd_handshake_packet_t; + typedef struct fastd_handshake_record { size_t length; uint8_t *data; diff --git a/src/packet.h b/src/packet.h deleted file mode 100644 index 01f77fb..0000000 --- a/src/packet.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) 2012-2013, Matthias Schiffer <mschiffer@universe-factory.net> - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef _FASTD_PACKET_H_ -#define _FASTD_PACKET_H_ - -#include <stdint.h> - - -#define PACKET_TYPE_LEN 1 - - -typedef enum fastd_packet_type { - PACKET_UNKNOWN = 0, - PACKET_HANDSHAKE, - PACKET_DATA, -} fastd_packet_type_t; - -typedef struct __attribute__((__packed__)) fastd_packet { - uint8_t rsv1; - uint16_t rsv2; - uint8_t tlv_data[]; -} fastd_packet_t; - -#endif /* _FASTD_PACKET_H_ */ diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c index 622f633..c3419d5 100644 --- a/src/protocol_ec25519_fhmqvc.c +++ b/src/protocol_ec25519_fhmqvc.c @@ -386,7 +386,7 @@ static void respond_handshake(fastd_context_t *ctx, const fastd_socket_t *sock, memset(&hmacbuf, 0, sizeof(hmacbuf)); fastd_handshake_add(ctx, &buffer, RECORD_HANDSHAKE_MAC, HASHBYTES, hmacbuf.b); - fastd_hmacsha256(&hmacbuf, peer->protocol_state->shared_handshake_key.w, buffer.data+3, buffer.len-3); + fastd_hmacsha256(&hmacbuf, peer->protocol_state->shared_handshake_key.w, buffer.data+sizeof(fastd_handshake_packet_t), buffer.len-sizeof(fastd_handshake_packet_t)); memcpy(buffer.data+buffer.len-HASHBYTES, hmacbuf.b, HASHBYTES); fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer); @@ -517,7 +517,7 @@ static void finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, const f memcpy(mac, handshake->records[RECORD_HANDSHAKE_MAC].data, HASHBYTES); memset(handshake->records[RECORD_HANDSHAKE_MAC].data, 0, HASHBYTES); - valid = fastd_hmacsha256_verify(mac, shared_handshake_key.w, handshake->buffer.data+3, handshake->buffer.len-3); + valid = fastd_hmacsha256_verify(mac, shared_handshake_key.w, handshake->buffer.data+sizeof(fastd_handshake_packet_t), handshake->buffer.len-sizeof(fastd_handshake_packet_t)); } else { valid = fastd_hmacsha256_blocks_verify(handshake->records[RECORD_T].data, shared_handshake_key.w, peer->protocol_config->public_key.p, peer_handshake_key->p, NULL); @@ -548,7 +548,7 @@ static void finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, const f memset(&hmacbuf, 0, sizeof(hmacbuf)); fastd_handshake_add(ctx, &buffer, RECORD_HANDSHAKE_MAC, HASHBYTES, hmacbuf.b); - fastd_hmacsha256(&hmacbuf, shared_handshake_key.w, buffer.data+3, buffer.len-3); + fastd_hmacsha256(&hmacbuf, shared_handshake_key.w, buffer.data+sizeof(fastd_handshake_packet_t), buffer.len-sizeof(fastd_handshake_packet_t)); memcpy(buffer.data+buffer.len-HASHBYTES, hmacbuf.b, HASHBYTES); fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer); @@ -568,7 +568,7 @@ static void handle_finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, memcpy(mac, handshake->records[RECORD_HANDSHAKE_MAC].data, HASHBYTES); memset(handshake->records[RECORD_HANDSHAKE_MAC].data, 0, HASHBYTES); - valid = fastd_hmacsha256_verify(mac, peer->protocol_state->shared_handshake_key.w, handshake->buffer.data+3, handshake->buffer.len-3); + valid = fastd_hmacsha256_verify(mac, peer->protocol_state->shared_handshake_key.w, handshake->buffer.data+sizeof(fastd_handshake_packet_t), handshake->buffer.len-sizeof(fastd_handshake_packet_t)); } else { valid = fastd_hmacsha256_blocks_verify(handshake->records[RECORD_T].data, peer->protocol_state->shared_handshake_key.w, peer->protocol_config->public_key.p, peer_handshake_key->p, NULL); diff --git a/src/receive.c b/src/receive.c index d91a5cd..9bf127d 100644 --- a/src/receive.c +++ b/src/receive.c @@ -26,7 +26,6 @@ #include "fastd.h" #include "handshake.h" -#include "packet.h" #include "peer.h" @@ -25,7 +25,6 @@ #include "fastd.h" -#include "packet.h" #include "peer.h" diff --git a/src/types.h b/src/types.h index e817f2e..16b1a5a 100644 --- a/src/types.h +++ b/src/types.h @@ -52,6 +52,15 @@ static const fastd_tristate_t fastd_tristate_false = {true, false}; static const fastd_tristate_t fastd_tristate_undef = {false, false}; +#define PACKET_TYPE_LEN 1 + + +typedef enum fastd_packet_type { + PACKET_UNKNOWN = 0, + PACKET_HANDSHAKE, + PACKET_DATA, +} fastd_packet_type_t; + typedef enum fastd_mode { MODE_TAP, MODE_TUN, |