예제 #1
0
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
  if (!dev)
    return ERR_OK;

#ifdef ETH_PAD_SIZE
  pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif

  /* Send the data from the pbuf to the interface, one pbuf at a
     time. The size of the data in each pbuf is kept in the ->len
     variable. */
  if (!p->next) {
    /* Only one fragment, can send it directly */
      netfront_xmit(dev, p->payload, p->len);
  } else {
    unsigned char data[p->tot_len], *cur;
    struct pbuf *q;

    for(q = p, cur = data; q != NULL; cur += q->len, q = q->next)
      memcpy(cur, q->payload, q->len);
    netfront_xmit(dev, data, p->tot_len);
  }

#if ETH_PAD_SIZE
  pbuf_header(p, ETH_PAD_SIZE);			/* reclaim the padding word */
#endif
  
  LINK_STATS_INC(link.xmit);

  return ERR_OK;
}
예제 #2
0
void
VIFHYPER_SEND(struct virtif_user *viu,
	struct iovec *iov, size_t iovlen)
{
	size_t tlen, i;
	int nlocks;
	void *d;
	char *d0;

	rumpkern_unsched(&nlocks, NULL);
	/*
	 * netfront doesn't do scatter-gather, so just simply
	 * copy the data into one lump here.
	 */
	if (iovlen == 1) {
		d = iov->iov_base;
		tlen = iov->iov_len;
	} else {
		for (i = 0, tlen = 0; i < iovlen; i++) {
			tlen += iov[i].iov_len;
		}
		d = d0 = malloc(tlen);
		for (i = 0; i < iovlen; i++) {
			memcpy(d0, iov[i].iov_base, iov[i].iov_len);
			d0 += iov[i].iov_len;
		}
	}

	netfront_xmit(viu->viu_dev, d, tlen);

	if (iovlen != 1)
		free(d);

	rumpkern_sched(nlocks, NULL);
}
예제 #3
0
int write(int fd, const void *buf, size_t nbytes)
{
    if (fd < 0 || fd >= NOFILE) {
	fd = EBADF;
	return -1;
    }
    switch (files[fd].type) {
        case FTYPE_SAVEFILE: {
                int ret = 0, tot = nbytes;
                while (nbytes > 0) {
                    ret = xencons_ring_send(files[fd].cons.dev, (char *)buf, nbytes);
                    nbytes -= ret;
                    buf = (char *)buf + ret;
                }
                return tot - nbytes;
            }
	case FTYPE_CONSOLE:
	    console_print(files[fd].cons.dev, (char *)buf, nbytes);
	    return nbytes;
#ifdef HAVE_LWIP
	case FTYPE_SOCKET:
	    return lwip_write(files[fd].socket.fd, (void*) buf, nbytes);
#endif
	case FTYPE_TAP:
	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
	    return nbytes;
	default:
	    break;
    }
    printk("write(%d): Bad descriptor\n", fd);
    errno = EBADF;
    return -1;
}
예제 #4
0
파일: mini-os.c 프로젝트: codercold/xen-4.4
static void minios_transmit (struct nic *nic, const char *d, unsigned int t,
                             unsigned int s, const char *p)
{
    struct frame *frame = alloca(sizeof(frame) + s);

    memcpy(frame->dest, d, ETH_ALEN);
    memcpy(frame->src, nic->node_addr, ETH_ALEN);
    frame->type = htons(t);
    memcpy(frame->data, p, s);

    netfront_xmit(net_dev, (void*) frame, sizeof(*frame) + s);
}
예제 #5
0
파일: sys.c 프로젝트: jonludlam/xen-arm
int write(int fd, const void *buf, size_t nbytes)
{
    switch (files[fd].type) {
        case FTYPE_SAVEFILE: {
                int ret = 0, tot = nbytes;
                while (nbytes > 0) {
                    ret = xencons_ring_send(files[fd].cons.dev, (char *)buf, nbytes);
                    nbytes -= ret;
                    buf = (char *)buf + ret;
                }
                return tot - nbytes;
            }
	case FTYPE_CONSOLE:
	    console_print(files[fd].cons.dev, (char *)buf, nbytes);
	    return nbytes;
#ifdef HAVE_LWIP
	case FTYPE_SOCKET:
	    return lwip_write(files[fd].socket.fd, (void*) buf, nbytes);
#endif
#ifdef CONFIG_NETFRONT
	case FTYPE_TAP:
	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
	    return nbytes;
#endif
#ifdef CONFIG_BLKFRONT
	case FTYPE_BLK:
	    return blkfront_posix_write(fd, buf, nbytes);
#endif
#ifdef CONFIG_TPMFRONT
	case FTYPE_TPMFRONT:
	    return tpmfront_posix_write(fd, buf, nbytes);
#endif
#ifdef CONFIG_TPM_TIS
	case FTYPE_TPM_TIS:
	    return tpm_tis_posix_write(fd, buf, nbytes);
#endif
	default:
	    break;
    }
    printk("write(%d): Bad descriptor\n", fd);
    errno = EBADF;
    return -1;
}
/*----------------------------------------------------------------------------*/
void sendViaEth(ethernet_frame_t* eth)
{
	uint8_t sendBuffer[max_frame_size]; // the byte array that will be sent
	uint8_t current_offset; // keeps track of current offset in the buffer
	uint8_t padding_len; // how much padding is required
	uint8_t message_len; // length of the message being sent
	
	createMac((uint8_t*)&(eth->eth_header.dest),dom0mac);
	createMac((uint8_t*)&(eth->eth_header.source),mymac);
	eth->eth_header.data_len = 0x0008; // 0x0008 means frame's content is IP

	writeEthernetHeader(sendBuffer, &(eth->eth_header), ethernet_header_offset);
	
	writeIPHeader(sendBuffer, &(eth->ip_header), ip_header_offset);
	
	writeUdpHeader(sendBuffer, &(eth->udp_header), udp_header_offset);
	
	writeMessage(sendBuffer, &eth->message, message_offset);

	message_len = eth->message.length;
	current_offset = message_offset+message_len;
	
	if(sum_headers_len + message_len < min_frame_size)
	{
		
		padding_len = min_frame_size - (sum_headers_len + message_len );
		writePadding(sendBuffer, current_offset, padding_len);
		current_offset += padding_len;
	}
	else
	{
		padding_len = 0;
	}
	
	writeChecksum(sendBuffer, current_offset);

	//netfront_xmit(xen_network_device,(unsigned char*) sendBuffer, current_offset+frame_checksum_length);
	netfront_xmit(net_dev,(unsigned char*) sendBuffer, current_offset+frame_checksum_length);//change it to linux version
	
}