dhcp-packet.c revision aa6fc9b8c823834f262ab5ab2ac094a3775370a9
/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation. All rights reserved.
Copyright (C) 2014 Tom Gundersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <net/ethernet.h>
#include "util.h"
#include "list.h"
#include "dhcp-protocol.h"
#include "dhcp-lease-internal.h"
#include "dhcp-internal.h"
#include "sd-dhcp-lease.h"
#include "sd-dhcp-client.h"
#define DHCP_CLIENT_MIN_OPTIONS_SIZE 312
int err;
&type);
if (err < 0)
return err;
return 0;
}
sum++;
buf_64 ++;
}
sum++;
buf_32 ++;
}
sum ++;
buf_16 ++;
}
sum++;
}
while (sum >> 16)
return ~sum;
}
}
/* IP */
log_debug("ignoring packet: not IPv4");
return -EINVAL;
}
log_debug("ignoring packet: IPv4 IHL (%u words) invalid",
return -EINVAL;
}
if (hdrlen < 20) {
log_debug("ignoring packet: IPv4 IHL (%zu bytes) "
"smaller than minimum (20 bytes)", hdrlen);
return -EINVAL;
}
log_debug("ignoring packet: packet (%zu bytes) "
"smaller than expected (%zu) by IP header", len,
hdrlen);
return -EINVAL;
}
/* UDP */
log_debug("ignoring packet: not UDP");
return -EINVAL;
}
log_debug("ignoring packet: packet (%zu bytes) "
"smaller than expected (%zu) by UDP header", len,
return -EINVAL;
}
log_debug("ignoring packet: to port %u, which "
"is not the DHCP client port (%u)",
return -EINVAL;
}
/* checksums - computing these is relatively expensive, so only do it
if all the other checks have passed
*/
log_debug("ignoring packet: invalid IP checksum");
return -EINVAL;
}
log_debug("ignoring packet: invalid UDP checksum");
return -EINVAL;
}
}
return 0;
}