Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
MFC_HASH in /net/ipmr.c

I'm working on multicast and encountered this hash in linux code(ipmr.c). As far I understand, the hash table size is 64. And MFC_HASH takes highest 8 bits of ip destination address and highest 6 bits of source ip address. It XORs both and AND it with 63. Hence the result is bound to be between 0-63.

Please find the below code for more information.

struct mr_table {
          struct list_head        list;
          possible_net_t          net;
          u32                     id;
          struct sock __rcu       *mroute_sk;
          struct timer_list       ipmr_expire_timer;
          struct list_head        mfc_unres_queue;
          struct list_head        mfc_cache_array[MFC_LINES];
...
...
}

 #define MFC_LINES               64

 #ifdef __BIG_ENDIAN
 #define MFC_HASH(a,b)   ((((a)>>24)^((b)>>26))&(MFC_LINES-1))
 #else
 #define MFC_HASH(a,b)   (((a)^((b)>>2))&(MFC_LINES-1))
 #endif

What is special about this hash? How is it better than just adding the two ip addresses and doing a modulo by 63. Or just doing a modulo on the group ip address? Also if I want to increase the hash table size to 128 from 64 then is it enough if I change the MFC_LINE to 128? Or do I need to change the number of bits MFC_HASH uses from group-ip and source-ip? Can someone please help? My machine is big endian.

Thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

How is it better than just adding the two ip addresses and doing a modulo by 63.?

If you added two IP addresses and took modulo 64 (it should be 64, not 63) then higher bytes would be neglected as they are multiples of 0x40. The intent of this hash is to differentiate addresses based on highest address bits. That is why it first xors them and only then puts in [0, 63] range.

Example:

a: 255.0.0.0

b: 54.0.0.0

(a + b) = 35.0.0.2 (neglecting unsigned int overflow - hardware will discard leftmost bit)

35.0.0.0 % 64 = 0 ( 35.0.0.0 = 889192448 = 13893632 * 64 + 0)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!