@@ -1734,45 +1734,97 @@ static int __mkroute_input(struct sk_buff *skb,
17341734}
17351735
17361736#ifdef CONFIG_IP_ROUTE_MULTIPATH
1737-
17381737/* To make ICMP packets follow the right flow, the multipath hash is
1739- * calculated from the inner IP addresses in reverse order .
1738+ * calculated from the inner IP addresses.
17401739 */
1741- static int ip_multipath_icmp_hash (struct sk_buff * skb )
1740+ static void ip_multipath_l3_keys (const struct sk_buff * skb ,
1741+ struct flow_keys * hash_keys )
17421742{
17431743 const struct iphdr * outer_iph = ip_hdr (skb );
1744- struct icmphdr _icmph ;
1744+ const struct iphdr * inner_iph ;
17451745 const struct icmphdr * icmph ;
17461746 struct iphdr _inner_iph ;
1747- const struct iphdr * inner_iph ;
1747+ struct icmphdr _icmph ;
1748+
1749+ hash_keys -> addrs .v4addrs .src = outer_iph -> saddr ;
1750+ hash_keys -> addrs .v4addrs .dst = outer_iph -> daddr ;
1751+ if (likely (outer_iph -> protocol != IPPROTO_ICMP ))
1752+ return ;
17481753
17491754 if (unlikely ((outer_iph -> frag_off & htons (IP_OFFSET )) != 0 ))
1750- goto standard_hash ;
1755+ return ;
17511756
17521757 icmph = skb_header_pointer (skb , outer_iph -> ihl * 4 , sizeof (_icmph ),
17531758 & _icmph );
17541759 if (!icmph )
1755- goto standard_hash ;
1760+ return ;
17561761
17571762 if (icmph -> type != ICMP_DEST_UNREACH &&
17581763 icmph -> type != ICMP_REDIRECT &&
17591764 icmph -> type != ICMP_TIME_EXCEEDED &&
1760- icmph -> type != ICMP_PARAMETERPROB ) {
1761- goto standard_hash ;
1762- }
1765+ icmph -> type != ICMP_PARAMETERPROB )
1766+ return ;
17631767
17641768 inner_iph = skb_header_pointer (skb ,
17651769 outer_iph -> ihl * 4 + sizeof (_icmph ),
17661770 sizeof (_inner_iph ), & _inner_iph );
17671771 if (!inner_iph )
1768- goto standard_hash ;
1772+ return ;
1773+ hash_keys -> addrs .v4addrs .src = inner_iph -> saddr ;
1774+ hash_keys -> addrs .v4addrs .dst = inner_iph -> daddr ;
1775+ }
17691776
1770- return fib_multipath_hash (inner_iph -> daddr , inner_iph -> saddr );
1777+ /* if skb is set it will be used and fl4 can be NULL */
1778+ int fib_multipath_hash (const struct fib_info * fi , const struct flowi4 * fl4 ,
1779+ const struct sk_buff * skb )
1780+ {
1781+ struct net * net = fi -> fib_net ;
1782+ struct flow_keys hash_keys ;
1783+ u32 mhash ;
17711784
1772- standard_hash :
1773- return fib_multipath_hash (outer_iph -> saddr , outer_iph -> daddr );
1774- }
1785+ switch (net -> ipv4 .sysctl_fib_multipath_hash_policy ) {
1786+ case 0 :
1787+ memset (& hash_keys , 0 , sizeof (hash_keys ));
1788+ hash_keys .control .addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS ;
1789+ if (skb ) {
1790+ ip_multipath_l3_keys (skb , & hash_keys );
1791+ } else {
1792+ hash_keys .addrs .v4addrs .src = fl4 -> saddr ;
1793+ hash_keys .addrs .v4addrs .dst = fl4 -> daddr ;
1794+ }
1795+ break ;
1796+ case 1 :
1797+ /* skb is currently provided only when forwarding */
1798+ if (skb ) {
1799+ unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP ;
1800+ struct flow_keys keys ;
1801+
1802+ /* short-circuit if we already have L4 hash present */
1803+ if (skb -> l4_hash )
1804+ return skb_get_hash_raw (skb ) >> 1 ;
1805+ memset (& hash_keys , 0 , sizeof (hash_keys ));
1806+ skb_flow_dissect_flow_keys (skb , & keys , flag );
1807+ hash_keys .addrs .v4addrs .src = keys .addrs .v4addrs .src ;
1808+ hash_keys .addrs .v4addrs .dst = keys .addrs .v4addrs .dst ;
1809+ hash_keys .ports .src = keys .ports .src ;
1810+ hash_keys .ports .dst = keys .ports .dst ;
1811+ hash_keys .basic .ip_proto = keys .basic .ip_proto ;
1812+ } else {
1813+ memset (& hash_keys , 0 , sizeof (hash_keys ));
1814+ hash_keys .control .addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS ;
1815+ hash_keys .addrs .v4addrs .src = fl4 -> saddr ;
1816+ hash_keys .addrs .v4addrs .dst = fl4 -> daddr ;
1817+ hash_keys .ports .src = fl4 -> fl4_sport ;
1818+ hash_keys .ports .dst = fl4 -> fl4_dport ;
1819+ hash_keys .basic .ip_proto = fl4 -> flowi4_proto ;
1820+ }
1821+ break ;
1822+ }
1823+ mhash = flow_hash_from_keys (& hash_keys );
17751824
1825+ return mhash >> 1 ;
1826+ }
1827+ EXPORT_SYMBOL_GPL (fib_multipath_hash );
17761828#endif /* CONFIG_IP_ROUTE_MULTIPATH */
17771829
17781830static int ip_mkroute_input (struct sk_buff * skb ,
@@ -1782,12 +1834,8 @@ static int ip_mkroute_input(struct sk_buff *skb,
17821834{
17831835#ifdef CONFIG_IP_ROUTE_MULTIPATH
17841836 if (res -> fi && res -> fi -> fib_nhs > 1 ) {
1785- int h ;
1837+ int h = fib_multipath_hash ( res -> fi , NULL , skb ) ;
17861838
1787- if (unlikely (ip_hdr (skb )-> protocol == IPPROTO_ICMP ))
1788- h = ip_multipath_icmp_hash (skb );
1789- else
1790- h = fib_multipath_hash (saddr , daddr );
17911839 fib_select_multipath (res , h );
17921840 }
17931841#endif
@@ -2203,7 +2251,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
22032251 */
22042252
22052253struct rtable * __ip_route_output_key_hash (struct net * net , struct flowi4 * fl4 ,
2206- int mp_hash )
2254+ const struct sk_buff * skb )
22072255{
22082256 struct net_device * dev_out = NULL ;
22092257 __u8 tos = RT_FL_TOS (fl4 );
@@ -2365,7 +2413,7 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
23652413 goto make_route ;
23662414 }
23672415
2368- fib_select_path (net , & res , fl4 , mp_hash );
2416+ fib_select_path (net , & res , fl4 , skb );
23692417
23702418 dev_out = FIB_RES_DEV (res );
23712419 fl4 -> flowi4_oif = dev_out -> ifindex ;
0 commit comments