5 #ifndef IPV6_INTERFACE_H 6 #define IPV6_INTERFACE_H 8 #include <basictypes.h> 10 #include <ipv6/dhcpv6_internal.h> 12 #include <ipv6/ipv6_frames.h> 17 #define ADDR_ALL_NODES_LINK_LOCAL IPADDR6::AsciiToIp6("FF02::1") 18 #define ADDR_ALL_ROUTERS_LINK_LOCAL IPADDR6::AsciiToIp6("FF02::2") 19 #define ADDR_ALL_NB_LINK_LOCAL IPADDR6::AsciiToIp6("FF02::4e42") 20 #define ADDR_UNICAST_LINK_LOCAL_PREFIX IPADDR6::AsciiToIp6("FE80::") 21 #define ADDR_MLDV2_REPORTS IPADDR6::AsciiToIp6("FF02::16") 23 #define IPV6_MULTICAST_NODE_LOCAL 0xFF01 24 #define IPV6_MULTICAST_LINK_LOCAL 0xFF02 25 #define IPV6_MULTICAST_REALM_LOCAL 0xFF03 26 #define IPV6_MULTICAST_ADMIN_LOCAL 0xFF04 27 #define IPV6_MULTICAST_SITE_LOCAL 0xFF05 28 #define IPV6_MULTICAST_ORG_LOCAL 0xFF08 29 #define IPV6_MULTICAST_GLOBAL 0xFF0E 32 struct ICMP6_ND_ADVERT;
34 struct IPv6FrameProcessingStruct
42 void free_proc_struct();
44 uint8_t WalkNextHeader(
int *pError_offset =
NULL);
45 bool DestOptHasError(puint8_t pData,
int *pError_offset);
46 bool HopByHopParseHasError(puint8_t pData,
int *pError_offset);
47 bool RouterHeaderParseHasError(puint8_t pData,
int *pError_offset);
48 IPv6FrameProcessingStruct(PoolPtr pp);
49 IPv6FrameProcessingStruct()
57 inline puint8_t GetDataPointer()
59 if (pLargeData)
return pLargeData;
60 if (root_pp)
return root_pp->pData;
63 inline EFRAME *GetEframe()
65 if (pLargeData)
return (EFRAME *)pLargeData;
66 if (root_pp)
return (EFRAME *)root_pp->pData;
78 struct IPV6_ROOT_EL_CONTAINER;
81 class TcpCarrierPacket;
83 typedef socket_struct SOCKET;
84 typedef SOCKET *PSOCKET;
86 enum IPV6_ROOT_EL_TYPE
88 IPV6_ROOT_TYPE_EL = 0,
89 IPV6_ROOT_TYPE_EL_CONTAINER = 1,
90 IPV6_ROOT_TYPE_ROUTER = 2,
91 IPV6_ROOT_TYPE_DHCPD = 3,
92 IPV6_ROOT_TYPE_PREFIX = 4,
93 IPV6_ROOT_TYPE_DNS = 5,
94 IPV6_ROOT_TYPE_NEIGHBOR = 6,
95 IPV6_ROOT_TYPE_DEST = 7,
100 IPV6_ROOT_EL *m_pNext;
101 IPV6_ROOT_EL *m_pPrev;
102 IPV6_ROOT_EL_CONTAINER *m_pContainer;
106 virtual void ShowItem();
107 virtual bool AgeStillValidTest();
108 virtual void free_element();
109 virtual ~IPV6_ROOT_EL();
112 struct IPV6_ROOT_EL_CONTAINER
115 IPV6_ROOT_EL *m_pHead;
116 IPV6_ROOT_EL *m_pTail;
117 IPv6Interface *m_pInterface;
120 void Insert(IPV6_ROOT_EL *pEl);
121 void InsertBack(IPV6_ROOT_EL *pEl);
122 IPV6_ROOT_EL *Find(
const IPADDR6 &ip,
bool age);
123 IPV6_ROOT_EL *First();
124 IPV6_ROOT_EL_CONTAINER();
125 void Attach(IPv6Interface &Interface,
const char *name);
126 void MoveToTop(IPV6_ROOT_EL *pEl);
127 void Remove(IPV6_ROOT_EL *pEl);
134 struct IPV6_DHCPD :
public IPV6_ROOT_EL
137 uint8_t m_ServerID[CLIENT_LONG_SERVID];
139 uint32_t m_renewTick;
140 uint32_t m_rebindTick;
143 virtual bool AgeStillValidTest();
144 virtual void ShowItem();
145 IPV6_PREFIX *FindIA_Addr(IPV6_PREFIX *start);
146 inline uint32_t GetDhcpRenewTime() {
return m_renewTick; }
147 inline uint32_t GetDhcpRebindTime() {
return m_rebindTick; }
150 struct IPV6_IA_ADDR :
public IPV6_ROOT_EL
153 virtual bool AgeStillValidTest();
154 virtual void ShowItem();
157 struct IPV6_ROUTER :
public IPV6_ROOT_EL
159 uint16_t m_CheckSumCache;
160 uint32_t m_SecsLastAdvertise;
161 IPV6_NEIGHBOR *m_pNeighbor;
162 uint32_t m_Life_In_Secs;
164 IPV6_ROUTER *GetNextValid();
165 IPV6_ROUTER *GetNext();
166 void CleanUpAndRemove();
167 void RemoveFromDefault();
169 virtual bool AgeStillValidTest();
171 virtual void ShowItem();
192 struct IPV6_PREFIX :
public IPV6_ROOT_EL
194 eMY_ADDR_STATE m_state;
195 uint32_t time_to_lose_prefered_in_secs_from_establish;
196 uint32_t time_to_lose_valid_in_secs_from_establish;
197 uint32_t time_established_in_secs;
198 uint32_t max_valid_time_seen;
199 IPV6_ROUTER *pRouter;
202 bool bValidForInterface;
205 IPV6_PREFIX *GetNext()
208 return (IPV6_PREFIX *)m_pNext;
213 void CleanUpAndRemove();
215 bool OnLink(
const IPADDR6 &ip);
217 eMY_ADDR_STATE GetState() {
return m_state; };
218 virtual void ShowItem();
220 inline ePrefixSource Source()
222 if (pDHCPD)
return eDHCP;
223 if (pRouter)
return eRouter;
224 if (m_IPAddress.IsLinkLocal())
return eLinkLocal;
225 if ((bValidForInterface) && (bOnLink))
return eStatic;
228 inline uint32_t RemainingValidTime()
230 uint32_t lastt = time_established_in_secs;
231 if (pRouter) lastt = pRouter->m_SecsLastAdvertise;
232 if (time_to_lose_valid_in_secs_from_establish == 0xffffffff)
return 0xffffffff;
233 return time_to_lose_valid_in_secs_from_establish - (Secs - lastt);
235 inline uint32_t GetRemainingDhcpLeaseTime() {
return time_to_lose_valid_in_secs_from_establish + time_established_in_secs - Secs; }
236 inline uint32_t GetRemainingDhcpLeasePreferredTime()
238 return time_to_lose_prefered_in_secs_from_establish + time_established_in_secs - Secs;
240 virtual bool AgeStillValidTest();
241 bool AgeStillPreferred();
242 void CheckTenative();
245 struct IPV6_DNS :
public IPV6_ROOT_EL
247 uint32_t m_nSecsToBeValid;
248 IPV6_ROUTER *pRouter;
253 return (IPV6_DNS *)m_pNext;
257 virtual bool AgeStillValidTest();
258 virtual void ShowItem();
259 void CleanUpAndRemove();
269 enum eMY_NEIGHBOR_STATE
278 struct IPV6_NEIGHBOR :
public IPV6_ROOT_EL
281 eMY_NEIGHBOR_STATE m_NeighborState;
282 uint8_t m_SentNDCount;
283 uint32_t m_TickTimeOfNextAction;
286 IPV6_ROUTER *m_pRouter;
287 PoolPtr m_pOutBound1;
288 PoolPtr m_pOutBound2;
291 IPV6_NEIGHBOR *GetNext()
294 return (IPV6_NEIGHBOR *)m_pNext;
301 bool ProcessAdvert(IPv6FrameProcessingStruct &p6proc, ICMP6_ND_ADVERT *pRsp);
303 void Send_ND_Solicit(
bool multicast);
304 eRouteOutResult Send(IPv6FrameProcessingStruct &p6proc, uint16_t mtu);
305 virtual bool AgeStillValidTest();
306 bool StillValidToSend();
307 void SetState(eMY_NEIGHBOR_STATE s);
308 eMY_NEIGHBOR_STATE GetState() {
return m_NeighborState; };
309 void CoreSendPend(PoolPtr pp);
311 virtual void ShowItem();
314 struct IPV6_DEST :
public IPV6_ROOT_EL
316 IPV6_NEIGHBOR *m_pNeighbor;
320 return (IPV6_DEST *)m_pNext;
325 uint32_t m_nSecsLastUsed;
329 virtual bool AgeStillValidTest();
330 virtual void ShowItem();
341 class IPv6Interface :
public TimeOutElement
345 uint32_t m_LastFragCheckSec;
346 uint32_t m_LastRouterSolSec;
347 uint32_t m_RouterSolCount;
348 uint32_t m_LastMLDRepSec;
349 bool m_solicitSendLinkLayer;
350 NB::V6::DHCPv6::DHCPClient *m_pDhcpClient;
353 IPV6_ROOT_EL_CONTAINER Prefixes;
354 IPV6_ROOT_EL_CONTAINER Destinations;
355 IPV6_ROOT_EL_CONTAINER Neighbors;
356 IPV6_ROOT_EL_CONTAINER Routers;
357 IPV6_ROOT_EL_CONTAINER DnsList;
358 IPV6_ROOT_EL_CONTAINER DHCPServers;
360 volatile PoolPtr m_pp_FragmentParts;
361 virtual void TimeElementEvent();
364 IPV6_PREFIX *PrefixAlloc(
const IPADDR6 &ip);
365 IPV6_DEST *DestAlloc(
const IPADDR6 &ip);
366 IPV6_ROUTER *RouterAlloc(
const IPADDR6 &ip);
367 IPV6_NEIGHBOR *NeighborAlloc(
const IPADDR6 &ip);
368 IPV6_DNS *DnsAlloc(
const IPADDR6 &ip,
bool front =
false);
369 IPV6_DHCPD *DHCPDAlloc(
const IPADDR6 &ip);
371 inline IPV6_PREFIX *FindPrefix(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_PREFIX *)Prefixes.Find(ip, age); };
372 inline IPV6_DEST *FindDest(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_DEST *)Destinations.Find(ip, age); };
373 inline IPV6_ROUTER *FindRouter(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_ROUTER *)Routers.Find(ip, age); };
374 inline IPV6_DHCPD *FindDHCPD(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_DHCPD *)DHCPServers.Find(ip, age); };
375 inline IPV6_NEIGHBOR *FindNeighbor(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_NEIGHBOR *)Neighbors.Find(ip, age); };
376 IPV6_NEIGHBOR *FindCreateNeighbor(
const IPADDR6 &ip);
377 inline IPV6_PREFIX *FindIA_Addr(IPV6_DHCPD *dhcpd, IPV6_PREFIX *prefix =
NULL)
379 if (prefix ==
NULL) { prefix = FirstPrefix(); }
380 return dhcpd->FindIA_Addr(prefix);
383 IPV6_DNS *FindDNS(
const IPADDR6 &ip,
bool age =
false, IPV6_DHCPD *pDhcp =
NULL);
384 IPV6_DNS *FindDNSByDHCPD(IPV6_DHCPD *pDhcp, IPV6_DNS *pEl);
387 uint16_t CurHopLimit;
388 uint32_t BaseReachableTime_Ticks;
389 uint32_t ReachableTime_Ticks;
390 uint32_t ND_RetranmistTimer_Ticks;
392 uint32_t CalcRandomReachable();
395 eRouteOutResult RouteOut(IPv6FrameProcessingStruct &p6proc, IPV6_DEST *dest =
NULL);
397 uint16_t m_MultiCastMtu;
399 uint8_t m_DefHopCount;
400 volatile bool bHadLink;
401 volatile int m_bStill_Need_To_Process_DupDiscovery_Ticks;
402 volatile bool m_bNeighborTicks;
405 static IPv6Interface *gifList;
406 IPv6Interface *m_pNext;
407 static IPADDR6 NetBurnerMultiCast;
412 void SumIcmp(IPv6FrameProcessingStruct &p6proc);
414 void RootErrors(uint8_t typev, uint8_t code, uint32_t ptr, IPv6FrameProcessingStruct &p6proc);
416 void SendParameterProblem(IPv6FrameProcessingStruct &p6proc,
int prob,
int offset);
418 void SendTimeExceeded(PoolPtr pp);
420 void SendUnreachable(IPv6FrameProcessingStruct &p6proc);
424 bool Process_UDP(IPv6FrameProcessingStruct &p6proc);
426 bool Process_TCP(IPv6FrameProcessingStruct &p6proc);
428 bool Process_Fragment(IPv6FrameProcessingStruct &p6proc);
430 bool ProcessND_N_Solicit(IPv6FrameProcessingStruct &p6proc);
432 bool ProcessND_N_Advertise(IPv6FrameProcessingStruct &p6proc);
434 bool ProcessND_R_Advertise(IPv6FrameProcessingStruct &p6proc);
436 bool ProcessRouterOptions(IPV6_ROUTER *pRouter, IPv6FrameProcessingStruct &p6proc,
int &rem, uint8_t *&pD);
438 bool ProcessND_Redirect(IPv6FrameProcessingStruct &p6proc);
440 bool ProcessPingRequest(IPv6FrameProcessingStruct &p6proc);
442 bool ProcessPingReply(IPv6FrameProcessingStruct &p6proc);
445 bool ProcessIcmpUnreach(IPv6FrameProcessingStruct &p6proc);
446 bool ProcessTooBig(IPv6FrameProcessingStruct &p6proc);
447 bool ProcessTimeExceeded(IPv6FrameProcessingStruct &p6proc);
448 bool ProcessParamProb(IPv6FrameProcessingStruct &p6proc);
450 bool ProcessIcmpV6(IPv6FrameProcessingStruct &p6proc);
452 bool ProcessV6(IPv6FrameProcessingStruct &p6proc);
454 void AddDefAddress(
const IPADDR6 &ip);
456 void AddPrefix(
const IPADDR6 &ip,
int len,
int expire);
458 bool ValidateIcmpPacket(IPv6FrameProcessingStruct &p6proc);
460 void SendRouterSolicit(
bool sendLinkLayer);
462 void SendDUP_Discover(
const IPADDR6 &ip);
466 if (m_pMyLinkLocal)
return m_pMyLinkLocal->m_IPAddress;
470 friend struct IPV6_PREFIX;
471 friend struct IPV6_DEST;
472 friend struct IPV6_ROUTER;
473 friend struct IPV6_NEIGHBOR;
474 friend struct IPV6_DNS;
475 friend struct IPV6_DHCPD;
477 friend class NB::V6::DHCPv6::DHCPClient;
478 friend void RetransmitV6Packet(PoolPtr pp, PSOCKET ps);
479 friend void TcpSendwSum6(PSOCKET ps,
const IPADDR &IPto, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
480 friend void TcpSendwSumFrom6(
const IPADDR &IPto,
const IPADDR &IPfrom, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
481 friend void InitIPv6(
int ifnum);
482 friend int Ping6(
const IPADDR6 &to, uint16_t
id, uint16_t seq, uint16_t maxwaitticks,
int size);
483 friend int Ping6ViaInterface(
IPADDR6 &to, uint16_t
id, uint16_t seq, uint16_t wait,
int interface,
int size);
485 static void RootProcessV6(PoolPtr pp);
490 bool ProcessICMPExtension(IPv6FrameProcessingStruct &p6proc);
491 void JoinMulticastGroup(
const IPADDR6 &addr);
492 void LeaveMulticastGroup(
const IPADDR6 &addr);
493 void ReadyMLDBase(IPv6FrameProcessingStruct &p6proc,
const IPADDR6 &recAddr);
494 void LinkLocalIsNowValid();
496 void ClearDHCPDInfo(IPV6_DHCPD *pDhcpd =
NULL);
499 inline IPV6_PREFIX *FirstPrefix() {
return (IPV6_PREFIX *)Prefixes.First(); };
500 inline IPV6_DEST *FirstDest() {
return (IPV6_DEST *)Destinations.First(); };
501 inline IPV6_ROUTER *FirstRouter() {
return (IPV6_ROUTER *)Routers.First(); };
502 IPV6_ROUTER *FirstDefRouter();
503 IPV6_DHCPD *FirstDHCPD() {
return (IPV6_DHCPD *)DHCPServers.First(); };
504 inline IPV6_NEIGHBOR *FirstNeighbor() {
return (IPV6_NEIGHBOR *)Neighbors.First(); };
505 inline IPV6_DNS *FirstDNS() {
return (IPV6_DNS *)DnsList.First(); };
507 IPV6_PREFIX *m_pMyLinkLocal;
511 uint16_t GetDestinationMTU(
const IPADDR &ip);
512 static IPv6Interface *GetInterfaceForDestination(
const IPADDR6 &ip);
513 static IPv6Interface *GetInterfaceForSource(
const IPADDR6 &ip);
514 static IPv6Interface *GetInterfaceN(
int n);
515 static IPv6Interface *GetFirst_IP6_Interface();
516 IPv6Interface *GetNext_IP6_Interface();
519 int GetInterfaceNumber() {
return m_ifnum; };
522 inline bool HadLink() {
return bHadLink; }
524 IPV6_PREFIX *AddStaticAddress(
const IPADDR6 &ip,
int PrefixLen);
525 IPV6_ROUTER *AddDefaultGateway(
const IPADDR6 &ip);
526 IPV6_DNS *AddStaticDNS(
const IPADDR6 &ip);
529 bool RemoveStaticAddress(
const IPADDR6 &ip);
530 bool RemoveDefaultGateway(
const IPADDR6 &ip);
531 bool RemoveStaticDNS(
const IPADDR6 &ip);
533 void SetStaticDNS(
IPADDR6 dns) { m_StaticDNS = dns; };
534 inline void StartDHCP_Solicit() { NB::V6::DHCPv6::DHCPClient::ProcessDHCPAvail(
this, (uint8_t)RA_FLAG_MANAGED_IP); }
535 inline void StartDHCP_InfoReq() { NB::V6::DHCPv6::DHCPClient::ProcessDHCPAvail(
this, (uint8_t)RA_FLAG_OTHER_AVAIL); }
537 bool IsMyAddress(
const IPADDR6 &ip6,
bool bMustBePrefered);
538 bool OnLink(
const IPADDR6 &ip6);
539 bool HasRoute(
const IPADDR6 &ip6);
540 void NotifyReachable(
const IPADDR6 &ip6);
541 void NotifyUnreachable(
const IPADDR6 &ip);
545 IPV6_PREFIX *pPrefix = FirstPrefix();
546 if (pPrefix)
return pPrefix->m_IPAddress;
552 IPV6_PREFIX *pPrefix = FindPrefix(ip);
555 pPrefix = pPrefix->GetNext();
556 if (pPrefix)
return pPrefix->m_IPAddress;
561 IPv6Interface(
int ifnum);
562 int ping(
const IPADDR6 &ip, uint16_t
id, uint16_t seq, uint16_t wait,
int siz);
563 int SendMLDRegistration(
const IPADDR ®Addr,
bool joinNotLeave =
true);
566 static void ShowAllInfo();
570 void ShowIP6Counters();
static IPADDR6 NullIP()
Return a null IPADDR6 object.
Definition: ipv6_addr.cpp:334
A FIFO is used to pass structures from one task to another. Note: Structures to be passed must have a...
Definition: nbrtos.h:736
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28
UDP Packet Class.
Definition: udp.h:70
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition: nbrtos.h:893
#define NULL
Definition: nm_bsp.h:76