Changeset e9caf47 in mainline


Ignore:
Timestamp:
2010-10-27T23:06:48Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e8199d77
Parents:
0a3fbc7
Message:

Cleanup arp.

Location:
uspace/srv/net/il/arp
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/il/arp/arp.c

    r0a3fbc7 re9caf47  
    2828
    2929/** @addtogroup arp
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  ARP module implementation.
    35  *  @see arp.h
    36  */
     34 * ARP module implementation.
     35 * @see arp.h
     36 */
     37
     38#include "arp.h"
     39#include "arp_header.h"
     40#include "arp_oc.h"
     41#include "arp_module.h"
    3742
    3843#include <async.h>
     
    4348#include <str.h>
    4449#include <task.h>
     50#include <adt/measured_strings.h>
    4551#include <ipc/ipc.h>
    4652#include <ipc/services.h>
     
    5359#include <net/modules.h>
    5460#include <net/device.h>
    55 #include <arp_interface.h>
     61#include <net/packet.h>
     62
    5663#include <nil_interface.h>
    5764#include <protocol_map.h>
    58 #include <adt/measured_strings.h>
    59 #include <net/packet.h>
    6065#include <packet_client.h>
    6166#include <packet_remote.h>
     
    6368#include <il_local.h>
    6469
    65 #include "arp.h"
    66 #include "arp_header.h"
    67 #include "arp_oc.h"
    68 #include "arp_module.h"
    69 
    70 
    71 /** ARP module name.
    72  */
     70
     71/** ARP module name. */
    7372#define NAME  "arp"
    7473
    75 /** ARP global data.
    76  */
    77 arp_globals_t   arp_globals;
     74/** ARP global data. */
     75arp_globals_t arp_globals;
     76
     77DEVICE_MAP_IMPLEMENT(arp_cache, arp_device_t);
     78INT_MAP_IMPLEMENT(arp_protos, arp_proto_t);
     79GENERIC_CHAR_MAP_IMPLEMENT(arp_addr, measured_string_t);
    7880
    7981/** Clears the device specific data.
    80  *  @param[in] device The device specific data.
    81  */
    82 void arp_clear_device(arp_device_ref device);
    83 
    84 /** Creates new protocol specific data.
    85  *  Allocates and returns the needed memory block as the proto parameter.
    86  *  @param[out] proto The allocated protocol specific data.
    87  *  @param[in] service The protocol module service.
    88  *  @param[in] address The actual protocol device address.
    89  *  @returns EOK on success.
    90  *  @returns ENOMEM if there is not enough memory left.
    91  */
    92 int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address);
    93 
    94 /** @name Message processing functions
    95  */
    96 /*@{*/
    97 
    98 /** Registers the device.
    99  *  Creates new device entry in the cache or updates the protocol address if the device with the device identifier and the driver service exists.
    100  *  @param[in] device_id The device identifier.
    101  *  @param[in] service The device driver service.
    102  *  @param[in] protocol The protocol service.
    103  *  @param[in] address The actual device protocol address.
    104  *  @returns EOK on success.
    105  *  @returns EEXIST if another device with the same device identifier and different driver service exists.
    106  *  @returns ENOMEM if there is not enough memory left.
    107  *  @returns Other error codes as defined for the measured_strings_return() function.
    108  */
    109 int arp_device_message(device_id_t device_id, services_t service, services_t protocol, measured_string_ref address);
    110 
    111 /** Updates the device content length according to the new MTU value.
    112  *  @param[in] device_id The device identifier.
    113  *  @param[in] mtu The new mtu value.
    114  *  @returns ENOENT if device is not found.
    115  *  @returns EOK on success.
    116  */
    117 int arp_mtu_changed_message(device_id_t device_id, size_t mtu);
    118 
    119 /** Processes the received ARP packet.
    120  *  Updates the source hardware address if the source entry exists or the packet is targeted to my protocol address.
    121  *  Responses to the ARP request if the packet is the ARP request and is targeted to my address.
    122  *  @param[in] device_id The source device identifier.
    123  *  @param[in,out] packet The received packet.
    124  *  @returns EOK on success and the packet is no longer needed.
    125  *  @returns 1 on success and the packet has been reused.
    126  *  @returns EINVAL if the packet is too small to carry an ARP packet.
    127  *  @returns EINVAL if the received address lengths differs from the registered values.
    128  *  @returns ENOENT if the device is not found in the cache.
    129  *  @returns ENOENT if the protocol for the device is not found in the cache.
    130  *  @returns ENOMEM if there is not enough memory left.
    131  */
    132 int arp_receive_message(device_id_t device_id, packet_t packet);
    133 
    134 /** Returns the hardware address for the given protocol address.
    135  *  Sends the ARP request packet if the hardware address is not found in the cache.
    136  *  @param[in] device_id The device identifier.
    137  *  @param[in] protocol The protocol service.
    138  *  @param[in] target The target protocol address.
    139  *  @returns The hardware address of the target.
    140  *  @returns NULL if the target parameter is NULL.
    141  *  @returns NULL if the device is not found.
    142  *  @returns NULL if the device packet is too small to send a&nbsp;request.
    143  *  @returns NULL if the hardware address is not found in the cache.
    144  */
    145 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target);
    146 
    147 /*@}*/
    148 
    149 DEVICE_MAP_IMPLEMENT(arp_cache, arp_device_t)
    150 
    151 INT_MAP_IMPLEMENT(arp_protos, arp_proto_t)
    152 
    153 GENERIC_CHAR_MAP_IMPLEMENT(arp_addr, measured_string_t)
    154 
    155 int arp_clean_cache_req(int arp_phone){
     82 *
     83 * @param[in] device    The device specific data.
     84 */
     85static void arp_clear_device(arp_device_ref device)
     86{
     87        int count;
     88        arp_proto_ref proto;
     89
     90        for (count = arp_protos_count(&device->protos) - 1; count >= 0;
     91            count--) {
     92                proto = arp_protos_get_index(&device->protos, count);
     93                if (proto) {
     94                        if (proto->addr)
     95                                free(proto->addr);
     96                        if (proto->addr_data)
     97                                free(proto->addr_data);
     98                        arp_addr_destroy(&proto->addresses);
     99                }
     100        }
     101        arp_protos_clear(&device->protos);
     102}
     103
     104static int arp_clean_cache_req(int arp_phone)
     105{
    156106        int count;
    157107        arp_device_ref device;
    158108
    159109        fibril_rwlock_write_lock(&arp_globals.lock);
    160         for(count = arp_cache_count(&arp_globals.cache) - 1; count >= 0; -- count){
     110        for (count = arp_cache_count(&arp_globals.cache) - 1; count >= 0;
     111            count--) {
    161112                device = arp_cache_get_index(&arp_globals.cache, count);
    162                 if(device){
     113                if (device) {
    163114                        arp_clear_device(device);
    164                         if(device->addr_data){
     115                        if (device->addr_data)
    165116                                free(device->addr_data);
    166                         }
    167                         if(device->broadcast_data){
     117                        if (device->broadcast_data)
    168118                                free(device->broadcast_data);
    169                         }
    170119                }
    171120        }
     
    176125}
    177126
    178 int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
     127static int
     128arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol,
     129    measured_string_ref address)
     130{
    179131        arp_device_ref device;
    180132        arp_proto_ref proto;
     
    182134        fibril_rwlock_write_lock(&arp_globals.lock);
    183135        device = arp_cache_find(&arp_globals.cache, device_id);
    184         if(! device){
     136        if (!device) {
    185137                fibril_rwlock_write_unlock(&arp_globals.lock);
    186138                return ENOENT;
    187139        }
    188140        proto = arp_protos_find(&device->protos, protocol);
    189         if(! proto){
     141        if (!proto) {
    190142                fibril_rwlock_write_unlock(&arp_globals.lock);
    191143                return ENOENT;
     
    196148}
    197149
    198 void arp_clear_device(arp_device_ref device){
    199         int count;
    200         arp_proto_ref proto;
    201 
    202         for(count = arp_protos_count(&device->protos) - 1; count >= 0; -- count){
    203                 proto = arp_protos_get_index(&device->protos, count);
    204                 if(proto){
    205                         if(proto->addr){
    206                                 free(proto->addr);
    207                         }
    208                         if(proto->addr_data){
    209                                 free(proto->addr_data);
    210                         }
    211                         arp_addr_destroy(&proto->addresses);
    212                 }
    213         }
    214         arp_protos_clear(&device->protos);
    215 }
    216 
    217 int arp_clear_device_req(int arp_phone, device_id_t device_id){
     150
     151static int arp_clear_device_req(int arp_phone, device_id_t device_id)
     152{
    218153        arp_device_ref device;
    219154
    220155        fibril_rwlock_write_lock(&arp_globals.lock);
    221156        device = arp_cache_find(&arp_globals.cache, device_id);
    222         if(! device){
     157        if (!device) {
    223158                fibril_rwlock_write_unlock(&arp_globals.lock);
    224159                return ENOENT;
     
    230165}
    231166
    232 int arp_device_message(device_id_t device_id, services_t service, services_t protocol, measured_string_ref address){
     167/** Creates new protocol specific data.
     168 *
     169 * Allocates and returns the needed memory block as the proto parameter.
     170 *
     171 * @param[out] proto    The allocated protocol specific data.
     172 * @param[in] service   The protocol module service.
     173 * @param[in] address   The actual protocol device address.
     174 * @returns             EOK on success.
     175 * @returns             ENOMEM if there is not enough memory left.
     176 */
     177static int
     178arp_proto_create(arp_proto_ref *proto, services_t service,
     179    measured_string_ref address)
     180{
     181        ERROR_DECLARE;
     182
     183        *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t));
     184        if (!*proto)
     185                return ENOMEM;
     186        (*proto)->service = service;
     187        (*proto)->addr = address;
     188        (*proto)->addr_data = address->value;
     189        if (ERROR_OCCURRED(arp_addr_initialize(&(*proto)->addresses))) {
     190                free(*proto);
     191                return ERROR_CODE;
     192        }
     193        return EOK;
     194}
     195
     196/** Registers the device.
     197 *
     198 * Creates new device entry in the cache or updates the protocol address if the
     199 * device with the device identifier and the driver service exists.
     200 *
     201 * @param[in] device_id The device identifier.
     202 * @param[in] service   The device driver service.
     203 * @param[in] protocol  The protocol service.
     204 * @param[in] address   The actual device protocol address.
     205 * @returns             EOK on success.
     206 * @returns             EEXIST if another device with the same device identifier
     207 *                      and different driver service exists.
     208 * @returns             ENOMEM if there is not enough memory left.
     209 * @returns             Other error codes as defined for the
     210 *                      measured_strings_return() function.
     211 */
     212static int
     213arp_device_message(device_id_t device_id, services_t service,
     214    services_t protocol, measured_string_ref address)
     215{
    233216        ERROR_DECLARE;
    234217
     
    241224        // an existing device?
    242225        device = arp_cache_find(&arp_globals.cache, device_id);
    243         if(device){
    244                 if(device->service != service){
     226        if (device) {
     227                if (device->service != service) {
    245228                        printf("Device %d already exists\n", device->device_id);
    246229                        fibril_rwlock_write_unlock(&arp_globals.lock);
     
    248231                }
    249232                proto = arp_protos_find(&device->protos, protocol);
    250                 if(proto){
     233                if (proto) {
    251234                        free(proto->addr);
    252235                        free(proto->addr_data);
    253236                        proto->addr = address;
    254237                        proto->addr_data = address->value;
    255                 }else{
    256                         if(ERROR_OCCURRED(arp_proto_create(&proto, protocol, address))){
     238                } else {
     239                        if (ERROR_OCCURRED(arp_proto_create(&proto, protocol,
     240                            address))) {
    257241                                fibril_rwlock_write_unlock(&arp_globals.lock);
    258242                                return ERROR_CODE;
    259243                        }
    260                         index = arp_protos_add(&device->protos, proto->service, proto);
    261                         if(index < 0){
     244                        index = arp_protos_add(&device->protos, proto->service,
     245                            proto);
     246                        if (index < 0) {
    262247                                fibril_rwlock_write_unlock(&arp_globals.lock);
    263248                                free(proto);
    264249                                return index;
    265250                        }
    266                         printf("New protocol added:\n\tdevice id\t= %d\n\tproto\t= %d", device_id, protocol);
    267                 }
    268         }else{
     251                        printf("New protocol added:\n\tdevice id\t= "
     252                            "%d\n\tproto\t= %d", device_id, protocol);
     253                }
     254        } else {
    269255                hardware = hardware_map(service);
    270                 if(! hardware){
     256                if (!hardware)
    271257                        return ENOENT;
    272                 }
     258               
    273259                // create a new device
    274260                device = (arp_device_ref) malloc(sizeof(arp_device_t));
    275                 if(! device){
     261                if (!device) {
    276262                        fibril_rwlock_write_unlock(&arp_globals.lock);
    277263                        return ENOMEM;
     
    279265                device->hardware = hardware;
    280266                device->device_id = device_id;
    281                 if(ERROR_OCCURRED(arp_protos_initialize(&device->protos))
    282                         || ERROR_OCCURRED(arp_proto_create(&proto, protocol, address))){
     267                if (ERROR_OCCURRED(arp_protos_initialize(&device->protos)) ||
     268                    ERROR_OCCURRED(arp_proto_create(&proto, protocol,
     269                    address))) {
    283270                        fibril_rwlock_write_unlock(&arp_globals.lock);
    284271                        free(device);
     
    286273                }
    287274                index = arp_protos_add(&device->protos, proto->service, proto);
    288                 if(index < 0){
     275                if (index < 0) {
    289276                        fibril_rwlock_write_unlock(&arp_globals.lock);
    290277                        arp_protos_destroy(&device->protos);
     
    293280                }
    294281                device->service = service;
     282               
    295283                // bind the new one
    296                 device->phone = nil_bind_service(device->service, (ipcarg_t) device->device_id, SERVICE_ARP, arp_globals.client_connection);
    297                 if(device->phone < 0){
     284                device->phone = nil_bind_service(device->service,
     285                    (ipcarg_t) device->device_id, SERVICE_ARP,
     286                    arp_globals.client_connection);
     287                if (device->phone < 0) {
    298288                        fibril_rwlock_write_unlock(&arp_globals.lock);
    299289                        arp_protos_destroy(&device->protos);
     
    301291                        return EREFUSED;
    302292                }
     293               
    303294                // get packet dimensions
    304                 if(ERROR_OCCURRED(nil_packet_size_req(device->phone, device_id, &device->packet_dimension))){
     295                if (ERROR_OCCURRED(nil_packet_size_req(device->phone, device_id,
     296                    &device->packet_dimension))) {
    305297                        fibril_rwlock_write_unlock(&arp_globals.lock);
    306298                        arp_protos_destroy(&device->protos);
     
    308300                        return ERROR_CODE;
    309301                }
     302               
    310303                // get hardware address
    311                 if(ERROR_OCCURRED(nil_get_addr_req(device->phone, device_id, &device->addr, &device->addr_data))){
     304                if (ERROR_OCCURRED(nil_get_addr_req(device->phone, device_id,
     305                    &device->addr, &device->addr_data))) {
    312306                        fibril_rwlock_write_unlock(&arp_globals.lock);
    313307                        arp_protos_destroy(&device->protos);
     
    315309                        return ERROR_CODE;
    316310                }
     311               
    317312                // get broadcast address
    318                 if(ERROR_OCCURRED(nil_get_broadcast_addr_req(device->phone, device_id, &device->broadcast_addr, &device->broadcast_data))){
     313                if (ERROR_OCCURRED(nil_get_broadcast_addr_req(device->phone,
     314                    device_id, &device->broadcast_addr,
     315                    &device->broadcast_data))) {
    319316                        fibril_rwlock_write_unlock(&arp_globals.lock);
    320317                        free(device->addr);
     
    324321                        return ERROR_CODE;
    325322                }
    326                 if(ERROR_OCCURRED(arp_cache_add(&arp_globals.cache, device->device_id, device))){
     323               
     324                if (ERROR_OCCURRED(arp_cache_add(&arp_globals.cache,
     325                    device->device_id, device))) {
    327326                        fibril_rwlock_write_unlock(&arp_globals.lock);
    328327                        free(device->addr);
     
    334333                        return ERROR_CODE;
    335334                }
    336                 printf("%s: Device registered (id: %d, type: 0x%x, service: %d, proto: %d)\n",
    337                     NAME, device->device_id, device->hardware, device->service, protocol);
     335                printf("%s: Device registered (id: %d, type: 0x%x, service: %d,"
     336                    " proto: %d)\n", NAME, device->device_id, device->hardware,
     337                    device->service, protocol);
    338338        }
    339339        fibril_rwlock_write_unlock(&arp_globals.lock);
    340         return EOK;
    341 }
    342 
    343 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
    344         ERROR_DECLARE;
    345 
    346         measured_string_ref tmp;
    347 
    348         // copy the given address for exclusive use
    349         tmp = measured_string_copy(address);
    350         if(ERROR_OCCURRED(arp_device_message(device_id, netif, protocol, tmp))){
    351                 free(tmp->value);
    352                 free(tmp);
    353         }
    354         return ERROR_CODE;
    355 }
    356 
    357 int arp_initialize(async_client_conn_t client_connection){
     340       
     341        return EOK;
     342}
     343
     344/** Initializes the ARP module.
     345 *
     346 *  @param[in] client_connection The client connection processing function.
     347 *                      The module skeleton propagates its own one.
     348 *  @returns            EOK on success.
     349 *  @returns            ENOMEM if there is not enough memory left.
     350 */
     351int arp_initialize(async_client_conn_t client_connection)
     352{
    358353        ERROR_DECLARE;
    359354
     
    366361}
    367362
    368 int arp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    369     ipc_call_t *answer, int *answer_count)
    370 {
    371         ERROR_DECLARE;
    372        
    373         measured_string_ref address;
    374         measured_string_ref translation;
    375         char * data;
    376         packet_t packet;
    377         packet_t next;
    378        
    379         *answer_count = 0;
    380         switch (IPC_GET_METHOD(*call)) {
    381                 case IPC_M_PHONE_HUNGUP:
    382                         return EOK;
    383                 case NET_ARP_DEVICE:
    384                         ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
    385                         if(ERROR_OCCURRED(arp_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address))){
    386                                 free(address);
    387                                 free(data);
    388                         }
    389                         return ERROR_CODE;
    390                 case NET_ARP_TRANSLATE:
    391                         ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
    392                         fibril_rwlock_read_lock(&arp_globals.lock);
    393                         translation = arp_translate_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), address);
    394                         free(address);
    395                         free(data);
    396                         if(! translation){
    397                                 fibril_rwlock_read_unlock(&arp_globals.lock);
    398                                 return ENOENT;
    399                         }
    400                         ERROR_CODE = measured_strings_reply(translation, 1);
    401                         fibril_rwlock_read_unlock(&arp_globals.lock);
    402                         return ERROR_CODE;
    403                 case NET_ARP_CLEAR_DEVICE:
    404                         return arp_clear_device_req(0, IPC_GET_DEVICE(call));
    405                 case NET_ARP_CLEAR_ADDRESS:
    406                         ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
    407                         arp_clear_address_req(0, IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), address);
    408                         free(address);
    409                         free(data);
    410                         return EOK;
    411                 case NET_ARP_CLEAN_CACHE:
    412                         return arp_clean_cache_req(0);
    413                 case NET_IL_DEVICE_STATE:
    414                         // do nothing - keep the cache
    415                         return EOK;
    416                 case NET_IL_RECEIVED:
    417                         if(! ERROR_OCCURRED(packet_translate_remote(arp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    418                                 fibril_rwlock_read_lock(&arp_globals.lock);
    419                                 do{
    420                                         next = pq_detach(packet);
    421                                         ERROR_CODE = arp_receive_message(IPC_GET_DEVICE(call), packet);
    422                                         if(ERROR_CODE != 1){
    423                                                 pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
    424                                         }
    425                                         packet = next;
    426                                 }while(packet);
    427                                 fibril_rwlock_read_unlock(&arp_globals.lock);
    428                         }
    429                         return ERROR_CODE;
    430                 case NET_IL_MTU_CHANGED:
    431                         return arp_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call));
    432         }
    433        
    434         return ENOTSUP;
    435 }
    436 
    437 int arp_mtu_changed_message(device_id_t device_id, size_t mtu){
     363/** Updates the device content length according to the new MTU value.
     364 *
     365 * @param[in] device_id The device identifier.
     366 * @param[in] mtu       The new mtu value.
     367 * @returns             ENOENT if device is not found.
     368 * @returns             EOK on success.
     369 */
     370static int arp_mtu_changed_message(device_id_t device_id, size_t mtu)
     371{
    438372        arp_device_ref device;
    439373
    440374        fibril_rwlock_write_lock(&arp_globals.lock);
    441375        device = arp_cache_find(&arp_globals.cache, device_id);
    442         if(! device){
     376        if (!device) {
    443377                fibril_rwlock_write_unlock(&arp_globals.lock);
    444378                return ENOENT;
    445379        }
    446380        device->packet_dimension.content = mtu;
     381        fibril_rwlock_write_unlock(&arp_globals.lock);
    447382        printf("arp - device %d changed mtu to %d\n\n", device_id, mtu);
    448         fibril_rwlock_write_unlock(&arp_globals.lock);
    449         return EOK;
    450 }
    451 
    452 int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address){
    453         ERROR_DECLARE;
    454 
    455         *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t));
    456         if(!(*proto)){
    457                 return ENOMEM;
    458         }
    459         (** proto).service = service;
    460         (** proto).addr = address;
    461         (** proto).addr_data = address->value;
    462         if(ERROR_OCCURRED(arp_addr_initialize(&(** proto).addresses))){
    463                 free(*proto);
    464                 return ERROR_CODE;
    465         }
    466         return EOK;
    467 }
    468 
    469 int arp_receive_message(device_id_t device_id, packet_t packet){
     383        return EOK;
     384}
     385
     386/** Processes the received ARP packet.
     387 *
     388 * Updates the source hardware address if the source entry exists or the packet
     389 * is targeted to my protocol address.
     390 * Responses to the ARP request if the packet is the ARP request and is
     391 * targeted to my address.
     392 *
     393 * @param[in] device_id The source device identifier.
     394 * @param[in,out] packet The received packet.
     395 * @returns             EOK on success and the packet is no longer needed.
     396 * @returns             One on success and the packet has been reused.
     397 * @returns             EINVAL if the packet is too small to carry an ARP
     398 *                      packet.
     399 * @returns             EINVAL if the received address lengths differs from
     400 *                      the registered values.
     401 * @returns             ENOENT if the device is not found in the cache.
     402 * @returns             ENOENT if the protocol for the device is not found in
     403 *                      the cache.
     404 * @returns             ENOMEM if there is not enough memory left.
     405 */
     406static int arp_receive_message(device_id_t device_id, packet_t packet)
     407{
    470408        ERROR_DECLARE;
    471409
     
    475413        arp_proto_ref proto;
    476414        measured_string_ref hw_source;
    477         uint8_t * src_hw;
    478         uint8_t * src_proto;
    479         uint8_t * des_hw;
    480         uint8_t * des_proto;
     415        uint8_t *src_hw;
     416        uint8_t *src_proto;
     417        uint8_t *des_hw;
     418        uint8_t *des_proto;
    481419
    482420        length = packet_get_data_length(packet);
    483         if(length <= sizeof(arp_header_t)){
     421        if (length <= sizeof(arp_header_t))
    484422                return EINVAL;
    485         }
     423
    486424        device = arp_cache_find(&arp_globals.cache, device_id);
    487         if(! device){
     425        if (!device)
    488426                return ENOENT;
    489         }
     427
    490428        header = (arp_header_ref) packet_get_data(packet);
    491         if((ntohs(header->hardware) != device->hardware)
    492                 || (length < sizeof(arp_header_t) + header->hardware_length * 2u + header->protocol_length * 2u)){
     429        if ((ntohs(header->hardware) != device->hardware) ||
     430            (length < sizeof(arp_header_t) + header->hardware_length * 2U +
     431            header->protocol_length * 2U)) {
    493432                return EINVAL;
    494433        }
    495         proto = arp_protos_find(&device->protos, protocol_unmap(device->service, ntohs(header->protocol)));
    496         if(! proto){
     434
     435        proto = arp_protos_find(&device->protos,
     436            protocol_unmap(device->service, ntohs(header->protocol)));
     437        if (!proto)
    497438                return ENOENT;
    498         }
     439
    499440        src_hw = ((uint8_t *) header) + sizeof(arp_header_t);
    500441        src_proto = src_hw + header->hardware_length;
    501442        des_hw = src_proto + header->protocol_length;
    502443        des_proto = des_hw + header->hardware_length;
    503         hw_source = arp_addr_find(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length));
     444        hw_source = arp_addr_find(&proto->addresses, (char *) src_proto,
     445            CONVERT_SIZE(uint8_t, char, header->protocol_length));
    504446        // exists?
    505         if(hw_source){
    506                 if(hw_source->length != CONVERT_SIZE(uint8_t, char, header->hardware_length)){
     447        if (hw_source) {
     448                if (hw_source->length != CONVERT_SIZE(uint8_t, char,
     449                    header->hardware_length)) {
    507450                        return EINVAL;
    508451                }
     
    510453        }
    511454        // is my protocol address?
    512         if(proto->addr->length != CONVERT_SIZE(uint8_t, char, header->protocol_length)){
     455        if (proto->addr->length != CONVERT_SIZE(uint8_t, char,
     456            header->protocol_length)) {
    513457                return EINVAL;
    514458        }
    515         if(! str_lcmp(proto->addr->value, (char *) des_proto, proto->addr->length)){
     459        if (!str_lcmp(proto->addr->value, (char *) des_proto,
     460            proto->addr->length)) {
    516461                // not already upadted?
    517                 if(! hw_source){
    518                         hw_source = measured_string_create_bulk((char *) src_hw, CONVERT_SIZE(uint8_t, char, header->hardware_length));
    519                         if(! hw_source){
     462                if (!hw_source) {
     463                        hw_source = measured_string_create_bulk((char *) src_hw,
     464                            CONVERT_SIZE(uint8_t, char,
     465                            header->hardware_length));
     466                        if (!hw_source)
    520467                                return ENOMEM;
    521                         }
    522                         ERROR_PROPAGATE(arp_addr_add(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length), hw_source));
    523                 }
    524                 if(ntohs(header->operation) == ARPOP_REQUEST){
     468
     469                        ERROR_PROPAGATE(arp_addr_add(&proto->addresses,
     470                            (char *) src_proto, CONVERT_SIZE(uint8_t, char,
     471                            header->protocol_length), hw_source));
     472                }
     473                if (ntohs(header->operation) == ARPOP_REQUEST) {
    525474                        header->operation = htons(ARPOP_REPLY);
    526475                        memcpy(des_proto, src_proto, header->protocol_length);
    527                         memcpy(src_proto, proto->addr->value, header->protocol_length);
    528                         memcpy(src_hw, device->addr->value, device->packet_dimension.addr_len);
    529                         memcpy(des_hw, hw_source->value, header->hardware_length);
    530                         ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw, header->hardware_length));
    531                         nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
     476                        memcpy(src_proto, proto->addr->value,
     477                            header->protocol_length);
     478                        memcpy(src_hw, device->addr->value,
     479                            device->packet_dimension.addr_len);
     480                        memcpy(des_hw, hw_source->value,
     481                            header->hardware_length);
     482                        ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw,
     483                            header->hardware_length));
     484                        nil_send_msg(device->phone, device_id, packet,
     485                            SERVICE_ARP);
    532486                        return 1;
    533487                }
    534488        }
    535         return EOK;
    536 }
    537 
    538 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target){
     489
     490        return EOK;
     491}
     492
     493
     494/** Returns the hardware address for the given protocol address.
     495 *
     496 * Sends the ARP request packet if the hardware address is not found in the
     497 * cache.
     498 *
     499 * @param[in] device_id The device identifier.
     500 * @param[in] protocol  The protocol service.
     501 * @param[in] target    The target protocol address.
     502 * @returns             The hardware address of the target.
     503 * @returns             NULL if the target parameter is NULL.
     504 * @returns             NULL if the device is not found.
     505 * @returns             NULL if the device packet is too small to send a
     506 *                      request.
     507 * @returns             NULL if the hardware address is not found in the cache.
     508 */
     509static measured_string_ref
     510arp_translate_message(device_id_t device_id, services_t protocol,
     511    measured_string_ref target)
     512{
    539513        arp_device_ref device;
    540514        arp_proto_ref proto;
     
    544518        arp_header_ref header;
    545519
    546         if(! target){
     520        if (!target)
    547521                return NULL;
    548         }
     522
    549523        device = arp_cache_find(&arp_globals.cache, device_id);
    550         if(! device){
     524        if (!device)
    551525                return NULL;
    552         }
     526
    553527        proto = arp_protos_find(&device->protos, protocol);
    554         if((! proto) || (proto->addr->length != target->length)){
     528        if (!proto || (proto->addr->length != target->length))
    555529                return NULL;
    556         }
     530
    557531        addr = arp_addr_find(&proto->addresses, target->value, target->length);
    558         if(addr){
     532        if (addr)
    559533                return addr;
    560         }
     534
    561535        // ARP packet content size = header + (address + translation) * 2
    562         length = 8 + (CONVERT_SIZE(char, uint8_t, proto->addr->length) + CONVERT_SIZE(char, uint8_t, device->addr->length)) * 2;
    563         if(length > device->packet_dimension.content){
     536        length = 8 + 2 * (CONVERT_SIZE(char, uint8_t, proto->addr->length) +
     537            CONVERT_SIZE(char, uint8_t, device->addr->length));
     538        if (length > device->packet_dimension.content)
    564539                return NULL;
    565         }
    566         packet = packet_get_4_remote(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
    567         if(! packet){
     540
     541        packet = packet_get_4_remote(arp_globals.net_phone,
     542            device->packet_dimension.addr_len, device->packet_dimension.prefix,
     543            length, device->packet_dimension.suffix);
     544        if (!packet)
    568545                return NULL;
    569         }
     546
    570547        header = (arp_header_ref) packet_suffix(packet, length);
    571         if(! header){
     548        if (!header) {
    572549                pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
    573550                return NULL;
    574551        }
     552
    575553        header->hardware = htons(device->hardware);
    576554        header->hardware_length = (uint8_t) device->addr->length;
     
    579557        header->operation = htons(ARPOP_REQUEST);
    580558        length = sizeof(arp_header_t);
    581         memcpy(((uint8_t *) header) + length, device->addr->value, device->addr->length);
     559        memcpy(((uint8_t *) header) + length, device->addr->value,
     560            device->addr->length);
    582561        length += device->addr->length;
    583         memcpy(((uint8_t *) header) + length, proto->addr->value, proto->addr->length);
     562        memcpy(((uint8_t *) header) + length, proto->addr->value,
     563            proto->addr->length);
    584564        length += proto->addr->length;
    585565        bzero(((uint8_t *) header) + length, device->addr->length);
    586566        length += device->addr->length;
    587567        memcpy(((uint8_t *) header) + length, target->value, target->length);
    588         if(packet_set_addr(packet, (uint8_t *) device->addr->value, (uint8_t *) device->broadcast_addr->value, CONVERT_SIZE(char, uint8_t, device->addr->length)) != EOK){
     568
     569        if (packet_set_addr(packet, (uint8_t *) device->addr->value,
     570            (uint8_t *) device->broadcast_addr->value,
     571            CONVERT_SIZE(char, uint8_t, device->addr->length)) != EOK) {
    589572                pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
    590573                return NULL;
    591574        }
     575
    592576        nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
    593577        return NULL;
    594578}
    595579
     580
     581/** Processes the ARP message.
     582 *
     583 * @param[in] callid    The message identifier.
     584 * @param[in] call      The message parameters.
     585 * @param[out] answer   The message answer parameters.
     586 * @param[out] answer_count The last parameter for the actual answer in the
     587 *                      answer parameter.
     588 * @returns             EOK on success.
     589 * @returns             ENOTSUP if the message is not known.
     590 *
     591 * @see arp_interface.h
     592 * @see IS_NET_ARP_MESSAGE()
     593 */
     594int
     595arp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     596    ipc_call_t *answer, int *answer_count)
     597{
     598        ERROR_DECLARE;
     599       
     600        measured_string_ref address;
     601        measured_string_ref translation;
     602        char *data;
     603        packet_t packet;
     604        packet_t next;
     605       
     606        *answer_count = 0;
     607        switch (IPC_GET_METHOD(*call)) {
     608        case IPC_M_PHONE_HUNGUP:
     609                return EOK;
     610       
     611        case NET_ARP_DEVICE:
     612                ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
     613                if (ERROR_OCCURRED(arp_device_message(IPC_GET_DEVICE(call),
     614                    IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address))) {
     615                        free(address);
     616                        free(data);
     617                }
     618                return ERROR_CODE;
     619       
     620        case NET_ARP_TRANSLATE:
     621                ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
     622                fibril_rwlock_read_lock(&arp_globals.lock);
     623                translation = arp_translate_message(IPC_GET_DEVICE(call),
     624                    IPC_GET_SERVICE(call), address);
     625                free(address);
     626                free(data);
     627                if (!translation) {
     628                        fibril_rwlock_read_unlock(&arp_globals.lock);
     629                        return ENOENT;
     630                }
     631                ERROR_CODE = measured_strings_reply(translation, 1);
     632                fibril_rwlock_read_unlock(&arp_globals.lock);
     633                return ERROR_CODE;
     634
     635        case NET_ARP_CLEAR_DEVICE:
     636                return arp_clear_device_req(0, IPC_GET_DEVICE(call));
     637
     638        case NET_ARP_CLEAR_ADDRESS:
     639                ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
     640                arp_clear_address_req(0, IPC_GET_DEVICE(call),
     641                    IPC_GET_SERVICE(call), address);
     642                free(address);
     643                free(data);
     644                return EOK;
     645       
     646        case NET_ARP_CLEAN_CACHE:
     647                return arp_clean_cache_req(0);
     648       
     649        case NET_IL_DEVICE_STATE:
     650                // do nothing - keep the cache
     651                return EOK;
     652       
     653        case NET_IL_RECEIVED:
     654                if (ERROR_NONE(packet_translate_remote(arp_globals.net_phone,
     655                    &packet, IPC_GET_PACKET(call)))) {
     656                        fibril_rwlock_read_lock(&arp_globals.lock);
     657                        do {
     658                                next = pq_detach(packet);
     659                                ERROR_CODE =
     660                                    arp_receive_message(IPC_GET_DEVICE(call),
     661                                    packet);
     662                                if (ERROR_CODE != 1) {
     663                                        pq_release_remote(arp_globals.net_phone,
     664                                            packet_get_id(packet));
     665                                }
     666                                packet = next;
     667                        } while (packet);
     668                        fibril_rwlock_read_unlock(&arp_globals.lock);
     669                }
     670                return ERROR_CODE;
     671       
     672        case NET_IL_MTU_CHANGED:
     673                return arp_mtu_changed_message(IPC_GET_DEVICE(call),
     674                    IPC_GET_MTU(call));
     675        }
     676       
     677        return ENOTSUP;
     678}
     679
    596680/** Default thread for new connections.
    597681 *
    598  *  @param[in] iid The initial message identifier.
    599  *  @param[in] icall The initial message call structure.
    600  *
    601  */
    602 static void il_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     682 * @param[in] iid       The initial message identifier.
     683 * @param[in] icall     The initial message call structure.
     684 */
     685static void il_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    603686{
    604687        /*
     
    608691        ipc_answer_0(iid, EOK);
    609692       
    610         while(true) {
     693        while (true) {
    611694                ipc_call_t answer;
    612695                int answer_count;
     
    623706                    &answer_count);
    624707               
    625                 /* End if said to either by the message or the processing result */
    626                 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     708                /*
     709                 * End if told to either by the message or the processing
     710                 * result.
     711                 */
     712                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) ||
     713                    (res == EHANGUP))
    627714                        return;
    628715               
     
    634721/** Starts the module.
    635722 *
    636  *  @param argc The count of the command line arguments. Ignored parameter.
    637  *  @param argv The command line parameters. Ignored parameter.
    638  *
    639  *  @returns EOK on success.
    640  *  @returns Other error codes as defined for each specific module start function.
    641  *
     723 * @returns             EOK on success.
     724 * @returns             Other error codes as defined for each specific module
     725 *                      start function.
    642726 */
    643727int main(int argc, char *argv[])
     
    646730       
    647731        /* Start the module */
    648         if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection)))
    649                 return ERROR_CODE;
    650        
     732        ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));
    651733        return EOK;
    652734}
     
    654736/** @}
    655737 */
     738
  • uspace/srv/net/il/arp/arp.h

    r0a3fbc7 re9caf47  
    2828
    2929/** @addtogroup arp
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  ARP module.
     34 * ARP module.
    3535 */
    3636
    37 #ifndef __NET_ARP_H__
    38 #define __NET_ARP_H__
     37#ifndef NET_ARP_H_
     38#define NET_ARP_H_
    3939
    4040#include <fibril_synch.h>
     
    4444
    4545#include <net/device.h>
     46#include <net/packet.h>
    4647#include <net_hardware.h>
    4748#include <adt/generic_char_map.h>
     
    4950#include <adt/measured_strings.h>
    5051
    51 
    5252/** Type definition of the ARP device specific data.
    53  *  @see arp_device
     53 * @see arp_device
    5454 */
    55 typedef struct arp_device       arp_device_t;
     55typedef struct arp_device arp_device_t;
    5656
    5757/** Type definition of the ARP device specific data pointer.
    58  *  @see arp_device
     58 * @see arp_device
    5959 */
    60 typedef arp_device_t *          arp_device_ref;
     60typedef arp_device_t *arp_device_ref;
    6161
    6262/** Type definition of the ARP global data.
    63  *  @see arp_globals
     63 * @see arp_globals
    6464 */
    65 typedef struct arp_globals      arp_globals_t;
     65typedef struct arp_globals arp_globals_t;
    6666
    6767/** Type definition of the ARP protocol specific data.
    68  *  @see arp_proto
     68 * @see arp_proto
    6969 */
    70 typedef struct arp_proto        arp_proto_t;
     70typedef struct arp_proto arp_proto_t;
    7171
    7272/** Type definition of the ARP protocol specific data pointer.
    73  *  @see arp_proto
     73 * @see arp_proto
    7474 */
    75 typedef arp_proto_t *           arp_proto_ref;
     75typedef arp_proto_t *arp_proto_ref;
    7676
    7777/** ARP address map.
    78  *  Translates addresses.
    79  *  @see generic_char_map.h
     78 *
     79 * Translates addresses.
     80 * @see generic_char_map.h
    8081 */
    81 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)
     82GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t);
    8283
    8384/** ARP address cache.
    84  *  Maps devices to the ARP device specific data.
    85  *  @see device.h
     85 *
     86 * Maps devices to the ARP device specific data.
     87 * @see device.h
    8688 */
    87 DEVICE_MAP_DECLARE(arp_cache, arp_device_t)
     89DEVICE_MAP_DECLARE(arp_cache, arp_device_t);
    8890
    8991/** ARP protocol map.
    90  *  Maps protocol identifiers to the ARP protocol specific data.
    91  *  @see int_map.h
     92 *
     93 * Maps protocol identifiers to the ARP protocol specific data.
     94 * @see int_map.h
    9295 */
    93 INT_MAP_DECLARE(arp_protos, arp_proto_t)
     96INT_MAP_DECLARE(arp_protos, arp_proto_t);
    9497
    95 /** ARP device specific data.
    96  */
    97 struct arp_device{
    98         /** Actual device hardware address.
    99          */
     98/** ARP device specific data. */
     99struct arp_device {
     100        /** Actual device hardware address. */
    100101        measured_string_ref addr;
    101         /** Actual device hardware address data.
    102          */
    103         char * addr_data;
    104         /** Broadcast device hardware address.
    105          */
     102        /** Actual device hardware address data. */
     103        char *addr_data;
     104        /** Broadcast device hardware address. */
    106105        measured_string_ref broadcast_addr;
    107         /** Broadcast device hardware address data.
    108          */
    109         char * broadcast_data;
    110         /** Device identifier.
    111          */
     106        /** Broadcast device hardware address data. */
     107        char *broadcast_data;
     108        /** Device identifier. */
    112109        device_id_t device_id;
    113         /** Hardware type.
    114          */
     110        /** Hardware type. */
    115111        hw_type_t hardware;
    116         /** Packet dimension.
    117          */
     112        /** Packet dimension. */
    118113        packet_dimension_t packet_dimension;
    119         /** Device module phone.
    120          */
     114        /** Device module phone. */
    121115        int phone;
    122         /** Protocol map.
    123          *  Address map for each protocol.
     116       
     117        /**
     118         * Protocol map.
     119         * Address map for each protocol.
    124120         */
    125121        arp_protos_t protos;
    126         /** Device module service.
    127         */
     122       
     123        /** Device module service. */
    128124        services_t service;
    129125};
    130126
    131 /** ARP global data.
    132  */
    133 struct  arp_globals{
    134         /** ARP address cache.
    135          */
     127/** ARP global data. */
     128struct arp_globals {
     129        /** ARP address cache. */
    136130        arp_cache_t cache;
    137         /** The client connection processing function.
    138          *  The module skeleton propagates its own one.
     131       
     132        /**
     133         * The client connection processing function.
     134         * The module skeleton propagates its own one.
    139135         */
    140136        async_client_conn_t client_connection;
    141         /** Networking module phone.
    142         */
     137       
     138        /** Networking module phone. */
    143139        int net_phone;
    144         /** Safety lock.
    145          */
     140        /** Safety lock. */
    146141        fibril_rwlock_t lock;
    147142};
    148143
    149 /** ARP protocol specific data.
    150  */
    151 struct arp_proto{
    152         /** Actual device protocol address.
    153          */
     144/** ARP protocol specific data. */
     145struct arp_proto {
     146        /** Actual device protocol address. */
    154147        measured_string_ref addr;
    155         /** Actual device protocol address data.
    156          */
    157         char * addr_data;
    158         /** Address map.
    159          */
     148        /** Actual device protocol address data. */
     149        char *addr_data;
     150        /** Address map. */
    160151        arp_addr_t addresses;
    161         /** Protocol service.
    162          */
     152        /** Protocol service. */
    163153        services_t service;
    164154};
  • uspace/srv/net/il/arp/arp_header.h

    r0a3fbc7 re9caf47  
    3232
    3333/** @file
    34  *  ARP protocol header.
    35  *  Based on the RFC~826.
     34 * ARP protocol header.
     35 * Based on the RFC 826.
    3636 */
    3737
    38 #ifndef __NET_ARP_HEADER_H__
    39 #define __NET_ARP_HEADER_H__
     38#ifndef NET_ARP_HEADER_H_
     39#define NET_ARP_HEADER_H_
    4040
    4141#include <sys/types.h>
    4242
    4343/** Type definition of an ARP protocol header.
    44  *  @see arp_header
     44 * @see arp_header
    4545 */
    46 typedef struct arp_header       arp_header_t;
     46typedef struct arp_header arp_header_t;
    4747
    4848/** Type definition of an ARP protocol header pointer.
    49  *  @see arp_header
     49 * @see arp_header
    5050 */
    51 typedef arp_header_t *          arp_header_ref;
     51typedef arp_header_t *arp_header_ref;
    5252
    53 /** ARP protocol header.
    54  */
    55 struct arp_header{
    56         /** Hardware type identifier.
    57          *  @see hardware.h
     53/** ARP protocol header. */
     54struct arp_header {
     55        /**
     56         * Hardware type identifier.
     57         * @see hardware.h
    5858         */
    5959        uint16_t hardware;
    60         /** Protocol identifier.
    61         */
     60       
     61        /** Protocol identifier. */
    6262        uint16_t protocol;
    63         /** Hardware address length in bytes.
    64          */
     63        /** Hardware address length in bytes. */
    6564        uint8_t hardware_length;
    66         /** Protocol address length in bytes.
    67          */
     65        /** Protocol address length in bytes. */
    6866        uint8_t protocol_length;
    69         /** ARP packet type.
    70          *  @see arp_oc.h
     67       
     68        /**
     69         * ARP packet type.
     70         * @see arp_oc.h
    7171         */
    7272        uint16_t operation;
  • uspace/srv/net/il/arp/arp_module.c

    r0a3fbc7 re9caf47  
    3232
    3333/** @file
    34  *  ARP standalone module implementation.
    35  *  Contains skeleton module functions mapping.
    36  *  The functions are used by the module skeleton as module specific entry points.
    37  *  @see module.c
     34 * ARP standalone module implementation.
     35 * Contains skeleton module functions mapping.
     36 * The functions are used by the module skeleton as module specific entry
     37 * points.
     38 * @see module.c
    3839 */
    3940
     
    5354#include "arp_module.h"
    5455
    55 /** ARP module global data.
    56  */
    57 extern arp_globals_t    arp_globals;
     56/** ARP module global data. */
     57extern arp_globals_t arp_globals;
    5858
    59 int il_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     59int
     60il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     61    ipc_call_t *answer, int *answer_count)
     62{
    6063        return arp_message_standalone(callid, call, answer, answer_count);
    6164}
    6265
    63 int il_module_start_standalone(async_client_conn_t client_connection){
     66int il_module_start_standalone(async_client_conn_t client_connection)
     67{
    6468        ERROR_DECLARE;
    6569       
     
    6973       
    7074        ipcarg_t phonehash;
    71         if (ERROR_OCCURRED(arp_initialize(client_connection))
    72             || ERROR_OCCURRED(REGISTER_ME(SERVICE_ARP, &phonehash))) {
     75        if (ERROR_OCCURRED(arp_initialize(client_connection)) ||
     76            ERROR_OCCURRED(REGISTER_ME(SERVICE_ARP, &phonehash))) {
    7377                pm_destroy();
    7478                return ERROR_CODE;
  • uspace/srv/net/il/arp/arp_module.h

    r0a3fbc7 re9caf47  
    2828
    2929/** @addtogroup arp
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  ARP module functions.
    35  *  The functions are used as ARP module entry points.
     34 * ARP module functions.
     35 * The functions are used as ARP module entry points.
    3636 */
    3737
    38 #ifndef __NET_ARP_MODULE_H__
    39 #define __NET_ARP_MODULE_H__
     38#ifndef NET_ARP_MODULE_H_
     39#define NET_ARP_MODULE_H_
    4040
    4141#include <ipc/ipc.h>
     42#include <async.h>
    4243
    43 /** Initializes the ARP module.
    44  *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
    45  *  @returns EOK on success.
    46  *  @returns ENOMEM if there is not enough memory left.
    47  */
    48 int arp_initialize(async_client_conn_t client_connection);
    49 
    50 /** Processes the ARP message.
    51  *  @param[in] callid The message identifier.
    52  *  @param[in] call The message parameters.
    53  *  @param[out] answer The message answer parameters.
    54  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    55  *  @returns EOK on success.
    56  *  @returns ENOTSUP if the message is not known.
    57  *  @see arp_interface.h
    58  *  @see IS_NET_ARP_MESSAGE()
    59  */
    60 int arp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     44extern int arp_initialize(async_client_conn_t);
     45extern int arp_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *,
     46    int *);
    6147
    6248#endif
  • uspace/srv/net/il/arp/arp_oc.h

    r0a3fbc7 re9caf47  
    3232
    3333/** @file
    34  *  ARP operation codes according to the on-line IANA - Address Resolution Protocol (ARP) Parameters - <http://www.iana.org/assignments/arp-parameters/arp-parameters.xml>, cited January 14 2009.
     34 * ARP operation codes according to the on-line IANA - Address Resolution
     35 * Protocol (ARP) Parameters
     36 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xml
     37 * cited January 14 2009.
    3538 */
    3639
    37 #ifndef __NET_ARP_ARPOP_H__
    38 #define __NET_ARP_ARPOP_H__
     40#ifndef NET_ARP_ARPOP_H_
     41#define NET_ARP_ARPOP_H_
    3942
    40 /** @name ARP operation codes definitions
    41  */
     43/** @name ARP operation codes definitions */
    4244/*@{*/
    4345
    44 /** REQUEST operation code.
    45  */
    46 #define ARPOP_REQUEST                                   1
     46/** REQUEST operation code. */
     47#define ARPOP_REQUEST   1
    4748
    48 /** REPLY operation code.
    49  */
    50 #define ARPOP_REPLY                                             2
    51 
    52 /** Reverse request operation code.
    53  */
    54 #define ARPOP_RREQUEST                                  3
    55 
    56 /** Reverse reply operation code.
    57  */
    58 #define ARPOP_RREPLY                                    4
    59 
    60 /** DRARP-Request operation code.
    61  */
    62 #define ARPOP_DRARP_Request                             5
    63 
    64 /** DRARP-Reply operation code.
    65  */
    66 #define ARPOP_DRARP_Reply                               6
    67 
    68 /** DRARP-Error operation code.
    69  */
    70 #define ARPOP_DRARP_Error                               7
    71 
    72 /** InARP-Request operation code.
    73  */
    74 #define ARPOP_InREQUEST                                 8
    75 
    76 /** InARP-Reply operation code.
    77  */
    78 #define ARPOP_InREPLY                                   9
    79 
    80 /** ARP-NAK operation code.
    81  */
    82 #define ARPOP_NAK                                               10
    83 
    84 /** MARS-Request operation code.
    85  */
    86 #define ARPOP_MARS_Request                              11
    87 
    88 /** MARS-Multi operation code.
    89  */
    90 #define ARPOP_MARS_Multi                                12
    91 
    92 /** MARS-MServ operation code.
    93  */
    94 #define ARPOP_MARS_MServ                                13
    95 
    96 /** MARS-Join operation code.
    97  */
    98 #define ARPOP_MARS_Join                                 14
    99 
    100 /** MARS-Leave operation code.
    101  */
    102 #define ARPOP_MARS_Leave                                15
    103 
    104 /** MARS-NAK operation code.
    105  */
    106 #define ARPOP_MARS_NAK                                  16
    107 
    108 /** MARS-Unserv operation code.
    109  */
    110 #define ARPOP_MARS_Unserv                               17
    111 
    112 /** MARS-SJoin operation code.
    113  */
    114 #define ARPOP_MARS_SJoin                                18
    115 
    116 /** MARS-SLeave operation code.
    117  */
    118 #define ARPOP_MARS_SLeave                               19
    119 
    120 /** MARS-Grouplist-Request operation code.
    121  */
    122 #define ARPOP_MARS_Grouplist_Request    20
    123 
    124 /** MARS-Grouplist-Reply operation code.
    125  */
    126 #define ARPOP_MARS_Grouplist_Reply              21
    127 
    128 /** MARS-Redirect-Map operation code.
    129  */
    130 #define ARPOP_MARS_Redirect_Map                 22
    131 
    132 /** MAPOS-UNARP operation code.
    133  */
    134 #define ARPOP_MAPOS_UNARP                               23
     49/** REPLY operation code. */
     50#define ARPOP_REPLY     2
    13551
    13652/*@}*/
Note: See TracChangeset for help on using the changeset viewer.