Changeset fab2746 in mainline for uspace/srv
- Timestamp:
- 2015-04-08T21:25:30Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 99ea91b2
- Parents:
- ba0eac5
- Location:
- uspace/srv
- Files:
-
- 1 added
- 2 deleted
- 21 edited
- 1 moved
-
hid/remcons/remcons.c (modified) (5 diffs)
-
hid/remcons/remcons.h (modified) (1 diff)
-
hid/remcons/user.c (modified) (5 diffs)
-
hid/remcons/user.h (modified) (3 diffs)
-
hid/rfb/main.c (modified) (2 diffs)
-
hid/rfb/rfb.c (modified) (21 diffs)
-
hid/rfb/rfb.h (modified) (3 diffs)
-
net/dhcp/dhcp.c (modified) (1 diff)
-
net/dhcp/transport.c (modified) (8 diffs)
-
net/dhcp/transport.h (modified) (2 diffs)
-
net/dnsrsrv/transport.c (modified) (8 diffs)
-
net/tcp/Makefile (modified) (2 diffs)
-
net/tcp/sock.c (deleted)
-
net/tcp/tcp.c (modified) (3 diffs)
-
net/tcp/tcp_type.h (modified) (3 diffs)
-
net/udp/Makefile (modified) (2 diffs)
-
net/udp/assoc.c (modified) (14 diffs)
-
net/udp/assoc.h (modified) (1 diff)
-
net/udp/pdu.c (modified) (1 diff)
-
net/udp/service.c (added)
-
net/udp/service.h (moved) (moved from uspace/srv/net/udp/sock.h ) (2 diffs)
-
net/udp/sock.c (deleted)
-
net/udp/ucall.c (modified) (3 diffs)
-
net/udp/udp.c (modified) (2 diffs)
-
net/udp/udp_type.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/remcons/remcons.c
rba0eac5 rfab2746 44 44 #include <fibril_synch.h> 45 45 #include <task.h> 46 #include < net/in.h>47 #include < net/inet.h>48 #include < net/socket.h>46 #include <inet/addr.h> 47 #include <inet/endpoint.h> 48 #include <inet/tcp.h> 49 49 #include <io/console.h> 50 50 #include <inttypes.h> … … 99 99 }; 100 100 101 static void remcons_new_conn(tcp_listener_t *lst, tcp_conn_t *conn); 102 103 static tcp_listen_cb_t listen_cb = { 104 .new_conn = remcons_new_conn 105 }; 106 107 static tcp_cb_t conn_cb = { 108 .connected = NULL 109 }; 110 101 111 static telnet_user_t *srv_to_user(con_srv_t *srv) 102 112 { … … 111 121 112 122 /* Force character mode. */ 113 send(user->socket, (void *)telnet_force_character_mode_command,114 telnet_force_character_mode_command_count , 0);123 (void) tcp_conn_send(user->conn, (void *)telnet_force_character_mode_command, 124 telnet_force_character_mode_command_count); 115 125 116 126 return EOK; … … 298 308 while (!user_can_be_destroyed_no_lock(user)) { 299 309 if (user->task_finished) { 300 closesocket(user->socket); 310 tcp_conn_destroy(user->conn); 311 user->conn = NULL; 301 312 user->socket_closed = true; 302 313 user->srvs.aborted = true; … … 324 335 } 325 336 337 static void remcons_new_conn(tcp_listener_t *lst, tcp_conn_t *conn) 338 { 339 telnet_user_t *user = telnet_user_create(conn); 340 assert(user); 341 342 con_srvs_init(&user->srvs); 343 user->srvs.ops = &con_ops; 344 user->srvs.sarg = user; 345 user->srvs.abort_timeout = 1000; 346 347 telnet_user_add(user); 348 349 fid_t fid = fibril_create(network_user_fibril, user); 350 assert(fid); 351 fibril_add_ready(fid); 352 } 353 326 354 int main(int argc, char *argv[]) 327 355 { 328 int port = 2223; 329 356 int rc; 357 tcp_listener_t *lst; 358 tcp_t *tcp; 359 inet_ep_t ep; 360 330 361 async_set_client_connection(client_connection); 331 intrc = loc_server_register(NAME);362 rc = loc_server_register(NAME); 332 363 if (rc != EOK) { 333 364 fprintf(stderr, "%s: Unable to register server\n", NAME); 334 365 return rc; 335 366 } 336 337 struct sockaddr_in addr; 338 339 addr.sin_family = AF_INET; 340 addr.sin_port = htons(port); 341 342 rc = inet_pton(AF_INET, "127.0.0.1", (void *) 343 &addr.sin_addr.s_addr); 344 if (rc != EOK) { 345 fprintf(stderr, "Error parsing network address: %s.\n", 346 str_error(rc)); 347 return 2; 348 } 349 350 int listen_sd = socket(PF_INET, SOCK_STREAM, 0); 351 if (listen_sd < 0) { 352 fprintf(stderr, "Error creating listening socket: %s.\n", 353 str_error(listen_sd)); 354 return 3; 355 } 356 357 rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr)); 358 if (rc != EOK) { 359 fprintf(stderr, "Error binding socket: %s.\n", 360 str_error(rc)); 361 return 4; 362 } 363 364 rc = listen(listen_sd, BACKLOG_SIZE); 365 if (rc != EOK) { 366 fprintf(stderr, "listen() failed: %s.\n", str_error(rc)); 367 return 5; 367 368 rc = tcp_create(&tcp); 369 if (tcp != EOK) { 370 fprintf(stderr, "%s: Error initialzing TCP.\n", NAME); 371 return rc; 372 } 373 374 inet_ep_init(&ep); 375 ep.port = 2223; 376 377 rc = tcp_listener_create(tcp, &ep, &listen_cb, NULL, &conn_cb, NULL, 378 &lst); 379 if (rc != EOK) { 380 fprintf(stderr, "%s: Error creating listener.\n", NAME); 381 return rc; 368 382 } 369 383 370 384 printf("%s: HelenOS Remote console service\n", NAME); 371 385 task_retval(0); 372 373 while (true) { 374 struct sockaddr_in raddr; 375 socklen_t raddr_len = sizeof(raddr); 376 int conn_sd = accept(listen_sd, (struct sockaddr *) &raddr, 377 &raddr_len); 378 379 if (conn_sd < 0) { 380 fprintf(stderr, "accept() failed: %s.\n", 381 str_error(rc)); 382 continue; 383 } 384 385 telnet_user_t *user = telnet_user_create(conn_sd); 386 assert(user); 387 388 con_srvs_init(&user->srvs); 389 user->srvs.ops = &con_ops; 390 user->srvs.sarg = user; 391 user->srvs.abort_timeout = 1000; 392 393 telnet_user_add(user); 394 395 fid_t fid = fibril_create(network_user_fibril, user); 396 assert(fid); 397 fibril_add_ready(fid); 398 } 399 386 async_manager(); 387 388 /* Not reached */ 400 389 return 0; 401 390 } -
uspace/srv/hid/remcons/remcons.h
rba0eac5 rfab2746 38 38 #define NAME "remcons" 39 39 #define NAMESPACE "term" 40 #define BACKLOG_SIZE 541 40 42 41 #endif -
uspace/srv/hid/remcons/user.c
rba0eac5 rfab2746 44 44 #include <fibril_synch.h> 45 45 #include <task.h> 46 #include <net/in.h> 47 #include <net/inet.h> 48 #include <net/socket.h> 46 #include <inet/tcp.h> 49 47 #include <io/console.h> 50 48 #include <inttypes.h> … … 58 56 /** Create new telnet user. 59 57 * 60 * @param socket Socket the user communicates through.58 * @param conn Incoming connection. 61 59 * @return New telnet user or NULL when out of memory. 62 60 */ 63 telnet_user_t *telnet_user_create( int socket)61 telnet_user_t *telnet_user_create(tcp_conn_t *conn) 64 62 { 65 63 static int telnet_user_id_counter = 0; … … 78 76 } 79 77 80 user-> socket = socket;78 user->conn = conn; 81 79 user->service_id = (service_id_t) -1; 82 80 prodcons_initialize(&user->in_events); … … 193 191 /* No more buffered data? */ 194 192 if (user->socket_buffer_len <= user->socket_buffer_pos) { 195 int recv_length = recv(user->socket, user->socket_buffer, BUFFER_SIZE, 0); 196 if ((recv_length == 0) || (recv_length == ENOTCONN)) { 193 int rc; 194 size_t recv_length; 195 196 rc = tcp_conn_recv_wait(user->conn, user->socket_buffer, 197 BUFFER_SIZE, &recv_length); 198 if (rc != EOK) 199 return rc; 200 201 if (recv_length == 0) { 197 202 user->socket_closed = true; 198 203 user->srvs.aborted = true; 199 204 return ENOENT; 200 205 } 201 if (recv_length < 0) { 202 return recv_length; 203 } 206 204 207 user->socket_buffer_len = recv_length; 205 208 user->socket_buffer_pos = 0; … … 359 362 360 363 361 int rc = send(user->socket, converted, converted_size, 0);364 int rc = tcp_conn_send(user->conn, converted, converted_size); 362 365 free(converted); 363 366 -
uspace/srv/hid/remcons/user.h
rba0eac5 rfab2746 38 38 #include <adt/prodcons.h> 39 39 #include <fibril_synch.h> 40 #include <inet/tcp.h> 40 41 #include <inttypes.h> 41 42 #include <io/con_srv.h> … … 51 52 /** Internal id, used for creating locfs entries. */ 52 53 int id; 53 /** Associated socket. */54 int socket;54 /** Associated connection. */ 55 tcp_conn_t *conn; 55 56 /** Location service id assigned to the virtual terminal. */ 56 57 service_id_t service_id; … … 80 81 } telnet_user_t; 81 82 82 extern telnet_user_t *telnet_user_create( int);83 extern telnet_user_t *telnet_user_create(tcp_conn_t *); 83 84 extern void telnet_user_add(telnet_user_t *); 84 85 extern void telnet_user_destroy(telnet_user_t *); -
uspace/srv/hid/rfb/main.c
rba0eac5 rfab2746 150 150 } 151 151 152 static int socket_fibril(void *unused)153 {154 rfb_accept(&rfb);155 156 /* Not reached */157 return EOK;158 }159 160 152 int main(int argc, char **argv) 161 153 { … … 267 259 } 268 260 269 fid_t fib = fibril_create(socket_fibril, NULL);270 if (!fib) {271 fprintf(stderr, NAME ": Unable to create socket fibril.\n");272 return 2;273 }274 275 fibril_add_ready(fib);276 277 261 printf("%s: Accepting connections\n", NAME); 278 262 task_retval(0); -
uspace/srv/hid/rfb/rfb.c
rba0eac5 rfab2746 31 31 #include <stdlib.h> 32 32 #include <fibril_synch.h> 33 #include <inet/addr.h> 34 #include <inet/endpoint.h> 35 #include <inet/tcp.h> 33 36 #include <inttypes.h> 34 37 #include <str.h> … … 38 41 #include <io/log.h> 39 42 40 #include <net/in.h>41 #include <net/inet.h>42 #include <net/socket.h>43 44 43 #include "rfb.h" 44 45 static void rfb_new_conn(tcp_listener_t *, tcp_conn_t *); 46 47 static tcp_listen_cb_t listen_cb = { 48 .new_conn = rfb_new_conn 49 }; 50 51 static tcp_cb_t conn_cb = { 52 .connected = NULL 53 }; 45 54 46 55 /** Buffer for receiving the request. */ … … 53 62 54 63 /** Receive one character (with buffering) */ 55 static int recv_char(int fd, char *c) 56 { 64 static int recv_char(tcp_conn_t *conn, char *c) 65 { 66 size_t nrecv; 67 int rc; 68 57 69 if (rbuf_out == rbuf_in) { 58 70 rbuf_out = 0; 59 71 rbuf_in = 0; 60 72 61 ssize_t rc = recv(fd, rbuf, BUFFER_SIZE, 0);62 if (rc <= 0)73 rc = tcp_conn_recv_wait(conn, rbuf, BUFFER_SIZE, &nrecv); 74 if (rc != EOK) 63 75 return rc; 64 76 65 rbuf_in = rc;77 rbuf_in = nrecv; 66 78 } 67 79 … … 71 83 72 84 /** Receive count characters (with buffering) */ 73 static int recv_chars( int fd, char *c, size_t count)85 static int recv_chars(tcp_conn_t *conn, char *c, size_t count) 74 86 { 75 87 for (size_t i = 0; i < count; i++) { 76 int rc = recv_char( fd, c);88 int rc = recv_char(conn, c); 77 89 if (rc != EOK) 78 90 return rc; … … 82 94 } 83 95 84 static int recv_skip_chars( int fd, size_t count)96 static int recv_skip_chars(tcp_conn_t *conn, size_t count) 85 97 { 86 98 for (size_t i = 0; i < count; i++) { 87 99 char c; 88 int rc = recv_char( fd, &c);100 int rc = recv_char(conn, &c); 89 101 if (rc != EOK) 90 102 return rc; … … 204 216 } 205 217 206 static int recv_message( int conn_sd, char type, void *buf, size_t size)218 static int recv_message(tcp_conn_t *conn, char type, void *buf, size_t size) 207 219 { 208 220 memcpy(buf, &type, 1); 209 return recv_chars(conn _sd, ((char *) buf) + 1, size -1);221 return recv_chars(conn, ((char *) buf) + 1, size -1); 210 222 } 211 223 … … 477 489 } 478 490 479 static int rfb_send_framebuffer_update(rfb_t *rfb, int conn_sd, bool incremental) 491 static int rfb_send_framebuffer_update(rfb_t *rfb, tcp_conn_t *conn, 492 bool incremental) 480 493 { 481 494 fibril_mutex_lock(&rfb->lock); … … 540 553 541 554 if (!rfb->pixel_format.true_color) { 542 int rc = send(conn_sd, send_palette, send_palette_size, 0);555 int rc = tcp_conn_send(conn, send_palette, send_palette_size); 543 556 if (rc != EOK) { 544 557 free(buf); … … 547 560 } 548 561 549 int rc = send(conn_sd, buf, buf_size, 0);562 int rc = tcp_conn_send(conn, buf, buf_size); 550 563 free(buf); 551 564 … … 580 593 } 581 594 582 static void rfb_socket_connection(rfb_t *rfb, int conn_sd)595 static void rfb_socket_connection(rfb_t *rfb, tcp_conn_t *conn) 583 596 { 584 597 /* Version handshake */ 585 int rc = send(conn_sd, "RFB 003.008\n", 12, 0);598 int rc = tcp_conn_send(conn, "RFB 003.008\n", 12); 586 599 if (rc != EOK) { 587 600 log_msg(LOG_DEFAULT, LVL_WARN, "Failed sending server version %d", rc); … … 590 603 591 604 char client_version[12]; 592 rc = recv_chars(conn _sd, client_version, 12);605 rc = recv_chars(conn, client_version, 12); 593 606 if (rc != EOK) { 594 607 log_msg(LOG_DEFAULT, LVL_WARN, "Failed receiving client version: %d", rc); … … 607 620 sec_types[0] = 1; /* length */ 608 621 sec_types[1] = RFB_SECURITY_NONE; 609 rc = send(conn_sd, sec_types, 2, 0);622 rc = tcp_conn_send(conn, sec_types, 2); 610 623 if (rc != EOK) { 611 624 log_msg(LOG_DEFAULT, LVL_WARN, … … 615 628 616 629 char selected_sec_type = 0; 617 rc = recv_char(conn _sd, &selected_sec_type);630 rc = recv_char(conn, &selected_sec_type); 618 631 if (rc != EOK) { 619 632 log_msg(LOG_DEFAULT, LVL_WARN, "Failed receiving security type: %d", rc); … … 626 639 } 627 640 uint32_t security_result = RFB_SECURITY_HANDSHAKE_OK; 628 rc = send(conn_sd, &security_result, sizeof(uint32_t), 0);641 rc = tcp_conn_send(conn, &security_result, sizeof(uint32_t)); 629 642 if (rc != EOK) { 630 643 log_msg(LOG_DEFAULT, LVL_WARN, "Failed sending security result: %d", rc); … … 634 647 /* Client init */ 635 648 char shared_flag; 636 rc = recv_char(conn _sd, &shared_flag);649 rc = recv_char(conn, &shared_flag); 637 650 if (rc != EOK) { 638 651 log_msg(LOG_DEFAULT, LVL_WARN, "Failed receiving client init: %d", rc); … … 657 670 memcpy(server_init->name, rfb->name, name_length); 658 671 fibril_mutex_unlock(&rfb->lock); 659 rc = send(conn_sd, server_init, msg_length, 0);672 rc = tcp_conn_send(conn, server_init, msg_length); 660 673 if (rc != EOK) { 661 674 log_msg(LOG_DEFAULT, LVL_WARN, "Failed sending server init: %d", rc); … … 665 678 while (true) { 666 679 char message_type = 0; 667 rc = recv_char(conn _sd, &message_type);680 rc = recv_char(conn, &message_type); 668 681 if (rc != EOK) { 669 682 log_msg(LOG_DEFAULT, LVL_WARN, … … 680 693 switch (message_type) { 681 694 case RFB_CMSG_SET_PIXEL_FORMAT: 682 recv_message(conn _sd, message_type, &spf, sizeof(spf));695 recv_message(conn, message_type, &spf, sizeof(spf)); 683 696 rfb_pixel_format_to_host(&spf.pixel_format, &spf.pixel_format); 684 697 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received SetPixelFormat message"); … … 690 703 break; 691 704 case RFB_CMSG_SET_ENCODINGS: 692 recv_message(conn _sd, message_type, &se, sizeof(se));705 recv_message(conn, message_type, &se, sizeof(se)); 693 706 rfb_set_encodings_to_host(&se, &se); 694 707 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received SetEncodings message"); 695 708 for (uint16_t i = 0; i < se.count; i++) { 696 709 int32_t encoding = 0; 697 rc = recv_chars(conn _sd, (char *) &encoding, sizeof(int32_t));710 rc = recv_chars(conn, (char *) &encoding, sizeof(int32_t)); 698 711 if (rc != EOK) 699 712 return; … … 707 720 break; 708 721 case RFB_CMSG_FRAMEBUFFER_UPDATE_REQUEST: 709 recv_message(conn _sd, message_type, &fbur, sizeof(fbur));722 recv_message(conn, message_type, &fbur, sizeof(fbur)); 710 723 rfb_framebuffer_update_request_to_host(&fbur, &fbur); 711 724 log_msg(LOG_DEFAULT, LVL_DEBUG2, 712 725 "Received FramebufferUpdateRequest message"); 713 rfb_send_framebuffer_update(rfb, conn _sd, fbur.incremental);726 rfb_send_framebuffer_update(rfb, conn, fbur.incremental); 714 727 break; 715 728 case RFB_CMSG_KEY_EVENT: 716 recv_message(conn _sd, message_type, &ke, sizeof(ke));729 recv_message(conn, message_type, &ke, sizeof(ke)); 717 730 rfb_key_event_to_host(&ke, &ke); 718 731 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received KeyEvent message"); 719 732 break; 720 733 case RFB_CMSG_POINTER_EVENT: 721 recv_message(conn _sd, message_type, &pe, sizeof(pe));734 recv_message(conn, message_type, &pe, sizeof(pe)); 722 735 rfb_pointer_event_to_host(&pe, &pe); 723 736 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received PointerEvent message"); 724 737 break; 725 738 case RFB_CMSG_CLIENT_CUT_TEXT: 726 recv_message(conn _sd, message_type, &cct, sizeof(cct));739 recv_message(conn, message_type, &cct, sizeof(cct)); 727 740 rfb_client_cut_text_to_host(&cct, &cct); 728 741 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Received ClientCutText message"); 729 recv_skip_chars(conn _sd, cct.length);742 recv_skip_chars(conn, cct.length); 730 743 break; 731 744 default: … … 737 750 } 738 751 739 int rfb_listen(rfb_t *rfb, uint16_t port) { 740 struct sockaddr_in addr; 741 742 addr.sin_family = AF_INET; 743 addr.sin_port = htons(port); 744 745 int rc = inet_pton(AF_INET, "127.0.0.1", (void *) 746 &addr.sin_addr.s_addr); 752 int rfb_listen(rfb_t *rfb, uint16_t port) 753 { 754 tcp_t *tcp = NULL; 755 tcp_listener_t *lst = NULL; 756 inet_ep_t ep; 757 int rc; 758 759 inet_ep_init(&ep); 760 ep.port = port; 761 762 rc = tcp_listener_create(tcp, &ep, &listen_cb, rfb, &conn_cb, rfb, 763 &lst); 747 764 if (rc != EOK) { 748 log_msg(LOG_DEFAULT, LVL_ERROR, "Error parsing network address (%s)", 749 str_error(rc)); 750 return rc; 751 } 752 753 int listen_sd = socket(PF_INET, SOCK_STREAM, 0); 754 if (listen_sd < 0) { 755 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating listening socket (%s)", 756 str_error(listen_sd)); 757 return rc; 758 } 759 760 rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr)); 761 if (rc != EOK) { 762 log_msg(LOG_DEFAULT, LVL_ERROR, "Error binding socket (%s)", 763 str_error(rc)); 764 return rc; 765 } 766 767 rc = listen(listen_sd, 2); 768 if (rc != EOK) { 769 log_msg(LOG_DEFAULT, LVL_ERROR, "listen() failed (%s)", str_error(rc)); 770 return rc; 771 } 772 773 rfb->listen_sd = listen_sd; 765 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating listener.\n"); 766 goto error; 767 } 768 769 rfb->tcp = tcp; 770 rfb->lst = lst; 774 771 775 772 return EOK; 776 } 777 778 void rfb_accept(rfb_t *rfb) 779 { 780 while (true) { 781 struct sockaddr_in raddr; 782 socklen_t raddr_len = sizeof(raddr); 783 int conn_sd = accept(rfb->listen_sd, (struct sockaddr *) &raddr, 784 &raddr_len); 785 786 if (conn_sd < 0) { 787 log_msg(LOG_DEFAULT, LVL_WARN, "accept() failed (%s)", 788 str_error(conn_sd)); 789 continue; 790 } 791 792 log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection accepted"); 793 794 rbuf_out = 0; 795 rbuf_in = 0; 796 797 rfb_socket_connection(rfb, conn_sd); 798 closesocket(conn_sd); 799 } 800 } 773 error: 774 tcp_listener_destroy(lst); 775 tcp_destroy(tcp); 776 return rc; 777 } 778 779 static void rfb_new_conn(tcp_listener_t *lst, tcp_conn_t *conn) 780 { 781 rfb_t *rfb = (rfb_t *)tcp_listener_userptr(lst); 782 log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection accepted"); 783 784 rbuf_out = 0; 785 rbuf_in = 0; 786 787 rfb_socket_connection(rfb, conn); 788 } -
uspace/srv/hid/rfb/rfb.h
rba0eac5 rfab2746 30 30 #define RFB_H__ 31 31 32 #include <inet/tcp.h> 32 33 #include <io/pixelmap.h> 33 34 #include <fibril_synch.h> … … 151 152 rfb_pixel_format_t pixel_format; 152 153 const char *name; 153 int listen_sd; 154 tcp_t *tcp; 155 tcp_listener_t *lst; 154 156 pixelmap_t framebuffer; 155 157 rfb_rectangle_t damage_rect; … … 165 167 extern int rfb_set_size(rfb_t *, uint16_t, uint16_t); 166 168 extern int rfb_listen(rfb_t *, uint16_t); 167 extern void rfb_accept(rfb_t *);168 169 169 170 #endif -
uspace/srv/net/dhcp/dhcp.c
rba0eac5 rfab2746 37 37 #include <adt/list.h> 38 38 #include <bitops.h> 39 #include <byteorder.h> 39 40 #include <errno.h> 40 41 #include <fibril_synch.h> -
uspace/srv/net/dhcp/transport.c
rba0eac5 rfab2746 36 36 37 37 #include <bitops.h> 38 #include <errno.h> 38 39 #include <inet/addr.h> 39 40 #include <inet/dnsr.h> … … 41 42 #include <io/log.h> 42 43 #include <loc.h> 43 #include <net/in.h>44 #include <net/inet.h>45 #include <net/socket.h>46 44 #include <stdio.h> 47 45 #include <stdlib.h> … … 67 65 } dhcp_offer_t; 68 66 69 static int dhcp_recv_fibril(void *); 67 static void dhcp_recv_msg(udp_assoc_t *, udp_rmsg_t *); 68 static void dhcp_recv_err(udp_assoc_t *, udp_rerr_t *); 69 static void dhcp_link_state(udp_assoc_t *, udp_link_state_t); 70 71 static udp_cb_t dhcp_transport_cb = { 72 .recv_msg = dhcp_recv_msg, 73 .recv_err = dhcp_recv_err, 74 .link_state = dhcp_link_state 75 }; 70 76 71 77 int dhcp_send(dhcp_transport_t *dt, void *msg, size_t size) 72 78 { 73 struct sockaddr_in addr;79 inet_ep_t ep; 74 80 int rc; 75 81 76 addr.sin_family = AF_INET;77 addr.sin_port = htons(dhcp_server_port);78 addr.sin_addr.s_addr = htonl(addr32_broadcast_all_hosts);82 inet_ep_init(&ep); 83 ep.port = dhcp_server_port; 84 inet_addr_set(addr32_broadcast_all_hosts, &ep.addr); 79 85 80 rc = sendto(dt->fd, msg, size, 0, 81 (struct sockaddr *)&addr, sizeof(addr)); 86 rc = udp_assoc_send_msg(dt->assoc, &ep, msg, size); 82 87 if (rc != EOK) { 83 log_msg(LOG_DEFAULT, LVL_ERROR, " Sending failed");88 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed sending message"); 84 89 return rc; 85 90 } … … 88 93 } 89 94 90 static int dhcp_recv_msg(dhcp_transport_t *dt, void **rmsg, size_t *rsize)95 static void dhcp_recv_msg(udp_assoc_t *assoc, udp_rmsg_t *rmsg) 91 96 { 92 struct sockaddr_in src_addr; 93 socklen_t src_addr_size; 94 size_t recv_size; 97 dhcp_transport_t *dt; 98 size_t s; 95 99 int rc; 96 100 97 src_addr_size = sizeof(src_addr); 98 rc = recvfrom(dt->fd, msgbuf, MAX_MSG_SIZE, 0, 99 (struct sockaddr *)&src_addr, &src_addr_size); 100 if (rc < 0) { 101 log_msg(LOG_DEFAULT, LVL_ERROR, "recvfrom failed (%d)", rc); 102 return rc; 101 log_msg(LOG_DEFAULT, LVL_NOTE, "dhcp_recv_msg()"); 102 103 dt = (dhcp_transport_t *)udp_assoc_userptr(assoc); 104 s = udp_rmsg_size(rmsg); 105 if (s > MAX_MSG_SIZE) 106 s = MAX_MSG_SIZE; /* XXX */ 107 108 rc = udp_rmsg_read(rmsg, 0, msgbuf, s); 109 if (rc != EOK) { 110 log_msg(LOG_DEFAULT, LVL_ERROR, "Error receiving message."); 111 return; 103 112 } 104 113 105 recv_size = (size_t)rc;106 *rmsg = msgbuf;107 *rsize = recv_size; 114 log_msg(LOG_DEFAULT, LVL_NOTE, "dhcp_recv_msg() - call recv_cb"); 115 dt->recv_cb(dt->cb_arg, msgbuf, s); 116 } 108 117 109 return EOK; 118 static void dhcp_recv_err(udp_assoc_t *assoc, udp_rerr_t *rerr) 119 { 120 log_msg(LOG_DEFAULT, LVL_WARN, "Ignoring ICMP error"); 121 } 122 123 static void dhcp_link_state(udp_assoc_t *assoc, udp_link_state_t ls) 124 { 125 log_msg(LOG_DEFAULT, LVL_NOTE, "Link state change"); 110 126 } 111 127 … … 113 129 dhcp_recv_cb_t recv_cb, void *arg) 114 130 { 115 int fd;116 struct sockaddr_in laddr;117 in t fid;131 udp_t *udp = NULL; 132 udp_assoc_t *assoc = NULL; 133 inet_ep2_t epp; 118 134 int rc; 119 135 120 log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcp transport_init()");136 log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcp_transport_init()"); 121 137 122 laddr.sin_family = AF_INET; 123 laddr.sin_port = htons(dhcp_client_port); 124 laddr.sin_addr.s_addr = INADDR_ANY; 138 inet_ep2_init(&epp); 139 epp.local.addr.version = ip_v4; 140 epp.local.port = dhcp_client_port; 141 epp.local_link = link_id; 125 142 126 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 127 if (fd < 0) { 128 rc = EIO; 129 goto error; 130 } 131 132 log_msg(LOG_DEFAULT, LVL_DEBUG, "Bind socket."); 133 rc = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)); 143 rc = udp_create(&udp); 134 144 if (rc != EOK) { 135 145 rc = EIO; … … 137 147 } 138 148 139 log_msg(LOG_DEFAULT, LVL_DEBUG, "Set socket options"); 140 rc = setsockopt(fd, SOL_SOCKET, SO_IPLINK, &link_id, sizeof(link_id)); 149 rc = udp_assoc_create(udp, &epp, &dhcp_transport_cb, dt, &assoc); 141 150 if (rc != EOK) { 142 151 rc = EIO; … … 144 153 } 145 154 146 dt->fd = fd; 155 dt->udp = udp; 156 dt->assoc = assoc; 147 157 dt->recv_cb = recv_cb; 148 158 dt->cb_arg = arg; 149 159 150 fid = fibril_create(dhcp_recv_fibril, dt);151 if (fid == 0) {152 rc = ENOMEM;153 goto error;154 }155 156 dt->recv_fid = fid;157 fibril_add_ready(fid);158 159 160 return EOK; 160 161 error: 161 closesocket(fd); 162 udp_assoc_destroy(assoc); 163 udp_destroy(udp); 162 164 return rc; 163 165 } … … 165 167 void dhcp_transport_fini(dhcp_transport_t *dt) 166 168 { 167 closesocket(dt->fd); 168 } 169 170 static int dhcp_recv_fibril(void *arg) 171 { 172 dhcp_transport_t *dt = (dhcp_transport_t *)arg; 173 void *msg; 174 size_t size = (size_t) -1; 175 int rc; 176 177 while (true) { 178 rc = dhcp_recv_msg(dt, &msg, &size); 179 if (rc != EOK) 180 break; 181 182 assert(size != (size_t) -1); 183 184 dt->recv_cb(dt->cb_arg, msg, size); 185 } 186 187 return EOK; 169 udp_assoc_destroy(dt->assoc); 170 udp_destroy(dt->udp); 188 171 } 189 172 -
uspace/srv/net/dhcp/transport.h
rba0eac5 rfab2746 38 38 #define TRANSPORT_H 39 39 40 #include <inet/udp.h> 40 41 #include <ipc/loc.h> 41 42 #include <sys/types.h> … … 47 48 48 49 struct dhcp_transport { 49 /** Transport socket */ 50 int fd; 50 /** UDP */ 51 udp_t *udp; 52 /** UDP association */ 53 udp_assoc_t *assoc; 51 54 /** Receive callback */ 52 55 dhcp_recv_cb_t recv_cb; 53 56 /** Callback argument */ 54 57 void *cb_arg; 55 /** Receive fibril ID */56 int recv_fid;57 58 }; 58 59 -
uspace/srv/net/dnsrsrv/transport.c
rba0eac5 rfab2746 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/addr.h> 40 #include <inet/endpoint.h> 41 #include <inet/udp.h> 39 42 #include <io/log.h> 40 #include <net/in.h>41 #include <net/inet.h>42 #include <net/socket.h>43 43 #include <stdbool.h> 44 44 #include <stdlib.h> … … 72 72 73 73 static uint8_t recv_buf[RECV_BUF_SIZE]; 74 static fid_t recv_fid;75 static int transport_fd = -1;74 static udp_t *transport_udp; 75 static udp_assoc_t *transport_assoc; 76 76 77 77 /** Outstanding requests */ … … 79 79 static FIBRIL_MUTEX_INITIALIZE(treq_lock); 80 80 81 static int transport_recv_fibril(void *arg); 81 static void transport_recv_msg(udp_assoc_t *, udp_rmsg_t *); 82 static void transport_recv_err(udp_assoc_t *, udp_rerr_t *); 83 static void transport_link_state(udp_assoc_t *, udp_link_state_t); 84 85 static udp_cb_t transport_cb = { 86 .recv_msg = transport_recv_msg, 87 .recv_err = transport_recv_err, 88 .link_state = transport_link_state 89 }; 82 90 83 91 int transport_init(void) 84 92 { 85 struct sockaddr_in laddr; 86 int fd; 87 fid_t fid; 93 inet_ep2_t epp; 88 94 int rc; 89 95 90 laddr.sin_family = AF_INET; 91 laddr.sin_port = htons(12345); 92 laddr.sin_addr.s_addr = INADDR_ANY; 93 94 fd = -1; 95 96 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 97 if (fd < 0) { 96 inet_ep2_init(&epp); 97 98 rc = udp_create(&transport_udp); 99 if (rc != EOK) { 98 100 rc = EIO; 99 101 goto error; 100 102 } 101 103 102 rc = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)); 103 if (rc != EOK) 104 goto error; 105 106 transport_fd = fd; 107 108 fid = fibril_create(transport_recv_fibril, NULL); 109 if (fid == 0) 110 goto error; 111 112 fibril_add_ready(fid); 113 recv_fid = fid; 104 rc = udp_assoc_create(transport_udp, &epp, &transport_cb, NULL, 105 &transport_assoc); 106 if (rc != EOK) { 107 rc = EIO; 108 goto error; 109 } 110 114 111 return EOK; 115 112 error: 116 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing network socket.");117 if (fd >= 0)118 closesocket(fd);113 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing network."); 114 udp_assoc_destroy(transport_assoc); 115 udp_destroy(transport_udp); 119 116 return rc; 120 117 } … … 122 119 void transport_fini(void) 123 120 { 124 if (transport_fd >= 0)125 closesocket(transport_fd);121 udp_assoc_destroy(transport_assoc); 122 udp_destroy(transport_udp); 126 123 } 127 124 … … 182 179 { 183 180 trans_req_t *treq = NULL; 184 struct sockaddr *saddr = NULL; 185 socklen_t saddrlen; 186 181 inet_ep_t ep; 182 187 183 void *req_data; 188 184 size_t req_size; … … 190 186 if (rc != EOK) 191 187 goto error; 192 193 rc = inet_addr_sockaddr(&dns_server_addr, DNS_SERVER_PORT, 194 &saddr, &saddrlen); 195 if (rc != EOK) { 196 assert(rc == ENOMEM); 197 goto error; 198 } 199 188 189 inet_ep_init(&ep); 190 ep.addr = dns_server_addr; 191 ep.port = DNS_SERVER_PORT; 192 200 193 size_t ntry = 0; 201 194 202 195 while (ntry < REQ_RETRY_MAX) { 203 rc = sendto(transport_fd, req_data, req_size, 0,204 saddr, saddrlen);196 rc = udp_assoc_send_msg(transport_assoc, &ep, req_data, 197 req_size); 205 198 if (rc != EOK) 206 199 goto error; 207 200 208 201 treq = treq_create(req); 209 202 if (treq == NULL) { … … 211 204 goto error; 212 205 } 213 206 214 207 fibril_mutex_lock(&treq->done_lock); 215 208 while (treq->done != true) { … … 221 214 } 222 215 } 223 216 224 217 fibril_mutex_unlock(&treq->done_lock); 225 218 226 219 if (rc != ETIMEOUT) 227 220 break; 228 221 } 229 222 230 223 if (ntry >= REQ_RETRY_MAX) { 231 224 rc = EIO; 232 225 goto error; 233 226 } 234 227 235 228 if (treq->status != EOK) { 236 229 rc = treq->status; 237 230 goto error; 238 231 } 239 232 240 233 *rresp = treq->resp; 241 234 treq_destroy(treq); 242 235 free(req_data); 243 free(saddr);244 236 return EOK; 245 237 246 238 error: 247 239 if (treq != NULL) 248 240 treq_destroy(treq); 249 241 250 242 free(req_data); 251 free(saddr);252 243 return rc; 253 244 } 254 245 255 static int transport_recv_msg(dns_message_t **rresp) 256 { 257 struct sockaddr_in src_addr; 258 socklen_t src_addr_size; 259 size_t recv_size; 260 dns_message_t *resp; 261 int rc; 262 263 src_addr_size = sizeof(src_addr); 264 rc = recvfrom(transport_fd, recv_buf, RECV_BUF_SIZE, 0, 265 (struct sockaddr *)&src_addr, &src_addr_size); 266 if (rc < 0) { 267 log_msg(LOG_DEFAULT, LVL_ERROR, "recvfrom returns error - %d", rc); 268 goto error; 269 } 270 271 recv_size = (size_t)rc; 272 273 rc = dns_message_decode(recv_buf, recv_size, &resp); 274 if (rc != EOK) { 275 rc = EIO; 276 goto error; 277 } 278 279 *rresp = resp; 280 return EOK; 281 282 error: 283 return rc; 284 } 285 286 static int transport_recv_fibril(void *arg) 246 static void transport_recv_msg(udp_assoc_t *assoc, udp_rmsg_t *rmsg) 287 247 { 288 248 dns_message_t *resp = NULL; 289 249 trans_req_t *treq; 250 size_t size; 251 inet_ep_t remote_ep; 290 252 int rc; 291 253 292 while (true) { 293 rc = transport_recv_msg(&resp); 294 if (rc != EOK) 295 continue; 296 297 assert(resp != NULL); 298 299 fibril_mutex_lock(&treq_lock); 300 treq = treq_match_resp(resp); 301 if (treq == NULL) { 302 fibril_mutex_unlock(&treq_lock); 303 continue; 304 } 305 306 list_remove(&treq->lreq); 254 size = udp_rmsg_size(rmsg); 255 if (size > RECV_BUF_SIZE) 256 size = RECV_BUF_SIZE; /* XXX */ 257 258 rc = udp_rmsg_read(rmsg, 0, recv_buf, size); 259 if (rc != EOK) { 260 log_msg(LOG_DEFAULT, LVL_ERROR, "Error reading message."); 261 return; 262 } 263 264 udp_rmsg_remote_ep(rmsg, &remote_ep); 265 /* XXX */ 266 267 rc = dns_message_decode(recv_buf, size, &resp); 268 if (rc != EOK) { 269 log_msg(LOG_DEFAULT, LVL_ERROR, "Error decoding message."); 270 return; 271 } 272 273 assert(resp != NULL); 274 275 fibril_mutex_lock(&treq_lock); 276 treq = treq_match_resp(resp); 277 if (treq == NULL) { 307 278 fibril_mutex_unlock(&treq_lock); 308 309 treq_complete(treq, resp); 310 } 311 312 return 0; 313 } 279 return; 280 } 281 282 list_remove(&treq->lreq); 283 fibril_mutex_unlock(&treq_lock); 284 285 treq_complete(treq, resp); 286 } 287 288 static void transport_recv_err(udp_assoc_t *assoc, udp_rerr_t *rerr) 289 { 290 log_msg(LOG_DEFAULT, LVL_WARN, "Ignoring ICMP error"); 291 } 292 293 static void transport_link_state(udp_assoc_t *assoc, udp_link_state_t ls) 294 { 295 log_msg(LOG_DEFAULT, LVL_NOTE, "Link state change"); 296 } 297 314 298 315 299 /** @} -
uspace/srv/net/tcp/Makefile
rba0eac5 rfab2746 28 28 29 29 USPACE_PREFIX = ../../.. 30 LIBS = $(LIBNET_PREFIX)/libnet.a31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include32 30 BINARY = tcp 33 31 … … 40 38 segment.c \ 41 39 seq_no.c \ 42 sock.c \43 40 tcp.c \ 44 41 test.c \ -
uspace/srv/net/tcp/tcp.c
rba0eac5 rfab2746 42 42 #include <io/log.h> 43 43 #include <stdio.h> 44 #include <stdlib.h> 44 45 #include <task.h> 45 46 … … 47 48 #include "pdu.h" 48 49 #include "rqueue.h" 49 #include "sock.h"50 50 #include "std.h" 51 51 #include "tcp.h" … … 192 192 } 193 193 194 rc = tcp_sock_init();195 if (rc != EOK) {196 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socket service.");197 return ENOENT;198 }194 // rc = tcp_sock_init(); 195 // if (rc != EOK) { 196 // log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socket service."); 197 // return ENOENT; 198 // } 199 199 200 200 return EOK; -
uspace/srv/net/tcp/tcp_type.h
rba0eac5 rfab2746 41 41 #include <fibril.h> 42 42 #include <fibril_synch.h> 43 #include <socket_core.h>44 43 #include <sys/types.h> 45 44 #include <inet/addr.h> … … 321 320 typedef struct { 322 321 async_sess_t *sess; 323 socket_cores_t sockets;322 // socket_cores_t sockets; 324 323 } tcp_client_t; 325 324 … … 330 329 fibril_mutex_t lock; 331 330 /** Socket core */ 332 socket_core_t *sock_core;331 // socket_core_t *sock_core; 333 332 /** Client */ 334 333 tcp_client_t *client; -
uspace/srv/net/udp/Makefile
rba0eac5 rfab2746 28 28 29 29 USPACE_PREFIX = ../../.. 30 LIBS = $(LIBNET_PREFIX)/libnet.a31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include32 30 BINARY = udp 33 31 … … 35 33 assoc.c \ 36 34 msg.c \ 37 sock.c \38 35 pdu.c \ 36 service.c \ 39 37 ucall.c \ 40 38 udp.c \ -
uspace/srv/net/udp/assoc.c
rba0eac5 rfab2746 36 36 37 37 #include <adt/list.h> 38 #include <errno.h> 38 39 #include <stdbool.h> 39 40 #include <fibril_synch.h> … … 62 63 * @return New association or NULL 63 64 */ 64 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock) 65 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock, 66 udp_assoc_cb_t *cb, void *cb_arg) 65 67 { 66 68 udp_assoc_t *assoc = NULL; … … 82 84 if (lsock != NULL) 83 85 assoc->ident.local = *lsock; 84 86 85 87 if (fsock != NULL) 86 88 assoc->ident.foreign = *fsock; 87 89 90 assoc->cb = cb; 91 assoc->cb_arg = cb_arg; 88 92 return assoc; 89 93 error: … … 258 262 int rc; 259 263 260 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_send(%p, %p, %p)",264 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send(%p, %p, %p)", 261 265 assoc, fsock, msg); 262 266 … … 266 270 sp.foreign = *fsock; 267 271 272 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check addr any"); 273 268 274 if ((inet_addr_is_any(&sp.foreign.addr)) || 269 275 (sp.foreign.port == UDP_PORT_ANY)) 270 276 return EINVAL; 271 277 278 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check version"); 279 280 if (sp.foreign.addr.version != sp.local.addr.version) 281 return EINVAL; 282 283 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - encode pdu"); 284 272 285 rc = udp_pdu_encode(&sp, msg, &pdu); 273 286 if (rc != EOK) 274 287 return ENOMEM; 275 288 289 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - transmit"); 290 276 291 rc = udp_transmit_pdu(pdu); 277 292 udp_pdu_delete(pdu); … … 280 295 return EIO; 281 296 297 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - success"); 282 298 return EOK; 283 299 } … … 292 308 udp_rcv_queue_entry_t *rqe; 293 309 294 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_recv()");310 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_recv()"); 295 311 296 312 fibril_mutex_lock(&assoc->lock); … … 303 319 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - association was reset"); 304 320 fibril_mutex_unlock(&assoc->lock); 305 return E CONNABORTED;321 return ENXIO; 306 322 } 307 323 308 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_recv() - got a message");324 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_recv() - got a message"); 309 325 link = list_first(&assoc->rcv_queue); 310 326 rqe = list_get_instance(link, udp_rcv_queue_entry_t, link); … … 328 344 int rc; 329 345 330 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_received(%p, %p)", rsp, msg);346 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", rsp, msg); 331 347 332 348 assoc = udp_assoc_find_ref(rsp); 333 349 if (assoc == NULL) { 334 log_msg(LOG_DEFAULT, LVL_ DEBUG, "No association found. Message dropped.");350 log_msg(LOG_DEFAULT, LVL_NOTE, "No association found. Message dropped."); 335 351 /* XXX Generate ICMP error. */ 336 352 /* XXX Might propagate error directly by error return. */ … … 339 355 } 340 356 341 rc = udp_assoc_queue_msg(assoc, rsp, msg); 342 if (rc != EOK) { 343 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped."); 357 if (0) { 358 rc = udp_assoc_queue_msg(assoc, rsp, msg); 359 if (rc != EOK) { 360 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped."); 344 361 /* XXX Generate ICMP error? */ 362 } 345 363 } 364 365 log_msg(LOG_DEFAULT, LVL_NOTE, "call assoc->cb->recv_msg"); 366 assoc->cb->recv_msg(assoc->cb_arg, rsp, msg); 346 367 } 347 368 … … 387 408 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt) 388 409 { 389 log_msg(LOG_DEFAULT, LVL_DEBUG, 390 "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port); 410 char *sa, *pa; 411 412 sa = pa = (char *)"?"; 413 (void) inet_addr_format(&sock->addr, &sa); 414 (void) inet_addr_format(&patt->addr, &pa); 415 416 log_msg(LOG_DEFAULT, LVL_NOTE, 417 "udp_socket_match(sock=(%s,%u), pat=(%s,%u))", 418 sa, sock->port, pa, patt->port); 391 419 392 420 if ((!inet_addr_is_any(&patt->addr)) && … … 394 422 return false; 395 423 424 log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK"); 425 396 426 if ((patt->port != UDP_PORT_ANY) && 397 427 (patt->port != sock->port)) 398 428 return false; 399 429 400 log_msg(LOG_DEFAULT, LVL_ DEBUG, " -> match");430 log_msg(LOG_DEFAULT, LVL_NOTE, " -> match"); 401 431 402 432 return true; … … 430 460 static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *sp) 431 461 { 432 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp); 462 char *la, *ra; 463 464 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", sp); 433 465 434 466 fibril_mutex_lock(&assoc_list_lock); 435 467 468 log_msg(LOG_DEFAULT, LVL_NOTE, "associations:"); 436 469 list_foreach(assoc_list, link, udp_assoc_t, assoc) { 437 470 udp_sockpair_t *asp = &assoc->ident; 438 471 472 la = ra = NULL; 473 474 (void) inet_addr_format(&asp->local.addr, &la); 475 (void) inet_addr_format(&asp->foreign.addr, &ra); 476 477 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:asp=%p la=%s ra=%s", 478 asp, la, ra); 439 479 /* Skip unbound associations */ 440 if (asp->local.port == UDP_PORT_ANY) 480 if (asp->local.port == UDP_PORT_ANY) { 481 log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound"); 441 482 continue; 483 } 442 484 443 485 if (udp_sockpair_match(sp, asp)) { … … 446 488 fibril_mutex_unlock(&assoc_list_lock); 447 489 return assoc; 490 } else { 491 log_msg(LOG_DEFAULT, LVL_NOTE, "not matched"); 448 492 } 449 493 } 450 494 495 log_msg(LOG_DEFAULT, LVL_NOTE, "associations END"); 451 496 fibril_mutex_unlock(&assoc_list_lock); 452 497 return NULL; -
uspace/srv/net/udp/assoc.h
rba0eac5 rfab2746 40 40 #include "udp_type.h" 41 41 42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *); 42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *, udp_assoc_cb_t *, 43 void *); 43 44 extern void udp_assoc_delete(udp_assoc_t *); 44 45 extern void udp_assoc_add(udp_assoc_t *); -
uspace/srv/net/udp/pdu.c
rba0eac5 rfab2746 41 41 #include <stdlib.h> 42 42 #include <inet/addr.h> 43 #include <net/socket_codes.h>44 43 #include "msg.h" 45 44 #include "pdu.h" -
uspace/srv/net/udp/service.h
rba0eac5 rfab2746 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 30 30 * @{ 31 31 */ 32 /** @file Socket provider32 /** @file HelenOS service implementation 33 33 */ 34 34 35 #ifndef S OCK_H36 #define S OCK_H35 #ifndef SERVICE_H 36 #define SERVICE_H 37 37 38 #include <async.h> 39 40 extern int udp_sock_init(void); 38 extern int udp_service_init(void); 41 39 42 40 #endif -
uspace/srv/net/udp/ucall.c
rba0eac5 rfab2746 35 35 */ 36 36 37 #include <errno.h> 37 38 #include <io/log.h> 38 39 #include <macros.h> 40 #include <mem.h> 39 41 40 42 #include "assoc.h" … … 48 50 49 51 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_create()"); 50 nassoc = udp_assoc_new(NULL, NULL );52 nassoc = udp_assoc_new(NULL, NULL, NULL, NULL); 51 53 if (nassoc == NULL) 52 54 return UDP_ENORES; … … 125 127 case EOK: 126 128 break; 127 case E CONNABORTED:129 case ENXIO: 128 130 return UDP_ERESET; 129 131 default: -
uspace/srv/net/udp/udp.c
rba0eac5 rfab2746 41 41 #include <task.h> 42 42 43 #include "service.h" 43 44 #include "udp_inet.h" 44 #include "sock.h"45 45 46 46 #define NAME "udp" … … 58 58 } 59 59 60 rc = udp_s ock_init();60 rc = udp_service_init(); 61 61 if (rc != EOK) { 62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socketservice.");62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing UDP service."); 63 63 return ENOENT; 64 64 } -
uspace/srv/net/udp/udp_type.h
rba0eac5 rfab2746 36 36 #define UDP_TYPE_H 37 37 38 #include <async.h> 38 39 #include <fibril.h> 39 40 #include <fibril_synch.h> 40 41 #include <ipc/loc.h> 41 #include <socket_core.h>42 42 #include <sys/types.h> 43 43 #include <inet/addr.h> … … 99 99 100 100 typedef struct { 101 async_sess_t *sess; 102 socket_cores_t sockets; 103 } udp_client_t; 101 void (*recv_msg)(void *, udp_sockpair_t *, udp_msg_t *); 102 } udp_assoc_cb_t; 104 103 105 104 /** UDP association … … 131 130 /** Receive queue CV. Broadcast when new datagram is inserted */ 132 131 fibril_condvar_t rcv_queue_cv; 132 133 udp_assoc_cb_t *cb; 134 void *cb_arg; 133 135 } udp_assoc_t; 134 136 135 137 typedef struct { 136 138 } udp_assoc_status_t; 137 138 typedef struct udp_sockdata {139 /** Lock */140 fibril_mutex_t lock;141 /** Socket core */142 socket_core_t *sock_core;143 /** Client */144 udp_client_t *client;145 /** Connection */146 udp_assoc_t *assoc;147 /** User-configured IP link */148 service_id_t iplink;149 /** Receiving fibril */150 fid_t recv_fibril;151 uint8_t recv_buffer[UDP_FRAGMENT_SIZE];152 size_t recv_buffer_used;153 udp_sock_t recv_fsock;154 fibril_mutex_t recv_buffer_lock;155 fibril_condvar_t recv_buffer_cv;156 udp_error_t recv_error;157 } udp_sockdata_t;158 139 159 140 typedef struct { … … 166 147 } udp_rcv_queue_entry_t; 167 148 149 typedef struct udp_cassoc { 150 /** Association */ 151 udp_assoc_t *assoc; 152 /** Association ID for the client */ 153 sysarg_t id; 154 /** Client */ 155 struct udp_client *client; 156 link_t lclient; 157 } udp_cassoc_t; 158 159 typedef struct { 160 /** Link to receive queue */ 161 link_t link; 162 /** Socket pair */ 163 udp_sockpair_t sp; 164 /** Message */ 165 udp_msg_t *msg; 166 /** Client association */ 167 udp_cassoc_t *cassoc; 168 } udp_crcv_queue_entry_t; 169 170 typedef struct udp_client { 171 /** Client callback session */ 172 async_sess_t *sess; 173 /** Client assocations */ 174 list_t cassoc; /* of udp_cassoc_t */ 175 /** Client receive queue */ 176 list_t crcv_queue; 177 } udp_client_t; 178 168 179 #endif 169 180
Note:
See TracChangeset
for help on using the changeset viewer.
