mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-06 05:31:50 +00:00
kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp()
uip_tx_do_ipv4_udp_dhcp() is used to handle DHCP packages from guest. Signed-off-by: Asias He <asias.hejun@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
#define UIP_TCP_FLAG_ACK 16
|
||||
#define UIP_TCP_FLAG_URG 32
|
||||
|
||||
#define UIP_BOOTP_VENDOR_SPECIFIC_LEN 64
|
||||
#define UIP_BOOTP_MAX_PAYLOAD_LEN 300
|
||||
#define UIP_DHCP_VENDOR_SPECIFIC_LEN 312
|
||||
#define UIP_DHCP_PORT_SERVER 67
|
||||
#define UIP_DHCP_PORT_CLIENT 68
|
||||
@@ -38,6 +40,7 @@
|
||||
#define UIP_DHCP_MAGIC_COOKIE 0x63825363
|
||||
#define UIP_DHCP_MAGIC_COOKIE_LEN 4
|
||||
#define UIP_DHCP_LEASE_TIME 0x00003840
|
||||
#define UIP_DHCP_MAX_PAYLOAD_LEN (UIP_BOOTP_MAX_PAYLOAD_LEN - UIP_BOOTP_VENDOR_SPECIFIC_LEN + UIP_DHCP_VENDOR_SPECIFIC_LEN)
|
||||
#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
|
||||
@@ -328,6 +331,7 @@ int uip_tx(struct iovec *iov, u16 out, struct uip_info *info);
|
||||
int uip_rx(struct iovec *iov, u16 in, struct uip_info *info);
|
||||
int uip_init(struct uip_info *info);
|
||||
|
||||
int uip_tx_do_ipv4_udp_dhcp(struct uip_tx_arg *arg);
|
||||
int uip_tx_do_ipv4_icmp(struct uip_tx_arg *arg);
|
||||
int uip_tx_do_ipv4_tcp(struct uip_tx_arg *arg);
|
||||
int uip_tx_do_ipv4_udp(struct uip_tx_arg *arg);
|
||||
|
||||
@@ -155,3 +155,41 @@ static int uip_dhcp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, s
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uip_tx_do_ipv4_udp_dhcp(struct uip_tx_arg *arg)
|
||||
{
|
||||
struct uip_udp_socket sk;
|
||||
struct uip_dhcp *dhcp;
|
||||
struct uip_info *info;
|
||||
struct uip_buf *buf;
|
||||
u8 reply_msg_type;
|
||||
|
||||
dhcp = (struct uip_dhcp *)arg->eth;
|
||||
|
||||
if (uip_dhcp_is_discovery(dhcp))
|
||||
reply_msg_type = UIP_DHCP_OFFER;
|
||||
else if (uip_dhcp_is_request(dhcp))
|
||||
reply_msg_type = UIP_DHCP_ACK;
|
||||
else
|
||||
return -1;
|
||||
|
||||
buf = uip_buf_clone(arg);
|
||||
info = arg->info;
|
||||
|
||||
/*
|
||||
* Cook DHCP pkg
|
||||
*/
|
||||
uip_dhcp_make_pkg(info, &sk, buf, reply_msg_type);
|
||||
|
||||
/*
|
||||
* Cook UDP pkg
|
||||
*/
|
||||
uip_udp_make_pkg(info, &sk, buf, NULL, UIP_DHCP_MAX_PAYLOAD_LEN);
|
||||
|
||||
/*
|
||||
* Send data received from socket to guest
|
||||
*/
|
||||
uip_buf_set_used(info, buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user