From 588f820301bf298496e7bf0e6dea7b2c60ab3936 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 23 Oct 2016 19:16:26 +0000 Subject: [PATCH] specing out the NAT service IPC messages' --- src/nat/nat.h | 190 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 179 insertions(+), 11 deletions(-) diff --git a/src/nat/nat.h b/src/nat/nat.h index e7bee54c0..9ab402c1d 100644 --- a/src/nat/nat.h +++ b/src/nat/nat.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2011 GNUnet e.V. + Copyright (C) 2011, 2016 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -66,7 +66,37 @@ struct GNUNET_NAT_TestMessage /** - * + * Flags specifying the events this client would be + * interested in being told about. + */ +enum GNUNET_NAT_RegisterFlags +{ + /** + * This client does not want any notifications. + */ + GNUNET_NAT_RF_NONE = 0, + + /** + * This client wants to be informed about our IPv4 address + * changing. + */ + GNUNET_NAT_RF_IPV4 = 1, + + /** + * This client wants to be informed about changes to our + * external addresses. + */ + GNUNET_NAT_RF_ADDRESSES = 2, + + /** + * This client supports address reversal. + */ + GNUNET_NAT_RF_REVERSAL = 4 +}; + + +/** + * Message sent by a client to register with its addresses. */ struct GNUNET_NAT_RegisterMessage { @@ -74,11 +104,38 @@ struct GNUNET_NAT_RegisterMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_REGISTER */ struct GNUNET_MessageHeader header; + + /** + * An `enum GNUNET_NAT_RegisterFlags`. + */ + uint8_t flags GNUNET_PACKED; + + /** + * Client's IPPROTO, e.g. IPPROTO_UDP or IPPROTO_TCP. + */ + uint8_t proto GNUNET_PACKED; + + /** + * Port we would like as we are configured to use this one for + * advertising (in addition to the one we are binding to). + */ + uint16_t adv_port GNUNET_PACKED; + + /** + * Number of addresses that this service is bound to that follow. + * Given as an array of "struct sockaddr" entries, the size of + * each entry being determined by the "sa_family" at the beginning. + */ + uint16_t num_addrs GNUNET_PACKED; + + /* Followed by @e num_addrs addresses of type 'struct + sockaddr' */ + }; /** - * + * Client telling the service to (possibly) handle a STUN message. */ struct GNUNET_NAT_HandleStunMessage { @@ -86,11 +143,25 @@ struct GNUNET_NAT_HandleStunMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN */ struct GNUNET_MessageHeader header; + + /** + * Size of the sender address included, in NBO. + */ + uint16_t sender_addr_size; + + /** + * Number of bytes of payload included, in NBO. + */ + uint16_t payload_size; + + /* followed by a `struct sockaddr` of @e sender_addr_size bytes */ + + /* followed by payload with @e payload_size bytes */ }; /** - * + * Client asking the service to initiate connection reversal. */ struct GNUNET_NAT_RequestConnectionReversalMessage { @@ -98,11 +169,26 @@ struct GNUNET_NAT_RequestConnectionReversalMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL */ struct GNUNET_MessageHeader header; + + /** + * Size of the local address included, in NBO. + */ + uint16_t local_addr_size; + + /** + * Size of the remote address included, in NBO. + */ + uint16_t remote_addr_size; + + /* followed by a `struct sockaddr` of @e local_addr_size bytes */ + + /* followed by a `struct sockaddr` of @e remote_addr_size bytes */ + }; /** - * + * Service telling a client that connection reversal was requested. */ struct GNUNET_NAT_ConnectionReversalRequestedMessage { @@ -110,11 +196,27 @@ struct GNUNET_NAT_ConnectionReversalRequestedMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED */ struct GNUNET_MessageHeader header; + + /** + * Size of the local address where we received the request, in NBO. + */ + uint16_t local_addr_size; + + /** + * Size of the remote address making the request, in NBO. + */ + uint16_t remote_addr_size; + + /* followed by a `struct sockaddr` of @e local_addr_size bytes */ + + /* followed by a `struct sockaddr` of @e remote_addr_size bytes */ + }; /** - * + * Service notifying the client about changes in the set of + * addresses it has. */ struct GNUNET_NAT_AddressChangeNotificationMessage { @@ -122,11 +224,20 @@ struct GNUNET_NAT_AddressChangeNotificationMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE */ struct GNUNET_MessageHeader header; + + /** + * #GNUNET_YES to add, #GNUNET_NO to remove the address from the list. + */ + int32_t add_remove GNUNET_PACKED; + + /* followed by a `struct sockaddr` */ + }; /** - * + * Service notifying the client about a change of our + * known external IPv4 address. */ struct GNUNET_NAT_Ipv4ChangeNotificationMessage { @@ -134,11 +245,22 @@ struct GNUNET_NAT_Ipv4ChangeNotificationMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_IPV4_CHANGE */ struct GNUNET_MessageHeader header; + + /** + * #GNUNET_YES to add, #GNUNET_NO to remove the address from the list. + */ + int32_t add_remove GNUNET_PACKED; + + /** + * IPv4 address affected. + */ + struct in_addr addr GNUNET_PACKED; + }; /** - * + * Client requesting test of network connectivity. */ struct GNUNET_NAT_RequestTestMessage { @@ -146,11 +268,37 @@ struct GNUNET_NAT_RequestTestMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_REQUEST_TEST */ struct GNUNET_MessageHeader header; + + /** + * Port to bind to, in NBO + */ + uint16_t bind_port GNUNET_PACKED; + + /** + * Port external verifier should try to connect to, in NBO. + */ + uint16_t extern_port GNUNET_PACKED; + + /** + * IPv4 to bind to, in NBO. + */ + struct in_addr bind_ip GNUNET_PACKED; + + /** + * IPv4 external verifier should try to connect to, in NBO. + */ + struct in_addr extern_ip GNUNET_PACKED; + + /** + * IP protocol to use, i.e. IPPROTO_UDP or IPPROTO_TCP. + */ + uint8_t proto; + }; /** - * + * Service responding with network connectivity test result. */ struct GNUNET_NAT_TestResultMessage { @@ -158,11 +306,16 @@ struct GNUNET_NAT_TestResultMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_TEST_RESULT */ struct GNUNET_MessageHeader header; + + /** + * An `enum GNUNET_NAT_StatusCode` in NBO. + */ + int32_t status_code GNUNET_PACKED; }; /** - * + * Client requesting automatic configuration. */ struct GNUNET_NAT_AutoconfigRequestMessage { @@ -170,11 +323,14 @@ struct GNUNET_NAT_AutoconfigRequestMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG */ struct GNUNET_MessageHeader header; + + /* Followed by configuration (diff, serialized, compressed) */ + }; /** - * + * Service responding with proposed configuration. */ struct GNUNET_NAT_AutoconfigResultMessage { @@ -182,6 +338,18 @@ struct GNUNET_NAT_AutoconfigResultMessage * Header with type #GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT */ struct GNUNET_MessageHeader header; + + /** + * An `enum GNUNET_NAT_StatusCode` in NBO. + */ + int32_t status_code GNUNET_PACKED; + + /** + * An `enum GNUNET_NAT_Type` in NBO. + */ + int32_t type GNUNET_PACKED; + + /* Followed by configuration (diff, serialized, compressed) */ }; -- 2.25.1