From: Asias He Date: Sun, 17 Jul 2011 08:56:51 +0000 (+0800) Subject: kvm tools: Add helper to tell if a UDP package is a DHCP package X-Git-Tag: next-20110824~3^2~104 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=402e8e3f19d0fe4a82d7755faee1688004997aa7;p=karo-tx-linux.git kvm tools: Add helper to tell if a UDP package is a DHCP package This patch checks: - sport and dport - magic cookie to detemine whether a UDP package is a DHCP package. Signed-off-by: Asias He Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 5d0437740fe9..b5c55169f59b 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -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 diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index c414267bbab7..7c84deab8fc8 100644 --- a/tools/kvm/include/kvm/uip.h +++ b/tools/kvm/include/kvm/uip.h @@ -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 */ diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c new file mode 100644 index 000000000000..af0407fb2fe5 --- /dev/null +++ b/tools/kvm/net/uip/dhcp.c @@ -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; +}