NetBurner 3.5.7
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 * Definitions
56 *------------------------------------------------------------------------------*/
57
58// PPP Interface Identifier
59#define ARP_PPP_INTERFACE (255)
60
61/*-------------------------------------------------------------------------------
62 *
63 * MAC Address for second and subsequent interfaces
64 * For a second and subsequent NICs the MSB(it) of the 5th octet is XOR'ed
65 * with 1 to support prior released tools.
66 *
67 * 6 bytes
68 * <--------------------------------------------------------------------->
69 * 0 1 2 3 4 5
70 * -----------------------------------------------------------------------
71 * | 6th byte | 5th byte | 4th byte | 3rd byte | 2nd byte | 1st byte |
72 * | 1st octet | 2nd octet | 3rd octet | 4th octet | 5th octet | 6th octet |
73 * -----------------------------------------------------------------------
74 *
75 * 3 bytes 3 bytes
76 * <---------------------------------> <--------------------------------->
77 * -----------------------------------------------------------------------
78 * | Organizationally Unique Identifier | Network Interface Controller |
79 * | | (OUI) | | | (NIC) | |
80 * | 0x00 | 0x03 | 0xF4 | 0xYX | 0xZX | 0xXX |
81 * -----------------------------------------------------------------------
82 * | \ OUI is NetBurner's Y is IIXX XXXX binary
83 * | \ I is the interface defined as
84 * | \ bits in NB_MAX_NIC... below
85 * | | Z is WXXX binary
86 * V V W ix XOR'd bit
87 * |1|2|3|4|5|6|7|8| (7) 0 global, 1 local, (8) 0 unicast, 1 multicast (IEE)
88 *
89 * Notes:
90 * 0-5 are C language offsets, 6th byte through 1st byte is Ethernet
91 * transmission order and octet notation is from IEEE 802 MAC-48 address.
92 * Derivation is needed if the NIC does not have a non-volatile MAC address.
93 *
94 *-------------------------------------------------------------------------------*/
95#ifndef NB_MAC_ADDRESS
96#define NB_MAC_ADDRESS
97
98/* 4th Octet */
99#define NB_MAC_NIC_INTERFACE (0x00)
100#define NB_MAC_NIC_SECOND_INTERFACE (0x80)
101#define NB_MAC_NIC_THIRD_INTERFACE (0x40)
102#define NB_MAC_NIC_FOURTH_INTERFACE (0xC0)
103#define NB_MAC_NIC_SECOND_INTERFACE_MASK \
104 (NB_MAC_NIC_INTERFACE | NB_MAC_NIC_SECOND_INTERFACE | NB_MAC_NIC_THIRD_INTERFACE | NB_MAC_NIC_FOURTH_INTERFACE)
105#define NB_MAC_OCTET_4 (3)
106#define NB_MAC_OCTET_5 (4)
107#define NB_MAC_OCTET_5_XOR (0x80)
108
109#endif /* NB_MAC_ADDRESS */
110
111
112/*-----------------------------------------------------------------------------
113 * Callback Function Prototypes
114 *-----------------------------------------------------------------------------*/
115
116/*
117 ******************************************************************************
118
119 Process Internet Protocol Packet (IP)
120
121 Parameters:
122 poolPtr - Packet from pool
123 ethernetFramePtr - Ethernet frame
124 checksum - IP frame checksum
125
126 Return:
127 None
128
129 Notes;
130 Called for every IP packet received and meets this criteria.
131 1)The packet is an IP packet.
132 2)The IP header checksum is valid.
133 3)The packet was addressed to us or to a broadcast address.
134 Before the callback is called the flags member of the buffer is setup to
135 indicate physical broadcast etc....
136
137 ******************************************************************************
138 */
139typedef void(ProcessPacketFunc)(PoolPtr poolPtr, PEFRAME ethernetFramePtr, uint16_t checksum);
140
141/*
142 ******************************************************************************
143
144 Process Address Resolution Packet (ARP)
145
146 Parameters:
147 poolPtr - Packet from pool
148 ethernetFramePtr - Ethernet frame
149
150 Return:
151 None
152
153 Notes;
154 Called for every ARP packet received. Before the callback is called the
155 flags member of the buffer is setup to indicate physical broadcast etc...
156
157 ******************************************************************************
158 */
159typedef void(ProcessArpFunc)(PoolPtr poolPtr, PEFRAME ethernetFramePtr);
160
161/*
162 ******************************************************************************
163
164 Process Address LLDP
165
166 Parameters:
167 poolPtr - Packet from pool
168 ethernetFramePtr - Ethernet frame
169
170 Return:
171 None
172
173 Notes;
174 If filled in called for every LLDP frame
175 flags member of the buffer is setup to indicate physical broadcast etc...
176
177 ******************************************************************************
178 */
179typedef void (*ProcessLLDPptr)(PoolPtr poolPtr);
180
181extern ProcessLLDPptr pProcessLLDP;
182
183/*
184 ******************************************************************************
185
186 Returns current link active status
187
188 Parameters:
189 None
190
191 Return:
192 TRUE active, FALSE all else.
193
194 Notes:
195 Interface driver must minimize latency.
196
197 ******************************************************************************
198 */
199typedef BOOL(LinkActiveFunc)(void);
200
201
202/*
203 ******************************************************************************
204 *
205 * Data Structures
206 *
207 ******************************************************************************
208 */
209
210#define INTF_CSUM_IP (0x01)
211#define INTF_CSUM_ICMP (0x02)
212#define INTF_CSUM_UDP (0x04)
213#define INTF_CSUM_TCP (0x08)
214#define INTF_CSUM_IP6 (0x10)
215#define INTF_CSUM_ICMP6 (0x20)
216#define INTF_CSUM_UDP6 (0x40)
217#define INTF_CSUM_TCP6 (0x80)
218
219#define INTF_CSUM_ALL4 (INTF_CSUM_IP | INTF_CSUM_ICMP | INTF_CSUM_UDP | INTF_CSUM_TCP)
220#define INTF_CSUM_ALL6 (INTF_CSUM_IP6 | INTF_CSUM_ICMP6 | INTF_CSUM_UDP6 | INTF_CSUM_TCP6)
221
222
244{
245 public:
246 I4Record ip4{"IPv4"};
247#ifdef IPV6
248 I6Record ip6{"IPv6"};
249#endif
250 config_MACADR MAC{"00:00:00:00:00:00", "MAC"};
251 config_string device_name{"", "DeviceName"};
252 config_string net_domain{"", "NetworkDomain"};
253 config_int dhcp_discover_secs{1, "DhcpDiscoverSec"};
254 config_string discovery_server{"discover.netburner.com/DevicePost", "DiscoveryReportUrl"};
255 config_int discovery_interval{(15 * 60), "DiscoveryReportInterval"};
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"};
259
260 ConfigEndMarker; // Marker for end of configuration structure
261
262 int32_t root_if;
263 int32_t my_ifnum;
264 uint16_t netMss;
268 discover_servlet disco_servlet{this};
269 void (*MCastLinkNotify)(InterfaceBlock *pBlock, bool bLink);
270
274
275#ifdef AUTOIP // if not defined don't compile anything...
276 AutoIPClient AutoClient;
277#endif
278
279#if defined MULTIHOME
280 BOOL bMultiHome;
281 InterfaceBlock *pChild;
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#ifdef ENABLE_SNMP
404 void AddInterfaceToSnmpTree();
405 unsigned int EthifInOctets;
406 unsigned int EthifInUcastPkts;
407 unsigned int EthifInNUcastPkts;
408 unsigned int EthifInDiscards;
409 unsigned int EthifInErrors;
410 unsigned int EthifInUnknownProtos;
411 unsigned int EthifOutOctets;
412 unsigned int EthifOutUcastPkts;
413 unsigned int EthifOutNUcastPkts;
414 unsigned int EthifOutDiscards;
415 unsigned int EthifOutErrors;
416#endif
417
418};
419
420
421
422// Adds additional features to an InterfaceBlock. Defaults to most features disabled
423class EtherLikeInterface : public InterfaceBlock
424{
425 public:
426 ConfigEndMarker;
427 EtherLikeInterface(const char *name, const char *desc = NULL) : InterfaceBlock(name, desc)
428 {
429 ip4.SetFlag(fConfigHidden);
430#ifdef IPV6
431 ip6.SetFlag(fConfigHidden);
432#endif
433 MAC.SetFlag(fConfigHidden);
434 SetFlag(fConfigHidden);
435 }
436
437 EtherLikeInterface(config_obj &owner, const char *name, const char *desc = NULL) : InterfaceBlock(owner, name, desc)
438 {
439 ip4.SetFlag(fConfigHidden);
440#ifdef IPV6
441 ip6.SetFlag(fConfigHidden);
442#endif
443 MAC.SetFlag(fConfigHidden);
444 SetFlag(fConfigHidden);
445 }
446
447 virtual void Enable()
448 {
449 ClrFlag(fConfigHidden);
450 ip4.ClrFlag(fConfigHidden);
451#ifdef IPV6
452 ip6.ClrFlag(fConfigHidden);
453#endif
454 MAC.ClrFlag(fConfigHidden);
455 MAC.SetFlag(fConfigReadOnly);
456 }
457};
458
459/* Global receive processing definition */
460int NetDoRX(PoolPtr pp, uint16_t count, int if_num);
461
462/*
463 ******************************************************************************
464 *
465 * External Definitions
466 *
467 ******************************************************************************
468 */
469/*
470 System ARP Process Function
471*/
472extern ProcessArpFunc *pArpFunc;
473
474#ifdef IPV6
475
476/*
477 ******************************************************************************
478
479 IP6 Network Packet
480
481 Parameters:
482 poolPtr - Packet from pool
483
484 Return:
485 None
486
487 ******************************************************************************
488 */
489typedef void(ProcessIp6Func)(PoolPtr poolPtr);
490
491extern ProcessIp6Func *pIp6Func;
492
493#endif
494
495/*
496 System IP Packet Process Function
497*/
498extern ProcessPacketFunc *pPacketfunc;
499
500/*
501 ******************************************************************************
502 *
503 * Routine Prototypes
504 *
505 ******************************************************************************
506 */
507
508/*
509 ******************************************************************************
510
511 Selects Packet Transmission for the Interface
512
513 Parameters:
514 poolPtr - Packet from pool
515 interface - Interface number
516
517
518 Return:
519 None
520
521 Notes:
522 Frees buffer if interface is not valid
523
524 ******************************************************************************
525 */
526void TransmitBuffer(PoolPtr poolPtr, int interface);
527
528/*
529 ******************************************************************************
530
531 Extracts Data (Ethernet Frame) Pointer from Pool Packet
532
533 Parameters:
534 poolPtr - Packet from pool
535
536
537 Return:
538 Pointer to data segment (ethernet frame) of pool packet.
539
540 Notes:
541 Does not check for validity
542
543 ******************************************************************************
544 */
545inline PEFRAME GetEframe(PoolPtr pp)
546{
547 return (PEFRAME)pp->pData;
548}
549
550inline PVLEFRAME GetVLEframe(PoolPtr pp)
551{
552 return (PVLEFRAME)pp->pData;
553}
554
555
565int Removeinterface(int interface);
566
567
578void EnableMulticast(MACADR macAddress, int interface = 0);
579
591void DisableMulticast(MACADR macAddress, int interface = 0);
592
593
603
604
613int32_t GetFirstInterface(void);
614
615
623int32_t GetNextInterface(int lastInterface);
624
625
636
637
646
647
657bool GetInterfaceLink(int ifn);
658
659
660/*
661 ******************************************************************************
662 *
663 * Runtime Libraries Routine Prototypes
664 *
665 ******************************************************************************
666 */
667
668/*
669 ******************************************************************************
670
671 Initialize the first Ethernet Interface
672
673 Parameters:
674 processPacketFuncPtr - IP Packet process function
675 processArpFuncPtr - ARP Packet process function
676
677
678 Return:
679 TRUE success, else problems
680
681 Notes:
682 Should be called once in the system to create first interface.
683
684 ******************************************************************************
685 */
686BOOL InitializeNetwork(ProcessPacketFunc *processPacketFuncPtr, ProcessArpFunc *processArpFuncPtr);
687
688/*
689 ******************************************************************************
690
691 Disables network.
692
693 Parameters:
694 None
695
696 Return:
697 None
698
699 Notes:
700 None
701
702 ******************************************************************************
703 */
704void StopNetworks(void);
705
706/*
707 ******************************************************************************
708
709 Get current network settings.
710
711 Parameters:
712 interface - Interface number
713
714 Return:
715 Specific setting requested for the interface, 0 if invalid interface.
716
717 Notes:
718 None
719
720 ******************************************************************************
721 */
722
730MACADR InterfaceMAC(int interface);
731
741bool InterfaceLinkActive(int interface);
742
743
753int InterfaceLinkSpeed(int interface);
754
755
765bool InterfaceLinkDuplex(int interface);
766
776const char *InterfaceName(int interface);
777
778
779void UnWrapVlan(PoolPtr pp, int len);
780
781
782
783
805IPADDR4 InterfaceIP(int interface);
806
815
823IPADDR4 InterfaceDNS(int interface);
824
832IPADDR4 InterfaceDNS2(int interface);
833
841IPADDR4 InterfaceMASK(int interface);
842
850IPADDR4 InterfaceGate(int interface);
851
861bool HaveActiveNetwork(int interface = -1);
862
867#endif /* _NB_NETIF_H */
868
869
DHCP client class.
Definition dhcpclient.h:71
Definition config_netobj.h:302
Definition config_netobj.h:384
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:244
uint16_t netMss
Network max segment size for this interface.
Definition netinterface.h:264
discover_servlet disco_servlet
The servlet that runs the NetBurner discovery server process.
Definition netinterface.h:268
config_int dhcp_discover_secs
Seconds to delay after boot before sending a DHCP Discover message.
Definition netinterface.h:253
uint8_t checksumOffload
Non-zero if hardware interface support offloading checksum calculation.
Definition netinterface.h:265
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:269
AutoIPClient AutoClient
AutoIP client object for this interface.
Definition netinterface.h:276
virtual void EnableMulticast(MACADR macAddress, BOOL addAddress)=0
Enable Multicast on this interface.
int32_t my_ifnum
This interface number.
Definition netinterface.h:263
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:250
DhcpObject dhcpClient
DHCP client support.
Definition netinterface.h:267
config_int vlan_tag_value
VLAN tag.
Definition netinterface.h:258
config_string device_name
Name of interface. Used to register for DNS and NetBIOS.
Definition netinterface.h:251
int GetInterfaceNumber()
Returns the Interface Number of the network interface.
Definition netinterface.h:375
IPADDR4 previous_addr
Previous IPv4 address.
Definition netinterface.h:271
config_string net_domain
Network Domain.
Definition netinterface.h:252
config_bool obfuscate_discovery
Obfuscate data instead of plain text.
Definition netinterface.h:256
config_int discovery_interval
How often to report to the NetBurner discover server.
Definition netinterface.h:255
I4Record ip4
IPv4 configuration for "this" interface, see config_netobj.h for details.
Definition netinterface.h:246
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.
config_string discovery_server
NetBurner discover server name.
Definition netinterface.h:254
IPADDR4 previous_mask
Previous IPv4 mask.
Definition netinterface.h:272
bool bHaveSeenLink
True if a link has been present previously at least once.
Definition netinterface.h:266
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:248
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:262
config_bool supress_default_responses
Disable Ping and Echo (port 7)
Definition netinterface.h:257
IPADDR4 previous_gate
Previous IPv4 gateway.
Definition netinterface.h:273
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Configuration Variable for MACADR object type.
Definition config_obj.h:1859
Boolean Configuration Variable.
Definition config_obj.h:998
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:701
Base class used to create configuration objects.
Definition config_obj.h:321
String Configuration Variable.
Definition config_obj.h:1128
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