Changes in uspace/srv/net/inetsrv/inetsrv.c [f9b2cb4c:9ae6fc7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetsrv.c
rf9b2cb4c r9ae6fc7 46 46 #include <stdlib.h> 47 47 #include <sys/types.h> 48 #include < task.h>48 #include <net/socket_codes.h> 49 49 #include "addrobj.h" 50 50 #include "icmp.h" … … 55 55 #include "inetcfg.h" 56 56 #include "inetping.h" 57 #include "inetping6.h" 57 58 #include "inet_link.h" 58 59 #include "reass.h" … … 62 63 63 64 static inet_naddr_t solicited_node_mask = { 64 . version = ip_v6,65 .family = AF_INET6, 65 66 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0}, 66 67 .prefix = 104 67 68 }; 68 69 69 static inet_addr_t broadcast4_all_hosts = {70 .version = ip_v4,71 .addr = 0xffffffff72 };73 74 70 static inet_addr_t multicast_all_nodes = { 75 . version = ip_v6,71 .family = AF_INET, 76 72 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01} 77 73 }; 78 74 75 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); 76 79 77 static FIBRIL_MUTEX_INITIALIZE(client_list_lock); 80 78 static LIST_INITIALIZE(client_list); 81 79 82 static void inet_default_conn(ipc_callid_t, ipc_call_t *, void *);83 84 80 static int inet_init(void) 85 81 { 86 82 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()"); 87 83 88 port_id_t port; 89 int rc = async_create_port(INTERFACE_INET, 90 inet_default_conn, NULL, &port); 91 if (rc != EOK) 92 return rc; 93 94 rc = async_create_port(INTERFACE_INETCFG, 95 inet_cfg_conn, NULL, &port); 96 if (rc != EOK) 97 return rc; 98 99 rc = async_create_port(INTERFACE_INETPING, 100 inetping_conn, NULL, &port); 101 if (rc != EOK) 102 return rc; 103 104 rc = loc_server_register(NAME); 84 async_set_client_connection(inet_client_conn); 85 86 int rc = loc_server_register(NAME); 105 87 if (rc != EOK) { 106 88 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc); … … 109 91 110 92 service_id_t sid; 111 rc = loc_service_register(SERVICE_NAME_INET, &sid); 93 rc = loc_service_register_with_iface(SERVICE_NAME_INET, &sid, 94 INET_PORT_DEFAULT); 112 95 if (rc != EOK) { 113 96 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 114 97 return EEXIST; 115 98 } 99 100 rc = loc_service_register_with_iface(SERVICE_NAME_INETCFG, &sid, 101 INET_PORT_CFG); 102 if (rc != EOK) { 103 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 104 return EEXIST; 105 } 106 107 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid, 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); 116 if (rc != EOK) { 117 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 118 return EEXIST; 119 } 120 121 inet_sroute_t *sroute = inet_sroute_new(); 122 if (sroute == NULL) { 123 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating default route (%d).", rc); 124 return ENOMEM; 125 } 126 127 inet_naddr(&sroute->dest, 0, 0, 0, 0, 0); 128 inet_addr(&sroute->router, 10, 0, 2, 2); 129 sroute->name = str_dup("default"); 130 inet_sroute_add(sroute); 131 132 rc = inet_link_discovery_start(); 133 if (rc != EOK) 134 return EEXIST; 116 135 117 136 return EOK; … … 167 186 { 168 187 inet_dir_t dir; 169 inet_link_t *ilink;170 188 int rc; 171 172 if (dgram->iplink != 0) {173 /* XXX TODO - IPv6 */174 log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram directly to iplink %zu",175 dgram->iplink);176 /* Send packet directly to the specified IP link */177 ilink = inet_link_get_by_id(dgram->iplink);178 if (ilink == 0)179 return ENOENT;180 181 if (dgram->src.version != ip_v4 ||182 dgram->dest.version != ip_v4)183 return EINVAL;184 185 return inet_link_send_dgram(ilink, dgram->src.addr,186 dgram->dest.addr, dgram, proto, ttl, df);187 }188 189 log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram to be routed");190 191 /* Route packet using source/destination addresses */192 189 193 190 rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir); … … 217 214 218 215 /* Take source address from the address object */ 219 if (remote->version == ip_v4 && remote->addr == 0xffffffff) {220 /* XXX TODO - IPv6 */221 local->version = ip_v4;222 local->addr = 0;223 return EOK;224 }225 226 216 inet_naddr_addr(&dir.aobj->naddr, local); 227 217 return EOK; … … 292 282 inet_dgram_t dgram; 293 283 294 dgram.iplink = IPC_GET_ARG1(*icall); 295 dgram.tos = IPC_GET_ARG2(*icall); 296 297 uint8_t ttl = IPC_GET_ARG3(*icall); 298 int df = IPC_GET_ARG4(*icall); 284 dgram.tos = IPC_GET_ARG1(*icall); 285 286 uint8_t ttl = IPC_GET_ARG2(*icall); 287 int df = IPC_GET_ARG3(*icall); 299 288 300 289 ipc_callid_t callid; … … 428 417 } 429 418 419 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 420 { 421 sysarg_t port; 422 423 port = IPC_GET_ARG1(*icall); 424 425 switch (port) { 426 case INET_PORT_DEFAULT: 427 inet_default_conn(iid, icall, arg); 428 break; 429 case INET_PORT_CFG: 430 inet_cfg_conn(iid, icall, arg); 431 break; 432 case INET_PORT_PING: 433 inetping_conn(iid, icall, arg); 434 break; 435 case INET_PORT_PING6: 436 inetping6_conn(iid, icall, arg); 437 break; 438 default: 439 async_answer_0(iid, ENOTSUP); 440 break; 441 } 442 } 443 430 444 static inet_client_t *inet_client_find(uint8_t proto) 431 445 { 432 446 fibril_mutex_lock(&client_list_lock); 433 447 434 list_foreach(client_list, client_list, inet_client_t, client) { 448 list_foreach(client_list, link) { 449 inet_client_t *client = list_get_instance(link, inet_client_t, 450 client_list); 451 435 452 if (client->protocol == proto) { 436 453 fibril_mutex_unlock(&client_list_lock); … … 446 463 { 447 464 async_exch_t *exch = async_exchange_begin(client->sess); 448 465 449 466 ipc_call_t answer; 450 451 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_ev_recv: iplink=%zu", 452 dgram->iplink); 453 454 aid_t req = async_send_2(exch, INET_EV_RECV, dgram->tos, 455 dgram->iplink, &answer); 456 467 aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer); 468 457 469 int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t)); 458 470 if (rc != EOK) { … … 461 473 return rc; 462 474 } 463 475 464 476 rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t)); 465 477 if (rc != EOK) { … … 468 480 return rc; 469 481 } 470 482 471 483 rc = async_data_write_start(exch, dgram->data, dgram->size); 472 484 473 485 async_exchange_end(exch); 474 486 475 487 if (rc != EOK) { 476 488 async_forget(req); 477 489 return rc; 478 490 } 479 491 480 492 sysarg_t retval; 481 493 async_wait_for(req, &retval); 482 494 483 495 return (int) retval; 484 496 } … … 493 505 if (proto == IP_PROTO_ICMP) 494 506 return icmp_recv(dgram); 495 507 496 508 if (proto == IP_PROTO_ICMPV6) 497 509 return icmpv6_recv(dgram); … … 515 527 if ((addr != NULL) || 516 528 (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) || 517 (inet_addr_compare(&multicast_all_nodes, &packet->dest)) || 518 (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) { 529 (inet_addr_compare(&multicast_all_nodes, &packet->dest))) { 519 530 /* Destined for one of the local addresses */ 520 531 … … 522 533 if (packet->offs == 0 && !packet->mf) { 523 534 /* It is complete deliver it immediately */ 524 dgram.iplink = packet->link_id;525 535 dgram.src = packet->src; 526 536 dgram.dest = packet->dest;
Note:
See TracChangeset
for help on using the changeset viewer.