Changeset 4c53333 in mainline for uspace/srv/net/inetsrv/inetsrv.c
- Timestamp:
- 2013-07-11T08:21:10Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 64e63ce1
- Parents:
- 80445cf (diff), c8bb1633 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetsrv.c
r80445cf r4c53333 46 46 #include <stdlib.h> 47 47 #include <sys/types.h> 48 48 #include <net/socket_codes.h> 49 49 #include "addrobj.h" 50 50 #include "icmp.h" 51 51 #include "icmp_std.h" 52 #include "inet.h" 52 #include "icmpv6.h" 53 #include "icmpv6_std.h" 54 #include "inetsrv.h" 53 55 #include "inetcfg.h" 54 56 #include "inetping.h" 57 #include "inetping6.h" 55 58 #include "inet_link.h" 56 59 #include "reass.h" 57 60 #include "sroute.h" 58 61 59 #define NAME "inet "62 #define NAME "inetsrv" 60 63 61 64 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 66 69 static int inet_init(void) 67 70 { 71 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()"); 72 73 async_set_client_connection(inet_client_conn); 74 75 int rc = loc_server_register(NAME); 76 if (rc != EOK) { 77 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc); 78 return EEXIST; 79 } 80 68 81 service_id_t sid; 69 int rc;70 71 log_msg(LVL_DEBUG, "inet_init()");72 73 async_set_client_connection(inet_client_conn);74 75 rc = loc_server_register(NAME);76 if (rc != EOK) {77 log_msg(LVL_ERROR, "Failed registering server (%d).", rc);78 return EEXIST;79 }80 81 82 rc = loc_service_register_with_iface(SERVICE_NAME_INET, &sid, 82 83 INET_PORT_DEFAULT); 83 84 if (rc != EOK) { 84 log_msg(L VL_ERROR, "Failed registering service (%d).", rc);85 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 85 86 return EEXIST; 86 87 } 87 88 88 89 rc = loc_service_register_with_iface(SERVICE_NAME_INETCFG, &sid, 89 90 INET_PORT_CFG); 90 91 if (rc != EOK) { 91 log_msg(L VL_ERROR, "Failed registering service (%d).", rc);92 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 92 93 return EEXIST; 93 94 } 94 95 95 96 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid, 96 97 INET_PORT_PING); 97 98 if (rc != EOK) { 98 log_msg(L VL_ERROR, "Failed registering service (%d).", rc);99 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 99 100 return EEXIST; 100 101 } 102 103 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING6, &sid, 104 INET_PORT_PING6); 105 if (rc != EOK) { 106 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 107 return EEXIST; 108 } 109 110 inet_sroute_t *sroute = inet_sroute_new(); 111 if (sroute == NULL) { 112 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating default route (%d).", rc); 113 return ENOMEM; 114 } 115 116 inet_naddr(&sroute->dest, 0, 0, 0, 0, 0); 117 inet_addr(&sroute->router, 10, 0, 2, 2); 118 sroute->name = str_dup("default"); 119 inet_sroute_add(sroute); 101 120 102 121 rc = inet_link_discovery_start(); 103 122 if (rc != EOK) 104 123 return EEXIST; 105 124 106 125 return EOK; 107 126 } … … 110 129 ipc_call_t *call) 111 130 { 112 log_msg(L VL_DEBUG, "inet_callback_create_srv()");131 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_callback_create_srv()"); 113 132 114 133 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); … … 145 164 146 165 if (dir->aobj == NULL) { 147 log_msg(L VL_DEBUG, "inet_send: No route to destination.");166 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send: No route to destination."); 148 167 return ENOENT; 149 168 } … … 184 203 185 204 /* Take source address from the address object */ 186 local->ipv4 = dir.aobj->naddr.ipv4;205 inet_naddr_addr(&dir.aobj->naddr, local); 187 206 return EOK; 188 207 } 189 208 190 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t callid, 191 ipc_call_t *call) 192 { 209 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t iid, 210 ipc_call_t *icall) 211 { 212 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); 221 return; 222 } 223 224 if (size != sizeof(inet_addr_t)) { 225 async_answer_0(callid, EINVAL); 226 async_answer_0(iid, EINVAL); 227 return; 228 } 229 193 230 inet_addr_t remote; 194 uint8_t tos; 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 195 237 inet_addr_t local; 196 int rc;197 198 log_msg(LVL_DEBUG, "inet_get_srcaddr_srv()");199 200 remote.ipv4 = IPC_GET_ARG1(*call);201 tos = IPC_GET_ARG2(*call);202 local.ipv4 = 0;203 204 238 rc = inet_get_srcaddr(&remote, tos, &local); 205 async_answer_1(callid, rc, local.ipv4); 206 } 207 208 static void inet_send_srv(inet_client_t *client, ipc_callid_t callid, 209 ipc_call_t *call) 210 { 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 211 271 inet_dgram_t dgram; 212 uint8_t ttl; 213 int df; 214 int rc; 215 216 log_msg(LVL_DEBUG, "inet_send_srv()"); 217 218 dgram.src.ipv4 = IPC_GET_ARG1(*call); 219 dgram.dest.ipv4 = IPC_GET_ARG2(*call); 220 dgram.tos = IPC_GET_ARG3(*call); 221 ttl = IPC_GET_ARG4(*call); 222 df = IPC_GET_ARG5(*call); 223 224 rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size); 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); 225 293 if (rc != EOK) { 226 294 async_answer_0(callid, rc); 227 return; 228 } 229 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 230 323 rc = inet_send(client, &dgram, client->protocol, ttl, df); 231 324 232 325 free(dgram.data); 233 async_answer_0( callid, rc);326 async_answer_0(iid, rc); 234 327 } 235 328 … … 240 333 241 334 proto = IPC_GET_ARG1(*call); 242 log_msg(L VL_DEBUG, "inet_set_proto_srv(%lu)", (unsigned long) proto);335 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_set_proto_srv(%lu)", (unsigned long) proto); 243 336 244 337 if (proto > UINT8_MAX) { … … 274 367 inet_client_t client; 275 368 276 log_msg(L VL_DEBUG, "inet_default_conn()");369 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_default_conn()"); 277 370 278 371 /* Accept the connection */ … … 329 422 inetping_conn(iid, icall, arg); 330 423 break; 424 case INET_PORT_PING6: 425 inetping6_conn(iid, icall, arg); 426 break; 331 427 default: 332 428 async_answer_0(iid, ENOTSUP); … … 356 452 { 357 453 async_exch_t *exch = async_exchange_begin(client->sess); 358 454 359 455 ipc_call_t answer; 360 aid_t req = async_send_3(exch, INET_EV_RECV, dgram->src.ipv4, 361 dgram->dest.ipv4, dgram->tos, &answer); 362 int rc = async_data_write_start(exch, dgram->data, dgram->size); 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); 461 async_forget(req); 462 return rc; 463 } 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 363 474 async_exchange_end(exch); 364 365 if (rc != EOK) { 366 async_ wait_for(req, NULL);475 476 if (rc != EOK) { 477 async_forget(req); 367 478 return rc; 368 479 } 369 480 370 481 sysarg_t retval; 371 482 async_wait_for(req, &retval); 372 if (retval != EOK) 373 return retval; 374 375 return EOK; 483 484 return (int) retval; 376 485 } 377 486 … … 380 489 inet_client_t *client; 381 490 382 log_msg(L VL_DEBUG, "inet_recv_dgram_local()");383 384 /* ICMP messages are handled internally */491 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_recv_dgram_local()"); 492 493 /* ICMP and ICMPv6 messages are handled internally */ 385 494 if (proto == IP_PROTO_ICMP) 386 495 return icmp_recv(dgram); 496 497 if (proto == IP_PROTO_ICMPV6) 498 return icmpv6_recv(dgram); 387 499 388 500 client = inet_client_find(proto); 389 501 if (client == NULL) { 390 log_msg(L VL_DEBUG, "No client found for protocol 0x%" PRIx8,502 log_msg(LOG_DEFAULT, LVL_DEBUG, "No client found for protocol 0x%" PRIx8, 391 503 proto); 392 504 return ENOENT; … … 430 542 printf(NAME ": HelenOS Internet Protocol service\n"); 431 543 432 if (log_init(NAME , LVL_WARN) != EOK) {544 if (log_init(NAME) != EOK) { 433 545 printf(NAME ": Failed to initialize logging.\n"); 434 546 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.