/branches/network/uspace/srv/net/il/arp/arp.c |
---|
50,6 → 50,7 |
#include "../../include/byteorder.h" |
#include "../../include/device.h" |
#include "../../include/arp_messages.h" |
#include "../../include/nil_messages.h" |
#include "../../include/protocol_map.h" |
60,13 → 61,9 |
#include "arp.h" |
#include "arp_header.h" |
#include "arp_oc.h" |
//#include "arp_messages.h" |
#include "arp_module.h" |
#include "arp_wrappers.h" |
/** Returns the protocol service message parameter. |
*/ |
#define ARP_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
/** ARP global data. |
*/ |
arp_globals_t arp_globals; |
120,23 → 117,11 |
*/ |
int arp_receive_message( device_id_t device_id, packet_t packet ); |
/** Clears the device specific data from the cache. |
* @param device_id The device identifier. Input parameter. |
* @returns EOK on success. |
* @returns ENOENT if the device is not found in the cache. |
*/ |
int arp_clear_device_message( device_id_t device_id ); |
/** Clears the device specific data. |
* @param device The device specific data. |
*/ |
void clear_device( arp_device_ref device ); |
/** Clears the whole cache. |
* @returns EOK on success. |
*/ |
int arp_clean_cache_message( void ); |
/** Processes IPC messages from the registered device driver modules in an infinite loop. |
* @param iid The message identifier. Input parameter. |
* @param icall The message parameters. Input/output parameter. |
149,6 → 134,73 |
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t ) |
int arp_clear_device_wrapper( device_id_t device_id ){ |
arp_device_ref device; |
rwlock_write_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
clear_device( device ); |
printf( "\nDevice %d cleared", device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
int arp_clean_cache_wrapper( void ){ |
int count; |
arp_device_ref device; |
rwlock_write_lock( & arp_globals.lock ); |
for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){ |
device = arp_cache_get_index( & arp_globals.cache, count ); |
if( device ){ |
clear_device( device ); |
if( device->addr_data ) free( device->addr_data ); |
if( device->broadcast_data ) free( device->broadcast_data ); |
} |
} |
arp_cache_clear( & arp_globals.cache ); |
rwlock_write_unlock( & arp_globals.lock ); |
printf( "\nCache cleaned" ); |
return EOK; |
} |
int arp_device_wrapper( device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ){ |
ERROR_DECLARE; |
measured_string_ref tmp; |
tmp = measured_string_copy( address ); |
if( ERROR_OCCURRED( arp_device_message( device_id, netif, protocol, tmp ))){ |
free( tmp->value ); |
free( tmp ); |
} |
return ERROR_CODE; |
} |
int arp_translate_wrapper( device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ){ |
measured_string_ref tmp; |
rwlock_read_lock( & arp_globals.lock ); |
tmp = arp_translate_message( device_id, protocol, address ); |
if( tmp ){ |
* translation = measured_string_copy( tmp ); |
rwlock_read_unlock( & arp_globals.lock ); |
if( * translation ){ |
* data = ( ** translation ).value; |
return EOK; |
}else{ |
return ENOMEM; |
} |
}else{ |
rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
} |
int arp_initialize( void ){ |
ERROR_DECLARE; |
382,21 → 434,6 |
return EOK; |
} |
int arp_clear_device_message( device_id_t device_id ){ |
arp_device_ref device; |
rwlock_write_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
clear_device( device ); |
printf( "\nDevice %d cleared", device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
void clear_device( arp_device_ref device ){ |
int count; |
arp_proto_ref proto; |
412,25 → 449,6 |
arp_protos_clear( & device->protos ); |
} |
int arp_clean_cache_message( void ){ |
int count; |
arp_device_ref device; |
rwlock_write_lock( & arp_globals.lock ); |
for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){ |
device = arp_cache_get_index( & arp_globals.cache, count ); |
if( device ){ |
clear_device( device ); |
if( device->addr_data ) free( device->addr_data ); |
if( device->broadcast_data ) free( device->broadcast_data ); |
} |
} |
arp_cache_clear( & arp_globals.cache ); |
rwlock_write_unlock( & arp_globals.lock ); |
printf( "\nCache cleaned" ); |
return EOK; |
} |
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
464,9 → 482,9 |
rwlock_read_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
case NET_ARP_CLEAR_DEVICE: |
return arp_clear_device_message( IPC_GET_DEVICE( call )); |
return arp_clear_device_wrapper( IPC_GET_DEVICE( call )); |
case NET_ARP_CLEAN_CACHE: |
return arp_clean_cache_message(); |
return arp_clean_cache_wrapper(); |
} |
return ENOTSUP; |
} |
/branches/network/uspace/srv/net/il/arp/arp_wrappers.h |
---|
0,0 → 1,63 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup arp |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_ARP_WRAPPERS_H__ |
#define __NET_ARP_WRAPPERS_H__ |
#include <ipc/services.h> |
#include "../../structures/measured_strings.h" |
#include "../../include/device.h" |
/** Clears the device specific data from the cache. |
* @param device_id The device identifier. Input parameter. |
* @returns EOK on success. |
* @returns ENOENT if the device is not found in the cache. |
*/ |
int arp_clear_device_wrapper( device_id_t device_id ); |
/** Clears the whole cache. |
* @returns EOK on success. |
*/ |
int arp_clean_cache_wrapper( void ); |
int arp_device_wrapper( device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ); |
int arp_translate_wrapper( device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
47,6 → 47,7 |
#include "../../include/sockaddr.h" |
#include "../../include/socket.h" |
#include "../../include/device.h" |
#include "../../include/arp_messages.h" |
#include "../../include/nil_messages.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/module_map.h" |
185,18 → 186,12 |
return ip_netif->phone; |
} |
if( ip_netif->arp ){ |
message = async_send_3( ip_netif->arp->phone, NET_ARP_DEVICE, ip_netif->device_id, SERVICE_IP, service, & answer ); |
configuration[ 0 ].value = ( char * ) & ip_netif->address; |
configuration[ 0 ].length = CONVERT_SIZE( in_addr_t, char, 1 ); |
if( ERROR_OCCURRED( measured_strings_send( ip_netif->arp->phone, & configuration[ 0 ], 1 ))){ |
if( ERROR_OCCURRED( arp_device_req( ip_netif->arp->phone, ip_netif->device_id, SERVICE_IP, service, & configuration[ 0 ] ))){ |
free( ip_netif ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
if( ERROR_OCCURRED( result )){ |
free( ip_netif ); |
return ERROR_CODE; |
} |
} |
index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ); |
if( index < 0 ){ |
277,12 → 272,9 |
ip_netif_ref netif; |
aid_t message; |
ipc_call_t answer; |
measured_string_t address; |
measured_string_ref translation; |
char * data; |
ipcarg_t result; |
netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
if( ! netif ) return ENOENT; |
289,21 → 281,12 |
// TODO state |
printf( "\nip - device %d changed state to %d\n", device_id, state ); |
if( netif->arp ){ |
message = async_send_2( netif->arp->phone, NET_ARP_TRANSLATE, netif->device_id, SERVICE_IP, & answer ); |
address.value = ( char * ) & netif->gateway; |
address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
if( ERROR_OCCURRED( measured_strings_send( netif->arp->phone, & address, 1 )) |
|| ERROR_OCCURRED( measured_strings_return( netif->arp->phone, & translation, & data, 1 ))){ |
async_wait_for( message, & result ); |
return result; |
} |
async_wait_for( message, & result ); |
if( ! ERROR_OCCURRED( result )){ |
printf( "\n\tgateway translated to\t= %X:%X:%X:%X:%X:%X", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
} |
ERROR_PROPAGATE( arp_translate_req( netif->arp->phone, netif->device_id, SERVICE_IP, & address, & translation, & data )); |
printf( "\n\tgateway translated to\t= %X:%X:%X:%X:%X:%X", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
free( translation ); |
free( data ); |
return result; |
} |
return EOK; |
} |