Changeset 0ac2158 in mainline
- Timestamp:
- 2011-12-08T23:29:06Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d9e14fa4
- Parents:
- 5f9ecd3
- Location:
- uspace/srv/net/tl/tcp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/pdu.c
r5f9ecd3 r0ac2158 48 48 #define TCP_CHECKSUM_INIT 0xffff 49 49 50 /** One's complement addition. 51 * 52 * Result is a + b + carry. 53 */ 54 static uint16_t tcp_ocadd16(uint16_t a, uint16_t b) 55 { 56 uint32_t s; 57 58 s = (uint32_t)a + (uint32_t)b; 59 return (s & 0xffff) + (s >> 16); 60 } 61 50 62 static uint16_t tcp_checksum_calc(uint16_t ivalue, void *data, size_t size) 51 63 { 52 64 uint16_t sum; 65 uint16_t w; 53 66 size_t words, i; 54 67 uint8_t *bdata; … … 59 72 60 73 for (i = 0; i < words; i++) { 61 sum += ~(((uint16_t)bdata[2*i] << 8) + bdata[2*i + 1]); 74 w = ((uint16_t)bdata[2*i] << 8) | bdata[2*i + 1]; 75 sum = tcp_ocadd16(sum, w); 62 76 } 63 77 64 78 if (size % 2 != 0) { 65 sum += ~((uint16_t)bdata[2*words] << 8); 79 w = ((uint16_t)bdata[2*words] << 8); 80 sum = tcp_ocadd16(sum, w); 66 81 } 67 82 … … 237 252 238 253 hdr = (tcp_header_t *)pdu->header; 239 hdr->checksum = host2uint16_t_ le(checksum);254 hdr->checksum = host2uint16_t_be(checksum); 240 255 } 241 256 -
uspace/srv/net/tl/tcp/sock.c
r5f9ecd3 r0ac2158 39 39 #include <errno.h> 40 40 #include <io/log.h> 41 #include <ip_client.h> 41 42 #include <ipc/socket.h> 42 43 #include <net/modules.h> … … 106 107 107 108 sock->client = client; 109 sock->laddr.ipv4 = TCP_IPV4_ANY; 108 110 109 111 sock_id = SOCKET_GET_SOCKET_ID(call); … … 211 213 tcp_sockdata_t *socket; 212 214 tcp_error_t trc; 215 tcp_sock_t lsocket; 213 216 tcp_sock_t fsocket; 214 uint16_t lport; 217 device_id_t dev_id; 218 tcp_phdr_t *phdr; 219 size_t phdr_len; 215 220 216 221 log_msg(LVL_DEBUG, "tcp_sock_connect()"); … … 243 248 } 244 249 245 lport = sock_core->port; 250 if (socket->laddr.ipv4 == TCP_IPV4_ANY) { 251 /* Find route to determine local IP address. */ 252 rc = ip_get_route_req(ip_sess, IPPROTO_TCP, 253 (struct sockaddr *)addr, sizeof(*addr), &dev_id, 254 (void **)&phdr, &phdr_len); 255 if (rc != EOK) { 256 async_answer_0(callid, rc); 257 log_msg(LVL_DEBUG, "tcp_transmit_connect: Failed to find route."); 258 return; 259 } 260 261 socket->laddr.ipv4 = uint32_t_be2host(phdr->src_addr); 262 log_msg(LVL_DEBUG, "Local IP address is %x", socket->laddr.ipv4); 263 free(phdr); 264 } 265 266 lsocket.addr.ipv4 = socket->laddr.ipv4; 267 lsocket.port = sock_core->port; 246 268 fsocket.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 247 269 fsocket.port = uint16_t_be2host(addr->sin_port); 248 270 249 trc = tcp_uc_open( lport, &fsocket, ap_active, &socket->conn);271 trc = tcp_uc_open(&lsocket, &fsocket, ap_active, &socket->conn); 250 272 251 273 if (socket->conn != NULL) … … 280 302 tcp_sockdata_t *asocket; 281 303 tcp_error_t trc; 304 tcp_sock_t lsocket; 282 305 tcp_sock_t fsocket; 283 306 tcp_conn_t *conn; … … 305 328 log_msg(LVL_DEBUG, " - open connection"); 306 329 330 lsocket.addr.ipv4 = TCP_IPV4_ANY; 331 lsocket.port = sock_core->port; 307 332 fsocket.addr.ipv4 = TCP_IPV4_ANY; 308 333 fsocket.port = TCP_PORT_ANY; 309 334 310 trc = tcp_uc_open( sock_core->port, &fsocket, ap_passive, &conn);335 trc = tcp_uc_open(&lsocket, &fsocket, ap_passive, &conn); 311 336 if (conn != NULL) 312 337 conn->name = (char *)"S"; -
uspace/srv/net/tl/tcp/tcp.c
r5f9ecd3 r0ac2158 64 64 async_sess_t *net_sess; 65 65 static async_sess_t *icmp_sess; 66 staticasync_sess_t *ip_sess;66 async_sess_t *ip_sess; 67 67 packet_dimensions_t pkt_dims; 68 68 -
uspace/srv/net/tl/tcp/tcp.h
r5f9ecd3 r0ac2158 41 41 42 42 extern async_sess_t *net_sess; 43 extern async_sess_t *ip_sess; 43 44 extern void tcp_transmit_pdu(tcp_pdu_t *); 44 45 -
uspace/srv/net/tl/tcp/tcp_type.h
r5f9ecd3 r0ac2158 304 304 305 305 typedef struct { 306 /** Client */ 306 307 tcp_client_t *client; 308 /** Connection */ 307 309 tcp_conn_t *conn; 310 /** Local address */ 311 netaddr_t laddr; 308 312 } tcp_sockdata_t; 309 313 -
uspace/srv/net/tl/tcp/test.c
r5f9ecd3 r0ac2158 50 50 { 51 51 tcp_conn_t *conn; 52 tcp_sock_t sock; 52 tcp_sock_t lsock; 53 tcp_sock_t fsock; 53 54 char rcv_buf[RCV_BUF_SIZE + 1]; 54 55 size_t rcvd; … … 56 57 57 58 printf("test_srv()\n"); 58 sock.port = 1024; 59 sock.addr.ipv4 = 0x7f000001; 59 lsock.port = 80; 60 lsock.addr.ipv4 = 0x7f000001; 61 fsock.port = 1024; 62 fsock.addr.ipv4 = 0x7f000001; 60 63 printf("S: User open...\n"); 61 tcp_uc_open( 80, &sock, ap_passive, &conn);64 tcp_uc_open(&lsock, &fsock, ap_passive, &conn); 62 65 conn->name = (char *) "S"; 63 66 … … 86 89 { 87 90 tcp_conn_t *conn; 88 tcp_sock_t sock; 91 tcp_sock_t lsock; 92 tcp_sock_t fsock; 89 93 const char *msg = "Hello World!"; 90 94 91 95 printf("test_cli()\n"); 92 96 93 sock.port = 80; 94 sock.addr.ipv4 = 0x7f000001; 97 lsock.port = 1024; 98 lsock.addr.ipv4 = 0x7f000001; 99 fsock.port = 80; 100 fsock.addr.ipv4 = 0x7f000001; 95 101 96 102 async_usleep(1000*1000*3); 97 103 printf("C: User open...\n"); 98 tcp_uc_open( 1024, &sock, ap_active, &conn);104 tcp_uc_open(&lsock, &fsock, ap_active, &conn); 99 105 conn->name = (char *) "C"; 100 106 -
uspace/srv/net/tl/tcp/ucall.c
r5f9ecd3 r0ac2158 50 50 /** OPEN user call 51 51 * 52 * @param l port Local port52 * @param lsock Local socket 53 53 * @param fsock Foreign socket 54 54 * @param acpass Active/passive 55 55 * @param conn Connection 56 * 57 * Unlike in the spec we allow specifying the local address. This means 58 * the implementation does not need to magically guess it, especially 59 * considering there can be more than one local address. 56 60 * 57 61 * XXX We should be able to call active open on an existing listening … … 60 64 * establishment. 61 65 */ 62 tcp_error_t tcp_uc_open( uint16_t lport, tcp_sock_t *fsock, acpass_t acpass,66 tcp_error_t tcp_uc_open(tcp_sock_t *lsock, tcp_sock_t *fsock, acpass_t acpass, 63 67 tcp_conn_t **conn) 64 68 { 65 69 tcp_conn_t *nconn; 66 tcp_sock_t lsock; 67 68 log_msg(LVL_DEBUG, "tcp_uc_open(%" PRIu16 ", %p, %s, %p)", 69 lport, fsock, acpass == ap_active ? "active" : "passive", 70 71 log_msg(LVL_DEBUG, "tcp_uc_open(%p, %p, %s, %p)", 72 lsock, fsock, acpass == ap_active ? "active" : "passive", 70 73 conn); 71 74 72 lsock.port = lport; 73 lsock.addr.ipv4 = TCP_IPV4_ANY; 74 75 nconn = tcp_conn_new(&lsock, fsock); 75 nconn = tcp_conn_new(lsock, fsock); 76 76 tcp_conn_add(nconn); 77 77 … … 246 246 if (conn->ident.foreign.port == TCP_PORT_ANY) 247 247 conn->ident.foreign.port = sp->foreign.port; 248 if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY) 249 conn->ident.local.addr.ipv4 = sp->local.addr.ipv4; 248 250 249 251 tcp_conn_segment_arrived(conn, seg); -
uspace/srv/net/tl/tcp/ucall.h
r5f9ecd3 r0ac2158 42 42 * User calls 43 43 */ 44 extern tcp_error_t tcp_uc_open( uint16_t, tcp_sock_t *, acpass_t, tcp_conn_t **);44 extern tcp_error_t tcp_uc_open(tcp_sock_t *, tcp_sock_t *, acpass_t, tcp_conn_t **); 45 45 extern tcp_error_t tcp_uc_send(tcp_conn_t *, void *, size_t, xflags_t); 46 46 extern tcp_error_t tcp_uc_receive(tcp_conn_t *, void *, size_t, size_t *, xflags_t *);
Note:
See TracChangeset
for help on using the changeset viewer.