我想移除r中的arp pakcet,并正常地发送另一个数据包。这是我的密码
for (;;) {
/*
* Receive packets on a port and forward them on the paired
* port. The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.
*/
RTE_ETH_FOREACH_DEV(port) {
/* Get burst of RX packets, from first port of pair. */
struct rte_mbuf *bufs[BURST_SIZE];
uint16_t nb_rx = rte_eth_rx_burst(port, 0,
bufs, BURST_SIZE);
if (unlikely(nb_rx == 0))
continue;
/* Send burst of TX packets, to second port of pair. */
int delete_packet_num = 0;
for(int i=0;i<nb_rx;i++){
struct rte_mbuf *p = bufs[i];
unsigned char *payload =(unsigned char*)p->buf_addr;
payload = payload+p->data_off;
struct ethhdr* eth_hdr = (struct ethhdr *)payload;
if(eth_hdr->h_proto == 1544)
{
printf("there is a arp packet!\n");
//remove a target mbuf or not?
rte_pktmbuf_free(bufs[i]);
delete_packet_num++;
}
}
nb_rx -=delete_packet_num;
const uint16_t nb_tx = rte_eth_tx_burst(port ^ 1, 0,bufs, nb_rx);
if (unlikely(nb_tx < nb_rx)) {
uint16_t buf;
for (buf = nb_tx; buf < nb_rx; buf++)
rte_pktmbuf_free(bufs[buf]);
}
}它可以拒绝我的vmware machine.but中的arp数据包,当代码运行大约半小时时,虚拟机变得非常慢。我猜:
rte_pktmbuf_free(bufs[i])代码没有释放内存。有人能帮我吗?
发布于 2022-01-11 04:51:10
正如注释中提到的,在释放ARP数据包之后,内存的使用是不正确的。因此,要使用的正确代码是
for (;;) {
/*
* Receive packets on a port and forward them on the paired
* port. The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.
*/
RTE_ETH_FOREACH_DEV(port) {
/* Get burst of RX packets, from first port of pair. */
struct rte_mbuf *bufs[BURST_SIZE];
uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs, BURST_SIZE);
if (unlikely(nb_rx == 0))
continue;
/* Send burst of TX packets, to second port of pair. */
int delete_packet_num = 0;
int i = 0, j = 0;
for(;i<nb_rx;i++){
struct rte_mbuf *p = bufs[i];
unsigned char *payload =(unsigned char*)p->buf_addr;
payload = payload+p->data_off;
struct ethhdr* eth_hdr = (struct ethhdr *)payload;
if(eth_hdr->h_proto == 1544)
{
printf("there is a arp packet!\n");
//remove a target mbuf or not?
rte_pktmbuf_free(bufs[i]);
delete_packet_num++;
}
else
{
/*
for all valid packets update the list
example:
- let nb_rx be 16 packets
- in which packet at index 5 is ARP packets
- with help of check for ARP we are reassigning bufs[5] = bufs[6], because j is running 1 step once it encounters ARP at index 5
*/
bufs[j++] = bufs[i];
}
}
nb_rx -=delete_packet_num;
const uint16_t nb_tx = rte_eth_tx_burst(port ^ 1, 0,bufs, nb_rx);
if (unlikely(nb_tx < nb_rx)) {
uint16_t buf;
for (buf = nb_tx; buf < nb_rx; buf++)
rte_pktmbuf_free(bufs[buf]);
}
}https://stackoverflow.com/questions/70446736
复制相似问题