Changes in uspace/srv/net/ethip/ethip.c [06a1d077:1d24ad3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip.c
r06a1d077 r1d24ad3 44 44 #include <stdio.h> 45 45 #include <stdlib.h> 46 46 #include <net/socket_codes.h> 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_s rv_sdu_t *sdu);57 static int ethip_send(iplink_srv_t *srv, iplink_sdu_t *sdu); 58 58 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu); 59 static int ethip_addr_add(iplink_srv_t *srv, i plink_srv_addr_t *addr);60 static int ethip_addr_remove(iplink_srv_t *srv, i plink_srv_addr_t *addr);59 static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr); 60 static int ethip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr); 61 61 62 62 static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 73 73 static int ethip_init(void) 74 74 { 75 int rc;76 77 75 async_set_client_connection(ethip_client_conn); 78 79 rc = loc_server_register(NAME);80 if (rc != EOK) { 81 log_msg(L VL_ERROR, "Failed registering server.");76 77 int rc = loc_server_register(NAME); 78 if (rc != EOK) { 79 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server."); 82 80 return rc; 83 81 } 84 82 85 83 rc = ethip_nic_discovery_start(); 86 84 if (rc != EOK) 87 85 return rc; 88 86 89 87 return EOK; 90 88 } … … 98 96 char *svc_name = NULL; 99 97 100 log_msg(L VL_DEBUG, "ethip_iplink_init()");98 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_iplink_init()"); 101 99 102 100 iplink_srv_init(&nic->iplink); … … 106 104 rc = asprintf(&svc_name, "net/eth%u", ++link_num); 107 105 if (rc < 0) { 108 log_msg(L VL_ERROR, "Out of memory.");106 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory."); 109 107 goto error; 110 108 } … … 112 110 rc = loc_service_register(svc_name, &sid); 113 111 if (rc != EOK) { 114 log_msg(L VL_ERROR, "Failed registering service %s.", svc_name);112 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service %s.", svc_name); 115 113 goto error; 116 114 } … … 120 118 rc = loc_category_get_id("iplink", &iplink_cat, IPC_FLAG_BLOCKING); 121 119 if (rc != EOK) { 122 log_msg(L VL_ERROR, "Failed resolving category 'iplink'.");120 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed resolving category 'iplink'."); 123 121 goto error; 124 122 } … … 126 124 rc = loc_service_add_to_cat(sid, iplink_cat); 127 125 if (rc != EOK) { 128 log_msg(L VL_ERROR, "Failed adding %s to category.", svc_name);126 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding %s to category.", svc_name); 129 127 goto error; 130 128 } … … 144 142 145 143 sid = (service_id_t)IPC_GET_ARG1(*icall); 146 log_msg(L VL_DEBUG, "ethip_client_conn(%u)", (unsigned)sid);144 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_client_conn(%u)", (unsigned)sid); 147 145 nic = ethip_nic_find_by_iplink_sid(sid); 148 146 if (nic == NULL) { 149 log_msg(L VL_WARN, "Uknown service ID.");147 log_msg(LOG_DEFAULT, LVL_WARN, "Uknown service ID."); 150 148 return; 151 149 } … … 156 154 static int ethip_open(iplink_srv_t *srv) 157 155 { 158 log_msg(L VL_DEBUG, "ethip_open()");156 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_open()"); 159 157 return EOK; 160 158 } … … 162 160 static int ethip_close(iplink_srv_t *srv) 163 161 { 164 log_msg(LVL_DEBUG, "ethip_close()"); 165 return EOK; 166 } 167 168 static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu) 169 { 170 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 162 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_close()"); 163 return EOK; 164 } 165 166 static int ethip_send(iplink_srv_t *srv, iplink_sdu_t *sdu) 167 { 168 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_send()"); 169 170 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 171 172 addr32_t src_v4; 173 addr128_t src_v6; 174 uint16_t src_af = inet_addr_get(&sdu->src, &src_v4, &src_v6); 175 176 addr32_t dest_v4; 177 addr128_t dest_v6; 178 uint16_t dest_af = inet_addr_get(&sdu->dest, &dest_v4, &dest_v6); 179 180 if (src_af != dest_af) 181 return EINVAL; 182 183 int rc; 171 184 eth_frame_t frame; 185 186 switch (src_af) { 187 case AF_INET: 188 rc = arp_translate(nic, src_v4, dest_v4, frame.dest); 189 if (rc != EOK) { 190 log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IPv4 address 0x%" 191 PRIx32, dest_v4); 192 return rc; 193 } 194 195 addr48(nic->mac_addr, frame.src); 196 frame.etype_len = ETYPE_IP; 197 frame.data = sdu->data; 198 frame.size = sdu->size; 199 200 break; 201 case AF_INET6: 202 // FIXME TODO 203 return ENOTSUP; 204 default: 205 return EINVAL; 206 } 207 172 208 void *data; 173 209 size_t size; 174 mac48_addr_t dest_mac_addr;175 int rc;176 177 log_msg(LVL_DEBUG, "ethip_send()");178 179 rc = arp_translate(nic, &sdu->lsrc, &sdu->ldest, &dest_mac_addr);180 if (rc != EOK) {181 log_msg(LVL_WARN, "Failed to look up IP address 0x%" PRIx32,182 sdu->ldest.ipv4);183 return rc;184 }185 186 frame.dest = dest_mac_addr;187 frame.src = nic->mac_addr;188 frame.etype_len = ETYPE_IP;189 frame.data = sdu->data;190 frame.size = sdu->size;191 192 210 rc = eth_pdu_encode(&frame, &data, &size); 193 211 if (rc != EOK) 194 212 return rc; 195 213 196 214 rc = ethip_nic_send(nic, data, size); 197 215 free(data); 198 216 199 217 return rc; 200 218 } … … 202 220 int ethip_received(iplink_srv_t *srv, void *data, size_t size) 203 221 { 204 log_msg(LVL_DEBUG, "ethip_received(): srv=%p", srv); 205 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 222 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_received(): srv=%p", srv); 223 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 224 225 log_msg(LOG_DEFAULT, LVL_DEBUG, " - eth_pdu_decode"); 226 206 227 eth_frame_t frame; 207 iplink_srv_sdu_t sdu; 208 int rc; 209 210 log_msg(LVL_DEBUG, "ethip_received()"); 211 212 log_msg(LVL_DEBUG, " - eth_pdu_decode"); 213 rc = eth_pdu_decode(data, size, &frame); 214 if (rc != EOK) { 215 log_msg(LVL_DEBUG, " - eth_pdu_decode failed"); 228 int rc = eth_pdu_decode(data, size, &frame); 229 if (rc != EOK) { 230 log_msg(LOG_DEFAULT, LVL_DEBUG, " - eth_pdu_decode failed"); 216 231 return rc; 217 232 } 218 233 234 iplink_recv_sdu_t sdu; 235 219 236 switch (frame.etype_len) { 220 237 case ETYPE_ARP: … … 222 239 break; 223 240 case ETYPE_IP: 224 log_msg(LVL_DEBUG, " - construct SDU"); 225 sdu.lsrc.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 1; 226 sdu.ldest.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 4; 241 log_msg(LOG_DEFAULT, LVL_DEBUG, " - construct SDU"); 227 242 sdu.data = frame.data; 228 243 sdu.size = frame.size; 229 log_msg(LVL_DEBUG, " - call iplink_ev_recv"); 230 rc = iplink_ev_recv(&nic->iplink, &sdu); 244 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call iplink_ev_recv"); 245 rc = iplink_ev_recv(&nic->iplink, &sdu, AF_INET); 246 break; 247 case ETYPE_IPV6: 248 log_msg(LOG_DEFAULT, LVL_DEBUG, " - construct SDU IPv6"); 249 sdu.data = frame.data; 250 sdu.size = frame.size; 251 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call iplink_ev_recv"); 252 rc = iplink_ev_recv(&nic->iplink, &sdu, AF_INET6); 231 253 break; 232 254 default: 233 log_msg(L VL_DEBUG, "Unknown ethertype 0x%" PRIx16,255 log_msg(LOG_DEFAULT, LVL_DEBUG, "Unknown ethertype 0x%" PRIx16, 234 256 frame.etype_len); 235 257 } 236 258 237 259 free(frame.data); 238 260 return rc; … … 241 263 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu) 242 264 { 243 log_msg(L VL_DEBUG, "ethip_get_mtu()");265 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_get_mtu()"); 244 266 *mtu = 1500; 245 267 return EOK; 246 268 } 247 269 248 static int ethip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr) 249 { 250 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 251 252 log_msg(LVL_DEBUG, "ethip_addr_add(0x%" PRIx32 ")", addr->ipv4); 270 static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr) 271 { 272 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 273 253 274 return ethip_nic_addr_add(nic, addr); 254 275 } 255 276 256 static int ethip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr) 257 { 258 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 259 260 log_msg(LVL_DEBUG, "ethip_addr_remove(0x%" PRIx32 ")", addr->ipv4); 261 return ethip_nic_addr_add(nic, addr); 277 static int ethip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr) 278 { 279 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 280 281 return ethip_nic_addr_remove(nic, addr); 262 282 } 263 283 … … 268 288 printf(NAME ": HelenOS IP over Ethernet service\n"); 269 289 270 if (log_init(NAME , LVL_WARN) != EOK) {290 if (log_init(NAME) != EOK) { 271 291 printf(NAME ": Failed to initialize logging.\n"); 272 292 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.