Lines Matching refs:packet
91 void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
94 packet->ip.version = IPVERSION;
95 packet->ip.ihl = DHCP_IP_SIZE / 4;
96 packet->ip.tot_len = htobe16(len);
98 packet->ip.tos = IPTOS_CLASS_CS6;
100 packet->ip.protocol = IPPROTO_UDP;
101 packet->ip.saddr = source_addr;
102 packet->ip.daddr = destination_addr;
104 packet->udp.source = htobe16(source_port);
105 packet->udp.dest = htobe16(destination_port);
107 packet->udp.len = htobe16(len - DHCP_IP_SIZE);
109 packet->ip.check = packet->udp.len;
110 packet->udp.check = dhcp_packet_checksum((uint8_t*)&packet->ip.ttl, len - 8);
112 packet->ip.ttl = IPDEFTTL;
113 packet->ip.check = 0;
114 packet->ip.check = dhcp_packet_checksum((uint8_t*)&packet->ip, DHCP_IP_SIZE);
117 int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
120 assert(packet);
124 if (packet->ip.version != IPVERSION) {
125 log_debug("ignoring packet: not IPv4");
129 if (packet->ip.ihl < 5) {
130 log_debug("ignoring packet: IPv4 IHL (%u words) invalid",
131 packet->ip.ihl);
135 hdrlen = packet->ip.ihl * 4;
137 log_debug("ignoring packet: IPv4 IHL (%zu bytes) "
143 log_debug("ignoring packet: packet (%zu bytes) "
151 if (packet->ip.protocol != IPPROTO_UDP) {
152 log_debug("ignoring packet: not UDP");
156 if (len < hdrlen + be16toh(packet->udp.len)) {
157 log_debug("ignoring packet: packet (%zu bytes) "
159 hdrlen + be16toh(packet->udp.len));
163 if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
164 log_debug("ignoring packet: to port %u, which "
166 be16toh(packet->udp.dest), DHCP_PORT_CLIENT);
174 if (dhcp_packet_checksum((uint8_t*)&packet->ip, hdrlen)) {
175 log_debug("ignoring packet: invalid IP checksum");
179 if (checksum && packet->udp.check) {
180 packet->ip.check = packet->udp.len;
181 packet->ip.ttl = 0;
183 if (dhcp_packet_checksum((uint8_t*)&packet->ip.ttl,
184 be16toh(packet->udp.len) + 12)) {
185 log_debug("ignoring packet: invalid UDP checksum");