@@ -33,9 +33,11 @@ static struct tcp_congestion_ops *tcp_ca_find(const char *name)
3333}
3434
3535/* Must be called with rcu lock held */
36- static const struct tcp_congestion_ops * __tcp_ca_find_autoload (const char * name )
36+ static struct tcp_congestion_ops * tcp_ca_find_autoload (struct net * net ,
37+ const char * name )
3738{
38- const struct tcp_congestion_ops * ca = tcp_ca_find (name );
39+ struct tcp_congestion_ops * ca = tcp_ca_find (name );
40+
3941#ifdef CONFIG_MODULES
4042 if (!ca && capable (CAP_NET_ADMIN )) {
4143 rcu_read_unlock ();
@@ -115,15 +117,15 @@ void tcp_unregister_congestion_control(struct tcp_congestion_ops *ca)
115117}
116118EXPORT_SYMBOL_GPL (tcp_unregister_congestion_control );
117119
118- u32 tcp_ca_get_key_by_name (const char * name , bool * ecn_ca )
120+ u32 tcp_ca_get_key_by_name (struct net * net , const char * name , bool * ecn_ca )
119121{
120122 const struct tcp_congestion_ops * ca ;
121123 u32 key = TCP_CA_UNSPEC ;
122124
123125 might_sleep ();
124126
125127 rcu_read_lock ();
126- ca = __tcp_ca_find_autoload ( name );
128+ ca = tcp_ca_find_autoload ( net , name );
127129 if (ca ) {
128130 key = ca -> key ;
129131 * ecn_ca = ca -> flags & TCP_CONG_NEEDS_ECN ;
@@ -153,23 +155,18 @@ EXPORT_SYMBOL_GPL(tcp_ca_get_name_by_key);
153155/* Assign choice of congestion control. */
154156void tcp_assign_congestion_control (struct sock * sk )
155157{
158+ struct net * net = sock_net (sk );
156159 struct inet_connection_sock * icsk = inet_csk (sk );
157- struct tcp_congestion_ops * ca ;
160+ const struct tcp_congestion_ops * ca ;
158161
159162 rcu_read_lock ();
160- list_for_each_entry_rcu (ca , & tcp_cong_list , list ) {
161- if (likely (try_module_get (ca -> owner ))) {
162- icsk -> icsk_ca_ops = ca ;
163- goto out ;
164- }
165- /* Fallback to next available. The last really
166- * guaranteed fallback is Reno from this list.
167- */
168- }
169- out :
163+ ca = rcu_dereference (net -> ipv4 .tcp_congestion_control );
164+ if (unlikely (!try_module_get (ca -> owner )))
165+ ca = & tcp_reno ;
166+ icsk -> icsk_ca_ops = ca ;
170167 rcu_read_unlock ();
171- memset (icsk -> icsk_ca_priv , 0 , sizeof (icsk -> icsk_ca_priv ));
172168
169+ memset (icsk -> icsk_ca_priv , 0 , sizeof (icsk -> icsk_ca_priv ));
173170 if (ca -> flags & TCP_CONG_NEEDS_ECN )
174171 INET_ECN_xmit (sk );
175172 else
@@ -214,37 +211,36 @@ void tcp_cleanup_congestion_control(struct sock *sk)
214211}
215212
216213/* Used by sysctl to change default congestion control */
217- int tcp_set_default_congestion_control (const char * name )
214+ int tcp_set_default_congestion_control (struct net * net , const char * name )
218215{
219216 struct tcp_congestion_ops * ca ;
220- int ret = - ENOENT ;
221-
222- spin_lock (& tcp_cong_list_lock );
223- ca = tcp_ca_find (name );
224- #ifdef CONFIG_MODULES
225- if (!ca && capable (CAP_NET_ADMIN )) {
226- spin_unlock (& tcp_cong_list_lock );
217+ const struct tcp_congestion_ops * prev ;
218+ int ret ;
227219
228- request_module ("tcp_%s" , name );
229- spin_lock (& tcp_cong_list_lock );
230- ca = tcp_ca_find (name );
231- }
232- #endif
220+ rcu_read_lock ();
221+ ca = tcp_ca_find_autoload (net , name );
222+ if (!ca ) {
223+ ret = - ENOENT ;
224+ } else if (!try_module_get (ca -> owner )) {
225+ ret = - EBUSY ;
226+ } else {
227+ prev = xchg (& net -> ipv4 .tcp_congestion_control , ca );
228+ if (prev )
229+ module_put (prev -> owner );
233230
234- if (ca ) {
235- ca -> flags |= TCP_CONG_NON_RESTRICTED ; /* default is always allowed */
236- list_move (& ca -> list , & tcp_cong_list );
231+ ca -> flags |= TCP_CONG_NON_RESTRICTED ;
237232 ret = 0 ;
238233 }
239- spin_unlock ( & tcp_cong_list_lock );
234+ rcu_read_unlock ( );
240235
241236 return ret ;
242237}
243238
244239/* Set default value from kernel configuration at bootup */
245240static int __init tcp_congestion_default (void )
246241{
247- return tcp_set_default_congestion_control (CONFIG_DEFAULT_TCP_CONG );
242+ return tcp_set_default_congestion_control (& init_net ,
243+ CONFIG_DEFAULT_TCP_CONG );
248244}
249245late_initcall (tcp_congestion_default );
250246
@@ -264,14 +260,12 @@ void tcp_get_available_congestion_control(char *buf, size_t maxlen)
264260}
265261
266262/* Get current default congestion control */
267- void tcp_get_default_congestion_control (char * name )
263+ void tcp_get_default_congestion_control (struct net * net , char * name )
268264{
269- struct tcp_congestion_ops * ca ;
270- /* We will always have reno... */
271- BUG_ON (list_empty (& tcp_cong_list ));
265+ const struct tcp_congestion_ops * ca ;
272266
273267 rcu_read_lock ();
274- ca = list_entry ( tcp_cong_list . next , struct tcp_congestion_ops , list );
268+ ca = rcu_dereference ( net -> ipv4 . tcp_congestion_control );
275269 strncpy (name , ca -> name , TCP_CA_NAME_MAX );
276270 rcu_read_unlock ();
277271}
@@ -351,12 +345,14 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, boo
351345 if (!load )
352346 ca = tcp_ca_find (name );
353347 else
354- ca = __tcp_ca_find_autoload (name );
348+ ca = tcp_ca_find_autoload (sock_net (sk ), name );
349+
355350 /* No change asking for existing value */
356351 if (ca == icsk -> icsk_ca_ops ) {
357352 icsk -> icsk_ca_setsockopt = 1 ;
358353 goto out ;
359354 }
355+
360356 if (!ca ) {
361357 err = - ENOENT ;
362358 } else if (!load ) {
0 commit comments