Changeset 02a09ed in mainline for uspace/srv/net/ethip/arp.c
- Timestamp:
- 2013-06-28T20:20:03Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d24ad3
- Parents:
- edf0d27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/arp.c
redf0d27 r02a09ed 38 38 #include <io/log.h> 39 39 #include <inet/iplink_srv.h> 40 #include <inet/addr.h> 40 41 #include <stdlib.h> 41 42 #include <net/socket_codes.h> 42 43 #include "arp.h" 43 44 #include "atrans.h" … … 54 55 void arp_received(ethip_nic_t *nic, eth_frame_t *frame) 55 56 { 56 int rc; 57 log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_received()"); 58 57 59 arp_eth_packet_t packet; 58 arp_eth_packet_t reply; 59 ethip_link_addr_t *laddr; 60 61 log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_received()"); 62 63 rc = arp_pdu_decode(frame->data, frame->size, &packet); 60 int rc = arp_pdu_decode(frame->data, frame->size, &packet); 64 61 if (rc != EOK) 65 62 return; 66 63 67 64 log_msg(LOG_DEFAULT, LVL_DEBUG, "ARP PDU decoded, opcode=%d, tpa=%x", 68 65 packet.opcode, packet.target_proto_addr); 69 70 laddr = ethip_nic_addr_find(nic, packet.target_proto_addr); 71 if (laddr != NULL) { 72 log_msg(LOG_DEFAULT, LVL_DEBUG, "Request/reply to my address"); 73 74 (void) atrans_add(packet.sender_proto_addr, 75 &packet.sender_hw_addr); 76 77 if (packet.opcode == aop_request) { 78 reply.opcode = aop_reply; 79 reply.sender_hw_addr = nic->mac_addr; 80 reply.sender_proto_addr = laddr->addr; 81 reply.target_hw_addr = packet.sender_hw_addr; 82 reply.target_proto_addr = packet.sender_proto_addr; 83 84 arp_send_packet(nic, &reply); 85 } 66 67 inet_addr_t addr; 68 inet_addr_set(packet.target_proto_addr, &addr); 69 70 ethip_link_addr_t *laddr = ethip_nic_addr_find(nic, &addr); 71 if (laddr == NULL) 72 return; 73 74 addr32_t laddr_v4; 75 uint16_t laddr_af = inet_addr_get(&laddr->addr, &laddr_v4, NULL); 76 if (laddr_af != AF_INET) 77 return; 78 79 log_msg(LOG_DEFAULT, LVL_DEBUG, "Request/reply to my address"); 80 81 (void) atrans_add(packet.sender_proto_addr, 82 packet.sender_hw_addr); 83 84 if (packet.opcode == aop_request) { 85 arp_eth_packet_t reply; 86 87 reply.opcode = aop_reply; 88 addr48(nic->mac_addr, reply.sender_hw_addr); 89 reply.sender_proto_addr = laddr_v4; 90 addr48(packet.sender_hw_addr, reply.target_hw_addr); 91 reply.target_proto_addr = packet.sender_proto_addr; 92 93 arp_send_packet(nic, &reply); 86 94 } 87 95 } 88 96 89 int arp_translate(ethip_nic_t *nic, uint32_t src_addr, uint32_t ip_addr,90 mac48_addr_t *mac_addr)97 int arp_translate(ethip_nic_t *nic, addr32_t src_addr, addr32_t ip_addr, 98 addr48_t mac_addr) 91 99 { 92 int rc; 93 arp_eth_packet_t packet; 94 95 rc = atrans_lookup(ip_addr, mac_addr); 100 int rc = atrans_lookup(ip_addr, mac_addr); 96 101 if (rc == EOK) 97 102 return EOK; 98 103 104 arp_eth_packet_t packet; 105 99 106 packet.opcode = aop_request; 100 packet.sender_hw_addr = nic->mac_addr;107 addr48(nic->mac_addr, packet.sender_hw_addr); 101 108 packet.sender_proto_addr = src_addr; 102 packet.target_hw_addr.addr = MAC48_BROADCAST;109 addr48(addr48_broadcast, packet.target_hw_addr); 103 110 packet.target_proto_addr = ip_addr; 104 111 105 112 rc = arp_send_packet(nic, &packet); 106 113 if (rc != EOK) … … 128 135 return rc; 129 136 130 frame.dest.addr = packet->target_hw_addr.addr;131 frame.src.addr = packet->sender_hw_addr.addr;137 addr48(packet->target_hw_addr, frame.dest); 138 addr48(packet->sender_hw_addr, frame.src); 132 139 frame.etype_len = ETYPE_ARP; 133 140 frame.data = pdata;
Note:
See TracChangeset
for help on using the changeset viewer.