Changeset 19a4f73 in mainline for uspace/srv/net
- Timestamp:
- 2013-06-20T15:21:48Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2e3ee6
- Parents:
- 3e66428
- Location:
- uspace/srv/net/udp
- Files:
-
- 5 edited
-
assoc.c (modified) (5 diffs)
-
pdu.c (modified) (1 diff)
-
sock.c (modified) (7 diffs)
-
udp_inet.c (modified) (2 diffs)
-
udp_type.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/assoc.c
r3e66428 r19a4f73 82 82 if (lsock != NULL) 83 83 assoc->ident.local = *lsock; 84 84 85 if (fsock != NULL) 85 86 assoc->ident.foreign = *fsock; … … 251 252 sp.foreign = *fsock; 252 253 253 if (sp.foreign.addr.ipv4 == 0 || sp.foreign.port == 0) 254 if ((inet2_addr_is_any(&sp.foreign.addr)) || 255 (sp.foreign.port == UDP_PORT_ANY)) 254 256 return EINVAL; 255 257 … … 370 372 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt) 371 373 { 372 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_socket_match(sock=(%x,%u), pat=(%x,%u))", 373 sock->addr.ipv4, sock->port, patt->addr.ipv4, patt->port); 374 375 if (patt->addr.ipv4 != UDP_IPV4_ANY && 376 patt->addr.ipv4 != sock->addr.ipv4) 374 if ((!inet2_addr_is_any(&patt->addr)) && 375 (!inet2_addr_compare(&patt->addr, &sock->addr))) 377 376 return false; 378 379 if ( patt->port != UDP_PORT_ANY&&380 patt->port != sock->port)377 378 if ((patt->port != UDP_PORT_ANY) && 379 (patt->port != sock->port)) 381 380 return false; 382 381 383 382 log_msg(LOG_DEFAULT, LVL_DEBUG, " -> match"); 384 383 385 384 return true; 386 385 } … … 414 413 { 415 414 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp); 416 415 417 416 fibril_mutex_lock(&assoc_list_lock); 418 417 419 418 list_foreach(assoc_list, link) { 420 419 udp_assoc_t *assoc = list_get_instance(link, udp_assoc_t, link); 421 420 udp_sockpair_t *asp = &assoc->ident; 422 log_msg(LOG_DEFAULT, LVL_DEBUG, "compare with assoc (f:(%x,%u), l:(%x,%u))", 423 asp->foreign.addr.ipv4, asp->foreign.port, 424 asp->local.addr.ipv4, asp->local.port); 425 421 426 422 /* Skip unbound associations */ 427 423 if (asp->local.port == UDP_PORT_ANY) 428 424 continue; 429 425 430 426 if (udp_sockpair_match(sp, asp)) { 431 427 log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc); … … 435 431 } 436 432 } 437 433 438 434 fibril_mutex_unlock(&assoc_list_lock); 439 435 return NULL; -
uspace/srv/net/udp/pdu.c
r3e66428 r19a4f73 86 86 static void udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr) 87 87 { 88 phdr->src_addr = host2uint32_t_be(pdu->src.ipv4); 89 phdr->dest_addr = host2uint32_t_be(pdu->dest.ipv4); 88 // FIXME: Check for correctness 89 90 uint32_t src; 91 inet2_addr_pack(&pdu->src, &src); 92 93 uint32_t dest; 94 inet2_addr_pack(&pdu->dest, &dest); 95 96 phdr->src_addr = host2uint32_t_be(src); 97 phdr->dest_addr = host2uint32_t_be(dest); 90 98 phdr->zero = 0; 91 99 phdr->protocol = IP_PROTO_UDP; -
uspace/srv/net/udp/sock.c
r3e66428 r19a4f73 199 199 } 200 200 201 socket = (udp_sockdata_t *)sock_core->specific_data; 202 203 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 201 socket = (udp_sockdata_t *) sock_core->specific_data; 202 203 inet2_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr), 204 &fsock.addr); 204 205 fsock.port = sock_core->port; 205 206 urc = udp_uc_set_local(socket->assoc, &fsock); … … 269 270 } 270 271 271 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 272 inet2_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr), 273 &fsock.addr); 272 274 fsock.port = uint16_t_be2host(addr->sin_port); 273 275 fsock_ptr = &fsock; … … 314 316 fibril_mutex_lock(&socket->lock); 315 317 316 if ( socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) {318 if (inet2_addr_is_any(&socket->assoc->ident.local.addr)) { 317 319 /* Determine local IP address */ 318 inet_addr_t loc_addr, rem_addr; 319 320 rem_addr.ipv4 = fsock_ptr ? fsock.addr.ipv4 : 321 socket->assoc->ident.foreign.addr.ipv4; 322 323 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 320 inet2_addr_t loc_addr; 321 inet2_addr_t rem_addr; 322 323 rem_addr = fsock_ptr ? fsock.addr : 324 socket->assoc->ident.foreign.addr; 325 326 int rc = inet2_get_srcaddr(&rem_addr, 0, &loc_addr); 324 327 if (rc != EOK) { 325 328 fibril_mutex_unlock(&socket->lock); … … 330 333 } 331 334 332 socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4; 333 log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x", 334 socket->assoc->ident.local.addr.ipv4); 335 socket->assoc->ident.local.addr = loc_addr; 335 336 } 336 337 … … 410 411 size_t data_len; 411 412 udp_error_t urc; 412 udp_sock_t rsock;413 udp_sock_t *rsock; 413 414 struct sockaddr_in addr; 414 415 int rc; … … 446 447 log_msg(LOG_DEFAULT, LVL_DEBUG, "Got data in sock recv_buffer"); 447 448 448 rsock = socket->recv_fsock;449 rsock = &socket->recv_fsock; 449 450 data_len = socket->recv_buffer_used; 450 451 urc = socket->recv_error; … … 476 477 477 478 if (IPC_GET_IMETHOD(call) == NET_SOCKET_RECVFROM) { 478 /* Fill addr */ 479 /* Fill address */ 480 uint32_t rsock_addr; 481 int rc = inet2_addr_pack(&rsock->addr, &rsock_addr); 482 if (rc != EOK) { 483 fibril_mutex_unlock(&socket->recv_buffer_lock); 484 fibril_mutex_unlock(&socket->lock); 485 async_answer_0(callid, rc); 486 return; 487 } 488 479 489 addr.sin_family = AF_INET; 480 addr.sin_addr.s_addr = host2uint32_t_be(rsock .addr.ipv4);481 addr.sin_port = host2uint16_t_be(rsock .port);490 addr.sin_addr.s_addr = host2uint32_t_be(rsock_addr); 491 addr.sin_port = host2uint16_t_be(rsock->port); 482 492 483 493 log_msg(LOG_DEFAULT, LVL_DEBUG, "addr read receive"); -
uspace/srv/net/udp/udp_inet.c
r3e66428 r19a4f73 66 66 pdu->data = dgram->data; 67 67 pdu->data_size = dgram->size; 68 69 pdu->src.ipv4 = dgram->src.ipv4; 70 pdu->dest.ipv4 = dgram->dest.ipv4; 71 log_msg(LOG_DEFAULT, LVL_DEBUG, "src: 0x%08x, dest: 0x%08x", 72 pdu->src.ipv4, pdu->dest.ipv4); 68 69 inet_inet2(&dgram->src, &pdu->src); 70 inet_inet2(&dgram->dest, &pdu->dest); 73 71 74 72 udp_received_pdu(pdu); … … 86 84 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()"); 87 85 88 dgram.src.ipv4 = pdu->src.ipv4;89 dgram.dest.ipv4 = pdu->dest.ipv4;86 inet2_inet(&pdu->src, &dgram.src); 87 inet2_inet(&pdu->dest, &dgram.dest); 90 88 dgram.tos = 0; 91 89 dgram.data = pdu->data; -
uspace/srv/net/udp/udp_type.h
r3e66428 r19a4f73 40 40 #include <socket_core.h> 41 41 #include <sys/types.h> 42 #include <inet/addr2.h> 42 43 43 44 #define UDP_FRAGMENT_SIZE 4096 … … 57 58 58 59 typedef enum { 59 XF_DUMMY = 0x160 XF_DUMMY = 0x1 60 61 } xflags_t; 61 62 typedef struct {63 uint32_t ipv4;64 } netaddr_t;65 66 enum netaddr {67 UDP_IPV4_ANY = 068 };69 62 70 63 enum udp_port { … … 73 66 74 67 typedef struct { 75 netaddr_t addr;68 inet2_addr_t addr; 76 69 uint16_t port; 77 70 } udp_sock_t; … … 93 86 typedef struct { 94 87 /** Source address */ 95 netaddr_t src;88 inet2_addr_t src; 96 89 /** Destination address */ 97 netaddr_t dest;98 90 inet2_addr_t dest; 91 99 92 /** Encoded PDU data including header */ 100 93 void *data;
Note:
See TracChangeset
for help on using the changeset viewer.
