forked from mirrors/linux
		
	net: fib: move metrics parsing to a helper
fib_create_info() is already quite large, so before adding more code to the metrics section move that to a helper, similar to ip6_convert_metrics. Suggested-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									87583ebb9f
								
							
						
					
					
						commit
						6cf9dfd3bd
					
				
					 1 changed files with 41 additions and 30 deletions
				
			
		|  | @ -876,6 +876,44 @@ static bool fib_valid_prefsrc(struct fib_config *cfg, __be32 fib_prefsrc) | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static int | ||||||
|  | fib_convert_metrics(struct fib_info *fi, const struct fib_config *cfg) | ||||||
|  | { | ||||||
|  | 	struct nlattr *nla; | ||||||
|  | 	int remaining; | ||||||
|  | 
 | ||||||
|  | 	if (!cfg->fc_mx) | ||||||
|  | 		return 0; | ||||||
|  | 
 | ||||||
|  | 	nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) { | ||||||
|  | 		int type = nla_type(nla); | ||||||
|  | 		u32 val; | ||||||
|  | 
 | ||||||
|  | 		if (!type) | ||||||
|  | 			continue; | ||||||
|  | 		if (type > RTAX_MAX) | ||||||
|  | 			return -EINVAL; | ||||||
|  | 
 | ||||||
|  | 		if (type == RTAX_CC_ALGO) { | ||||||
|  | 			char tmp[TCP_CA_NAME_MAX]; | ||||||
|  | 
 | ||||||
|  | 			nla_strlcpy(tmp, nla, sizeof(tmp)); | ||||||
|  | 			val = tcp_ca_get_key_by_name(tmp); | ||||||
|  | 			if (val == TCP_CA_UNSPEC) | ||||||
|  | 				return -EINVAL; | ||||||
|  | 		} else { | ||||||
|  | 			val = nla_get_u32(nla); | ||||||
|  | 		} | ||||||
|  | 		if (type == RTAX_ADVMSS && val > 65535 - 40) | ||||||
|  | 			val = 65535 - 40; | ||||||
|  | 		if (type == RTAX_MTU && val > 65535 - 15) | ||||||
|  | 			val = 65535 - 15; | ||||||
|  | 		fi->fib_metrics[type - 1] = val; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| struct fib_info *fib_create_info(struct fib_config *cfg) | struct fib_info *fib_create_info(struct fib_config *cfg) | ||||||
| { | { | ||||||
| 	int err; | 	int err; | ||||||
|  | @ -948,36 +986,9 @@ struct fib_info *fib_create_info(struct fib_config *cfg) | ||||||
| 			goto failure; | 			goto failure; | ||||||
| 	} endfor_nexthops(fi) | 	} endfor_nexthops(fi) | ||||||
| 
 | 
 | ||||||
| 	if (cfg->fc_mx) { | 	err = fib_convert_metrics(fi, cfg); | ||||||
| 		struct nlattr *nla; | 	if (err) | ||||||
| 		int remaining; | 		goto failure; | ||||||
| 
 |  | ||||||
| 		nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) { |  | ||||||
| 			int type = nla_type(nla); |  | ||||||
| 
 |  | ||||||
| 			if (type) { |  | ||||||
| 				u32 val; |  | ||||||
| 
 |  | ||||||
| 				if (type > RTAX_MAX) |  | ||||||
| 					goto err_inval; |  | ||||||
| 				if (type == RTAX_CC_ALGO) { |  | ||||||
| 					char tmp[TCP_CA_NAME_MAX]; |  | ||||||
| 
 |  | ||||||
| 					nla_strlcpy(tmp, nla, sizeof(tmp)); |  | ||||||
| 					val = tcp_ca_get_key_by_name(tmp); |  | ||||||
| 					if (val == TCP_CA_UNSPEC) |  | ||||||
| 						goto err_inval; |  | ||||||
| 				} else { |  | ||||||
| 					val = nla_get_u32(nla); |  | ||||||
| 				} |  | ||||||
| 				if (type == RTAX_ADVMSS && val > 65535 - 40) |  | ||||||
| 					val = 65535 - 40; |  | ||||||
| 				if (type == RTAX_MTU && val > 65535 - 15) |  | ||||||
| 					val = 65535 - 15; |  | ||||||
| 				fi->fib_metrics[type - 1] = val; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if (cfg->fc_mp) { | 	if (cfg->fc_mp) { | ||||||
| #ifdef CONFIG_IP_ROUTE_MULTIPATH | #ifdef CONFIG_IP_ROUTE_MULTIPATH | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Florian Westphal
						Florian Westphal