net/devif: fix poll issue when ifdown #17701
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When the interface bound to the socket is in the down state, polling the socket will return an error message, which in some cases will cause a busy loop.
The function call stack is roughly as follows: poll->pkt_pollsetup->pkt_callback_alloc->devif_callback_alloc. Then return NULL if interface is down.
To fix this problem, we modified the error judgment condition in devif_callback_alloc.
Impact
No impact on functions
Testing
Set up a sim environment, start the sim and ifdown eth0, then start the poll program, and repeat that the poll is always in the busy loop. After the current patch is marked, the problem is fixed.
`
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/poll.h>
#include <netpacket/packet.h>
#include <net/if.h>
#include <errno.h>
#include <arpa/inet.h>
#define TEST_DATA "Hello, PKT poll!"
#define PKT_IFNAME "eth0" // 使用eth0接口
#ifndef ETH_P_ALL
#define ETH_P_ALL 0x0003
#endif
int main(void)
{
int sockfd;
struct sockaddr_ll addr;
struct pollfd pfd;
char buf[128];
int ret;
}
`