File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -195,23 +195,29 @@ static const struct nf_hook_ops ila_nf_hook_ops[] = {
195195 },
196196};
197197
198+ static DEFINE_MUTEX (ila_mutex );
199+
198200static int ila_add_mapping (struct net * net , struct ila_xlat_params * xp )
199201{
200202 struct ila_net * ilan = net_generic (net , ila_net_id );
201203 struct ila_map * ila , * head ;
202204 spinlock_t * lock = ila_get_lock (ilan , xp -> ip .locator_match );
203205 int err = 0 , order ;
204206
205- if (!ilan -> xlat .hooks_registered ) {
207+ if (!READ_ONCE ( ilan -> xlat .hooks_registered ) ) {
206208 /* We defer registering net hooks in the namespace until the
207209 * first mapping is added.
208210 */
209- err = nf_register_net_hooks (net , ila_nf_hook_ops ,
210- ARRAY_SIZE (ila_nf_hook_ops ));
211+ mutex_lock (& ila_mutex );
212+ if (!ilan -> xlat .hooks_registered ) {
213+ err = nf_register_net_hooks (net , ila_nf_hook_ops ,
214+ ARRAY_SIZE (ila_nf_hook_ops ));
215+ if (!err )
216+ WRITE_ONCE (ilan -> xlat .hooks_registered , true);
217+ }
218+ mutex_unlock (& ila_mutex );
211219 if (err )
212220 return err ;
213-
214- ilan -> xlat .hooks_registered = true;
215221 }
216222
217223 ila = kzalloc (sizeof (* ila ), GFP_KERNEL );
You can’t perform that action at this time.
0 commit comments