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