source: mainline/uspace/lib/net/il/ip_remote.c@ 522253c1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 522253c1 was 522253c1, checked in by Jakub Jermar <jakub@…>, 15 years ago

Move Internet layer modules messages definitions to standard library.

  • Property mode set to 100644
File size: 7.8 KB
Line 
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 *
35 * IP interface implementation for remote modules.
36 *
37 * @see ip_interface.h
38 * @see il_interface.h
39 *
40 */
41
42#include <ip_remote.h>
43#include <ip_interface.h>
44#include <ip_messages.h>
45#include <packet_client.h>
46#include <generic.h>
47
48#include <ipc/services.h>
49#include <ipc/il.h>
50
51#include <net/modules.h>
52#include <net/device.h>
53#include <net/inet.h>
54
55/** Add a route to the device routing table.
56 *
57 * The target network is routed using this device.
58 *
59 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
60 * @param[in] device_id The device identifier.
61 * @param[in] address The target network address.
62 * @param[in] netmask The target network mask.
63 * @param[in] gateway The target network gateway. Not used if zero.
64 *
65 */
66int ip_add_route_req_remote(int ip_phone, device_id_t device_id,
67 in_addr_t address, in_addr_t netmask, in_addr_t gateway)
68{
69 return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE,
70 (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr,
71 (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
72}
73
74int ip_bind_service(services_t service, int protocol, services_t me,
75 async_client_conn_t receiver)
76{
77 return (int) bind_service(service, (ipcarg_t) protocol, me, service,
78 receiver);
79}
80
81int ip_connect_module(services_t service)
82{
83 return connect_to_service(SERVICE_IP);
84}
85
86/** Register the new device.
87 *
88 * Register itself as the ip packet receiver.
89 * If the device uses ARP registers also the new ARP device.
90 *
91 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
92 * @param[in] device_id The new device identifier.
93 * @param[in] netif The underlying device network interface layer service.
94 *
95 * @return EOK on success.
96 * @return ENOMEM if there is not enough memory left.
97 * @return EINVAL if the device configuration is invalid.
98 * @return ENOTSUP if the device uses IPv6.
99 * @return ENOTSUP if the device uses DHCP.
100 * @return Other error codes as defined for the net_get_device_conf_req()
101 * function.
102 * @return Other error codes as defined for the arp_device_req() function.
103 *
104 */
105int ip_device_req_remote(int ip_phone, device_id_t device_id,
106 services_t service)
107{
108 return generic_device_req_remote(ip_phone, NET_IL_DEVICE, device_id, 0,
109 service);
110}
111
112/** Return the device identifier and the IP pseudo header based on the destination address.
113 *
114 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
115 * @param[in] protocol The transport protocol.
116 * @param[in] destination The destination address.
117 * @param[in] addrlen The destination address length.
118 * @param[out] device_id The device identifier.
119 * @param[out] header The constructed IP pseudo header.
120 * @param[out] headerlen The IP pseudo header length.
121 *
122 */
123int ip_get_route_req_remote(int ip_phone, ip_protocol_t protocol,
124 const struct sockaddr *destination, socklen_t addrlen,
125 device_id_t *device_id, void **header, size_t *headerlen)
126{
127 if ((!destination) || (addrlen == 0))
128 return EINVAL;
129
130 if ((!device_id) || (!header) || (!headerlen))
131 return EBADMEM;
132
133 *header = NULL;
134
135 ipc_call_t answer;
136 aid_t message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE,
137 (ipcarg_t) protocol, &answer);
138
139 if ((async_data_write_start(ip_phone, destination, addrlen) == EOK)
140 && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK)
141 && (*headerlen > 0)) {
142 *header = malloc(*headerlen);
143 if (*header) {
144 if (async_data_read_start(ip_phone, *header, *headerlen) != EOK)
145 free(*header);
146 }
147 }
148
149 ipcarg_t result;
150 async_wait_for(message_id, &result);
151
152 if ((result != EOK) && (*header))
153 free(*header);
154 else
155 *device_id = IPC_GET_DEVICE(&answer);
156
157 return (int) result;
158}
159
160/** Return the device packet dimension for sending.
161 *
162 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
163 * @param[in] device_id The device identifier.
164 * @param[out] packet_dimension The packet dimension.
165 *
166 * @return EOK on success.
167 * @return ENOENT if there is no such device.
168 * @return Other error codes as defined for the
169 * generic_packet_size_req_remote() function.
170 *
171 */
172int ip_packet_size_req_remote(int ip_phone, device_id_t device_id,
173 packet_dimension_ref packet_dimension)
174{
175 return generic_packet_size_req_remote(ip_phone, NET_IL_PACKET_SPACE, device_id,
176 packet_dimension);
177}
178
179/** Notify the IP module about the received error notification packet.
180 *
181 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
182 * @param[in] device_id The device identifier.
183 * @param[in] packet The received packet or the received packet queue.
184 * @param[in] target The target internetwork module service to be
185 * delivered to.
186 * @param[in] error The packet error reporting service. Prefixes the
187 * received packet.
188 *
189 * @return EOK on success.
190 *
191 */
192int ip_received_error_msg_remote(int ip_phone, device_id_t device_id,
193 packet_t packet, services_t target, services_t error)
194{
195 return generic_received_msg_remote(ip_phone, NET_IP_RECEIVED_ERROR,
196 device_id, packet_get_id(packet), target, error);
197}
198
199/** Send the packet queue.
200 *
201 * The packets may get fragmented if needed.
202 *
203 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
204 * @param[in] device_id The device identifier.
205 * @param[in] packet The packet fragments as a packet queue. All the
206 * packets have to have the same destination address.
207 * @param[in] sender The sending module service.
208 * @param[in] error The packet error reporting service. Prefixes the
209 * received packet.
210 *
211 * @return EOK on success.
212 * @return Other error codes as defined for the generic_send_msg() function.
213 *
214 */
215int ip_send_msg_remote(int ip_phone, device_id_t device_id, packet_t packet,
216 services_t sender, services_t error)
217{
218 return generic_send_msg_remote(ip_phone, NET_IL_SEND, device_id,
219 packet_get_id(packet), sender, error);
220}
221
222/** Set the default gateway.
223 *
224 * This gateway is used if no other route is found.
225 *
226 * @param[in] ip_phone The IP module phone used for (semi)remote calls.
227 * @param[in] device_id The device identifier.
228 * @param[in] gateway The default gateway.
229 *
230 */
231int ip_set_gateway_req_remote(int ip_phone, device_id_t device_id,
232 in_addr_t gateway)
233{
234 return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY,
235 (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
236}
237
238/** @}
239 */
Note: See TracBrowser for help on using the repository browser.