diff options
Diffstat (limited to 'net/ipv4/fib_semantics.c')
| -rw-r--r-- | net/ipv4/fib_semantics.c | 80 | 
1 files changed, 79 insertions, 1 deletions
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index e5b7182fa099..da80dc14cc76 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -140,6 +140,62 @@ const struct fib_prop fib_props[RTN_MAX + 1] = {  	},  }; +static void rt_fibinfo_free(struct rtable __rcu **rtp) +{ +	struct rtable *rt = rcu_dereference_protected(*rtp, 1); + +	if (!rt) +		return; + +	/* Not even needed : RCU_INIT_POINTER(*rtp, NULL); +	 * because we waited an RCU grace period before calling +	 * free_fib_info_rcu() +	 */ + +	dst_free(&rt->dst); +} + +static void free_nh_exceptions(struct fib_nh *nh) +{ +	struct fnhe_hash_bucket *hash = nh->nh_exceptions; +	int i; + +	for (i = 0; i < FNHE_HASH_SIZE; i++) { +		struct fib_nh_exception *fnhe; + +		fnhe = rcu_dereference_protected(hash[i].chain, 1); +		while (fnhe) { +			struct fib_nh_exception *next; +			 +			next = rcu_dereference_protected(fnhe->fnhe_next, 1); + +			rt_fibinfo_free(&fnhe->fnhe_rth); + +			kfree(fnhe); + +			fnhe = next; +		} +	} +	kfree(hash); +} + +static void rt_fibinfo_free_cpus(struct rtable __rcu * __percpu *rtp) +{ +	int cpu; + +	if (!rtp) +		return; + +	for_each_possible_cpu(cpu) { +		struct rtable *rt; + +		rt = rcu_dereference_protected(*per_cpu_ptr(rtp, cpu), 1); +		if (rt) +			dst_free(&rt->dst); +	} +	free_percpu(rtp); +} +  /* Release a nexthop info record */  static void free_fib_info_rcu(struct rcu_head *head)  { @@ -148,6 +204,10 @@ static void free_fib_info_rcu(struct rcu_head *head)  	change_nexthops(fi) {  		if (nexthop_nh->nh_dev)  			dev_put(nexthop_nh->nh_dev); +		if (nexthop_nh->nh_exceptions) +			free_nh_exceptions(nexthop_nh); +		rt_fibinfo_free_cpus(nexthop_nh->nh_pcpu_rth_output); +		rt_fibinfo_free(&nexthop_nh->nh_rth_input);  	} endfor_nexthops(fi);  	release_net(fi->fib_net); @@ -163,6 +223,12 @@ void free_fib_info(struct fib_info *fi)  		return;  	}  	fib_info_cnt--; +#ifdef CONFIG_IP_ROUTE_CLASSID +	change_nexthops(fi) { +		if (nexthop_nh->nh_tclassid) +			fi->fib_net->ipv4.fib_num_tclassid_users--; +	} endfor_nexthops(fi); +#endif  	call_rcu(&fi->rcu, free_fib_info_rcu);  } @@ -421,6 +487,8 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,  #ifdef CONFIG_IP_ROUTE_CLASSID  			nla = nla_find(attrs, attrlen, RTA_FLOW);  			nexthop_nh->nh_tclassid = nla ? nla_get_u32(nla) : 0; +			if (nexthop_nh->nh_tclassid) +				fi->fib_net->ipv4.fib_num_tclassid_users++;  #endif  		} @@ -769,6 +837,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)  	fi->fib_nhs = nhs;  	change_nexthops(fi) {  		nexthop_nh->nh_parent = fi; +		nexthop_nh->nh_pcpu_rth_output = alloc_percpu(struct rtable __rcu *);  	} endfor_nexthops(fi)  	if (cfg->fc_mx) { @@ -779,9 +848,16 @@ struct fib_info *fib_create_info(struct fib_config *cfg)  			int type = nla_type(nla);  			if (type) { +				u32 val; +  				if (type > RTAX_MAX)  					goto err_inval; -				fi->fib_metrics[type - 1] = nla_get_u32(nla); +				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;  			}  		}  	} @@ -810,6 +886,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg)  		nh->nh_flags = cfg->fc_flags;  #ifdef CONFIG_IP_ROUTE_CLASSID  		nh->nh_tclassid = cfg->fc_flow; +		if (nh->nh_tclassid) +			fi->fib_net->ipv4.fib_num_tclassid_users++;  #endif  #ifdef CONFIG_IP_ROUTE_MULTIPATH  		nh->nh_weight = 1;  | 
