5#ifndef IPV6_INTERFACE_H
6#define IPV6_INTERFACE_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
32struct ICMP6_ND_ADVERT;
34struct 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;
78struct IPV6_ROOT_EL_CONTAINER;
81class TcpCarrierPacket;
83typedef socket_struct SOCKET;
84typedef SOCKET *PSOCKET;
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();
112struct 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);
134struct 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; }
150struct IPV6_IA_ADDR :
public IPV6_ROOT_EL
153 virtual bool AgeStillValidTest();
154 virtual void ShowItem();
157struct 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();
192struct 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()
207 return (IPV6_PREFIX*)m_pNext;
210 void CleanUpAndRemove();
212 bool OnLink(
const IPADDR6 &ip);
214 eMY_ADDR_STATE GetState() {
return m_state; };
215 virtual void ShowItem();
217 inline ePrefixSource Source()
219 if (pDHCPD)
return eDHCP;
220 if (pRouter)
return eRouter;
222 if ((bValidForInterface) && (bOnLink))
return eStatic;
225 inline uint32_t RemainingValidTime()
227 uint32_t lastt = time_established_in_secs;
228 if (pRouter) lastt = pRouter->m_SecsLastAdvertise;
229 if (time_to_lose_valid_in_secs_from_establish == 0xffffffff)
return 0xffffffff;
230 return time_to_lose_valid_in_secs_from_establish - (Secs - lastt);
232 inline uint32_t GetRemainingDhcpLeaseTime() {
return time_to_lose_valid_in_secs_from_establish + time_established_in_secs - Secs; }
233 inline uint32_t GetRemainingDhcpLeasePreferredTime()
235 return time_to_lose_prefered_in_secs_from_establish + time_established_in_secs - Secs;
237 virtual bool AgeStillValidTest();
238 bool AgeStillPreferred();
239 void CheckTenative();
242struct IPV6_DNS :
public IPV6_ROOT_EL
244 uint32_t m_nSecsToBeValid;
245 IPV6_ROUTER *pRouter;
249 return (IPV6_DNS *)m_pNext;
251 virtual bool AgeStillValidTest();
252 virtual void ShowItem();
253 void CleanUpAndRemove();
263enum eMY_NEIGHBOR_STATE
272inline bool ThisCheck(
void * p) {
return p!=0; }
275struct IPV6_NEIGHBOR :
public IPV6_ROOT_EL
278 eMY_NEIGHBOR_STATE m_NeighborState;
279 uint8_t m_SentNDCount;
280 uint32_t m_TickTimeOfNextAction;
283 IPV6_ROUTER *m_pRouter;
284 PoolPtr m_pOutBound1;
285 PoolPtr m_pOutBound2;
288 IPV6_NEIGHBOR *GetNext()
291 return (IPV6_NEIGHBOR *)m_pNext;
298 bool ProcessAdvert(IPv6FrameProcessingStruct &p6proc, ICMP6_ND_ADVERT *pRsp);
300 void Send_ND_Solicit(
bool multicast);
301 eRouteOutResult Send(IPv6FrameProcessingStruct &p6proc, uint16_t mtu);
302 virtual bool AgeStillValidTest();
303 bool StillValidToSend();
304 void SetState(eMY_NEIGHBOR_STATE s);
305 eMY_NEIGHBOR_STATE GetState() {
return m_NeighborState; };
306 void CoreSendPend(PoolPtr pp);
308 virtual void ShowItem();
311struct IPV6_DEST :
public IPV6_ROOT_EL
313 IPV6_NEIGHBOR *m_pNeighbor;
317 return (IPV6_DEST *)m_pNext;
322 uint32_t m_nSecsLastUsed;
326 virtual bool AgeStillValidTest();
327 virtual void ShowItem();
338class IPv6Interface :
public TimeOutElement
342 uint32_t m_LastFragCheckSec;
343 uint32_t m_LastRouterSolSec;
344 uint32_t m_RouterSolCount;
345 uint32_t m_LastMLDRepSec;
346 bool m_solicitSendLinkLayer;
347 NB::V6::DHCPv6::DHCPClient *m_pDhcpClient;
350 IPV6_ROOT_EL_CONTAINER Prefixes;
351 IPV6_ROOT_EL_CONTAINER Destinations;
352 IPV6_ROOT_EL_CONTAINER Neighbors;
353 IPV6_ROOT_EL_CONTAINER Routers;
354 IPV6_ROOT_EL_CONTAINER DnsList;
355 IPV6_ROOT_EL_CONTAINER DHCPServers;
357 volatile PoolPtr m_pp_FragmentParts;
358 virtual void TimeElementEvent();
361 IPV6_PREFIX *PrefixAlloc(
const IPADDR6 &ip);
362 IPV6_DEST *DestAlloc(
const IPADDR6 &ip);
363 IPV6_ROUTER *RouterAlloc(
const IPADDR6 &ip);
364 IPV6_NEIGHBOR *NeighborAlloc(
const IPADDR6 &ip);
365 IPV6_DNS *DnsAlloc(
const IPADDR6 &ip,
bool front =
false);
366 IPV6_DHCPD *DHCPDAlloc(
const IPADDR6 &ip);
368 inline IPV6_PREFIX *FindPrefix(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_PREFIX *)Prefixes.Find(ip, age); };
369 inline IPV6_DEST *FindDest(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_DEST *)Destinations.Find(ip, age); };
370 inline IPV6_ROUTER *FindRouter(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_ROUTER *)Routers.Find(ip, age); };
371 inline IPV6_DHCPD *FindDHCPD(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_DHCPD *)DHCPServers.Find(ip, age); };
372 inline IPV6_NEIGHBOR *FindNeighbor(
const IPADDR6 &ip,
bool age =
false) {
return (IPV6_NEIGHBOR *)Neighbors.Find(ip, age); };
373 IPV6_NEIGHBOR *FindCreateNeighbor(
const IPADDR6 &ip);
374 inline IPV6_PREFIX *FindIA_Addr(IPV6_DHCPD *dhcpd, IPV6_PREFIX *prefix = NULL)
376 if (prefix == NULL) { prefix = FirstPrefix(); }
377 return dhcpd->FindIA_Addr(prefix);
380 IPV6_DNS *FindDNS(
const IPADDR6 &ip,
bool age =
false, IPV6_DHCPD *pDhcp = NULL);
381 IPV6_DNS *FindDNSByDHCPD(IPV6_DHCPD *pDhcp, IPV6_DNS *pEl);
384 uint16_t CurHopLimit;
385 uint32_t BaseReachableTime_Ticks;
386 uint32_t ReachableTime_Ticks;
387 uint32_t ND_RetranmistTimer_Ticks;
389 uint32_t CalcRandomReachable();
392 eRouteOutResult RouteOut(IPv6FrameProcessingStruct &p6proc, IPV6_DEST *dest = NULL);
394 uint16_t m_MultiCastMtu;
396 uint8_t m_DefHopCount;
397 volatile bool bHadLink;
398 volatile int m_bStill_Need_To_Process_DupDiscovery_Ticks;
399 volatile bool m_bNeighborTicks;
402 static IPv6Interface *gifList;
403 IPv6Interface *m_pNext;
404 static IPADDR6 NetBurnerMultiCast;
409 void SumIcmp(IPv6FrameProcessingStruct &p6proc);
411 void RootErrors(uint8_t typev, uint8_t code, uint32_t ptr, IPv6FrameProcessingStruct &p6proc);
413 void SendParameterProblem(IPv6FrameProcessingStruct &p6proc,
int prob,
int offset);
415 void SendTimeExceeded(PoolPtr pp);
417 void SendUnreachable(IPv6FrameProcessingStruct &p6proc);
421 bool Process_UDP(IPv6FrameProcessingStruct &p6proc);
423 bool Process_TCP(IPv6FrameProcessingStruct &p6proc);
425 bool Process_Fragment(IPv6FrameProcessingStruct &p6proc);
427 bool ProcessND_N_Solicit(IPv6FrameProcessingStruct &p6proc);
429 bool ProcessND_N_Advertise(IPv6FrameProcessingStruct &p6proc);
431 bool ProcessND_R_Advertise(IPv6FrameProcessingStruct &p6proc);
433 bool ProcessRouterOptions(IPV6_ROUTER *pRouter, IPv6FrameProcessingStruct &p6proc,
int &rem, uint8_t *&pD);
435 bool ProcessND_Redirect(IPv6FrameProcessingStruct &p6proc);
437 bool ProcessPingRequest(IPv6FrameProcessingStruct &p6proc);
439 bool ProcessPingReply(IPv6FrameProcessingStruct &p6proc);
442 bool ProcessIcmpUnreach(IPv6FrameProcessingStruct &p6proc);
443 bool ProcessTooBig(IPv6FrameProcessingStruct &p6proc);
444 bool ProcessTimeExceeded(IPv6FrameProcessingStruct &p6proc);
445 bool ProcessParamProb(IPv6FrameProcessingStruct &p6proc);
447 bool ProcessIcmpV6(IPv6FrameProcessingStruct &p6proc);
449 bool ProcessV6(IPv6FrameProcessingStruct &p6proc);
451 void AddDefAddress(
const IPADDR6 &ip);
453 void AddPrefix(
const IPADDR6 &ip,
int len,
int expire);
455 bool ValidateIcmpPacket(IPv6FrameProcessingStruct &p6proc);
457 void SendRouterSolicit(
bool sendLinkLayer);
459 void SendDUP_Discover(
const IPADDR6 &ip);
463 if (m_pMyLinkLocal)
return m_pMyLinkLocal->m_IPAddress;
467 friend struct IPV6_PREFIX;
468 friend struct IPV6_DEST;
469 friend struct IPV6_ROUTER;
470 friend struct IPV6_NEIGHBOR;
471 friend struct IPV6_DNS;
472 friend struct IPV6_DHCPD;
474 friend class NB::V6::DHCPv6::DHCPClient;
475 friend void RetransmitV6Packet(PoolPtr pp, PSOCKET ps);
476 friend void TcpSendwSum6(PSOCKET ps,
const IPADDR &IPto, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
477 friend void TcpSendwSumFrom6(
const IPADDR &IPto,
const IPADDR &IPfrom, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
479 friend int Ping6(
const IPADDR6 &to, uint16_t
id, uint16_t seq, uint16_t maxwaitticks,
int size);
480 friend int Ping6ViaInterface(
IPADDR6 &to, uint16_t
id, uint16_t seq, uint16_t wait,
int interface,
int size);
482 static void RootProcessV6(PoolPtr pp);
487 bool ProcessICMPExtension(IPv6FrameProcessingStruct &p6proc);
488 void JoinMulticastGroup(
const IPADDR6 &addr);
489 void LeaveMulticastGroup(
const IPADDR6 &addr);
490 void ReadyMLDBase(IPv6FrameProcessingStruct &p6proc,
const IPADDR6 &recAddr);
491 void LinkLocalIsNowValid();
493 void ClearDHCPDInfo(IPV6_DHCPD *pDhcpd = NULL);
496 inline IPV6_PREFIX *FirstPrefix() {
return (IPV6_PREFIX *)Prefixes.First(); };
497 inline IPV6_DEST *FirstDest() {
return (IPV6_DEST *)Destinations.First(); };
498 inline IPV6_ROUTER *FirstRouter() {
return (IPV6_ROUTER *)Routers.First(); };
499 IPV6_ROUTER *FirstDefRouter();
500 IPV6_DHCPD *FirstDHCPD() {
return (IPV6_DHCPD *)DHCPServers.First(); };
501 inline IPV6_NEIGHBOR *FirstNeighbor() {
return (IPV6_NEIGHBOR *)Neighbors.First(); };
502 inline IPV6_DNS *FirstDNS() {
return (IPV6_DNS *)DnsList.First(); };
504 IPV6_PREFIX *m_pMyLinkLocal;
508 uint16_t GetDestinationMTU(
const IPADDR &ip);
509 static IPv6Interface *GetInterfaceForDestination(
const IPADDR6 &ip);
510 static IPv6Interface *GetInterfaceForSource(
const IPADDR6 &ip);
511 static IPv6Interface *GetInterfaceN(
int n);
512 static IPv6Interface *GetFirst_IP6_Interface();
513 IPv6Interface *GetNext_IP6_Interface();
519 inline bool HadLink() {
return bHadLink; }
521 IPV6_PREFIX *AddStaticAddress(
const IPADDR6 &ip,
int PrefixLen);
522 IPV6_ROUTER *AddDefaultGateway(
const IPADDR6 &ip);
523 IPV6_DNS *AddStaticDNS(
const IPADDR6 &ip);
526 bool RemoveStaticAddress(
const IPADDR6 &ip);
527 bool RemoveDefaultGateway(
const IPADDR6 &ip);
528 bool RemoveStaticDNS(
const IPADDR6 &ip);
530 void SetStaticDNS(
IPADDR6 dns) { m_StaticDNS = dns; };
531 inline void StartDHCP_Solicit() { NB::V6::DHCPv6::DHCPClient::ProcessDHCPAvail(
this, (uint8_t)RA_FLAG_MANAGED_IP); }
532 inline void StartDHCP_InfoReq() { NB::V6::DHCPv6::DHCPClient::ProcessDHCPAvail(
this, (uint8_t)RA_FLAG_OTHER_AVAIL); }
534 bool IsMyAddress(
const IPADDR6 &ip6,
bool bMustBePrefered);
535 bool OnLink(
const IPADDR6 &ip6);
536 bool HasRoute(
const IPADDR6 &ip6);
537 void NotifyReachable(
const IPADDR6 &ip6);
538 void NotifyUnreachable(
const IPADDR6 &ip);
542 IPV6_PREFIX *pPrefix = FirstPrefix();
543 if (pPrefix)
return pPrefix->m_IPAddress;
549 IPV6_PREFIX *pPrefix = FindPrefix(ip);
552 pPrefix = pPrefix->GetNext();
553 if (pPrefix)
return pPrefix->m_IPAddress;
558 IPv6Interface(
int ifnum);
559 int ping(
const IPADDR6 &ip, uint16_t
id, uint16_t seq, uint16_t wait,
int siz);
560 int SendMLDRegistration(
const IPADDR ®Addr,
bool joinNotLeave =
true);
563 static void ShowAllInfo();
567void ShowIP6Counters();
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
bool IsLinkLocal() const
Check if the IP address is the link-local address for the interface.
Definition ipv6_addr.h:143
static IPADDR6 NullIP()
Static function to return a null IPADDR6 object.
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
UDP Packet Class.
Definition udp.h:81
int32_t GetInterfaceNumber(InterfaceBlock *pifb)
Returns the Interface Number of the specified network interface InterfaceBlock.
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1084