Changes in uspace/srv/net/inetsrv/inetping.c [13be2583:a1a101d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetping.c
r13be2583 ra1a101d 43 43 #include <stdlib.h> 44 44 #include <sys/types.h> 45 #include <types/inetping.h> 46 #include <net/socket_codes.h> 45 47 46 #include "icmp.h" 48 47 #include "icmp_std.h" … … 56 55 static uint16_t inetping_ident = 0; 57 56 57 static inetping_client_t *inetping_client_find(uint16_t); 58 58 59 static int inetping_send(inetping_client_t *client, inetping_sdu_t *sdu) 59 60 { … … 61 62 } 62 63 63 static int inetping_get_srcaddr(inetping_client_t *client, addr32_t remote, 64 addr32_t *local) 65 { 66 inet_addr_t remote_addr; 67 inet_addr_set(remote, &remote_addr); 68 69 inet_addr_t local_addr; 70 int rc = inet_get_srcaddr(&remote_addr, ICMP_TOS, &local_addr); 71 if (rc != EOK) 72 return rc; 73 74 uint16_t family = inet_addr_get(&local_addr, local, NULL); 75 if (family != AF_INET) 76 return EINVAL; 77 78 return EOK; 79 } 80 81 static inetping_client_t *inetping_client_find(uint16_t ident) 82 { 83 fibril_mutex_lock(&client_list_lock); 84 85 list_foreach(client_list, client_list, inetping_client_t, client) { 86 if (client->ident == ident) { 87 fibril_mutex_unlock(&client_list_lock); 88 return client; 89 } 90 } 91 92 fibril_mutex_unlock(&client_list_lock); 93 return NULL; 64 static int inetping_get_srcaddr(inetping_client_t *client, inet_addr_t *remote, 65 inet_addr_t *local) 66 { 67 return inet_get_srcaddr(remote, ICMP_TOS, local); 94 68 } 95 69 96 70 int inetping_recv(uint16_t ident, inetping_sdu_t *sdu) 97 71 { 98 inetping_client_t *client = inetping_client_find(ident); 72 inetping_client_t *client; 73 async_exch_t *exch; 74 ipc_call_t answer; 75 76 client = inetping_client_find(ident); 99 77 if (client == NULL) { 100 78 log_msg(LOG_DEFAULT, LVL_DEBUG, "Unknown ICMP ident. Dropping."); 101 79 return ENOENT; 102 80 } 103 104 async_exch_t *exch = async_exchange_begin(client->sess); 105 106 ipc_call_t answer; 107 aid_t req = async_send_3(exch, INETPING_EV_RECV, (sysarg_t) sdu->src, 108 (sysarg_t) sdu->dest, sdu->seq_no, &answer); 81 82 exch = async_exchange_begin(client->sess); 83 84 aid_t req = async_send_3(exch, INETPING_EV_RECV, sdu->src.ipv4, 85 sdu->dest.ipv4, sdu->seq_no, &answer); 109 86 int rc = async_data_write_start(exch, sdu->data, sdu->size); 110 111 87 async_exchange_end(exch); 112 88 113 89 if (rc != EOK) { 114 90 async_forget(req); 115 91 return rc; 116 92 } 117 93 118 94 sysarg_t retval; 119 95 async_wait_for(req, &retval); 120 121 return (int) retval; 96 if (retval != EOK) { 97 return retval; 98 } 99 100 return EOK; 122 101 } 123 102 … … 137 116 } 138 117 139 sdu.src = IPC_GET_ARG1(*call);140 sdu.dest = IPC_GET_ARG2(*call);118 sdu.src.ipv4 = IPC_GET_ARG1(*call); 119 sdu.dest.ipv4 = IPC_GET_ARG2(*call); 141 120 sdu.seq_no = IPC_GET_ARG3(*call); 142 121 … … 150 129 ipc_callid_t callid, ipc_call_t *call) 151 130 { 131 inet_addr_t remote; 132 inet_addr_t local; 133 int rc; 134 152 135 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetping_get_srcaddr_srv()"); 153 154 uint32_t remote= IPC_GET_ARG1(*call);155 uint32_t local= 0;156 157 int rc = inetping_get_srcaddr(client,remote, &local);158 async_answer_1(callid, rc, (sysarg_t) local);136 137 remote.ipv4 = IPC_GET_ARG1(*call); 138 local.ipv4 = 0; 139 140 rc = inetping_get_srcaddr(client, &remote, &local); 141 async_answer_1(callid, rc, local.ipv4); 159 142 } 160 143 … … 164 147 if (sess == NULL) 165 148 return ENOMEM; 166 149 167 150 client->sess = sess; 168 151 link_initialize(&client->client_list); 169 152 170 153 fibril_mutex_lock(&client_list_lock); 171 154 client->ident = ++inetping_ident; 172 155 list_append(&client->client_list, &client_list); 173 156 fibril_mutex_unlock(&client_list_lock); 174 157 175 158 return EOK; 176 159 } … … 180 163 async_hangup(client->sess); 181 164 client->sess = NULL; 182 165 183 166 fibril_mutex_lock(&client_list_lock); 184 167 list_remove(&client->client_list); … … 186 169 } 187 170 171 static inetping_client_t *inetping_client_find(uint16_t ident) 172 { 173 fibril_mutex_lock(&client_list_lock); 174 175 list_foreach(client_list, link) { 176 inetping_client_t *client = list_get_instance(link, 177 inetping_client_t, client_list); 178 179 if (client->ident == ident) { 180 fibril_mutex_unlock(&client_list_lock); 181 return client; 182 } 183 } 184 185 fibril_mutex_unlock(&client_list_lock); 186 return NULL; 187 } 188 188 189 void inetping_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 189 190 { 191 inetping_client_t client; 192 int rc; 193 190 194 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetping_conn()"); 191 195 192 196 /* Accept the connection */ 193 197 async_answer_0(iid, EOK); 194 195 inetping_client_t client; 196 int rc = inetping_client_init(&client); 198 199 rc = inetping_client_init(&client); 197 200 if (rc != EOK) 198 201 return; 199 202 200 203 while (true) { 201 204 ipc_call_t call; 202 205 ipc_callid_t callid = async_get_call(&call); 203 206 sysarg_t method = IPC_GET_IMETHOD(call); 204 207 205 208 if (!method) { 206 209 /* The other side has hung up */ … … 208 211 break; 209 212 } 210 213 211 214 switch (method) { 212 215 case INETPING_SEND: … … 220 223 } 221 224 } 222 225 223 226 inetping_client_fini(&client); 224 227 }
Note:
See TracChangeset
for help on using the changeset viewer.