Exemplo n.º 1
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;
}
Exemplo n.º 2
0
Arquivo: icmp.c Projeto: joyxu/kvmtool
int uip_tx_do_ipv4_icmp(struct uip_tx_arg *arg)
{
	struct uip_ip *ip, *ip2;
	struct uip_icmp *icmp2;
	struct uip_icmp *icmp;
	struct uip_buf *buf;

	ip		= (struct uip_ip *)(arg->eth);
	icmp		= uip_ip_proto(ip);

	/* Check the icmp type first.. */

	switch(icmp->type) {
	case UIP_ICMP_ECHO:
		buf		= uip_buf_clone(arg);
		ip2		= (struct uip_ip *)(buf->eth);
		icmp2		= uip_ip_proto(ip2);
		ip2->sip	= ip->dip;
		ip2->dip	= ip->sip;
		ip2->csum	= 0;
		/*
		 * ICMP reply: 0
		 */
		icmp2->type	= UIP_ICMP_ECHO_REPLY;
		icmp2->csum	= 0;
		ip2->csum	= uip_csum_ip(ip2);
		icmp2->csum	= uip_csum_icmp(ip2, icmp2);

		uip_buf_set_used(arg->info, buf);

		return 0;
	/* FIXME: need to process unreachable reports */
	default:
		return 0;
	}
}