2 * Copyright (c) 2020, The OpenThread Authors.
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.
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.
31 * This file includes definition for ICMPv6 Neighbor Advertisement (ND) proxy management.
38 #define __APPLE_USE_RFC_3542
42 #include <libnetfilter_queue/libnetfilter_queue.h>
44 #include <netinet/in.h>
48 #include <openthread/backbone_router_ftd.h>
50 #include "agent/ncp_openthread.hpp"
51 #include "common/types.hpp"
54 namespace BackboneRouter {
57 * @addtogroup border-router-bbr
60 * This module includes definition for ND Proxy manager.
66 * This class implements ND Proxy manager.
73 * This constructor initializes a NdProxyManager instance.
76 explicit NdProxyManager(otbr::Ncp::ControllerOpenThread &aNcp)
79 , mUnicastNsQueueSock(-1)
80 , mNfqHandler(nullptr)
81 , mNfqQueueHandler(nullptr)
86 * This method initializes a ND Proxy manager instance.
92 * This method enables the ND Proxy manager.
94 * @param[in] aDomainPrefix The Domain Prefix.
97 void Enable(const Ip6Prefix &aDomainPrefix);
100 * This method disables the ND Proxy manager.
106 * This method updates the fd_set and timeout for mainloop.
108 * @param[inout] aReadFdSet A reference to fd_set for polling read.
109 * @param[inout] aWriteFdSet A reference to fd_set for polling read.
110 * @param[inout] aErrorFdSet A reference to fd_set for polling error.
111 * @param[inout] aMaxFd A reference to the current max fd in @p aReadFdSet and @p aWriteFdSet.
112 * @param[inout] aTimeout A reference to the timeout.
115 void UpdateFdSet(fd_set & aReadFdSet,
116 fd_set & aWriteFdSet,
117 fd_set & aErrorFdSet,
119 timeval &aTimeout) const;
122 * This method performs border agent processing.
124 * @param[in] aReadFdSet A reference to read file descriptors.
125 * @param[in] aWriteFdSet A reference to write file descriptors.
126 * @param[in] aErrorFdSet A reference to error file descriptors.
129 void Process(const fd_set &aReadFdSet, const fd_set &aWriteFdSet, const fd_set &aErrorFdSet);
132 * This method handles a Backbone Router ND Proxy event.
134 * @param[in] aEvent The Backbone Router ND Proxy event type.
135 * @param[in] aDua The Domain Unicast Address of the ND Proxy, or `nullptr` if @p `aEvent` is
136 * `OT_BACKBONE_ROUTER_NDPROXY_CLEARED`.
139 void HandleBackboneRouterNdProxyEvent(otBackboneRouterNdProxyEvent aEvent, const otIp6Address *aDua);
142 * This method returns if the ND Proxy manager is enabled.
144 * @returns If the ND Proxy manager is enabled;
147 bool IsEnabled(void) const { return mIcmp6RawSock >= 0; }
152 kMaxICMP6PacketSize = 1500, ///< Max size of an ICMP6 packet in bytes.
155 void SendNeighborAdvertisement(const Ip6Address &aTarget, const Ip6Address &aDst);
156 otbrError UpdateMacAddress(void);
157 otbrError InitIcmp6RawSocket(void);
158 void FiniIcmp6RawSocket(void);
159 otbrError InitNetfilterQueue(void);
160 void FiniNetfilterQueue(void);
161 void ProcessMulticastNeighborSolicition(void);
162 void ProcessUnicastNeighborSolicition(void);
163 void JoinSolicitedNodeMulticastGroup(const Ip6Address &aTarget) const;
164 void LeaveSolicitedNodeMulticastGroup(const Ip6Address &aTarget) const;
165 static int HandleNetfilterQueue(struct nfq_q_handle *aNfQueueHandler,
166 struct nfgenmsg * aNfMsg,
167 struct nfq_data * aNfData,
169 int HandleNetfilterQueue(struct nfq_q_handle *aNfQueueHandler, struct nfgenmsg *aNfMsg, struct nfq_data *aNfData);
171 otbr::Ncp::ControllerOpenThread &mNcp;
172 std::set<Ip6Address> mNdProxySet;
173 uint32_t mBackboneIfIndex;
175 int mUnicastNsQueueSock;
176 struct nfq_handle * mNfqHandler; ///< A pointer to an NFQUEUE handler.
177 struct nfq_q_handle * mNfqQueueHandler; ///< A pointer to a newly created queue.
178 MacAddress mMacAddress;
179 Ip6Prefix mDomainPrefix;
186 } // namespace BackboneRouter
189 #endif // ND_PROXY_HPP_