Skip to content

Commit

Permalink
ng_ipv6: initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 7, 2015
1 parent b081d15 commit beeca50
Show file tree
Hide file tree
Showing 6 changed files with 1,247 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ endif
ifneq (,$(filter oneway_malloc,$(USEMODULE)))
DIRS += oneway-malloc
endif
ifneq (,$(filter ng_ipv6,$(USEMODULE)))
DIRS += net/network_layer/ng_ipv6
endif
ifneq (,$(filter ng_ipv6_addr,$(USEMODULE)))
DIRS += net/network_layer/ng_ipv6/addr
endif
Expand Down
273 changes: 272 additions & 1 deletion sys/include/net/ng_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,138 @@
* @defgroup net_ng_ipv6 IPv6
* @ingroup net
* @brief New IPv6 implementation
*
* The IPv6 control thread understands messages of type
*
* * @ref NG_NETAPI_MSG_TYPE_RCV,
* * @ref NG_NETAPI_MSG_TYPE_SND,
* * @ref NG_NETAPI_MSG_TYPE_GET, and
* * @ref NG_NETAPI_MSG_TYPE_SET
*
* For @ref NG_NETAPI_MSG_TYPE_GET the following values are supported for
* ng_netapi_opt_t::opt
*
* * @ref NETCONF_OPT_ADDRESS : Get IPv6 addresses
* - ng_netapi_opt_t::context:
* + **expected type:** kernel_pid_t
* + **description**: identifies an interface (via its PID) of which
* you want the IPv6 addresses from. Can be @ref KERNEL_PID_UNDEF
* for all interfaces.
* - ng_netapi_opt_t::data:
* + **expected type:** ng_ipv6_addr_t*
* + **precondition:** unequal NULL
* + **description:** Will be set to an array of all IPv6 addresses
* registered to the interface identified by ng_netapi_opt_t::context.
* - ng_netapi_opt_t::data_len:
* + **precondition:** greater than or equal to `sizeof(ng_ipv6_addr_t)`
* + **description:** Will be set to `sizeof(ng_ipv6_addr_t) * array_size`.
* If it is shorter than required, the data will be truncated to the
* last fitting IPv6 address.
* - @ref NG_NETAPI_MSG_TYPE_ACK values:
* + 0 on success
* + -EFAULT, if ng_netapi_opt_t::data was NULL
* + -ENOENT, if ng_netapi_opt_t::context was unequal @ref KERNEL_PID_UNDEF
* and interface specified by it does not exist
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was lesser than
* `sizeof(ng_ipv6_addr_t)`
* * @ref NETCONF_OPT_ADDR_LEN : Get IPv6 address length
* - ng_netapi_opt_t::context:
* + **ignored**
* - ng_netapi_opt_t::data:
* + **expected type:** uint16_t
* + **precondition:** unequal NULL
* + **description:** Will always be set to `sizeof(ng_ipv6_addr_t)`
* - ng_netapi_opt_t::data_len:
* + **precondition:** equal to `sizeof(uint16_t)`
* - @ref NG_NETAPI_MSG_TYPE_ACK values:
* + 0 on success
* + -EFAULT, if ng_netapi_opt_t::data was NULL
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was unequal to
* `sizeof(uint16_t)`
* * @ref NETCONF_OPT_MIN_PACKET_SIZE : Get MTU
* - ng_netapi_opt_t::context:
* + **expected type:** kernel_pid_t
* + **description**: identifies an interface (via its PID) of which
* you want the MTU from. Can be @ref KERNEL_PID_UNDEF for the
* minimum MTU of all interfaces.
* - ng_netapi_opt_t::data:
* + **expected type:** uint16_t
* + **precondition:** unequal NULL
* + **description:** Will be set to the MTU set to the interface
* identified by ng_netapi_opt_t::context.
* - ng_netapi_opt_t::data_len:
* + **precondition:** equal to `sizeof(uint16_t)`
* - @ref NG_NETAPI_MSG_TYPE_ACK values:
* + 0 on success
* + -EFAULT, if ng_netapi_opt_t::data was NULL
* + -ENOENT, if ng_netapi_opt_t::context was unequal @ref KERNEL_PID_UNDEF
* and interface specified by it does not exist
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was unequal to
* `sizeof(uint16_t)`
* * @ref NETCONF_OPT_PROTO : Get the protocol of this layer.
* - ng_netapi_opt_t::context:
* + **ignored**:
* - ng_netapi_opt_t::data:
* + **expected type:** ng_nettype_t
* + **precondition:** unequal NULL
* + **description:** Will always be set to `NG_NETTYPE_IPV6`
* - ng_netapi_opt_t::data_len:
* + **precondition:** equal to `sizeof(ng_nettype_t)`
* - @ref NG_NETAPI_MSG_TYPE_ACK values:
* + 0 on success
* + -EFAULT, if ng_netapi_opt_t::data was NULL
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was unequal to
* `sizeof(ng_nettype_t)`
*
* For @ref NG_NETAPI_MSG_TYPE_SET the following values are supported for
* ng_netapi_opt_t::opt
*
* * @ref NETCONF_OPT_ADDRESS : Add or remove IPv6 addresses
* - ng_netapi_opt_t::context:
* + **expected type:** kernel_pid_t
* + **precondition**: unequal @ref KERNEL_PID_UNDEF
* + **description**: identifies an interface (via its PID) of which
* you want to add the IPv6 address to or remove it from.
* - ng_netapi_opt_t::data:
* + **expected type:** ng_ipv6_addr_t
* + **precondition:** unequal NULL
* + **description:** An IPv6 address. If the address does not exist
* on the interface it will be added, if it already exists it will
* be removed.
* - ng_netapi_opt_t::data_len:
* + **precondition:** equal to `sizeof(ng_ipv6_addr_t)`
* - @ref NG_NETAPI_MSG_TYPE_ACK values:
* + 0 on success
* + -EFAULT, if ng_netapi_opt_t::data was NULL
* + -EINVAL, if ng_netapi_opt_t::data was the unspecified address
* (all zero)
* + -ENOENT, if ng_netapi_opt_t::context was @ref KERNEL_PID_UNDEF
* or interface specified by it does not exist
* + -ENOMEM, if there is no space left to store the address in
* ng_netapi_opt_t::data.
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was unequal to
* `sizeof(ng_ipv6_addr_t)`
* * @ref NETCONF_OPT_MIN_PACKET_SIZE : Set MTU
* - ng_netapi_opt_t::context:
* + **expected type:** kernel_pid_t
* + **description**: identifies an interface (via its PID) of which
* you want set the MTU for.
* - ng_netapi_opt_t::data:
* + **expected type:** uint16_t
* + **precondition:** unequal NULL
* + **description:** The MTU for the interface identified by
* ng_netapi_opt_t::context.
* - ng_netapi_opt_t::data_len:
* + **precondition:** equal to `sizeof(uint16_t)`
* - @ref NG_NETAPI_MSG_TYPE_ACK values:
* + 0 on success
* + -EFAULT, if ng_netapi_opt_t::data was NULL
* + -ENOENT, if ng_netapi_opt_t::context was @ref KERNEL_PID_UNDEF
* or interface specified by it does not exist
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was unequal to
* + -EOVERFLOW, if ng_netapi_opt_t::data_len was unequal to
* `sizeof(uint16_t)`
*
* @{
*
* @file
Expand All @@ -22,13 +154,38 @@
#ifndef NG_IPV6_H_
#define NG_IPV6_H_

#include "kernel_types.h"
#include "net/ng_pkt.h"
#include "net/ng_netapi.h"

#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/netif.h"
#include "net/ng_ipv6/hdr.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Default stack size to use for the IPv6 thread
*/
#ifndef NG_IPV6_STACK_SIZE
#define NG_IPV6_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
#endif

/**
* @brief Default name for the IPv6 thread
*/
#ifndef NG_IPV6_THREAD_NAME
#define NG_IPV6_THREAD_NAME "IPv6"
#endif

/**
* @brief Default message queue size to use for the IPv6 thread.
*/
#ifndef NG_IPV6_MSG_QUEUE_SIZE
#define NG_IPV6_MSG_QUEUE_SIZE (8U)
#endif

/**
* @brief Default maximum transition unit
*
Expand All @@ -38,6 +195,120 @@ extern "C" {
*/
#define NG_IPV6_DEFAULT_MTU (1280)

/**
* @brief Initialization of the IPv6 thread.
*
* @param[in] priority The priority for the IPv6 thread
*
* @return The PID to the IPv6 thread, on success.
* @return a negative errno on error.
* @return -EINVAL, if @p priority is higher or equal @ref SCHED_PRIO_LEVELS
* @return -EOVERFLOW, if there are too many threads running already
* @return -EEXIST, if IPv6 was already initialized.
*/
kernel_pid_t ng_ipv6_init(char priority);

/**
* @brief Get all IPv6 addresses registered to one or all interfaces
*
* Wrapper for @ref NG_NETAPI_MSG_TYPE_GET with @ref NETCONF_OPT_ADDRESS.
*
* @param[in] ipv6_pid The PID of the IPv6 control thread.
* @param[in] iface The interface you want the IPv6 addresses from.
* Can be @ref KERNEL_PID_UNDEF for all interfaces.
* @param[out] addrs An array of IPv6 addresses. Must not be NULL
* @param[in] addrs_len The length of @p addrs. Must be greater than or equal
* to `sizeof(ng_ipv6_addr_t)`. If smaller than required
* for all addresses, the result in @p addrs will be
* truncated to the last fitting IPv6 address.
*
* @return 0 on success
* @return -EFAULT, if @p addrs was NULL.
* @return -ENOENT, if @p iface was unequal @ref KERNEL_PID_UNDEF and interface
* does not exist.
* @return -EOVERFLOW, if @p addrs_len was `< sizeof(ng_ipv6_addr_t)`.
*/
static inline int ng_ipv6_get_addresses(kernel_pid_t ipv6_pid, kernel_pid_t iface,
ng_ipv6_addr_t *addrs, uint16_t addrs_len)
{
return ng_netapi_get(ipv6_pid, NETCONF_OPT_ADDRESS, (uint16_t)iface,
addrs, addrs_len);
}

/**
* @brief Adds an IPv6 address to an interface or removes it from it.
*
* Wrapper for @ref NG_NETAPI_MSG_TYPE_SET with @ref NETCONF_OPT_ADDRESS.
*
* If @p addr does not exists on @p iface it will be added. If it already
* exists it will be removed.
*
* @param[in] ipv6_pid The PID of the IPv6 control thread.
* @param[in] iface The interface you want add the IPv6 address to or
* remove it from. Must not be @ref KERNEL_PID_UNDEF
* @param[in] addr An IPv6 address. Must not be NULL
*
* @return 0 on success
* @return -EINVAL, if @p addr was unspecified address (::).
* @return -EFAULT, if @p addr was NULL.
* @return -ENOMEM, if there is no space left to store @p addr.
* @return -ENOENT, if @p iface was @ref KERNEL_PID_UNDEF or interface
* does not exist.
*/
static inline int ng_ipv6_toggle_address(kernel_pid_t ipv6_pid, kernel_pid_t iface,
ng_ipv6_addr_t *addr)
{
return ng_netapi_set(ipv6_pid, NETCONF_OPT_ADDRESS, (uint16_t)iface,
addr, (uint16_t)sizeof(ng_ipv6_addr_t));
}

/**
* @brief Gets the MTU for an interface or of all interfaces
*
* @see <a href="https://tools.ietf.org/html/rfc2460#section-2">
* RFC 2460, section 2
* </a>
*
* @param[in] ipv6_pid The PID of the IPv6 control thread.
* @param[in] iface The interface you want the MTU from. Can be
* @ref KERNEL_PID_UNDEF for minimum MTU of all interfaces.
* @param[out] mtu The MTU of @p iface.
*
* @return 0 on success
* @return -EFAULT, if @p mtu was NULL.
* @return -ENOENT, if @p iface was unequal @ref KERNEL_PID_UNDEF and interface
* does not exist.
*/
static inline int ng_ipv6_get_mtu(kernel_pid_t ipv6_pid, kernel_pid_t iface,
uint16_t *mtu)
{
return ng_netapi_get(ipv6_pid, NETCONF_OPT_MIN_PACKET_SIZE, (uint16_t)iface,
mtu, (uint16_t)sizeof(uint16_t));
}

/**
* @brief Sets the MTU for an interface.
*
* @see <a href="https://tools.ietf.org/html/rfc2460#section-2">
* RFC 2460, section 2
* </a>
*
* @param[in] ipv6_pid The PID of the IPv6 control thread.
* @param[in] iface The interface you want add the IPv6 address to or
* remove it from. Must not be @ref KERNEL_PID_UNDEF
* @param[in] mtu The MTU for @p iface.
*
* @return -EFAULT, if @p mtu was NULL.
* @return -ENOENT, if @p iface was @ref KERNEL_PID_UNDEF or interface
* does not exist.
*/
static inline int ng_ipv6_set_mtu(kernel_pid_t ipv6_pid, kernel_pid_t iface,
uint16_t mtu)
{
return ng_netapi_set(ipv6_pid, NETCONF_OPT_MIN_PACKET_SIZE, (uint16_t)iface,
&mtu, (uint16_t)sizeof(uint16_t));
}

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit beeca50

Please sign in to comment.