net: Simplify skb_tx_hash()
Subsystems (2)
PATCH 1/1 net: Simplify skb_tx_hash()
From: Krishna Kumar <[email protected]>
The initialization of skb_tx_hashrnd is moved so that it gets called after "random" driver is initialized. Random numbers generated at this point are different across 3 immediate reboots:
(reboot1) Random number: 0xd52f08b6 (reboot2) Random number: 0x8beeef46 (reboot3) Random number: 0x7d60a4b6
---
net/core/dev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
net/core/dev.c +8 -6
@@ -1745,17 +1745,11 @@ out_kfree_skb: }static u32 skb_tx_hashrnd; -static int skb_tx_hashrnd_initialized =0 ;static u16 skb_tx_hash (struct net_device *dev,struct sk_buff *skb) {u32 hash; -if (unlikely (!skb_tx_hashrnd_initialized)) { -get_random_bytes (&skb_tx_hashrnd,4 ); - skb_tx_hashrnd_initialized =1 ; - } -if (skb_rx_queue_recorded (skb)) { hash =skb_get_rx_queue (skb); }else if (skb->sk && skb->sk->sk_hash) {
@@ -5291,6 +5285,14 @@ out:subsys_initcall (net_dev_init); +static int __init initialize_hashrnd (void ) +{ +get_random_bytes (&skb_tx_hashrnd,sizeof (skb_tx_hashrnd)); +return 0 ; +} + +late_initcall_sync (initialize_hashrnd); +EXPORT_SYMBOL (__dev_get_by_index);EXPORT_SYMBOL (__dev_get_by_name);EXPORT_SYMBOL (__dev_remove_pack);
David Miller
maintainerFrom: Krishna Kumar <[email protected]>
Date: Wed, 18 Feb 2009 11:02:11 +0530
Quoted 10 lines
From: Krishna Kumar <[email protected]>
The initialization of
skb_tx_hashrndis moved so that it gets called after "random" driver is initialized. Random numbers generated at this point are different across 3 immediate reboots:(reboot1) Random number: 0xd52f08b6 (reboot2) Random number: 0x8beeef46 (reboot3) Random number: 0x7d60a4b6Signed-off-by Krishna Kumar <[email protected]>
Well, two questions:
1) How in the world are you getting a packet transmitted before the random driver initializes?
2) How can an initcall be more random than when the first packet is transmitted by the system?
A patch like this needs justification, so in your commit logs you shouldn't just list out mechanically what your patch is doing, but rather explain "why".
Hi Dave,
Quoted 3 lines
David Miller <[email protected]>
1) How in the world are you getting a packet transmitted before the random driver initializes?
(I am not sure I understood the question) Since the device is activated after late_initcalls startup sequence (during /etc/rc stage), no packets should get sent out before that. In any case, packets can be sent out earlier since skb_tx_hashrnd is set to 0.
Quoted 2 lines
2) How can an initcall be more random than when the first packet is transmitted by the system?
initcall doesn't give more random, sorry if my mail suggested that any where. I merely mentioned that the numbers generated at this stage are different at 3 successive boots (as is the case for the existing code) and hence is not broken by giving the same random numbers at each boot.
Quoted 3 lines
A patch like this needs justification, so in your commit logs you shouldn't just list out mechanically what your patch is doing, but rather explain "why".
Please let me know if I should give a better text for justification?
Thanks,
- KK
David Miller
maintainerFrom: Krishna Kumar2 <[email protected]>
Date: Wed, 18 Feb 2009 12:57:23 +0530
Quoted 6 lines
Quoted 4 lines
David Miller <[email protected]>
A patch like this needs justification, so in your commit logs you shouldn't just list out mechanically what your patch is doing, but rather explain "why".Please let me know if I should give a better text for justification?
Even after reading all of this I still don't understand why you're making the change.
Is it to eliminate the comparison every packet in skb_tx_hash()?
If so, say that in the commit message so nobody has to guess. Saying just "simplify" doesn't express that at all.