Changeset 7a68fe5 in mainline for uspace/srv/net/il/arp/arp.c
- Timestamp:
- 2011-10-10T06:58:55Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2ea6392
- Parents:
- e68c834 (diff), 80099c19 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
re68c834 r7a68fe5 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( device_id_t device_id, services_t protocol,193 measured_string_t *address)186 static int arp_clear_address_req(nic_device_id_t device_id, 187 services_t protocol, measured_string_t *address) 194 188 { 195 189 fibril_mutex_lock(&arp_globals.lock); … … 218 212 } 219 213 220 static int arp_clear_device_req( 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, … … 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); … … 409 403 printf("%s: Device %d changed MTU to %zu\n", NAME, device_id, mtu); 410 404 405 return EOK; 406 } 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); 411 437 return EOK; 412 438 } … … 456 482 async_answer_0(iid, (sysarg_t) rc); 457 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); 458 487 459 488 default: … … 483 512 * 484 513 */ 485 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, 486 515 services_t protocol, measured_string_t *address) 487 516 { … … 586 615 587 616 /* Get hardware address */ 588 rc = nil_get_addr_req(device->sess, device_id, &device->addr,589 &device->addr_data);590 if ( rc != EOK) {617 int len = nil_get_addr_req(device->sess, device_id, device->addr, 618 NIC_MAX_ADDRESS_LENGTH); 619 if (len < 0) { 591 620 fibril_mutex_unlock(&arp_globals.lock); 592 621 arp_protos_destroy(&device->protos, free); 593 622 free(device); 594 return rc; 595 } 623 return len; 624 } 625 626 device->addr_len = len; 596 627 597 628 /* Get broadcast address */ 598 rc = nil_get_broadcast_addr_req(device->sess, device_id, 599 &device->broadcast_addr, &device->broadcast_data); 600 if (rc != EOK) { 601 fibril_mutex_unlock(&arp_globals.lock); 602 free(device->addr); 603 free(device->addr_data); 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); 604 633 arp_protos_destroy(&device->protos, free); 605 634 free(device); 606 return rc; 607 } 635 return len; 636 } 637 638 device->broadcast_addr_len = len; 608 639 609 640 rc = arp_cache_add(&arp_globals.cache, device->device_id, … … 611 642 if (rc != EOK) { 612 643 fibril_mutex_unlock(&arp_globals.lock); 613 free(device->addr);614 free(device->addr_data);615 free(device->broadcast_addr);616 free(device->broadcast_data);617 644 arp_protos_destroy(&device->protos, free); 618 645 free(device); … … 640 667 } 641 668 642 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, 643 670 measured_string_t *target, arp_device_t *device, arp_proto_t *proto) 644 671 { 645 672 /* ARP packet content size = header + (address + translation) * 2 */ 646 size_t length = 8 + 2 * (proto->addr->length + device->addr ->length);673 size_t length = 8 + 2 * (proto->addr->length + device->addr_len); 647 674 if (length > device->packet_dimension.content) 648 675 return ELIMIT; … … 661 688 662 689 header->hardware = htons(device->hardware); 663 header->hardware_length = (uint8_t) device->addr ->length;690 header->hardware_length = (uint8_t) device->addr_len; 664 691 header->protocol = htons(protocol_map(device->service, protocol)); 665 692 header->protocol_length = (uint8_t) proto->addr->length; … … 667 694 668 695 length = sizeof(arp_header_t); 669 670 memcpy(((uint8_t *) header) + length, device->addr->value, 671 device->addr->length); 672 length += device->addr->length; 696 memcpy(((uint8_t *) header) + length, device->addr, 697 device->addr_len); 698 length += device->addr_len; 673 699 memcpy(((uint8_t *) header) + length, proto->addr->value, 674 700 proto->addr->length); 675 701 length += proto->addr->length; 676 bzero(((uint8_t *) header) + length, device->addr ->length);677 length += device->addr ->length;702 bzero(((uint8_t *) header) + length, device->addr_len); 703 length += device->addr_len; 678 704 memcpy(((uint8_t *) header) + length, target->value, target->length); 679 680 int rc = packet_set_addr(packet, (uint8_t *) device->addr->value,681 (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); 682 708 if (rc != EOK) { 683 709 pq_release_remote(arp_globals.net_sess, packet_get_id(packet)); … … 704 730 * 705 731 */ 706 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, 707 733 measured_string_t *target, measured_string_t **translation) 708 734 {
Note:
See TracChangeset
for help on using the changeset viewer.