Changes in uspace/srv/net/il/arp/arp.c [5fe7692:609243f4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
r5fe7692 r609243f4 164 164 } 165 165 166 static int arp_clean_cache_req( int arp_phone)166 static int arp_clean_cache_req(void) 167 167 { 168 168 int count; … … 174 174 count); 175 175 176 if (device) {176 if (device) 177 177 arp_clear_device(device); 178 if (device->addr_data)179 free(device->addr_data);180 181 if (device->broadcast_data)182 free(device->broadcast_data);183 }184 178 } 185 179 … … 190 184 } 191 185 192 static int arp_clear_address_req( int arp_phone,device_id_t device_id,186 static int arp_clear_address_req(nic_device_id_t device_id, 193 187 services_t protocol, measured_string_t *address) 194 188 { … … 218 212 } 219 213 220 static int arp_clear_device_req( int arp_phone,device_id_t device_id)214 static int arp_clear_device_req(nic_device_id_t device_id) 221 215 { 222 216 fibril_mutex_lock(&arp_globals.lock); … … 289 283 * 290 284 */ 291 static int arp_receive_message( device_id_t device_id, packet_t *packet)285 static int arp_receive_message(nic_device_id_t device_id, packet_t *packet) 292 286 { 293 287 int rc; … … 365 359 memcpy(src_proto, proto->addr->value, 366 360 header->protocol_length); 367 memcpy(src_hw, device->addr ->value,361 memcpy(src_hw, device->addr, 368 362 device->packet_dimension.addr_len); 369 363 memcpy(des_hw, trans->hw_addr->value, … … 375 369 return rc; 376 370 377 nil_send_msg(device-> phone, device_id, packet,371 nil_send_msg(device->sess, device_id, packet, 378 372 SERVICE_ARP); 379 373 return 1; … … 393 387 * 394 388 */ 395 static int arp_mtu_changed_message( device_id_t device_id, size_t mtu)389 static int arp_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 396 390 { 397 391 fibril_mutex_lock(&arp_globals.lock); … … 412 406 } 413 407 408 static int arp_addr_changed_message(nic_device_id_t device_id) 409 { 410 uint8_t addr_buffer[NIC_MAX_ADDRESS_LENGTH]; 411 size_t length; 412 ipc_callid_t data_callid; 413 if (!async_data_write_receive(&data_callid, &length)) { 414 async_answer_0(data_callid, EINVAL); 415 return EINVAL; 416 } 417 if (length > NIC_MAX_ADDRESS_LENGTH) { 418 async_answer_0(data_callid, ELIMIT); 419 return ELIMIT; 420 } 421 if (async_data_write_finalize(data_callid, addr_buffer, length) != EOK) { 422 return EINVAL; 423 } 424 425 fibril_mutex_lock(&arp_globals.lock); 426 427 arp_device_t *device = arp_cache_find(&arp_globals.cache, device_id); 428 if (!device) { 429 fibril_mutex_unlock(&arp_globals.lock); 430 return ENOENT; 431 } 432 433 memcpy(device->addr, addr_buffer, length); 434 device->addr_len = length; 435 436 fibril_mutex_unlock(&arp_globals.lock); 437 return EOK; 438 } 439 414 440 /** Process IPC messages from the registered device driver modules 415 441 * 416 442 * @param[in] iid Message identifier. 417 443 * @param[in,out] icall Message parameters. 418 * 419 */ 420 static void arp_receiver(ipc_callid_t iid, ipc_call_t *icall) 444 * @param[in] arg Local argument. 445 * 446 */ 447 static void arp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 421 448 { 422 449 packet_t *packet; … … 431 458 432 459 case NET_IL_RECEIVED: 433 rc = packet_translate_remote(arp_globals.net_ phone, &packet,460 rc = packet_translate_remote(arp_globals.net_sess, &packet, 434 461 IPC_GET_PACKET(*icall)); 435 462 if (rc == EOK) { … … 439 466 rc = arp_receive_message(IPC_GET_DEVICE(*icall), packet); 440 467 if (rc != 1) { 441 pq_release_remote(arp_globals.net_ phone,468 pq_release_remote(arp_globals.net_sess, 442 469 packet_get_id(packet)); 443 470 } … … 455 482 async_answer_0(iid, (sysarg_t) rc); 456 483 break; 484 case NET_IL_ADDR_CHANGED: 485 rc = arp_addr_changed_message(IPC_GET_DEVICE(*icall)); 486 async_answer_0(iid, (sysarg_t) rc); 457 487 458 488 default: … … 482 512 * 483 513 */ 484 static int arp_device_message( device_id_t device_id, services_t service,514 static int arp_device_message(nic_device_id_t device_id, services_t service, 485 515 services_t protocol, measured_string_t *address) 486 516 { … … 564 594 565 595 /* Bind */ 566 device-> phone= nil_bind_service(device->service,596 device->sess = nil_bind_service(device->service, 567 597 (sysarg_t) device->device_id, SERVICE_ARP, 568 598 arp_receiver); 569 if (device-> phone < 0) {599 if (device->sess == NULL) { 570 600 fibril_mutex_unlock(&arp_globals.lock); 571 601 arp_protos_destroy(&device->protos, free); … … 575 605 576 606 /* Get packet dimensions */ 577 rc = nil_packet_size_req(device-> phone, device_id,607 rc = nil_packet_size_req(device->sess, device_id, 578 608 &device->packet_dimension); 579 609 if (rc != EOK) { … … 585 615 586 616 /* Get hardware address */ 587 rc = nil_get_addr_req(device->phone, device_id, &device->addr, 588 &device->addr_data); 617 int len = nil_get_addr_req(device->sess, device_id, device->addr, 618 NIC_MAX_ADDRESS_LENGTH); 619 if (len < 0) { 620 fibril_mutex_unlock(&arp_globals.lock); 621 arp_protos_destroy(&device->protos, free); 622 free(device); 623 return len; 624 } 625 626 device->addr_len = len; 627 628 /* Get broadcast address */ 629 len = nil_get_broadcast_addr_req(device->sess, device_id, 630 device->broadcast_addr, NIC_MAX_ADDRESS_LENGTH); 631 if (len < 0) { 632 fibril_mutex_unlock(&arp_globals.lock); 633 arp_protos_destroy(&device->protos, free); 634 free(device); 635 return len; 636 } 637 638 device->broadcast_addr_len = len; 639 640 rc = arp_cache_add(&arp_globals.cache, device->device_id, 641 device); 589 642 if (rc != EOK) { 590 643 fibril_mutex_unlock(&arp_globals.lock); … … 593 646 return rc; 594 647 } 595 596 /* Get broadcast address */597 rc = nil_get_broadcast_addr_req(device->phone, device_id,598 &device->broadcast_addr, &device->broadcast_data);599 if (rc != EOK) {600 fibril_mutex_unlock(&arp_globals.lock);601 free(device->addr);602 free(device->addr_data);603 arp_protos_destroy(&device->protos, free);604 free(device);605 return rc;606 }607 608 rc = arp_cache_add(&arp_globals.cache, device->device_id,609 device);610 if (rc != EOK) {611 fibril_mutex_unlock(&arp_globals.lock);612 free(device->addr);613 free(device->addr_data);614 free(device->broadcast_addr);615 free(device->broadcast_data);616 arp_protos_destroy(&device->protos, free);617 free(device);618 return rc;619 }620 648 printf("%s: Device registered (id: %d, type: 0x%x, service: %d," 621 649 " proto: %d)\n", NAME, device->device_id, device->hardware, … … 627 655 } 628 656 629 int il_initialize( int net_phone)657 int il_initialize(async_sess_t *net_sess) 630 658 { 631 659 fibril_mutex_initialize(&arp_globals.lock); 632 660 633 661 fibril_mutex_lock(&arp_globals.lock); 634 arp_globals.net_ phone = net_phone;662 arp_globals.net_sess = net_sess; 635 663 int rc = arp_cache_initialize(&arp_globals.cache); 636 664 fibril_mutex_unlock(&arp_globals.lock); … … 639 667 } 640 668 641 static int arp_send_request( device_id_t device_id, services_t protocol,669 static int arp_send_request(nic_device_id_t device_id, services_t protocol, 642 670 measured_string_t *target, arp_device_t *device, arp_proto_t *proto) 643 671 { 644 672 /* ARP packet content size = header + (address + translation) * 2 */ 645 size_t length = 8 + 2 * (proto->addr->length + device->addr ->length);673 size_t length = 8 + 2 * (proto->addr->length + device->addr_len); 646 674 if (length > device->packet_dimension.content) 647 675 return ELIMIT; 648 676 649 packet_t *packet = packet_get_4_remote(arp_globals.net_ phone,677 packet_t *packet = packet_get_4_remote(arp_globals.net_sess, 650 678 device->packet_dimension.addr_len, device->packet_dimension.prefix, 651 679 length, device->packet_dimension.suffix); … … 655 683 arp_header_t *header = (arp_header_t *) packet_suffix(packet, length); 656 684 if (!header) { 657 pq_release_remote(arp_globals.net_ phone, packet_get_id(packet));685 pq_release_remote(arp_globals.net_sess, packet_get_id(packet)); 658 686 return ENOMEM; 659 687 } 660 688 661 689 header->hardware = htons(device->hardware); 662 header->hardware_length = (uint8_t) device->addr ->length;690 header->hardware_length = (uint8_t) device->addr_len; 663 691 header->protocol = htons(protocol_map(device->service, protocol)); 664 692 header->protocol_length = (uint8_t) proto->addr->length; … … 666 694 667 695 length = sizeof(arp_header_t); 668 669 memcpy(((uint8_t *) header) + length, device->addr->value, 670 device->addr->length); 671 length += device->addr->length; 696 memcpy(((uint8_t *) header) + length, device->addr, 697 device->addr_len); 698 length += device->addr_len; 672 699 memcpy(((uint8_t *) header) + length, proto->addr->value, 673 700 proto->addr->length); 674 701 length += proto->addr->length; 675 bzero(((uint8_t *) header) + length, device->addr ->length);676 length += device->addr ->length;702 bzero(((uint8_t *) header) + length, device->addr_len); 703 length += device->addr_len; 677 704 memcpy(((uint8_t *) header) + length, target->value, target->length); 678 679 int rc = packet_set_addr(packet, (uint8_t *) device->addr->value,680 (uint8_t *) device->broadcast_addr->value, device->addr->length);705 706 int rc = packet_set_addr(packet, device->addr, device->broadcast_addr, 707 device->addr_len); 681 708 if (rc != EOK) { 682 pq_release_remote(arp_globals.net_ phone, packet_get_id(packet));709 pq_release_remote(arp_globals.net_sess, packet_get_id(packet)); 683 710 return rc; 684 711 } 685 712 686 nil_send_msg(device-> phone, device_id, packet, SERVICE_ARP);713 nil_send_msg(device->sess, device_id, packet, SERVICE_ARP); 687 714 return EOK; 688 715 } … … 703 730 * 704 731 */ 705 static int arp_translate_message( device_id_t device_id, services_t protocol,732 static int arp_translate_message(nic_device_id_t device_id, services_t protocol, 706 733 measured_string_t *target, measured_string_t **translation) 707 734 { … … 845 872 846 873 *count = 0; 874 875 if (!IPC_GET_IMETHOD(*call)) 876 return EOK; 877 847 878 switch (IPC_GET_IMETHOD(*call)) { 848 case IPC_M_PHONE_HUNGUP:849 return EOK;850 851 879 case NET_ARP_DEVICE: 852 880 rc = measured_strings_receive(&address, &data, 1); … … 889 917 890 918 case NET_ARP_CLEAR_DEVICE: 891 return arp_clear_device_req( 0,IPC_GET_DEVICE(*call));919 return arp_clear_device_req(IPC_GET_DEVICE(*call)); 892 920 893 921 case NET_ARP_CLEAR_ADDRESS: … … 896 924 return rc; 897 925 898 arp_clear_address_req( 0,IPC_GET_DEVICE(*call),926 arp_clear_address_req(IPC_GET_DEVICE(*call), 899 927 IPC_GET_SERVICE(*call), address); 900 928 free(address); … … 903 931 904 932 case NET_ARP_CLEAN_CACHE: 905 return arp_clean_cache_req( 0);933 return arp_clean_cache_req(); 906 934 } 907 935
Note:
See TracChangeset
for help on using the changeset viewer.