]>
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 | |
88e9c12e | 8 | #include "macro.h" |
586fc304 LDM |
9 | #include "libkmod.h" |
10 | ||
a70c1e77 | 11 | static _always_inline_ _printf_format_(2, 3) void |
586fc304 LDM |
12 | kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} |
13 | ||
14 | #define kmod_log_cond(ctx, prio, arg...) \ | |
15 | do { \ | |
16 | if (kmod_get_log_priority(ctx) >= prio) \ | |
87beacc9 | 17 | kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ## arg);\ |
586fc304 LDM |
18 | } while (0) |
19 | ||
20 | #ifdef ENABLE_LOGGING | |
21 | # ifdef ENABLE_DEBUG | |
ae6df84a | 22 | # define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg) |
586fc304 | 23 | # else |
ae6df84a | 24 | # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) |
586fc304 | 25 | # endif |
ae6df84a LDM |
26 | # define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg) |
27 | # define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg) | |
586fc304 | 28 | #else |
ae6df84a LDM |
29 | # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) |
30 | # define INFO(ctx, arg...) kmod_log_null(ctx, ## arg) | |
31 | # define ERR(ctx, arg...) kmod_log_null(ctx, ## arg) | |
586fc304 LDM |
32 | #endif |
33 | ||
34 | #define KMOD_EXPORT __attribute__ ((visibility("default"))) | |
35 | ||
1684e440 LDM |
36 | #define KCMD_LINE_SIZE 4096 |
37 | ||
41a51c2a CR |
38 | #ifndef HAVE_SECURE_GETENV |
39 | # ifdef HAVE___SECURE_GETENV | |
40 | # define secure_getenv __secure_getenv | |
41 | # else | |
42 | # warning neither secure_getenv nor __secure_getenv is available | |
43 | # define secure_getenv getenv | |
44 | # endif | |
45 | #endif | |
46 | ||
1bdd951e | 47 | void kmod_log(const struct kmod_ctx *ctx, |
586fc304 | 48 | int priority, const char *file, int line, const char *fn, |
12d9419d | 49 | const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5))); |
586fc304 | 50 | |
6924e47a LDM |
51 | struct list_node { |
52 | struct list_node *next, *prev; | |
53 | }; | |
54 | ||
55 | struct kmod_list { | |
56 | struct list_node node; | |
57 | void *data; | |
58 | }; | |
59 | ||
a70c1e77 LDM |
60 | struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2))); |
61 | struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2))); | |
62 | struct kmod_list *kmod_list_remove(struct kmod_list *list) _must_check_; | |
6924e47a | 63 | struct kmod_list *kmod_list_remove_data(struct kmod_list *list, |
a70c1e77 | 64 | const void *data) _must_check_ __attribute__((nonnull(2))); |
62be7995 | 65 | struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, |
a70c1e77 | 66 | unsigned int n) _must_check_; |
86e87885 | 67 | struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); |
b91a1c6d | 68 | struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); |
a70c1e77 | 69 | struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) _must_check_; |
86e87885 | 70 | |
cf91579b LDM |
71 | #undef kmod_list_foreach |
72 | #define kmod_list_foreach(list_entry, first_entry) \ | |
d2d648df | 73 | for (list_entry = ((first_entry) == NULL) ? NULL : (first_entry); \ |
cf91579b | 74 | list_entry != NULL; \ |
d2d648df | 75 | list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \ |
cf91579b | 76 | container_of(list_entry->node.next, struct kmod_list, node)) |
60aa4d8b | 77 | |
d6b55b7d GSB |
78 | #undef kmod_list_foreach_reverse |
79 | #define kmod_list_foreach_reverse(list_entry, first_entry) \ | |
80 | for (list_entry = (((first_entry) == NULL) ? NULL : container_of(first_entry->node.prev, struct kmod_list, node)); \ | |
81 | list_entry != NULL; \ | |
82 | list_entry = ((list_entry == first_entry) ? NULL : \ | |
83 | container_of(list_entry->node.prev, struct kmod_list, node))) | |
84 | ||
60aa4d8b | 85 | /* libkmod.c */ |
1ce08a56 | 86 | const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1))); |
fd186ae9 | 87 | |
12d9419d GSB |
88 | int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
89 | int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | |
90 | int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | |
91 | int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | |
3805274b | 92 | int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
f4fc5523 | 93 | int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
ece09aac | 94 | void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited) __attribute__((nonnull((1)))); |
fd186ae9 | 95 | |
671d4894 | 96 | char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2))); |
221631d5 | 97 | |
8bdeca11 LDM |
98 | struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) __attribute__((nonnull(1,2))); |
99 | void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3))); | |
100 | void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3))); | |
fd186ae9 | 101 | |
e7fc2c86 | 102 | const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx) __attribute__((nonnull(1))); |
fd186ae9 | 103 | |
60aa4d8b | 104 | /* libkmod-config.c */ |
b6a4dfb1 LDM |
105 | struct kmod_config_path { |
106 | unsigned long long stamp; | |
107 | char path[]; | |
108 | }; | |
109 | ||
7c2ab358 | 110 | struct kmod_config { |
d13e606f | 111 | struct kmod_ctx *ctx; |
7c2ab358 | 112 | struct kmod_list *aliases; |
81cf2060 | 113 | struct kmod_list *blacklists; |
615c42be | 114 | struct kmod_list *options; |
a5cce6d6 LDM |
115 | struct kmod_list *remove_commands; |
116 | struct kmod_list *install_commands; | |
1c522600 | 117 | struct kmod_list *softdeps; |
b6a4dfb1 LDM |
118 | |
119 | struct kmod_list *paths; | |
7c2ab358 | 120 | }; |
b6a4dfb1 | 121 | |
cb8d4d3e | 122 | int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3))); |
d13e606f | 123 | void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1))); |
c1c9c446 | 124 | const char *kmod_blacklist_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); |
12d9419d GSB |
125 | const char *kmod_alias_get_name(const struct kmod_list *l) __attribute__((nonnull(1))); |
126 | const char *kmod_alias_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); | |
bd3f5535 GSB |
127 | const char *kmod_option_get_options(const struct kmod_list *l) __attribute__((nonnull(1))); |
128 | const char *kmod_option_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); | |
129 | const char *kmod_command_get_command(const struct kmod_list *l) __attribute__((nonnull(1))); | |
130 | const char *kmod_command_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); | |
131 | ||
1c522600 GSB |
132 | const char *kmod_softdep_get_name(const struct kmod_list *l) __attribute__((nonnull(1))); |
133 | const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) __attribute__((nonnull(1, 2))); | |
134 | const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count); | |
135 | ||
7c2ab358 | 136 | |
7636e72b | 137 | /* libkmod-module.c */ |
6ad5f263 | 138 | int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod); |
671d4894 | 139 | int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2))); |
f4fc5523 LDM |
140 | void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1))); |
141 | void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1))); | |
ece09aac | 142 | void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute__((nonnull(1))); |
3805274b | 143 | void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute__((nonnull((1)))); |
7636e72b | 144 | |
7db08652 | 145 | /* libkmod-hash.c */ |
529148ea LDM |
146 | |
147 | #include "libkmod-hash.h" | |
7db08652 | 148 | |
3d8226ed | 149 | /* libkmod-file.c */ |
a70c1e77 | 150 | struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2))); |
1eff942e | 151 | struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) __attribute__((nonnull(1))); |
a70c1e77 LDM |
152 | void *kmod_file_get_contents(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); |
153 | off_t kmod_file_get_size(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); | |
144d1826 KC |
154 | bool kmod_file_get_direct(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); |
155 | int kmod_file_get_fd(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); | |
3d8226ed GSB |
156 | void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1))); |
157 | ||
708624a4 GSB |
158 | /* libkmod-elf.c */ |
159 | struct kmod_elf; | |
160 | struct kmod_modversion { | |
161 | uint64_t crc; | |
674f8590 | 162 | enum kmod_symbol_bind bind; |
708624a4 GSB |
163 | char *symbol; |
164 | }; | |
165 | ||
a70c1e77 | 166 | struct kmod_elf *kmod_elf_new(const void *memory, off_t size) _must_check_ __attribute__((nonnull(1))); |
708624a4 | 167 | void kmod_elf_unref(struct kmod_elf *elf) __attribute__((nonnull(1))); |
a70c1e77 LDM |
168 | const void *kmod_elf_get_memory(const struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1))); |
169 | int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) _must_check_ __attribute__((nonnull(1,2,3))); | |
170 | int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2))); | |
171 | int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2))); | |
172 | int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2))); | |
173 | int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) _must_check_ __attribute__((nonnull(1,2))); | |
174 | int kmod_elf_strip_vermagic(struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1))); | |
7db08652 | 175 | |
ea17e2b0 LDM |
176 | /* |
177 | * Debug mock lib need to find section ".gnu.linkonce.this_module" in order to | |
178 | * get modname | |
179 | */ | |
a70c1e77 | 180 | int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size) _must_check_ __attribute__((nonnull(1,2,3,4))); |
ea17e2b0 | 181 | |
8fe1681c MM |
182 | /* libkmod-signature.c */ |
183 | struct kmod_signature_info { | |
184 | const char *signer; | |
185 | size_t signer_len; | |
186 | const char *key_id; | |
187 | size_t key_id_len; | |
188 | const char *algo, *hash_algo, *id_type; | |
189 | }; | |
190 | bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) _must_check_ __attribute__((nonnull(1, 2))); | |
60aa4d8b | 191 | /* util functions */ |
a4848e24 | 192 | #include "libkmod-util.h" |