NetBurner 3.5.6
PDF Version
netinterface.h
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"};
248#ifdef IPV6
249 I6Record ip6{"IPv6"};
250#endif
251 config_MACADR MAC{"00:00:00:00:00:00", "MAC"};
252 config_string device_name{"", "DeviceName"};
253 config_string net_domain{"", "NetworkDomain"};
254 config_int dhcp_discover_secs{1, "DhcpDiscoverSec"};
255 config_string discovery_server{"discover.netburner.com/DevicePost", "DiscoveryReportUrl"};
256 config_int discovery_interval{(15 * 60), "DiscoveryReportInterval"};
257 config_bool obfuscate_discovery{true, "DiscoveryObfuscate", "Should discovery obfuscate data"};
258 config_bool supress_default_responses{false, "SupressDefault", "Supress ping and udp Echo ports"};
260
261 ConfigEndMarker; // Marker for end of configuration structure
262
263 int32_t root_if;
264 int32_t my_ifnum;
265 uint16_t netMss;
269 discover_servlet disco_servlet{this};
270 void (*MCastLinkNotify)(InterfaceBlock *pBlock, bool bLink);
271
275
276#ifdef AUTOIP // if not defined don't compile anything...
277 AutoIPClient AutoClient;
278#endif
279
280#if defined MULTIHOME
281 BOOL bMultiHome;
282 InterfaceBlock *pChild;
283#endif
284
291 InterfaceBlock(const char *name, const char *desc = NULL);
292
300 InterfaceBlock(config_obj &owner, const char *name, const char *desc = NULL);
301
310
311 virtual void send_func(PoolPtr poolPtr) = 0;
312 virtual void kill_if();
313
324 virtual void EnableMulticast(MACADR macAddress, BOOL addAddress) = 0;
325
333 virtual bool LinkActive() = 0;
334
342 virtual int LinkSpeed() = 0;
343
351 virtual bool LinkDuplex() = 0;
352
358 void InterfaceLinkChange(bool link);
359
367 virtual const char *GetInterfaceName();
368
376 int GetInterfaceNumber() { return my_ifnum; }
377
383 inline bool IsRootInterface() { return root_if == 0; }
384
385 // Move values from the IPV4 settings to cur stuff.
386 // Starts /Shutdowns DHCP if necessary
387 // Stores previous values in previous_addr,_mask,_gate;
388 // Returns true if the address changed.
389 bool ProcessIPConfigChange(uint16_t ticks_to_wait);
390
391 //Used if the web page changes IP values to swap so one can complete socket.
392 void SwapOldAndCurrentAddr();
393
394 virtual bool bNeedsArp() { return true; };
395 void fdShowInterfaceValues(int fd);
396 inline void ShowInterfaceValues() { fdShowInterfaceValues(1); };
397 void SetDefaultFlags();
398 // Called by DHCP client when we get new settings...
399 void DHCPNotify();
400
401#if defined MULTIHOME
402 int RegisterMultiHomeInterface(InterfaceBlock &UnderBlock);
403#endif
404};
405
406
407
408// Adds additional features to an InterfaceBlock. Defaults to most features disabled
409class EtherLikeInterface : public InterfaceBlock
410{
411 public:
412 ConfigEndMarker;
413 EtherLikeInterface(const char *name, const char *desc = NULL) : InterfaceBlock(name, desc)
414 {
415 ip4.SetFlag(fConfigHidden);
416#ifdef IPV6
417 ip6.SetFlag(fConfigHidden);
418#endif
419 MAC.SetFlag(fConfigHidden);
420 SetFlag(fConfigHidden);
421 }
422
423 EtherLikeInterface(config_obj &owner, const char *name, const char *desc = NULL) : InterfaceBlock(owner, name, desc)
424 {
425 ip4.SetFlag(fConfigHidden);
426#ifdef IPV6
427 ip6.SetFlag(fConfigHidden);
428#endif
429 MAC.SetFlag(fConfigHidden);
430 SetFlag(fConfigHidden);
431 }
432
433 virtual void Enable()
434 {
435 ClrFlag(fConfigHidden);
436 ip4.ClrFlag(fConfigHidden);
437#ifdef IPV6
438 ip6.ClrFlag(fConfigHidden);
439#endif
440 MAC.ClrFlag(fConfigHidden);
441 MAC.SetFlag(fConfigReadOnly);
442 }
443};
444
445/* Global receive processing definition */
446int NetDoRX(PoolPtr pp, uint16_t count, int if_num);
447
448/*
449 ******************************************************************************
450 *
451 * External Definitions
452 *
453 ******************************************************************************
454 */
455/*
456 System ARP Process Function
457*/
458extern ProcessArpFunc *pArpFunc;
459
460#ifdef IPV6
461
462/*
463 ******************************************************************************
464
465 IP6 Network Packet
466
467 Parameters:
468 poolPtr - Packet from pool
469
470 Return:
471 None
472
473 ******************************************************************************
474 */
475typedef void(ProcessIp6Func)(PoolPtr poolPtr);
476
477extern ProcessIp6Func *pIp6Func;
478
479#endif
480
481/*
482 System IP Packet Process Function
483*/
484extern ProcessPacketFunc *pPacketfunc;
485
486/*
487 ******************************************************************************
488 *
489 * Routine Prototypes
490 *
491 ******************************************************************************
492 */
493
494/*
495 ******************************************************************************
496
497 Selects Packet Transmission for the Interface
498
499 Parameters:
500 poolPtr - Packet from pool
501 interface - Interface number
502
503
504 Return:
505 None
506
507 Notes:
508 Frees buffer if interface is not valid
509
510 ******************************************************************************
511 */
512void TransmitBuffer(PoolPtr poolPtr, int interface);
513
514/*
515 ******************************************************************************
516
517 Extracts Data (Ethernet Frame) Pointer from Pool Packet
518
519 Parameters:
520 poolPtr - Packet from pool
521
522
523 Return:
524 Pointer to data segment (ethernet frame) of pool packet.
525
526 Notes:
527 Does not check for validity
528
529 ******************************************************************************
530 */
531inline PEFRAME GetEframe(PoolPtr pp)
532{
533 return (PEFRAME)pp->pData;
534}
535
536inline PVLEFRAME GetVLEframe(PoolPtr pp)
537{
538 return (PVLEFRAME)pp->pData;
539}
540
541
551int Removeinterface(int interface);
552
553
564void EnableMulticast(MACADR macAddress, int interface = 0);
565
577void DisableMulticast(MACADR macAddress, int interface = 0);
578
579
589
590
599int32_t GetFirstInterface(void);
600
601
609int32_t GetNextInterface(int lastInterface);
610
611
622
623
632
633
643bool GetInterfaceLink(int ifn);
644
645
646/*
647 ******************************************************************************
648 *
649 * Runtime Libraries Routine Prototypes
650 *
651 ******************************************************************************
652 */
653
654/*
655 ******************************************************************************
656
657 Initialize the first Ethernet Interface
658
659 Parameters:
660 processPacketFuncPtr - IP Packet process function
661 processArpFuncPtr - ARP Packet process function
662
663
664 Return:
665 TRUE success, else problems
666
667 Notes:
668 Should be called once in the system to create first interface.
669
670 ******************************************************************************
671 */
672BOOL InitializeNetwork(ProcessPacketFunc *processPacketFuncPtr, ProcessArpFunc *processArpFuncPtr);
673
674/*
675 ******************************************************************************
676
677 Disables network.
678
679 Parameters:
680 None
681
682 Return:
683 None
684
685 Notes:
686 None
687
688 ******************************************************************************
689 */
690void StopNetworks(void);
691
692/*
693 ******************************************************************************
694
695 Get current network settings.
696
697 Parameters:
698 interface - Interface number
699
700 Return:
701 Specific setting requested for the interface, 0 if invalid interface.
702
703 Notes:
704 None
705
706 ******************************************************************************
707 */
708
716MACADR InterfaceMAC(int interface);
717
727bool InterfaceLinkActive(int interface);
728
729
739int InterfaceLinkSpeed(int interface);
740
741
751bool InterfaceLinkDuplex(int interface);
752
762const char *InterfaceName(int interface);
763
764
765void UnWrapVlan(PoolPtr pp, int len);
766
767
768
769
791IPADDR4 InterfaceIP(int interface);
792
801
809IPADDR4 InterfaceDNS(int interface);
810
818IPADDR4 InterfaceDNS2(int interface);
819
827IPADDR4 InterfaceMASK(int interface);
828
836IPADDR4 InterfaceGate(int interface);
837
847bool HaveActiveNetwork(int interface = -1);
848
853#endif /* _NB_NETIF_H */
854
855
DHCP client class.
Definition dhcpclient.h:71
Definition config_netobj.h:302
Definition config_netobj.h:382
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
Network interface configuration block class for interface control and configuration.
Definition netinterface.h:245
uint16_t netMss
Network max segment size for this interface.
Definition netinterface.h:265
discover_servlet disco_servlet
The servlet that runs the NetBurner discovery server process.
Definition netinterface.h:269
config_int dhcp_discover_secs
Seconds to delay after boot before sending a DHCP Discover message.
Definition netinterface.h:254
uint8_t checksumOffload
Non-zero if hardware interface support offloading checksum calculation.
Definition netinterface.h:266
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.
void(* MCastLinkNotify)(InterfaceBlock *pBlock, bool bLink)
A funciton pointer called when link changes for multicast.
Definition netinterface.h:270
AutoIPClient AutoClient
AutoIP client object for this interface.
Definition netinterface.h:277
virtual void EnableMulticast(MACADR macAddress, BOOL addAddress)=0
Enable Multicast on this interface.
int32_t my_ifnum
This interface number.
Definition netinterface.h:264
virtual bool LinkActive()=0
Returns the link status of the network interface.
void RegisterInterface()
Register a network interface with system.
config_MACADR MAC
Interface MAC address. May be 0 or null for interfaces such as PPP.
Definition netinterface.h:251
DhcpObject dhcpClient
DHCP client support.
Definition netinterface.h:268
config_int vlan_tag_value
VLAN tag.
Definition netinterface.h:259
config_string device_name
Name of interface. Used to register for DNS and NetBIOS.
Definition netinterface.h:252
int GetInterfaceNumber()
Returns the Interface Number of the network interface.
Definition netinterface.h:376
IPADDR4 previous_addr
Previous IPv4 address.
Definition netinterface.h:272
config_string net_domain
Network Domain.
Definition netinterface.h:253
config_bool obfuscate_discovery
Obfuscate data instead of plain text.
Definition netinterface.h:257
config_int discovery_interval
How often to report to the NetBurner discover server.
Definition netinterface.h:256
I4Record ip4
IPv4 configuration for "this" interface, see config_netobj.h for details.
Definition netinterface.h:247
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:383
InterfaceBlock(config_obj &owner, const char *name, const char *desc=NULL)
Constructor with config_obj owner, interface name and description.
config_string discovery_server
NetBurner discover server name.
Definition netinterface.h:255
IPADDR4 previous_mask
Previous IPv4 mask.
Definition netinterface.h:273
bool bHaveSeenLink
True if a link has been present previously at least once.
Definition netinterface.h:267
virtual int LinkSpeed()=0
Returns the link speed of the network interface.
I6Record ip6
IPv6 configuration for "this" interface, see config_netobj.h for details.
Definition netinterface.h:249
void InterfaceLinkChange(bool link)
Change the link status of the network interface.
int32_t root_if
Root interface number. If multihomed, the interface would be a child of the root interface.
Definition netinterface.h:263
config_bool supress_default_responses
Disable Ping and Echo (port 7)
Definition netinterface.h:258
IPADDR4 previous_gate
Previous IPv4 gateway.
Definition netinterface.h:274
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Configuration Variable for MACADR object type.
Definition config_obj.h:1853
Boolean Configuration Variable.
Definition config_obj.h:997
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:700
Base class used to create configuration objects.
Definition config_obj.h:320
String Configuration Variable.
Definition config_obj.h:1127
const uint32_t fConfigHidden
Not visible to configuration web server display.
Definition config_obj.h:78
const uint32_t fConfigReadOnly
Variable is read-only.
Definition config_obj.h:76
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.
bool HaveActiveNetwork(int interface=-1)
Returns the network routability 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.
Main buffer structure for network and serial communication.
Definition buffers.h:90
uint8_t pData[ETHER_BUFFER_SIZE]
Buffer data payload (1548 bytes)
Definition buffers.h:104