提交 8f9d84df 编写于 作者: P Peter Maydell

Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging

# gpg: Signature made Wed 26 Oct 2016 03:19:06 BST
# gpg:                using RSA key 0xEF04965B398D6211
# gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <jasowang@redhat.com>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 215D 46F4 8246 689E C77F  3562 EF04 965B 398D 6211

* remotes/jasowang/tags/net-pull-request:
  colo-proxy: fix memory leak
  net: rtl8139: limit processing of ring descriptors
  net: vmxnet: initialise local tx descriptor
  e1000e: Don't zero out buffer address in rx descriptor
  net: rocker: set limit to DMA buffer size
  net: eepro100: fix memory leak in device uninit
  tap-bsd: OpenBSD uses tap(4) now
  net: pcnet: fix source formatting and indentation
  net: pcnet: check rx/tx descriptor ring length
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
...@@ -1278,11 +1278,10 @@ e1000e_write_lgcy_rx_descr(E1000ECore *core, uint8_t *desc, ...@@ -1278,11 +1278,10 @@ e1000e_write_lgcy_rx_descr(E1000ECore *core, uint8_t *desc,
struct e1000_rx_desc *d = (struct e1000_rx_desc *) desc; struct e1000_rx_desc *d = (struct e1000_rx_desc *) desc;
memset(d, 0, sizeof(*d));
assert(!rss_info->enabled); assert(!rss_info->enabled);
d->length = cpu_to_le16(length); d->length = cpu_to_le16(length);
d->csum = 0;
e1000e_build_rx_metadata(core, pkt, pkt != NULL, e1000e_build_rx_metadata(core, pkt, pkt != NULL,
rss_info, rss_info,
...@@ -1291,6 +1290,7 @@ e1000e_write_lgcy_rx_descr(E1000ECore *core, uint8_t *desc, ...@@ -1291,6 +1290,7 @@ e1000e_write_lgcy_rx_descr(E1000ECore *core, uint8_t *desc,
&d->special); &d->special);
d->errors = (uint8_t) (le32_to_cpu(status_flags) >> 24); d->errors = (uint8_t) (le32_to_cpu(status_flags) >> 24);
d->status = (uint8_t) le32_to_cpu(status_flags); d->status = (uint8_t) le32_to_cpu(status_flags);
d->special = 0;
} }
static inline void static inline void
...@@ -1301,7 +1301,7 @@ e1000e_write_ext_rx_descr(E1000ECore *core, uint8_t *desc, ...@@ -1301,7 +1301,7 @@ e1000e_write_ext_rx_descr(E1000ECore *core, uint8_t *desc,
{ {
union e1000_rx_desc_extended *d = (union e1000_rx_desc_extended *) desc; union e1000_rx_desc_extended *d = (union e1000_rx_desc_extended *) desc;
memset(d, 0, sizeof(*d)); memset(&d->wb, 0, sizeof(d->wb));
d->wb.upper.length = cpu_to_le16(length); d->wb.upper.length = cpu_to_le16(length);
...@@ -1325,7 +1325,7 @@ e1000e_write_ps_rx_descr(E1000ECore *core, uint8_t *desc, ...@@ -1325,7 +1325,7 @@ e1000e_write_ps_rx_descr(E1000ECore *core, uint8_t *desc,
union e1000_rx_desc_packet_split *d = union e1000_rx_desc_packet_split *d =
(union e1000_rx_desc_packet_split *) desc; (union e1000_rx_desc_packet_split *) desc;
memset(d, 0, sizeof(*d)); memset(&d->wb, 0, sizeof(d->wb));
d->wb.middle.length0 = cpu_to_le16((*written)[0]); d->wb.middle.length0 = cpu_to_le16((*written)[0]);
......
...@@ -1843,6 +1843,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev) ...@@ -1843,6 +1843,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
vmstate_unregister(&pci_dev->qdev, s->vmstate, s); vmstate_unregister(&pci_dev->qdev, s->vmstate, s);
g_free(s->vmstate);
eeprom93xx_free(&pci_dev->qdev, s->eeprom); eeprom93xx_free(&pci_dev->qdev, s->eeprom);
qemu_del_nic(s->nic); qemu_del_nic(s->nic);
} }
......
...@@ -302,7 +302,7 @@ static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd, ...@@ -302,7 +302,7 @@ static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd,
uint32_t tbadr; uint32_t tbadr;
int16_t length; int16_t length;
int16_t status; int16_t status;
} xda; } xda;
s->phys_mem_read(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); s->phys_mem_read(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0);
tmd->tbadr = le32_to_cpu(xda.tbadr) & 0xffffff; tmd->tbadr = le32_to_cpu(xda.tbadr) & 0xffffff;
tmd->length = le16_to_cpu(xda.length); tmd->length = le16_to_cpu(xda.length);
...@@ -664,7 +664,9 @@ static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size) ...@@ -664,7 +664,9 @@ static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size)
static inline hwaddr pcnet_rdra_addr(PCNetState *s, int idx) static inline hwaddr pcnet_rdra_addr(PCNetState *s, int idx)
{ {
while (idx < 1) idx += CSR_RCVRL(s); while (idx < 1) {
idx += CSR_RCVRL(s);
}
return s->rdra + ((CSR_RCVRL(s) - idx) * (BCR_SWSTYLE(s) ? 16 : 8)); return s->rdra + ((CSR_RCVRL(s) - idx) * (BCR_SWSTYLE(s) ? 16 : 8));
} }
...@@ -672,8 +674,10 @@ static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_ti ...@@ -672,8 +674,10 @@ static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_ti
{ {
int64_t next_time = current_time + int64_t next_time = current_time +
(65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s))) * 30; (65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s))) * 30;
if (next_time <= current_time)
if (next_time <= current_time) {
next_time = current_time + 1; next_time = current_time + 1;
}
return next_time; return next_time;
} }
...@@ -795,13 +799,13 @@ static void pcnet_init(PCNetState *s) ...@@ -795,13 +799,13 @@ static void pcnet_init(PCNetState *s)
mode = le16_to_cpu(initblk.mode); mode = le16_to_cpu(initblk.mode);
rlen = initblk.rlen >> 4; rlen = initblk.rlen >> 4;
tlen = initblk.tlen >> 4; tlen = initblk.tlen >> 4;
ladrf[0] = le16_to_cpu(initblk.ladrf[0]); ladrf[0] = le16_to_cpu(initblk.ladrf[0]);
ladrf[1] = le16_to_cpu(initblk.ladrf[1]); ladrf[1] = le16_to_cpu(initblk.ladrf[1]);
ladrf[2] = le16_to_cpu(initblk.ladrf[2]); ladrf[2] = le16_to_cpu(initblk.ladrf[2]);
ladrf[3] = le16_to_cpu(initblk.ladrf[3]); ladrf[3] = le16_to_cpu(initblk.ladrf[3]);
padr[0] = le16_to_cpu(initblk.padr[0]); padr[0] = le16_to_cpu(initblk.padr[0]);
padr[1] = le16_to_cpu(initblk.padr[1]); padr[1] = le16_to_cpu(initblk.padr[1]);
padr[2] = le16_to_cpu(initblk.padr[2]); padr[2] = le16_to_cpu(initblk.padr[2]);
rdra = le32_to_cpu(initblk.rdra); rdra = le32_to_cpu(initblk.rdra);
tdra = le32_to_cpu(initblk.tdra); tdra = le32_to_cpu(initblk.tdra);
} else { } else {
...@@ -809,13 +813,13 @@ static void pcnet_init(PCNetState *s) ...@@ -809,13 +813,13 @@ static void pcnet_init(PCNetState *s)
s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)), s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)),
(uint8_t *)&initblk, sizeof(initblk), 0); (uint8_t *)&initblk, sizeof(initblk), 0);
mode = le16_to_cpu(initblk.mode); mode = le16_to_cpu(initblk.mode);
ladrf[0] = le16_to_cpu(initblk.ladrf[0]); ladrf[0] = le16_to_cpu(initblk.ladrf[0]);
ladrf[1] = le16_to_cpu(initblk.ladrf[1]); ladrf[1] = le16_to_cpu(initblk.ladrf[1]);
ladrf[2] = le16_to_cpu(initblk.ladrf[2]); ladrf[2] = le16_to_cpu(initblk.ladrf[2]);
ladrf[3] = le16_to_cpu(initblk.ladrf[3]); ladrf[3] = le16_to_cpu(initblk.ladrf[3]);
padr[0] = le16_to_cpu(initblk.padr[0]); padr[0] = le16_to_cpu(initblk.padr[0]);
padr[1] = le16_to_cpu(initblk.padr[1]); padr[1] = le16_to_cpu(initblk.padr[1]);
padr[2] = le16_to_cpu(initblk.padr[2]); padr[2] = le16_to_cpu(initblk.padr[2]);
rdra = le32_to_cpu(initblk.rdra); rdra = le32_to_cpu(initblk.rdra);
tdra = le32_to_cpu(initblk.tdra); tdra = le32_to_cpu(initblk.tdra);
rlen = rdra >> 29; rlen = rdra >> 29;
...@@ -858,12 +862,12 @@ static void pcnet_start(PCNetState *s) ...@@ -858,12 +862,12 @@ static void pcnet_start(PCNetState *s)
printf("pcnet_start\n"); printf("pcnet_start\n");
#endif #endif
if (!CSR_DTX(s)) if (!CSR_DTX(s)) {
s->csr[0] |= 0x0010; /* set TXON */ s->csr[0] |= 0x0010; /* set TXON */
}
if (!CSR_DRX(s)) if (!CSR_DRX(s)) {
s->csr[0] |= 0x0020; /* set RXON */ s->csr[0] |= 0x0020; /* set RXON */
}
s->csr[0] &= ~0x0004; /* clear STOP bit */ s->csr[0] &= ~0x0004; /* clear STOP bit */
s->csr[0] |= 0x0002; s->csr[0] |= 0x0002;
pcnet_poll_timer(s); pcnet_poll_timer(s);
...@@ -925,8 +929,7 @@ static void pcnet_rdte_poll(PCNetState *s) ...@@ -925,8 +929,7 @@ static void pcnet_rdte_poll(PCNetState *s)
crda); crda);
} }
} else { } else {
printf("pcnet: BAD RMD RDA=0x" TARGET_FMT_plx "\n", printf("pcnet: BAD RMD RDA=0x" TARGET_FMT_plx "\n", crda);
crda);
#endif #endif
} }
} }
...@@ -1168,10 +1171,11 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_) ...@@ -1168,10 +1171,11 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
#endif #endif
while (pktcount--) { while (pktcount--) {
if (CSR_RCVRC(s) <= 1) if (CSR_RCVRC(s) <= 1) {
CSR_RCVRC(s) = CSR_RCVRL(s); CSR_RCVRC(s) = CSR_RCVRL(s);
else } else {
CSR_RCVRC(s)--; CSR_RCVRC(s)--;
}
} }
pcnet_rdte_poll(s); pcnet_rdte_poll(s);
...@@ -1207,7 +1211,7 @@ static void pcnet_transmit(PCNetState *s) ...@@ -1207,7 +1211,7 @@ static void pcnet_transmit(PCNetState *s)
s->tx_busy = 1; s->tx_busy = 1;
txagain: txagain:
if (pcnet_tdte_poll(s)) { if (pcnet_tdte_poll(s)) {
struct pcnet_TMD tmd; struct pcnet_TMD tmd;
...@@ -1251,7 +1255,7 @@ static void pcnet_transmit(PCNetState *s) ...@@ -1251,7 +1255,7 @@ static void pcnet_transmit(PCNetState *s)
s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr), s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr),
s->buffer + s->xmit_pos, bcnt, CSR_BSWP(s)); s->buffer + s->xmit_pos, bcnt, CSR_BSWP(s));
s->xmit_pos += bcnt; s->xmit_pos += bcnt;
if (!GET_FIELD(tmd.status, TMDS, ENP)) { if (!GET_FIELD(tmd.status, TMDS, ENP)) {
goto txdone; goto txdone;
} }
...@@ -1276,21 +1280,22 @@ static void pcnet_transmit(PCNetState *s) ...@@ -1276,21 +1280,22 @@ static void pcnet_transmit(PCNetState *s)
s->csr[4] |= 0x0004; /* set TXSTRT */ s->csr[4] |= 0x0004; /* set TXSTRT */
s->xmit_pos = -1; s->xmit_pos = -1;
txdone: txdone:
SET_FIELD(&tmd.status, TMDS, OWN, 0); SET_FIELD(&tmd.status, TMDS, OWN, 0);
TMDSTORE(&tmd, PHYSADDR(s,CSR_CXDA(s))); TMDSTORE(&tmd, PHYSADDR(s,CSR_CXDA(s)));
if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && GET_FIELD(tmd.status, TMDS, LTINT))) if (!CSR_TOKINTD(s)
|| (CSR_LTINTEN(s) && GET_FIELD(tmd.status, TMDS, LTINT))) {
s->csr[0] |= 0x0200; /* set TINT */ s->csr[0] |= 0x0200; /* set TINT */
}
if (CSR_XMTRC(s)<=1) if (CSR_XMTRC(s) <= 1) {
CSR_XMTRC(s) = CSR_XMTRL(s); CSR_XMTRC(s) = CSR_XMTRL(s);
else } else {
CSR_XMTRC(s)--; CSR_XMTRC(s)--;
if (count--) }
if (count--) {
goto txagain; goto txagain;
}
} else } else if (s->xmit_pos >= 0) {
if (s->xmit_pos >= 0) {
struct pcnet_TMD tmd; struct pcnet_TMD tmd;
TMDLOAD(&tmd, xmit_cxda); TMDLOAD(&tmd, xmit_cxda);
SET_FIELD(&tmd.misc, TMDM, BUFF, 1); SET_FIELD(&tmd.misc, TMDM, BUFF, 1);
...@@ -1301,9 +1306,9 @@ static void pcnet_transmit(PCNetState *s) ...@@ -1301,9 +1306,9 @@ static void pcnet_transmit(PCNetState *s)
s->csr[0] |= 0x0200; /* set TINT */ s->csr[0] |= 0x0200; /* set TINT */
if (!CSR_DXSUFLO(s)) { if (!CSR_DXSUFLO(s)) {
s->csr[0] &= ~0x0010; s->csr[0] &= ~0x0010;
} else } else if (count--) {
if (count--) goto txagain;
goto txagain; }
} }
s->tx_busy = 0; s->tx_busy = 0;
...@@ -1315,13 +1320,11 @@ static void pcnet_poll(PCNetState *s) ...@@ -1315,13 +1320,11 @@ static void pcnet_poll(PCNetState *s)
pcnet_rdte_poll(s); pcnet_rdte_poll(s);
} }
if (CSR_TDMD(s) || if (CSR_TDMD(s) || (CSR_TXON(s) && !CSR_DPOLL(s) && pcnet_tdte_poll(s))) {
(CSR_TXON(s) && !CSR_DPOLL(s) && pcnet_tdte_poll(s)))
{
/* prevent recursion */ /* prevent recursion */
if (s->tx_busy) if (s->tx_busy) {
return; return;
}
pcnet_transmit(s); pcnet_transmit(s);
} }
} }
...@@ -1340,15 +1343,16 @@ static void pcnet_poll_timer(void *opaque) ...@@ -1340,15 +1343,16 @@ static void pcnet_poll_timer(void *opaque)
if (!CSR_STOP(s) && !CSR_SPND(s) && !CSR_DPOLL(s)) { if (!CSR_STOP(s) && !CSR_SPND(s) && !CSR_DPOLL(s)) {
uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) * 33; uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) * 33;
if (!s->timer || !now) if (!s->timer || !now) {
s->timer = now; s->timer = now;
else { } else {
uint64_t t = now - s->timer + CSR_POLL(s); uint64_t t = now - s->timer + CSR_POLL(s);
if (t > 0xffffLL) { if (t > 0xffffLL) {
pcnet_poll(s); pcnet_poll(s);
CSR_POLL(s) = CSR_PINT(s); CSR_POLL(s) = CSR_PINT(s);
} else } else {
CSR_POLL(s) = t; CSR_POLL(s) = t;
}
} }
timer_mod(s->poll_timer, timer_mod(s->poll_timer,
pcnet_get_next_poll_time(s,qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL))); pcnet_get_next_poll_time(s,qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)));
...@@ -1371,21 +1375,21 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value) ...@@ -1371,21 +1375,21 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value)
val = (val & 0x007f) | (s->csr[0] & 0x7f00); val = (val & 0x007f) | (s->csr[0] & 0x7f00);
/* IFF STOP, STRT and INIT are set, clear STRT and INIT */ /* IFF STOP, STRT and INIT are set, clear STRT and INIT */
if ((val&7) == 7) if ((val & 7) == 7) {
val &= ~3; val &= ~3;
}
if (!CSR_STOP(s) && (val & 4)) if (!CSR_STOP(s) && (val & 4)) {
pcnet_stop(s); pcnet_stop(s);
}
if (!CSR_INIT(s) && (val & 1)) if (!CSR_INIT(s) && (val & 1)) {
pcnet_init(s); pcnet_init(s);
}
if (!CSR_STRT(s) && (val & 2)) if (!CSR_STRT(s) && (val & 2)) {
pcnet_start(s); pcnet_start(s);
}
if (CSR_TDMD(s)) if (CSR_TDMD(s)) {
pcnet_transmit(s); pcnet_transmit(s);
}
return; return;
case 1: case 1:
case 2: case 2:
...@@ -1429,12 +1433,16 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value) ...@@ -1429,12 +1433,16 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value)
case 47: /* POLLINT */ case 47: /* POLLINT */
case 72: case 72:
case 74: case 74:
break;
case 76: /* RCVRL */ case 76: /* RCVRL */
case 78: /* XMTRL */ case 78: /* XMTRL */
val = (val > 0) ? val : 512;
break;
case 112: case 112:
if (CSR_STOP(s) || CSR_SPND(s)) if (CSR_STOP(s) || CSR_SPND(s)) {
break; break;
return; }
return;
case 3: case 3:
break; break;
case 4: case 4:
...@@ -1651,8 +1659,7 @@ void pcnet_ioport_writel(void *opaque, uint32_t addr, uint32_t val) ...@@ -1651,8 +1659,7 @@ void pcnet_ioport_writel(void *opaque, uint32_t addr, uint32_t val)
pcnet_bcr_writew(s, s->rap, val & 0xffff); pcnet_bcr_writew(s, s->rap, val & 0xffff);
break; break;
} }
} else } else if ((addr & 0x0f) == 0) {
if ((addr & 0x0f) == 0) {
/* switch device to dword i/o mode */ /* switch device to dword i/o mode */
pcnet_bcr_writew(s, BCR_BSBC, pcnet_bcr_readw(s, BCR_BSBC) | 0x0080); pcnet_bcr_writew(s, BCR_BSBC, pcnet_bcr_readw(s, BCR_BSBC) | 0x0080);
#ifdef PCNET_DEBUG_IO #ifdef PCNET_DEBUG_IO
......
...@@ -860,7 +860,7 @@ static void rocker_io_writel(void *opaque, hwaddr addr, uint32_t val) ...@@ -860,7 +860,7 @@ static void rocker_io_writel(void *opaque, hwaddr addr, uint32_t val)
rocker_msix_irq(r, val); rocker_msix_irq(r, val);
break; break;
case ROCKER_TEST_DMA_SIZE: case ROCKER_TEST_DMA_SIZE:
r->test_dma_size = val; r->test_dma_size = val & 0xFFFF;
break; break;
case ROCKER_TEST_DMA_ADDR + 4: case ROCKER_TEST_DMA_ADDR + 4:
r->test_dma_addr = ((uint64_t)val) << 32 | r->lower32; r->test_dma_addr = ((uint64_t)val) << 32 | r->lower32;
......
...@@ -2350,7 +2350,7 @@ static void rtl8139_cplus_transmit(RTL8139State *s) ...@@ -2350,7 +2350,7 @@ static void rtl8139_cplus_transmit(RTL8139State *s)
{ {
int txcount = 0; int txcount = 0;
while (rtl8139_cplus_transmit_one(s)) while (txcount < 64 && rtl8139_cplus_transmit_one(s))
{ {
++txcount; ++txcount;
} }
......
...@@ -531,6 +531,7 @@ static void vmxnet3_complete_packet(VMXNET3State *s, int qidx, uint32_t tx_ridx) ...@@ -531,6 +531,7 @@ static void vmxnet3_complete_packet(VMXNET3State *s, int qidx, uint32_t tx_ridx)
VMXNET3_RING_DUMP(VMW_RIPRN, "TXC", qidx, &s->txq_descr[qidx].comp_ring); VMXNET3_RING_DUMP(VMW_RIPRN, "TXC", qidx, &s->txq_descr[qidx].comp_ring);
memset(&txcq_descr, 0, sizeof(txcq_descr));
txcq_descr.txdIdx = tx_ridx; txcq_descr.txdIdx = tx_ridx;
txcq_descr.gen = vmxnet3_ring_curr_gen(&s->txq_descr[qidx].comp_ring); txcq_descr.gen = vmxnet3_ring_curr_gen(&s->txq_descr[qidx].comp_ring);
......
...@@ -188,7 +188,6 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) ...@@ -188,7 +188,6 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
{ {
struct tcphdr *ptcp, *stcp; struct tcphdr *ptcp, *stcp;
int res; int res;
char *sdebug, *ddebug;
trace_colo_compare_main("compare tcp"); trace_colo_compare_main("compare tcp");
if (ppkt->size != spkt->size) { if (ppkt->size != spkt->size) {
...@@ -219,24 +218,21 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) ...@@ -219,24 +218,21 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
(spkt->size - ETH_HLEN)); (spkt->size - ETH_HLEN));
if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
sdebug = strdup(inet_ntoa(ppkt->ip->ip_src)); trace_colo_compare_pkt_info(inet_ntoa(ppkt->ip->ip_src),
ddebug = strdup(inet_ntoa(ppkt->ip->ip_dst)); inet_ntoa(ppkt->ip->ip_dst),
fprintf(stderr, "%s: src/dst: %s/%s p: seq/ack=%u/%u" ntohl(ptcp->th_seq),
" s: seq/ack=%u/%u res=%d flags=%x/%x\n", ntohl(ptcp->th_ack),
__func__, sdebug, ddebug, ntohl(stcp->th_seq),
(unsigned int)ntohl(ptcp->th_seq), ntohl(stcp->th_ack),
(unsigned int)ntohl(ptcp->th_ack), res, ptcp->th_flags,
(unsigned int)ntohl(stcp->th_seq), stcp->th_flags,
(unsigned int)ntohl(stcp->th_ack), ppkt->size,
res, ptcp->th_flags, stcp->th_flags); spkt->size);
fprintf(stderr, "Primary len = %d\n", ppkt->size); qemu_hexdump((char *)ppkt->data, stderr,
qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->size); "colo-compare ppkt", ppkt->size);
fprintf(stderr, "Secondary len = %d\n", spkt->size); qemu_hexdump((char *)spkt->data, stderr,
qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size); "colo-compare spkt", spkt->size);
g_free(sdebug);
g_free(ddebug);
} }
return res; return res;
......
...@@ -68,15 +68,11 @@ static int handle_primary_tcp_pkt(NetFilterState *nf, ...@@ -68,15 +68,11 @@ static int handle_primary_tcp_pkt(NetFilterState *nf,
tcp_pkt = (struct tcphdr *)pkt->transport_header; tcp_pkt = (struct tcphdr *)pkt->transport_header;
if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) { if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
char *sdebug, *ddebug; trace_colo_filter_rewriter_pkt_info(__func__,
sdebug = strdup(inet_ntoa(pkt->ip->ip_src)); inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
ddebug = strdup(inet_ntoa(pkt->ip->ip_dst));
trace_colo_filter_rewriter_pkt_info(__func__, sdebug, ddebug,
ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack), ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
tcp_pkt->th_flags); tcp_pkt->th_flags);
trace_colo_filter_rewriter_conn_offset(conn->offset); trace_colo_filter_rewriter_conn_offset(conn->offset);
g_free(sdebug);
g_free(ddebug);
} }
if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) { if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
...@@ -116,15 +112,11 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf, ...@@ -116,15 +112,11 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf,
tcp_pkt = (struct tcphdr *)pkt->transport_header; tcp_pkt = (struct tcphdr *)pkt->transport_header;
if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) { if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
char *sdebug, *ddebug; trace_colo_filter_rewriter_pkt_info(__func__,
sdebug = strdup(inet_ntoa(pkt->ip->ip_src)); inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
ddebug = strdup(inet_ntoa(pkt->ip->ip_dst));
trace_colo_filter_rewriter_pkt_info(__func__, sdebug, ddebug,
ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack), ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
tcp_pkt->th_flags); tcp_pkt->th_flags);
trace_colo_filter_rewriter_conn_offset(conn->offset); trace_colo_filter_rewriter_conn_offset(conn->offset);
g_free(sdebug);
g_free(ddebug);
} }
if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) { if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) {
...@@ -162,6 +154,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, ...@@ -162,6 +154,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
iov_to_buf(iov, iovcnt, 0, buf, size); iov_to_buf(iov, iovcnt, 0, buf, size);
pkt = packet_new(buf, size); pkt = packet_new(buf, size);
g_free(buf);
/* /*
* if we get tcp packet * if we get tcp packet
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
#include <net/if_tap.h> #include <net/if_tap.h>
#endif #endif
#if defined(__OpenBSD__)
#include <sys/param.h>
#endif
#ifndef __FreeBSD__ #ifndef __FreeBSD__
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int vnet_hdr_required, int mq_required, Error **errp) int vnet_hdr_required, int mq_required, Error **errp)
...@@ -55,7 +59,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, ...@@ -55,7 +59,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
if (*ifname) { if (*ifname) {
snprintf(dname, sizeof dname, "/dev/%s", ifname); snprintf(dname, sizeof dname, "/dev/%s", ifname);
} else { } else {
#if defined(__OpenBSD__) #if defined(__OpenBSD__) && OpenBSD < 201605
snprintf(dname, sizeof dname, "/dev/tun%d", i); snprintf(dname, sizeof dname, "/dev/tun%d", i);
#else #else
snprintf(dname, sizeof dname, "/dev/tap%d", i); snprintf(dname, sizeof dname, "/dev/tap%d", i);
......
...@@ -13,6 +13,7 @@ colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" ...@@ -13,6 +13,7 @@ colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d"
colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
colo_old_packet_check_found(int64_t old_time) "%" PRId64 colo_old_packet_check_found(int64_t old_time) "%" PRId64
colo_compare_miscompare(void) "" colo_compare_miscompare(void) ""
colo_compare_pkt_info(const char *src, const char *dst, uint32_t pseq, uint32_t pack, uint32_t sseq, uint32_t sack, int res, uint32_t pflag, uint32_t sflag, int psize, int ssize) "src/dst: %s/%s p: seq/ack=%u/%u s: seq/ack=%u/%u res=%d flags=%x/%x ppkt_size: %d spkt_size: %d\n"
# net/filter-rewriter.c # net/filter-rewriter.c
colo_filter_rewriter_debug(void) "" colo_filter_rewriter_debug(void) ""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册