From 63d0813f9357b6d4eba2cac2ba8cb1efd8c0c9ac Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Sat, 8 Apr 2017 21:34:59 +0200 Subject: [PATCH] Sync ubus familly tools. --- src/3P/libubox/.gitignore | 1 - src/3P/libubox/blob.h | 4 +- src/3P/libubox/blobmsg.h | 2 +- src/3P/libubox/blobmsg_json.c | 2 +- src/3P/libubox/jshn.c | 2 +- src/3P/libubox/kvlist.h | 10 --- src/3P/libubox/uloop.c | 1 - src/3P/netifd/CMakeLists.txt | 5 ++ src/3P/netifd/bridge.c | 2 + src/3P/netifd/builders/cmake/CMakeLists.txt | 46 +++++------ src/3P/netifd/config.c | 2 +- src/3P/netifd/config.h | 2 +- src/3P/netifd/device.c | 10 --- src/3P/netifd/device.h | 3 - src/3P/netifd/interface-ip.c | 21 +---- src/3P/netifd/interface-ip.h | 5 +- src/3P/netifd/proto.c | 19 ++--- src/3P/netifd/system-dummy.c | 6 -- src/3P/netifd/system-linux.c | 83 +++---------------- src/3P/netifd/system.h | 1 - src/3P/netifd/ubus.c | 3 - src/3P/netifd/utils.h | 2 +- src/3P/procd/jail/jail.c | 24 +----- src/3P/ubox/builders/cmake/CMakeLists.txt | 40 ++++++++++ src/3P/ubox/getrandom.c | 50 ++++++------ src/3P/ubox/kmodloader.c | 5 +- src/3P/ubox/log/logd.c | 84 ++++++-------------- src/3P/ubox/log/logread.c | 3 +- src/3P/ubox/log/syslog.c | 8 +- src/3P/ubox/validate/cli.c | 65 ++++++++------- src/3P/ubox/validate/validate.c | 2 +- src/3P/ubus/.gitignore | 2 - src/3P/ubus/CMakeLists.original.txt | 55 +++++++++++++ src/3P/ubus/CMakeLists.txt | 88 ++++++++++++--------- src/3P/ubus/cli.c | 11 +-- src/3P/ubus/libubus-internal.h | 4 +- src/3P/ubus/libubus-obj.c | 24 ++---- src/3P/ubus/libubus-req.c | 49 ++++++------ src/3P/ubus/libubus.c | 7 +- src/3P/ubus/libubus.h | 33 ++------ src/3P/ubus/lua/publisher.lua | 0 src/3P/ubus/lua/subscriber.lua | 0 src/3P/ubus/lua/test.lua | 12 --- src/3P/ubus/lua/ubus.c | 22 ------ src/3P/ubus/ubusd.c | 5 +- src/3P/ubus/ubusd_acl.c | 4 +- src/3P/ubus/ubusd_proto.c | 20 ++--- src/3P/ubus/ubusmsg.h | 3 +- src/3P/uci/builders/cmake/CMakeLists.txt | 47 +++++++++++ src/3P/uci/uci.h | 2 +- src/3P/uhttpd/CMakeLists.txt | 3 - src/3P/uhttpd/cgi.c | 6 +- src/3P/uhttpd/client.c | 8 -- src/3P/uhttpd/file.c | 23 ++---- src/3P/uhttpd/handler.c | 30 +------ src/3P/uhttpd/uhttpd.h | 2 - src/3P/uhttpd/utils.c | 4 - 57 files changed, 413 insertions(+), 564 deletions(-) create mode 100644 src/3P/ubox/builders/cmake/CMakeLists.txt create mode 100644 src/3P/ubus/CMakeLists.original.txt mode change 100755 => 100644 src/3P/ubus/lua/publisher.lua mode change 100755 => 100644 src/3P/ubus/lua/subscriber.lua create mode 100644 src/3P/uci/builders/cmake/CMakeLists.txt diff --git a/src/3P/libubox/.gitignore b/src/3P/libubox/.gitignore index 5ffd2358..0c59f966 100644 --- a/src/3P/libubox/.gitignore +++ b/src/3P/libubox/.gitignore @@ -8,4 +8,3 @@ CMakeFiles install_manifest.txt jshn *-example -tests.* diff --git a/src/3P/libubox/blob.h b/src/3P/libubox/blob.h index 307523d0..ab077eab 100644 --- a/src/3P/libubox/blob.h +++ b/src/3P/libubox/blob.h @@ -240,7 +240,7 @@ blob_put_u64(struct blob_buf *buf, int id, uint64_t val) #define blob_put_int64 blob_put_u64 #define __blob_for_each_attr(pos, attr, rem) \ - for (pos = (struct blob_attr *) attr; \ + for (pos = (void *) attr; \ rem > 0 && (blob_pad_len(pos) <= rem) && \ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \ rem -= blob_pad_len(pos), pos = blob_next(pos)) @@ -248,7 +248,7 @@ blob_put_u64(struct blob_buf *buf, int id, uint64_t val) #define blob_for_each_attr(pos, attr, rem) \ for (rem = attr ? blob_len(attr) : 0, \ - pos = (struct blob_attr *) (attr ? blob_data(attr) : NULL); \ + pos = attr ? blob_data(attr) : 0; \ rem > 0 && (blob_pad_len(pos) <= rem) && \ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \ rem -= blob_pad_len(pos), pos = blob_next(pos)) diff --git a/src/3P/libubox/blobmsg.h b/src/3P/libubox/blobmsg.h index 861a4e8d..84997a67 100644 --- a/src/3P/libubox/blobmsg.h +++ b/src/3P/libubox/blobmsg.h @@ -233,7 +233,7 @@ int blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, . #define blobmsg_for_each_attr(pos, attr, rem) \ for (rem = attr ? blobmsg_data_len(attr) : 0, \ - pos = (struct blob_attr *) (attr ? blobmsg_data(attr) : NULL); \ + pos = attr ? blobmsg_data(attr) : 0; \ rem > 0 && (blob_pad_len(pos) <= rem) && \ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \ rem -= blob_pad_len(pos), pos = blob_next(pos)) diff --git a/src/3P/libubox/blobmsg_json.c b/src/3P/libubox/blobmsg_json.c index 8a6ed8f8..72d0de6e 100644 --- a/src/3P/libubox/blobmsg_json.c +++ b/src/3P/libubox/blobmsg_json.c @@ -18,7 +18,7 @@ #include "blobmsg_json.h" #ifdef JSONC - #include + #include #else #include #endif diff --git a/src/3P/libubox/jshn.c b/src/3P/libubox/jshn.c index 49890994..d396d8f6 100644 --- a/src/3P/libubox/jshn.c +++ b/src/3P/libubox/jshn.c @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifdef JSONC - #include + #include #else #include #endif diff --git a/src/3P/libubox/kvlist.h b/src/3P/libubox/kvlist.h index eaa691c2..d59ff9e0 100644 --- a/src/3P/libubox/kvlist.h +++ b/src/3P/libubox/kvlist.h @@ -18,7 +18,6 @@ #ifndef __LIBUBOX_KVLIST_H #define __LIBUBOX_KVLIST_H -#include "avl-cmp.h" #include "avl.h" struct kvlist { @@ -33,15 +32,6 @@ struct kvlist_node { char data[0] __attribute__((aligned(4))); }; -#define KVLIST_INIT(_name, _get_len) \ - { \ - .avl = AVL_TREE_INIT(_name.avl, avl_strcmp, false, NULL), \ - .get_len = _get_len \ - } - -#define KVLIST(_name, _get_len) \ - struct kvlist _name = KVLIST_INIT(_name, _get_len) - #define __ptr_to_kv(_ptr) container_of(((char *) (_ptr)), struct kvlist_node, data[0]) #define __avl_list_to_kv(_l) container_of(_l, struct kvlist_node, avl.list) diff --git a/src/3P/libubox/uloop.c b/src/3P/libubox/uloop.c index 1c5bcee7..296366e8 100644 --- a/src/3P/libubox/uloop.c +++ b/src/3P/libubox/uloop.c @@ -382,7 +382,6 @@ static void uloop_handle_processes(void) p->cb(p, ret); } } - } static void uloop_signal_wake(void) diff --git a/src/3P/netifd/CMakeLists.txt b/src/3P/netifd/CMakeLists.txt index 1f35d260..85527bec 100644 --- a/src/3P/netifd/CMakeLists.txt +++ b/src/3P/netifd/CMakeLists.txt @@ -5,6 +5,11 @@ ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations) SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +IF(APPLE) + INCLUDE_DIRECTORIES(/opt/local/include) + LINK_DIRECTORIES(/opt/local/lib) +ENDIF() + SET(SOURCES main.c utils.c system.c tunnel.c handler.c interface.c interface-ip.c interface-event.c diff --git a/src/3P/netifd/bridge.c b/src/3P/netifd/bridge.c index c46d44e2..ba1ce5d2 100644 --- a/src/3P/netifd/bridge.c +++ b/src/3P/netifd/bridge.c @@ -568,6 +568,8 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb) /* defaults */ cfg->stp = false; cfg->forward_delay = 2; + cfg->igmp_snoop = true; + cfg->multicast_querier = true; cfg->robustness = 2; cfg->query_interval = 12500; cfg->query_response_interval = 1000; diff --git a/src/3P/netifd/builders/cmake/CMakeLists.txt b/src/3P/netifd/builders/cmake/CMakeLists.txt index a2617f3c..eefb8126 100644 --- a/src/3P/netifd/builders/cmake/CMakeLists.txt +++ b/src/3P/netifd/builders/cmake/CMakeLists.txt @@ -10,35 +10,35 @@ set (CMAKE_MODULE_PATH "${MODULE_PATH}") set(DISABLE_TARGET_OPTIMIZATION ON) -include (br) +include (aw) file ( GLOB_RECURSE source_files - $ENV{SRC_DIR}/src/3P/netifd/main.c - $ENV{SRC_DIR}/src/3P/netifd/utils.c - $ENV{SRC_DIR}/src/3P/netifd/system.c - $ENV{SRC_DIR}/src/3P/netifd/tunnel.c - $ENV{SRC_DIR}/src/3P/netifd/handler.c - $ENV{SRC_DIR}/src/3P/netifd/interface.c - $ENV{SRC_DIR}/src/3P/netifd/interface-ip.c - $ENV{SRC_DIR}/src/3P/netifd/interface-event.c - $ENV{SRC_DIR}/src/3P/netifd/iprule.c - $ENV{SRC_DIR}/src/3P/netifd/proto.c - $ENV{SRC_DIR}/src/3P/netifd/proto-static.c - $ENV{SRC_DIR}/src/3P/netifd/proto-shell.c - $ENV{SRC_DIR}/src/3P/netifd/config.c - $ENV{SRC_DIR}/src/3P/netifd/device.c - $ENV{SRC_DIR}/src/3P/netifd/bridge.c - $ENV{SRC_DIR}/src/3P/netifd/vlan.c - $ENV{SRC_DIR}/src/3P/netifd/alias.c - $ENV{SRC_DIR}/src/3P/netifd/macvlan.c - $ENV{SRC_DIR}/src/3P/netifd/ubus.c - $ENV{SRC_DIR}/src/3P/netifd/vlandev.c - $ENV{SRC_DIR}/src/3P/netifd/wireless.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/main.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/utils.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/system.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/tunnel.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/handler.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/interface.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/interface-ip.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/interface-event.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/iprule.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/proto.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/proto-static.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/proto-shell.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/config.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/device.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/bridge.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/vlan.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/alias.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/macvlan.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/ubus.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/vlandev.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/wireless.c - $ENV{SRC_DIR}/src/3P/netifd/system-linux.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/system-linux.c ) diff --git a/src/3P/netifd/config.c b/src/3P/netifd/config.c index 0d965d33..9c5bf30b 100644 --- a/src/3P/netifd/config.c +++ b/src/3P/netifd/config.c @@ -16,7 +16,7 @@ #include #include -#include +#include #include "netifd.h" #include "interface.h" diff --git a/src/3P/netifd/config.h b/src/3P/netifd/config.h index 5adaca6d..b29e94a5 100644 --- a/src/3P/netifd/config.h +++ b/src/3P/netifd/config.h @@ -15,7 +15,7 @@ #define __NETIFD_CONFIG_H #include -#include +#include extern bool config_init; diff --git a/src/3P/netifd/device.c b/src/3P/netifd/device.c index 43881e5f..3c57a028 100644 --- a/src/3P/netifd/device.c +++ b/src/3P/netifd/device.c @@ -58,7 +58,6 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = { [DEV_ATTR_MULTICAST] = { .name ="multicast", .type = BLOBMSG_TYPE_BOOL }, [DEV_ATTR_LEARNING] = { .name ="learning", .type = BLOBMSG_TYPE_BOOL }, [DEV_ATTR_UNICAST_FLOOD] = { .name ="unicast_flood", .type = BLOBMSG_TYPE_BOOL }, - [DEV_ATTR_SENDREDIRECTS] = { .name = "sendredirects", .type = BLOBMSG_TYPE_BOOL }, }; const struct uci_blob_param_list device_attr_list = { @@ -226,8 +225,6 @@ device_merge_settings(struct device *dev, struct device_settings *n) n->multicast_fast_leave = s->multicast_fast_leave; n->learning = s->learning; n->unicast_flood = s->unicast_flood; - n->sendredirects = s->flags & DEV_OPT_SENDREDIRECTS ? - s->sendredirects : os->sendredirects; n->flags = s->flags | os->flags | os->valid_flags; } @@ -366,11 +363,6 @@ device_init_settings(struct device *dev, struct blob_attr **tb) s->flags |= DEV_OPT_UNICAST_FLOOD; } - if ((cur = tb[DEV_ATTR_SENDREDIRECTS])) { - s->sendredirects = blobmsg_get_bool(cur); - s->flags |= DEV_OPT_SENDREDIRECTS; - } - device_set_disabled(dev, disabled); } @@ -1058,8 +1050,6 @@ device_dump_status(struct blob_buf *b, struct device *dev) blobmsg_add_u8(b, "learning", st.learning); if (st.flags & DEV_OPT_UNICAST_FLOOD) blobmsg_add_u8(b, "unicast_flood", st.unicast_flood); - if (st.flags & DEV_OPT_SENDREDIRECTS) - blobmsg_add_u8(b, "sendredirects", st.sendredirects); } s = blobmsg_open_table(b, "statistics"); diff --git a/src/3P/netifd/device.h b/src/3P/netifd/device.h index 87236d42..2af93bb1 100644 --- a/src/3P/netifd/device.h +++ b/src/3P/netifd/device.h @@ -50,7 +50,6 @@ enum { DEV_ATTR_LEARNING, DEV_ATTR_UNICAST_FLOOD, DEV_ATTR_NEIGHGCSTALETIME, - DEV_ATTR_SENDREDIRECTS, __DEV_ATTR_MAX, }; @@ -102,7 +101,6 @@ enum { DEV_OPT_UNICAST_FLOOD = (1 << 18), DEV_OPT_NEIGHGCSTALETIME = (1 << 19), DEV_OPT_MULTICAST_FAST_LEAVE = (1 << 20), - DEV_OPT_SENDREDIRECTS = (1 << 21), }; /* events broadcasted to all users of a device */ @@ -169,7 +167,6 @@ struct device_settings { bool multicast; bool learning; bool unicast_flood; - bool sendredirects; }; /* diff --git a/src/3P/netifd/interface-ip.c b/src/3P/netifd/interface-ip.c index f8dab840..24ea0549 100644 --- a/src/3P/netifd/interface-ip.c +++ b/src/3P/netifd/interface-ip.c @@ -40,7 +40,6 @@ enum { ROUTE_SOURCE, ROUTE_ONLINK, ROUTE_TYPE, - ROUTE_PROTO, __ROUTE_MAX }; @@ -55,8 +54,7 @@ static const struct blobmsg_policy route_attr[__ROUTE_MAX] = { [ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 }, [ROUTE_SOURCE] = { .name = "source", .type = BLOBMSG_TYPE_STRING }, [ROUTE_ONLINK] = { .name = "onlink", .type = BLOBMSG_TYPE_BOOL }, - [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING }, - [ROUTE_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING }, + [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING } }; const struct uci_blob_param_list route_attr_list = { @@ -407,14 +405,6 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) route->flags |= DEVROUTE_TYPE; } - if ((cur = tb[ROUTE_PROTO]) != NULL) { - if (!system_resolve_rt_proto(blobmsg_data(cur), &route->proto)) { - DPRINTF("Failed to resolve proto type: %s\n", (char *) blobmsg_data(cur)); - goto error; - } - route->flags |= DEVROUTE_PROTO; - } - interface_set_route_info(iface, route); vlist_add(&ip->route, &route->node, route); return; @@ -488,13 +478,10 @@ interface_handle_subnet_route(struct interface *iface, struct device_addr *addr, memcpy(&r->addr, &addr->addr, sizeof(r->addr)); clear_if_addr(&r->addr, r->mask); - if (!system_resolve_rt_proto("kernel", &r->proto)) - return; - - r->flags |= DEVROUTE_PROTO; + r->flags |= DEVADDR_KERNEL; system_del_route(dev, r); - r->flags &= ~DEVROUTE_PROTO; + r->flags &= ~DEVADDR_KERNEL; interface_set_route_info(iface, r); system_add_route(dev, r); @@ -647,7 +634,7 @@ interface_update_proto_route(struct vlist_tree *tree, if (node_old && node_new) keep = !memcmp(&route_old->nexthop, &route_new->nexthop, sizeof(route_old->nexthop)) && (route_old->mtu == route_new->mtu) && (route_old->type == route_new->type) && - (route_old->proto == route_new->proto) && !route_old->failed; + !route_old->failed; if (node_old) { if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep) diff --git a/src/3P/netifd/interface-ip.h b/src/3P/netifd/interface-ip.h index 01727c9b..bbef62ce 100644 --- a/src/3P/netifd/interface-ip.h +++ b/src/3P/netifd/interface-ip.h @@ -31,8 +31,8 @@ enum device_addr_flags { /* route overrides the default interface mtu */ DEVROUTE_MTU = (1 << 4), - /* route overrides the default proto type */ - DEVROUTE_PROTO = (1 << 5), + /* route automatically added by kernel */ + DEVADDR_KERNEL = (1 << 5), /* address is off-link (no subnet-route) */ DEVADDR_OFFLINK = (1 << 6), @@ -92,7 +92,6 @@ struct device_route { union if_addr nexthop; int mtu; unsigned int type; - unsigned int proto; time_t valid_until; /* must be last */ diff --git a/src/3P/netifd/proto.c b/src/3P/netifd/proto.c index fd48354d..23304f35 100644 --- a/src/3P/netifd/proto.c +++ b/src/3P/netifd/proto.c @@ -36,7 +36,6 @@ enum { OPT_GATEWAY, OPT_IP6GW, OPT_IP6PREFIX, - OPT_IP6DEPRECATED, __OPT_MAX, }; @@ -48,7 +47,6 @@ static const struct blobmsg_policy proto_ip_attributes[__OPT_MAX] = { [OPT_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING }, [OPT_IP6GW] = { .name = "ip6gw", .type = BLOBMSG_TYPE_STRING }, [OPT_IP6PREFIX] = { .name = "ip6prefix", .type = BLOBMSG_TYPE_ARRAY }, - [OPT_IP6DEPRECATED] = { .name = "ip6deprecated", .type = BLOBMSG_TYPE_BOOL }, }; static const struct uci_blob_param_info proto_ip_attr_info[__OPT_MAX] = { @@ -115,7 +113,7 @@ alloc_device_addr(bool v6, bool ext) static bool parse_addr(struct interface *iface, const char *str, bool v6, int mask, - bool ext, uint32_t broadcast, bool deprecated) + bool ext, uint32_t broadcast) { struct device_addr *addr; int af = v6 ? AF_INET6 : AF_INET; @@ -138,9 +136,6 @@ parse_addr(struct interface *iface, const char *str, bool v6, int mask, if (broadcast) addr->broadcast = broadcast; - if (deprecated) - addr->preferred_until = system_get_rtime(); - vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags); return true; @@ -153,8 +148,7 @@ error: static int parse_static_address_option(struct interface *iface, struct blob_attr *attr, - bool v6, int netmask, bool ext, uint32_t broadcast, - bool deprecated) + bool v6, int netmask, bool ext, uint32_t broadcast) { struct blob_attr *cur; int n_addr = 0; @@ -166,7 +160,7 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr, n_addr++; if (!parse_addr(iface, blobmsg_data(cur), v6, netmask, ext, - broadcast, deprecated)) + broadcast)) return -1; } @@ -406,7 +400,6 @@ proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr) struct blob_attr *cur; const char *error; unsigned int netmask = 32; - bool ip6deprecated; int n_v4 = 0, n_v6 = 0; struct in_addr bcast = {}; @@ -427,15 +420,13 @@ proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr) } } - ip6deprecated = blobmsg_get_bool_default(tb[OPT_IP6DEPRECATED], false); - if ((cur = tb[OPT_IPADDR])) n_v4 = parse_static_address_option(iface, cur, false, - netmask, false, bcast.s_addr, false); + netmask, false, bcast.s_addr); if ((cur = tb[OPT_IP6ADDR])) n_v6 = parse_static_address_option(iface, cur, true, - 128, false, 0, ip6deprecated); + 128, false, 0); if ((cur = tb[OPT_IP6PREFIX])) if (parse_prefix_list(iface, cur) < 0) diff --git a/src/3P/netifd/system-dummy.c b/src/3P/netifd/system-dummy.c index 2ea25ac5..9c734ea5 100644 --- a/src/3P/netifd/system-dummy.c +++ b/src/3P/netifd/system-dummy.c @@ -202,12 +202,6 @@ bool system_resolve_rt_type(const char *type, unsigned int *id) return true; } -bool system_resolve_rt_proto(const char *type, unsigned int *id) -{ - *id = 0; - return true; -} - bool system_resolve_rt_table(const char *name, unsigned int *id) { *id = 0; diff --git a/src/3P/netifd/system-linux.c b/src/3P/netifd/system-linux.c index fcd1b2e5..67fa2b1b 100644 --- a/src/3P/netifd/system-linux.c +++ b/src/3P/netifd/system-linux.c @@ -52,6 +52,7 @@ #define IFA_FLAGS (IFA_MULTICAST + 1) #endif + #include #include #include @@ -396,11 +397,6 @@ static void system_bridge_set_unicast_flood(struct device *dev, const char *val) system_set_dev_sysctl("/sys/class/net/%s/brport/unicast_flood", dev->ifname, val); } -static void system_set_sendredirects(struct device *dev, const char *val) -{ - system_set_dev_sysctl("/proc/sys/net/ipv4/conf/%s/send_redirects", dev->ifname, val); -} - static int system_get_sysctl(const char *path, char *buf, const size_t buf_sz) { int fd = -1, ret = -1; @@ -489,12 +485,6 @@ static int system_get_dadtransmits(struct device *dev, char *buf, const size_t b dev->ifname, buf, buf_sz); } -static int system_get_sendredirects(struct device *dev, char *buf, const size_t buf_sz) -{ - return system_get_dev_sysctl("/proc/sys/net/ipv4/conf/%s/send_redirects", - dev->ifname, buf, buf_sz); -} - // Evaluate netlink messages static int cb_rtnl_event(struct nl_msg *msg, void *arg) { @@ -1298,11 +1288,6 @@ system_if_get_settings(struct device *dev, struct device_settings *s) s->dadtransmits = strtoul(buf, NULL, 0); s->flags |= DEV_OPT_DADTRANSMITS; } - - if (!system_get_sendredirects(dev, buf, sizeof(buf))) { - s->sendredirects = strtoul(buf, NULL, 0); - s->flags |= DEV_OPT_SENDREDIRECTS; - } } static void @@ -1408,8 +1393,6 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned !s->multicast ? IFF_MULTICAST : 0) < 0) s->flags &= ~DEV_OPT_MULTICAST; } - if (s->flags & DEV_OPT_SENDREDIRECTS & apply_mask) - system_set_sendredirects(dev, s->sendredirects ? "1" : "0"); system_if_apply_rps_xps(dev, s); } @@ -1781,7 +1764,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd) .rtm_dst_len = route->mask, .rtm_src_len = route->sourcemask, .rtm_table = (table < 256) ? table : RT_TABLE_UNSPEC, - .rtm_protocol = (route->flags & DEVROUTE_PROTO) ? route->proto : RTPROT_STATIC, + .rtm_protocol = (route->flags & DEVADDR_KERNEL) ? RTPROT_KERNEL : RTPROT_STATIC, .rtm_scope = RT_SCOPE_NOWHERE, .rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST, .rtm_flags = (route->flags & DEVROUTE_ONLINK) ? RTNH_F_ONLINK : 0, @@ -1899,45 +1882,6 @@ bool system_resolve_rt_type(const char *type, unsigned int *id) return system_rtn_aton(type, id); } -bool system_resolve_rt_proto(const char *type, unsigned int *id) -{ - FILE *f; - char *e, buf[128]; - unsigned int n, proto = 256; - - if ((n = strtoul(type, &e, 0)) >= 0 && !*e && e != type) - proto = n; - else if (!strcmp(type, "unspec")) - proto = RTPROT_UNSPEC; - else if (!strcmp(type, "kernel")) - proto = RTPROT_KERNEL; - else if (!strcmp(type, "boot")) - proto = RTPROT_BOOT; - else if (!strcmp(type, "static")) - proto = RTPROT_STATIC; - else if ((f = fopen("/etc/iproute2/rt_protos", "r")) != NULL) { - while (fgets(buf, sizeof(buf) - 1, f) != NULL) { - if ((e = strtok(buf, " \t\n")) == NULL || *e == '#') - continue; - - n = strtoul(e, NULL, 10); - e = strtok(NULL, " \t\n"); - - if (e && !strcmp(e, type)) { - proto = n; - break; - } - } - fclose(f); - } - - if (proto > 255) - return false; - - *id = proto; - return true; -} - bool system_resolve_rt_table(const char *name, unsigned int *id) { FILE *f; @@ -2183,7 +2127,7 @@ static int system_add_gre_tunnel(const char *name, const char *kind, uint32_t ikey = 0, okey = 0, flags = 0, flowinfo = 0; uint16_t iflags = 0, oflags = 0; uint8_t tos = 0; - int ret = 0, ttl = 0; + int ret = 0, ttl = 64; nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE); if (!nlm) @@ -2211,6 +2155,8 @@ static int system_add_gre_tunnel(const char *name, const char *kind, if ((cur = tb[TUNNEL_ATTR_TTL])) ttl = blobmsg_get_u32(cur); + nla_put_u8(nlm, IFLA_GRE_TTL, ttl); + if ((cur = tb[TUNNEL_ATTR_TOS])) { char *str = blobmsg_get_string(cur); if (strcmp(str, "inherit")) { @@ -2284,9 +2230,6 @@ static int system_add_gre_tunnel(const char *name, const char *kind, if (flags) nla_put_u32(nlm, IFLA_GRE_FLAGS, flags); - - if (!ttl) - ttl = 64; } else { struct in_addr inbuf; bool set_df = true; @@ -2322,23 +2265,17 @@ static int system_add_gre_tunnel(const char *name, const char *kind, if ((cur = tb[TUNNEL_ATTR_DF])) set_df = blobmsg_get_bool(cur); - if (!set_df) { - /* ttl != 0 and nopmtudisc are incompatible */ - if (ttl) { - ret = -EINVAL; - goto failure; - } - } else if (!ttl) - ttl = 64; + /* ttl !=0 and nopmtudisc are incompatible */ + if (ttl && !set_df) { + ret = -EINVAL; + goto failure; + } nla_put_u8(nlm, IFLA_GRE_PMTUDISC, set_df ? 1 : 0); nla_put_u8(nlm, IFLA_GRE_TOS, tos); } - if (ttl) - nla_put_u8(nlm, IFLA_GRE_TTL, ttl); - if (oflags) nla_put_u16(nlm, IFLA_GRE_OFLAGS, oflags); diff --git a/src/3P/netifd/system.h b/src/3P/netifd/system.h index e810ed9e..d5cb4e37 100644 --- a/src/3P/netifd/system.h +++ b/src/3P/netifd/system.h @@ -146,7 +146,6 @@ int system_del_route(struct device *dev, struct device_route *route); int system_flush_routes(void); bool system_resolve_rt_type(const char *type, unsigned int *id); -bool system_resolve_rt_proto(const char *type, unsigned int *id); bool system_resolve_rt_table(const char *name, unsigned int *id); bool system_is_default_rt_table(unsigned int id); bool system_resolve_rpfilter(const char *filter, unsigned int *id); diff --git a/src/3P/netifd/ubus.c b/src/3P/netifd/ubus.c index 0123b17e..29924c11 100644 --- a/src/3P/netifd/ubus.c +++ b/src/3P/netifd/ubus.c @@ -486,9 +486,6 @@ interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled) if (route->flags & DEVROUTE_TYPE) blobmsg_add_u32(&b, "type", route->type); - if (route->flags & DEVROUTE_PROTO) - blobmsg_add_u32(&b, "proto", route->proto); - if (route->flags & DEVROUTE_MTU) blobmsg_add_u32(&b, "mtu", route->mtu); diff --git a/src/3P/netifd/utils.h b/src/3P/netifd/utils.h index 4e14bcf5..12cfda1f 100644 --- a/src/3P/netifd/utils.h +++ b/src/3P/netifd/utils.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/3P/procd/jail/jail.c b/src/3P/procd/jail/jail.c index 9d7483c9..8e7cddc9 100644 --- a/src/3P/procd/jail/jail.c +++ b/src/3P/procd/jail/jail.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "capabilities.h" #include "elf.h" @@ -299,19 +298,12 @@ static void jail_process_timeout_cb(struct uloop_timeout *t) kill(jail_process.pid, SIGKILL); } -static void jail_handle_signal(int signo) -{ - DEBUG("forwarding signal %d to the jailed process\n", signo); - kill(jail_process.pid, signo); -} - int main(int argc, char **argv) { - sigset_t sigmask; uid_t uid = getuid(); char log[] = "/dev/log"; char ubus[] = "/var/run/ubus.sock"; - int ch, i; + int ch; if (uid) { ERROR("not root, aborting: %s\n", strerror(errno)); @@ -405,20 +397,6 @@ int main(int argc, char **argv) prctl(PR_SET_NAME, opts.name, NULL, NULL, NULL); uloop_init(); - - sigfillset(&sigmask); - for (i = 0; i < _NSIG; i++) { - struct sigaction s = { 0 }; - - if (!sigismember(&sigmask, i)) - continue; - if ((i == SIGCHLD) || (i == SIGPIPE)) - continue; - - s.sa_handler = jail_handle_signal; - sigaction(i, &s, NULL); - } - if (opts.namespace) { add_mount("/dev/full", 0, -1); add_mount("/dev/null", 0, -1); diff --git a/src/3P/ubox/builders/cmake/CMakeLists.txt b/src/3P/ubox/builders/cmake/CMakeLists.txt new file mode 100644 index 00000000..9c3c4702 --- /dev/null +++ b/src/3P/ubox/builders/cmake/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required (VERSION 3.0) + +project (ubox) + +ADD_DEFINITIONS(-Os -ggdb -Wall -Werror --std=gnu99 -Wmissing-declarations) + +set (CMAKE_MODULE_PATH "${MODULE_PATH}") + +set(DISABLE_TARGET_OPTIMIZATION ON) + +include (aw) + +# Logd + +add_executable (logd + $ENV{AWOXCVS}/AwoxAudio/Products/External/ubox/log/logd.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/ubox/log/syslog.c) +target_link_libraries (logd ubox ubus) +install (TARGETS logd RUNTIME DESTINATION sbin) + +# Logread + +add_executable (logread + $ENV{AWOXCVS}/AwoxAudio/Products/External/ubox/log/logread.c) +target_link_libraries (logread ubox ubus json-c blobmsg_json) +install (TARGETS logread RUNTIME DESTINATION sbin) + +# kmodloader + +add_executable (kmodloader + $ENV{AWOXCVS}/AwoxAudio/Products/External/ubox/kmodloader.c) +target_link_libraries (kmodloader ubox) +install (TARGETS kmodloader RUNTIME DESTINATION ../sbin) + +# validate_data +add_executable (validate_data + $ENV{AWOXCVS}/AwoxAudio/Products/External/ubox/validate/cli.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/ubox/validate/validate.c) +target_link_libraries (validate_data ubox uci) +install (TARGETS validate_data RUNTIME DESTINATION ../sbin) diff --git a/src/3P/ubox/getrandom.c b/src/3P/ubox/getrandom.c index 73a37b0f..96712028 100644 --- a/src/3P/ubox/getrandom.c +++ b/src/3P/ubox/getrandom.c @@ -21,40 +21,38 @@ #include #define ERROR_EXIT(fmt, ...) do { \ - fprintf(stderr, fmt, ## __VA_ARGS__); \ - return EXIT_FAILURE; \ - } while (0) + fprintf(stderr, fmt, ## __VA_ARGS__); \ + return EXIT_FAILURE; \ + } while (0) static int usage(char *name) { - fprintf(stderr, "Usage: %s \n", name); - fprintf(stderr, " => return bytes from getrandom()\n"); - return EXIT_FAILURE; + fprintf(stderr, "Usage: %s \n", name); + fprintf(stderr, " => return bytes from getrandom()\n"); + return EXIT_FAILURE; } int main(int argc, char *argv[]) { - if (argc != 2) - return usage(argv[0]); + if (argc != 2) + return usage(argv[0]); - if (isatty(STDOUT_FILENO)) - ERROR_EXIT("Not outputting random to a tty\n"); + if (isatty(STDOUT_FILENO)) + ERROR_EXIT("Not outputting random to a tty\n"); - int nbtot = atoi(argv[1]); - if (nbtot < 1) - ERROR_EXIT("Invalid param (must be > 0)\n"); + int nbtot = atoi(argv[1]); + if (nbtot < 1) + ERROR_EXIT("Invalid param (must be > 0)\n"); - char buf[256]; - int len = sizeof(buf); - while (nbtot > 0) { - if (nbtot <= sizeof(buf)) - len = nbtot; - if (syscall(SYS_getrandom, buf, len, 0) == -1) - ERROR_EXIT("getrandom() failed: %s\n", strerror(errno)); - if (write(STDOUT_FILENO, buf, len) != len) - ERROR_EXIT("write() failed: %s\n", strerror(errno)); - nbtot -= sizeof(buf); - } - - return 0; + char buf[256]; + int len = sizeof(buf); + while (nbtot > 0) { + if (nbtot <= sizeof(buf)) + len = nbtot; + if (syscall(SYS_getrandom, buf, len, 0) == -1) + ERROR_EXIT("getrandom() failed: %s\n", strerror(errno)); + if (write(STDOUT_FILENO, buf, len) != len) + ERROR_EXIT("write() failed: %s\n", strerror(errno)); + nbtot -= sizeof(buf); + } } diff --git a/src/3P/ubox/kmodloader.c b/src/3P/ubox/kmodloader.c index 5ba75c1a..e32e6aff 100644 --- a/src/3P/ubox/kmodloader.c +++ b/src/3P/ubox/kmodloader.c @@ -609,10 +609,7 @@ static int main_insmod(int argc, char **argv) cur += sprintf(cur, "%s", argv[i]); } - if (init_module_folders()) { - fprintf(stderr, "falied to find the folder holding the modules\n"); - return -1; - } + init_module_folders(); if (get_module_path(argv[1])) { name = argv[1]; diff --git a/src/3P/ubox/log/logd.c b/src/3P/ubox/log/logd.c index d778909e..27d3cac8 100644 --- a/src/3P/ubox/log/logd.c +++ b/src/3P/ubox/log/logd.c @@ -31,16 +31,8 @@ static struct blob_buf b; static struct ubus_auto_conn conn; static LIST_HEAD(clients); -enum { - READ_LINES, - READ_STREAM, - __READ_MAX -}; - -static const struct blobmsg_policy read_policy[__READ_MAX] = { - [READ_LINES] = { .name = "lines", .type = BLOBMSG_TYPE_INT32 }, - [READ_STREAM] = { .name = "stream", .type = BLOBMSG_TYPE_BOOL }, -}; +static const struct blobmsg_policy read_policy = + { .name = "lines", .type = BLOBMSG_TYPE_INT32 }; static const struct blobmsg_policy write_policy = { .name = "event", .type = BLOBMSG_TYPE_STRING }; @@ -68,75 +60,48 @@ static void client_notify_state(struct ustream *s) client_close(s); } -static void -log_fill_msg(struct blob_buf *b, struct log_head *l) -{ - blobmsg_add_string(b, "msg", l->data); - blobmsg_add_u32(b, "id", l->id); - blobmsg_add_u32(b, "priority", l->priority); - blobmsg_add_u32(b, "source", l->source); - blobmsg_add_u64(b, "time", l->ts.tv_sec * 1000LL); -} - static int read_log(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct client *cl; - struct blob_attr *tb[__READ_MAX]; + struct blob_attr *tb; struct log_head *l; int count = 0; int fds[2]; int ret; - bool stream = true; - void *c, *e; - - if (!stream) - count = 100; if (msg) { - blobmsg_parse(read_policy, __READ_MAX, tb, blob_data(msg), blob_len(msg)); - if (tb[READ_LINES]) - count = blobmsg_get_u32(tb[READ_LINES]); - if (tb[READ_STREAM]) - stream = blobmsg_get_bool(tb[READ_STREAM]); + blobmsg_parse(&read_policy, 1, &tb, blob_data(msg), blob_len(msg)); + if (tb) + count = blobmsg_get_u32(tb); } if (pipe(fds) == -1) { fprintf(stderr, "logd: failed to create pipe: %s\n", strerror(errno)); return -1; } - + ubus_request_set_fd(ctx, req, fds[0]); + cl = calloc(1, sizeof(*cl)); + cl->s.stream.notify_state = client_notify_state; + cl->fd = fds[1]; + ustream_fd_init(&cl->s, cl->fd); + list_add(&cl->list, &clients); l = log_list(count, NULL); - if (stream) { - ubus_request_set_fd(ctx, req, fds[0]); - cl = calloc(1, sizeof(*cl)); - cl->s.stream.notify_state = client_notify_state; - cl->fd = fds[1]; - ustream_fd_init(&cl->s, cl->fd); - list_add(&cl->list, &clients); - while ((!tb[READ_LINES] || count) && l) { - blob_buf_init(&b, 0); - log_fill_msg(&b, l); - l = log_list(count, l); - ret = ustream_write(&cl->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false); - if (ret < 0) - break; - } - } else { + while ((!tb || count) && l) { blob_buf_init(&b, 0); - c = blobmsg_open_array(&b, "log"); - while ((!tb[READ_LINES] || count) && l) { - e = blobmsg_open_table(&b, NULL); - log_fill_msg(&b, l); - blobmsg_close_table(&b, e); - l = log_list(count, l); - } - blobmsg_close_array(&b, c); - ubus_send_reply(ctx, req, b.head); + blobmsg_add_string(&b, "msg", l->data); + blobmsg_add_u32(&b, "id", l->id); + blobmsg_add_u32(&b, "priority", l->priority); + blobmsg_add_u32(&b, "source", l->source); + blobmsg_add_u64(&b, "time", l->ts.tv_sec * 1000LL); + l = log_list(count, l); + ret = ustream_write(&cl->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false); + blob_buf_free(&b); + if (ret < 0) + break; } - blob_buf_free(&b); return 0; } @@ -160,7 +125,7 @@ write_log(struct ubus_context *ctx, struct ubus_object *obj, } static const struct ubus_method log_methods[] = { - UBUS_METHOD("read", read_log, read_policy), + { .name = "read", .handler = read_log, .policy = &read_policy, .n_policy = 1 }, { .name = "write", .handler = write_log, .policy = &write_policy, .n_policy = 1 }, }; @@ -232,7 +197,6 @@ main(int argc, char **argv) uloop_run(); log_shutdown(); uloop_done(); - ubus_auto_shutdown(&conn); return 0; } diff --git a/src/3P/ubox/log/logread.c b/src/3P/ubox/log/logread.c index 676bb82b..4c042eb9 100644 --- a/src/3P/ubox/log/logread.c +++ b/src/3P/ubox/log/logread.c @@ -30,7 +30,7 @@ #include #include #include -#include "libubus.h" +#include #include "syslog.h" enum { @@ -313,7 +313,6 @@ int main(int argc, char **argv) } blob_buf_init(&b, 0); - blobmsg_add_u8(&b, "stream", 1); if (lines) blobmsg_add_u32(&b, "lines", lines); else if (log_follow) diff --git a/src/3P/ubox/log/syslog.c b/src/3P/ubox/log/syslog.c index ac4f1ae9..b7e1e46e 100644 --- a/src/3P/ubox/log/syslog.c +++ b/src/3P/ubox/log/syslog.c @@ -11,6 +11,12 @@ * GNU General Public License for more details. */ +#include + +#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,21) +typedef unsigned short sa_family_t; +#endif + #include #include @@ -300,6 +306,4 @@ log_shutdown(void) close(slog.fd.fd); close(klog.fd.fd); free(log); - regfree(&pat_prio); - regfree(&pat_tstamp); } diff --git a/src/3P/ubox/validate/cli.c b/src/3P/ubox/validate/cli.c index f03c8a16..ba4601de 100644 --- a/src/3P/ubox/validate/cli.c +++ b/src/3P/ubox/validate/cli.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include "libvalidate.h" @@ -109,28 +109,39 @@ static int validate_value(struct uci_ptr *ptr, const char *expr, const char *def) { int i = 0; - bool empty = true; + bool empty = true, first = true; enum dt_type type = DT_INVALID; struct uci_element *e; - struct uci_option *opt = NULL; + struct uci_option *opt = ptr->o; - if ((ptr->flags & UCI_LOOKUP_COMPLETE) && - (ptr->last->type == UCI_TYPE_OPTION)) - opt = ptr->o; - - if (opt && opt->type == UCI_TYPE_LIST) + if (opt->type == UCI_TYPE_LIST) { uci_foreach_element(&opt->v.list, e) { if (!e->name || !*e->name) continue; - if (empty) + empty = false; + break; + } + + if (empty) + { + export_value(DT_STRING, ptr->option, def); + return 0; + } + + uci_foreach_element(&opt->v.list, e) + { + if (!e->name || !*e->name) + continue; + + if (first) printf("%s=", ptr->option); else printf("\\ "); - empty = false; + first = false; type = dt_parse(expr, e->name); if (type != DT_INVALID) @@ -141,12 +152,16 @@ validate_value(struct uci_ptr *ptr, const char *expr, const char *def) expr, type ? "true" : "false"); } - if (!empty) - printf("; "); + printf("; "); } - else if (opt && opt->v.string && *opt->v.string) + else { - empty = false; + if (!opt->v.string || !*opt->v.string) + { + export_value(DT_STRING, ptr->option, def); + return 0; + } + type = dt_parse(expr, opt->v.string); export_value(type, ptr->option, opt->v.string); @@ -154,20 +169,6 @@ validate_value(struct uci_ptr *ptr, const char *expr, const char *def) ptr->package, ptr->section, ptr->option, opt->v.string, expr, type ? "true" : "false"); } - - if (empty) - { - type = dt_parse(expr, def); - - if (type == DT_INVALID) - type = DT_STRING; - - export_value(type, ptr->option, def); - - fprintf(stderr, "%s.%s.%s is unset and defaults to %s %s\n", - ptr->package, ptr->section, ptr->option, expr, def); - } - return type ? 0 : -1; } @@ -187,7 +188,13 @@ validate_option(struct uci_context *ctx, char *package, char *section, char *opt ptr.section = section; ptr.option = opt; - uci_lookup_ptr(ctx, &ptr, NULL, false); + if (uci_lookup_ptr(ctx, &ptr, NULL, false) || + !(ptr.flags & UCI_LOOKUP_COMPLETE) || + (ptr.last->type != UCI_TYPE_OPTION)) + { + export_value(DT_STRING, opt, def); + return 0; + } return validate_value(&ptr, expr, def); } diff --git a/src/3P/ubox/validate/validate.c b/src/3P/ubox/validate/validate.c index 5bc3bc4e..62c7de33 100644 --- a/src/3P/ubox/validate/validate.c +++ b/src/3P/ubox/validate/validate.c @@ -24,7 +24,7 @@ #include #include -#include +#include #include "libvalidate.h" diff --git a/src/3P/ubus/.gitignore b/src/3P/ubus/.gitignore index 551b024f..8a09daf7 100644 --- a/src/3P/ubus/.gitignore +++ b/src/3P/ubus/.gitignore @@ -7,6 +7,4 @@ CMakeFiles *.dylib examples/server examples/client -ubusd -ubus install_manifest.txt diff --git a/src/3P/ubus/CMakeLists.original.txt b/src/3P/ubus/CMakeLists.original.txt new file mode 100644 index 00000000..7123096a --- /dev/null +++ b/src/3P/ubus/CMakeLists.original.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 2.6) + +PROJECT(ubus C) +ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations) + +OPTION(BUILD_LUA "build Lua plugin" ON) +OPTION(BUILD_EXAMPLES "build examples" ON) + +SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock") +SET(UBUS_MAX_MSGLEN 1048576) + +ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}") +ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN}) + +IF(APPLE) + INCLUDE_DIRECTORIES(/opt/local/include) + LINK_DIRECTORIES(/opt/local/lib) +ENDIF() + +IF(BUILD_STATIC) + FIND_LIBRARY(ubox_library NAMES ubox.a) + FIND_LIBRARY(blob_library NAMES blobmsg_json.a) +ELSE(BUILD_STATIC) + FIND_LIBRARY(ubox_library NAMES ubox) + FIND_LIBRARY(blob_library NAMES blobmsg_json) +ENDIF(BUILD_STATIC) + +FIND_PATH(ubox_include_dir libubox/usock.h) +INCLUDE_DIRECTORIES(${ubox_include_dir}) + +ADD_LIBRARY(ubus SHARED libubus.c libubus-io.c libubus-obj.c libubus-sub.c libubus-req.c libubus-acl.c) +TARGET_LINK_LIBRARIES(ubus ${ubox_library}) + +find_library(json NAMES json-c json) + +ADD_EXECUTABLE(ubusd ubusd.c ubusd_id.c ubusd_obj.c ubusd_proto.c ubusd_event.c ubusd_acl.c ubusd_monitor.c) +TARGET_LINK_LIBRARIES(ubusd ${ubox_library} ${blob_library} ${json}) + +ADD_EXECUTABLE(cli cli.c) +SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME ubus) +TARGET_LINK_LIBRARIES(cli ubus ${ubox_library} ${blob_library} ${json}) + +ADD_SUBDIRECTORY(lua) +ADD_SUBDIRECTORY(examples) + +INSTALL(TARGETS ubus cli + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) +INSTALL(TARGETS ubusd + RUNTIME DESTINATION sbin +) + +INSTALL(FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include) diff --git a/src/3P/ubus/CMakeLists.txt b/src/3P/ubus/CMakeLists.txt index 471b38e3..7c313a6e 100644 --- a/src/3P/ubus/CMakeLists.txt +++ b/src/3P/ubus/CMakeLists.txt @@ -1,50 +1,64 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.0) -PROJECT(ubus C) -ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations) +project (ubus) -OPTION(BUILD_LUA "build Lua plugin" ON) -OPTION(BUILD_EXAMPLES "build examples" ON) +set (CMAKE_MODULE_PATH "${MODULE_PATH}") -SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") -SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock") -SET(UBUS_MAX_MSGLEN 1048576) +set(DISABLE_TARGET_OPTIMIZATION ON) -ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}") -ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN}) +include_directories ($ENV{SRC_DIR}/src/3P/ubus) -IF(BUILD_STATIC) - FIND_LIBRARY(ubox_library NAMES ubox.a) - FIND_LIBRARY(blob_library NAMES blobmsg_json.a) -ELSE(BUILD_STATIC) - FIND_LIBRARY(ubox_library NAMES ubox) - FIND_LIBRARY(blob_library NAMES blobmsg_json) -ENDIF(BUILD_STATIC) +ADD_DEFINITIONS (-Wall -Werror --std=gnu99 -Wmissing-declarations) -FIND_PATH(ubox_include_dir libubox/usock.h) -INCLUDE_DIRECTORIES(${ubox_include_dir}) +ADD_DEFINITIONS (-DUBUS_MAX_MSGLEN=1048576) +ADD_DEFINITIONS (-DUBUS_UNIX_SOCKET="/tmp/ubus.sock") -ADD_LIBRARY(ubus SHARED libubus.c libubus-io.c libubus-obj.c libubus-sub.c libubus-req.c libubus-acl.c) -TARGET_LINK_LIBRARIES(ubus ${ubox_library}) +# ubus library +file ( + GLOB_RECURSE + source_files + + libubus.c + libubus-io.c + libubus-obj.c + libubus-sub.c + libubus-req.c + libubus-acl.c + ) -find_library(json NAMES json-c json) +# Library +add_library (ubus SHARED ${source_files}) +target_link_libraries (ubus LINK_PUBLIC ubox) -ADD_EXECUTABLE(ubusd ubusd.c ubusd_id.c ubusd_obj.c ubusd_proto.c ubusd_event.c ubusd_acl.c ubusd_monitor.c) -TARGET_LINK_LIBRARIES(ubusd ${ubox_library} ${blob_library} ${json}) +target_include_directories (ubus PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -ADD_EXECUTABLE(cli cli.c) -SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME ubus) -TARGET_LINK_LIBRARIES(cli ubus ${ubox_library} ${blob_library} ${json}) +install (TARGETS ubus LIBRARY DESTINATION lib) -ADD_SUBDIRECTORY(lua) -ADD_SUBDIRECTORY(examples) +install (FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include) -INSTALL(TARGETS ubus cli - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin -) -INSTALL(TARGETS ubusd - RUNTIME DESTINATION sbin -) +# Daemon ubusd +file ( + GLOB_RECURSE + ubusd_source_files + + ubusd.c + ubusd_id.c + ubusd_obj.c + ubusd_proto.c + ubusd_event.c + ubusd_acl.c + ubusd_monitor.c + ) -INSTALL(FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include) +# Daemon ubusd +add_executable (ubusd ${ubusd_source_files}) +target_link_libraries (ubusd ubox blobmsg_json) + +install (TARGETS ubusd RUNTIME DESTINATION ../sbin) + +# cmd line tool. +add_executable (ucli cli.c) +set_target_properties (ucli PROPERTIES OUTPUT_NAME ubus) +target_link_libraries (ucli LINK_PUBLIC ubox ubus blobmsg_json) + +install (TARGETS ucli RUNTIME DESTINATION bin) diff --git a/src/3P/ubus/cli.c b/src/3P/ubus/cli.c index 080f9531..c5cbfc3b 100644 --- a/src/3P/ubus/cli.c +++ b/src/3P/ubus/cli.c @@ -293,13 +293,6 @@ static int ubus_cli_wait_for(struct ubus_context *ctx, int argc, char **argv) uloop_init(); ubus_add_uloop(ctx); - ret = ubus_register_event_handler(ctx, &data.ev, "ubus.object.add"); - if (ret) - return ret; - - if (!data.n_pending) - return ret; - ret = ubus_lookup(ctx, NULL, wait_list_cb, &data); if (ret) return ret; @@ -307,6 +300,10 @@ static int ubus_cli_wait_for(struct ubus_context *ctx, int argc, char **argv) if (!data.n_pending) return ret; + ret = ubus_register_event_handler(ctx, &data.ev, "ubus.object.add"); + if (ret) + return ret; + uloop_timeout_set(&data.timeout, timeout * 1000); uloop_run(); uloop_done(); diff --git a/src/3P/ubus/libubus-internal.h b/src/3P/ubus/libubus-internal.h index c4067d34..f62edc38 100644 --- a/src/3P/ubus/libubus-internal.h +++ b/src/3P/ubus/libubus-internal.h @@ -24,9 +24,7 @@ int ubus_send_msg(struct ubus_context *ctx, uint32_t seq, void ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd); int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, struct blob_attr *msg, int cmd, uint32_t peer); -int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, - struct blob_attr *msg, int cmd, uint32_t peer); -void ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd); +void ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf); void ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd); void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout); diff --git a/src/3P/ubus/libubus-obj.c b/src/3P/ubus/libubus-obj.c index a9972c58..990d04bd 100644 --- a/src/3P/ubus/libubus-obj.c +++ b/src/3P/ubus/libubus-obj.c @@ -11,13 +11,12 @@ * GNU General Public License for more details. */ -#include #include "libubus.h" #include "libubus-internal.h" static void ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr, - struct ubus_object *obj, struct blob_attr **attrbuf, int fd) + struct ubus_object *obj, struct blob_attr **attrbuf) { struct ubus_subscriber *s; @@ -30,13 +29,11 @@ ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr, s = container_of(obj, struct ubus_subscriber, obj); if (s->remove_cb) s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET])); - - close(fd); } static void ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr, - struct ubus_object *obj, struct blob_attr **attrbuf, int fd) + struct ubus_object *obj, struct blob_attr **attrbuf) { if (!obj || !attrbuf[UBUS_ATTR_ACTIVE]) return; @@ -44,18 +41,14 @@ ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr, obj->has_subscribers = blob_get_u8(attrbuf[UBUS_ATTR_ACTIVE]); if (obj->subscribe_cb) obj->subscribe_cb(ctx, obj); - - close(fd); } static void ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr, - struct ubus_object *obj, struct blob_attr **attrbuf, int fd) + struct ubus_object *obj, struct blob_attr **attrbuf) { struct ubus_request_data req = { .fd = -1, - .req_fd = fd, }; - int method; int ret; bool no_reply = false; @@ -72,7 +65,7 @@ ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr, if (attrbuf[UBUS_ATTR_NO_REPLY]) no_reply = blob_get_int8(attrbuf[UBUS_ATTR_NO_REPLY]); - + req.peer = hdr->peer; req.seq = hdr->seq; req.object = obj->id; @@ -95,7 +88,6 @@ found: ret = obj->methods[method].handler(ctx, obj, &req, blob_data(attrbuf[UBUS_ATTR_METHOD]), attrbuf[UBUS_ATTR_DATA]); - close(req.req_fd); if (req.deferred || no_reply) return; @@ -103,16 +95,16 @@ send: ubus_complete_deferred_request(ctx, &req, ret); } - -void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd) +void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf) { void (*cb)(struct ubus_context *, struct ubus_msghdr *, - struct ubus_object *, struct blob_attr **, int fd); + struct ubus_object *, struct blob_attr **); struct ubus_msghdr *hdr = &buf->hdr; struct blob_attr **attrbuf; struct ubus_object *obj; uint32_t objid; void *prev_data = NULL; + attrbuf = ubus_parse_msg(buf->data); if (!attrbuf[UBUS_ATTR_OBJID]) return; @@ -139,7 +131,7 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_ buf->data = NULL; } - cb(ctx, hdr, obj, attrbuf, fd); + cb(ctx, hdr, obj, attrbuf); if (prev_data) { if (buf->data) diff --git a/src/3P/ubus/libubus-req.c b/src/3P/ubus/libubus-req.c index db5061ca..416adaba 100644 --- a/src/3P/ubus/libubus-req.c +++ b/src/3P/ubus/libubus-req.c @@ -49,9 +49,10 @@ static void __ubus_process_req_data(struct ubus_request *req) } } -int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, +int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, struct blob_attr *msg, int cmd, uint32_t peer) { + memset(req, 0, sizeof(*req)); if (msg && blob_pad_len(msg) > UBUS_MAX_MSGLEN) return -1; @@ -61,21 +62,9 @@ int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request req->ctx = ctx; req->peer = peer; req->seq = ++ctx->request_seq; - - return ubus_send_msg(ctx, req->seq, msg, cmd, peer, req->fd); + return ubus_send_msg(ctx, req->seq, msg, cmd, peer, -1); } -int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, - struct blob_attr *msg, int cmd, uint32_t peer) -{ - memset(req, 0, sizeof(*req)); - - req->fd = -1; - - return __ubus_start_request(ctx, req, msg, cmd, peer); -} - - void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req) { if (list_empty(&req->list)) @@ -140,9 +129,15 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, int req_timeout) { ubus_complete_handler_t complete_cb = req->complete_cb; + bool registered = ctx->sock.registered; int status = UBUS_STATUS_NO_DATA; int64_t timeout = 0, time_end = 0; + if (!registered) { + uloop_init(); + ubus_add_uloop(ctx); + } + if (req_timeout) time_end = get_time_msec() + req_timeout; @@ -181,8 +176,12 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, if (req->complete_cb) req->complete_cb(req, status); - if (!ctx->stack_depth && !ctx->sock.registered) - ctx->pending_timer.cb(&ctx->pending_timer); + if (!registered) { + uloop_fd_delete(&ctx->sock); + + if (!ctx->stack_depth) + ctx->pending_timer.cb(&ctx->pending_timer); + } return status; } @@ -210,9 +209,8 @@ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, return 0; } -int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, - const char *method, struct blob_attr *msg, - struct ubus_request *req, int fd) +int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, struct ubus_request *req) { blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj); @@ -220,21 +218,20 @@ int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, if (msg) blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); - memset(req, 0, sizeof(*req)); - req->fd = fd; - if (__ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0) + if (ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0) return UBUS_STATUS_INVALID_ARGUMENT; + return 0; } -int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, ubus_data_handler_t cb, void *priv, - int timeout, int fd) +int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, ubus_data_handler_t cb, void *priv, + int timeout) { struct ubus_request req; int rc; - rc = ubus_invoke_async_fd(ctx, obj, method, msg, &req, fd); + rc = ubus_invoke_async(ctx, obj, method, msg, &req); if (rc) return rc; diff --git a/src/3P/ubus/libubus.c b/src/3P/ubus/libubus.c index 94635224..076c5507 100644 --- a/src/3P/ubus/libubus.c +++ b/src/3P/ubus/libubus.c @@ -103,7 +103,7 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd) break; } - ubus_process_obj_msg(ctx, buf, fd); + ubus_process_obj_msg(ctx, buf); break; case UBUS_MSG_MONITOR: if (ctx->monitor_cb) @@ -196,7 +196,8 @@ int ubus_lookup_id(struct ubus_context *ctx, const char *path, uint32_t *id) req.raw_data_cb = ubus_lookup_id_cb; req.priv = id; - return ubus_complete_request(ctx, &req, 0); + // Awox Remomve infinite timeout: return ubus_complete_request(ctx, &req, 0); + return ubus_complete_request(ctx, &req, 5000); } static int ubus_event_cb(struct ubus_context *ctx, struct ubus_object *obj, @@ -277,7 +278,6 @@ static void ubus_default_connection_lost(struct ubus_context *ctx) int ubus_connect_ctx(struct ubus_context *ctx, const char *path) { - uloop_init(); memset(ctx, 0, sizeof(*ctx)); ctx->sock.fd = -1; @@ -363,7 +363,6 @@ void ubus_shutdown(struct ubus_context *ctx) if (!ctx) return; close(ctx->sock.fd); - uloop_timeout_cancel(&ctx->pending_timer); free(ctx->msgbuf.data); } diff --git a/src/3P/ubus/libubus.h b/src/3P/ubus/libubus.h index ea532720..8b0be968 100644 --- a/src/3P/ubus/libubus.h +++ b/src/3P/ubus/libubus.h @@ -143,6 +143,7 @@ struct ubus_event_handler { struct ubus_object obj; ubus_event_handler_t cb; + void *priv; // Awox Addon }; struct ubus_context { @@ -188,7 +189,6 @@ struct ubus_request_data { /* internal use */ bool deferred; int fd; - int req_fd; /* fd received from the initial request */ }; struct ubus_request { @@ -209,8 +209,6 @@ struct ubus_request { ubus_fd_handler_t fd_cb; ubus_complete_handler_t complete_cb; - int fd; - struct ubus_context *ctx; void *priv; }; @@ -331,26 +329,13 @@ int ubus_register_acl(struct ubus_context *ctx); /* ----------- rpc ----------- */ /* invoke a method on a specific object */ -int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method, +int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, ubus_data_handler_t cb, void *priv, - int timeout, int fd); -static inline int -ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, ubus_data_handler_t cb, void *priv, - int timeout) -{ - return ubus_invoke_fd(ctx, obj, method, msg, cb, priv, timeout, -1); -} + int timeout); /* asynchronous version of ubus_invoke() */ -int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, struct ubus_request *req, int fd); -static inline int -ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, - struct blob_attr *msg, struct ubus_request *req) -{ - return ubus_invoke_async_fd(ctx, obj, method, msg, req, -1); -} +int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, + struct blob_attr *msg, struct ubus_request *req); /* send a reply to an incoming object method call */ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, @@ -372,14 +357,6 @@ static inline void ubus_request_set_fd(struct ubus_context *ctx, req->fd = fd; } -static inline int ubus_request_get_caller_fd(struct ubus_request_data *req) -{ - int fd = req->req_fd; - req->req_fd = -1; - - return fd; -} - void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_request_data *req, int ret); diff --git a/src/3P/ubus/lua/publisher.lua b/src/3P/ubus/lua/publisher.lua old mode 100755 new mode 100644 diff --git a/src/3P/ubus/lua/subscriber.lua b/src/3P/ubus/lua/subscriber.lua old mode 100755 new mode 100644 diff --git a/src/3P/ubus/lua/test.lua b/src/3P/ubus/lua/test.lua index 277956a9..d24ac6e4 100755 --- a/src/3P/ubus/lua/test.lua +++ b/src/3P/ubus/lua/test.lua @@ -34,18 +34,6 @@ local my_method = { conn:reply(req, {message="foo2"}); print("Call to function 'hello1'") end, {id = ubus.INT32, msg = ubus.STRING } - }, - deferred = { - function(req) - conn:reply(req, {message="wait for it"}) - local def_req = conn:defer_request(req) - uloop.timer(function() - conn:reply(def_req, {message="done"}) - conn:complete_deferred_request(def_req, 0) - print("Deferred request complete") - end, 2000) - print("Call to function 'deferred'") - end, {} } } } diff --git a/src/3P/ubus/lua/ubus.c b/src/3P/ubus/lua/ubus.c index 74a15b05..f59af90c 100644 --- a/src/3P/ubus/lua/ubus.c +++ b/src/3P/ubus/lua/ubus.c @@ -352,26 +352,6 @@ static int ubus_lua_reply(lua_State *L) return 0; } -static int ubus_lua_defer_request(lua_State *L) -{ - struct ubus_lua_connection *c = luaL_checkudata(L, 1, METANAME); - struct ubus_request_data *req = lua_touserdata(L, 2); - struct ubus_request_data *new_req = lua_newuserdata(L, sizeof(struct ubus_request_data)); - ubus_defer_request(c->ctx, req, new_req); - - return 1; -} - -static int ubus_lua_complete_deferred_request(lua_State *L) -{ - struct ubus_lua_connection *c = luaL_checkudata(L, 1, METANAME); - struct ubus_request_data *req = lua_touserdata(L, 2); - int ret = luaL_checkinteger(L, 3); - ubus_complete_deferred_request(c->ctx, req, ret); - - return 0; -} - static int ubus_lua_load_methods(lua_State *L, struct ubus_method *m) { struct blobmsg_policy *p; @@ -940,8 +920,6 @@ static const luaL_Reg ubus[] = { { "add", ubus_lua_add }, { "notify", ubus_lua_notify }, { "reply", ubus_lua_reply }, - { "defer_request", ubus_lua_defer_request }, - { "complete_deferred_request", ubus_lua_complete_deferred_request }, { "signatures", ubus_lua_signatures }, { "call", ubus_lua_call }, { "close", ubus_lua__gc }, diff --git a/src/3P/ubus/ubusd.c b/src/3P/ubus/ubusd.c index 5409b7f6..7279a706 100644 --- a/src/3P/ubus/ubusd.c +++ b/src/3P/ubus/ubusd.c @@ -148,13 +148,12 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free) if (!cl->tx_queue[cl->txq_cur]) { written = ubus_msg_writev(cl->sock.fd, ub, 0); + if (written >= ub->len + sizeof(ub->hdr)) + goto out; if (written < 0) written = 0; - if (written >= ub->len + sizeof(ub->hdr)) - goto out; - cl->txq_ofs = written; /* get an event once we can write to the socket again */ diff --git a/src/3P/ubus/ubusd_acl.c b/src/3P/ubus/ubusd_acl.c index 4b72663d..85ada5dc 100644 --- a/src/3P/ubus/ubusd_acl.c +++ b/src/3P/ubus/ubusd_acl.c @@ -101,7 +101,7 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, struct blob_attr *cur; int rem; - if (!cl->uid || !obj) + if (!cl->uid) return 0; acl = avl_find_ge_element(&ubusd_acls, obj, acl, avl); @@ -434,7 +434,7 @@ ubusd_reply_add(struct ubus_object *obj) if (!acl->priv) continue; - if (ubusd_acl_match_path(obj->path.key, acl->avl.key, NULL)) + if (!ubusd_acl_match_path(obj->path.key, acl->avl.key, NULL)) continue; c = blobmsg_open_table(&b, NULL); diff --git a/src/3P/ubus/ubusd_proto.c b/src/3P/ubus/ubusd_proto.c index 72da7a73..0af11f27 100644 --- a/src/3P/ubus/ubusd_proto.c +++ b/src/3P/ubus/ubusd_proto.c @@ -80,15 +80,11 @@ void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub, uint8_t type) { - /* keep the fd to be passed if it is UBUS_MSG_INVOKE */ - int fd = ub->fd; ub = ubus_reply_from_blob(ub, true); if (!ub) return; ub->hdr.type = type; - ub->fd = fd; - ubus_msg_send(cl, ub, true); } @@ -134,8 +130,8 @@ static int ubusd_handle_remove_object(struct ubus_client *cl, struct ubus_msg_bu if (obj->type && obj->type->refcount == 1) blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id); - ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); ubusd_free_object(obj); + ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); return 0; } @@ -150,7 +146,7 @@ static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf * blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id); - if (attr[UBUS_ATTR_SIGNATURE] && obj->type) + if (attr[UBUS_ATTR_SIGNATURE]) blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id); ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); @@ -160,12 +156,9 @@ static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf * static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj) { struct ubus_method *m; - int all_cnt = 0, cnt = 0; + int cnt = 0; void *s; - if (!obj->type) - return; - blob_buf_init(&b, 0); blob_put_string(&b, UBUS_ATTR_OBJPATH, obj->path.key); @@ -174,7 +167,6 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE); list_for_each_entry(m, &obj->type->methods, list) { - all_cnt++; if (!ubusd_acl_check(cl, obj->path.key, blobmsg_name(m->data), UBUS_ACL_ACCESS)) { blobmsg_add_blob(&b, m->data); cnt++; @@ -182,7 +174,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru } blob_nest_end(&b, s); - if (cnt || !all_cnt) + if (cnt) ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); } @@ -382,7 +374,7 @@ static int ubusd_handle_add_watch(struct ubus_client *cl, struct ubus_msg_buf *u return UBUS_STATUS_INVALID_ARGUMENT; target = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_TARGET])); - if (!target || !target->client) + if (!target) return UBUS_STATUS_NOT_FOUND; if (cl == target->client) @@ -451,7 +443,7 @@ void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub if (ub->hdr.type < __UBUS_MSG_LAST) cb = handlers[ub->hdr.type]; - if (ub->hdr.type != UBUS_MSG_STATUS && ub->hdr.type != UBUS_MSG_INVOKE) + if (ub->hdr.type != UBUS_MSG_STATUS) ubus_msg_close_fd(ub); if (cb) diff --git a/src/3P/ubus/ubusmsg.h b/src/3P/ubus/ubusmsg.h index 398b126b..b95c4725 100644 --- a/src/3P/ubus/ubusmsg.h +++ b/src/3P/ubus/ubusmsg.h @@ -19,7 +19,8 @@ #define __packetdata __attribute__((packed)) __attribute__((__aligned__(4))) -#define UBUS_MSG_CHUNK_SIZE 65536 +//AWOX REDUCE SIZE. #define UBUS_MSG_CHUNK_SIZE 65536 +#define UBUS_MSG_CHUNK_SIZE 16384 #define UBUS_SYSTEM_OBJECT_EVENT 1 #define UBUS_SYSTEM_OBJECT_ACL 2 diff --git a/src/3P/uci/builders/cmake/CMakeLists.txt b/src/3P/uci/builders/cmake/CMakeLists.txt new file mode 100644 index 00000000..bfa8eff1 --- /dev/null +++ b/src/3P/uci/builders/cmake/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.0) + +project (uci) + +set (CMAKE_MODULE_PATH "${MODULE_PATH}") + +set(DISABLE_TARGET_OPTIMIZATION ON) + +include (aw) + +include_directories ($ENV{AWOXCVS}/AwoxAudio/Products/External/uci) + +ADD_DEFINITIONS (-Werror --std=gnu99 -Wmissing-declarations) + +CONFIGURE_FILE ($ENV{AWOXCVS}/AwoxAudio/Products/External/uci/uci_config.h.in $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/uci_config.h ) + +# uci library +file ( + GLOB_RECURSE + lib_source_files + + $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/libuci.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/file.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/util.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/delta.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/parse.c + $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/blob.c +) + +# Library +add_library (uci SHARED ${lib_source_files}) +target_link_libraries (uci LINK_PUBLIC ubox) + +target_include_directories (uci PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +install (TARGETS uci LIBRARY DESTINATION local/lib) + +file (GLOB uci_headers $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/*.h) +install (FILES ${uci_headers} DESTINATION include/uci) + + +# cmd line tool. +add_executable (uci_cli $ENV{AWOXCVS}/AwoxAudio/Products/External/uci/cli.c) +set_target_properties (uci_cli PROPERTIES OUTPUT_NAME uci) +target_link_libraries (uci_cli LINK_PUBLIC uci ubox blobmsg_json) + +install (TARGETS uci_cli RUNTIME DESTINATION ../sbin) \ No newline at end of file diff --git a/src/3P/uci/uci.h b/src/3P/uci/uci.h index c5583ed0..0c098bd6 100644 --- a/src/3P/uci/uci.h +++ b/src/3P/uci/uci.h @@ -36,7 +36,7 @@ extern "C" { #include #define UCI_CONFDIR "/etc/config" -#define UCI_SAVEDIR "/tmp/.uci" +#define UCI_SAVEDIR "/mnt/user/uci/" #define UCI_DIRMODE 0700 #define UCI_FILEMODE 0600 diff --git a/src/3P/uhttpd/CMakeLists.txt b/src/3P/uhttpd/CMakeLists.txt index 7ae8ba4d..8514351b 100644 --- a/src/3P/uhttpd/CMakeLists.txt +++ b/src/3P/uhttpd/CMakeLists.txt @@ -21,9 +21,6 @@ IF(LIBS STREQUAL "LIBS-NOTFOUND") SET(LIBS "") ENDIF() -FIND_PATH(ubox_include_dir libubox/usock.h) -INCLUDE_DIRECTORIES(${ubox_include_dir}) - SET(SOURCES main.c listen.c client.c utils.c file.c auth.c cgi.c relay.c proc.c plugin.c handler.c) IF(TLS_SUPPORT) SET(SOURCES ${SOURCES} tls.c) diff --git a/src/3P/uhttpd/cgi.c b/src/3P/uhttpd/cgi.c index 0ffb1308..dc302a9a 100644 --- a/src/3P/uhttpd/cgi.c +++ b/src/3P/uhttpd/cgi.c @@ -104,11 +104,7 @@ static bool check_cgi_path(struct path_info *pi, const char *url) } pi->ip = NULL; - - if (conf.cgi_docroot_path) - return uh_path_match(conf.cgi_docroot_path, pi->phys); - - return false; + return uh_path_match(conf.cgi_docroot_path, pi->phys); } struct dispatch_handler cgi_dispatch = { diff --git a/src/3P/uhttpd/client.c b/src/3P/uhttpd/client.c index 05044ed9..73e0e49c 100644 --- a/src/3P/uhttpd/client.c +++ b/src/3P/uhttpd/client.c @@ -45,10 +45,8 @@ const char * const http_methods[] = { void uh_http_header(struct client *cl, int code, const char *summary) { struct http_request *r = &cl->request; - struct blob_attr *cur; const char *enc = "Transfer-Encoding: chunked\r\n"; const char *conn; - int rem; cl->http_code = code; @@ -66,10 +64,6 @@ void uh_http_header(struct client *cl, int code, const char *summary) if (!r->connection_close) ustream_printf(cl->us, "Keep-Alive: timeout=%d\r\n", conf.http_keepalive); - - blobmsg_for_each_attr(cur, cl->hdr_response.head, rem) - ustream_printf(cl->us, "%s: %s\r\n", blobmsg_name(cur), - blobmsg_get_string(cur)); } static void uh_connection_close(struct client *cl) @@ -120,7 +114,6 @@ void uh_request_done(struct client *cl) { uh_chunk_eof(cl); uh_dispatch_done(cl); - blob_buf_init(&cl->hdr_response, 0); memset(&cl->dispatch, 0, sizeof(cl->dispatch)); if (!conf.http_keepalive || cl->request.connection_close) @@ -537,7 +530,6 @@ static void client_close(struct client *cl) close(cl->sfd.fd.fd); list_del(&cl->list); blob_buf_free(&cl->hdr); - blob_buf_free(&cl->hdr_response); free(cl); uh_unblock_listeners(); diff --git a/src/3P/uhttpd/file.c b/src/3P/uhttpd/file.c index 047b4dac..12aa1303 100644 --- a/src/3P/uhttpd/file.c +++ b/src/3P/uhttpd/file.c @@ -565,12 +565,11 @@ static void uh_file_free(struct client *cl) static void uh_file_data(struct client *cl, struct path_info *pi, int fd) { /* test preconditions */ - if (!cl->dispatch.no_cache && - (!uh_file_if_modified_since(cl, &pi->stat) || - !uh_file_if_match(cl, &pi->stat) || - !uh_file_if_range(cl, &pi->stat) || - !uh_file_if_unmodified_since(cl, &pi->stat) || - !uh_file_if_none_match(cl, &pi->stat))) { + if (!uh_file_if_modified_since(cl, &pi->stat) || + !uh_file_if_match(cl, &pi->stat) || + !uh_file_if_range(cl, &pi->stat) || + !uh_file_if_unmodified_since(cl, &pi->stat) || + !uh_file_if_none_match(cl, &pi->stat)) { ustream_printf(cl->us, "\r\n"); uh_request_done(cl); close(fd); @@ -864,7 +863,6 @@ void uh_handle_request(struct client *cl) char *url = blobmsg_data(blob_data(cl->hdr.head)); char *error_handler; - blob_buf_init(&cl->hdr_response, 0); url = uh_handle_alias(url); uh_handler_run(cl, &url, false); @@ -879,14 +877,9 @@ void uh_handle_request(struct client *cl) if (__handle_file_request(cl, url)) return; - if (uh_handler_run(cl, &url, true)) { - if (!url) - return; - - uh_handler_run(cl, &url, false); - if (__handle_file_request(cl, url)) - return; - } + if (uh_handler_run(cl, &url, true) && + (!url || __handle_file_request(cl, url))) + return; req->redirect_status = 404; if (conf.error_handler) { diff --git a/src/3P/uhttpd/handler.c b/src/3P/uhttpd/handler.c index 04e71e0f..8e8b9c8c 100644 --- a/src/3P/uhttpd/handler.c +++ b/src/3P/uhttpd/handler.c @@ -102,32 +102,6 @@ handle_set_uri(struct json_script_ctx *ctx, struct blob_attr *data) json_script_abort(ctx); } -static void -handle_add_header(struct json_script_ctx *ctx, struct blob_attr *data) -{ - struct client *cl = cur_client; - static struct blobmsg_policy policy[2] = { - { .type = BLOBMSG_TYPE_STRING }, - { .type = BLOBMSG_TYPE_STRING }, - }; - struct blob_attr *tb[2]; - - blobmsg_parse_array(policy, ARRAY_SIZE(tb), tb, blobmsg_data(data), blobmsg_data_len(data)); - if (!tb[0] || !tb[1]) - return; - - blobmsg_add_string(&cl->hdr_response, blobmsg_get_string(tb[0]), - blobmsg_get_string(tb[1])); -} - -static void -handle_no_cache(struct json_script_ctx *ctx, struct blob_attr *data) -{ - struct client *cl = cur_client; - - cl->dispatch.no_cache = true; -} - static void handle_command(struct json_script_ctx *ctx, const char *name, struct blob_attr *data, struct blob_attr *vars) @@ -137,9 +111,7 @@ handle_command(struct json_script_ctx *ctx, const char *name, void (*func)(struct json_script_ctx *ctx, struct blob_attr *data); } cmds[] = { { "redirect", handle_redirect }, - { "rewrite", handle_set_uri }, - { "add-header", handle_add_header }, - { "no-cache", handle_no_cache }, + { "rewrite", handle_set_uri } }; int i; diff --git a/src/3P/uhttpd/uhttpd.h b/src/3P/uhttpd/uhttpd.h index fe05f0d9..f9ea7619 100644 --- a/src/3P/uhttpd/uhttpd.h +++ b/src/3P/uhttpd/uhttpd.h @@ -224,7 +224,6 @@ struct dispatch { void (*req_free)(struct client *cl); bool data_blocked; - bool no_cache; union { struct { @@ -259,7 +258,6 @@ struct client { struct uh_addr srv_addr, peer_addr; struct blob_buf hdr; - struct blob_buf hdr_response; struct dispatch dispatch; }; diff --git a/src/3P/uhttpd/utils.c b/src/3P/uhttpd/utils.c index 9342eb66..29e03c0b 100644 --- a/src/3P/uhttpd/utils.c +++ b/src/3P/uhttpd/utils.c @@ -208,10 +208,6 @@ bool uh_path_match(const char *prefix, const char *url) { int len = strlen(prefix); - /* A prefix of "/" will - by definition - match any url */ - if (prefix[0] == '/' && len == 1) - return true; - if (strncmp(url, prefix, len) != 0) return false;