Changes in uspace/lib/c/generic/iplink_srv.c [02a09ed:962f03b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/iplink_srv.c
r02a09ed r962f03b 34 34 * @brief IP link server stub 35 35 */ 36 37 36 #include <errno.h> 38 37 #include <ipc/iplink.h> 39 38 #include <stdlib.h> 40 39 #include <sys/types.h> 41 #include <inet/addr.h> 40 42 41 #include <inet/iplink_srv.h> 43 42 … … 45 44 ipc_call_t *call) 46 45 { 46 int rc; 47 47 size_t mtu; 48 int rc = srv->ops->get_mtu(srv, &mtu); 48 49 rc = srv->ops->get_mtu(srv, &mtu); 49 50 async_answer_1(callid, rc, mtu); 50 51 } 51 52 52 static void iplink_addr_add_srv(iplink_srv_t *srv, ipc_callid_t iid,53 ipc_call_t * icall)53 static void iplink_addr_add_srv(iplink_srv_t *srv, ipc_callid_t callid, 54 ipc_call_t *call) 54 55 { 55 ipc_callid_t callid; 56 size_t size; 57 if (!async_data_write_receive(&callid, &size)) { 58 async_answer_0(callid, EREFUSED); 59 async_answer_0(iid, EREFUSED); 56 int rc; 57 iplink_srv_addr_t addr; 58 59 addr.ipv4 = IPC_GET_ARG1(*call); 60 61 rc = srv->ops->addr_add(srv, &addr); 62 async_answer_0(callid, rc); 63 } 64 65 static void iplink_addr_remove_srv(iplink_srv_t *srv, ipc_callid_t callid, 66 ipc_call_t *call) 67 { 68 int rc; 69 iplink_srv_addr_t addr; 70 71 addr.ipv4 = IPC_GET_ARG1(*call); 72 73 rc = srv->ops->addr_remove(srv, &addr); 74 async_answer_0(callid, rc); 75 } 76 77 static void iplink_send_srv(iplink_srv_t *srv, ipc_callid_t callid, 78 ipc_call_t *call) 79 { 80 iplink_srv_sdu_t sdu; 81 int rc; 82 83 sdu.lsrc.ipv4 = IPC_GET_ARG1(*call); 84 sdu.ldest.ipv4 = IPC_GET_ARG2(*call); 85 86 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 87 if (rc != EOK) { 88 async_answer_0(callid, rc); 60 89 return; 61 90 } 62 63 if (size != sizeof(inet_addr_t)) {64 async_answer_0(callid, EINVAL);65 async_answer_0(iid, EINVAL);66 return;67 }68 69 inet_addr_t addr;70 int rc = async_data_write_finalize(callid, &addr, size);71 if (rc != EOK) {72 async_answer_0(callid, (sysarg_t) rc);73 async_answer_0(iid, (sysarg_t) rc);74 }75 76 rc = srv->ops->addr_add(srv, &addr);77 async_answer_0(iid, (sysarg_t) rc);78 }79 91 80 static void iplink_addr_remove_srv(iplink_srv_t *srv, ipc_callid_t iid,81 ipc_call_t *icall)82 {83 ipc_callid_t callid;84 size_t size;85 if (!async_data_write_receive(&callid, &size)) {86 async_answer_0(callid, EREFUSED);87 async_answer_0(iid, EREFUSED);88 return;89 }90 91 if (size != sizeof(inet_addr_t)) {92 async_answer_0(callid, EINVAL);93 async_answer_0(iid, EINVAL);94 return;95 }96 97 inet_addr_t addr;98 int rc = async_data_write_finalize(callid, &addr, size);99 if (rc != EOK) {100 async_answer_0(callid, (sysarg_t) rc);101 async_answer_0(iid, (sysarg_t) rc);102 }103 104 rc = srv->ops->addr_remove(srv, &addr);105 async_answer_0(iid, (sysarg_t) rc);106 }107 108 static void iplink_send_srv(iplink_srv_t *srv, ipc_callid_t iid,109 ipc_call_t *icall)110 {111 iplink_sdu_t sdu;112 113 ipc_callid_t callid;114 size_t size;115 if (!async_data_write_receive(&callid, &size)) {116 async_answer_0(callid, EREFUSED);117 async_answer_0(iid, EREFUSED);118 return;119 }120 121 if (size != sizeof(inet_addr_t)) {122 async_answer_0(callid, EINVAL);123 async_answer_0(iid, EINVAL);124 return;125 }126 127 int rc = async_data_write_finalize(callid, &sdu.src, size);128 if (rc != EOK) {129 async_answer_0(callid, (sysarg_t) rc);130 async_answer_0(iid, (sysarg_t) rc);131 }132 133 if (!async_data_write_receive(&callid, &size)) {134 async_answer_0(callid, EREFUSED);135 async_answer_0(iid, EREFUSED);136 return;137 }138 139 if (size != sizeof(inet_addr_t)) {140 async_answer_0(callid, EINVAL);141 async_answer_0(iid, EINVAL);142 return;143 }144 145 rc = async_data_write_finalize(callid, &sdu.dest, size);146 if (rc != EOK) {147 async_answer_0(callid, (sysarg_t) rc);148 async_answer_0(iid, (sysarg_t) rc);149 }150 151 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0,152 &sdu.size);153 if (rc != EOK)154 return;155 156 92 rc = srv->ops->send(srv, &sdu); 157 93 free(sdu.data); 158 async_answer_0( iid, rc);94 async_answer_0(callid, rc); 159 95 } 160 96 … … 172 108 iplink_srv_t *srv = (iplink_srv_t *)arg; 173 109 int rc; 174 110 175 111 fibril_mutex_lock(&srv->lock); 176 112 if (srv->connected) { … … 179 115 return EBUSY; 180 116 } 181 117 182 118 srv->connected = true; 183 119 fibril_mutex_unlock(&srv->lock); 184 120 185 121 /* Accept the connection */ 186 122 async_answer_0(iid, EOK); 187 123 188 124 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 189 125 if (sess == NULL) 190 126 return ENOMEM; 191 127 192 128 srv->client_sess = sess; 193 129 194 130 rc = srv->ops->open(srv); 195 131 if (rc != EOK) 196 132 return rc; 197 133 198 134 while (true) { 199 135 ipc_call_t call; 200 136 ipc_callid_t callid = async_get_call(&call); 201 137 sysarg_t method = IPC_GET_IMETHOD(call); 202 138 203 139 if (!method) { 204 140 /* The other side has hung up */ 205 fibril_mutex_lock(&srv->lock);206 srv->connected = false;207 fibril_mutex_unlock(&srv->lock);208 141 async_answer_0(callid, EOK); 209 142 break; 210 143 } 211 144 212 145 switch (method) { 213 146 case IPLINK_GET_MTU: … … 227 160 } 228 161 } 229 162 230 163 return srv->ops->close(srv); 231 164 } 232 165 233 int iplink_ev_recv(iplink_srv_t *srv, iplink_ recv_sdu_t *sdu, uint16_t af)166 int iplink_ev_recv(iplink_srv_t *srv, iplink_srv_sdu_t *sdu) 234 167 { 235 168 if (srv->client_sess == NULL) 236 169 return EIO; 237 170 238 171 async_exch_t *exch = async_exchange_begin(srv->client_sess); 239 172 240 173 ipc_call_t answer; 241 aid_t req = async_send_1(exch, IPLINK_EV_RECV, (sysarg_t) af, 242 &answer); 243 174 aid_t req = async_send_2(exch, IPLINK_EV_RECV, sdu->lsrc.ipv4, 175 sdu->ldest.ipv4, &answer); 244 176 int rc = async_data_write_start(exch, sdu->data, sdu->size); 245 177 async_exchange_end(exch); 246 178 247 179 if (rc != EOK) { 248 async_ forget(req);180 async_wait_for(req, NULL); 249 181 return rc; 250 182 } 251 183 252 184 sysarg_t retval; 253 185 async_wait_for(req, &retval); 254 186 if (retval != EOK) 255 187 return retval; 256 188 257 189 return EOK; 258 190 }
Note:
See TracChangeset
for help on using the changeset viewer.