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