xref: /haiku/headers/private/kernel/boot/net/IP.h (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _BOOT_IP_H
7 #define _BOOT_IP_H
8 
9 #include <boot/net/Ethernet.h>
10 
11 class ARPService;
12 class IPService;
13 
14 // IPSubService
15 class IPSubService : public NetService {
16 public:
17 	IPSubService(const char *serviceName);
18 	virtual ~IPSubService();
19 
20 	virtual uint8 IPProtocol() const = 0;
21 
22 	virtual void HandleIPPacket(IPService *ipService, ip_addr_t sourceIP,
23 		ip_addr_t destinationIP, const void *data, size_t size) = 0;
24 };
25 
26 
27 // IPService
28 class IPService : public EthernetSubService {
29 	// actually IP over ethernet
30 public:
31 	IPService(EthernetService *ethernet, ARPService *arpService);
32 	virtual ~IPService();
33 
34 	status_t Init();
35 
36 	ip_addr_t IPAddress() const;
37 
38 	virtual uint16 EthernetProtocol() const;
39 
40 	virtual void HandleEthernetPacket(EthernetService *ethernet,
41 		const mac_addr_t &targetAddress, const void *data, size_t size);
42 
43 	status_t Send(ip_addr_t destination, uint8 protocol, ChainBuffer *buffer);
44 
45 	void ProcessIncomingPackets();
46 
47 	bool RegisterIPSubService(IPSubService *service);
48 	bool UnregisterIPSubService(IPSubService *service);
49 
50 	virtual int CountSubNetServices() const;
51 	virtual NetService *SubNetServiceAt(int index) const;
52 
53 private:
54 	uint16 _Checksum(const ip_header &header);
55 
56 	EthernetService			*fEthernet;
57 	ARPService				*fARPService;
58 	Vector<IPSubService*>	fServices;
59 };
60 
61 uint16 ip_checksum(ChainBuffer *buffer);
62 ip_addr_t ip_parse_address(const char* address);
63 
64 
65 #endif	// _BOOT_IP_H
66