]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add helpers to tell the type of a DHCP message
authorAsias He <asias.hejun@gmail.com>
Sun, 17 Jul 2011 08:56:52 +0000 (16:56 +0800)
committerPekka Enberg <penberg@kernel.org>
Mon, 18 Jul 2011 10:09:59 +0000 (13:09 +0300)
If DHCP DISCOVER or DHCP REQUEST is found, reply with DHCP OFFER or DHCP
ACK respectively.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/uip.h
tools/kvm/net/uip/dhcp.c

index 7c84deab8fc8f0ed7573079b019def2abe2591ed..6534c7f19e95259f0fe3d87709842bcee390e414 100644 (file)
 #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)
+#define UIP_DHCP_DISCOVER              1
+#define UIP_DHCP_OFFER                 2
+#define UIP_DHCP_REQUEST               3
+#define UIP_DHCP_ACK                   5
+#define UIP_DHCP_TAG_MSG_TYPE          53
+#define UIP_DHCP_TAG_MSG_TYPE_LEN      1
 /*
  * IP package maxium len == 64 KBytes
  * IP header == 20 Bytes
index af0407fb2fe5f7eed43965fbfdfe93017c3517bb..0a6293a1edff9242327746de73ad936afcf6c9ca 100644 (file)
@@ -1,5 +1,19 @@
 #include "kvm/uip.h"
 
+static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
+{
+       return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
+               dhcp->option[1] == UIP_DHCP_TAG_MSG_TYPE_LEN &&
+               dhcp->option[0] == UIP_DHCP_TAG_MSG_TYPE);
+}
+
+static inline bool uip_dhcp_is_request(struct uip_dhcp *dhcp)
+{
+       return (dhcp->option[2] == UIP_DHCP_REQUEST &&
+               dhcp->option[1] == UIP_DHCP_TAG_MSG_TYPE_LEN &&
+               dhcp->option[0] == UIP_DHCP_TAG_MSG_TYPE);
+}
+
 bool uip_udp_is_dhcp(struct uip_udp *udp)
 {
        struct uip_dhcp *dhcp;