0.01.00
ip6.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #ifndef IP6_HPP_
35 #define IP6_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <stddef.h>
40 
41 #include <openthread/ip6.h>
42 #include <openthread/udp.h>
43 
44 #include "common/encoding.hpp"
45 #include "common/locator.hpp"
46 #include "common/message.hpp"
47 #include "net/icmp6.hpp"
48 #include "net/ip6_address.hpp"
49 #include "net/ip6_headers.hpp"
50 #include "net/ip6_mpl.hpp"
51 #include "net/ip6_routes.hpp"
52 #include "net/netif.hpp"
53 #include "net/socket.hpp"
54 #include "net/udp6.hpp"
55 
56 using ot::Encoding::BigEndian::HostSwap16;
57 using ot::Encoding::BigEndian::HostSwap32;
58 
59 namespace ot {
60 
68 namespace Ip6 {
69 
101 class Ip6 : public InstanceLocator
102 {
103 public:
104  enum
105  {
106  kDefaultHopLimit = 64,
107  kMaxDatagramLength = 1280,
108  };
109 
118  Message *NewMessage(uint16_t aReserved);
119 
126  Ip6(otInstance &aInstance);
127 
139  otError SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto aIpProto);
140 
151  otError SendRaw(Message &aMessage, int8_t aInterfaceId);
152 
166  otError HandleDatagram(Message &aMessage, Netif *aNetif, int8_t aInterfaceId,
167  const void *aLinkMessageInfo, bool aFromNcpHost);
168 
169 
175  void EnqueueDatagram(Message &aMessage);
176 
186  static uint16_t UpdateChecksum(uint16_t aChecksum, const Address &aAddress);
187 
199  static uint16_t ComputePseudoheaderChecksum(const Address &aSource, const Address &aDestination,
200  uint16_t aLength, IpProto aProto);
201 
216  void SetReceiveDatagramCallback(otIp6ReceiveCallback aCallback, void *aCallbackContext);
217 
228  bool IsReceiveIp6FilterEnabled(void) { return mIsReceiveIp6FilterEnabled; }
229 
240  void SetReceiveIp6FilterEnabled(bool aEnabled) { mIsReceiveIp6FilterEnabled = aEnabled; }
241 
248  bool IsForwardingEnabled(void) { return mForwardingEnabled; }
249 
256  void SetForwardingEnabled(bool aEnable) { mForwardingEnabled = aEnable; }
257 
267  otError AddNetif(Netif &aNetif);
268 
278  otError RemoveNetif(Netif &aNetif);
279 
286  Netif *GetNetifList(void) { return mNetifListHead; }
287 
296  Netif *GetNetifById(int8_t aInterfaceId);
297 
307  bool IsUnicastAddress(const Address &aAddress);
308 
318 
327  int8_t GetOnLinkNetif(const Address &aAddress);
328 
335  const PriorityQueue &GetSendQueue(void) const { return mSendQueue; }
336 
343  Routes &GetRoutes(void) { return mRoutes; }
344 
351  Icmp &GetIcmp(void) { return mIcmp; }
352 
359  Udp &GetUdp(void) { return mUdp; }
360 
367  Mpl &GetMpl(void) { return mMpl; }
368 
375  static const char *IpProtoToString(IpProto aIpProto);
376 
377 private:
378  static void HandleSendQueue(Tasklet &aTasklet);
379  void HandleSendQueue(void);
380 
381  otError ProcessReceiveCallback(const Message &aMessage, const MessageInfo &aMessageInfo, uint8_t aIpProto,
382  bool aFromNcpHost);
383  otError HandleExtensionHeaders(Message &aMessage, Header &aHeader, uint8_t &aNextHeader, bool aForward,
384  bool aReceive);
385  otError HandleFragment(Message &aMessage);
386  otError AddMplOption(Message &aMessage, Header &aHeader);
387  otError AddTunneledMplOption(Message &aMessage, Header &aHeader, MessageInfo &aMessageInfo);
388  otError InsertMplOption(Message &aMessage, Header &aHeader, MessageInfo &aMessageInfo);
389  otError RemoveMplOption(Message &aMessage);
390  otError HandleOptions(Message &aMessage, Header &aHeader, bool &aForward);
391  otError HandlePayload(Message &aMessage, MessageInfo &aMessageInfo, uint8_t aIpProto);
392  int8_t FindForwardInterfaceId(const MessageInfo &aMessageInfo);
393 
394  static Ip6 &GetOwner(const Context &aContext);
395 
396  bool mForwardingEnabled;
397  bool mIsReceiveIp6FilterEnabled;
398  otIp6ReceiveCallback mReceiveIp6DatagramCallback;
399  void *mReceiveIp6DatagramCallbackContext;
400  Netif *mNetifListHead;
401 
402  PriorityQueue mSendQueue;
403  Tasklet mSendQueueTask;
404 
405  Routes mRoutes;
406  Icmp mIcmp;
407  Udp mUdp;
408  Mpl mMpl;
409 
410 };
411 
417 } // namespace Ip6
418 } // namespace ot
419 
420 #endif // NET_IP6_HPP_
This class implements IPv6 header generation and parsing.
Definition: ip6_headers.hpp:136
otError HandleDatagram(Message &aMessage, Netif *aNetif, int8_t aInterfaceId, const void *aLinkMessageInfo, bool aFromNcpHost)
This method processes a received IPv6 datagram.
Definition: ip6.cpp:694
const PriorityQueue & GetSendQueue(void) const
This method returns a reference to the send queue.
Definition: ip6.hpp:335
This type represents all the static / global variables used by OpenThread allocated in one place...
Definition: openthread-instance.h:59
bool IsUnicastAddress(const Address &aAddress)
This method indicates whether or not aAddress is assigned to a network interface. ...
Definition: ip6.cpp:953
Definition: cli.cpp:90
Netif * GetNetifList(void)
This method returns the network interface list.
Definition: ip6.hpp:286
This file includes definitions for IPv6 addresses.
This class implements an IPv6 address object.
Definition: ip6_address.hpp:60
This file includes definitions for locator class for OpenThread objects.
This file defines the OpenThread IPv6 API.
void SetForwardingEnabled(bool aEnable)
This method enables/disables IPv6 forwarding.
Definition: ip6.hpp:256
otError SendRaw(Message &aMessage, int8_t aInterfaceId)
This method sends a raw IPv6 datagram with a fully formed IPv6 header.
Definition: ip6.cpp:661
This class implements ICMPv6.
Definition: icmp6.hpp:225
Icmp & GetIcmp(void)
This method returns a reference to the ICMP6 controller instance.
Definition: ip6.hpp:351
Routes & GetRoutes(void)
This method returns a reference to the IPv6 route management instance.
Definition: ip6.hpp:343
This class implements message information for an IPv6 message.
Definition: socket.hpp:57
This file includes definitions for manipulating IPv6 routing tables.
This class implements IPv6 route management.
Definition: ip6_routes.hpp:74
This class is used to represent a tasklet.
Definition: tasklet.hpp:64
otError RemoveNetif(Netif &aNetif)
This method disables the network interface.
Definition: ip6.cpp:906
This file includes definitions for MPL.
This class implements the core IPv6 message processing.
Definition: ip6.hpp:101
otError AddNetif(Netif &aNetif)
This method enables the network interface.
Definition: ip6.cpp:875
This file includes definitions for UDP/IPv6 sockets.
Ip6(otInstance &aInstance)
This constructor initializes the object.
Definition: ip6.cpp:53
IpProto
Internet Protocol Numbers.
Definition: ip6_headers.hpp:93
This class implements an IPv6 network interface unicast address.
Definition: netif.hpp:85
This class implements definitions for maintaining a pointer to arbitrary context information.
Definition: context.hpp:61
This class represents a message.
Definition: message.hpp:195
This file includes definitions for IPv6 sockets.
This file includes definitions for the message buffer pool and message buffers.
void SetReceiveIp6FilterEnabled(bool aEnabled)
This method sets whether or not Thread control traffic is filtered out when delivering IPv6 datagrams...
Definition: ip6.hpp:240
This class implements locator for otInstance object.
Definition: locator.hpp:63
This file includes definitions for byte-ordering encoding.
static uint16_t UpdateChecksum(uint16_t aChecksum, const Address &aAddress)
This static method updates a checksum.
Definition: ip6.cpp:75
bool IsForwardingEnabled(void)
This method indicates whether or not IPv6 forwarding is enabled.
Definition: ip6.hpp:248
This class implements core UDP message handling.
Definition: udp6.hpp:167
Netif * GetNetifById(int8_t aInterfaceId)
This method returns the network interface identified by aInterfaceId.
Definition: ip6.cpp:937
static const char * IpProtoToString(IpProto aIpProto)
This static method converts an IpProto enumeration to a string.
Definition: ip6.cpp:1129
This class implements a priority queue.
Definition: message.hpp:932
const NetifUnicastAddress * SelectSourceAddress(MessageInfo &aMessageInfo)
This method perform default source address selection.
Definition: ip6.cpp:971
Udp & GetUdp(void)
This method returns a reference to the UDP controller instance.
Definition: ip6.hpp:359
void SetReceiveDatagramCallback(otIp6ReceiveCallback aCallback, void *aCallbackContext)
This method registers a callback to provide received raw IPv6 datagrams.
Definition: ip6.cpp:93
static uint16_t ComputePseudoheaderChecksum(const Address &aSource, const Address &aDestination, uint16_t aLength, IpProto aProto)
This static method computes the pseudoheader checksum.
Definition: ip6.cpp:80
This file includes definitions for IPv6 network interfaces.
void EnqueueDatagram(Message &aMessage)
This methods adds a full IPv6 packet to the transmit queue.
Definition: ip6.cpp:328
otError SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto aIpProto)
This method sends an IPv6 datagram.
Definition: ip6.cpp:334
This file includes definitions for IPv6 packet processing.
void(* otIp6ReceiveCallback)(otMessage *aMessage, void *aContext)
This function pointer is called when an IPv6 datagram is received.
Definition: ip6.h:255
This file includes definitions for ICMPv6.
bool IsReceiveIp6FilterEnabled(void)
This method indicates whether or not Thread control traffic is filtered out when delivering IPv6 data...
Definition: ip6.hpp:228
This class implements an IPv6 network interface.
Definition: netif.hpp:255
Message * NewMessage(uint16_t aReserved)
This method allocates a new message buffer from the buffer pool.
Definition: ip6.cpp:69
otError
This enumeration represents error codes used throughout OpenThread.
Definition: types.h:107
This file includes compile-time configuration constants for OpenThread.
This file defines the OpenThread UDP API.
Mpl & GetMpl(void)
This method returns a reference to the UDMPL message processing controller instance.
Definition: ip6.hpp:367
This class implements MPL message processing.
Definition: ip6_mpl.hpp:433
int8_t GetOnLinkNetif(const Address &aAddress)
This method determines which network interface aAddress is on-link, if any.
Definition: ip6.cpp:1099