config: replace config_memdup with blob_memdup from libubox
[project/netifd.git] / config.h
1 /*
2  * netifd - network interface daemon
3  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14 #ifndef __NETIFD_CONFIG_H
15 #define __NETIFD_CONFIG_H
16
17 #include <libubox/blobmsg.h>
18
19 extern bool config_init;
20
21 enum config_param_type {
22         CONFIG_PARAM_TYPE_SIMPLE,
23         CONFIG_PARAM_TYPE_LIST,
24         CONFIG_PARAM_TYPE_SECTION,
25 };
26
27 union config_param_info {
28         enum blobmsg_type type;
29         struct config_params *section;
30 };
31
32 struct config_param_list {
33         int n_params, n_next;
34
35         const struct blobmsg_policy *params;
36         const union config_param_info *info;
37
38         const struct config_param_list *next[];
39 };
40
41 #ifndef BITS_PER_LONG
42 #define BITS_PER_LONG (8 * sizeof(unsigned long))
43 #endif
44
45 static inline void set_bit(unsigned long *bits, int bit)
46 {
47         bits[bit / BITS_PER_LONG] |= (1UL << (bit % BITS_PER_LONG));
48 }
49
50 static inline bool test_bit(unsigned long *bits, int bit)
51 {
52         return !!(bits[bit / BITS_PER_LONG] & (1UL << (bit % BITS_PER_LONG)));
53 }
54
55 void config_init_all(void);
56 bool config_check_equal(struct blob_attr *c1, struct blob_attr *c2,
57                         const struct config_param_list *config);
58 bool config_diff(struct blob_attr **tb1, struct blob_attr **tb2,
59                  const struct config_param_list *config, unsigned long *diff);
60
61 #endif