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

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

Cleanup IP module remote interfaces.

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