Changeset 609243f4 in mainline for uspace/srv/net/il
- Timestamp:
- 2011-10-07T15:46:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e2c50e1
- Parents:
- f51b1d3
- Location:
- uspace/srv/net/il
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
rf51b1d3 r609243f4 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 { -
uspace/srv/net/il/arp/arp.h
rf51b1d3 r609243f4 92 92 struct arp_device { 93 93 /** Actual device hardware address. */ 94 measured_string_t *addr;95 /** Actual device hardware address data. */96 uint8_t *addr_data;94 uint8_t addr[NIC_MAX_ADDRESS_LENGTH]; 95 /** Actual device hardware address length. */ 96 size_t addr_len; 97 97 /** Broadcast device hardware address. */ 98 measured_string_t *broadcast_addr;99 /** Broadcast device hardware address data. */100 uint8_t *broadcast_data;98 uint8_t broadcast_addr[NIC_MAX_ADDRESS_LENGTH]; 99 /** Broadcast device hardware address length. */ 100 size_t broadcast_addr_len; 101 101 /** Device identifier. */ 102 device_id_t device_id;102 nic_device_id_t device_id; 103 103 /** Hardware type. */ 104 104 hw_type_t hardware; -
uspace/srv/net/il/ip/ip.c
rf51b1d3 r609243f4 482 482 } 483 483 484 static int ip_device_req_local( device_id_t device_id, services_t netif)484 static int ip_device_req_local(nic_device_id_t device_id, services_t netif) 485 485 { 486 486 ip_netif_t *ip_netif; … … 501 501 ip_netif->device_id = device_id; 502 502 ip_netif->service = netif; 503 ip_netif->state = N ETIF_STOPPED;503 ip_netif->state = NIC_STATE_STOPPED; 504 504 505 505 fibril_rwlock_write_lock(&ip_globals.netifs_lock); … … 594 594 while (index >= 0) { 595 595 netif = ip_netifs_get_index(&ip_globals.netifs, index); 596 if (netif && (netif->state == N ETIF_ACTIVE)) {596 if (netif && (netif->state == NIC_STATE_ACTIVE)) { 597 597 route = ip_netif_find_route(netif, destination); 598 598 if (route) … … 1142 1142 } 1143 1143 1144 static int ip_send_msg_local( device_id_t device_id, packet_t *packet,1144 static int ip_send_msg_local(nic_device_id_t device_id, packet_t *packet, 1145 1145 services_t sender, services_t error) 1146 1146 { … … 1258 1258 * @return ENOENT if device is not found. 1259 1259 */ 1260 static int ip_device_state_message(device_id_t device_id, device_state_t state) 1260 static int ip_device_state_message(nic_device_id_t device_id, 1261 nic_device_state_t state) 1261 1262 { 1262 1263 ip_netif_t *netif; … … 1272 1273 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 1273 1274 1274 printf("%s: Device %d changed state to %d\n", NAME, device_id, state); 1275 printf("%s: Device %d changed state to '%s'\n", NAME, device_id, 1276 nic_device_state_to_string(state)); 1275 1277 1276 1278 return EOK; … … 1312 1314 * tl_received_msg() function. 1313 1315 */ 1314 static int ip_deliver_local( device_id_t device_id, packet_t *packet,1316 static int ip_deliver_local(nic_device_id_t device_id, packet_t *packet, 1315 1317 ip_header_t *header, services_t error) 1316 1318 { … … 1413 1415 * is disabled. 1414 1416 */ 1415 static int ip_process_packet( device_id_t device_id, packet_t *packet)1417 static int ip_process_packet(nic_device_id_t device_id, packet_t *packet) 1416 1418 { 1417 1419 ip_header_t *header; … … 1514 1516 * 1515 1517 */ 1516 static int ip_packet_size_message( device_id_t device_id, size_t *addr_len,1518 static int ip_packet_size_message(nic_device_id_t device_id, size_t *addr_len, 1517 1519 size_t *prefix, size_t *content, size_t *suffix) 1518 1520 { … … 1572 1574 * @return ENOENT if device is not found. 1573 1575 */ 1574 static int ip_mtu_changed_message( device_id_t device_id, size_t mtu)1576 static int ip_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 1575 1577 { 1576 1578 ip_netif_t *netif; … … 1629 1631 async_answer_0(iid, (sysarg_t) rc); 1630 1632 break; 1631 1633 case NET_IL_ADDR_CHANGED: 1634 async_answer_0(iid, (sysarg_t) EOK); 1635 break; 1636 1632 1637 default: 1633 1638 async_answer_0(iid, (sysarg_t) ENOTSUP); … … 1689 1694 } 1690 1695 1691 static int ip_add_route_req_local( device_id_t device_id, in_addr_t address,1696 static int ip_add_route_req_local(nic_device_id_t device_id, in_addr_t address, 1692 1697 in_addr_t netmask, in_addr_t gateway) 1693 1698 { … … 1723 1728 } 1724 1729 1725 static int ip_set_gateway_req_local(device_id_t device_id, in_addr_t gateway) 1730 static int ip_set_gateway_req_local(nic_device_id_t device_id, 1731 in_addr_t gateway) 1726 1732 { 1727 1733 ip_netif_t *netif; … … 1757 1763 * 1758 1764 */ 1759 static int ip_received_error_msg_local( device_id_t device_id,1765 static int ip_received_error_msg_local(nic_device_id_t device_id, 1760 1766 packet_t *packet, services_t target, services_t error) 1761 1767 { … … 1818 1824 static int ip_get_route_req_local(ip_protocol_t protocol, 1819 1825 const struct sockaddr *destination, socklen_t addrlen, 1820 device_id_t *device_id, void **header, size_t *headerlen)1826 nic_device_id_t *device_id, void **header, size_t *headerlen) 1821 1827 { 1822 1828 struct sockaddr_in *address_in; … … 1909 1915 size_t suffix; 1910 1916 size_t content; 1911 device_id_t device_id;1917 nic_device_id_t device_id; 1912 1918 int rc; 1913 1919 -
uspace/srv/net/il/ip/ip.h
rf51b1d3 r609243f4 92 92 in_addr_t broadcast; 93 93 /** Device identifier. */ 94 device_id_t device_id;94 nic_device_id_t device_id; 95 95 /** Indicates whether using DHCP. */ 96 96 int dhcp; … … 108 108 services_t service; 109 109 /** Device state. */ 110 device_state_t state;110 nic_device_state_t state; 111 111 }; 112 112
Note:
See TracChangeset
for help on using the changeset viewer.
