]>
Commit | Line | Data |
---|---|---|
e8fd8fec | 1 | #pragma once |
586fc304 LDM |
2 | |
3 | #include <stdbool.h> | |
4462c4ac | 4 | #include <stdio.h> |
586fc304 | 5 | #include <syslog.h> |
d917f274 | 6 | #include <limits.h> |
586fc304 | 7 | |
576dd439 | 8 | #include <shared/macro.h> |
8b7189bc | 9 | #include <shared/missing.h> |
576dd439 | 10 | |
586fc304 LDM |
11 | #include "libkmod.h" |
12 | ||
8c1c901e EV |
13 | #define kmod_log_cond(ctx, prio, arg...) \ |
14 | do { \ | |
15 | if (ENABLE_LOGGING == 1 && \ | |
16 | (ENABLE_DEBUG == 1 || (!ENABLE_DEBUG && prio != LOG_DEBUG)) && \ | |
17 | kmod_get_log_priority(ctx) >= prio) \ | |
18 | kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ##arg); \ | |
586fc304 LDM |
19 | } while (0) |
20 | ||
115bcd52 | 21 | #define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ##arg) |
115bcd52 EV |
22 | #define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ##arg) |
23 | #define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ##arg) | |
24 | #define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ##arg) | |
586fc304 | 25 | |
115bcd52 | 26 | #define KMOD_EXPORT __attribute__((visibility("default"))) |
586fc304 | 27 | |
1684e440 LDM |
28 | #define KCMD_LINE_SIZE 4096 |
29 | ||
1996121e | 30 | #if !HAVE_SECURE_GETENV |
df6ef609 EV |
31 | #warning secure_getenv is not available |
32 | #define secure_getenv getenv | |
41a51c2a CR |
33 | #endif |
34 | ||
bfea05f5 | 35 | _printf_format_(6, 7) _nonnull_(1, 3, 5) void kmod_log(const struct kmod_ctx *ctx, |
115bcd52 EV |
36 | int priority, const char *file, |
37 | int line, const char *fn, | |
38 | const char *format, ...); | |
586fc304 | 39 | |
6924e47a LDM |
40 | struct list_node { |
41 | struct list_node *next, *prev; | |
42 | }; | |
43 | ||
44 | struct kmod_list { | |
45 | struct list_node node; | |
46 | void *data; | |
47 | }; | |
48 | ||
e5398276 LDM |
49 | enum kmod_file_compression_type { |
50 | KMOD_FILE_COMPRESSION_NONE = 0, | |
51 | KMOD_FILE_COMPRESSION_ZSTD, | |
52 | KMOD_FILE_COMPRESSION_XZ, | |
53 | KMOD_FILE_COMPRESSION_ZLIB, | |
54 | }; | |
55 | ||
8335c8c8 | 56 | // clang-format off |
bfea05f5 EV |
57 | _must_check_ _nonnull_(2) struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data); |
58 | _must_check_ _nonnull_(2) struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data); | |
2f3be925 | 59 | _must_check_ struct kmod_list *kmod_list_remove(struct kmod_list *list); |
8335c8c8 | 60 | _must_check_ _nonnull_(2) struct kmod_list *kmod_list_remove_data(struct kmod_list *list, const void *data); |
bfea05f5 EV |
61 | _nonnull_(2) struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data); |
62 | _nonnull_(2) struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data); | |
2f3be925 | 63 | _must_check_ struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2); |
63aec609 TS |
64 | #define kmod_list_release(list, free_data) \ |
65 | while (list) { \ | |
66 | free_data((list)->data); \ | |
67 | list = kmod_list_remove(list); \ | |
68 | } | |
86e87885 | 69 | |
60aa4d8b | 70 | /* libkmod.c */ |
6141edc7 EV |
71 | _nonnull_all_ int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); |
72 | _nonnull_all_ int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); | |
73 | _nonnull_all_ int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); | |
74 | _nonnull_all_ int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); | |
75 | _nonnull_all_ int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); | |
76 | _nonnull_all_ int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); | |
77 | _nonnull_all_ bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name); | |
78 | _nonnull_all_ int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); | |
bfea05f5 EV |
79 | _nonnull_(1) void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited); |
80 | _nonnull_(1) void kmod_set_modules_required(struct kmod_ctx *ctx, bool required); | |
fd186ae9 | 81 | |
6141edc7 | 82 | _nonnull_all_ char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name); |
221631d5 | 83 | |
6141edc7 | 84 | _nonnull_all_ struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key); |
808eb4b8 | 85 | _nonnull_all_ int kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key); |
6141edc7 | 86 | _nonnull_all_ void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key); |
fd186ae9 | 87 | |
6141edc7 EV |
88 | _nonnull_all_ const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx); |
89 | _nonnull_all_ enum kmod_file_compression_type kmod_get_kernel_compression(const struct kmod_ctx *ctx); | |
fd186ae9 | 90 | |
60aa4d8b | 91 | /* libkmod-config.c */ |
b6a4dfb1 LDM |
92 | struct kmod_config_path { |
93 | unsigned long long stamp; | |
94 | char path[]; | |
95 | }; | |
96 | ||
7c2ab358 | 97 | struct kmod_config { |
d13e606f | 98 | struct kmod_ctx *ctx; |
7c2ab358 | 99 | struct kmod_list *aliases; |
81cf2060 | 100 | struct kmod_list *blacklists; |
615c42be | 101 | struct kmod_list *options; |
a5cce6d6 LDM |
102 | struct kmod_list *remove_commands; |
103 | struct kmod_list *install_commands; | |
1c522600 | 104 | struct kmod_list *softdeps; |
05828b4a | 105 | struct kmod_list *weakdeps; |
b6a4dfb1 LDM |
106 | |
107 | struct kmod_list *paths; | |
7c2ab358 | 108 | }; |
b6a4dfb1 | 109 | |
5a65df53 | 110 | _nonnull_all_ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char *const *config_paths); |
6141edc7 EV |
111 | _nonnull_all_ void kmod_config_free(struct kmod_config *config); |
112 | _nonnull_all_ const char *kmod_blacklist_get_modname(const struct kmod_list *l); | |
113 | _nonnull_all_ const char *kmod_alias_get_name(const struct kmod_list *l); | |
114 | _nonnull_all_ const char *kmod_alias_get_modname(const struct kmod_list *l); | |
115 | _nonnull_all_ const char *kmod_option_get_options(const struct kmod_list *l); | |
116 | _nonnull_all_ const char *kmod_option_get_modname(const struct kmod_list *l); | |
117 | _nonnull_all_ const char *kmod_command_get_command(const struct kmod_list *l); | |
118 | _nonnull_all_ const char *kmod_command_get_modname(const struct kmod_list *l); | |
119 | ||
120 | _nonnull_all_ const char *kmod_softdep_get_name(const struct kmod_list *l); | |
5a65df53 EV |
121 | _nonnull_all_ const char *const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count); |
122 | const char *const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count); | |
1c522600 | 123 | |
6141edc7 | 124 | _nonnull_all_ const char * kmod_weakdep_get_name(const struct kmod_list *l); |
5a65df53 | 125 | _nonnull_all_ const char *const *kmod_weakdep_get_weak(const struct kmod_list *l, unsigned int *count); |
7c2ab358 | 126 | |
7636e72b | 127 | /* libkmod-module.c */ |
6ad5f263 | 128 | int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod); |
be728dd3 | 129 | _nonnull_all_ void kmod_module_parse_depline(struct kmod_module *mod, char *line); |
bfea05f5 EV |
130 | _nonnull_(1) void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd); |
131 | _nonnull_(1) void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd); | |
132 | _nonnull_(1)void kmod_module_set_visited(struct kmod_module *mod, bool visited); | |
133 | _nonnull_(1) void kmod_module_set_builtin(struct kmod_module *mod, bool builtin); | |
134 | _nonnull_(1) void kmod_module_set_required(struct kmod_module *mod, bool required); | |
6141edc7 | 135 | _nonnull_all_ bool kmod_module_is_builtin(struct kmod_module *mod); |
7db08652 | 136 | |
3d8226ed | 137 | /* libkmod-file.c */ |
5cd2a2a4 EV |
138 | struct kmod_file; |
139 | struct kmod_elf; | |
140 | _must_check_ _nonnull_all_ int kmod_file_open(const struct kmod_ctx *ctx, const char *filename, struct kmod_file **file); | |
141 | _must_check_ _nonnull_all_ int kmod_file_get_elf(struct kmod_file *file, struct kmod_elf **elf); | |
6141edc7 | 142 | _nonnull_all_ int kmod_file_load_contents(struct kmod_file *file); |
0e9ac857 | 143 | _must_check_ _nonnull_all_ const void *kmod_file_get_contents(const struct kmod_file *file); |
6141edc7 EV |
144 | _must_check_ _nonnull_all_ off_t kmod_file_get_size(const struct kmod_file *file); |
145 | _must_check_ _nonnull_all_ enum kmod_file_compression_type kmod_file_get_compression(const struct kmod_file *file); | |
146 | _must_check_ _nonnull_all_ int kmod_file_get_fd(const struct kmod_file *file); | |
147 | _nonnull_all_ void kmod_file_unref(struct kmod_file *file); | |
3d8226ed | 148 | |
708624a4 | 149 | /* libkmod-elf.c */ |
708624a4 GSB |
150 | struct kmod_modversion { |
151 | uint64_t crc; | |
674f8590 | 152 | enum kmod_symbol_bind bind; |
b5c9f241 | 153 | const char *symbol; |
708624a4 GSB |
154 | }; |
155 | ||
a0fb3098 | 156 | _must_check_ _nonnull_all_ int kmod_elf_new(const void *memory, off_t size, struct kmod_elf **elf); |
6141edc7 EV |
157 | _nonnull_all_ void kmod_elf_unref(struct kmod_elf *elf); |
158 | _must_check_ _nonnull_all_ const void *kmod_elf_get_memory(const struct kmod_elf *elf); | |
9099346c | 159 | _must_check_ _nonnull_all_ int kmod_elf_get_modinfo_strings(const struct kmod_elf *elf, char ***array); |
6141edc7 EV |
160 | _must_check_ _nonnull_all_ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array); |
161 | _must_check_ _nonnull_all_ int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **array); | |
162 | _must_check_ _nonnull_all_ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array); | |
132eb4ca | 163 | _must_check_ _nonnull_all_ int kmod_elf_strip(const struct kmod_elf *elf, unsigned int flags, const void **stripped); |
7db08652 | 164 | |
ea17e2b0 LDM |
165 | /* |
166 | * Debug mock lib need to find section ".gnu.linkonce.this_module" in order to | |
167 | * get modname | |
168 | */ | |
25ab561b | 169 | _must_check_ _nonnull_all_ int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, uint64_t *sec_off, uint64_t *sec_size); |
ea17e2b0 | 170 | |
8fe1681c MM |
171 | /* libkmod-signature.c */ |
172 | struct kmod_signature_info { | |
173 | const char *signer; | |
174 | size_t signer_len; | |
175 | const char *key_id; | |
176 | size_t key_id_len; | |
177 | const char *algo, *hash_algo, *id_type; | |
e5b6a658 YK |
178 | const char *sig; |
179 | size_t sig_len; | |
391b4714 YK |
180 | void (*free)(void *); |
181 | void *private; | |
8fe1681c | 182 | }; |
6141edc7 EV |
183 | _must_check_ _nonnull_all_ bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info); |
184 | _nonnull_all_ void kmod_module_signature_info_free(struct kmod_signature_info *sig_info); | |
60084cf1 AG |
185 | |
186 | /* libkmod-builtin.c */ | |
6141edc7 | 187 | _nonnull_all_ ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname, char ***modinfo); |
8335c8c8 | 188 | // clang-format on |