Changeset a64c64d in mainline for uspace/srv/net/il
- Timestamp:
- 2010-03-09T22:24:31Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74520daf
- Parents:
- 9f2ea28
- Location:
- uspace/srv/net/il
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
r9f2ea28 ra64c64d 73 73 arp_globals_t arp_globals; 74 74 75 /** Clears the device specific data. 76 * @param[in] device The device specific data. 77 */ 78 void arp_clear_device(arp_device_ref device); 79 75 80 /** Creates new protocol specific data. 76 81 * Allocates and returns the needed memory block as the proto parameter. … … 82 87 */ 83 88 int 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);89 89 90 90 /** @name Message processing functions … … 105 105 int arp_device_message(device_id_t device_id, services_t service, services_t protocol, measured_string_ref address); 106 106 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. 109 108 * @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 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 */ 113 int arp_mtu_changed_message(device_id_t device_id, size_t mtu); 119 114 120 115 /** Processes the received ARP packet. … … 133 128 int arp_receive_message(device_id_t device_id, packet_t packet); 134 129 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. 136 132 * @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 request. 139 * @returns NULL if the hardware address is not found in the cache. 140 */ 141 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target); 142 142 143 143 /*@}*/ … … 148 148 149 149 GENERIC_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 }189 150 190 151 int arp_clean_cache_req(int arp_phone){ … … 211 172 } 212 173 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); 174 int 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); 243 182 return ENOENT; 244 183 } 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 194 void 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 213 int arp_clear_device_req(int arp_phone, device_id_t device_id){ 214 arp_device_ref device; 215 251 216 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); 254 224 fibril_rwlock_write_unlock(&arp_globals.lock); 255 225 return EOK; 256 226 } 257 227 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; 228 int arp_connect_module(services_t service){ 229 if(service != SERVICE_ARP){ 230 return EINVAL; 271 231 } 272 232 return EOK; … … 383 343 } 384 344 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){ 345 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){ 444 346 ERROR_DECLARE; 445 347 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 359 int arp_initialize(async_client_conn_t client_connection){ 360 ERROR_DECLARE; 361 362 fibril_rwlock_initialize(&arp_globals.lock); 541 363 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)); 549 366 fibril_rwlock_write_unlock(&arp_globals.lock); 550 367 return EOK; … … 618 435 } 619 436 437 int 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 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){ 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 538 task_id_t arp_task_get_id(void){ 539 return task_get_id(); 540 } 541 542 measured_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 600 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){ 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 620 620 /** @} 621 621 */ -
uspace/srv/net/il/arp/arp.h
r9f2ea28 ra64c64d 51 51 52 52 53 /** Type definition of the ARP global data.54 * @see arp_globals55 */56 typedef struct arp_globals arp_globals_t;57 58 53 /** Type definition of the ARP device specific data. 59 54 * @see arp_device … … 66 61 typedef arp_device_t * arp_device_ref; 67 62 63 /** Type definition of the ARP global data. 64 * @see arp_globals 65 */ 66 typedef struct arp_globals arp_globals_t; 67 68 68 /** Type definition of the ARP protocol specific data. 69 69 * @see arp_proto … … 75 75 */ 76 76 typedef arp_proto_t * arp_proto_ref; 77 78 /** ARP address map. 79 * Translates addresses. 80 * @see generic_char_map.h 81 */ 82 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t) 77 83 78 84 /** ARP address cache. … … 88 94 INT_MAP_DECLARE(arp_protos, arp_proto_t) 89 95 90 /** ARP address map.91 * Translates addresses.92 * @see generic_char_map.h93 */94 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)95 96 96 /** ARP device specific data. 97 97 */ 98 98 struct 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;108 99 /** Actual device hardware address. 109 100 */ … … 118 109 */ 119 110 char * broadcast_data; 120 /** Device module service.111 /** Device identifier. 121 112 */ 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; 123 120 /** Device module phone. 124 121 */ … … 128 125 */ 129 126 arp_protos_t protos; 127 /** Device module service. 128 */ 129 services_t service; 130 }; 131 132 /** ARP global data. 133 */ 134 struct 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; 130 148 }; 131 149 … … 133 151 */ 134 152 struct arp_proto{ 135 /** Protocol service.136 */137 services_t service;138 153 /** Actual device protocol address. 139 154 */ … … 145 160 */ 146 161 arp_addr_t addresses; 147 }; 148 149 /** ARP global data. 150 */ 151 struct arp_globals{ 152 /** Networking module phone. 162 /** Protocol service. 153 163 */ 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; 165 165 }; 166 166 -
uspace/srv/net/il/arp/arp_messages.h
r9f2ea28 ra64c64d 46 46 */ 47 47 typedef enum{ 48 /** New device message.49 * @see arp_ device_req()48 /** Clean cache message. 49 * @see arp_clean_cache() 50 50 */ 51 NET_ARP_ DEVICE = NET_ARP_FIRST,52 /** Address translationmessage.53 * @see arp_ translate_req()51 NET_ARP_CLEAN_CACHE = NET_ARP_FIRST, 52 /** Clear address cache message. 53 * @see arp_clear_address_msg() 54 54 */ 55 NET_ARP_ TRANSLATE,55 NET_ARP_CLEAR_ADDRESS, 56 56 /** Clear device cache message. 57 57 * @see arp_clear_device_req() 58 58 */ 59 59 NET_ARP_CLEAR_DEVICE, 60 /** Clear address cache message.61 * @see arp_ clear_address_msg()60 /** New device message. 61 * @see arp_device_req() 62 62 */ 63 NET_ARP_ CLEAR_ADDRESS,64 /** Clean cachemessage.65 * @see arp_ clean_cache()63 NET_ARP_DEVICE, 64 /** Address translation message. 65 * @see arp_translate_req() 66 66 */ 67 NET_ARP_ CLEAN_CACHE,67 NET_ARP_TRANSLATE 68 68 } arp_messages; 69 69 -
uspace/srv/net/il/arp/arp_module.c
r9f2ea28 ra64c64d 58 58 #define NAME "ARP protocol" 59 59 60 /** ARP module global data. 61 */ 62 extern 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 */ 72 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 73 60 74 /** Prints the module name. 61 75 * @see NAME … … 72 86 int module_start(async_client_conn_t client_connection); 73 87 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; 88 int 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 } 87 91 88 92 void module_print_name(void){ … … 110 114 } 111 115 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 116 116 /** @} 117 117 */ -
uspace/srv/net/il/arp/arp_oc.h
r9f2ea28 ra64c64d 44 44 /** REQUEST operation code. 45 45 */ 46 #define ARPOP_REQUEST 146 #define ARPOP_REQUEST 1 47 47 48 48 /** REPLY operation code. 49 49 */ 50 #define ARPOP_REPLY 250 #define ARPOP_REPLY 2 51 51 52 52 /** Reverse request operation code. 53 53 */ 54 #define ARPOP_RREQUEST 354 #define ARPOP_RREQUEST 3 55 55 56 56 /** Reverse reply operation code. 57 57 */ 58 #define ARPOP_RREPLY 458 #define ARPOP_RREPLY 4 59 59 60 60 /** DRARP-Request operation code. 61 61 */ 62 #define ARPOP_DRARP_Request 562 #define ARPOP_DRARP_Request 5 63 63 64 64 /** DRARP-Reply operation code. 65 65 */ 66 #define ARPOP_DRARP_Reply 666 #define ARPOP_DRARP_Reply 6 67 67 68 68 /** DRARP-Error operation code. 69 69 */ 70 #define ARPOP_DRARP_Error 770 #define ARPOP_DRARP_Error 7 71 71 72 72 /** InARP-Request operation code. 73 73 */ 74 #define ARPOP_InREQUEST 874 #define ARPOP_InREQUEST 8 75 75 76 76 /** InARP-Reply operation code. 77 77 */ 78 #define ARPOP_InREPLY 978 #define ARPOP_InREPLY 9 79 79 80 80 /** ARP-NAK operation code. 81 81 */ 82 #define ARPOP_NAK 1082 #define ARPOP_NAK 10 83 83 84 84 /** MARS-Request operation code. 85 85 */ 86 #define ARPOP_MARS_Request 1186 #define ARPOP_MARS_Request 11 87 87 88 88 /** MARS-Multi operation code. 89 89 */ 90 #define ARPOP_MARS_Multi 1290 #define ARPOP_MARS_Multi 12 91 91 92 92 /** MARS-MServ operation code. 93 93 */ 94 #define ARPOP_MARS_MServ 1394 #define ARPOP_MARS_MServ 13 95 95 96 96 /** MARS-Join operation code. 97 97 */ 98 #define ARPOP_MARS_Join 1498 #define ARPOP_MARS_Join 14 99 99 100 100 /** MARS-Leave operation code. 101 101 */ 102 #define ARPOP_MARS_Leave 15102 #define ARPOP_MARS_Leave 15 103 103 104 104 /** MARS-NAK operation code. 105 105 */ 106 #define ARPOP_MARS_NAK 16106 #define ARPOP_MARS_NAK 16 107 107 108 108 /** MARS-Unserv operation code. 109 109 */ 110 #define ARPOP_MARS_Unserv 17110 #define ARPOP_MARS_Unserv 17 111 111 112 112 /** MARS-SJoin operation code. 113 113 */ 114 #define ARPOP_MARS_SJoin 18114 #define ARPOP_MARS_SJoin 18 115 115 116 116 /** MARS-SLeave operation code. 117 117 */ 118 #define ARPOP_MARS_SLeave 19118 #define ARPOP_MARS_SLeave 19 119 119 120 120 /** MARS-Grouplist-Request operation code. 121 121 */ 122 #define ARPOP_MARS_Grouplist_Request 122 #define ARPOP_MARS_Grouplist_Request 20 123 123 124 124 /** MARS-Grouplist-Reply operation code. … … 128 128 /** MARS-Redirect-Map operation code. 129 129 */ 130 #define ARPOP_MARS_Redirect_Map 22130 #define ARPOP_MARS_Redirect_Map 22 131 131 132 132 /** MAPOS-UNARP operation code. 133 133 */ 134 #define ARPOP_MAPOS_UNARP 23134 #define ARPOP_MAPOS_UNARP 23 135 135 136 136 /*@}*/ -
uspace/srv/net/il/arp/arp_remote.c
r9f2ea28 ra64c64d 52 52 #include "arp_messages.h" 53 53 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; 54 int arp_connect_module(services_t service){ 55 if(service != SERVICE_ARP){ 56 return EINVAL; 57 } 58 return connect_to_service(SERVICE_ARP); 62 59 } 63 60 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); 61 int arp_clean_cache_req(int arp_phone){ 62 return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE); 70 63 } 71 64 … … 80 73 } 81 74 82 int arp_clea n_cache_req(int arp_phone){83 return (int) async_req_ 0_0(arp_phone, NET_ARP_CLEAN_CACHE);75 int 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); 84 77 } 85 78 86 int arp_connect_module(services_t service){ 87 if(service != SERVICE_ARP){ 88 return EINVAL; 89 } 90 return connect_to_service(SERVICE_ARP); 79 int 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; 91 87 } 92 88 … … 95 91 } 96 92 93 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){ 94 return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data); 95 } 96 97 97 /** @} 98 98 */ -
uspace/srv/net/il/il_messages.h
r9f2ea28 ra64c64d 53 53 */ 54 54 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, 55 63 /** Packet received message. 56 64 * @see il_received_msg() … … 60 68 * @see il_send_msg() 61 69 */ 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 71 71 } il_messages; 72 72 … … 83 83 * @param[in] call The message call structure. 84 84 */ 85 #define IL_GET_SERVICE(call) 85 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call) 86 86 87 87 /*@}*/ -
uspace/srv/net/il/ip/ip.h
r9f2ea28 ra64c64d 106 106 */ 107 107 struct 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;117 108 /** ARP module. 118 109 * Assigned if using ARP. 119 110 */ 120 111 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; 121 121 /** IP version. 122 122 */ 123 123 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; 127 133 /** Indicates whether IP routing is enabled. 128 134 */ 129 135 int routing; 136 /** Netif module service. 137 */ 138 services_t service; 130 139 /** Device state. 131 140 */ 132 141 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;142 142 }; 143 143 … … 145 145 */ 146 146 struct ip_proto{ 147 /** Protocol module phone. 148 */ 149 int phone; 147 150 /** Protocol number. 148 151 */ 149 152 int protocol; 153 /** Protocol packet receiving function. 154 */ 155 tl_received_msg_t received_msg; 150 156 /** Protocol module service. 151 157 */ 152 158 services_t service; 153 /** Protocol module phone.154 */155 int phone;156 /** Protocol packet receiving function.157 */158 tl_received_msg_t received_msg;159 159 }; 160 160 … … 165 165 */ 166 166 in_addr_t address; 167 /** Target network mask.168 */169 in_addr_t netmask;170 167 /** Gateway. 171 168 */ … … 174 171 */ 175 172 ip_netif_ref netif; 173 /** Target network mask. 174 */ 175 in_addr_t netmask; 176 176 }; 177 177 … … 179 179 */ 180 180 struct 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; 181 193 /** Networking module phone. 182 194 */ … … 188 200 */ 189 201 fibril_rwlock_t netifs_lock; 202 /** Packet counter. 203 */ 204 uint16_t packet_counter; 190 205 /** Registered protocols. 191 206 */ … … 194 209 */ 195 210 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;211 211 }; 212 212 -
uspace/srv/net/il/ip/ip_client.c
r9f2ea28 ra64c64d 48 48 #include "ip_header.h" 49 49 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 106 50 size_t ip_client_header_length(packet_t packet){ 107 51 ip_header_ref header; … … 113 57 } 114 58 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 }130 59 } 131 60 … … 140 69 return EINVAL; 141 70 } 71 142 72 switch(src->sa_family){ 143 73 case AF_INET: … … 171 101 } 172 102 103 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){ 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 140 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){ 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 169 int 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 173 186 /** @} 174 187 */ -
uspace/srv/net/il/ip/ip_header.h
r9f2ea28 ra64c64d 42 42 #include <sys/types.h> 43 43 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) 48 53 49 54 /** Returns the IP header length. … … 52 57 #define IP_COMPUTE_HEADER_LENGTH(length) ((uint8_t) ((length) / 4u)) 53 58 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 54 79 /** Returns the actual IP packet total length. 55 80 * @param[in] header The IP packet header. … … 57 82 #define IP_TOTAL_LENGTH(header) ntohs((header)->total_length) 58 83 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 /*@}*/ 83 117 84 118 /** Type definition of the internet header. … … 91 125 */ 92 126 typedef ip_header_t * ip_header_ref; 127 128 /** Type definition of the internet option header. 129 * @see ip_header 130 */ 131 typedef struct ip_option ip_option_t; 132 133 /** Type definition of the internet option header pointer. 134 * @see ip_header 135 */ 136 typedef ip_option_t * ip_option_ref; 137 138 /** Type definition of the internet version 4 pseudo header. 139 * @see ipv4_pseudo_header 140 */ 141 typedef 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 */ 146 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref; 93 147 94 148 /** Internet header. … … 171 225 } __attribute__ ((packed)); 172 226 173 /** Type definition of the internet option header.174 * @see ip_header175 */176 typedef struct ip_option ip_option_t;177 178 /** Type definition of the internet option header pointer.179 * @see ip_header180 */181 typedef ip_option_t * ip_option_ref;182 183 227 /** Internet option header. 184 228 * Only type field is always valid. … … 212 256 } __attribute__ ((packed)); 213 257 214 /** @name IP flags definitions215 */216 /*@{*/217 218 /** Fragment flag field shift.219 */220 #define IPFLAG_FRAGMENT_SHIFT 1221 222 /** Fragmented flag field shift.223 */224 #define IPFLAG_FRAGMENTED_SHIFT 0225 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_header250 */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_header255 */256 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref;257 258 258 /** Internet version 4 pseudo header. 259 259 */ -
uspace/srv/net/il/ip/ip_messages.h
r9f2ea28 ra64c64d 51 51 */ 52 52 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() 55 55 */ 56 NET_IP_ SET_GATEWAY,56 NET_IP_GET_ROUTE, 57 57 /** Processes the received error notification. 58 58 * @see ip_received_error_msg() 59 59 */ 60 60 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() 63 63 */ 64 NET_IP_ GET_ROUTE64 NET_IP_SET_GATEWAY 65 65 } ip_messages; 66 66 … … 69 69 /*@{*/ 70 70 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 71 76 /** Returns the gateway message parameter. 72 77 * @param[in] call The message call structure. … … 74 79 #define IP_GET_GATEWAY(call) ({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;}) 75 80 76 /** Returns the address message parameter.77 * @param[ in] call The message callstructure.81 /** Sets the header length in the message answer. 82 * @param[out] answer The message answer structure. 78 83 */ 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)) 80 85 81 86 /** Returns the network mask message parameter. … … 89 94 #define IP_GET_PROTOCOL(call) ((ip_protocol_t) IPC_GET_ARG1(*call)) 90 95 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 96 96 /*@}*/ 97 97 -
uspace/srv/net/il/ip/ip_module.c
r9f2ea28 ra64c64d 58 58 #define NAME "IP protocol" 59 59 60 /** IP module global data. 61 */ 62 extern 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 */ 72 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 73 60 74 /** Prints the module name. 61 75 * @see NAME … … 72 86 int module_start(async_client_conn_t client_connection); 73 87 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; 88 int 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 } 87 91 88 92 void module_print_name(void){ … … 110 114 } 111 115 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 116 116 /** @} 117 117 */ -
uspace/srv/net/il/ip/ip_remote.c
r9f2ea28 ra64c64d 52 52 #include "ip_messages.h" 53 53 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);54 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){ 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); 56 56 } 57 57 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);58 int 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); 60 60 } 61 61 … … 64 64 } 65 65 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); 66 int 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); 84 68 } 85 69 … … 95 79 return EBADMEM; 96 80 } 81 97 82 *header = NULL; 98 83 message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer); … … 108 93 } 109 94 async_wait_for(message_id, &result); 95 110 96 if((result != EOK) && (*header)){ 111 97 free(*header); … … 116 102 } 117 103 104 int 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 108 int 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 112 int 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 116 int 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 118 120 /** @} 119 121 */
Note:
See TracChangeset
for help on using the changeset viewer.