Changes in uspace/srv/net/inetsrv/inetsrv.c [4a5a18be:b323a3a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetsrv.c
r4a5a18be rb323a3a 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 "icmpv6.h" 53 #include "icmpv6_std.h" 52 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" … … 59 62 #define NAME "inetsrv" 60 63 64 static inet_naddr_t solicited_node_mask = { 65 .family = AF_INET6, 66 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0}, 67 .prefix = 104 68 }; 69 70 static inet_addr_t multicast_all_nodes = { 71 .family = AF_INET6, 72 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01} 73 }; 74 61 75 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); 62 76 … … 93 107 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid, 94 108 INET_PORT_PING); 109 if (rc != EOK) { 110 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 111 return EEXIST; 112 } 113 114 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING6, &sid, 115 INET_PORT_PING6); 95 116 if (rc != EOK) { 96 117 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); … … 104 125 } 105 126 106 sroute->dest.ipv4 = 0; 107 sroute->dest.bits = 0; 108 sroute->router.ipv4 = (10 << 24) | (0 << 16) | (2 << 8) | 2; 127 inet_naddr(&sroute->dest, 0, 0, 0, 0, 0); 128 inet_addr(&sroute->router, 10, 0, 2, 2); 109 129 sroute->name = str_dup("default"); 110 130 inet_sroute_add(sroute); 111 131 112 132 rc = inet_link_discovery_start(); 113 133 if (rc != EOK) 114 134 return EEXIST; … … 194 214 195 215 /* Take source address from the address object */ 196 local->ipv4 = dir.aobj->naddr.ipv4;216 inet_naddr_addr(&dir.aobj->naddr, local); 197 217 return EOK; 198 218 } 199 219 200 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t callid, 201 ipc_call_t *call) 202 { 220 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t iid, 221 ipc_call_t *icall) 222 { 223 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()"); 224 225 uint8_t tos = IPC_GET_ARG1(*icall); 226 227 ipc_callid_t callid; 228 size_t size; 229 if (!async_data_write_receive(&callid, &size)) { 230 async_answer_0(callid, EREFUSED); 231 async_answer_0(iid, EREFUSED); 232 return; 233 } 234 235 if (size != sizeof(inet_addr_t)) { 236 async_answer_0(callid, EINVAL); 237 async_answer_0(iid, EINVAL); 238 return; 239 } 240 203 241 inet_addr_t remote; 204 uint8_t tos; 242 int rc = async_data_write_finalize(callid, &remote, size); 243 if (rc != EOK) { 244 async_answer_0(callid, rc); 245 async_answer_0(iid, rc); 246 } 247 205 248 inet_addr_t local; 206 int rc;207 208 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()");209 210 remote.ipv4 = IPC_GET_ARG1(*call);211 tos = IPC_GET_ARG2(*call);212 local.ipv4 = 0;213 214 249 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 { 250 if (rc != EOK) { 251 async_answer_0(iid, rc); 252 return; 253 } 254 255 if (!async_data_read_receive(&callid, &size)) { 256 async_answer_0(callid, EREFUSED); 257 async_answer_0(iid, EREFUSED); 258 return; 259 } 260 261 if (size != sizeof(inet_addr_t)) { 262 async_answer_0(callid, EINVAL); 263 async_answer_0(iid, EINVAL); 264 return; 265 } 266 267 rc = async_data_read_finalize(callid, &local, size); 268 if (rc != EOK) { 269 async_answer_0(callid, rc); 270 async_answer_0(iid, rc); 271 return; 272 } 273 274 async_answer_0(iid, rc); 275 } 276 277 static void inet_send_srv(inet_client_t *client, ipc_callid_t iid, 278 ipc_call_t *icall) 279 { 280 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()"); 281 221 282 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); 283 284 dgram.tos = IPC_GET_ARG1(*icall); 285 286 uint8_t ttl = IPC_GET_ARG2(*icall); 287 int df = IPC_GET_ARG3(*icall); 288 289 ipc_callid_t callid; 290 size_t size; 291 if (!async_data_write_receive(&callid, &size)) { 292 async_answer_0(callid, EREFUSED); 293 async_answer_0(iid, EREFUSED); 294 return; 295 } 296 297 if (size != sizeof(inet_addr_t)) { 298 async_answer_0(callid, EINVAL); 299 async_answer_0(iid, EINVAL); 300 return; 301 } 302 303 int rc = async_data_write_finalize(callid, &dgram.src, size); 235 304 if (rc != EOK) { 236 305 async_answer_0(callid, rc); 237 return; 238 } 239 306 async_answer_0(iid, rc); 307 } 308 309 if (!async_data_write_receive(&callid, &size)) { 310 async_answer_0(callid, EREFUSED); 311 async_answer_0(iid, EREFUSED); 312 return; 313 } 314 315 if (size != sizeof(inet_addr_t)) { 316 async_answer_0(callid, EINVAL); 317 async_answer_0(iid, EINVAL); 318 return; 319 } 320 321 rc = async_data_write_finalize(callid, &dgram.dest, size); 322 if (rc != EOK) { 323 async_answer_0(callid, rc); 324 async_answer_0(iid, rc); 325 } 326 327 rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, 328 &dgram.size); 329 if (rc != EOK) { 330 async_answer_0(iid, rc); 331 return; 332 } 333 240 334 rc = inet_send(client, &dgram, client->protocol, ttl, df); 241 335 242 336 free(dgram.data); 243 async_answer_0( callid, rc);337 async_answer_0(iid, rc); 244 338 } 245 339 … … 339 433 inetping_conn(iid, icall, arg); 340 434 break; 435 case INET_PORT_PING6: 436 inetping6_conn(iid, icall, arg); 437 break; 341 438 default: 342 439 async_answer_0(iid, ENOTSUP); … … 366 463 { 367 464 async_exch_t *exch = async_exchange_begin(client->sess); 368 465 369 466 ipc_call_t answer; 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) { 467 aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer); 468 469 int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t)); 470 if (rc != EOK) { 471 async_exchange_end(exch); 376 472 async_forget(req); 377 473 return rc; 378 474 } 379 475 476 rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t)); 477 if (rc != EOK) { 478 async_exchange_end(exch); 479 async_forget(req); 480 return rc; 481 } 482 483 rc = async_data_write_start(exch, dgram->data, dgram->size); 484 485 async_exchange_end(exch); 486 487 if (rc != EOK) { 488 async_forget(req); 489 return rc; 490 } 491 380 492 sysarg_t retval; 381 493 async_wait_for(req, &retval); 382 if (retval != EOK) 383 return retval; 384 385 return EOK; 494 495 return (int) retval; 386 496 } 387 497 … … 392 502 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_recv_dgram_local()"); 393 503 394 /* ICMP messages are handled internally */504 /* ICMP and ICMPv6 messages are handled internally */ 395 505 if (proto == IP_PROTO_ICMP) 396 506 return icmp_recv(dgram); 507 508 if (proto == IP_PROTO_ICMPV6) 509 return icmpv6_recv(dgram); 397 510 398 511 client = inet_client_find(proto); … … 412 525 413 526 addr = inet_addrobj_find(&packet->dest, iaf_addr); 414 if (addr != NULL) { 527 if ((addr != NULL) || 528 (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) || 529 (inet_addr_compare(&multicast_all_nodes, &packet->dest))) { 415 530 /* Destined for one of the local addresses */ 416 531
Note:
See TracChangeset
for help on using the changeset viewer.