Changes in uspace/srv/net/inetsrv/inetsrv.c [d8b47eca:4a5a18be] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetsrv.c
rd8b47eca r4a5a18be 46 46 #include <stdlib.h> 47 47 #include <sys/types.h> 48 #include <net/socket_codes.h> 48 49 49 #include "addrobj.h" 50 50 #include "icmp.h" 51 51 #include "icmp_std.h" 52 #include "icmpv6.h"53 #include "icmpv6_std.h"54 52 #include "inetsrv.h" 55 53 #include "inetcfg.h" 56 54 #include "inetping.h" 57 #include "inetping6.h"58 55 #include "inet_link.h" 59 56 #include "reass.h" … … 96 93 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid, 97 94 INET_PORT_PING); 98 if (rc != EOK) {99 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);100 return EEXIST;101 }102 103 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING6, &sid,104 INET_PORT_PING6);105 95 if (rc != EOK) { 106 96 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); … … 114 104 } 115 105 116 inet_naddr(&sroute->dest, 0, 0, 0, 0, 0); 117 inet_addr(&sroute->router, 10, 0, 2, 2); 106 sroute->dest.ipv4 = 0; 107 sroute->dest.bits = 0; 108 sroute->router.ipv4 = (10 << 24) | (0 << 16) | (2 << 8) | 2; 118 109 sroute->name = str_dup("default"); 119 110 inet_sroute_add(sroute); 120 111 121 rc = inet_link_discovery_start();112 rc = inet_link_discovery_start(); 122 113 if (rc != EOK) 123 114 return EEXIST; … … 203 194 204 195 /* Take source address from the address object */ 205 inet_naddr_addr(&dir.aobj->naddr, local);196 local->ipv4 = dir.aobj->naddr.ipv4; 206 197 return EOK; 207 198 } 208 199 209 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t iid, 210 ipc_call_t *icall) 211 { 200 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t callid, 201 ipc_call_t *call) 202 { 203 inet_addr_t remote; 204 uint8_t tos; 205 inet_addr_t local; 206 int rc; 207 212 208 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()"); 213 214 uint8_t tos = IPC_GET_ARG1(*icall); 215 216 ipc_callid_t callid; 217 size_t size; 218 if (!async_data_write_receive(&callid, &size)) { 219 async_answer_0(callid, EREFUSED); 220 async_answer_0(iid, EREFUSED); 209 210 remote.ipv4 = IPC_GET_ARG1(*call); 211 tos = IPC_GET_ARG2(*call); 212 local.ipv4 = 0; 213 214 rc = inet_get_srcaddr(&remote, tos, &local); 215 async_answer_1(callid, rc, local.ipv4); 216 } 217 218 static void inet_send_srv(inet_client_t *client, ipc_callid_t callid, 219 ipc_call_t *call) 220 { 221 inet_dgram_t dgram; 222 uint8_t ttl; 223 int df; 224 int rc; 225 226 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()"); 227 228 dgram.src.ipv4 = IPC_GET_ARG1(*call); 229 dgram.dest.ipv4 = IPC_GET_ARG2(*call); 230 dgram.tos = IPC_GET_ARG3(*call); 231 ttl = IPC_GET_ARG4(*call); 232 df = IPC_GET_ARG5(*call); 233 234 rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size); 235 if (rc != EOK) { 236 async_answer_0(callid, rc); 221 237 return; 222 238 } 223 224 if (size != sizeof(inet_addr_t)) { 225 async_answer_0(callid, EINVAL); 226 async_answer_0(iid, EINVAL); 227 return; 228 } 229 230 inet_addr_t remote; 231 int rc = async_data_write_finalize(callid, &remote, size); 232 if (rc != EOK) { 233 async_answer_0(callid, rc); 234 async_answer_0(iid, rc); 235 } 236 237 inet_addr_t local; 238 rc = inet_get_srcaddr(&remote, tos, &local); 239 if (rc != EOK) { 240 async_answer_0(iid, rc); 241 return; 242 } 243 244 if (!async_data_read_receive(&callid, &size)) { 245 async_answer_0(callid, EREFUSED); 246 async_answer_0(iid, EREFUSED); 247 return; 248 } 249 250 if (size != sizeof(inet_addr_t)) { 251 async_answer_0(callid, EINVAL); 252 async_answer_0(iid, EINVAL); 253 return; 254 } 255 256 rc = async_data_read_finalize(callid, &local, size); 257 if (rc != EOK) { 258 async_answer_0(callid, rc); 259 async_answer_0(iid, rc); 260 return; 261 } 262 263 async_answer_0(iid, rc); 264 } 265 266 static void inet_send_srv(inet_client_t *client, ipc_callid_t iid, 267 ipc_call_t *icall) 268 { 269 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()"); 270 271 inet_dgram_t dgram; 272 273 dgram.tos = IPC_GET_ARG1(*icall); 274 275 uint8_t ttl = IPC_GET_ARG2(*icall); 276 int df = IPC_GET_ARG3(*icall); 277 278 ipc_callid_t callid; 279 size_t size; 280 if (!async_data_write_receive(&callid, &size)) { 281 async_answer_0(callid, EREFUSED); 282 async_answer_0(iid, EREFUSED); 283 return; 284 } 285 286 if (size != sizeof(inet_addr_t)) { 287 async_answer_0(callid, EINVAL); 288 async_answer_0(iid, EINVAL); 289 return; 290 } 291 292 int rc = async_data_write_finalize(callid, &dgram.src, size); 293 if (rc != EOK) { 294 async_answer_0(callid, rc); 295 async_answer_0(iid, rc); 296 } 297 298 if (!async_data_write_receive(&callid, &size)) { 299 async_answer_0(callid, EREFUSED); 300 async_answer_0(iid, EREFUSED); 301 return; 302 } 303 304 if (size != sizeof(inet_addr_t)) { 305 async_answer_0(callid, EINVAL); 306 async_answer_0(iid, EINVAL); 307 return; 308 } 309 310 rc = async_data_write_finalize(callid, &dgram.dest, size); 311 if (rc != EOK) { 312 async_answer_0(callid, rc); 313 async_answer_0(iid, rc); 314 } 315 316 rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, 317 &dgram.size); 318 if (rc != EOK) { 319 async_answer_0(iid, rc); 320 return; 321 } 322 239 323 240 rc = inet_send(client, &dgram, client->protocol, ttl, df); 324 241 325 242 free(dgram.data); 326 async_answer_0( iid, rc);243 async_answer_0(callid, rc); 327 244 } 328 245 … … 422 339 inetping_conn(iid, icall, arg); 423 340 break; 424 case INET_PORT_PING6:425 inetping6_conn(iid, icall, arg);426 break;427 341 default: 428 342 async_answer_0(iid, ENOTSUP); … … 452 366 { 453 367 async_exch_t *exch = async_exchange_begin(client->sess); 454 368 455 369 ipc_call_t answer; 456 aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer); 457 458 int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t)); 459 if (rc != EOK) { 460 async_exchange_end(exch); 370 aid_t req = async_send_3(exch, INET_EV_RECV, dgram->src.ipv4, 371 dgram->dest.ipv4, dgram->tos, &answer); 372 int rc = async_data_write_start(exch, dgram->data, dgram->size); 373 async_exchange_end(exch); 374 375 if (rc != EOK) { 461 376 async_forget(req); 462 377 return rc; 463 378 } 464 465 rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t)); 466 if (rc != EOK) { 467 async_exchange_end(exch); 468 async_forget(req); 469 return rc; 470 } 471 472 rc = async_data_write_start(exch, dgram->data, dgram->size); 473 474 async_exchange_end(exch); 475 476 if (rc != EOK) { 477 async_forget(req); 478 return rc; 479 } 480 379 481 380 sysarg_t retval; 482 381 async_wait_for(req, &retval); 483 484 return (int) retval; 382 if (retval != EOK) 383 return retval; 384 385 return EOK; 485 386 } 486 387 … … 491 392 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_recv_dgram_local()"); 492 393 493 /* ICMP and ICMPv6messages are handled internally */394 /* ICMP messages are handled internally */ 494 395 if (proto == IP_PROTO_ICMP) 495 396 return icmp_recv(dgram); 496 497 if (proto == IP_PROTO_ICMPV6)498 return icmpv6_recv(dgram);499 397 500 398 client = inet_client_find(proto);
Note:
See TracChangeset
for help on using the changeset viewer.