In netif_receive_skb, a piece of code is to clone the receive data packet and hand it over to the chain of ptype_all. The Code is as follows:
......
Pt_prev = NULL;
List_for_each_entry_rcu (ptype, & ptype_all, list ){
If (! Ptype-> Dev | ptype-> Dev = SKB-> Dev ){
If (pt_prev)
Ret = deliver_skb (SKB, pt_prev, orig_dev );
Pt_prev = ptype;
}
}
I think the above Code is a bit confused. Since it is traversing the ptype_all chain, why do I need a pt_prev to save it? Just do it below.
List_for_each_entry_rcu (ptype, & ptype_all, list ){
If (! Ptype-> Dev | ptype-> Dev = SKB-> Dev ){
Ret = deliver_skb (SKB, ptype, orig_dev );
}
}
Let's explain the prawns.
[This post was last edited by godbach]
Author:GodbachTime:
Okay, lz. I have edited your title. I hope more people will discuss your issue.
Author:DreamiceTime:
Quote: original post
Hanhai ShuxiangPublished
In netif_receive_skb, a piece of code is to clone the receive data packet and hand it over to the chain of ptype_all. The Code is as follows:
......
Pt_prev = NULL;
List_for_each_entry_rcu (ptype, & ptype_all, list ){
If (! Ptype-> Dev | ptype-> Dev = Sk...
Here, we want to determine whether the pt_prev has been shipped. If it has been shipped, We will traverse it down.
This may be to avoid multiple packet deliver operations caused by SMP concurrent processing.
Author:Hanhai ShuxiangTime:Title:Reply #2 godbach's post
Thank you moderator
Could you give the moderator an analysis?
Author:GodbachTime:
Let's take a look at the explanation of dreamice.
However, in terms of programs, when traversing to the current node, it will save the previous non-empty node deliver.
Author:Hanhai ShuxiangTime:Title:Reply #3 dreamice post
Can I explain it in detail?
In the above case, how does one prevent SMP multiple deliver and under what circumstances does this happen ??
I 'd like to hear more
Author:GodbachTime:
It is reasonable to say that the records are locked when the records are stored.
Author:Hanhai ShuxiangTime:
What makes me more confused is that, according to the above situation, it seems that the ptype that the linked list finally meets the condition does not have deliver.
Author:DreamiceTime:
Quote: original post
Hanhai ShuxiangPublished at, September 21
Can I explain it in detail?
In the above case, how does one prevent SMP multiple deliver and under what circumstances does this happen ??
I 'd like to hear more
Let's look at the code first.
Author:PlatinumTime:
Because it will be used later
Author:Hanhai ShuxiangTime:Title:Reply to #10 platinum posts
The subsequent code is bridge and VLAN, and then the protocol processing function corresponding to ptype_base.
In the chain table traversal of ptype_base, The deliver is indeed given to the last one in ptype_all. But why does the deilver give to the last one in ptype_all?
In addition, if the packet is returned in the processing of the bridge or VLAN, the last packet in ptype_all cannot be received.
Author:ShadowstarTime:
Quote: original post
Hanhai ShuxiangPublished
The subsequent code is bridge and VLAN, and then the protocol processing function corresponding to ptype_base.
In the chain table traversal of ptype_base, The deliver is indeed given to the last one in ptype_all. But why does the deilver give to the last one in ptype_all?
And if we say...
There is no problem in logic processing.
Pt_prev indicates "the previous packet_type ".
It can be said that the last ptype_all func is called in the cycle of ptype_base. (If it is true in the cycle of ptype_base)
You can see under the ptype_base loop, there is also an IF (pt_prev ){......
I don't know why.
Besides, I think this is a problem.
Because deliver_skb (that is, executing packet_type-> func () may be kfree_skb.
In this case, if there is a match later, the SKB has been released.
[This post was last edited by shadowstar]
Author:Hanhai ShuxiangTime:Title:Reply #12 shadowstar's post
Quote: No problem in logic processing.
Pt_prev indicates "the previous packet_type ".
It can be said that the last ptype_all func is called in the cycle of ptype_base. (If it is true in the cycle of ptype_base)
You can see below the ptype_base Loop
This is indeed the case, but if it is not run, it will return?
Quote: besides, I think there is a problem here.
Because deliver_skb (that is, executing packet_type-> func () may be kfree_skb.
This is okay, because when deliver_skb is used to operate atomic_inc (& SKB-> users), and then kfree_skb () is also atomic_dec (& SKB-> users ), free (SKB) and free (SKB-> data) are available only when SKB-> Users = 0)
Author:EexplorerTime:Title:Reply #1 hanhai Shuxiang's post
This still involves optimization issues.
If there is only one packet_type match, we can directly call pt_prev-> func (SKB, SKB-> Dev, pt_prev, orig_dev). Note that there is no increase SKB-> uesrs, this SKB is unique to this handler.
If multiple handler matches exist, increase SKB-> users is required for deliver_skb, and then in this handler, if this SKB is shared, you need skb_clone this SKB (see skb_share_check for details)
So it is so troublesome to optimize the most common case, that is, if there is only one handler match, skb_clone overhead is saved.
[This post was last edited by eexplorer]
Author:Hanhai ShuxiangTime:Title:Reply #14 eexplorer posts
This is indeed the case.
However, the ptype_all type handle is followed by the bridge and VLAN processing, followed by the ptype_base type handle processing. However, if either of the bridge and VLAN processing return NULL, directly jump to the out: Where to execute, so that the last handle will not be able to receive the packet?
Author:EexplorerTime:
Quote: original post
Hanhai ShuxiangPublished
This is indeed the case.
However, the ptype_all type handle is followed by the bridge and VLAN processing, followed by the ptype_base type handle processing. However, if either of the bridge and VLAN processing return NULL, directly jump to the out: to execute, in this case, the last one...
After reading handle_bridge and hanel_macvlan, both functions have the following code:
If (* pt_prev ){
* Ret = deliver_skb (SKB, * pt_prev, orig_dev );
* Pt_prev = NULL;
}
Author:Hanhai ShuxiangTime:Title:Reply #16 eexplorer posts
Then you will understand
Thanks.
Author:PlatinumTime:
Quote: original post
Hanhai ShuxiangPublished at, September 22
Then you will understand
Thanks.
I already said this before. I will use it later.