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