Sync ubus familly tools.

This commit is contained in:
2017-04-08 21:34:59 +02:00
parent 0e9f199c9c
commit 63d0813f93
57 changed files with 413 additions and 564 deletions

View File

@@ -8,4 +8,3 @@ CMakeFiles
install_manifest.txt install_manifest.txt
jshn jshn
*-example *-example
tests.*

View File

@@ -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_put_int64 blob_put_u64
#define __blob_for_each_attr(pos, attr, rem) \ #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) && \ rem > 0 && (blob_pad_len(pos) <= rem) && \
(blob_pad_len(pos) >= sizeof(struct blob_attr)); \ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \
rem -= blob_pad_len(pos), pos = blob_next(pos)) 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) \ #define blob_for_each_attr(pos, attr, rem) \
for (rem = attr ? blob_len(attr) : 0, \ 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) && \ rem > 0 && (blob_pad_len(pos) <= rem) && \
(blob_pad_len(pos) >= sizeof(struct blob_attr)); \ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \
rem -= blob_pad_len(pos), pos = blob_next(pos)) rem -= blob_pad_len(pos), pos = blob_next(pos))

View File

@@ -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) \ #define blobmsg_for_each_attr(pos, attr, rem) \
for (rem = attr ? blobmsg_data_len(attr) : 0, \ 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) && \ rem > 0 && (blob_pad_len(pos) <= rem) && \
(blob_pad_len(pos) >= sizeof(struct blob_attr)); \ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \
rem -= blob_pad_len(pos), pos = blob_next(pos)) rem -= blob_pad_len(pos), pos = blob_next(pos))

View File

@@ -18,7 +18,7 @@
#include "blobmsg_json.h" #include "blobmsg_json.h"
#ifdef JSONC #ifdef JSONC
#include <json.h> #include <json-c/json.h>
#else #else
#include <json/json.h> #include <json/json.h>
#endif #endif

View File

@@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifdef JSONC #ifdef JSONC
#include <json.h> #include <json-c/json.h>
#else #else
#include <json/json.h> #include <json/json.h>
#endif #endif

View File

@@ -18,7 +18,6 @@
#ifndef __LIBUBOX_KVLIST_H #ifndef __LIBUBOX_KVLIST_H
#define __LIBUBOX_KVLIST_H #define __LIBUBOX_KVLIST_H
#include "avl-cmp.h"
#include "avl.h" #include "avl.h"
struct kvlist { struct kvlist {
@@ -33,15 +32,6 @@ struct kvlist_node {
char data[0] __attribute__((aligned(4))); 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 __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) #define __avl_list_to_kv(_l) container_of(_l, struct kvlist_node, avl.list)

View File

@@ -382,7 +382,6 @@ static void uloop_handle_processes(void)
p->cb(p, ret); p->cb(p, ret);
} }
} }
} }
static void uloop_signal_wake(void) static void uloop_signal_wake(void)

View File

@@ -5,6 +5,11 @@ ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
IF(APPLE)
INCLUDE_DIRECTORIES(/opt/local/include)
LINK_DIRECTORIES(/opt/local/lib)
ENDIF()
SET(SOURCES SET(SOURCES
main.c utils.c system.c tunnel.c handler.c main.c utils.c system.c tunnel.c handler.c
interface.c interface-ip.c interface-event.c interface.c interface-ip.c interface-event.c

View File

@@ -568,6 +568,8 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb)
/* defaults */ /* defaults */
cfg->stp = false; cfg->stp = false;
cfg->forward_delay = 2; cfg->forward_delay = 2;
cfg->igmp_snoop = true;
cfg->multicast_querier = true;
cfg->robustness = 2; cfg->robustness = 2;
cfg->query_interval = 12500; cfg->query_interval = 12500;
cfg->query_response_interval = 1000; cfg->query_response_interval = 1000;

View File

@@ -10,35 +10,35 @@ set (CMAKE_MODULE_PATH "${MODULE_PATH}")
set(DISABLE_TARGET_OPTIMIZATION ON) set(DISABLE_TARGET_OPTIMIZATION ON)
include (br) include (aw)
file ( file (
GLOB_RECURSE GLOB_RECURSE
source_files source_files
$ENV{SRC_DIR}/src/3P/netifd/main.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/main.c
$ENV{SRC_DIR}/src/3P/netifd/utils.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/utils.c
$ENV{SRC_DIR}/src/3P/netifd/system.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/system.c
$ENV{SRC_DIR}/src/3P/netifd/tunnel.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/tunnel.c
$ENV{SRC_DIR}/src/3P/netifd/handler.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/handler.c
$ENV{SRC_DIR}/src/3P/netifd/interface.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/interface.c
$ENV{SRC_DIR}/src/3P/netifd/interface-ip.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/interface-ip.c
$ENV{SRC_DIR}/src/3P/netifd/interface-event.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/interface-event.c
$ENV{SRC_DIR}/src/3P/netifd/iprule.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/iprule.c
$ENV{SRC_DIR}/src/3P/netifd/proto.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/proto.c
$ENV{SRC_DIR}/src/3P/netifd/proto-static.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/proto-static.c
$ENV{SRC_DIR}/src/3P/netifd/proto-shell.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/proto-shell.c
$ENV{SRC_DIR}/src/3P/netifd/config.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/config.c
$ENV{SRC_DIR}/src/3P/netifd/device.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/device.c
$ENV{SRC_DIR}/src/3P/netifd/bridge.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/bridge.c
$ENV{SRC_DIR}/src/3P/netifd/vlan.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/vlan.c
$ENV{SRC_DIR}/src/3P/netifd/alias.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/alias.c
$ENV{SRC_DIR}/src/3P/netifd/macvlan.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/macvlan.c
$ENV{SRC_DIR}/src/3P/netifd/ubus.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/ubus.c
$ENV{SRC_DIR}/src/3P/netifd/vlandev.c $ENV{AWOXCVS}/AwoxAudio/Products/External/netifd/vlandev.c
$ENV{SRC_DIR}/src/3P/netifd/wireless.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
) )

View File

@@ -16,7 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <uci.h> #include <uci/uci.h>
#include "netifd.h" #include "netifd.h"
#include "interface.h" #include "interface.h"

View File

@@ -15,7 +15,7 @@
#define __NETIFD_CONFIG_H #define __NETIFD_CONFIG_H
#include <libubox/blobmsg.h> #include <libubox/blobmsg.h>
#include <uci_blob.h> #include <uci/uci_blob.h>
extern bool config_init; extern bool config_init;

View File

@@ -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_MULTICAST] = { .name ="multicast", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_LEARNING] = { .name ="learning", .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_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 = { 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->multicast_fast_leave = s->multicast_fast_leave;
n->learning = s->learning; n->learning = s->learning;
n->unicast_flood = s->unicast_flood; 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; 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; 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); 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); blobmsg_add_u8(b, "learning", st.learning);
if (st.flags & DEV_OPT_UNICAST_FLOOD) if (st.flags & DEV_OPT_UNICAST_FLOOD)
blobmsg_add_u8(b, "unicast_flood", st.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"); s = blobmsg_open_table(b, "statistics");

View File

@@ -50,7 +50,6 @@ enum {
DEV_ATTR_LEARNING, DEV_ATTR_LEARNING,
DEV_ATTR_UNICAST_FLOOD, DEV_ATTR_UNICAST_FLOOD,
DEV_ATTR_NEIGHGCSTALETIME, DEV_ATTR_NEIGHGCSTALETIME,
DEV_ATTR_SENDREDIRECTS,
__DEV_ATTR_MAX, __DEV_ATTR_MAX,
}; };
@@ -102,7 +101,6 @@ enum {
DEV_OPT_UNICAST_FLOOD = (1 << 18), DEV_OPT_UNICAST_FLOOD = (1 << 18),
DEV_OPT_NEIGHGCSTALETIME = (1 << 19), DEV_OPT_NEIGHGCSTALETIME = (1 << 19),
DEV_OPT_MULTICAST_FAST_LEAVE = (1 << 20), DEV_OPT_MULTICAST_FAST_LEAVE = (1 << 20),
DEV_OPT_SENDREDIRECTS = (1 << 21),
}; };
/* events broadcasted to all users of a device */ /* events broadcasted to all users of a device */
@@ -169,7 +167,6 @@ struct device_settings {
bool multicast; bool multicast;
bool learning; bool learning;
bool unicast_flood; bool unicast_flood;
bool sendredirects;
}; };
/* /*

View File

@@ -40,7 +40,6 @@ enum {
ROUTE_SOURCE, ROUTE_SOURCE,
ROUTE_ONLINK, ROUTE_ONLINK,
ROUTE_TYPE, ROUTE_TYPE,
ROUTE_PROTO,
__ROUTE_MAX __ROUTE_MAX
}; };
@@ -55,8 +54,7 @@ static const struct blobmsg_policy route_attr[__ROUTE_MAX] = {
[ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 }, [ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 },
[ROUTE_SOURCE] = { .name = "source", .type = BLOBMSG_TYPE_STRING }, [ROUTE_SOURCE] = { .name = "source", .type = BLOBMSG_TYPE_STRING },
[ROUTE_ONLINK] = { .name = "onlink", .type = BLOBMSG_TYPE_BOOL }, [ROUTE_ONLINK] = { .name = "onlink", .type = BLOBMSG_TYPE_BOOL },
[ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING }, [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING }
[ROUTE_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING },
}; };
const struct uci_blob_param_list route_attr_list = { 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; 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); interface_set_route_info(iface, route);
vlist_add(&ip->route, &route->node, route); vlist_add(&ip->route, &route->node, route);
return; return;
@@ -488,13 +478,10 @@ interface_handle_subnet_route(struct interface *iface, struct device_addr *addr,
memcpy(&r->addr, &addr->addr, sizeof(r->addr)); memcpy(&r->addr, &addr->addr, sizeof(r->addr));
clear_if_addr(&r->addr, r->mask); clear_if_addr(&r->addr, r->mask);
if (!system_resolve_rt_proto("kernel", &r->proto)) r->flags |= DEVADDR_KERNEL;
return;
r->flags |= DEVROUTE_PROTO;
system_del_route(dev, r); system_del_route(dev, r);
r->flags &= ~DEVROUTE_PROTO; r->flags &= ~DEVADDR_KERNEL;
interface_set_route_info(iface, r); interface_set_route_info(iface, r);
system_add_route(dev, r); system_add_route(dev, r);
@@ -647,7 +634,7 @@ interface_update_proto_route(struct vlist_tree *tree,
if (node_old && node_new) if (node_old && node_new)
keep = !memcmp(&route_old->nexthop, &route_new->nexthop, sizeof(route_old->nexthop)) && 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->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 (node_old) {
if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep) if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep)

View File

@@ -31,8 +31,8 @@ enum device_addr_flags {
/* route overrides the default interface mtu */ /* route overrides the default interface mtu */
DEVROUTE_MTU = (1 << 4), DEVROUTE_MTU = (1 << 4),
/* route overrides the default proto type */ /* route automatically added by kernel */
DEVROUTE_PROTO = (1 << 5), DEVADDR_KERNEL = (1 << 5),
/* address is off-link (no subnet-route) */ /* address is off-link (no subnet-route) */
DEVADDR_OFFLINK = (1 << 6), DEVADDR_OFFLINK = (1 << 6),
@@ -92,7 +92,6 @@ struct device_route {
union if_addr nexthop; union if_addr nexthop;
int mtu; int mtu;
unsigned int type; unsigned int type;
unsigned int proto;
time_t valid_until; time_t valid_until;
/* must be last */ /* must be last */

View File

@@ -36,7 +36,6 @@ enum {
OPT_GATEWAY, OPT_GATEWAY,
OPT_IP6GW, OPT_IP6GW,
OPT_IP6PREFIX, OPT_IP6PREFIX,
OPT_IP6DEPRECATED,
__OPT_MAX, __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_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING },
[OPT_IP6GW] = { .name = "ip6gw", .type = BLOBMSG_TYPE_STRING }, [OPT_IP6GW] = { .name = "ip6gw", .type = BLOBMSG_TYPE_STRING },
[OPT_IP6PREFIX] = { .name = "ip6prefix", .type = BLOBMSG_TYPE_ARRAY }, [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] = { 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 static bool
parse_addr(struct interface *iface, const char *str, bool v6, int mask, 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; struct device_addr *addr;
int af = v6 ? AF_INET6 : AF_INET; 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) if (broadcast)
addr->broadcast = broadcast; addr->broadcast = broadcast;
if (deprecated)
addr->preferred_until = system_get_rtime();
vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags); vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags);
return true; return true;
@@ -153,8 +148,7 @@ error:
static int static int
parse_static_address_option(struct interface *iface, struct blob_attr *attr, parse_static_address_option(struct interface *iface, struct blob_attr *attr,
bool v6, int netmask, bool ext, uint32_t broadcast, bool v6, int netmask, bool ext, uint32_t broadcast)
bool deprecated)
{ {
struct blob_attr *cur; struct blob_attr *cur;
int n_addr = 0; int n_addr = 0;
@@ -166,7 +160,7 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr,
n_addr++; n_addr++;
if (!parse_addr(iface, blobmsg_data(cur), v6, netmask, ext, if (!parse_addr(iface, blobmsg_data(cur), v6, netmask, ext,
broadcast, deprecated)) broadcast))
return -1; return -1;
} }
@@ -406,7 +400,6 @@ proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr)
struct blob_attr *cur; struct blob_attr *cur;
const char *error; const char *error;
unsigned int netmask = 32; unsigned int netmask = 32;
bool ip6deprecated;
int n_v4 = 0, n_v6 = 0; int n_v4 = 0, n_v6 = 0;
struct in_addr bcast = {}; 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])) if ((cur = tb[OPT_IPADDR]))
n_v4 = parse_static_address_option(iface, cur, false, 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])) if ((cur = tb[OPT_IP6ADDR]))
n_v6 = parse_static_address_option(iface, cur, true, n_v6 = parse_static_address_option(iface, cur, true,
128, false, 0, ip6deprecated); 128, false, 0);
if ((cur = tb[OPT_IP6PREFIX])) if ((cur = tb[OPT_IP6PREFIX]))
if (parse_prefix_list(iface, cur) < 0) if (parse_prefix_list(iface, cur) < 0)

View File

@@ -202,12 +202,6 @@ bool system_resolve_rt_type(const char *type, unsigned int *id)
return true; 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) bool system_resolve_rt_table(const char *name, unsigned int *id)
{ {
*id = 0; *id = 0;

View File

@@ -52,6 +52,7 @@
#define IFA_FLAGS (IFA_MULTICAST + 1) #define IFA_FLAGS (IFA_MULTICAST + 1)
#endif #endif
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <glob.h> #include <glob.h>
@@ -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); 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) static int system_get_sysctl(const char *path, char *buf, const size_t buf_sz)
{ {
int fd = -1, ret = -1; 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); 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 // Evaluate netlink messages
static int cb_rtnl_event(struct nl_msg *msg, void *arg) 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->dadtransmits = strtoul(buf, NULL, 0);
s->flags |= DEV_OPT_DADTRANSMITS; 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 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->multicast ? IFF_MULTICAST : 0) < 0)
s->flags &= ~DEV_OPT_MULTICAST; 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); 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_dst_len = route->mask,
.rtm_src_len = route->sourcemask, .rtm_src_len = route->sourcemask,
.rtm_table = (table < 256) ? table : RT_TABLE_UNSPEC, .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_scope = RT_SCOPE_NOWHERE,
.rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST, .rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST,
.rtm_flags = (route->flags & DEVROUTE_ONLINK) ? RTNH_F_ONLINK : 0, .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); 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) bool system_resolve_rt_table(const char *name, unsigned int *id)
{ {
FILE *f; 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; uint32_t ikey = 0, okey = 0, flags = 0, flowinfo = 0;
uint16_t iflags = 0, oflags = 0; uint16_t iflags = 0, oflags = 0;
uint8_t tos = 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); nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE);
if (!nlm) if (!nlm)
@@ -2211,6 +2155,8 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
if ((cur = tb[TUNNEL_ATTR_TTL])) if ((cur = tb[TUNNEL_ATTR_TTL]))
ttl = blobmsg_get_u32(cur); ttl = blobmsg_get_u32(cur);
nla_put_u8(nlm, IFLA_GRE_TTL, ttl);
if ((cur = tb[TUNNEL_ATTR_TOS])) { if ((cur = tb[TUNNEL_ATTR_TOS])) {
char *str = blobmsg_get_string(cur); char *str = blobmsg_get_string(cur);
if (strcmp(str, "inherit")) { if (strcmp(str, "inherit")) {
@@ -2284,9 +2230,6 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
if (flags) if (flags)
nla_put_u32(nlm, IFLA_GRE_FLAGS, flags); nla_put_u32(nlm, IFLA_GRE_FLAGS, flags);
if (!ttl)
ttl = 64;
} else { } else {
struct in_addr inbuf; struct in_addr inbuf;
bool set_df = true; 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])) if ((cur = tb[TUNNEL_ATTR_DF]))
set_df = blobmsg_get_bool(cur); set_df = blobmsg_get_bool(cur);
if (!set_df) { /* ttl !=0 and nopmtudisc are incompatible */
/* ttl != 0 and nopmtudisc are incompatible */ if (ttl && !set_df) {
if (ttl) { ret = -EINVAL;
ret = -EINVAL; goto failure;
goto failure; }
}
} else if (!ttl)
ttl = 64;
nla_put_u8(nlm, IFLA_GRE_PMTUDISC, set_df ? 1 : 0); nla_put_u8(nlm, IFLA_GRE_PMTUDISC, set_df ? 1 : 0);
nla_put_u8(nlm, IFLA_GRE_TOS, tos); nla_put_u8(nlm, IFLA_GRE_TOS, tos);
} }
if (ttl)
nla_put_u8(nlm, IFLA_GRE_TTL, ttl);
if (oflags) if (oflags)
nla_put_u16(nlm, IFLA_GRE_OFLAGS, oflags); nla_put_u16(nlm, IFLA_GRE_OFLAGS, oflags);

View File

@@ -146,7 +146,6 @@ int system_del_route(struct device *dev, struct device_route *route);
int system_flush_routes(void); int system_flush_routes(void);
bool system_resolve_rt_type(const char *type, unsigned int *id); 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_resolve_rt_table(const char *name, unsigned int *id);
bool system_is_default_rt_table(unsigned int id); bool system_is_default_rt_table(unsigned int id);
bool system_resolve_rpfilter(const char *filter, unsigned int *id); bool system_resolve_rpfilter(const char *filter, unsigned int *id);

View File

@@ -486,9 +486,6 @@ interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled)
if (route->flags & DEVROUTE_TYPE) if (route->flags & DEVROUTE_TYPE)
blobmsg_add_u32(&b, "type", route->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) if (route->flags & DEVROUTE_MTU)
blobmsg_add_u32(&b, "mtu", route->mtu); blobmsg_add_u32(&b, "mtu", route->mtu);

View File

@@ -16,7 +16,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <uci_blob.h> #include <uci/uci_blob.h>
#include <libubox/list.h> #include <libubox/list.h>
#include <libubox/avl.h> #include <libubox/avl.h>
#include <libubox/avl-cmp.h> #include <libubox/avl-cmp.h>

View File

@@ -25,7 +25,6 @@
#include <libgen.h> #include <libgen.h>
#include <sched.h> #include <sched.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <signal.h>
#include "capabilities.h" #include "capabilities.h"
#include "elf.h" #include "elf.h"
@@ -299,19 +298,12 @@ static void jail_process_timeout_cb(struct uloop_timeout *t)
kill(jail_process.pid, SIGKILL); 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) int main(int argc, char **argv)
{ {
sigset_t sigmask;
uid_t uid = getuid(); uid_t uid = getuid();
char log[] = "/dev/log"; char log[] = "/dev/log";
char ubus[] = "/var/run/ubus.sock"; char ubus[] = "/var/run/ubus.sock";
int ch, i; int ch;
if (uid) { if (uid) {
ERROR("not root, aborting: %s\n", strerror(errno)); 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); prctl(PR_SET_NAME, opts.name, NULL, NULL, NULL);
uloop_init(); 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) { if (opts.namespace) {
add_mount("/dev/full", 0, -1); add_mount("/dev/full", 0, -1);
add_mount("/dev/null", 0, -1); add_mount("/dev/null", 0, -1);

View File

@@ -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)

View File

@@ -21,40 +21,38 @@
#include <unistd.h> #include <unistd.h>
#define ERROR_EXIT(fmt, ...) do { \ #define ERROR_EXIT(fmt, ...) do { \
fprintf(stderr, fmt, ## __VA_ARGS__); \ fprintf(stderr, fmt, ## __VA_ARGS__); \
return EXIT_FAILURE; \ return EXIT_FAILURE; \
} while (0) } while (0)
static int usage(char *name) static int usage(char *name)
{ {
fprintf(stderr, "Usage: %s <nb>\n", name); fprintf(stderr, "Usage: %s <nb>\n", name);
fprintf(stderr, " => return <nb> bytes from getrandom()\n"); fprintf(stderr, " => return <nb> bytes from getrandom()\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc != 2) if (argc != 2)
return usage(argv[0]); return usage(argv[0]);
if (isatty(STDOUT_FILENO)) if (isatty(STDOUT_FILENO))
ERROR_EXIT("Not outputting random to a tty\n"); ERROR_EXIT("Not outputting random to a tty\n");
int nbtot = atoi(argv[1]); int nbtot = atoi(argv[1]);
if (nbtot < 1) if (nbtot < 1)
ERROR_EXIT("Invalid <nb> param (must be > 0)\n"); ERROR_EXIT("Invalid <nb> param (must be > 0)\n");
char buf[256]; char buf[256];
int len = sizeof(buf); int len = sizeof(buf);
while (nbtot > 0) { while (nbtot > 0) {
if (nbtot <= sizeof(buf)) if (nbtot <= sizeof(buf))
len = nbtot; len = nbtot;
if (syscall(SYS_getrandom, buf, len, 0) == -1) if (syscall(SYS_getrandom, buf, len, 0) == -1)
ERROR_EXIT("getrandom() failed: %s\n", strerror(errno)); ERROR_EXIT("getrandom() failed: %s\n", strerror(errno));
if (write(STDOUT_FILENO, buf, len) != len) if (write(STDOUT_FILENO, buf, len) != len)
ERROR_EXIT("write() failed: %s\n", strerror(errno)); ERROR_EXIT("write() failed: %s\n", strerror(errno));
nbtot -= sizeof(buf); nbtot -= sizeof(buf);
} }
return 0;
} }

View File

@@ -609,10 +609,7 @@ static int main_insmod(int argc, char **argv)
cur += sprintf(cur, "%s", argv[i]); cur += sprintf(cur, "%s", argv[i]);
} }
if (init_module_folders()) { init_module_folders();
fprintf(stderr, "falied to find the folder holding the modules\n");
return -1;
}
if (get_module_path(argv[1])) { if (get_module_path(argv[1])) {
name = argv[1]; name = argv[1];

View File

@@ -31,16 +31,8 @@ static struct blob_buf b;
static struct ubus_auto_conn conn; static struct ubus_auto_conn conn;
static LIST_HEAD(clients); static LIST_HEAD(clients);
enum { static const struct blobmsg_policy read_policy =
READ_LINES, { .name = "lines", .type = BLOBMSG_TYPE_INT32 };
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 write_policy = static const struct blobmsg_policy write_policy =
{ .name = "event", .type = BLOBMSG_TYPE_STRING }; { .name = "event", .type = BLOBMSG_TYPE_STRING };
@@ -68,75 +60,48 @@ static void client_notify_state(struct ustream *s)
client_close(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 static int
read_log(struct ubus_context *ctx, struct ubus_object *obj, read_log(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
struct client *cl; struct client *cl;
struct blob_attr *tb[__READ_MAX]; struct blob_attr *tb;
struct log_head *l; struct log_head *l;
int count = 0; int count = 0;
int fds[2]; int fds[2];
int ret; int ret;
bool stream = true;
void *c, *e;
if (!stream)
count = 100;
if (msg) { if (msg) {
blobmsg_parse(read_policy, __READ_MAX, tb, blob_data(msg), blob_len(msg)); blobmsg_parse(&read_policy, 1, &tb, blob_data(msg), blob_len(msg));
if (tb[READ_LINES]) if (tb)
count = blobmsg_get_u32(tb[READ_LINES]); count = blobmsg_get_u32(tb);
if (tb[READ_STREAM])
stream = blobmsg_get_bool(tb[READ_STREAM]);
} }
if (pipe(fds) == -1) { if (pipe(fds) == -1) {
fprintf(stderr, "logd: failed to create pipe: %s\n", strerror(errno)); fprintf(stderr, "logd: failed to create pipe: %s\n", strerror(errno));
return -1; 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); l = log_list(count, NULL);
if (stream) { while ((!tb || count) && l) {
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 {
blob_buf_init(&b, 0); blob_buf_init(&b, 0);
c = blobmsg_open_array(&b, "log"); blobmsg_add_string(&b, "msg", l->data);
while ((!tb[READ_LINES] || count) && l) { blobmsg_add_u32(&b, "id", l->id);
e = blobmsg_open_table(&b, NULL); blobmsg_add_u32(&b, "priority", l->priority);
log_fill_msg(&b, l); blobmsg_add_u32(&b, "source", l->source);
blobmsg_close_table(&b, e); blobmsg_add_u64(&b, "time", l->ts.tv_sec * 1000LL);
l = log_list(count, l); l = log_list(count, l);
} ret = ustream_write(&cl->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false);
blobmsg_close_array(&b, c); blob_buf_free(&b);
ubus_send_reply(ctx, req, b.head); if (ret < 0)
break;
} }
blob_buf_free(&b);
return 0; return 0;
} }
@@ -160,7 +125,7 @@ write_log(struct ubus_context *ctx, struct ubus_object *obj,
} }
static const struct ubus_method log_methods[] = { 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 }, { .name = "write", .handler = write_log, .policy = &write_policy, .n_policy = 1 },
}; };
@@ -232,7 +197,6 @@ main(int argc, char **argv)
uloop_run(); uloop_run();
log_shutdown(); log_shutdown();
uloop_done(); uloop_done();
ubus_auto_shutdown(&conn);
return 0; return 0;
} }

View File

@@ -30,7 +30,7 @@
#include <libubox/blobmsg_json.h> #include <libubox/blobmsg_json.h>
#include <libubox/usock.h> #include <libubox/usock.h>
#include <libubox/uloop.h> #include <libubox/uloop.h>
#include "libubus.h" #include <libubus.h>
#include "syslog.h" #include "syslog.h"
enum { enum {
@@ -313,7 +313,6 @@ int main(int argc, char **argv)
} }
blob_buf_init(&b, 0); blob_buf_init(&b, 0);
blobmsg_add_u8(&b, "stream", 1);
if (lines) if (lines)
blobmsg_add_u32(&b, "lines", lines); blobmsg_add_u32(&b, "lines", lines);
else if (log_follow) else if (log_follow)

View File

@@ -11,6 +11,12 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include <linux/version.h>
#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,21)
typedef unsigned short sa_family_t;
#endif
#include <linux/un.h> #include <linux/un.h>
#include <sys/types.h> #include <sys/types.h>
@@ -300,6 +306,4 @@ log_shutdown(void)
close(slog.fd.fd); close(slog.fd.fd);
close(klog.fd.fd); close(klog.fd.fd);
free(log); free(log);
regfree(&pat_prio);
regfree(&pat_tstamp);
} }

View File

@@ -8,7 +8,7 @@
#include <netinet/ether.h> #include <netinet/ether.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <uci.h> #include <uci/uci.h>
#include "libvalidate.h" #include "libvalidate.h"
@@ -109,28 +109,39 @@ static int
validate_value(struct uci_ptr *ptr, const char *expr, const char *def) validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
{ {
int i = 0; int i = 0;
bool empty = true; bool empty = true, first = true;
enum dt_type type = DT_INVALID; enum dt_type type = DT_INVALID;
struct uci_element *e; struct uci_element *e;
struct uci_option *opt = NULL; struct uci_option *opt = ptr->o;
if ((ptr->flags & UCI_LOOKUP_COMPLETE) && if (opt->type == UCI_TYPE_LIST)
(ptr->last->type == UCI_TYPE_OPTION))
opt = ptr->o;
if (opt && opt->type == UCI_TYPE_LIST)
{ {
uci_foreach_element(&opt->v.list, e) uci_foreach_element(&opt->v.list, e)
{ {
if (!e->name || !*e->name) if (!e->name || !*e->name)
continue; 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); printf("%s=", ptr->option);
else else
printf("\\ "); printf("\\ ");
empty = false; first = false;
type = dt_parse(expr, e->name); type = dt_parse(expr, e->name);
if (type != DT_INVALID) if (type != DT_INVALID)
@@ -141,12 +152,16 @@ validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
expr, type ? "true" : "false"); 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); type = dt_parse(expr, opt->v.string);
export_value(type, ptr->option, 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, ptr->package, ptr->section, ptr->option, opt->v.string,
expr, type ? "true" : "false"); 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; return type ? 0 : -1;
} }
@@ -187,7 +188,13 @@ validate_option(struct uci_context *ctx, char *package, char *section, char *opt
ptr.section = section; ptr.section = section;
ptr.option = opt; 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); return validate_value(&ptr, expr, def);
} }

View File

@@ -24,7 +24,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <regex.h> #include <regex.h>
#include <uci.h> #include <uci/uci.h>
#include "libvalidate.h" #include "libvalidate.h"

View File

@@ -7,6 +7,4 @@ CMakeFiles
*.dylib *.dylib
examples/server examples/server
examples/client examples/client
ubusd
ubus
install_manifest.txt install_manifest.txt

View File

@@ -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)

View File

@@ -1,50 +1,64 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 3.0)
PROJECT(ubus C) project (ubus)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
OPTION(BUILD_LUA "build Lua plugin" ON) set (CMAKE_MODULE_PATH "${MODULE_PATH}")
OPTION(BUILD_EXAMPLES "build examples" ON)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set(DISABLE_TARGET_OPTIMIZATION ON)
SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
SET(UBUS_MAX_MSGLEN 1048576)
ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}") include_directories ($ENV{SRC_DIR}/src/3P/ubus)
ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN})
IF(BUILD_STATIC) ADD_DEFINITIONS (-Wall -Werror --std=gnu99 -Wmissing-declarations)
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) ADD_DEFINITIONS (-DUBUS_MAX_MSGLEN=1048576)
INCLUDE_DIRECTORIES(${ubox_include_dir}) 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) # ubus library
TARGET_LINK_LIBRARIES(ubus ${ubox_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_include_directories (ubus PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
TARGET_LINK_LIBRARIES(ubusd ${ubox_library} ${blob_library} ${json})
ADD_EXECUTABLE(cli cli.c) install (TARGETS ubus LIBRARY DESTINATION lib)
SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME ubus)
TARGET_LINK_LIBRARIES(cli ubus ${ubox_library} ${blob_library} ${json})
ADD_SUBDIRECTORY(lua) install (FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include)
ADD_SUBDIRECTORY(examples)
INSTALL(TARGETS ubus cli # Daemon ubusd
LIBRARY DESTINATION lib file (
RUNTIME DESTINATION bin GLOB_RECURSE
) ubusd_source_files
INSTALL(TARGETS ubusd
RUNTIME DESTINATION sbin 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)

View File

@@ -293,13 +293,6 @@ static int ubus_cli_wait_for(struct ubus_context *ctx, int argc, char **argv)
uloop_init(); uloop_init();
ubus_add_uloop(ctx); 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); ret = ubus_lookup(ctx, NULL, wait_list_cb, &data);
if (ret) if (ret)
return 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) if (!data.n_pending)
return ret; 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_timeout_set(&data.timeout, timeout * 1000);
uloop_run(); uloop_run();
uloop_done(); uloop_done();

View File

@@ -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); 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, int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req,
struct blob_attr *msg, int cmd, uint32_t peer); struct blob_attr *msg, int cmd, uint32_t peer);
int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, void ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf);
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_req_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd); 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); void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout);

View File

@@ -11,13 +11,12 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include <unistd.h>
#include "libubus.h" #include "libubus.h"
#include "libubus-internal.h" #include "libubus-internal.h"
static void static void
ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr, 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; 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); s = container_of(obj, struct ubus_subscriber, obj);
if (s->remove_cb) if (s->remove_cb)
s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET])); s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET]));
close(fd);
} }
static void static void
ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr, 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]) if (!obj || !attrbuf[UBUS_ATTR_ACTIVE])
return; 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]); obj->has_subscribers = blob_get_u8(attrbuf[UBUS_ATTR_ACTIVE]);
if (obj->subscribe_cb) if (obj->subscribe_cb)
obj->subscribe_cb(ctx, obj); obj->subscribe_cb(ctx, obj);
close(fd);
} }
static void static void
ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr, 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 = { struct ubus_request_data req = {
.fd = -1, .fd = -1,
.req_fd = fd,
}; };
int method; int method;
int ret; int ret;
bool no_reply = false; 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]) if (attrbuf[UBUS_ATTR_NO_REPLY])
no_reply = blob_get_int8(attrbuf[UBUS_ATTR_NO_REPLY]); no_reply = blob_get_int8(attrbuf[UBUS_ATTR_NO_REPLY]);
req.peer = hdr->peer; req.peer = hdr->peer;
req.seq = hdr->seq; req.seq = hdr->seq;
req.object = obj->id; req.object = obj->id;
@@ -95,7 +88,6 @@ found:
ret = obj->methods[method].handler(ctx, obj, &req, ret = obj->methods[method].handler(ctx, obj, &req,
blob_data(attrbuf[UBUS_ATTR_METHOD]), blob_data(attrbuf[UBUS_ATTR_METHOD]),
attrbuf[UBUS_ATTR_DATA]); attrbuf[UBUS_ATTR_DATA]);
close(req.req_fd);
if (req.deferred || no_reply) if (req.deferred || no_reply)
return; return;
@@ -103,16 +95,16 @@ send:
ubus_complete_deferred_request(ctx, &req, ret); ubus_complete_deferred_request(ctx, &req, ret);
} }
void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf)
void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
{ {
void (*cb)(struct ubus_context *, struct ubus_msghdr *, 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 ubus_msghdr *hdr = &buf->hdr;
struct blob_attr **attrbuf; struct blob_attr **attrbuf;
struct ubus_object *obj; struct ubus_object *obj;
uint32_t objid; uint32_t objid;
void *prev_data = NULL; void *prev_data = NULL;
attrbuf = ubus_parse_msg(buf->data); attrbuf = ubus_parse_msg(buf->data);
if (!attrbuf[UBUS_ATTR_OBJID]) if (!attrbuf[UBUS_ATTR_OBJID])
return; return;
@@ -139,7 +131,7 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_
buf->data = NULL; buf->data = NULL;
} }
cb(ctx, hdr, obj, attrbuf, fd); cb(ctx, hdr, obj, attrbuf);
if (prev_data) { if (prev_data) {
if (buf->data) if (buf->data)

View File

@@ -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) struct blob_attr *msg, int cmd, uint32_t peer)
{ {
memset(req, 0, sizeof(*req));
if (msg && blob_pad_len(msg) > UBUS_MAX_MSGLEN) if (msg && blob_pad_len(msg) > UBUS_MAX_MSGLEN)
return -1; return -1;
@@ -61,21 +62,9 @@ int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request
req->ctx = ctx; req->ctx = ctx;
req->peer = peer; req->peer = peer;
req->seq = ++ctx->request_seq; req->seq = ++ctx->request_seq;
return ubus_send_msg(ctx, req->seq, msg, cmd, peer, -1);
return ubus_send_msg(ctx, req->seq, msg, cmd, peer, req->fd);
} }
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) void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req)
{ {
if (list_empty(&req->list)) if (list_empty(&req->list))
@@ -140,9 +129,15 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req,
int req_timeout) int req_timeout)
{ {
ubus_complete_handler_t complete_cb = req->complete_cb; ubus_complete_handler_t complete_cb = req->complete_cb;
bool registered = ctx->sock.registered;
int status = UBUS_STATUS_NO_DATA; int status = UBUS_STATUS_NO_DATA;
int64_t timeout = 0, time_end = 0; int64_t timeout = 0, time_end = 0;
if (!registered) {
uloop_init();
ubus_add_uloop(ctx);
}
if (req_timeout) if (req_timeout)
time_end = get_time_msec() + 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) if (req->complete_cb)
req->complete_cb(req, status); req->complete_cb(req, status);
if (!ctx->stack_depth && !ctx->sock.registered) if (!registered) {
ctx->pending_timer.cb(&ctx->pending_timer); uloop_fd_delete(&ctx->sock);
if (!ctx->stack_depth)
ctx->pending_timer.cb(&ctx->pending_timer);
}
return status; return status;
} }
@@ -210,9 +209,8 @@ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req,
return 0; return 0;
} }
int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
const char *method, struct blob_attr *msg, struct blob_attr *msg, struct ubus_request *req)
struct ubus_request *req, int fd)
{ {
blob_buf_init(&b, 0); blob_buf_init(&b, 0);
blob_put_int32(&b, UBUS_ATTR_OBJID, obj); 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) if (msg)
blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
memset(req, 0, sizeof(*req)); if (ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0)
req->fd = fd;
if (__ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0)
return UBUS_STATUS_INVALID_ARGUMENT; return UBUS_STATUS_INVALID_ARGUMENT;
return 0; return 0;
} }
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, struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
int timeout, int fd) int timeout)
{ {
struct ubus_request req; struct ubus_request req;
int rc; int rc;
rc = ubus_invoke_async_fd(ctx, obj, method, msg, &req, fd); rc = ubus_invoke_async(ctx, obj, method, msg, &req);
if (rc) if (rc)
return rc; return rc;

View File

@@ -103,7 +103,7 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
break; break;
} }
ubus_process_obj_msg(ctx, buf, fd); ubus_process_obj_msg(ctx, buf);
break; break;
case UBUS_MSG_MONITOR: case UBUS_MSG_MONITOR:
if (ctx->monitor_cb) 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.raw_data_cb = ubus_lookup_id_cb;
req.priv = id; 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, 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) int ubus_connect_ctx(struct ubus_context *ctx, const char *path)
{ {
uloop_init();
memset(ctx, 0, sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx));
ctx->sock.fd = -1; ctx->sock.fd = -1;
@@ -363,7 +363,6 @@ void ubus_shutdown(struct ubus_context *ctx)
if (!ctx) if (!ctx)
return; return;
close(ctx->sock.fd); close(ctx->sock.fd);
uloop_timeout_cancel(&ctx->pending_timer);
free(ctx->msgbuf.data); free(ctx->msgbuf.data);
} }

View File

@@ -143,6 +143,7 @@ struct ubus_event_handler {
struct ubus_object obj; struct ubus_object obj;
ubus_event_handler_t cb; ubus_event_handler_t cb;
void *priv; // Awox Addon
}; };
struct ubus_context { struct ubus_context {
@@ -188,7 +189,6 @@ struct ubus_request_data {
/* internal use */ /* internal use */
bool deferred; bool deferred;
int fd; int fd;
int req_fd; /* fd received from the initial request */
}; };
struct ubus_request { struct ubus_request {
@@ -209,8 +209,6 @@ struct ubus_request {
ubus_fd_handler_t fd_cb; ubus_fd_handler_t fd_cb;
ubus_complete_handler_t complete_cb; ubus_complete_handler_t complete_cb;
int fd;
struct ubus_context *ctx; struct ubus_context *ctx;
void *priv; void *priv;
}; };
@@ -331,26 +329,13 @@ int ubus_register_acl(struct ubus_context *ctx);
/* ----------- rpc ----------- */ /* ----------- rpc ----------- */
/* invoke a method on a specific object */ /* 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, struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
int timeout, int fd); int timeout);
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);
}
/* asynchronous version of ubus_invoke() */ /* asynchronous version of ubus_invoke() */
int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, const char *method, int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
struct blob_attr *msg, struct ubus_request *req, int fd); struct blob_attr *msg, struct ubus_request *req);
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);
}
/* send a reply to an incoming object method call */ /* send a reply to an incoming object method call */
int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, 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; 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, void ubus_complete_deferred_request(struct ubus_context *ctx,
struct ubus_request_data *req, int ret); struct ubus_request_data *req, int ret);

0
src/3P/ubus/lua/publisher.lua Executable file → Normal file
View File

0
src/3P/ubus/lua/subscriber.lua Executable file → Normal file
View File

View File

@@ -34,18 +34,6 @@ local my_method = {
conn:reply(req, {message="foo2"}); conn:reply(req, {message="foo2"});
print("Call to function 'hello1'") print("Call to function 'hello1'")
end, {id = ubus.INT32, msg = ubus.STRING } 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, {}
} }
} }
} }

View File

@@ -352,26 +352,6 @@ static int ubus_lua_reply(lua_State *L)
return 0; 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) static int ubus_lua_load_methods(lua_State *L, struct ubus_method *m)
{ {
struct blobmsg_policy *p; struct blobmsg_policy *p;
@@ -940,8 +920,6 @@ static const luaL_Reg ubus[] = {
{ "add", ubus_lua_add }, { "add", ubus_lua_add },
{ "notify", ubus_lua_notify }, { "notify", ubus_lua_notify },
{ "reply", ubus_lua_reply }, { "reply", ubus_lua_reply },
{ "defer_request", ubus_lua_defer_request },
{ "complete_deferred_request", ubus_lua_complete_deferred_request },
{ "signatures", ubus_lua_signatures }, { "signatures", ubus_lua_signatures },
{ "call", ubus_lua_call }, { "call", ubus_lua_call },
{ "close", ubus_lua__gc }, { "close", ubus_lua__gc },

View File

@@ -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]) { if (!cl->tx_queue[cl->txq_cur]) {
written = ubus_msg_writev(cl->sock.fd, ub, 0); written = ubus_msg_writev(cl->sock.fd, ub, 0);
if (written >= ub->len + sizeof(ub->hdr))
goto out;
if (written < 0) if (written < 0)
written = 0; written = 0;
if (written >= ub->len + sizeof(ub->hdr))
goto out;
cl->txq_ofs = written; cl->txq_ofs = written;
/* get an event once we can write to the socket again */ /* get an event once we can write to the socket again */

View File

@@ -101,7 +101,7 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj,
struct blob_attr *cur; struct blob_attr *cur;
int rem; int rem;
if (!cl->uid || !obj) if (!cl->uid)
return 0; return 0;
acl = avl_find_ge_element(&ubusd_acls, obj, acl, avl); acl = avl_find_ge_element(&ubusd_acls, obj, acl, avl);
@@ -434,7 +434,7 @@ ubusd_reply_add(struct ubus_object *obj)
if (!acl->priv) if (!acl->priv)
continue; 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; continue;
c = blobmsg_open_table(&b, NULL); c = blobmsg_open_table(&b, NULL);

View File

@@ -80,15 +80,11 @@ void
ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub, ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub,
uint8_t type) 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); ub = ubus_reply_from_blob(ub, true);
if (!ub) if (!ub)
return; return;
ub->hdr.type = type; ub->hdr.type = type;
ub->fd = fd;
ubus_msg_send(cl, ub, true); 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) if (obj->type && obj->type->refcount == 1)
blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id); 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); ubusd_free_object(obj);
ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA);
return 0; 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_buf_init(&b, 0);
blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id); 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); blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id);
ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); 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) static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj)
{ {
struct ubus_method *m; struct ubus_method *m;
int all_cnt = 0, cnt = 0; int cnt = 0;
void *s; void *s;
if (!obj->type)
return;
blob_buf_init(&b, 0); blob_buf_init(&b, 0);
blob_put_string(&b, UBUS_ATTR_OBJPATH, obj->path.key); 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); s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE);
list_for_each_entry(m, &obj->type->methods, list) { 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)) { if (!ubusd_acl_check(cl, obj->path.key, blobmsg_name(m->data), UBUS_ACL_ACCESS)) {
blobmsg_add_blob(&b, m->data); blobmsg_add_blob(&b, m->data);
cnt++; 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); blob_nest_end(&b, s);
if (cnt || !all_cnt) if (cnt)
ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); 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; return UBUS_STATUS_INVALID_ARGUMENT;
target = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_TARGET])); target = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_TARGET]));
if (!target || !target->client) if (!target)
return UBUS_STATUS_NOT_FOUND; return UBUS_STATUS_NOT_FOUND;
if (cl == target->client) 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) if (ub->hdr.type < __UBUS_MSG_LAST)
cb = handlers[ub->hdr.type]; 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); ubus_msg_close_fd(ub);
if (cb) if (cb)

View File

@@ -19,7 +19,8 @@
#define __packetdata __attribute__((packed)) __attribute__((__aligned__(4))) #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_EVENT 1
#define UBUS_SYSTEM_OBJECT_ACL 2 #define UBUS_SYSTEM_OBJECT_ACL 2

View File

@@ -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)

View File

@@ -36,7 +36,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#define UCI_CONFDIR "/etc/config" #define UCI_CONFDIR "/etc/config"
#define UCI_SAVEDIR "/tmp/.uci" #define UCI_SAVEDIR "/mnt/user/uci/"
#define UCI_DIRMODE 0700 #define UCI_DIRMODE 0700
#define UCI_FILEMODE 0600 #define UCI_FILEMODE 0600

View File

@@ -21,9 +21,6 @@ IF(LIBS STREQUAL "LIBS-NOTFOUND")
SET(LIBS "") SET(LIBS "")
ENDIF() 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) 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) IF(TLS_SUPPORT)
SET(SOURCES ${SOURCES} tls.c) SET(SOURCES ${SOURCES} tls.c)

View File

@@ -104,11 +104,7 @@ static bool check_cgi_path(struct path_info *pi, const char *url)
} }
pi->ip = NULL; pi->ip = NULL;
return uh_path_match(conf.cgi_docroot_path, pi->phys);
if (conf.cgi_docroot_path)
return uh_path_match(conf.cgi_docroot_path, pi->phys);
return false;
} }
struct dispatch_handler cgi_dispatch = { struct dispatch_handler cgi_dispatch = {

View File

@@ -45,10 +45,8 @@ const char * const http_methods[] = {
void uh_http_header(struct client *cl, int code, const char *summary) void uh_http_header(struct client *cl, int code, const char *summary)
{ {
struct http_request *r = &cl->request; struct http_request *r = &cl->request;
struct blob_attr *cur;
const char *enc = "Transfer-Encoding: chunked\r\n"; const char *enc = "Transfer-Encoding: chunked\r\n";
const char *conn; const char *conn;
int rem;
cl->http_code = code; cl->http_code = code;
@@ -66,10 +64,6 @@ void uh_http_header(struct client *cl, int code, const char *summary)
if (!r->connection_close) if (!r->connection_close)
ustream_printf(cl->us, "Keep-Alive: timeout=%d\r\n", conf.http_keepalive); 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) static void uh_connection_close(struct client *cl)
@@ -120,7 +114,6 @@ void uh_request_done(struct client *cl)
{ {
uh_chunk_eof(cl); uh_chunk_eof(cl);
uh_dispatch_done(cl); uh_dispatch_done(cl);
blob_buf_init(&cl->hdr_response, 0);
memset(&cl->dispatch, 0, sizeof(cl->dispatch)); memset(&cl->dispatch, 0, sizeof(cl->dispatch));
if (!conf.http_keepalive || cl->request.connection_close) if (!conf.http_keepalive || cl->request.connection_close)
@@ -537,7 +530,6 @@ static void client_close(struct client *cl)
close(cl->sfd.fd.fd); close(cl->sfd.fd.fd);
list_del(&cl->list); list_del(&cl->list);
blob_buf_free(&cl->hdr); blob_buf_free(&cl->hdr);
blob_buf_free(&cl->hdr_response);
free(cl); free(cl);
uh_unblock_listeners(); uh_unblock_listeners();

View File

@@ -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) static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
{ {
/* test preconditions */ /* test preconditions */
if (!cl->dispatch.no_cache && if (!uh_file_if_modified_since(cl, &pi->stat) ||
(!uh_file_if_modified_since(cl, &pi->stat) || !uh_file_if_match(cl, &pi->stat) ||
!uh_file_if_match(cl, &pi->stat) || !uh_file_if_range(cl, &pi->stat) ||
!uh_file_if_range(cl, &pi->stat) || !uh_file_if_unmodified_since(cl, &pi->stat) ||
!uh_file_if_unmodified_since(cl, &pi->stat) || !uh_file_if_none_match(cl, &pi->stat)) {
!uh_file_if_none_match(cl, &pi->stat))) {
ustream_printf(cl->us, "\r\n"); ustream_printf(cl->us, "\r\n");
uh_request_done(cl); uh_request_done(cl);
close(fd); close(fd);
@@ -864,7 +863,6 @@ void uh_handle_request(struct client *cl)
char *url = blobmsg_data(blob_data(cl->hdr.head)); char *url = blobmsg_data(blob_data(cl->hdr.head));
char *error_handler; char *error_handler;
blob_buf_init(&cl->hdr_response, 0);
url = uh_handle_alias(url); url = uh_handle_alias(url);
uh_handler_run(cl, &url, false); uh_handler_run(cl, &url, false);
@@ -879,14 +877,9 @@ void uh_handle_request(struct client *cl)
if (__handle_file_request(cl, url)) if (__handle_file_request(cl, url))
return; return;
if (uh_handler_run(cl, &url, true)) { if (uh_handler_run(cl, &url, true) &&
if (!url) (!url || __handle_file_request(cl, url)))
return; return;
uh_handler_run(cl, &url, false);
if (__handle_file_request(cl, url))
return;
}
req->redirect_status = 404; req->redirect_status = 404;
if (conf.error_handler) { if (conf.error_handler) {

View File

@@ -102,32 +102,6 @@ handle_set_uri(struct json_script_ctx *ctx, struct blob_attr *data)
json_script_abort(ctx); 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 static void
handle_command(struct json_script_ctx *ctx, const char *name, handle_command(struct json_script_ctx *ctx, const char *name,
struct blob_attr *data, struct blob_attr *vars) 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); void (*func)(struct json_script_ctx *ctx, struct blob_attr *data);
} cmds[] = { } cmds[] = {
{ "redirect", handle_redirect }, { "redirect", handle_redirect },
{ "rewrite", handle_set_uri }, { "rewrite", handle_set_uri }
{ "add-header", handle_add_header },
{ "no-cache", handle_no_cache },
}; };
int i; int i;

View File

@@ -224,7 +224,6 @@ struct dispatch {
void (*req_free)(struct client *cl); void (*req_free)(struct client *cl);
bool data_blocked; bool data_blocked;
bool no_cache;
union { union {
struct { struct {
@@ -259,7 +258,6 @@ struct client {
struct uh_addr srv_addr, peer_addr; struct uh_addr srv_addr, peer_addr;
struct blob_buf hdr; struct blob_buf hdr;
struct blob_buf hdr_response;
struct dispatch dispatch; struct dispatch dispatch;
}; };

View File

@@ -208,10 +208,6 @@ bool uh_path_match(const char *prefix, const char *url)
{ {
int len = strlen(prefix); 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) if (strncmp(url, prefix, len) != 0)
return false; return false;