Changeset a64c64d in mainline for uspace/srv/net/il


Ignore:
Timestamp:
2010-03-09T22:24:31Z (16 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74520daf
Parents:
9f2ea28
Message:
  • code reorganization (no functional change)
Location:
uspace/srv/net/il
Files:
13 edited

Legend:

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

    r9f2ea28 ra64c64d  
    7373arp_globals_t   arp_globals;
    7474
     75/** Clears the device specific data.
     76 *  @param[in] device The device specific data.
     77 */
     78void arp_clear_device(arp_device_ref device);
     79
    7580/** Creates new protocol specific data.
    7681 *  Allocates and returns the needed memory block as the proto parameter.
     
    8287 */
    8388int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address);
    84 
    85 /** Clears the device specific data.
    86  *  @param[in] device The device specific data.
    87  */
    88 void arp_clear_device(arp_device_ref device);
    8989
    9090/** @name Message processing functions
     
    105105int arp_device_message(device_id_t device_id, services_t service, services_t protocol, measured_string_ref address);
    106106
    107 /** Returns the hardware address for the given protocol address.
    108  *  Sends the ARP request packet if the hardware address is not found in the cache.
     107/** Updates the device content length according to the new MTU value.
    109108 *  @param[in] device_id The device identifier.
    110  *  @param[in] protocol The protocol service.
    111  *  @param[in] target The target protocol address.
    112  *  @returns The hardware address of the target.
    113  *  @returns NULL if the target parameter is NULL.
    114  *  @returns NULL if the device is not found.
    115  *  @returns NULL if the device packet is too small to send a&nbsp;request.
    116  *  @returns NULL if the hardware address is not found in the cache.
    117  */
    118 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target);
     109 *  @param[in] mtu The new mtu value.
     110 *  @returns ENOENT if device is not found.
     111 *  @returns EOK on success.
     112 */
     113int arp_mtu_changed_message(device_id_t device_id, size_t mtu);
    119114
    120115/** Processes the received ARP packet.
     
    133128int arp_receive_message(device_id_t device_id, packet_t packet);
    134129
    135 /** Updates the device content length according to the new MTU value.
     130/** Returns the hardware address for the given protocol address.
     131 *  Sends the ARP request packet if the hardware address is not found in the cache.
    136132 *  @param[in] device_id The device identifier.
    137  *  @param[in] mtu The new mtu value.
    138  *  @returns ENOENT if device is not found.
    139  *  @returns EOK on success.
    140  */
    141 int arp_mtu_changed_message(device_id_t device_id, size_t mtu);
     133 *  @param[in] protocol The protocol service.
     134 *  @param[in] target The target protocol address.
     135 *  @returns The hardware address of the target.
     136 *  @returns NULL if the target parameter is NULL.
     137 *  @returns NULL if the device is not found.
     138 *  @returns NULL if the device packet is too small to send a&nbsp;request.
     139 *  @returns NULL if the hardware address is not found in the cache.
     140 */
     141measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target);
    142142
    143143/*@}*/
     
    148148
    149149GENERIC_CHAR_MAP_IMPLEMENT(arp_addr, measured_string_t)
    150 
    151 task_id_t arp_task_get_id(void){
    152         return task_get_id();
    153 }
    154 
    155 int arp_clear_device_req(int arp_phone, device_id_t device_id){
    156         arp_device_ref device;
    157 
    158         fibril_rwlock_write_lock(&arp_globals.lock);
    159         device = arp_cache_find(&arp_globals.cache, device_id);
    160         if(! device){
    161                 fibril_rwlock_write_unlock(&arp_globals.lock);
    162                 return ENOENT;
    163         }
    164         arp_clear_device(device);
    165         printf("Device %d cleared\n", device_id);
    166         fibril_rwlock_write_unlock(&arp_globals.lock);
    167         return EOK;
    168 }
    169 
    170 int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
    171         arp_device_ref device;
    172         arp_proto_ref proto;
    173 
    174         fibril_rwlock_write_lock(&arp_globals.lock);
    175         device = arp_cache_find(&arp_globals.cache, device_id);
    176         if(! device){
    177                 fibril_rwlock_write_unlock(&arp_globals.lock);
    178                 return ENOENT;
    179         }
    180         proto = arp_protos_find(&device->protos, protocol);
    181         if(! proto){
    182                 fibril_rwlock_write_unlock(&arp_globals.lock);
    183                 return ENOENT;
    184         }
    185         arp_addr_exclude(&proto->addresses, address->value, address->length);
    186         fibril_rwlock_write_unlock(&arp_globals.lock);
    187         return EOK;
    188 }
    189150
    190151int arp_clean_cache_req(int arp_phone){
     
    211172}
    212173
    213 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
    214         ERROR_DECLARE;
    215 
    216         measured_string_ref tmp;
    217 
    218         // copy the given address for exclusive use
    219         tmp = measured_string_copy(address);
    220         if(ERROR_OCCURRED(arp_device_message(device_id, netif, protocol, tmp))){
    221                 free(tmp->value);
    222                 free(tmp);
    223         }
    224         return ERROR_CODE;
    225 }
    226 
    227 int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
    228         measured_string_ref tmp;
    229 
    230         fibril_rwlock_read_lock(&arp_globals.lock);
    231         tmp = arp_translate_message(device_id, protocol, address);
    232         if(tmp){
    233                 *translation = measured_string_copy(tmp);
    234                 fibril_rwlock_read_unlock(&arp_globals.lock);
    235                 if(*translation){
    236                         *data = (** translation).value;
    237                         return EOK;
    238                 }else{
    239                         return ENOMEM;
    240                 }
    241         }else{
    242                 fibril_rwlock_read_unlock(&arp_globals.lock);
     174int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
     175        arp_device_ref device;
     176        arp_proto_ref proto;
     177
     178        fibril_rwlock_write_lock(&arp_globals.lock);
     179        device = arp_cache_find(&arp_globals.cache, device_id);
     180        if(! device){
     181                fibril_rwlock_write_unlock(&arp_globals.lock);
    243182                return ENOENT;
    244183        }
    245 }
    246 
    247 int arp_initialize(async_client_conn_t client_connection){
    248         ERROR_DECLARE;
    249 
    250         fibril_rwlock_initialize(&arp_globals.lock);
     184        proto = arp_protos_find(&device->protos, protocol);
     185        if(! proto){
     186                fibril_rwlock_write_unlock(&arp_globals.lock);
     187                return ENOENT;
     188        }
     189        arp_addr_exclude(&proto->addresses, address->value, address->length);
     190        fibril_rwlock_write_unlock(&arp_globals.lock);
     191        return EOK;
     192}
     193
     194void arp_clear_device(arp_device_ref device){
     195        int count;
     196        arp_proto_ref proto;
     197
     198        for(count = arp_protos_count(&device->protos) - 1; count >= 0; -- count){
     199                proto = arp_protos_get_index(&device->protos, count);
     200                if(proto){
     201                        if(proto->addr){
     202                                free(proto->addr);
     203                        }
     204                        if(proto->addr_data){
     205                                free(proto->addr_data);
     206                        }
     207                        arp_addr_destroy(&proto->addresses);
     208                }
     209        }
     210        arp_protos_clear(&device->protos);
     211}
     212
     213int arp_clear_device_req(int arp_phone, device_id_t device_id){
     214        arp_device_ref device;
     215
    251216        fibril_rwlock_write_lock(&arp_globals.lock);
    252         arp_globals.client_connection = client_connection;
    253         ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));
     217        device = arp_cache_find(&arp_globals.cache, device_id);
     218        if(! device){
     219                fibril_rwlock_write_unlock(&arp_globals.lock);
     220                return ENOENT;
     221        }
     222        arp_clear_device(device);
     223        printf("Device %d cleared\n", device_id);
    254224        fibril_rwlock_write_unlock(&arp_globals.lock);
    255225        return EOK;
    256226}
    257227
    258 int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address){
    259         ERROR_DECLARE;
    260 
    261         *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t));
    262         if(!(*proto)){
    263                 return ENOMEM;
    264         }
    265         (** proto).service = service;
    266         (** proto).addr = address;
    267         (** proto).addr_data = address->value;
    268         if(ERROR_OCCURRED(arp_addr_initialize(&(** proto).addresses))){
    269                 free(*proto);
    270                 return ERROR_CODE;
     228int arp_connect_module(services_t service){
     229        if(service != SERVICE_ARP){
     230                return EINVAL;
    271231        }
    272232        return EOK;
     
    383343}
    384344
    385 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target){
    386         arp_device_ref device;
    387         arp_proto_ref proto;
    388         measured_string_ref addr;
    389         size_t length;
    390         packet_t packet;
    391         arp_header_ref header;
    392 
    393         if(! target){
    394                 return NULL;
    395         }
    396         device = arp_cache_find(&arp_globals.cache, device_id);
    397         if(! device){
    398                 return NULL;
    399         }
    400         proto = arp_protos_find(&device->protos, protocol);
    401         if((! proto) || (proto->addr->length != target->length)){
    402                 return NULL;
    403         }
    404         addr = arp_addr_find(&proto->addresses, target->value, target->length);
    405         if(addr){
    406                 return addr;
    407         }
    408         // ARP packet content size = header + (address + translation) * 2
    409         length = 8 + (CONVERT_SIZE(char, uint8_t, proto->addr->length) + CONVERT_SIZE(char, uint8_t, device->addr->length)) * 2;
    410         if(length > device->packet_dimension.content){
    411                 return NULL;
    412         }
    413         packet = packet_get_4(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
    414         if(! packet){
    415                 return NULL;
    416         }
    417         header = (arp_header_ref) packet_suffix(packet, length);
    418         if(! header){
    419                 pq_release(arp_globals.net_phone, packet_get_id(packet));
    420                 return NULL;
    421         }
    422         header->hardware = htons(device->hardware);
    423         header->hardware_length = (uint8_t) device->addr->length;
    424         header->protocol = htons(protocol_map(device->service, protocol));
    425         header->protocol_length = (uint8_t) proto->addr->length;
    426         header->operation = htons(ARPOP_REQUEST);
    427         length = sizeof(arp_header_t);
    428         memcpy(((uint8_t *) header) + length, device->addr->value, device->addr->length);
    429         length += device->addr->length;
    430         memcpy(((uint8_t *) header) + length, proto->addr->value, proto->addr->length);
    431         length += proto->addr->length;
    432         bzero(((uint8_t *) header) + length, device->addr->length);
    433         length += device->addr->length;
    434         memcpy(((uint8_t *) header) + length, target->value, target->length);
    435         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){
    436                 pq_release(arp_globals.net_phone, packet_get_id(packet));
    437                 return NULL;
    438         }
    439         nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
    440         return NULL;
    441 }
    442 
    443 int arp_receive_message(device_id_t device_id, packet_t packet){
     345int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
    444346        ERROR_DECLARE;
    445347
    446         size_t length;
    447         arp_header_ref header;
    448         arp_device_ref device;
    449         arp_proto_ref proto;
    450         measured_string_ref hw_source;
    451         uint8_t * src_hw;
    452         uint8_t * src_proto;
    453         uint8_t * des_hw;
    454         uint8_t * des_proto;
    455 
    456         length = packet_get_data_length(packet);
    457         if(length <= sizeof(arp_header_t)){
    458                 return EINVAL;
    459         }
    460         device = arp_cache_find(&arp_globals.cache, device_id);
    461         if(! device){
    462                 return ENOENT;
    463         }
    464         header = (arp_header_ref) packet_get_data(packet);
    465         if((ntohs(header->hardware) != device->hardware)
    466                 || (length < sizeof(arp_header_t) + header->hardware_length * 2u + header->protocol_length * 2u)){
    467                 return EINVAL;
    468         }
    469         proto = arp_protos_find(&device->protos, protocol_unmap(device->service, ntohs(header->protocol)));
    470         if(! proto){
    471                 return ENOENT;
    472         }
    473         src_hw = ((uint8_t *) header) + sizeof(arp_header_t);
    474         src_proto = src_hw + header->hardware_length;
    475         des_hw = src_proto + header->protocol_length;
    476         des_proto = des_hw + header->hardware_length;
    477         hw_source = arp_addr_find(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length));
    478         // exists?
    479         if(hw_source){
    480                 if(hw_source->length != CONVERT_SIZE(uint8_t, char, header->hardware_length)){
    481                         return EINVAL;
    482                 }
    483                 memcpy(hw_source->value, src_hw, hw_source->length);
    484         }
    485         // is my protocol address?
    486         if(proto->addr->length != CONVERT_SIZE(uint8_t, char, header->protocol_length)){
    487                 return EINVAL;
    488         }
    489         if(! str_lcmp(proto->addr->value, (char *) des_proto, proto->addr->length)){
    490                 // not already upadted?
    491                 if(! hw_source){
    492                         hw_source = measured_string_create_bulk((char *) src_hw, CONVERT_SIZE(uint8_t, char, header->hardware_length));
    493                         if(! hw_source){
    494                                 return ENOMEM;
    495                         }
    496                         ERROR_PROPAGATE(arp_addr_add(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length), hw_source));
    497                 }
    498                 if(ntohs(header->operation) == ARPOP_REQUEST){
    499                         header->operation = htons(ARPOP_REPLY);
    500                         memcpy(des_proto, src_proto, header->protocol_length);
    501                         memcpy(src_proto, proto->addr->value, header->protocol_length);
    502                         memcpy(src_hw, device->addr->value, device->packet_dimension.addr_len);
    503                         memcpy(des_hw, hw_source->value, header->hardware_length);
    504                         ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw, header->hardware_length));
    505                         nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
    506                         return 1;
    507                 }
    508         }
    509         return EOK;
    510 }
    511 
    512 void arp_clear_device(arp_device_ref device){
    513         int count;
    514         arp_proto_ref proto;
    515 
    516         for(count = arp_protos_count(&device->protos) - 1; count >= 0; -- count){
    517                 proto = arp_protos_get_index(&device->protos, count);
    518                 if(proto){
    519                         if(proto->addr){
    520                                 free(proto->addr);
    521                         }
    522                         if(proto->addr_data){
    523                                 free(proto->addr_data);
    524                         }
    525                         arp_addr_destroy(&proto->addresses);
    526                 }
    527         }
    528         arp_protos_clear(&device->protos);
    529 }
    530 
    531 int arp_connect_module(services_t service){
    532         if(service != SERVICE_ARP){
    533                 return EINVAL;
    534         }
    535         return EOK;
    536 }
    537 
    538 int arp_mtu_changed_message(device_id_t device_id, size_t mtu){
    539         arp_device_ref device;
    540 
     348        measured_string_ref tmp;
     349
     350        // copy the given address for exclusive use
     351        tmp = measured_string_copy(address);
     352        if(ERROR_OCCURRED(arp_device_message(device_id, netif, protocol, tmp))){
     353                free(tmp->value);
     354                free(tmp);
     355        }
     356        return ERROR_CODE;
     357}
     358
     359int arp_initialize(async_client_conn_t client_connection){
     360        ERROR_DECLARE;
     361
     362        fibril_rwlock_initialize(&arp_globals.lock);
    541363        fibril_rwlock_write_lock(&arp_globals.lock);
    542         device = arp_cache_find(&arp_globals.cache, device_id);
    543         if(! device){
    544                 fibril_rwlock_write_unlock(&arp_globals.lock);
    545                 return ENOENT;
    546         }
    547         device->packet_dimension.content = mtu;
    548         printf("arp - device %d changed mtu to %d\n\n", device_id, mtu);
     364        arp_globals.client_connection = client_connection;
     365        ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));
    549366        fibril_rwlock_write_unlock(&arp_globals.lock);
    550367        return EOK;
     
    618435}
    619436
     437int arp_mtu_changed_message(device_id_t device_id, size_t mtu){
     438        arp_device_ref device;
     439
     440        fibril_rwlock_write_lock(&arp_globals.lock);
     441        device = arp_cache_find(&arp_globals.cache, device_id);
     442        if(! device){
     443                fibril_rwlock_write_unlock(&arp_globals.lock);
     444                return ENOENT;
     445        }
     446        device->packet_dimension.content = mtu;
     447        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
     452int 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
     469int arp_receive_message(device_id_t device_id, packet_t packet){
     470        ERROR_DECLARE;
     471
     472        size_t length;
     473        arp_header_ref header;
     474        arp_device_ref device;
     475        arp_proto_ref proto;
     476        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;
     481
     482        length = packet_get_data_length(packet);
     483        if(length <= sizeof(arp_header_t)){
     484                return EINVAL;
     485        }
     486        device = arp_cache_find(&arp_globals.cache, device_id);
     487        if(! device){
     488                return ENOENT;
     489        }
     490        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)){
     493                return EINVAL;
     494        }
     495        proto = arp_protos_find(&device->protos, protocol_unmap(device->service, ntohs(header->protocol)));
     496        if(! proto){
     497                return ENOENT;
     498        }
     499        src_hw = ((uint8_t *) header) + sizeof(arp_header_t);
     500        src_proto = src_hw + header->hardware_length;
     501        des_hw = src_proto + header->protocol_length;
     502        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));
     504        // exists?
     505        if(hw_source){
     506                if(hw_source->length != CONVERT_SIZE(uint8_t, char, header->hardware_length)){
     507                        return EINVAL;
     508                }
     509                memcpy(hw_source->value, src_hw, hw_source->length);
     510        }
     511        // is my protocol address?
     512        if(proto->addr->length != CONVERT_SIZE(uint8_t, char, header->protocol_length)){
     513                return EINVAL;
     514        }
     515        if(! str_lcmp(proto->addr->value, (char *) des_proto, proto->addr->length)){
     516                // 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){
     520                                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){
     525                        header->operation = htons(ARPOP_REPLY);
     526                        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);
     532                        return 1;
     533                }
     534        }
     535        return EOK;
     536}
     537
     538task_id_t arp_task_get_id(void){
     539        return task_get_id();
     540}
     541
     542measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target){
     543        arp_device_ref device;
     544        arp_proto_ref proto;
     545        measured_string_ref addr;
     546        size_t length;
     547        packet_t packet;
     548        arp_header_ref header;
     549
     550        if(! target){
     551                return NULL;
     552        }
     553        device = arp_cache_find(&arp_globals.cache, device_id);
     554        if(! device){
     555                return NULL;
     556        }
     557        proto = arp_protos_find(&device->protos, protocol);
     558        if((! proto) || (proto->addr->length != target->length)){
     559                return NULL;
     560        }
     561        addr = arp_addr_find(&proto->addresses, target->value, target->length);
     562        if(addr){
     563                return addr;
     564        }
     565        // ARP packet content size = header + (address + translation) * 2
     566        length = 8 + (CONVERT_SIZE(char, uint8_t, proto->addr->length) + CONVERT_SIZE(char, uint8_t, device->addr->length)) * 2;
     567        if(length > device->packet_dimension.content){
     568                return NULL;
     569        }
     570        packet = packet_get_4(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
     571        if(! packet){
     572                return NULL;
     573        }
     574        header = (arp_header_ref) packet_suffix(packet, length);
     575        if(! header){
     576                pq_release(arp_globals.net_phone, packet_get_id(packet));
     577                return NULL;
     578        }
     579        header->hardware = htons(device->hardware);
     580        header->hardware_length = (uint8_t) device->addr->length;
     581        header->protocol = htons(protocol_map(device->service, protocol));
     582        header->protocol_length = (uint8_t) proto->addr->length;
     583        header->operation = htons(ARPOP_REQUEST);
     584        length = sizeof(arp_header_t);
     585        memcpy(((uint8_t *) header) + length, device->addr->value, device->addr->length);
     586        length += device->addr->length;
     587        memcpy(((uint8_t *) header) + length, proto->addr->value, proto->addr->length);
     588        length += proto->addr->length;
     589        bzero(((uint8_t *) header) + length, device->addr->length);
     590        length += device->addr->length;
     591        memcpy(((uint8_t *) header) + length, target->value, target->length);
     592        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){
     593                pq_release(arp_globals.net_phone, packet_get_id(packet));
     594                return NULL;
     595        }
     596        nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
     597        return NULL;
     598}
     599
     600int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
     601        measured_string_ref tmp;
     602
     603        fibril_rwlock_read_lock(&arp_globals.lock);
     604        tmp = arp_translate_message(device_id, protocol, address);
     605        if(tmp){
     606                *translation = measured_string_copy(tmp);
     607                fibril_rwlock_read_unlock(&arp_globals.lock);
     608                if(*translation){
     609                        *data = (** translation).value;
     610                        return EOK;
     611                }else{
     612                        return ENOMEM;
     613                }
     614        }else{
     615                fibril_rwlock_read_unlock(&arp_globals.lock);
     616                return ENOENT;
     617        }
     618}
     619
    620620/** @}
    621621 */
  • uspace/srv/net/il/arp/arp.h

    r9f2ea28 ra64c64d  
    5151
    5252
    53 /** Type definition of the ARP global data.
    54  *  @see arp_globals
    55  */
    56 typedef struct arp_globals      arp_globals_t;
    57 
    5853/** Type definition of the ARP device specific data.
    5954 *  @see arp_device
     
    6661typedef arp_device_t *          arp_device_ref;
    6762
     63/** Type definition of the ARP global data.
     64 *  @see arp_globals
     65 */
     66typedef struct arp_globals      arp_globals_t;
     67
    6868/** Type definition of the ARP protocol specific data.
    6969 *  @see arp_proto
     
    7575 */
    7676typedef arp_proto_t *           arp_proto_ref;
     77
     78/** ARP address map.
     79 *  Translates addresses.
     80 *  @see generic_char_map.h
     81 */
     82GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)
    7783
    7884/** ARP address cache.
     
    8894INT_MAP_DECLARE(arp_protos, arp_proto_t)
    8995
    90 /** ARP address map.
    91  *  Translates addresses.
    92  *  @see generic_char_map.h
    93  */
    94 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)
    95 
    9696/** ARP device specific data.
    9797 */
    9898struct arp_device{
    99         /** Device identifier.
    100          */
    101         device_id_t device_id;
    102         /** Hardware type.
    103          */
    104         hw_type_t hardware;
    105         /** Packet dimension.
    106          */
    107         packet_dimension_t packet_dimension;
    10899        /** Actual device hardware address.
    109100         */
     
    118109         */
    119110        char * broadcast_data;
    120         /** Device module service.
     111        /** Device identifier.
    121112         */
    122         services_t service;
     113        device_id_t device_id;
     114        /** Hardware type.
     115         */
     116        hw_type_t hardware;
     117        /** Packet dimension.
     118         */
     119        packet_dimension_t packet_dimension;
    123120        /** Device module phone.
    124121         */
     
    128125         */
    129126        arp_protos_t protos;
     127        /** Device module service.
     128         */
     129        services_t service;
     130};
     131
     132/** ARP global data.
     133 */
     134struct  arp_globals{
     135        /** ARP address cache.
     136         */
     137        arp_cache_t cache;
     138        /** The client connection processing function.
     139         *  The module skeleton propagates its own one.
     140         */
     141        async_client_conn_t client_connection;
     142        /** Networking module phone.
     143         */
     144        int net_phone;
     145        /** Safety lock.
     146         */
     147        fibril_rwlock_t lock;
    130148};
    131149
     
    133151 */
    134152struct arp_proto{
    135         /** Protocol service.
    136          */
    137         services_t service;
    138153        /** Actual device protocol address.
    139154         */
     
    145160         */
    146161        arp_addr_t addresses;
    147 };
    148 
    149 /** ARP global data.
    150  */
    151 struct  arp_globals{
    152         /** Networking module phone.
     162        /** Protocol service.
    153163         */
    154         int net_phone;
    155         /** Safety lock.
    156          */
    157         fibril_rwlock_t lock;
    158         /** ARP address cache.
    159          */
    160         arp_cache_t cache;
    161         /** The client connection processing function.
    162          *  The module skeleton propagates its own one.
    163          */
    164         async_client_conn_t client_connection;
     164        services_t service;
    165165};
    166166
  • uspace/srv/net/il/arp/arp_messages.h

    r9f2ea28 ra64c64d  
    4646 */
    4747typedef enum{
    48         /** New device message.
    49          *  @see arp_device_req()
     48        /** Clean cache message.
     49         *  @see arp_clean_cache()
    5050         */
    51         NET_ARP_DEVICE = NET_ARP_FIRST,
    52         /** Address translation message.
    53          *  @see arp_translate_req()
     51        NET_ARP_CLEAN_CACHE = NET_ARP_FIRST,
     52        /** Clear address cache message.
     53         *  @see arp_clear_address_msg()
    5454         */
    55         NET_ARP_TRANSLATE,
     55        NET_ARP_CLEAR_ADDRESS,
    5656        /** Clear device cache message.
    5757         *  @see arp_clear_device_req()
    5858         */
    5959        NET_ARP_CLEAR_DEVICE,
    60         /** Clear address cache message.
    61          *  @see arp_clear_address_msg()
     60        /** New device message.
     61         *  @see arp_device_req()
    6262         */
    63         NET_ARP_CLEAR_ADDRESS,
    64         /** Clean cache message.
    65          *  @see arp_clean_cache()
     63        NET_ARP_DEVICE,
     64        /** Address translation message.
     65         *  @see arp_translate_req()
    6666         */
    67         NET_ARP_CLEAN_CACHE,
     67        NET_ARP_TRANSLATE
    6868} arp_messages;
    6969
  • uspace/srv/net/il/arp/arp_module.c

    r9f2ea28 ra64c64d  
    5858#define NAME    "ARP protocol"
    5959
     60/** ARP module global data.
     61 */
     62extern arp_globals_t    arp_globals;
     63
     64/** Processes the ARP message.
     65 *  @param[in] callid The message identifier.
     66 *  @param[in] call The message parameters.
     67 *  @param[out] answer The message answer parameters.
     68 *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
     69 *  @returns EOK on success.
     70 *  @returns Other error codes as defined for the arp_message() function.
     71 */
     72int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     73
    6074/** Prints the module name.
    6175 *  @see NAME
     
    7286int module_start(async_client_conn_t client_connection);
    7387
    74 /** Processes the ARP message.
    75  *  @param[in] callid The message identifier.
    76  *  @param[in] call The message parameters.
    77  *  @param[out] answer The message answer parameters.
    78  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    79  *  @returns EOK on success.
    80  *  @returns Other error codes as defined for the arp_message() function.
    81  */
    82 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
    83 
    84 /** ARP module global data.
    85  */
    86 extern arp_globals_t    arp_globals;
     88int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     89        return arp_message(callid, call, answer, answer_count);
     90}
    8791
    8892void module_print_name(void){
     
    110114}
    111115
    112 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    113         return arp_message(callid, call, answer, answer_count);
    114 }
    115 
    116116/** @}
    117117 */
  • uspace/srv/net/il/arp/arp_oc.h

    r9f2ea28 ra64c64d  
    4444/** REQUEST operation code.
    4545 */
    46 #define ARPOP_REQUEST           1
     46#define ARPOP_REQUEST                                   1
    4747
    4848/** REPLY operation code.
    4949 */
    50 #define ARPOP_REPLY             2
     50#define ARPOP_REPLY                                             2
    5151
    5252/** Reverse request operation code.
    5353 */
    54 #define ARPOP_RREQUEST          3
     54#define ARPOP_RREQUEST                                  3
    5555
    5656/** Reverse reply operation code.
    5757 */
    58 #define ARPOP_RREPLY            4
     58#define ARPOP_RREPLY                                    4
    5959
    6060/** DRARP-Request operation code.
    6161 */
    62 #define ARPOP_DRARP_Request             5
     62#define ARPOP_DRARP_Request                             5
    6363
    6464/** DRARP-Reply operation code.
    6565 */
    66 #define ARPOP_DRARP_Reply               6
     66#define ARPOP_DRARP_Reply                               6
    6767
    6868/** DRARP-Error operation code.
    6969 */
    70 #define ARPOP_DRARP_Error               7
     70#define ARPOP_DRARP_Error                               7
    7171
    7272/** InARP-Request operation code.
    7373 */
    74 #define ARPOP_InREQUEST         8
     74#define ARPOP_InREQUEST                                 8
    7575
    7676/** InARP-Reply operation code.
    7777 */
    78 #define ARPOP_InREPLY           9
     78#define ARPOP_InREPLY                                   9
    7979
    8080/** ARP-NAK operation code.
    8181 */
    82 #define ARPOP_NAK               10
     82#define ARPOP_NAK                                               10
    8383
    8484/** MARS-Request operation code.
    8585 */
    86 #define ARPOP_MARS_Request              11
     86#define ARPOP_MARS_Request                              11
    8787
    8888/** MARS-Multi operation code.
    8989 */
    90 #define ARPOP_MARS_Multi                12
     90#define ARPOP_MARS_Multi                                12
    9191
    9292/** MARS-MServ operation code.
    9393 */
    94 #define ARPOP_MARS_MServ                13
     94#define ARPOP_MARS_MServ                                13
    9595
    9696/** MARS-Join operation code.
    9797 */
    98 #define ARPOP_MARS_Join         14
     98#define ARPOP_MARS_Join                                 14
    9999
    100100/** MARS-Leave operation code.
    101101 */
    102 #define ARPOP_MARS_Leave                15
     102#define ARPOP_MARS_Leave                                15
    103103
    104104/** MARS-NAK operation code.
    105105 */
    106 #define ARPOP_MARS_NAK          16
     106#define ARPOP_MARS_NAK                                  16
    107107
    108108/** MARS-Unserv operation code.
    109109 */
    110 #define ARPOP_MARS_Unserv               17
     110#define ARPOP_MARS_Unserv                               17
    111111
    112112/** MARS-SJoin operation code.
    113113 */
    114 #define ARPOP_MARS_SJoin                18
     114#define ARPOP_MARS_SJoin                                18
    115115
    116116/** MARS-SLeave operation code.
    117117 */
    118 #define ARPOP_MARS_SLeave               19
     118#define ARPOP_MARS_SLeave                               19
    119119
    120120/** MARS-Grouplist-Request operation code.
    121121 */
    122 #define ARPOP_MARS_Grouplist_Request            20
     122#define ARPOP_MARS_Grouplist_Request    20
    123123
    124124/** MARS-Grouplist-Reply operation code.
     
    128128/** MARS-Redirect-Map operation code.
    129129 */
    130 #define ARPOP_MARS_Redirect_Map         22
     130#define ARPOP_MARS_Redirect_Map                 22
    131131
    132132/** MAPOS-UNARP operation code.
    133133 */
    134 #define ARPOP_MAPOS_UNARP               23
     134#define ARPOP_MAPOS_UNARP                               23
    135135
    136136/*@}*/
  • uspace/srv/net/il/arp/arp_remote.c

    r9f2ea28 ra64c64d  
    5252#include "arp_messages.h"
    5353
    54 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
    55         aid_t message_id;
    56         ipcarg_t result;
    57 
    58         message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL);
    59         measured_strings_send(arp_phone, address, 1);
    60         async_wait_for(message_id, &result);
    61         return (int) result;
     54int arp_connect_module(services_t service){
     55        if(service != SERVICE_ARP){
     56                return EINVAL;
     57        }
     58        return connect_to_service(SERVICE_ARP);
    6259}
    6360
    64 int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
    65         return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data);
    66 }
    67 
    68 int arp_clear_device_req(int arp_phone, device_id_t device_id){
    69         return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id);
     61int arp_clean_cache_req(int arp_phone){
     62        return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
    7063}
    7164
     
    8073}
    8174
    82 int arp_clean_cache_req(int arp_phone){
    83         return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
     75int arp_clear_device_req(int arp_phone, device_id_t device_id){
     76        return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id);
    8477}
    8578
    86 int arp_connect_module(services_t service){
    87         if(service != SERVICE_ARP){
    88                 return EINVAL;
    89         }
    90         return connect_to_service(SERVICE_ARP);
     79int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
     80        aid_t message_id;
     81        ipcarg_t result;
     82
     83        message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL);
     84        measured_strings_send(arp_phone, address, 1);
     85        async_wait_for(message_id, &result);
     86        return (int) result;
    9187}
    9288
     
    9591}
    9692
     93int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
     94        return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data);
     95}
     96
    9797/** @}
    9898 */
  • uspace/srv/net/il/il_messages.h

    r9f2ea28 ra64c64d  
    5353         */
    5454        NET_IL_DEVICE_STATE,
     55        /** Device MTU changed message.
     56         *  @see il_mtu_changed_msg()
     57         */
     58        NET_IL_MTU_CHANGED,
     59        /** Packet size message.
     60         *  @see il_packet_size_req()
     61         */
     62        NET_IL_PACKET_SPACE,
    5563        /** Packet received message.
    5664         *  @see il_received_msg()
     
    6068         *  @see il_send_msg()
    6169         */
    62         NET_IL_SEND,
    63         /** Packet size message.
    64          *  @see il_packet_size_req()
    65          */
    66         NET_IL_PACKET_SPACE,
    67         /** Device MTU changed message.
    68          *  @see il_mtu_changed_msg()
    69          */
    70         NET_IL_MTU_CHANGED
     70        NET_IL_SEND
    7171} il_messages;
    7272
     
    8383 *  @param[in] call The message call structure.
    8484 */
    85 #define IL_GET_SERVICE(call)            (services_t) IPC_GET_ARG2(*call)
     85#define IL_GET_SERVICE(call)    (services_t) IPC_GET_ARG2(*call)
    8686
    8787/*@}*/
  • uspace/srv/net/il/ip/ip.h

    r9f2ea28 ra64c64d  
    106106 */
    107107struct  ip_netif{
    108         /** Device identifier.
    109          */
    110         device_id_t device_id;
    111         /** Netif module service.
    112          */
    113         services_t service;
    114         /** Netif module phone.
    115          */
    116         int phone;
    117108        /** ARP module.
    118109         *  Assigned if using ARP.
    119110         */
    120111        module_ref arp;
     112        /** Broadcast address.
     113         */
     114        in_addr_t broadcast;
     115        /** Device identifier.
     116         */
     117        device_id_t device_id;
     118        /** Indicates whether using DHCP.
     119         */
     120        int dhcp;
    121121        /** IP version.
    122122         */
    123123        int ipv;
    124         /** Indicates whether using DHCP.
    125          */
    126         int dhcp;
     124        /** Packet dimension.
     125         */
     126        packet_dimension_t packet_dimension;
     127        /** Netif module phone.
     128         */
     129        int phone;
     130        /** Routing table.
     131         */
     132        ip_routes_t routes;
    127133        /** Indicates whether IP routing is enabled.
    128134         */
    129135        int routing;
     136        /** Netif module service.
     137         */
     138        services_t service;
    130139        /** Device state.
    131140         */
    132141        device_state_t state;
    133         /** Broadcast address.
    134          */
    135         in_addr_t broadcast;
    136         /** Routing table.
    137          */
    138         ip_routes_t routes;
    139         /** Packet dimension.
    140          */
    141         packet_dimension_t packet_dimension;
    142142};
    143143
     
    145145 */
    146146struct ip_proto{
     147        /** Protocol module phone.
     148         */
     149        int phone;
    147150        /** Protocol number.
    148151         */
    149152        int protocol;
     153        /** Protocol packet receiving function.
     154         */
     155        tl_received_msg_t received_msg;
    150156        /** Protocol module service.
    151157         */
    152158        services_t service;
    153         /** Protocol module phone.
    154          */
    155         int phone;
    156         /** Protocol packet receiving function.
    157          */
    158         tl_received_msg_t received_msg;
    159159};
    160160
     
    165165         */
    166166        in_addr_t address;
    167         /** Target network mask.
    168          */
    169         in_addr_t netmask;
    170167        /** Gateway.
    171168         */
     
    174171         */
    175172        ip_netif_ref netif;
     173        /** Target network mask.
     174         */
     175        in_addr_t netmask;
    176176};
    177177
     
    179179 */
    180180struct  ip_globals{
     181        /** Default client connection function for support modules.
     182         */
     183        async_client_conn_t client_connection;
     184        /** Default gateway.
     185         */
     186        ip_route_t gateway;
     187        /** Safety lock.
     188         */
     189        fibril_rwlock_t lock;
     190        /** Known support modules.
     191         */
     192        modules_t modules;
    181193        /** Networking module phone.
    182194         */
     
    188200         */
    189201        fibril_rwlock_t netifs_lock;
     202        /** Packet counter.
     203         */
     204        uint16_t packet_counter;
    190205        /** Registered protocols.
    191206         */
     
    194209         */
    195210        fibril_rwlock_t protos_lock;
    196         /** Default gateway.
    197          */
    198         ip_route_t gateway;
    199         /** Known support modules.
    200          */
    201         modules_t modules;
    202         /** Default client connection function for support modules.
    203          */
    204         async_client_conn_t client_connection;
    205         /** Packet counter.
    206          */
    207         uint16_t packet_counter;
    208         /** Safety lock.
    209          */
    210         fibril_rwlock_t lock;
    211211};
    212212
  • uspace/srv/net/il/ip/ip_client.c

    r9f2ea28 ra64c64d  
    4848#include "ip_header.h"
    4949
    50 int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
    51         ip_header_ref header;
    52         uint8_t * data;
    53         size_t padding;
    54 
    55         padding =  ipopt_length % 4;
    56         if(padding){
    57                 padding = 4 - padding;
    58                 ipopt_length += padding;
    59         }
    60         data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
    61         if(! data){
    62                 return ENOMEM;
    63         }
    64         while(padding --){
    65                 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
    66         }
    67         header = (ip_header_ref) data;
    68         header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
    69         header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
    70         header->tos = tos;
    71         header->protocol = protocol;
    72         if(dont_fragment){
    73                 header->flags = IPFLAG_DONT_FRAGMENT;
    74         }
    75         return EOK;
    76 }
    77 
    78 int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
    79         ip_header_ref header;
    80 
    81         header = (ip_header_ref) packet_get_data(packet);
    82         if((! header)
    83                 || (packet_get_data_length(packet) < sizeof(ip_header_t))){
    84                 return ENOMEM;
    85         }
    86         if(protocol){
    87                 *protocol = header->protocol;
    88         }
    89         if(ttl){
    90                 *ttl = header->ttl;
    91         }
    92         if(tos){
    93                 *tos = header->tos;
    94         }
    95         if(dont_fragment){
    96                 *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
    97         }
    98         if(ipopt_length){
    99                 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
    100                 return sizeof(ip_header_t);
    101         }else{
    102                 return IP_HEADER_LENGTH(header);
    103         }
    104 }
    105 
    10650size_t ip_client_header_length(packet_t packet){
    10751        ip_header_ref header;
     
    11357        }
    11458        return IP_HEADER_LENGTH(header);
    115 }
    116 
    117 int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
    118         ipv4_pseudo_header_ref header_in;
    119 
    120         if(! header){
    121                 return EBADMEM;
    122         }
    123         if(headerlen == sizeof(ipv4_pseudo_header_t)){
    124                 header_in = (ipv4_pseudo_header_ref) header;
    125                 header_in->data_length = htons(data_length);
    126                 return EOK;
    127         }else{
    128                 return EINVAL;
    129         }
    13059}
    13160
     
    14069                return EINVAL;
    14170        }
     71
    14272        switch(src->sa_family){
    14373                case AF_INET:
     
    171101}
    172102
     103int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
     104        ip_header_ref header;
     105        uint8_t * data;
     106        size_t padding;
     107
     108        // compute the padding if IP options are set
     109        // multiple of 4 bytes
     110        padding =  ipopt_length % 4;
     111        if(padding){
     112                padding = 4 - padding;
     113                ipopt_length += padding;
     114        }
     115
     116        // prefix the header
     117        data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
     118        if(! data){
     119                return ENOMEM;
     120        }
     121
     122        // add the padding
     123        while(padding --){
     124                data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
     125        }
     126
     127        // set the header
     128        header = (ip_header_ref) data;
     129        header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
     130        header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
     131        header->tos = tos;
     132        header->protocol = protocol;
     133
     134        if(dont_fragment){
     135                header->flags = IPFLAG_DONT_FRAGMENT;
     136        }
     137        return EOK;
     138}
     139
     140int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
     141        ip_header_ref header;
     142
     143        header = (ip_header_ref) packet_get_data(packet);
     144        if((! header)
     145                || (packet_get_data_length(packet) < sizeof(ip_header_t))){
     146                return ENOMEM;
     147        }
     148
     149        if(protocol){
     150                *protocol = header->protocol;
     151        }
     152        if(ttl){
     153                *ttl = header->ttl;
     154        }
     155        if(tos){
     156                *tos = header->tos;
     157        }
     158        if(dont_fragment){
     159                *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
     160        }
     161        if(ipopt_length){
     162                *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
     163                return sizeof(ip_header_t);
     164        }else{
     165                return IP_HEADER_LENGTH(header);
     166        }
     167}
     168
     169int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
     170        ipv4_pseudo_header_ref header_in;
     171
     172        if(! header){
     173                return EBADMEM;
     174        }
     175
     176        if(headerlen == sizeof(ipv4_pseudo_header_t)){
     177                header_in = (ipv4_pseudo_header_ref) header;
     178                header_in->data_length = htons(data_length);
     179                return EOK;
     180        // TODO IPv6
     181        }else{
     182                return EINVAL;
     183        }
     184}
     185
    173186/** @}
    174187 */
  • uspace/srv/net/il/ip/ip_header.h

    r9f2ea28 ra64c64d  
    4242#include <sys/types.h>
    4343
    44 /** Returns the actual IP header length in bytes.
    45  *  @param[in] header The IP packet header.
    46  */
    47 #define IP_HEADER_LENGTH(header)                ((header)->header_length * 4u)
     44/** Returns the fragment offest high bits.
     45 *  @param[in] length The prefixed data total length.
     46 */
     47#define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ((((length) / 8u) &0x1F00) >> 8)
     48
     49/** Returns the fragment offest low bits.
     50 *  @param[in] length The prefixed data total length.
     51 */
     52#define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF)
    4853
    4954/** Returns the IP header length.
     
    5257#define IP_COMPUTE_HEADER_LENGTH(length)                ((uint8_t) ((length) / 4u))
    5358
     59/** Returns the fragment offest.
     60 *  @param[in] header The IP packet header.
     61 */
     62#define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u)
     63
     64/** Returns the IP packet header checksum.
     65 *  @param[in] header The IP packet header.
     66 */
     67#define IP_HEADER_CHECKSUM(header)      (htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
     68
     69/** Returns the actual IP packet data length.
     70 *  @param[in] header The IP packet header.
     71 */
     72#define IP_HEADER_DATA_LENGTH(header)   (IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
     73
     74/** Returns the actual IP header length in bytes.
     75 *  @param[in] header The IP packet header.
     76 */
     77#define IP_HEADER_LENGTH(header)                ((header)->header_length * 4u)
     78
    5479/** Returns the actual IP packet total length.
    5580 *  @param[in] header The IP packet header.
     
    5782#define IP_TOTAL_LENGTH(header)         ntohs((header)->total_length)
    5883
    59 /** Returns the actual IP packet data length.
    60  *  @param[in] header The IP packet header.
    61  */
    62 #define IP_HEADER_DATA_LENGTH(header)   (IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
    63 
    64 /** Returns the IP packet header checksum.
    65  *  @param[in] header The IP packet header.
    66  */
    67 #define IP_HEADER_CHECKSUM(header)      (htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
    68 
    69 /** Returns the fragment offest.
    70  *  @param[in] header The IP packet header.
    71  */
    72 #define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u)
    73 
    74 /** Returns the fragment offest high bits.
    75  *  @param[in] length The prefixed data total length.
    76  */
    77 #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ((((length) / 8u) &0x1F00) >> 8)
    78 
    79 /** Returns the fragment offest low bits.
    80  *  @param[in] length The prefixed data total length.
    81  */
    82 #define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF)
     84/** @name IP flags definitions
     85 */
     86/*@{*/
     87
     88/** Fragment flag field shift.
     89 */
     90#define IPFLAG_FRAGMENT_SHIFT           1
     91
     92/** Fragmented flag field shift.
     93 */
     94#define IPFLAG_FRAGMENTED_SHIFT         0
     95
     96/** Don't fragment flag value.
     97 *  Permits the packet fragmentation.
     98 */
     99#define IPFLAG_DONT_FRAGMENT            (0x1 << IPFLAG_FRAGMENT_SHIFT)
     100
     101/** Last fragment flag value.
     102 *  Indicates the last packet fragment.
     103 */
     104#define IPFLAG_LAST_FRAGMENT            (0x0 << IPFLAG_FRAGMENTED_SHIFT)
     105
     106/** May fragment flag value.
     107 *  Allows the packet fragmentation.
     108 */
     109#define IPFLAG_MAY_FRAGMENT                     (0x0 << IPFLAG_FRAGMENT_SHIFT)
     110
     111/** More fragments flag value.
     112 *  Indicates that more packet fragments follow.
     113 */
     114#define IPFLAG_MORE_FRAGMENTS           (0x1 << IPFLAG_FRAGMENTED_SHIFT)
     115
     116/*@}*/
    83117
    84118/** Type definition of the internet header.
     
    91125 */
    92126typedef ip_header_t *           ip_header_ref;
     127
     128/** Type definition of the internet option header.
     129 *  @see ip_header
     130 */
     131typedef struct ip_option        ip_option_t;
     132
     133/** Type definition of the internet option header pointer.
     134 *  @see ip_header
     135 */
     136typedef ip_option_t *           ip_option_ref;
     137
     138/** Type definition of the internet version 4 pseudo header.
     139 *  @see ipv4_pseudo_header
     140 */
     141typedef struct ipv4_pseudo_header       ipv4_pseudo_header_t;
     142
     143/** Type definition of the internet version 4 pseudo header pointer.
     144 *  @see ipv4_pseudo_header
     145 */
     146typedef ipv4_pseudo_header_t *          ipv4_pseudo_header_ref;
    93147
    94148/** Internet header.
     
    171225} __attribute__ ((packed));
    172226
    173 /** Type definition of the internet option header.
    174  *  @see ip_header
    175  */
    176 typedef struct ip_option        ip_option_t;
    177 
    178 /** Type definition of the internet option header pointer.
    179  *  @see ip_header
    180  */
    181 typedef ip_option_t *           ip_option_ref;
    182 
    183227/** Internet option header.
    184228 *  Only type field is always valid.
     
    212256} __attribute__ ((packed));
    213257
    214 /** @name IP flags definitions
    215  */
    216 /*@{*/
    217 
    218 /** Fragment flag field shift.
    219  */
    220 #define IPFLAG_FRAGMENT_SHIFT           1
    221 
    222 /** Fragmented flag field shift.
    223  */
    224 #define IPFLAG_FRAGMENTED_SHIFT         0
    225 
    226 /** May fragment flag value.
    227  *  Allows the packet fragmentation.
    228  */
    229 #define IPFLAG_MAY_FRAGMENT                     (0x0 << IPFLAG_FRAGMENT_SHIFT)
    230 
    231 /** Don't fragment flag value.
    232  *  Permits the packet fragmentation.
    233  */
    234 #define IPFLAG_DONT_FRAGMENT            (0x1 << IPFLAG_FRAGMENT_SHIFT)
    235 
    236 /** Last fragment flag value.
    237  *  Indicates the last packet fragment.
    238  */
    239 #define IPFLAG_LAST_FRAGMENT            (0x0 << IPFLAG_FRAGMENTED_SHIFT)
    240 
    241 /** More fragments flag value.
    242  *  Indicates that more packet fragments follow.
    243  */
    244 #define IPFLAG_MORE_FRAGMENTS           (0x1 << IPFLAG_FRAGMENTED_SHIFT)
    245 
    246 /*@}*/
    247 
    248 /** Type definition of the internet version 4 pseudo header.
    249  *  @see ipv4_pseudo_header
    250  */
    251 typedef struct ipv4_pseudo_header       ipv4_pseudo_header_t;
    252 
    253 /** Type definition of the internet version 4 pseudo header pointer.
    254  *  @see ipv4_pseudo_header
    255  */
    256 typedef ipv4_pseudo_header_t *          ipv4_pseudo_header_ref;
    257 
    258258/** Internet version 4 pseudo header.
    259259 */
  • uspace/srv/net/il/ip/ip_messages.h

    r9f2ea28 ra64c64d  
    5151         */
    5252        NET_IP_ADD_ROUTE = NET_IP_FIRST,
    53         /** Sets the default gateway.
    54          *  @see ip_set_default_gateway()
     53        /** Gets the actual route information.
     54         *  @see ip_get_route()
    5555         */
    56         NET_IP_SET_GATEWAY,
     56        NET_IP_GET_ROUTE,
    5757        /** Processes the received error notification.
    5858         *  @see ip_received_error_msg()
    5959         */
    6060        NET_IP_RECEIVED_ERROR,
    61         /** Gets the actual route information.
    62          *  @see ip_get_route()
     61        /** Sets the default gateway.
     62         *  @see ip_set_default_gateway()
    6363         */
    64         NET_IP_GET_ROUTE
     64        NET_IP_SET_GATEWAY
    6565} ip_messages;
    6666
     
    6969/*@{*/
    7070
     71/** Returns the address message parameter.
     72 *  @param[in] call The message call structure.
     73 */
     74#define IP_GET_ADDRESS(call)            ({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;})
     75
    7176/** Returns the gateway message parameter.
    7277 *  @param[in] call The message call structure.
     
    7479#define IP_GET_GATEWAY(call)            ({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;})
    7580
    76 /** Returns the address message parameter.
    77  *  @param[in] call The message call structure.
     81/** Sets the header length in the message answer.
     82 *  @param[out] answer The message answer structure.
    7883 */
    79 #define IP_GET_ADDRESS(call)            ({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;})
     84#define IP_SET_HEADERLEN(answer)        ((size_t *) &IPC_GET_ARG2(*answer))
    8085
    8186/** Returns the network mask message parameter.
     
    8994#define IP_GET_PROTOCOL(call)           ((ip_protocol_t) IPC_GET_ARG1(*call))
    9095
    91 /** Sets the header length in the message answer.
    92  *  @param[out] answer The message answer structure.
    93  */
    94 #define IP_SET_HEADERLEN(answer)        ((size_t *) &IPC_GET_ARG2(*answer))
    95 
    9696/*@}*/
    9797
  • uspace/srv/net/il/ip/ip_module.c

    r9f2ea28 ra64c64d  
    5858#define NAME    "IP protocol"
    5959
     60/** IP module global data.
     61 */
     62extern ip_globals_t     ip_globals;
     63
     64/** Processes the IP message.
     65 *  @param[in] callid The message identifier.
     66 *  @param[in] call The message parameters.
     67 *  @param[out] answer The message answer parameters.
     68 *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
     69 *  @returns EOK on success.
     70 *  @returns Other error codes as defined for the ip_message() function.
     71 */
     72int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     73
    6074/** Prints the module name.
    6175 *  @see NAME
     
    7286int module_start(async_client_conn_t client_connection);
    7387
    74 /** Processes the IP message.
    75  *  @param[in] callid The message identifier.
    76  *  @param[in] call The message parameters.
    77  *  @param[out] answer The message answer parameters.
    78  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    79  *  @returns EOK on success.
    80  *  @returns Other error codes as defined for the ip_message() function.
    81  */
    82 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
    83 
    84 /** IP module global data.
    85  */
    86 extern ip_globals_t     ip_globals;
     88int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     89        return ip_message(callid, call, answer, answer_count);
     90}
    8791
    8892void module_print_name(void){
     
    110114}
    111115
    112 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    113         return ip_message(callid, call, answer, answer_count);
    114 }
    115 
    116116/** @}
    117117 */
  • uspace/srv/net/il/ip/ip_remote.c

    r9f2ea28 ra64c64d  
    5252#include "ip_messages.h"
    5353
    54 int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
    55         return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
     54int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
     55        return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
    5656}
    5757
    58 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
    59         return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error);
     58int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg){
     59        return (int) bind_service(service, (ipcarg_t) protocol, me, service, receiver);
    6060}
    6161
     
    6464}
    6565
    66 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
    67         return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
    68 }
    69 
    70 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
    71         return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
    72 }
    73 
    74 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
    75         return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension);
    76 }
    77 
    78 int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg){
    79         return (int) bind_service(service, (ipcarg_t) protocol, me, service, receiver);
    80 }
    81 
    82 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
    83         return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error);
     66int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
     67        return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
    8468}
    8569
     
    9579                return EBADMEM;
    9680        }
     81
    9782        *header = NULL;
    9883        message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer);
     
    10893        }
    10994        async_wait_for(message_id, &result);
     95
    11096        if((result != EOK) && (*header)){
    11197                free(*header);
     
    116102}
    117103
     104int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
     105        return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension);
     106}
     107
     108int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
     109        return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error);
     110}
     111
     112int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
     113        return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error);
     114}
     115
     116int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
     117        return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
     118}
     119
    118120/** @}
    119121 */
Note: See TracChangeset for help on using the changeset viewer.