Changes in uspace/srv/net/ethip/arp.c [a1a101d:695b6ff] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/arp.c
ra1a101d r695b6ff 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 packet.opcode, packet.target_proto_addr.ipv4); 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 } 65 packet.opcode, packet.target_proto_addr); 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, iplink_srv_addr_t *src_addr,90 iplink_srv_addr_t *ip_addr, 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; 100 /* Broadcast address */ 101 if (ip_addr == addr32_broadcast_all_hosts) { 102 addr48(addr48_broadcast, mac_addr); 103 return EOK; 104 } 94 105 95 rc = atrans_lookup(ip_addr, mac_addr);106 int rc = atrans_lookup(ip_addr, mac_addr); 96 107 if (rc == EOK) 97 108 return EOK; 98 109 110 arp_eth_packet_t packet; 111 99 112 packet.opcode = aop_request; 100 packet.sender_hw_addr = nic->mac_addr;101 packet.sender_proto_addr = *src_addr;102 packet.target_hw_addr.addr = MAC48_BROADCAST;103 packet.target_proto_addr = *ip_addr;104 113 addr48(nic->mac_addr, packet.sender_hw_addr); 114 packet.sender_proto_addr = src_addr; 115 addr48(addr48_broadcast, packet.target_hw_addr); 116 packet.target_proto_addr = ip_addr; 117 105 118 rc = arp_send_packet(nic, &packet); 106 119 if (rc != EOK) 107 120 return rc; 108 121 109 122 (void) atrans_wait_timeout(ARP_REQUEST_TIMEOUT); 110 123 111 124 return atrans_lookup(ip_addr, mac_addr); 112 125 } … … 128 141 return rc; 129 142 130 frame.dest.addr = packet->target_hw_addr.addr;131 frame.src.addr = packet->sender_hw_addr.addr;143 addr48(packet->target_hw_addr, frame.dest); 144 addr48(packet->sender_hw_addr, frame.src); 132 145 frame.etype_len = ETYPE_ARP; 133 146 frame.data = pdata;
Note:
See TracChangeset
for help on using the changeset viewer.