NetBurner 3.5.0
PDF Version
 
netinterface.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
41#ifndef _NB_NETIF_H
42#define _NB_NETIF_H
43
44#include <predef.h>
45#include <autoip.h>
46#include <config_netobj.h>
47#include <config_obj.h>
48#include <dhcpclient.h>
49#include <discoveryservlet.h>
50#include <mDNS.h>
51#include <nettypes.h>
52#include <buffers.h>
53
54
55/*------------------------------------------------------------------------------
56 * Definitions
57 *------------------------------------------------------------------------------*/
58
59// PPP Interface Identifier
60#define ARP_PPP_INTERFACE (255)
61
62/*-------------------------------------------------------------------------------
63 *
64 * MAC Address for second and subsequent interfaces
65 * For a second and subsequent NICs the MSB(it) of the 5th octet is XOR'ed
66 * with 1 to support prior released tools.
67 *
68 * 6 bytes
69 * <--------------------------------------------------------------------->
70 * 0 1 2 3 4 5
71 * -----------------------------------------------------------------------
72 * | 6th byte | 5th byte | 4th byte | 3rd byte | 2nd byte | 1st byte |
73 * | 1st octet | 2nd octet | 3rd octet | 4th octet | 5th octet | 6th octet |
74 * -----------------------------------------------------------------------
75 *
76 * 3 bytes 3 bytes
77 * <---------------------------------> <--------------------------------->
78 * -----------------------------------------------------------------------
79 * | Organizationally Unique Identifier | Network Interface Controller |
80 * | | (OUI) | | | (NIC) | |
81 * | 0x00 | 0x03 | 0xF4 | 0xYX | 0xZX | 0xXX |
82 * -----------------------------------------------------------------------
83 * | \ OUI is NetBurner's Y is IIXX XXXX binary
84 * | \ I is the interface defined as
85 * | \ bits in NB_MAX_NIC... below
86 * | | Z is WXXX binary
87 * V V W ix XOR'd bit
88 * |1|2|3|4|5|6|7|8| (7) 0 global, 1 local, (8) 0 unicast, 1 multicast (IEE)
89 *
90 * Notes:
91 * 0-5 are C language offsets, 6th byte through 1st byte is Ethernet
92 * transmission order and octet notation is from IEEE 802 MAC-48 address.
93 * Derivation is needed if the NIC does not have a non-volatile MAC address.
94 *
95 *-------------------------------------------------------------------------------*/
96#ifndef NB_MAC_ADDRESS
97#define NB_MAC_ADDRESS
98
99/* 4th Octet */
100#define NB_MAC_NIC_INTERFACE (0x00)
101#define NB_MAC_NIC_SECOND_INTERFACE (0x80)
102#define NB_MAC_NIC_THIRD_INTERFACE (0x40)
103#define NB_MAC_NIC_FOURTH_INTERFACE (0xC0)
104#define NB_MAC_NIC_SECOND_INTERFACE_MASK \
105 (NB_MAC_NIC_INTERFACE | NB_MAC_NIC_SECOND_INTERFACE | NB_MAC_NIC_THIRD_INTERFACE | NB_MAC_NIC_FOURTH_INTERFACE)
106#define NB_MAC_OCTET_4 (3)
107#define NB_MAC_OCTET_5 (4)
108#define NB_MAC_OCTET_5_XOR (0x80)
109
110#endif /* NB_MAC_ADDRESS */
111
112
113/*-----------------------------------------------------------------------------
114 * Callback Function Prototypes
115 *-----------------------------------------------------------------------------*/
116
117/*
118 ******************************************************************************
119
120 Process Internet Protocol Packet (IP)
121
122 Parameters:
123 poolPtr - Packet from pool
124 ethernetFramePtr - Ethernet frame
125 checksum - IP frame checksum
126
127 Return:
128 None
129
130 Notes;
131 Called for every IP packet received and meets this criteria.
132 1)The packet is an IP packet.
133 2)The IP header checksum is valid.
134 3)The packet was addressed to us or to a broadcast address.
135 Before the callback is called the flags member of the buffer is setup to
136 indicate physical broadcast etc....
137
138 ******************************************************************************
139 */
140typedef void(ProcessPacketFunc)(PoolPtr poolPtr, PEFRAME ethernetFramePtr, uint16_t checksum);
141
142/*
143 ******************************************************************************
144
145 Process Address Resolution Packet (ARP)
146
147 Parameters:
148 poolPtr - Packet from pool
149 ethernetFramePtr - Ethernet frame
150
151 Return:
152 None
153
154 Notes;
155 Called for every ARP packet received. Before the callback is called the
156 flags member of the buffer is setup to indicate physical broadcast etc...
157
158 ******************************************************************************
159 */
160typedef void(ProcessArpFunc)(PoolPtr poolPtr, PEFRAME ethernetFramePtr);
161
162/*
163 ******************************************************************************
164
165 Process Address LLDP
166
167 Parameters:
168 poolPtr - Packet from pool
169 ethernetFramePtr - Ethernet frame
170
171 Return:
172 None
173
174 Notes;
175 If filled in called for every LLDP frame
176 flags member of the buffer is setup to indicate physical broadcast etc...
177
178 ******************************************************************************
179 */
180typedef void (*ProcessLLDPptr)(PoolPtr poolPtr);
181
182extern ProcessLLDPptr pProcessLLDP;
183
184/*
185 ******************************************************************************
186
187 Returns current link active status
188
189 Parameters:
190 None
191
192 Return:
193 TRUE active, FALSE all else.
194
195 Notes:
196 Interface driver must minimize latency.
197
198 ******************************************************************************
199 */
200typedef BOOL(LinkActiveFunc)(void);
201
202
203/*
204 ******************************************************************************
205 *
206 * Data Structures
207 *
208 ******************************************************************************
209 */
210
211#define INTF_CSUM_IP (0x01)
212#define INTF_CSUM_ICMP (0x02)
213#define INTF_CSUM_UDP (0x04)
214#define INTF_CSUM_TCP (0x08)
215#define INTF_CSUM_IP6 (0x10)
216#define INTF_CSUM_ICMP6 (0x20)
217#define INTF_CSUM_UDP6 (0x40)
218#define INTF_CSUM_TCP6 (0x80)
219
220#define INTF_CSUM_ALL4 (INTF_CSUM_IP | INTF_CSUM_ICMP | INTF_CSUM_UDP | INTF_CSUM_TCP)
221#define INTF_CSUM_ALL6 (INTF_CSUM_IP6 | INTF_CSUM_ICMP6 | INTF_CSUM_UDP6 | INTF_CSUM_TCP6)
222
223
245{
246 public:
247 I4Record ip4{"IPv4"}; // The IPv4 configuration for "this" interface, see config_netobj.h for details
248#ifdef IPV6
249 I6Record ip6{"IPv6"}; // The IPv6 configuration for "this" interface, see config_netobj.h for details
250#endif
251 config_MACADR MAC{"00:00:00:00:00:00", "MAC"}; // Interface MAC address. May be 0/null for interfaces such as PPP
252 config_string device_name{"", "DeviceName"}; // Name of interface. Used to register for DNS and NetBIOS
253 config_int dhcp_discover_secs{1, "DhcpDiscoverSec"}; // How long to wait after boot before sending a DHCP Discover message
254 config_string discovery_server{"discover.netburner.com/DevicePost", "DiscoveryReportUrl"}; // NetBurner discover server name
255 config_int discovery_interval{(15 * 60), "DiscoveryReportInterval"}; // How often to report to NetBurner discover server
256 config_bool obfuscate_discovery{true, "DiscoveryObfuscate", "Should discovery obfuscate data"};
257 config_bool supress_default_responses{false, "SupressDefault", "Supress ping and udp Echo ports"};
258 config_int vlan_tag_value{0, "VlanTag"};
259
260 ConfigEndMarker; // Marker for end of configuration structure
261
262 int32_t root_if; // Root interface number. If multihomed, the interface would be a child of the root interface
263 int32_t my_ifnum; // This interface number
264 uint16_t netMss; // Network max segment size for this interface
265 uint8_t checksumOffload; // Non-zero if hardware interface support offloading checksum calculation
266 bool bHaveSeenLink; // Have seen a link at once before
267 DhcpObject dhcpClient{this}; // DHCP client support
268 discover_servlet disco_servlet{this}; // the servlet that runs the NetBurner discovery server process
269 void (*MCastLinkNotify)(InterfaceBlock *pBlock, bool bLink); // A funciton pointer called when link changes for multicast.
270
271 IPADDR4 previous_addr;
272 IPADDR4 previous_mask;
273 IPADDR4 previous_gate;
274
275#ifdef AUTOIP // if not defined don't compile anything...
276 AutoIPClient AutoClient; // AutoIP client object for this interface
277#endif
278
279#if defined MULTIHOME
280 BOOL bMultiHome; // True if this is a multihomed interface
281 InterfaceBlock *pChild; // Parrent points to list, children are linked list of pchilds.
282#endif
283
290 InterfaceBlock(const char *name, const char *desc = NULL);
291
299 InterfaceBlock(config_obj &owner, const char *name, const char *desc = NULL);
300
309
310 virtual void send_func(PoolPtr poolPtr) = 0;
311 virtual void kill_if();
312
323 virtual void EnableMulticast(MACADR macAddress, BOOL addAddress) = 0;
324
332 virtual bool LinkActive() = 0;
333
341 virtual int LinkSpeed() = 0;
342
350 virtual bool LinkDuplex() = 0;
351
357 void InterfaceLinkChange(bool link);
358
366 virtual const char *GetInterfaceName();
367
375 int GetInterfaceNumber() { return my_ifnum; }
376
382 inline bool IsRootInterface() { return root_if == 0; }
383
384 // Move values from the IPV4 settings to cur stuff.
385 // Starts /Shutdowns DHCP if necessary
386 // Stores previous values in previous_addr,_mask,_gate;
387 // Returns true if the address changed.
388 bool ProcessIPConfigChange(uint16_t ticks_to_wait);
389
390 //Used if the web page changes IP values to swap so one can complete socket.
391 void SwapOldAndCurrentAddr();
392
393 virtual bool bNeedsArp() { return true; };
394 void fdShowInterfaceValues(int fd);
395 inline void ShowInterfaceValues() { fdShowInterfaceValues(1); };
396 void SetDefaultFlags();
397 // Called by DHCP client when we get new settings...
398 void DHCPNotify();
399
400#if defined MULTIHOME
401 int RegisterMultiHomeInterface(InterfaceBlock &UnderBlock);
402#endif
403};
404
405
406
407// Adds additional features to an InterfaceBlock. Defaults to most features disabled
408class EtherLikeInterface : public InterfaceBlock
409{
410 public:
411 ConfigEndMarker;
412 EtherLikeInterface(const char *name, const char *desc = NULL) : InterfaceBlock(name, desc)
413 {
414 ip4.SetFlag(fConfigHidden);
415#ifdef IPV6
416 ip6.SetFlag(fConfigHidden);
417#endif
418 MAC.SetFlag(fConfigHidden);
419 SetFlag(fConfigHidden);
420 }
421
422 EtherLikeInterface(config_obj &owner, const char *name, const char *desc = NULL) : InterfaceBlock(owner, name, desc)
423 {
424 ip4.SetFlag(fConfigHidden);
425#ifdef IPV6
426 ip6.SetFlag(fConfigHidden);
427#endif
428 MAC.SetFlag(fConfigHidden);
429 SetFlag(fConfigHidden);
430 }
431
432 virtual void Enable()
433 {
434 ClrFlag(fConfigHidden);
435 ip4.ClrFlag(fConfigHidden);
436#ifdef IPV6
437 ip6.ClrFlag(fConfigHidden);
438#endif
439 MAC.ClrFlag(fConfigHidden);
440 MAC.SetFlag(fConfigReadOnly);
441 }
442};
443
444/* Global receive processing definition */
445int NetDoRX(PoolPtr pp, uint16_t count, int if_num);
446
447/*
448 ******************************************************************************
449 *
450 * External Definitions
451 *
452 ******************************************************************************
453 */
454/*
455 System ARP Process Function
456*/
457extern ProcessArpFunc *pArpFunc;
458
459#ifdef IPV6
460
461/*
462 ******************************************************************************
463
464 IP6 Network Packet
465
466 Parameters:
467 poolPtr - Packet from pool
468
469 Return:
470 None
471
472 ******************************************************************************
473 */
474typedef void(ProcessIp6Func)(PoolPtr poolPtr);
475
476extern ProcessIp6Func *pIp6Func;
477
478#endif
479
480/*
481 System IP Packet Process Function
482*/
483extern ProcessPacketFunc *pPacketfunc;
484
485/*
486 ******************************************************************************
487 *
488 * Routine Prototypes
489 *
490 ******************************************************************************
491 */
492
493/*
494 ******************************************************************************
495
496 Selects Packet Transmission for the Interface
497
498 Parameters:
499 poolPtr - Packet from pool
500 interface - Interface number
501
502
503 Return:
504 None
505
506 Notes:
507 Frees buffer if interface is not valid
508
509 ******************************************************************************
510 */
511void TransmitBuffer(PoolPtr poolPtr, int interface);
512
513/*
514 ******************************************************************************
515
516 Extracts Data (Ethernet Frame) Pointer from Pool Packet
517
518 Parameters:
519 poolPtr - Packet from pool
520
521
522 Return:
523 Pointer to data segment (ethernet frame) of pool packet.
524
525 Notes:
526 Does not check for validity
527
528 ******************************************************************************
529 */
530inline PEFRAME GetEframe(PoolPtr pp)
531{
532 return (PEFRAME)pp->pData;
533}
534
535inline PVLEFRAME GetVLEframe(PoolPtr pp)
536{
537 return (PVLEFRAME)pp->pData;
538}
539
540
550int Removeinterface(int interface);
551
552
563void EnableMulticast(MACADR macAddress, int interface = 0);
564
576void DisableMulticast(MACADR macAddress, int interface = 0);
577
578
588
589
598int32_t GetFirstInterface(void);
599
600
608int32_t GetNextInterface(int lastInterface);
609
610
621
622
631
632
642bool GetInterfaceLink(int ifn);
643
644
645/*
646 ******************************************************************************
647 *
648 * Runtime Libraries Routine Prototypes
649 *
650 ******************************************************************************
651 */
652
653/*
654 ******************************************************************************
655
656 Initialize the first Ethernet Interface
657
658 Parameters:
659 processPacketFuncPtr - IP Packet process function
660 processArpFuncPtr - ARP Packet process function
661
662
663 Return:
664 TRUE success, else problems
665
666 Notes:
667 Should be called once in the system to create first interface.
668
669 ******************************************************************************
670 */
671BOOL InitializeNetwork(ProcessPacketFunc *processPacketFuncPtr, ProcessArpFunc *processArpFuncPtr);
672
673/*
674 ******************************************************************************
675
676 Disables network.
677
678 Parameters:
679 None
680
681 Return:
682 None
683
684 Notes:
685 None
686
687 ******************************************************************************
688 */
689void StopNetworks(void);
690
691/*
692 ******************************************************************************
693
694 Get current network settings.
695
696 Parameters:
697 interface - Interface number
698
699 Return:
700 Specific setting requested for the interface, 0 if invalid interface.
701
702 Notes:
703 None
704
705 ******************************************************************************
706 */
707
715MACADR InterfaceMAC(int interface);
716
726bool InterfaceLinkActive(int interface);
727
728
738int InterfaceLinkSpeed(int interface);
739
740
750bool InterfaceLinkDuplex(int interface);
751
761const char *InterfaceName(int interface);
762
763
764void UnWrapVlan(PoolPtr pp, int len);
765
766
767
768
790IPADDR4 InterfaceIP(int interface);
791
800
808IPADDR4 InterfaceDNS(int interface);
809
817IPADDR4 InterfaceDNS2(int interface);
818
826IPADDR4 InterfaceMASK(int interface);
827
835IPADDR4 InterfaceGate(int interface);
836
841#endif /* _NB_NETIF_H */
842
843
NetBurner Buffers API.
DHCP client class.
Definition dhcpclient.h:71
Definition config_netobj.h:274
Definition config_netobj.h:352
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:208
Network interface configuration block class for interface control and configuration.
Definition netinterface.h:245
virtual const char * GetInterfaceName()
Returns the interface name network interface.
virtual bool LinkDuplex()=0
Returns the full or half link duplex of the network interface.
virtual void EnableMulticast(MACADR macAddress, BOOL addAddress)=0
Enable Multicast on this interface.
virtual bool LinkActive()=0
Returns the link status of the network interface.
void RegisterInterface()
Register a network interface with system.
int GetInterfaceNumber()
Returns the Interface Number of the network interface.
Definition netinterface.h:375
InterfaceBlock(const char *name, const char *desc=NULL)
Constructor with interface name and description.
bool IsRootInterface()
Returns true if this is the first interface in the interface list.
Definition netinterface.h:382
InterfaceBlock(config_obj &owner, const char *name, const char *desc=NULL)
Constructor with config_obj owner, interface name and description.
virtual int LinkSpeed()=0
Returns the link speed of the network interface.
void InterfaceLinkChange(bool link)
Change the link status of the network interface.
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Configuration Variable for MACADR object type.
Definition config_obj.h:1750
Boolean Configuration Variable.
Definition config_obj.h:932
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:649
Base class used to create configuration objects.
Definition config_obj.h:277
String Configuration Variable.
Definition config_obj.h:1055
NetBurner Network Config Header File.
Configuration object header file.
NetBurner IPv4 DHCP Client Header File.
const uint32_t fConfigHidden
Not visible to configuration web server display.
Definition config_obj.h:74
const uint32_t fConfigReadOnly
Variable is read-only.
Definition config_obj.h:72
int Removeinterface(int interface)
Remove a network interface from the system.
bool InterfaceLinkDuplex(int interface)
Returns the full or half link duplex of the specified network interface.
int32_t GetInterfaceForMyAddress4(IPADDR4 ip)
Returns the Interface Number of the specified network interface IPv4 address.
const char * InterfaceName(int interface)
Returns the interface name of the specified network interface.
int InterfaceLinkSpeed(int interface)
Returns the 10/100 link speed of the specified network interface.
int32_t GetFirstInterface(void)
Returns the Interface Number of the first registered network interface.
int32_t GetNextInterface(int lastInterface)
Returns the Interface Number of the next registered network interface.
int32_t GetInterfaceNumber(InterfaceBlock *pifb)
Returns the Interface Number of the specified network interface InterfaceBlock.
MACADR InterfaceMAC(int interface)
Returns the MAC address of the specified network interface.
void EnableMulticast(MACADR macAddress, int interface=0)
Enable Multicast on an existing interface.
bool GetInterfaceLink(int ifn)
Returns the network interface link status.
void DisableMulticast(MACADR macAddress, int interface=0)
Disable Multicast on an existing interface.
bool InterfaceLinkActive(int interface)
Returns the link status of the specified network interface.
InterfaceBlock * GetInterfaceBlock(int interface=0)
Get an InterfaceBlock control and configuration object.
IPADDR4 InterfaceDNS2(int interface)
Returns the second IPv4 DNS address of the specified network interface.
IPADDR4 InterfaceMASK(int interface)
Returns the IPv4 network mask of the specified network interface.
IPADDR4 InterfaceAutoIP(int interface)
Returns the IPv4 IP AutoIP address of the specified network interface.
IPADDR4 InterfaceDNS(int interface)
Returns the IPv4 DNS address of the specified network interface.
IPADDR4 InterfaceIP(int interface)
Returns the IPv4 IP address of the specified network interface.
IPADDR4 InterfaceGate(int interface)
Returns the IPv4 gateway address of the specified network interface.
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.