socket_vmnet should learn the MAC addresses of the VMs, set the MAC addresses to the struct conn objects, and avoid flooding when possible.
|
struct conn { |
|
// TODO: uint8_t mac[6]; |
|
int socket_fd; |
|
struct conn *next; |
|
} _conn; |
|
for (struct conn *conn = conns; conn != NULL; conn = conn->next) { |
|
// FIXME: avoid flooding |
|
DEBUGF("[Handler i=%d] Sending to the socket %d: 4 + %ld bytes [Dest " |
|
"%02X:%02X:%02X:%02X:%02X:%02X]", |
|
i, conn->socket_fd, pdv[i].vm_pkt_size, dest_mac[0], dest_mac[1], |
|
dest_mac[2], dest_mac[3], dest_mac[4], dest_mac[5]); |
|
uint32_t header_be = htonl(pdv[i].vm_pkt_size); |
|
struct iovec iov[2] = { |
|
{ |
|
.iov_base = &header_be, |
|
.iov_len = 4, |
|
}, |
|
{ |
|
.iov_base = pdv[i].vm_pkt_iov[0].iov_base, |
|
.iov_len = pdv[i].vm_pkt_size, // not vm_pkt_iov[0].iov_len |
|
}, |
|
}; |
|
ssize_t written = writev(conn->socket_fd, iov, 2); |
|
DEBUGF("[Handler i=%d] Sent to the socket: %ld bytes (including uint32be " |
|
"header)", |
|
i, written); |
|
if (written < 0) { |
|
perror("writev"); |
|
goto done; |
|
} |
|
} |
|
// Flood the packet to other VMs in the same network too. |
|
// (Not handled by vmnet) |
|
// FIXME: avoid flooding |
|
dispatch_semaphore_wait(state->sem, DISPATCH_TIME_FOREVER); |
|
struct conn *conns = state->conns; |
|
dispatch_semaphore_signal(state->sem); |
|
for (struct conn *conn = conns; conn != NULL; conn = conn->next) { |
|
if (conn->socket_fd == accept_fd) |
|
continue; |
|
DEBUGF("[Socket-to-Socket i=%lld] Sending from socket %d to socket %d: " |
|
"4 + %d bytes", |
|
i, accept_fd, conn->socket_fd, header); |
|
struct iovec iov[2] = { |
|
{ |
|
.iov_base = &header_be, |
|
.iov_len = 4, |
|
}, |
|
{ |
|
.iov_base = buf, |
|
.iov_len = header, |
|
}, |
|
}; |
|
ssize_t written = writev(conn->socket_fd, iov, 2); |
|
DEBUGF("[Socket-to-Socket i=%lld] Sent from socket %d to socket %d: %ld " |
|
"bytes (including uint32be header)", |
|
i, accept_fd, conn->socket_fd, written); |
|
if (written < 0) { |
|
perror("writev"); |
|
continue; |
|
} |
|
} |
socket_vmnet should learn the MAC addresses of the VMs, set the MAC addresses to the
struct connobjects, and avoid flooding when possible.socket_vmnet/main.c
Lines 85 to 89 in 8b16e51
socket_vmnet/main.c
Lines 180 to 205 in 8b16e51
socket_vmnet/main.c
Lines 512 to 542 in 8b16e51