@@ -61,6 +61,7 @@ OBJS += net/uip/tcp.o
OBJS += net/uip/udp.o
OBJS += net/uip/buf.o
OBJS += net/uip/csum.o
+OBJS += net/uip/dhcp.o
OBJS += kvm-cmd.o
OBJS += mptable.o
OBJS += rbtree.o
@@ -30,9 +30,12 @@
#define UIP_TCP_FLAG_URG 32
#define UIP_DHCP_VENDOR_SPECIFIC_LEN 312
+#define UIP_DHCP_PORT_SERVER 67
+#define UIP_DHCP_PORT_CLIENT 68
#define UIP_DHCP_MACPAD_LEN 10
#define UIP_DHCP_HOSTNAME_LEN 64
#define UIP_DHCP_FILENAME_LEN 128
+#define UIP_DHCP_MAGIC_COOKIE 0x63825363
#define UIP_DHCP_MAGIC_COOKIE_LEN 4
#define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN)
/*
@@ -317,4 +320,5 @@ struct uip_buf *uip_buf_get_free(struct uip_info *info);
struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg);
int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len);
+bool uip_udp_is_dhcp(struct uip_udp *udp);
#endif /* KVM__UIP_H */
new file mode 100644
@@ -0,0 +1,17 @@
+#include "kvm/uip.h"
+
+bool uip_udp_is_dhcp(struct uip_udp *udp)
+{
+ struct uip_dhcp *dhcp;
+
+ if (ntohs(udp->sport) != UIP_DHCP_PORT_CLIENT ||
+ ntohs(udp->dport) != UIP_DHCP_PORT_SERVER)
+ return false;
+
+ dhcp = (struct uip_dhcp *)udp;
+
+ if (ntohl(dhcp->magic_cookie) != UIP_DHCP_MAGIC_COOKIE)
+ return false;
+
+ return true;
+}
This patch checks: - sport and dport - magic cookie to detemine whether a UDP package is a DHCP package. Signed-off-by: Asias He <asias.hejun@gmail.com> --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/uip.h | 4 ++++ tools/kvm/net/uip/dhcp.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/net/uip/dhcp.c