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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 96b02eb9 was 96b02eb9, checked in by Martin Decky <martin@…>, 15 years ago

more unification of basic types

  • use sysarg_t and native_t (unsigned and signed variant) in both kernel and uspace
  • remove ipcarg_t in favour of sysarg_t

(no change in functionality)

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