Changes in uspace/srv/net/ethip/pdu.c [02a09ed:96c0b7b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/pdu.c
r02a09ed r96c0b7b 62 62 63 63 hdr = (eth_header_t *)data; 64 addr48(frame->src, hdr->src);65 addr48(frame->dest, hdr->dest);64 mac48_encode(&frame->src, hdr->src); 65 mac48_encode(&frame->dest, hdr->dest); 66 66 hdr->etype_len = host2uint16_t_be(frame->etype_len); 67 67 … … 69 69 frame->size); 70 70 71 log_msg(LOG_DEFAULT, LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size); 71 log_msg(LVL_DEBUG, "Encoding Ethernet frame src=%llx dest=%llx etype=%x", 72 frame->src, frame->dest, frame->etype_len); 73 log_msg(LVL_DEBUG, "Encoded Ethernet frame (%zu bytes)", size); 72 74 73 75 *rdata = data; … … 81 83 eth_header_t *hdr; 82 84 83 log_msg(L OG_DEFAULT, LVL_DEBUG, "eth_pdu_decode()");85 log_msg(LVL_DEBUG, "eth_pdu_decode()"); 84 86 85 87 if (size < sizeof(eth_header_t)) { 86 log_msg(L OG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);88 log_msg(LVL_DEBUG, "PDU too short (%zu)", size); 87 89 return EINVAL; 88 90 } … … 95 97 return ENOMEM; 96 98 97 addr48(hdr->src,frame->src);98 addr48(hdr->dest,frame->dest);99 mac48_decode(hdr->src, &frame->src); 100 mac48_decode(hdr->dest, &frame->dest); 99 101 frame->etype_len = uint16_t_be2host(hdr->etype_len); 100 102 … … 102 104 frame->size); 103 105 104 log_msg(LOG_DEFAULT, LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size); 105 106 return EOK; 106 log_msg(LVL_DEBUG, "Decoding Ethernet frame src=%llx dest=%llx etype=%x", 107 frame->src, frame->dest, frame->etype_len); 108 log_msg(LVL_DEBUG, "Decoded Ethernet frame payload (%zu bytes)", frame->size); 109 110 return EOK; 111 } 112 113 void mac48_encode(mac48_addr_t *addr, void *buf) 114 { 115 uint64_t val; 116 uint8_t *bbuf = (uint8_t *)buf; 117 int i; 118 119 val = addr->addr; 120 for (i = 0; i < MAC48_BYTES; i++) 121 bbuf[i] = (val >> (8 * (MAC48_BYTES - i - 1))) & 0xff; 122 } 123 124 void mac48_decode(void *data, mac48_addr_t *addr) 125 { 126 uint64_t val; 127 uint8_t *bdata = (uint8_t *)data; 128 int i; 129 130 val = 0; 131 for (i = 0; i < MAC48_BYTES; i++) 132 val |= (uint64_t)bdata[i] << (8 * (MAC48_BYTES - i - 1)); 133 134 addr->addr = val; 107 135 } 108 136 … … 115 143 uint16_t fopcode; 116 144 117 log_msg(L OG_DEFAULT, LVL_DEBUG, "arp_pdu_encode()");145 log_msg(LVL_DEBUG, "arp_pdu_encode()"); 118 146 119 147 size = sizeof(arp_eth_packet_fmt_t); … … 138 166 pfmt->proto_addr_size = IPV4_ADDR_SIZE; 139 167 pfmt->opcode = host2uint16_t_be(fopcode); 140 addr48(packet->sender_hw_addr, pfmt->sender_hw_addr);168 mac48_encode(&packet->sender_hw_addr, pfmt->sender_hw_addr); 141 169 pfmt->sender_proto_addr = 142 host2uint32_t_be(packet->sender_proto_addr );143 addr48(packet->target_hw_addr, pfmt->target_hw_addr);170 host2uint32_t_be(packet->sender_proto_addr.ipv4); 171 mac48_encode(&packet->target_hw_addr, pfmt->target_hw_addr); 144 172 pfmt->target_proto_addr = 145 host2uint32_t_be(packet->target_proto_addr );173 host2uint32_t_be(packet->target_proto_addr.ipv4); 146 174 147 175 *rdata = data; … … 155 183 arp_eth_packet_fmt_t *pfmt; 156 184 157 log_msg(L OG_DEFAULT, LVL_DEBUG, "arp_pdu_decode()");185 log_msg(LVL_DEBUG, "arp_pdu_decode()"); 158 186 159 187 if (size < sizeof(arp_eth_packet_fmt_t)) { 160 log_msg(L OG_DEFAULT, LVL_DEBUG, "ARP PDU too short (%zu)", size);188 log_msg(LVL_DEBUG, "ARP PDU too short (%zu)", size); 161 189 return EINVAL; 162 190 } … … 165 193 166 194 if (uint16_t_be2host(pfmt->hw_addr_space) != AHRD_ETHERNET) { 167 log_msg(L OG_DEFAULT, LVL_DEBUG, "HW address space != %u (%" PRIu16 ")",195 log_msg(LVL_DEBUG, "HW address space != %u (%" PRIu16 ")", 168 196 AHRD_ETHERNET, uint16_t_be2host(pfmt->hw_addr_space)); 169 197 return EINVAL; … … 171 199 172 200 if (uint16_t_be2host(pfmt->proto_addr_space) != 0x0800) { 173 log_msg(L OG_DEFAULT, LVL_DEBUG, "Proto address space != %u (%" PRIu16 ")",201 log_msg(LVL_DEBUG, "Proto address space != %u (%" PRIu16 ")", 174 202 ETYPE_IP, uint16_t_be2host(pfmt->proto_addr_space)); 175 203 return EINVAL; … … 177 205 178 206 if (pfmt->hw_addr_size != ETH_ADDR_SIZE) { 179 log_msg(L OG_DEFAULT, LVL_DEBUG, "HW address size != %zu (%zu)",207 log_msg(LVL_DEBUG, "HW address size != %zu (%zu)", 180 208 (size_t)ETH_ADDR_SIZE, (size_t)pfmt->hw_addr_size); 181 209 return EINVAL; … … 183 211 184 212 if (pfmt->proto_addr_size != IPV4_ADDR_SIZE) { 185 log_msg(L OG_DEFAULT, LVL_DEBUG, "Proto address size != %zu (%zu)",213 log_msg(LVL_DEBUG, "Proto address size != %zu (%zu)", 186 214 (size_t)IPV4_ADDR_SIZE, (size_t)pfmt->proto_addr_size); 187 215 return EINVAL; … … 192 220 case AOP_REPLY: packet->opcode = aop_reply; break; 193 221 default: 194 log_msg(L OG_DEFAULT, LVL_DEBUG, "Invalid ARP opcode (%" PRIu16 ")",222 log_msg(LVL_DEBUG, "Invalid ARP opcode (%" PRIu16 ")", 195 223 uint16_t_be2host(pfmt->opcode)); 196 224 return EINVAL; 197 225 } 198 226 199 addr48(pfmt->sender_hw_addr,packet->sender_hw_addr);200 packet->sender_proto_addr =227 mac48_decode(pfmt->sender_hw_addr, &packet->sender_hw_addr); 228 packet->sender_proto_addr.ipv4 = 201 229 uint32_t_be2host(pfmt->sender_proto_addr); 202 addr48(pfmt->target_hw_addr,packet->target_hw_addr);203 packet->target_proto_addr =230 mac48_decode(pfmt->target_hw_addr, &packet->target_hw_addr); 231 packet->target_proto_addr.ipv4 = 204 232 uint32_t_be2host(pfmt->target_proto_addr); 205 log_msg(LOG_DEFAULT, LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr); 206 207 return EOK; 208 } 233 log_msg(LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr); 234 235 return EOK; 236 } 237 209 238 210 239 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.