Changes in uspace/srv/net/ethip/ethip.c [1d24ad3:06a1d077] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/ethip.c
r1d24ad3 r06a1d077 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_s du_t *sdu);57 static int ethip_send(iplink_srv_t *srv, iplink_srv_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 net_addr_t *addr);60 static int ethip_addr_remove(iplink_srv_t *srv, i net_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); 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 75 77 async_set_client_connection(ethip_client_conn); 76 77 intrc = loc_server_register(NAME);78 if (rc != EOK) { 79 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed registering server.");80 return rc; 81 } 82 78 79 rc = loc_server_register(NAME); 80 if (rc != EOK) { 81 log_msg(LVL_ERROR, "Failed registering server."); 82 return rc; 83 } 84 83 85 rc = ethip_nic_discovery_start(); 84 86 if (rc != EOK) 85 87 return rc; 86 88 87 89 return EOK; 88 90 } … … 96 98 char *svc_name = NULL; 97 99 98 log_msg(L OG_DEFAULT, LVL_DEBUG, "ethip_iplink_init()");100 log_msg(LVL_DEBUG, "ethip_iplink_init()"); 99 101 100 102 iplink_srv_init(&nic->iplink); … … 104 106 rc = asprintf(&svc_name, "net/eth%u", ++link_num); 105 107 if (rc < 0) { 106 log_msg(L OG_DEFAULT, LVL_ERROR, "Out of memory.");108 log_msg(LVL_ERROR, "Out of memory."); 107 109 goto error; 108 110 } … … 110 112 rc = loc_service_register(svc_name, &sid); 111 113 if (rc != EOK) { 112 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed registering service %s.", svc_name);114 log_msg(LVL_ERROR, "Failed registering service %s.", svc_name); 113 115 goto error; 114 116 } … … 118 120 rc = loc_category_get_id("iplink", &iplink_cat, IPC_FLAG_BLOCKING); 119 121 if (rc != EOK) { 120 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed resolving category 'iplink'.");122 log_msg(LVL_ERROR, "Failed resolving category 'iplink'."); 121 123 goto error; 122 124 } … … 124 126 rc = loc_service_add_to_cat(sid, iplink_cat); 125 127 if (rc != EOK) { 126 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed adding %s to category.", svc_name);128 log_msg(LVL_ERROR, "Failed adding %s to category.", svc_name); 127 129 goto error; 128 130 } … … 142 144 143 145 sid = (service_id_t)IPC_GET_ARG1(*icall); 144 log_msg(L OG_DEFAULT, LVL_DEBUG, "ethip_client_conn(%u)", (unsigned)sid);146 log_msg(LVL_DEBUG, "ethip_client_conn(%u)", (unsigned)sid); 145 147 nic = ethip_nic_find_by_iplink_sid(sid); 146 148 if (nic == NULL) { 147 log_msg(L OG_DEFAULT, LVL_WARN, "Uknown service ID.");149 log_msg(LVL_WARN, "Uknown service ID."); 148 150 return; 149 151 } … … 154 156 static int ethip_open(iplink_srv_t *srv) 155 157 { 156 log_msg(L OG_DEFAULT, LVL_DEBUG, "ethip_open()");158 log_msg(LVL_DEBUG, "ethip_open()"); 157 159 return EOK; 158 160 } … … 160 162 static int ethip_close(iplink_srv_t *srv) 161 163 { 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; 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; 184 171 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 TODO203 return ENOTSUP;204 default:205 return EINVAL;206 }207 208 172 void *data; 209 173 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 210 192 rc = eth_pdu_encode(&frame, &data, &size); 211 193 if (rc != EOK) 212 194 return rc; 213 195 214 196 rc = ethip_nic_send(nic, data, size); 215 197 free(data); 216 198 217 199 return rc; 218 200 } … … 220 202 int ethip_received(iplink_srv_t *srv, void *data, size_t size) 221 203 { 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 204 log_msg(LVL_DEBUG, "ethip_received(): srv=%p", srv); 205 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 227 206 eth_frame_t frame; 228 int rc = eth_pdu_decode(data, size, &frame); 229 if (rc != EOK) { 230 log_msg(LOG_DEFAULT, LVL_DEBUG, " - eth_pdu_decode failed"); 231 return rc; 232 } 233 234 iplink_recv_sdu_t sdu; 235 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"); 216 return rc; 217 } 218 236 219 switch (frame.etype_len) { 237 220 case ETYPE_ARP: … … 239 222 break; 240 223 case ETYPE_IP: 241 log_msg(LOG_DEFAULT, LVL_DEBUG, " - construct SDU"); 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; 242 227 sdu.data = frame.data; 243 228 sdu.size = frame.size; 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); 229 log_msg(LVL_DEBUG, " - call iplink_ev_recv"); 230 rc = iplink_ev_recv(&nic->iplink, &sdu); 253 231 break; 254 232 default: 255 log_msg(L OG_DEFAULT, LVL_DEBUG, "Unknown ethertype 0x%" PRIx16,233 log_msg(LVL_DEBUG, "Unknown ethertype 0x%" PRIx16, 256 234 frame.etype_len); 257 235 } 258 236 259 237 free(frame.data); 260 238 return rc; … … 263 241 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu) 264 242 { 265 log_msg(L OG_DEFAULT, LVL_DEBUG, "ethip_get_mtu()");243 log_msg(LVL_DEBUG, "ethip_get_mtu()"); 266 244 *mtu = 1500; 267 245 return EOK; 268 246 } 269 247 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 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); 274 253 return ethip_nic_addr_add(nic, addr); 275 254 } 276 255 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); 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); 282 262 } 283 263 … … 288 268 printf(NAME ": HelenOS IP over Ethernet service\n"); 289 269 290 if (log_init(NAME ) != EOK) {270 if (log_init(NAME, LVL_WARN) != EOK) { 291 271 printf(NAME ": Failed to initialize logging.\n"); 292 272 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.