Changes in uspace/srv/net/inetsrv/inetsrv.c [9ae6fc7:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetsrv.c
r9ae6fc7 rf9b2cb4c 46 46 #include <stdlib.h> 47 47 #include <sys/types.h> 48 #include < net/socket_codes.h>48 #include <task.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"58 57 #include "inet_link.h" 59 58 #include "reass.h" … … 63 62 64 63 static inet_naddr_t solicited_node_mask = { 65 . family = AF_INET6,64 .version = ip_v6, 66 65 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0}, 67 66 .prefix = 104 68 67 }; 69 68 69 static inet_addr_t broadcast4_all_hosts = { 70 .version = ip_v4, 71 .addr = 0xffffffff 72 }; 73 70 74 static inet_addr_t multicast_all_nodes = { 71 . family = AF_INET,75 .version = ip_v6, 72 76 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01} 73 77 }; 74 78 75 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);76 77 79 static FIBRIL_MUTEX_INITIALIZE(client_list_lock); 78 80 static LIST_INITIALIZE(client_list); 79 81 82 static void inet_default_conn(ipc_callid_t, ipc_call_t *, void *); 83 80 84 static int inet_init(void) 81 85 { 82 86 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()"); 83 87 84 async_set_client_connection(inet_client_conn); 85 86 int rc = loc_server_register(NAME); 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); 87 105 if (rc != EOK) { 88 106 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc); … … 91 109 92 110 service_id_t sid; 93 rc = loc_service_register_with_iface(SERVICE_NAME_INET, &sid, 94 INET_PORT_DEFAULT); 111 rc = loc_service_register(SERVICE_NAME_INET, &sid); 95 112 if (rc != EOK) { 96 113 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc); 97 114 return EEXIST; 98 115 } 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;135 116 136 117 return EOK; … … 186 167 { 187 168 inet_dir_t dir; 169 inet_link_t *ilink; 188 170 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 */ 189 192 190 193 rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir); … … 214 217 215 218 /* 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 216 226 inet_naddr_addr(&dir.aobj->naddr, local); 217 227 return EOK; … … 282 292 inet_dgram_t dgram; 283 293 284 dgram.tos = IPC_GET_ARG1(*icall); 285 286 uint8_t ttl = IPC_GET_ARG2(*icall); 287 int df = IPC_GET_ARG3(*icall); 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); 288 299 289 300 ipc_callid_t callid; … … 417 428 } 418 429 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 444 430 static inet_client_t *inet_client_find(uint8_t proto) 445 431 { 446 432 fibril_mutex_lock(&client_list_lock); 447 433 448 list_foreach(client_list, link) { 449 inet_client_t *client = list_get_instance(link, inet_client_t, 450 client_list); 451 434 list_foreach(client_list, client_list, inet_client_t, client) { 452 435 if (client->protocol == proto) { 453 436 fibril_mutex_unlock(&client_list_lock); … … 463 446 { 464 447 async_exch_t *exch = async_exchange_begin(client->sess); 465 448 466 449 ipc_call_t answer; 467 aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer); 468 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 469 457 int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t)); 470 458 if (rc != EOK) { … … 473 461 return rc; 474 462 } 475 463 476 464 rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t)); 477 465 if (rc != EOK) { … … 480 468 return rc; 481 469 } 482 470 483 471 rc = async_data_write_start(exch, dgram->data, dgram->size); 484 472 485 473 async_exchange_end(exch); 486 474 487 475 if (rc != EOK) { 488 476 async_forget(req); 489 477 return rc; 490 478 } 491 479 492 480 sysarg_t retval; 493 481 async_wait_for(req, &retval); 494 482 495 483 return (int) retval; 496 484 } … … 505 493 if (proto == IP_PROTO_ICMP) 506 494 return icmp_recv(dgram); 507 495 508 496 if (proto == IP_PROTO_ICMPV6) 509 497 return icmpv6_recv(dgram); … … 527 515 if ((addr != NULL) || 528 516 (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) || 529 (inet_addr_compare(&multicast_all_nodes, &packet->dest))) { 517 (inet_addr_compare(&multicast_all_nodes, &packet->dest)) || 518 (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) { 530 519 /* Destined for one of the local addresses */ 531 520 … … 533 522 if (packet->offs == 0 && !packet->mf) { 534 523 /* It is complete deliver it immediately */ 524 dgram.iplink = packet->link_id; 535 525 dgram.src = packet->src; 536 526 dgram.dest = packet->dest;
Note:
See TracChangeset
for help on using the changeset viewer.