chiark / gitweb /
udev/rules: setup tty permissions and group for sclp_line, ttysclp and 3270/tty
[elogind.git] / src / libsystemd-dhcp / dhcp-packet.c
index 8f9ec43c43d2891f57c1270362c2305fbcc9ee92..8388e5622278c811c8ab4d810d7addbf98991b94 100644 (file)
 #define DHCP_CLIENT_MIN_OPTIONS_SIZE            312
 
 int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
-                      uint8_t type, uint16_t secs, uint8_t **opt,
-                      size_t *optlen) {
+                      uint8_t type, uint8_t **opt, size_t *optlen) {
         int err;
 
+        assert(op == BOOTREQUEST || op == BOOTREPLY);
+
         *opt = (uint8_t *)(message + 1);
 
         if (*optlen < 4)
@@ -52,10 +53,6 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
         message->hlen = ETHER_ADDR_LEN;
         message->xid = htobe32(xid);
 
-        /* Although 'secs' field is a SHOULD in RFC 2131, certain DHCP servers
-           refuse to issue an DHCP lease if 'secs' is set to zero */
-        message->secs = htobe16(secs);
-
         (*opt)[0] = 0x63;
         (*opt)[1] = 0x82;
         (*opt)[2] = 0x53;
@@ -116,7 +113,7 @@ void dhcp_packet_append_ip_headers(DHCPPacket *packet, uint16_t len) {
         packet->ip.check = dhcp_checksum(&packet->ip, DHCP_IP_SIZE);
 }
 
-int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
+int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
         size_t hdrlen;
 
         assert(packet);
@@ -164,14 +161,14 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
                 return -EINVAL;
         }
 
-        if (hdrlen + be16toh(packet->udp.len) > len) {
+        if (len < hdrlen + be16toh(packet->udp.len)) {
                 log_dhcp_client(client, "ignoring packet: packet (%zu bytes) "
                                 "smaller than expected (%zu) by UDP header", len,
                                 hdrlen + be16toh(packet->udp.len));
                 return -EINVAL;
         }
 
-        if (packet->udp.check) {
+        if (checksum && packet->udp.check) {
                 packet->ip.check = packet->udp.len;
                 packet->ip.ttl = 0;
 
@@ -182,10 +179,10 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
                 }
         }
 
-        if (be16toh(packet->udp.source) != DHCP_PORT_SERVER ||
-            be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
-                log_dhcp_client(client, "ignoring packet: wrong ports (source: %u, destination: %u)",
-                                be16toh(packet->udp.source), be16toh(packet->udp.dest));
+        if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
+                log_dhcp_client(client, "ignoring packet: to port %u, which "
+                                "is not the DHCP client port (%u)",
+                                be16toh(packet->udp.dest), DHCP_PORT_CLIENT);
                 return -EINVAL;
         }