Changes in uspace/srv/net/il/arp/arp.c [609243f4:6b82009] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
r609243f4 r6b82009 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,187 services_t protocol,measured_string_t *address)192 static int arp_clear_address_req(device_id_t device_id, services_t protocol, 193 measured_string_t *address) 188 194 { 189 195 fibril_mutex_lock(&arp_globals.lock); … … 212 218 } 213 219 214 static int arp_clear_device_req( nic_device_id_t device_id)220 static int arp_clear_device_req(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, … … 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); … … 403 409 printf("%s: Device %d changed MTU to %zu\n", NAME, device_id, mtu); 404 410 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);437 411 return EOK; 438 412 } … … 482 456 async_answer_0(iid, (sysarg_t) rc); 483 457 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 458 488 459 default: … … 512 483 * 513 484 */ 514 static int arp_device_message( nic_device_id_t device_id, services_t service,485 static int arp_device_message(device_id_t device_id, services_t service, 515 486 services_t protocol, measured_string_t *address) 516 487 { … … 615 586 616 587 /* 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) {588 rc = nil_get_addr_req(device->sess, device_id, &device->addr, 589 &device->addr_data); 590 if (rc != EOK) { 620 591 fibril_mutex_unlock(&arp_globals.lock); 621 592 arp_protos_destroy(&device->protos, free); 622 593 free(device); 623 return len; 624 } 625 626 device->addr_len = len; 594 return rc; 595 } 627 596 628 597 /* 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); 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); 633 604 arp_protos_destroy(&device->protos, free); 634 605 free(device); 635 return len; 636 } 637 638 device->broadcast_addr_len = len; 606 return rc; 607 } 639 608 640 609 rc = arp_cache_add(&arp_globals.cache, device->device_id, … … 642 611 if (rc != EOK) { 643 612 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); 644 617 arp_protos_destroy(&device->protos, free); 645 618 free(device); … … 667 640 } 668 641 669 static int arp_send_request( nic_device_id_t device_id, services_t protocol,642 static int arp_send_request(device_id_t device_id, services_t protocol, 670 643 measured_string_t *target, arp_device_t *device, arp_proto_t *proto) 671 644 { 672 645 /* ARP packet content size = header + (address + translation) * 2 */ 673 size_t length = 8 + 2 * (proto->addr->length + device->addr _len);646 size_t length = 8 + 2 * (proto->addr->length + device->addr->length); 674 647 if (length > device->packet_dimension.content) 675 648 return ELIMIT; … … 688 661 689 662 header->hardware = htons(device->hardware); 690 header->hardware_length = (uint8_t) device->addr _len;663 header->hardware_length = (uint8_t) device->addr->length; 691 664 header->protocol = htons(protocol_map(device->service, protocol)); 692 665 header->protocol_length = (uint8_t) proto->addr->length; … … 694 667 695 668 length = sizeof(arp_header_t); 696 memcpy(((uint8_t *) header) + length, device->addr, 697 device->addr_len); 698 length += device->addr_len; 669 670 memcpy(((uint8_t *) header) + length, device->addr->value, 671 device->addr->length); 672 length += device->addr->length; 699 673 memcpy(((uint8_t *) header) + length, proto->addr->value, 700 674 proto->addr->length); 701 675 length += proto->addr->length; 702 bzero(((uint8_t *) header) + length, device->addr _len);703 length += device->addr _len;676 bzero(((uint8_t *) header) + length, device->addr->length); 677 length += device->addr->length; 704 678 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);679 680 int rc = packet_set_addr(packet, (uint8_t *) device->addr->value, 681 (uint8_t *) device->broadcast_addr->value, device->addr->length); 708 682 if (rc != EOK) { 709 683 pq_release_remote(arp_globals.net_sess, packet_get_id(packet)); … … 730 704 * 731 705 */ 732 static int arp_translate_message( nic_device_id_t device_id, services_t protocol,706 static int arp_translate_message(device_id_t device_id, services_t protocol, 733 707 measured_string_t *target, measured_string_t **translation) 734 708 {
Note:
See TracChangeset
for help on using the changeset viewer.