Changeset 962f03b in mainline
- Timestamp:
- 2012-02-27T19:32:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 56792a2
- Parents:
- 87e5658c
- Location:
- uspace
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/iplink.c
r87e5658c r962f03b 121 121 } 122 122 123 int iplink_addr_add(iplink_t *iplink, iplink_addr_t *addr) 124 { 125 async_exch_t *exch = async_exchange_begin(iplink->sess); 126 127 int rc = async_req_1_0(exch, IPLINK_ADDR_ADD, (sysarg_t)addr->ipv4); 128 async_exchange_end(exch); 129 130 return rc; 131 } 132 133 int iplink_addr_remove(iplink_t *iplink, iplink_addr_t *addr) 134 { 135 async_exch_t *exch = async_exchange_begin(iplink->sess); 136 137 int rc = async_req_1_0(exch, IPLINK_ADDR_REMOVE, (sysarg_t)addr->ipv4); 138 async_exchange_end(exch); 139 140 return rc; 141 } 142 123 143 static void iplink_ev_recv(iplink_t *iplink, ipc_callid_t callid, 124 144 ipc_call_t *call) -
uspace/lib/c/generic/iplink_srv.c
r87e5658c r962f03b 49 49 rc = srv->ops->get_mtu(srv, &mtu); 50 50 async_answer_1(callid, rc, mtu); 51 } 52 53 static void iplink_addr_add_srv(iplink_srv_t *srv, ipc_callid_t callid, 54 ipc_call_t *call) 55 { 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); 51 75 } 52 76 … … 126 150 iplink_send_srv(srv, callid, &call); 127 151 break; 152 case IPLINK_ADDR_ADD: 153 iplink_addr_add_srv(srv, callid, &call); 154 break; 155 case IPLINK_ADDR_REMOVE: 156 iplink_addr_remove_srv(srv, callid, &call); 157 break; 128 158 default: 129 159 async_answer_0(callid, EINVAL); -
uspace/lib/c/include/inet/iplink.h
r87e5658c r962f03b 69 69 extern void iplink_close(iplink_t *); 70 70 extern int iplink_send(iplink_t *, iplink_sdu_t *); 71 extern int iplink_addr_add(iplink_t *, iplink_addr_t *); 72 extern int iplink_addr_remove(iplink_t *, iplink_addr_t *); 71 73 extern int iplink_get_mtu(iplink_t *, size_t *); 72 74 -
uspace/lib/c/include/inet/iplink_srv.h
r87e5658c r962f03b 72 72 int (*send)(iplink_srv_t *, iplink_srv_sdu_t *); 73 73 int (*get_mtu)(iplink_srv_t *, size_t *); 74 int (*addr_add)(iplink_srv_t *, iplink_srv_addr_t *); 75 int (*addr_remove)(iplink_srv_t *, iplink_srv_addr_t *); 74 76 } iplink_ops_t; 75 77 -
uspace/lib/c/include/ipc/iplink.h
r87e5658c r962f03b 40 40 typedef enum { 41 41 IPLINK_GET_MTU = IPC_FIRST_USER_METHOD, 42 IPLINK_SEND 42 IPLINK_SEND, 43 IPLINK_ADDR_ADD, 44 IPLINK_ADDR_REMOVE 43 45 } iplink_request_t; 44 46 -
uspace/srv/ethip/arp.c
r87e5658c r962f03b 46 46 #include "std.h" 47 47 48 #define MY_IPV4_ADDR ( (192 << 24) | (168 << 16) | (0 << 8) | 4U )49 48 #define MY_ETH_ADDR 0xaafeedfaceee 50 49 … … 56 55 arp_eth_packet_t packet; 57 56 arp_eth_packet_t reply; 57 ethip_link_addr_t *laddr; 58 58 59 59 log_msg(LVL_DEBUG, "arp_received()"); … … 65 65 log_msg(LVL_DEBUG, "ARP PDU decoded, opcode=%d, tpa=%x", 66 66 packet.opcode, packet.target_proto_addr.ipv4); 67 if (packet.opcode == aop_request && 68 packet.target_proto_addr.ipv4 == MY_IPV4_ADDR) { 69 log_msg(LVL_DEBUG, "Request on my address"); 67 if (packet.opcode == aop_request) { 68 log_msg(LVL_DEBUG, "ARP request"); 70 69 71 reply.opcode = aop_reply; 72 reply.sender_hw_addr.addr = MY_ETH_ADDR; 73 reply.sender_proto_addr.ipv4 = MY_IPV4_ADDR; 74 reply.target_hw_addr = packet.sender_hw_addr; 75 reply.target_proto_addr = packet.sender_proto_addr; 70 laddr = ethip_nic_addr_find(nic, &packet.target_proto_addr); 71 if (laddr != NULL) { 72 log_msg(LVL_DEBUG, "Request on my address"); 76 73 77 arp_send_packet(nic, &reply); 74 reply.opcode = aop_reply; 75 reply.sender_hw_addr.addr = MY_ETH_ADDR; 76 reply.sender_proto_addr = laddr->addr; 77 reply.target_hw_addr = packet.sender_hw_addr; 78 reply.target_proto_addr = packet.sender_proto_addr; 79 80 arp_send_packet(nic, &reply); 81 } 78 82 } 79 83 } -
uspace/srv/ethip/ethip.c
r87e5658c r962f03b 57 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, iplink_srv_addr_t *addr); 60 static int ethip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr); 59 61 60 62 static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 64 66 .close = ethip_close, 65 67 .send = ethip_send, 66 .get_mtu = ethip_get_mtu 68 .get_mtu = ethip_get_mtu, 69 .addr_add = ethip_addr_add, 70 .addr_remove = ethip_addr_remove 67 71 }; 68 72 … … 234 238 } 235 239 240 static int ethip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr) 241 { 242 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 243 244 log_msg(LVL_DEBUG, "ethip_addr_add(0x%" PRIx32 ")", addr->ipv4); 245 return ethip_nic_addr_add(nic, addr); 246 } 247 248 static int ethip_addr_remove(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_remove(0x%" PRIx32 ")", addr->ipv4); 253 return ethip_nic_addr_add(nic, addr); 254 } 255 236 256 int main(int argc, char *argv[]) 237 257 { -
uspace/srv/ethip/ethip.h
r87e5658c r962f03b 52 52 iplink_srv_t iplink; 53 53 service_id_t iplink_sid; 54 55 /** List of IP addresses configured on this link */ 56 list_t addr_list; /* of ethip_link_addr_t */ 54 57 } ethip_nic_t; 58 59 typedef struct { 60 link_t addr_list; 61 iplink_srv_addr_t addr; 62 } ethip_link_addr_t; 55 63 56 64 /** IEEE MAC-48 identifier */ -
uspace/srv/ethip/ethip_nic.c
r87e5658c r962f03b 115 115 116 116 link_initialize(&nic->nic_list); 117 list_initialize(&nic->addr_list); 117 118 118 119 return nic; 120 } 121 122 static ethip_link_addr_t *ethip_nic_addr_new(iplink_srv_addr_t *addr) 123 { 124 ethip_link_addr_t *laddr = calloc(1, sizeof(ethip_link_addr_t)); 125 126 if (laddr == NULL) { 127 log_msg(LVL_ERROR, "Failed allocating NIC address structure. " 128 "Out of memory."); 129 return NULL; 130 } 131 132 link_initialize(&laddr->addr_list); 133 laddr->addr.ipv4 = addr->ipv4; 134 return laddr; 119 135 } 120 136 … … 124 140 free(nic->svc_name); 125 141 free(nic); 142 } 143 144 static void ethip_link_addr_delete(ethip_link_addr_t *laddr) 145 { 146 free(laddr); 126 147 } 127 148 … … 308 329 rc = nic_send_frame(nic->sess, data, size); 309 330 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc); 310 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);311 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);312 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);313 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);314 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);315 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);316 log_msg(LVL_DEBUG, "nic_send_frame -> %d", rc);317 331 return rc; 332 } 333 334 int ethip_nic_addr_add(ethip_nic_t *nic, iplink_srv_addr_t *addr) 335 { 336 ethip_link_addr_t *laddr; 337 338 log_msg(LVL_DEBUG, "ethip_nic_addr_add()"); 339 laddr = ethip_nic_addr_new(addr); 340 if (laddr == NULL) 341 return ENOMEM; 342 343 list_append(&laddr->addr_list, &nic->addr_list); 344 return EOK; 345 } 346 347 int ethip_nic_addr_remove(ethip_nic_t *nic, iplink_srv_addr_t *addr) 348 { 349 ethip_link_addr_t *laddr; 350 351 log_msg(LVL_DEBUG, "ethip_nic_addr_remove()"); 352 353 laddr = ethip_nic_addr_find(nic, addr); 354 if (laddr == NULL) 355 return ENOENT; 356 357 list_remove(&laddr->addr_list); 358 ethip_link_addr_delete(laddr); 359 return EOK; 360 } 361 362 ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *nic, 363 iplink_srv_addr_t *addr) 364 { 365 log_msg(LVL_DEBUG, "ethip_nic_addr_find()"); 366 367 list_foreach(nic->addr_list, link) { 368 ethip_link_addr_t *laddr = list_get_instance(link, 369 ethip_link_addr_t, addr_list); 370 371 if (addr->ipv4 == laddr->addr.ipv4) 372 return laddr; 373 } 374 375 return NULL; 318 376 } 319 377 -
uspace/srv/ethip/ethip_nic.h
r87e5658c r962f03b 39 39 40 40 #include <ipc/loc.h> 41 #include "ethip.h" 41 42 42 43 extern int ethip_nic_discovery_start(void); 43 44 extern ethip_nic_t *ethip_nic_find_by_iplink_sid(service_id_t); 44 45 extern int ethip_nic_send(ethip_nic_t *, void *, size_t); 45 46 extern int ethip_nic_addr_add(ethip_nic_t *, iplink_srv_addr_t *); 47 extern int ethip_nic_addr_remove(ethip_nic_t *, iplink_srv_addr_t *); 48 extern ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *, 49 iplink_srv_addr_t *); 46 50 47 51 #endif -
uspace/srv/inet/inet_link.c
r87e5658c r962f03b 151 151 { 152 152 inet_link_t *ilink; 153 iplink_addr_t iaddr; 153 154 int rc; 154 155 … … 194 195 addr->ilink = ilink; 195 196 inet_addrobj_add(addr); 197 198 iaddr.ipv4 = addr->naddr.ipv4; 199 rc = iplink_addr_add(ilink->iplink, &iaddr); 200 if (rc != EOK) { 201 log_msg(LVL_ERROR, "Failed setting IP address on internet link."); 202 /* XXX Roll back */ 203 return rc; 204 } 196 205 197 206 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.