Changes in uspace/srv/net/il/arp/arp.c [e9caf47:a852181] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
re9caf47 ra852181 55 55 #include <ipc/il.h> 56 56 #include <byteorder.h> 57 #include <err .h>57 #include <errno.h> 58 58 59 59 #include <net/modules.h> … … 179 179 measured_string_ref address) 180 180 { 181 ERROR_DECLARE;181 int rc; 182 182 183 183 *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t)); 184 184 if (!*proto) 185 185 return ENOMEM; 186 186 187 (*proto)->service = service; 187 188 (*proto)->addr = address; 188 189 (*proto)->addr_data = address->value; 189 if (ERROR_OCCURRED(arp_addr_initialize(&(*proto)->addresses))) { 190 191 rc = arp_addr_initialize(&(*proto)->addresses); 192 if (rc != EOK) { 190 193 free(*proto); 191 return ERROR_CODE; 192 } 194 return rc; 195 } 196 193 197 return EOK; 194 198 } … … 214 218 services_t protocol, measured_string_ref address) 215 219 { 216 ERROR_DECLARE;217 218 220 arp_device_ref device; 219 221 arp_proto_ref proto; 222 hw_type_t hardware; 220 223 int index; 221 hw_type_t hardware;224 int rc; 222 225 223 226 fibril_rwlock_write_lock(&arp_globals.lock); … … 237 240 proto->addr_data = address->value; 238 241 } else { 239 if (ERROR_OCCURRED(arp_proto_create(&proto, protocol,240 address))) {242 rc = arp_proto_create(&proto, protocol, address); 243 if (rc != EOK) { 241 244 fibril_rwlock_write_unlock(&arp_globals.lock); 242 return ERROR_CODE;245 return rc; 243 246 } 244 247 index = arp_protos_add(&device->protos, proto->service, … … 265 268 device->hardware = hardware; 266 269 device->device_id = device_id; 267 if (ERROR_OCCURRED(arp_protos_initialize(&device->protos)) || 268 ERROR_OCCURRED(arp_proto_create(&proto, protocol, 269 address))) { 270 rc = arp_protos_initialize(&device->protos); 271 if (rc != EOK) { 270 272 fibril_rwlock_write_unlock(&arp_globals.lock); 271 273 free(device); 272 return ERROR_CODE; 274 return rc; 275 } 276 rc = arp_proto_create(&proto, protocol, address); 277 if (rc != EOK) { 278 fibril_rwlock_write_unlock(&arp_globals.lock); 279 free(device); 280 return rc; 273 281 } 274 282 index = arp_protos_add(&device->protos, proto->service, proto); … … 293 301 294 302 // get packet dimensions 295 if (ERROR_OCCURRED(nil_packet_size_req(device->phone, device_id, 296 &device->packet_dimension))) { 303 rc = nil_packet_size_req(device->phone, device_id, 304 &device->packet_dimension); 305 if (rc != EOK) { 297 306 fibril_rwlock_write_unlock(&arp_globals.lock); 298 307 arp_protos_destroy(&device->protos); 299 308 free(device); 300 return ERROR_CODE;309 return rc; 301 310 } 302 311 303 312 // get hardware address 304 if (ERROR_OCCURRED(nil_get_addr_req(device->phone, device_id, 305 &device->addr, &device->addr_data))) { 313 rc = nil_get_addr_req(device->phone, device_id, &device->addr, 314 &device->addr_data); 315 if (rc != EOK) { 306 316 fibril_rwlock_write_unlock(&arp_globals.lock); 307 317 arp_protos_destroy(&device->protos); 308 318 free(device); 309 return ERROR_CODE;319 return rc; 310 320 } 311 321 312 322 // get broadcast address 313 if (ERROR_OCCURRED(nil_get_broadcast_addr_req(device->phone,314 device_id, &device->broadcast_addr,315 &device->broadcast_data))) {323 rc = nil_get_broadcast_addr_req(device->phone, device_id, 324 &device->broadcast_addr, &device->broadcast_data); 325 if (rc != EOK) { 316 326 fibril_rwlock_write_unlock(&arp_globals.lock); 317 327 free(device->addr); … … 319 329 arp_protos_destroy(&device->protos); 320 330 free(device); 321 return ERROR_CODE; 322 } 323 324 if (ERROR_OCCURRED(arp_cache_add(&arp_globals.cache, 325 device->device_id, device))) { 331 return rc; 332 } 333 334 rc = arp_cache_add(&arp_globals.cache, device->device_id, 335 device); 336 if (rc != EOK) { 326 337 fibril_rwlock_write_unlock(&arp_globals.lock); 327 338 free(device->addr); … … 331 342 arp_protos_destroy(&device->protos); 332 343 free(device); 333 return ERROR_CODE;344 return rc; 334 345 } 335 346 printf("%s: Device registered (id: %d, type: 0x%x, service: %d," … … 351 362 int arp_initialize(async_client_conn_t client_connection) 352 363 { 353 ERROR_DECLARE;364 int rc; 354 365 355 366 fibril_rwlock_initialize(&arp_globals.lock); 356 367 fibril_rwlock_write_lock(&arp_globals.lock); 357 368 arp_globals.client_connection = client_connection; 358 ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));369 rc = arp_cache_initialize(&arp_globals.cache); 359 370 fibril_rwlock_write_unlock(&arp_globals.lock); 360 return EOK; 371 372 return rc; 361 373 } 362 374 … … 406 418 static int arp_receive_message(device_id_t device_id, packet_t packet) 407 419 { 408 ERROR_DECLARE;409 410 420 size_t length; 411 421 arp_header_ref header; … … 417 427 uint8_t *des_hw; 418 428 uint8_t *des_proto; 429 int rc; 419 430 420 431 length = packet_get_data_length(packet); … … 467 478 return ENOMEM; 468 479 469 ERROR_PROPAGATE(arp_addr_add(&proto->addresses, 470 (char *) src_proto, CONVERT_SIZE(uint8_t, char, 471 header->protocol_length), hw_source)); 480 rc = arp_addr_add(&proto->addresses, (char *) src_proto, 481 CONVERT_SIZE(uint8_t, char, 482 header->protocol_length), hw_source); 483 if (rc != EOK) 484 return rc; 472 485 } 473 486 if (ntohs(header->operation) == ARPOP_REQUEST) { … … 480 493 memcpy(des_hw, hw_source->value, 481 494 header->hardware_length); 482 ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw, 483 header->hardware_length)); 495 496 rc = packet_set_addr(packet, src_hw, des_hw, 497 header->hardware_length); 498 if (rc != EOK) 499 return rc; 500 484 501 nil_send_msg(device->phone, device_id, packet, 485 502 SERVICE_ARP); … … 596 613 ipc_call_t *answer, int *answer_count) 597 614 { 598 ERROR_DECLARE;599 600 615 measured_string_ref address; 601 616 measured_string_ref translation; … … 603 618 packet_t packet; 604 619 packet_t next; 620 int rc; 605 621 606 622 *answer_count = 0; … … 610 626 611 627 case NET_ARP_DEVICE: 612 ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1)); 613 if (ERROR_OCCURRED(arp_device_message(IPC_GET_DEVICE(call), 614 IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address))) { 628 rc = measured_strings_receive(&address, &data, 1); 629 if (rc != EOK) 630 return rc; 631 632 rc = arp_device_message(IPC_GET_DEVICE(call), 633 IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address); 634 if (rc != EOK) { 615 635 free(address); 616 636 free(data); 617 637 } 618 return ERROR_CODE;638 return rc; 619 639 620 640 case NET_ARP_TRANSLATE: 621 ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1)); 641 rc = measured_strings_receive(&address, &data, 1); 642 if (rc != EOK) 643 return rc; 644 622 645 fibril_rwlock_read_lock(&arp_globals.lock); 623 646 translation = arp_translate_message(IPC_GET_DEVICE(call), … … 629 652 return ENOENT; 630 653 } 631 ERROR_CODE= measured_strings_reply(translation, 1);654 rc = measured_strings_reply(translation, 1); 632 655 fibril_rwlock_read_unlock(&arp_globals.lock); 633 return ERROR_CODE;656 return rc; 634 657 635 658 case NET_ARP_CLEAR_DEVICE: … … 637 660 638 661 case NET_ARP_CLEAR_ADDRESS: 639 ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1)); 662 rc = measured_strings_receive(&address, &data, 1); 663 if (rc != EOK) 664 return rc; 665 640 666 arp_clear_address_req(0, IPC_GET_DEVICE(call), 641 667 IPC_GET_SERVICE(call), address); … … 652 678 653 679 case NET_IL_RECEIVED: 654 if (ERROR_NONE(packet_translate_remote(arp_globals.net_phone, 655 &packet, IPC_GET_PACKET(call)))) { 656 fibril_rwlock_read_lock(&arp_globals.lock); 657 do { 658 next = pq_detach(packet); 659 ERROR_CODE = 660 arp_receive_message(IPC_GET_DEVICE(call), 661 packet); 662 if (ERROR_CODE != 1) { 663 pq_release_remote(arp_globals.net_phone, 664 packet_get_id(packet)); 665 } 666 packet = next; 667 } while (packet); 668 fibril_rwlock_read_unlock(&arp_globals.lock); 669 } 670 return ERROR_CODE; 680 rc = packet_translate_remote(arp_globals.net_phone, &packet, 681 IPC_GET_PACKET(call)); 682 if (rc != EOK) 683 return rc; 684 685 fibril_rwlock_read_lock(&arp_globals.lock); 686 do { 687 next = pq_detach(packet); 688 rc = arp_receive_message(IPC_GET_DEVICE(call), packet); 689 if (rc != 1) { 690 pq_release_remote(arp_globals.net_phone, 691 packet_get_id(packet)); 692 } 693 packet = next; 694 } while (packet); 695 fibril_rwlock_read_unlock(&arp_globals.lock); 696 697 return EOK; 671 698 672 699 case NET_IL_MTU_CHANGED: … … 727 754 int main(int argc, char *argv[]) 728 755 { 729 ERROR_DECLARE;756 int rc; 730 757 731 758 /* Start the module */ 732 ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));733 return EOK;759 rc = il_module_start_standalone(il_client_connection); 760 return rc; 734 761 } 735 762
Note:
See TracChangeset
for help on using the changeset viewer.