Changes in uspace/srv/net/ethip/ethip.c [a17356fd:a1a101d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip.c
ra17356fd ra1a101d 44 44 #include <stdio.h> 45 45 #include <stdlib.h> 46 #include <net/socket_codes.h> 46 47 47 #include "arp.h" 48 48 #include "ethip.h" … … 55 55 static int ethip_open(iplink_srv_t *srv); 56 56 static int ethip_close(iplink_srv_t *srv); 57 static int ethip_send(iplink_srv_t *srv, iplink_sdu_t *sdu); 58 static int ethip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu); 57 static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu); 59 58 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu); 60 static int ethip_get_mac48(iplink_srv_t *srv, addr48_t *mac); 61 static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr); 62 static int ethip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr); 59 static int ethip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr); 60 static int ethip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr); 63 61 64 62 static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 68 66 .close = ethip_close, 69 67 .send = ethip_send, 70 .send6 = ethip_send6,71 68 .get_mtu = ethip_get_mtu, 72 .get_mac48 = ethip_get_mac48,73 69 .addr_add = ethip_addr_add, 74 70 .addr_remove = ethip_addr_remove … … 168 164 } 169 165 170 static int ethip_send(iplink_srv_t *srv, iplink_sdu_t *sdu) 171 { 166 static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu) 167 { 168 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 169 eth_frame_t frame; 170 void *data; 171 size_t size; 172 mac48_addr_t dest_mac_addr; 173 int rc; 174 172 175 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_send()"); 173 174 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 175 eth_frame_t frame; 176 177 int rc = arp_translate(nic, sdu->src, sdu->dest, frame.dest); 178 if (rc != EOK) { 179 log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IPv4 address 0x%" 180 PRIx32, sdu->dest); 181 return rc; 182 } 183 184 addr48(nic->mac_addr, frame.src); 176 177 rc = arp_translate(nic, &sdu->lsrc, &sdu->ldest, &dest_mac_addr); 178 if (rc != EOK) { 179 log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IP address 0x%" PRIx32, 180 sdu->ldest.ipv4); 181 return rc; 182 } 183 184 frame.dest = dest_mac_addr; 185 frame.src = nic->mac_addr; 185 186 frame.etype_len = ETYPE_IP; 186 187 frame.data = sdu->data; 187 188 frame.size = sdu->size; 188 189 void *data; 190 size_t size; 189 191 190 rc = eth_pdu_encode(&frame, &data, &size); 192 191 if (rc != EOK) 193 192 return rc; 194 193 195 194 rc = ethip_nic_send(nic, data, size); 196 195 free(data); 197 196 198 197 return rc; 199 198 } 200 199 201 static int ethip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu) 202 { 203 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_send6()"); 204 205 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 200 int ethip_received(iplink_srv_t *srv, void *data, size_t size) 201 { 202 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_received(): srv=%p", srv); 203 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 206 204 eth_frame_t frame; 207 208 addr48(sdu->dest, frame.dest); 209 addr48(nic->mac_addr, frame.src); 210 frame.etype_len = ETYPE_IPV6; 211 frame.data = sdu->data; 212 frame.size = sdu->size; 213 214 void *data; 215 size_t size; 216 int rc = eth_pdu_encode(&frame, &data, &size); 217 if (rc != EOK) 218 return rc; 219 220 rc = ethip_nic_send(nic, data, size); 221 free(data); 222 223 return rc; 224 } 225 226 int ethip_received(iplink_srv_t *srv, void *data, size_t size) 227 { 228 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_received(): srv=%p", srv); 229 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 230 205 iplink_srv_sdu_t sdu; 206 int rc; 207 208 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_received()"); 209 231 210 log_msg(LOG_DEFAULT, LVL_DEBUG, " - eth_pdu_decode"); 232 233 eth_frame_t frame; 234 int rc = eth_pdu_decode(data, size, &frame); 211 rc = eth_pdu_decode(data, size, &frame); 235 212 if (rc != EOK) { 236 213 log_msg(LOG_DEFAULT, LVL_DEBUG, " - eth_pdu_decode failed"); 237 214 return rc; 238 215 } 239 240 iplink_recv_sdu_t sdu; 241 216 242 217 switch (frame.etype_len) { 243 218 case ETYPE_ARP: … … 246 221 case ETYPE_IP: 247 222 log_msg(LOG_DEFAULT, LVL_DEBUG, " - construct SDU"); 223 sdu.lsrc.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 1; 224 sdu.ldest.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 4; 248 225 sdu.data = frame.data; 249 226 sdu.size = frame.size; 250 227 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call iplink_ev_recv"); 251 rc = iplink_ev_recv(&nic->iplink, &sdu, AF_INET); 252 break; 253 case ETYPE_IPV6: 254 log_msg(LOG_DEFAULT, LVL_DEBUG, " - construct SDU IPv6"); 255 sdu.data = frame.data; 256 sdu.size = frame.size; 257 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call iplink_ev_recv"); 258 rc = iplink_ev_recv(&nic->iplink, &sdu, AF_INET6); 228 rc = iplink_ev_recv(&nic->iplink, &sdu); 259 229 break; 260 230 default: … … 262 232 frame.etype_len); 263 233 } 264 234 265 235 free(frame.data); 266 236 return rc; … … 274 244 } 275 245 276 static int ethip_get_mac48(iplink_srv_t *srv, addr48_t *mac) 277 { 278 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_get_mac48()"); 279 280 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 281 addr48(nic->mac_addr, *mac); 282 283 return EOK; 284 } 285 286 static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr) 287 { 288 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 289 246 static int ethip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr) 247 { 248 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 249 250 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_addr_add(0x%" PRIx32 ")", addr->ipv4); 290 251 return ethip_nic_addr_add(nic, addr); 291 252 } 292 253 293 static int ethip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr) 294 { 295 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 296 297 return ethip_nic_addr_remove(nic, addr); 254 static int ethip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr) 255 { 256 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 257 258 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_addr_remove(0x%" PRIx32 ")", addr->ipv4); 259 return ethip_nic_addr_add(nic, addr); 298 260 } 299 261
Note:
See TracChangeset
for help on using the changeset viewer.