1 | /*
|
---|
2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup ip
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @file
|
---|
34 | * IP module.
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef NET_IP_H_
|
---|
38 | #define NET_IP_H_
|
---|
39 |
|
---|
40 | #include <fibril_synch.h>
|
---|
41 | #include <ipc/ipc.h>
|
---|
42 | #include <ipc/services.h>
|
---|
43 |
|
---|
44 | #include <net/device.h>
|
---|
45 | #include <net/inet.h>
|
---|
46 | #include <ip_interface.h>
|
---|
47 | #include <adt/int_map.h>
|
---|
48 | #include <adt/generic_field.h>
|
---|
49 | #include <adt/module_map.h>
|
---|
50 |
|
---|
51 | /** Type definition of the IP global data.
|
---|
52 | * @see ip_globals
|
---|
53 | */
|
---|
54 | typedef struct ip_globals ip_globals_t;
|
---|
55 |
|
---|
56 | /** Type definition of the IP network interface specific data.
|
---|
57 | * @see ip_netif
|
---|
58 | */
|
---|
59 | typedef struct ip_netif ip_netif_t;
|
---|
60 |
|
---|
61 | /** Type definition of the IP protocol specific data.
|
---|
62 | * @see ip_proto
|
---|
63 | */
|
---|
64 | typedef struct ip_proto ip_proto_t;
|
---|
65 |
|
---|
66 | /** Type definition of the IP route specific data.
|
---|
67 | * @see ip_route
|
---|
68 | */
|
---|
69 | typedef struct ip_route ip_route_t;
|
---|
70 |
|
---|
71 | /** IP network interfaces.
|
---|
72 | * Maps devices to the IP network interface specific data.
|
---|
73 | * @see device.h
|
---|
74 | */
|
---|
75 | DEVICE_MAP_DECLARE(ip_netifs, ip_netif_t);
|
---|
76 |
|
---|
77 | /** IP registered protocols.
|
---|
78 | * Maps protocols to the IP protocol specific data.
|
---|
79 | * @see int_map.h
|
---|
80 | */
|
---|
81 | INT_MAP_DECLARE(ip_protos, ip_proto_t);
|
---|
82 |
|
---|
83 | /** IP routing table.
|
---|
84 | * @see generic_field.h
|
---|
85 | */
|
---|
86 | GENERIC_FIELD_DECLARE(ip_routes, ip_route_t);
|
---|
87 |
|
---|
88 | /** IP network interface specific data. */
|
---|
89 | struct ip_netif {
|
---|
90 | /** ARP module. Assigned if using ARP. */
|
---|
91 | module_t *arp;
|
---|
92 | /** Broadcast address. */
|
---|
93 | in_addr_t broadcast;
|
---|
94 | /** Device identifier. */
|
---|
95 | device_id_t device_id;
|
---|
96 | /** Indicates whether using DHCP. */
|
---|
97 | int dhcp;
|
---|
98 | /** IP version. */
|
---|
99 | int ipv;
|
---|
100 | /** Packet dimension. */
|
---|
101 | packet_dimension_t packet_dimension;
|
---|
102 | /** Netif module phone. */
|
---|
103 | int phone;
|
---|
104 | /** Routing table. */
|
---|
105 | ip_routes_t routes;
|
---|
106 | /** Indicates whether IP routing is enabled. */
|
---|
107 | int routing;
|
---|
108 | /** Netif module service. */
|
---|
109 | services_t service;
|
---|
110 | /** Device state. */
|
---|
111 | device_state_t state;
|
---|
112 | };
|
---|
113 |
|
---|
114 | /** IP protocol specific data. */
|
---|
115 | struct ip_proto {
|
---|
116 | /** Protocol module phone. */
|
---|
117 | int phone;
|
---|
118 | /** Protocol number. */
|
---|
119 | int protocol;
|
---|
120 | /** Protocol packet receiving function. */
|
---|
121 | tl_received_msg_t received_msg;
|
---|
122 | /** Protocol module service. */
|
---|
123 | services_t service;
|
---|
124 | };
|
---|
125 |
|
---|
126 | /** IP route specific data. */
|
---|
127 | struct ip_route {
|
---|
128 | /** Target address. */
|
---|
129 | in_addr_t address;
|
---|
130 | /** Gateway. */
|
---|
131 | in_addr_t gateway;
|
---|
132 | /** Parent netif. */
|
---|
133 | ip_netif_t *netif;
|
---|
134 | /** Target network mask. */
|
---|
135 | in_addr_t netmask;
|
---|
136 | };
|
---|
137 |
|
---|
138 | /** IP global data. */
|
---|
139 | struct ip_globals {
|
---|
140 | /** Default client connection function for support modules. */
|
---|
141 | async_client_conn_t client_connection;
|
---|
142 | /** Default gateway. */
|
---|
143 | ip_route_t gateway;
|
---|
144 | /** Safety lock. */
|
---|
145 | fibril_rwlock_t lock;
|
---|
146 | /** Known support modules. */
|
---|
147 | modules_t modules;
|
---|
148 | /** Networking module phone. */
|
---|
149 | int net_phone;
|
---|
150 | /** Registered network interfaces. */
|
---|
151 | ip_netifs_t netifs;
|
---|
152 | /** Netifs safeyt lock. */
|
---|
153 | fibril_rwlock_t netifs_lock;
|
---|
154 | /** Packet counter. */
|
---|
155 | uint16_t packet_counter;
|
---|
156 | /** Registered protocols. */
|
---|
157 | ip_protos_t protos;
|
---|
158 | /** Protocols safety lock. */
|
---|
159 | fibril_rwlock_t protos_lock;
|
---|
160 | };
|
---|
161 |
|
---|
162 | #endif
|
---|
163 |
|
---|
164 | /** @}
|
---|
165 | */
|
---|