|
EDGESEC
0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
|
File containing the implementation of the uci utilities. More...
#include <arpa/inet.h>#include <inttypes.h>#include <string.h>#include <uci.h>#include "uci_wrt.h"#include "allocs.h"#include "iface_mapper.h"#include "log.h"#include "net.h"#include "squeue.h"#include <uthash.h>Data Structures | |
| struct | uci_section_type_count |
| Hashmap that stores the count of all the seen section types. More... | |
Macros | |
| #define | IFNAME_EXPR ".ifname=" |
| #define | IPADDR_EXPR ".ipaddr=" |
| #define | IP_SECTION_STR "%d%d%d%d" |
Functions | |
| void | uwrt_print_error (struct uci_context *ctx, const char *name) |
| int | uwrt_lookup_package (struct uci_package *p, UT_array *kv) |
| int | uwrt_lookup_key (struct uci_context *ctx, char *key, UT_array *kv) |
| const char * | uwrt_extract_value (const char *str, const char *key) |
| int | uwrt_get_net_if (UT_array *kv, netif_info_t *nif) |
| int | uwrt_set_property (struct uci_context *ctx, char *property) |
| int | uwrt_set_properties (struct uci_context *ctx, UT_array *properties) |
| Set multiple OpenWRT UCI properties at once. More... | |
| int | uwrt_add_list (struct uci_context *ctx, char *property) |
| int | uwrt_add_list_properties (struct uci_context *ctx, UT_array *properties) |
| Set multiple OpenWRT UCI list properties at once. More... | |
| int | uwrt_delete_property (struct uci_context *ctx, char *property) |
| void | uwrt_delete_properties (struct uci_context *ctx, UT_array *properties) |
| Delete multiple OpenWRT UCI properties at once Errors with uwrt_delete_property will be logged and ignored. More... | |
| void | uwrt_free_context (struct uctx *context) |
| Frees the uci context. More... | |
| struct uctx * | uwrt_init_context (const char *path) |
| Initialises the uci context. More... | |
| UT_array * | uwrt_get_interfaces (const struct uctx *context, const char *ifname) |
Get the array of struct netif_info_t for each available interface. More... | |
| int | uwrt_set_interface_ip (const struct uctx *context, const char *ifname, const char *ip_addr, const char *netmask) |
| Assigns an IP to an interface. More... | |
| int | uwrt_create_interface (const struct uctx *context, const char *ifname, const char *type, const char *ip_addr, const char *brd_addr, const char *netmask) |
| Creates and interface and assigns an IP. More... | |
| int | uwrt_commit_section (const struct uctx *context, const char *section) |
| Commit a uci section. More... | |
| int | uwrt_gen_dnsmasq_instance (const struct uctx *context, const struct string_queue *ifname_queue, const UT_array *server_array, const char *leasefile, const char *scriptfile) |
| Generates a dnsmasq uci instance. More... | |
| int | uwrt_add_dhcp_pool (const struct uctx *context, const char *ifname, const char *ip_addr_low, const char *ip_addr_upp, const char *subnet_mask, const char *lease_time) |
| Adds a dhcp pool entry. More... | |
| int | uwrt_gen_hostapd_instance (const struct uctx *context, const struct hostapd_params *params) |
| Generate the hostapd config. More... | |
| int | uwrt_gen_firewall_zone (const struct uctx *context, const char *brname) |
| Generate a firewall zone for a bridge. More... | |
| int | uwrt_add_firewall_nat (const struct uctx *context, const char *brname, const char *ip_addr, const char *nat_name) |
| Adds a firewall rule for an IP address. More... | |
| int | uwrt_delete_firewall_nat (const struct uctx *context, const char *ip_addr) |
| Deletes a firewall rule for an IP address. More... | |
| int | uwrt_add_firewall_bridge (const struct uctx *context, const char *sip, const char *sbr, const char *dip, const char *dbr) |
| Adds a firewall bridge rule for two IP addresses. More... | |
| int | uwrt_delete_firewall_bridge (const struct uctx *context, const char *sip, const char *dip) |
| Deletes a firewall bridge rule for two IP addresses. More... | |
| int | uwrt_cleanup_firewall (const struct uctx *context) |
| Removes all the firewall rules. More... | |
File containing the implementation of the uci utilities.
Utility functions for working with UCI (Unified Configuration Interface), which is most commonly used to configure OpenWRT services.
Please see https://openwrt.org/docs/guide-user/base-system/uci for a description of UCI data/object model.
| #define IFNAME_EXPR ".ifname=" |
| #define IP_SECTION_STR "%d%d%d%d" |
| #define IPADDR_EXPR ".ipaddr=" |
| int uwrt_add_dhcp_pool | ( | const struct uctx * | context, |
| const char * | ifname, | ||
| const char * | ip_addr_low, | ||
| const char * | ip_addr_upp, | ||
| const char * | subnet_mask, | ||
| const char * | lease_time | ||
| ) |
Adds a dhcp pool entry.
| context | The uci context |
| ifname | The interface name |
| ip_addr_low | Interface string IP address lower bound |
| ip_addr_upp | Interface string IP address upper bound |
| subnet_mask | Interface string IP subnet mask |
| lease_time | Interface lease time string |
| int uwrt_add_firewall_bridge | ( | const struct uctx * | context, |
| const char * | sip, | ||
| const char * | sbr, | ||
| const char * | dip, | ||
| const char * | dbr | ||
| ) |
Adds a firewall bridge rule for two IP addresses.
| context | The uci context |
| sip | The source IP address |
| sbr | The source bridge interface name |
| dip | The destination IP address |
| dbr | The destination bridge interface name |
| int uwrt_add_firewall_nat | ( | const struct uctx * | context, |
| const char * | brname, | ||
| const char * | ip_addr, | ||
| const char * | nat_name | ||
| ) |
Adds a firewall rule for an IP address.
| context | The uci context |
| brname | The bridge name |
| ip_addr | The IP address |
| nat_name | The NAT bridge name |
| int uwrt_add_list | ( | struct uci_context * | ctx, |
| char * | property | ||
| ) |
| int uwrt_add_list_properties | ( | struct uci_context * | ctx, |
| UT_array * | properties | ||
| ) |
Set multiple OpenWRT UCI list properties at once.
| [in] | ctx | UCI context. The context ptr will be modified. |
| [in] | properties | Array of list properties to set. Warning, strings may be modified by UCI. |
| 0 | Success |
| -1 | Error |
| int uwrt_cleanup_firewall | ( | const struct uctx * | context | ) |
Removes all the firewall rules.
| context | The uci context |
| int uwrt_commit_section | ( | const struct uctx * | context, |
| const char * | section | ||
| ) |
Commit a uci section.
| context | The uci context |
| section | The uci section |
| int uwrt_create_interface | ( | const struct uctx * | context, |
| const char * | ifname, | ||
| const char * | type, | ||
| const char * | ip_addr, | ||
| const char * | brd_addr, | ||
| const char * | netmask | ||
| ) |
Creates and interface and assigns an IP.
| context | The uci context |
| ifname | The interface name |
| type | The interface type |
| ip_addr | The interface IP4 address |
| brd_addr | The interface IP4 broadcast address |
| netmask | The interface IP4 netmask |
| int uwrt_delete_firewall_bridge | ( | const struct uctx * | context, |
| const char * | sip, | ||
| const char * | dip | ||
| ) |
Deletes a firewall bridge rule for two IP addresses.
| context | The uci context |
| sip | The source IP address |
| dip | The destination IP address |
| int uwrt_delete_firewall_nat | ( | const struct uctx * | context, |
| const char * | ip_addr | ||
| ) |
Deletes a firewall rule for an IP address.
| context | The uci context |
| ip_addr | The IP address |
| void uwrt_delete_properties | ( | struct uci_context * | ctx, |
| UT_array * | properties | ||
| ) |
Delete multiple OpenWRT UCI properties at once Errors with uwrt_delete_property will be logged and ignored.
| [in] | ctx | UCI context. The context ptr will be modified. |
| [in] | properties | Array of properties to delete. Warning, strings may be modified by UCI. |
| int uwrt_delete_property | ( | struct uci_context * | ctx, |
| char * | property | ||
| ) |
| const char* uwrt_extract_value | ( | const char * | str, |
| const char * | key | ||
| ) |
| void uwrt_free_context | ( | struct uctx * | context | ) |
Frees the uci context.
| context | The uci context |
| int uwrt_gen_dnsmasq_instance | ( | const struct uctx * | context, |
| const struct string_queue * | ifname_queue, | ||
| const UT_array * | server_array, | ||
| const char * | leasefile, | ||
| const char * | scriptfile | ||
| ) |
Generates a dnsmasq uci instance.
| context | The uci context |
| ifname_queue | The interface queue |
| server_array | The array of servers |
| leasefile | The lease file path string |
| scriptfile | The script file path string |
| int uwrt_gen_firewall_zone | ( | const struct uctx * | context, |
| const char * | brname | ||
| ) |
Generate a firewall zone for a bridge.
| context | The uci context |
| brname | The bridge name |
| int uwrt_gen_hostapd_instance | ( | const struct uctx * | context, |
| const struct hostapd_params * | params | ||
| ) |
Generate the hostapd config.
| context | The uci context |
| params | The hostapd params |
| UT_array* uwrt_get_interfaces | ( | const struct uctx * | context, |
| const char * | ifname | ||
| ) |
Get the array of struct netif_info_t for each available interface.
| context | The uci context |
| ifname | The interface name, if NULL return all interfaces |
struct netif_info_t This return variable must be cleaned up by utarray_free(). | int uwrt_get_net_if | ( | UT_array * | kv, |
| netif_info_t * | nif | ||
| ) |
| struct uctx* uwrt_init_context | ( | const char * | path | ) |
Initialises the uci context.
| path | The path string to the config folder |
NULL on error. This return variable must be cleaned up by uwrt_free_context(). | int uwrt_lookup_key | ( | struct uci_context * | ctx, |
| char * | key, | ||
| UT_array * | kv | ||
| ) |
| int uwrt_lookup_package | ( | struct uci_package * | p, |
| UT_array * | kv | ||
| ) |
Counts the section types we've already encountered
| void uwrt_print_error | ( | struct uci_context * | ctx, |
| const char * | name | ||
| ) |
| int uwrt_set_interface_ip | ( | const struct uctx * | context, |
| const char * | ifname, | ||
| const char * | ip_addr, | ||
| const char * | netmask | ||
| ) |
Assigns an IP to an interface.
| context | The uci context |
| ifname | The interface name |
| ip_addr | The interface IP4 address |
| netmask | The interface IP4 netmask |
| int uwrt_set_properties | ( | struct uci_context * | ctx, |
| UT_array * | properties | ||
| ) |
Set multiple OpenWRT UCI properties at once.
| [in] | ctx | UCI context. The context ptr will be modified. |
| [in] | properties | Array of properties to set. Warning, strings may be modified by UCI. |
| 0 | Success |
| -1 | Error |
| int uwrt_set_property | ( | struct uci_context * | ctx, |
| char * | property | ||
| ) |