Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng_icmpv6: Initial import #2555

Merged
merged 4 commits into from
May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ ifneq (,$(filter ng_sixlowpan_ctx,$(USEMODULE)))
USEMODULE += vtimer
endif

ifneq (,$(filter ng_icmpv6_echo,$(USEMODULE)))
USEMODULE += ng_icmpv6
USEMODULE += ng_netbase
endif

ifneq (,$(filter ng_icmpv6,$(USEMODULE)))
USEMODULE += ng_ipv6
endif

ifneq (,$(filter ng_ipv6_hdr,$(USEMODULE)))
USEMODULE += ng_inet_csum
USEMODULE += ng_pktbuf
Expand All @@ -63,6 +72,7 @@ ifneq (,$(filter ng_ipv6_router,$(USEMODULE)))
endif

ifneq (,$(filter ng_ipv6,$(USEMODULE)))
USEMODULE += ng_icmpv6
USEMODULE += ng_inet_csum
USEMODULE += ng_ipv6_addr
USEMODULE += ng_ipv6_hdr
Expand Down
6 changes: 6 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ endif
ifneq (,$(filter oneway_malloc,$(USEMODULE)))
DIRS += oneway-malloc
endif
ifneq (,$(filter ng_icmpv6,$(USEMODULE)))
DIRS += net/network_layer/ng_icmpv6
endif
ifneq (,$(filter ng_icmpv6_echo,$(USEMODULE)))
DIRS += net/network_layer/ng_icmpv6/echo
endif
ifneq (,$(filter ng_ipv6,$(USEMODULE)))
DIRS += net/network_layer/ng_ipv6
endif
Expand Down
103 changes: 103 additions & 0 deletions sys/include/net/ng_icmpv6.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for
* more details.
*/

/**
* @defgroup net_ng_icmpv6 Internet Control Message Protocol for IPv6
* @ingroup net_ng_ipv6
* @brief Basic implementation of ICMPv6
*
* @see <a href="https://tools.ietf.org/html/rfc4443">
* RFC 4443
* </a>
* @{
*
* @file
* @brief Definitions for ICMPv6
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/

#ifndef NG_ICMPV6_H_
#define NG_ICMPV6_H_

#include <inttypes.h>

#include "byteorder.h"
#include "kernel_types.h"
#include "net/ng_ipv6/hdr.h"
#include "net/ng_nettype.h"
#include "net/ng_nettype.h"
#include "net/ng_pkt.h"

#include "net/ng_icmpv6/echo.h"
#include "net/ng_icmpv6/error.h"
#include "net/ng_icmpv6/types.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief General ICMPv6 message format.
*
* @see <a href="https://tools.ietf.org/html/rfc4443#section-2.1">
* RFC 4443, section 2.1
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
} ng_icmpv6_hdr_t;

/**
* @brief Demultiplexes a received ICMPv6 packet according to its type field.
*
* @param[in] iface The receiving interface
* @param[in] pkt The packet to demultiplex.
*/
void ng_icmpv6_demux(kernel_pid_t iface, ng_pktsnip_t *pkt);

/**
* @brief Builds an ICMPv6 message for sending.
*
* @param[in] type Type for the ICMPv6 message.
* @param[in] code Code for the ICMPv6 message.
* @param[in] size Size of the ICMPv6 message (needs do be >
* `sizeof(ng_icmpv6_hdr_t)`).
*
* @return The ICMPv6 message on success
* @return NULL, on failure
*/
ng_pktsnip_t *ng_icmpv6_build(uint8_t type, uint8_t code, size_t size);

/* TODO: build error messages */

/**
* @brief Calculates the checksum for an ICMPv6 packet.
*
* @param[in] hdr The header the checksum should be calculated
* for.
* @param[in] pseudo_hdr The header the pseudo header shall be generated
* from. NULL if none is needed.
*
* @return 0, on success.
* @return -EINVAL, if ng_pktsnip_t::type of @p pkt was not NG_NETTYPE_ICMPV6
* @return -ENOENT, if ng_pktsnip_t::type of @p pseudo_hdr was not
* NG_NETTYPE_IPV6
*/
int ng_icmpv6_calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr);

#ifdef __cplusplus
}
#endif

#endif /* NG_ICMPV6_H_ */
/**
* @}
*/
129 changes: 129 additions & 0 deletions sys/include/net/ng_icmpv6/echo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup net_ng_icmpv6_echo ICMPv6 echo messages
* @ingroup net_ng_icmpv6
* @brief ICMPv6 echo request and reply
* @{
*
* @file
* @brief ICMPv6 echo message definitions
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_ICMPV6_ECHO_H_
#define NG_ICMPV6_ECHO_H_

#include <inttypes.h>

#include "byteorder.h"
#include "kernel_types.h"
#include "net/ng_icmpv6/types.h"
#include "net/ng_ipv6/hdr.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Echo request and response message format.
* @extends ng_icmpv6_hdr_t
*
* @see <a href="https://tools.ietf.org/html/rfc4443#section-4.1">
* RFC 4443, section 4.1
* </a>
* @see <a href="https://tools.ietf.org/html/rfc4443#section-4.2">
* RFC 4443, section 4.2
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
network_uint16_t id; /**< identifier */
network_uint16_t seq; /**< Sequence number */
} ng_icmpv6_echo_t;

/**
* @brief Builds an ICMPv6 echo message of type @p type for sending.
*
* @param[in] type Type of the echo message. Expected to be either
* NG_ICMPV6_ECHO_REQ or NG_ICMPV6_ECHO_REP.
* @param[in] id ID for the echo message in host byte-order
* @param[in] seq Sequence number for the echo message in host byte-order
* @param[in] data Payload for the echo message
* @param[in] data_len Length of @p data
*
* @return The echo message on success
* @return NULL, on failure
*/
ng_pktsnip_t *ng_icmpv6_echo_build(uint8_t type, uint16_t id, uint16_t seq,
uint8_t *data, size_t data_len);

/**
* @brief Builds an ICMPv6 echo request for sending.
*
* @see <a href="https://tools.ietf.org/html/rfc4443#section-4.1">
* RFC 4443, section 4.1
* </a>
*
* @param[in] id ID for the echo request in host byte-order
* @param[in] seq Sequence number for the echo request in host byte-order
* @param[in] data Payload for the echo request
* @param[in] data_len Length of @p data
*
* @return The echo request message on success
* @return NULL, on failure
*/
static inline ng_pktsnip_t *ng_icmpv6_echo_req_build(uint16_t id, uint16_t seq,
uint8_t *data, size_t data_len)
{
return ng_icmpv6_echo_build(NG_ICMPV6_ECHO_REQ, id, seq, data, data_len);
}

/**
* @brief Builds an ICMPv6 echo reply for sending.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this in the public header?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So an application (I'm thinking test applications specifically here) can build it easily.

*
* @see <a href="https://tools.ietf.org/html/rfc4443#section-4.2">
* RFC 4443, section 4.2
* </a>
*
* @param[in] id ID for the echo reply in host byte-order
* @param[in] seq Sequence number for the echo reply in host byte-order
* @param[in] data Payload for the echo reply
* @param[in] data_len Length of @p data
*
* @return The echo reply message on success
* @return NULL, on failure
*/
static inline ng_pktsnip_t *ng_icmpv6_echo_rep_build(uint16_t id, uint16_t seq,
uint8_t *data, size_t data_len)
{
return ng_icmpv6_echo_build(NG_ICMPV6_ECHO_REP, id, seq, data, data_len);
}


/**
* @brief ICMPv6 echo request handler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ng_icmpv6_demux() can call this submodule-function.

*
* @param[in] iface The interface the echo requuest was received on.
* @param[in] ipv6_hdr The IPv6 header of the echo request.
* @param[in] echo The Echo Request message.
* @param[in] len Length of the echo request message (ng_ipv6_hdr_t::len
* of @p ipv6_hdr minus length of extension headers).
*/
void ng_icmpv6_echo_req_handle(kernel_pid_t iface, ng_ipv6_hdr_t *ipv6_hdr,
ng_icmpv6_echo_t *echo, uint16_t len);

#ifdef __cplusplus
}
#endif

#endif /* NG_ICMPV6_ECHO_H_ */
/** @} */
Loading