@@ -51,6 +51,11 @@ struct kmod_weakdep {
5151 unsigned int n_weak ;
5252};
5353
54+ const char * kmod_mask_get_modname (const struct kmod_list * l )
55+ {
56+ return l -> data ;
57+ }
58+
5459const char * kmod_blacklist_get_modname (const struct kmod_list * l )
5560{
5661 return l -> data ;
@@ -232,6 +237,27 @@ static int kmod_config_add_blacklist(struct kmod_config *config, const char *mod
232237 return 0 ;
233238}
234239
240+ static int kmod_config_add_mask (struct kmod_config * config , const char * modname )
241+ {
242+ _cleanup_free_ char * p ;
243+ struct kmod_list * list ;
244+
245+ DBG (config -> ctx , "modname=%s\n" , modname );
246+
247+ _clang_suppress_alloc_ p = strdup (modname );
248+ if (!p )
249+ return - ENOMEM ;
250+
251+ list = kmod_list_append (config -> masks , p );
252+ if (!list )
253+ return - ENOMEM ;
254+
255+ TAKE_PTR (p );
256+ config -> masks = list ;
257+
258+ return 0 ;
259+ }
260+
235261static int kmod_config_add_softdep (struct kmod_config * config , const char * modname ,
236262 const char * line )
237263{
@@ -607,12 +633,15 @@ static char *weakdep_to_char(struct kmod_weakdep *dep)
607633static void kcmdline_parse_result (struct kmod_config * config , char * modname , char * param ,
608634 char * value )
609635{
636+ bool is_blacklist , is_mask ;
610637 if (modname == NULL || param == NULL )
611638 return ;
612639
613640 DBG (config -> ctx , "%s %s\n" , modname , param );
614641
615- if (streq (modname , "modprobe" ) && strstartswith (param , "blacklist=" )) {
642+ is_blacklist = strstartswith (param , "blacklist=" );
643+ is_mask = strstartswith (param , "mask=" );
644+ if (streq (modname , "modprobe" ) && (is_blacklist || is_mask )) {
616645 for (;;) {
617646 char * t = strsep (& value , "," );
618647 if (t == NULL )
@@ -621,7 +650,10 @@ static void kcmdline_parse_result(struct kmod_config *config, char *modname, cha
621650 if (underscores (t ) < 0 )
622651 continue ;
623652
624- kmod_config_add_blacklist (config , t );
653+ if (is_blacklist )
654+ kmod_config_add_blacklist (config , t );
655+ else
656+ kmod_config_add_mask (config , t );
625657 }
626658 } else {
627659 if (underscores (modname ) < 0 ) {
@@ -827,6 +859,13 @@ static int kmod_config_parse(struct kmod_config *config, int fd, const char *fil
827859
828860 kmod_config_add_command (config , modname , installcmd , cmd ,
829861 & config -> install_commands );
862+ } else if (streq (cmd , "mask" )) {
863+ char * modname = strtok_r (NULL , "\t " , & saveptr );
864+
865+ if (underscores (modname ) < 0 )
866+ goto syntax_error ;
867+
868+ kmod_config_add_mask (config , modname );
830869 } else if (streq (cmd , "remove" )) {
831870 char * modname = strtok_r (NULL , "\t " , & saveptr );
832871 char * removecmd = strtok_r (NULL , "\0" , & saveptr );
@@ -876,6 +915,7 @@ void kmod_config_free(struct kmod_config *config)
876915 kmod_list_release (config -> blacklists , free );
877916 kmod_list_release (config -> options , free );
878917 kmod_list_release (config -> install_commands , free );
918+ kmod_list_release (config -> masks , free );
879919 kmod_list_release (config -> remove_commands , free );
880920 kmod_list_release (config -> softdeps , free );
881921 kmod_list_release (config -> weakdeps , free );
@@ -1098,6 +1138,7 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
10981138enum config_type {
10991139 CONFIG_TYPE_BLACKLIST = 0 ,
11001140 CONFIG_TYPE_INSTALL ,
1141+ CONFIG_TYPE_MASK ,
11011142 CONFIG_TYPE_REMOVE ,
11021143 CONFIG_TYPE_ALIAS ,
11031144 CONFIG_TYPE_OPTION ,
@@ -1148,6 +1189,10 @@ static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx *ctx,
11481189 iter -> get_key = kmod_command_get_modname ;
11491190 iter -> get_value = kmod_command_get_command ;
11501191 break ;
1192+ case CONFIG_TYPE_MASK :
1193+ iter -> list = config -> masks ;
1194+ iter -> get_key = kmod_mask_get_modname ;
1195+ break ;
11511196 case CONFIG_TYPE_REMOVE :
11521197 iter -> list = config -> remove_commands ;
11531198 iter -> get_key = kmod_command_get_modname ;
@@ -1198,6 +1243,14 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_install_commands(const stru
11981243 return kmod_config_iter_new (ctx , CONFIG_TYPE_INSTALL );
11991244}
12001245
1246+ KMOD_EXPORT struct kmod_config_iter * kmod_config_get_masks (const struct kmod_ctx * ctx )
1247+ {
1248+ if (ctx == NULL )
1249+ return NULL ;
1250+
1251+ return kmod_config_iter_new (ctx , CONFIG_TYPE_MASK );
1252+ }
1253+
12011254// clang-format off
12021255KMOD_EXPORT struct kmod_config_iter * kmod_config_get_remove_commands (const struct kmod_ctx * ctx )
12031256// clang-format on
0 commit comments