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

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

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