Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/netmap/bridge.c
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | rings_move(struct netmap_ring *rxring, struct netmap_ring *txring, | ||||
m = nm_ring_space(txring); | m = nm_ring_space(txring); | ||||
if (m < limit) | if (m < limit) | ||||
limit = m; | limit = m; | ||||
m = limit; | m = limit; | ||||
while (limit-- > 0) { | while (limit-- > 0) { | ||||
struct netmap_slot *rs = &rxring->slot[j]; | struct netmap_slot *rs = &rxring->slot[j]; | ||||
struct netmap_slot *ts = &txring->slot[k]; | struct netmap_slot *ts = &txring->slot[k]; | ||||
/* swap packets */ | |||||
if (ts->buf_idx < 2 || rs->buf_idx < 2) { | if (ts->buf_idx < 2 || rs->buf_idx < 2) { | ||||
RD(2, "wrong index rxr[%d] = %d -> txr[%d] = %d", | RD(2, "wrong index rxr[%d] = %d -> txr[%d] = %d", | ||||
j, rs->buf_idx, k, ts->buf_idx); | j, rs->buf_idx, k, ts->buf_idx); | ||||
sleep(2); | sleep(2); | ||||
} | } | ||||
/* copy the packet length. */ | /* Copy the packet length. */ | ||||
if (rs->len > rxring->nr_buf_size) { | if (rs->len > rxring->nr_buf_size) { | ||||
RD(2, "%s: invalid len %u, rxr[%d] -> txr[%d]", | RD(2, "%s: invalid len %u, rxr[%d] -> txr[%d]", | ||||
msg, rs->len, j, k); | msg, rs->len, j, k); | ||||
rs->len = 0; | rs->len = 0; | ||||
} else if (verbose > 1) { | } else if (verbose > 1) { | ||||
D("%s: fwd len %u, rx[%d] -> tx[%d]", | D("%s: fwd len %u, rx[%d] -> tx[%d]", | ||||
msg, rs->len, j, k); | msg, rs->len, j, k); | ||||
} | } | ||||
ts->len = rs->len; | ts->len = rs->len; | ||||
if (zerocopy) { | if (zerocopy) { | ||||
uint32_t pkt = ts->buf_idx; | uint32_t pkt = ts->buf_idx; | ||||
ts->buf_idx = rs->buf_idx; | ts->buf_idx = rs->buf_idx; | ||||
rs->buf_idx = pkt; | rs->buf_idx = pkt; | ||||
/* report the buffer change. */ | /* report the buffer change. */ | ||||
ts->flags |= NS_BUF_CHANGED; | ts->flags |= NS_BUF_CHANGED; | ||||
rs->flags |= NS_BUF_CHANGED; | rs->flags |= NS_BUF_CHANGED; | ||||
/* copy the NS_MOREFRAG */ | |||||
rs->flags = (rs->flags & ~NS_MOREFRAG) | (ts->flags & NS_MOREFRAG); | |||||
} else { | } else { | ||||
char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx); | char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx); | ||||
char *txbuf = NETMAP_BUF(txring, ts->buf_idx); | char *txbuf = NETMAP_BUF(txring, ts->buf_idx); | ||||
nm_pkt_copy(rxbuf, txbuf, ts->len); | nm_pkt_copy(rxbuf, txbuf, ts->len); | ||||
} | } | ||||
/* | |||||
* Copy the NS_MOREFRAG from rs to ts, leaving any | |||||
* other flags unchanged. | |||||
*/ | |||||
ts->flags = (ts->flags & ~NS_MOREFRAG) | (rs->flags & NS_MOREFRAG); | |||||
j = nm_ring_next(rxring, j); | j = nm_ring_next(rxring, j); | ||||
k = nm_ring_next(txring, k); | k = nm_ring_next(txring, k); | ||||
} | } | ||||
rxring->head = rxring->cur = j; | rxring->head = rxring->cur = j; | ||||
txring->head = txring->cur = k; | txring->head = txring->cur = k; | ||||
if (verbose && m > 0) | if (verbose && m > 0) | ||||
D("%s fwd %d packets: rxring %u --> txring %u", | D("%s fwd %d packets: rxring %u --> txring %u", | ||||
msg, m, rxring->ringid, txring->ringid); | msg, m, rxring->ringid, txring->ringid); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* If only one name, or the two interfaces are the same, | * If only one name, or the two interfaces are the same, | ||||
* bridges userland and the adapter. Otherwise bridge | * bridges userland and the adapter. Otherwise bridge | ||||
* two intefaces. | * two intefaces. | ||||
*/ | */ | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
char msg_a2b[128], msg_b2a[128]; | char msg_a2b[256], msg_b2a[256]; | ||||
struct pollfd pollfd[2]; | struct pollfd pollfd[2]; | ||||
u_int burst = 1024, wait_link = 4; | u_int burst = 1024, wait_link = 4; | ||||
struct nmport_d *pa = NULL, *pb = NULL; | struct nmport_d *pa = NULL, *pb = NULL; | ||||
char *ifa = NULL, *ifb = NULL; | char *ifa = NULL, *ifb = NULL; | ||||
char ifabuf[64] = { 0 }; | char ifabuf[64] = { 0 }; | ||||
int pa_sw_rings, pb_sw_rings; | int pa_sw_rings, pb_sw_rings; | ||||
int loopback = 0; | int loopback = 0; | ||||
int ch; | int ch; | ||||
▲ Show 20 Lines • Show All 190 Lines • Show Last 20 Lines |