2 * luci-rpcd - LuCI UBUS RPC server
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #include <sys/types.h>
28 #include <arpa/inet.h>
33 static struct blob_buf buf;
34 static struct uci_context *cursor;
42 static const struct blobmsg_policy rpc_signal_policy[__RPC_S_MAX] = {
43 [RPC_S_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
44 [RPC_S_SIGNAL] = { .name = "signal", .type = BLOBMSG_TYPE_INT32 },
53 static const struct blobmsg_policy rpc_init_policy[__RPC_I_MAX] = {
54 [RPC_I_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
55 [RPC_I_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING },
63 static const struct blobmsg_policy rpc_sshkey_policy[__RPC_K_MAX] = {
64 [RPC_K_KEYS] = { .name = "keys", .type = BLOBMSG_TYPE_ARRAY },
69 rpc_errno_status(void)
74 return UBUS_STATUS_PERMISSION_DENIED;
77 return UBUS_STATUS_INVALID_ARGUMENT;
80 return UBUS_STATUS_NOT_FOUND;
83 return UBUS_STATUS_INVALID_ARGUMENT;
86 return UBUS_STATUS_UNKNOWN_ERROR;
91 log_read(FILE *log, int logsize)
97 logsize = RPC_LUCI2_DEF_LOGSIZE;
99 len = (logsize > RPC_LUCI2_MAX_LOGSIZE) ? RPC_LUCI2_MAX_LOGSIZE : logsize;
100 logbuf = blobmsg_alloc_string_buffer(&buf, "log", len + 1);
105 while (logsize > RPC_LUCI2_MAX_LOGSIZE)
107 len = logsize % RPC_LUCI2_MAX_LOGSIZE;
110 len = RPC_LUCI2_MAX_LOGSIZE;
112 fread(logbuf, 1, len, log);
116 len = fread(logbuf, 1, logsize, log);
119 blobmsg_add_string_buffer(&buf);
123 rpc_luci2_system_log(struct ubus_context *ctx, struct ubus_object *obj,
124 struct ubus_request_data *req, const char *method,
125 struct blob_attr *msg)
129 const char *logfile = NULL;
131 struct uci_package *p;
132 struct uci_element *e;
133 struct uci_section *s;
134 struct uci_ptr ptr = { .package = "system" };
136 uci_load(cursor, ptr.package, &p);
139 return UBUS_STATUS_NOT_FOUND;
141 uci_foreach_element(&p->sections, e)
143 s = uci_to_section(e);
145 if (strcmp(s->type, "system"))
149 ptr.option = "log_type";
150 ptr.section = e->name;
151 uci_lookup_ptr(cursor, &ptr, NULL, true);
155 if (ptr.o && ptr.o->type == UCI_TYPE_STRING &&
156 !strcmp(ptr.o->v.string, "file"))
159 ptr.option = "log_file";
160 uci_lookup_ptr(cursor, &ptr, NULL, true);
162 if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
163 logfile = ptr.o->v.string;
165 logfile = "/var/log/messages";
167 if (stat(logfile, &st) || !(log = fopen(logfile, "r")))
170 logsize = st.st_size;
175 ptr.option = "log_size";
176 uci_lookup_ptr(cursor, &ptr, NULL, true);
178 if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
179 logsize = atoi(ptr.o->v.string) * 1024;
181 if (!(log = popen("logread", "r")))
185 blob_buf_init(&buf, 0);
187 log_read(log, logsize);
190 uci_unload(cursor, p);
191 ubus_send_reply(ctx, req, buf.head);
195 uci_unload(cursor, p);
196 return rpc_errno_status();
200 rpc_luci2_system_dmesg(struct ubus_context *ctx, struct ubus_object *obj,
201 struct ubus_request_data *req, const char *method,
202 struct blob_attr *msg)
206 if (!(log = popen("dmesg", "r")))
207 return rpc_errno_status();
209 blob_buf_init(&buf, 0);
211 log_read(log, RPC_LUCI2_MAX_LOGSIZE);
214 ubus_send_reply(ctx, req, buf.head);
219 rpc_luci2_process_list(struct ubus_context *ctx, struct ubus_object *obj,
220 struct ubus_request_data *req, const char *method,
221 struct blob_attr *msg)
226 char *pid, *ppid, *user, *stat, *vsz, *pvsz, *pcpu, *cmd;
228 if (!(top = popen("/bin/busybox top -bn1", "r")))
229 return rpc_errno_status();
231 blob_buf_init(&buf, 0);
232 c = blobmsg_open_array(&buf, "processes");
234 while (fgets(line, sizeof(line) - 1, top))
236 pid = strtok(line, " ");
238 if (*pid < '0' || *pid > '9')
241 ppid = strtok(NULL, " ");
242 user = strtok(NULL, " ");
243 stat = strtok(NULL, " ");
256 vsz = strtok(stat + 4, " ");
257 pvsz = strtok(NULL, " ");
258 pcpu = strtok(NULL, " ");
259 cmd = strtok(NULL, "\n");
264 d = blobmsg_open_table(&buf, NULL);
266 blobmsg_add_u32(&buf, "pid", atoi(pid));
267 blobmsg_add_u32(&buf, "ppid", atoi(ppid));
268 blobmsg_add_string(&buf, "user", user);
269 blobmsg_add_string(&buf, "stat", stat);
270 blobmsg_add_u32(&buf, "vsize", atoi(vsz) * 1024);
271 blobmsg_add_u32(&buf, "vsize_percent", atoi(pvsz));
272 blobmsg_add_u32(&buf, "cpu_percent", atoi(pcpu));
273 blobmsg_add_string(&buf, "command", cmd);
275 blobmsg_close_table(&buf, d);
279 blobmsg_close_array(&buf, c);
281 ubus_send_reply(ctx, req, buf.head);
286 rpc_luci2_process_signal(struct ubus_context *ctx, struct ubus_object *obj,
287 struct ubus_request_data *req, const char *method,
288 struct blob_attr *msg)
291 struct blob_attr *tb[__RPC_S_MAX];
293 blobmsg_parse(rpc_signal_policy, __RPC_S_MAX, tb,
294 blob_data(msg), blob_len(msg));
296 if (!tb[RPC_S_SIGNAL] || !tb[RPC_S_PID])
299 return rpc_errno_status();
302 pid = blobmsg_get_u32(tb[RPC_S_PID]);
303 sig = blobmsg_get_u32(tb[RPC_S_SIGNAL]);
306 return rpc_errno_status();
312 rpc_luci2_init_list(struct ubus_context *ctx, struct ubus_object *obj,
313 struct ubus_request_data *req, const char *method,
314 struct blob_attr *msg)
318 char *p, path[PATH_MAX];
324 if (!(d = opendir("/etc/init.d")))
325 return rpc_errno_status();
327 blob_buf_init(&buf, 0);
328 c = blobmsg_open_array(&buf, "initscripts");
330 while ((e = readdir(d)) != NULL)
332 snprintf(path, sizeof(path) - 1, "/etc/init.d/%s", e->d_name);
334 if (stat(path, &s) || !S_ISREG(s.st_mode) || !(s.st_mode & S_IXUSR))
337 if ((f = fopen(path, "r")) != NULL)
340 p = fgets(path, sizeof(path) - 1, f);
342 if (!p || !strstr(p, "/etc/rc.common"))
345 t = blobmsg_open_table(&buf, NULL);
347 blobmsg_add_string(&buf, "name", e->d_name);
349 while (fgets(path, sizeof(path) - 1, f))
351 p = strtok(path, "= \t");
353 if (!strcmp(p, "START") && !!(p = strtok(NULL, "= \t\n")))
356 blobmsg_add_u32(&buf, "start", n);
358 else if (!strcmp(p, "STOP") && !!(p = strtok(NULL, "= \t\n")))
360 blobmsg_add_u32(&buf, "stop", atoi(p));
367 snprintf(path, sizeof(path) - 1, "/etc/rc.d/S%02d%s",
370 blobmsg_add_u8(&buf, "enabled",
371 (!stat(path, &s) && (s.st_mode & S_IXUSR)));
375 blobmsg_add_u8(&buf, "enabled", 0);
378 blobmsg_close_table(&buf, t);
386 blobmsg_close_array(&buf, c);
388 ubus_send_reply(ctx, req, buf.head);
393 rpc_luci2_init_action(struct ubus_context *ctx, struct ubus_object *obj,
394 struct ubus_request_data *req, const char *method,
395 struct blob_attr *msg)
402 struct blob_attr *tb[__RPC_I_MAX];
404 blobmsg_parse(rpc_init_policy, __RPC_I_MAX, tb,
405 blob_data(msg), blob_len(msg));
407 if (!tb[RPC_I_NAME] || !tb[RPC_I_ACTION])
408 return UBUS_STATUS_INVALID_ARGUMENT;
410 action = blobmsg_data(tb[RPC_I_ACTION]);
412 if (strcmp(action, "start") && strcmp(action, "stop") &&
413 strcmp(action, "reload") && strcmp(action, "restart") &&
414 strcmp(action, "enable") && strcmp(action, "disable"))
415 return UBUS_STATUS_INVALID_ARGUMENT;
417 snprintf(path, sizeof(path) - 1, "/etc/init.d/%s",
418 (char *)blobmsg_data(tb[RPC_I_NAME]));
421 return rpc_errno_status();
423 if (!(s.st_mode & S_IXUSR))
424 return UBUS_STATUS_PERMISSION_DENIED;
426 switch ((pid = fork()))
429 return rpc_errno_status();
434 if ((fd = open("/dev/null", O_RDWR)) > -1)
445 if (execl(path, path, action, NULL))
446 return rpc_errno_status();
454 rpc_luci2_sshkeys_get(struct ubus_context *ctx, struct ubus_object *obj,
455 struct ubus_request_data *req, const char *method,
456 struct blob_attr *msg)
462 if (!(f = fopen("/etc/dropbear/authorized_keys", "r")))
463 return rpc_errno_status();
465 blob_buf_init(&buf, 0);
466 c = blobmsg_open_array(&buf, "keys");
468 while (fgets(line, sizeof(line) - 1, f))
470 for (p = line + strlen(line) - 1; (p > line) && isspace(*p); p--)
473 for (p = line; isspace(*p); p++)
477 blobmsg_add_string(&buf, NULL, p);
480 blobmsg_close_array(&buf, c);
483 ubus_send_reply(ctx, req, buf.head);
488 rpc_luci2_sshkeys_set(struct ubus_context *ctx, struct ubus_object *obj,
489 struct ubus_request_data *req, const char *method,
490 struct blob_attr *msg)
494 struct blob_attr *cur, *tb[__RPC_K_MAX];
496 blobmsg_parse(rpc_sshkey_policy, __RPC_K_MAX, tb,
497 blob_data(msg), blob_len(msg));
500 return UBUS_STATUS_INVALID_ARGUMENT;
502 if (!(f = fopen("/etc/dropbear/authorized_keys", "w")))
503 return rpc_errno_status();
505 blobmsg_for_each_attr(cur, tb[RPC_K_KEYS], rem)
507 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
510 fwrite(blobmsg_data(cur), blobmsg_data_len(cur) - 1, 1, f);
511 fwrite("\n", 1, 1, f);
520 dnsmasq_leasefile(void)
523 struct uci_package *p;
524 struct uci_element *e;
525 struct uci_section *s;
526 struct uci_ptr ptr = {
529 .option = "leasefile"
532 uci_load(cursor, ptr.package, &p);
537 uci_foreach_element(&p->sections, e)
539 s = uci_to_section(e);
541 if (strcmp(s->type, "dnsmasq"))
544 ptr.section = e->name;
545 uci_lookup_ptr(cursor, &ptr, NULL, true);
549 if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
550 leases = fopen(ptr.o->v.string, "r");
552 uci_unload(cursor, p);
558 rpc_luci2_network_leases(struct ubus_context *ctx, struct ubus_object *obj,
559 struct ubus_request_data *req, const char *method,
560 struct blob_attr *msg)
565 char *ts, *mac, *addr, *name;
566 time_t now = time(NULL);
568 blob_buf_init(&buf, 0);
569 c = blobmsg_open_array(&buf, "leases");
571 leases = dnsmasq_leasefile();
576 while (fgets(line, sizeof(line) - 1, leases))
578 ts = strtok(line, " \t");
579 mac = strtok(NULL, " \t");
580 addr = strtok(NULL, " \t");
581 name = strtok(NULL, " \t");
583 if (!ts || !mac || !addr || !name)
586 if (strchr(addr, ':'))
589 d = blobmsg_open_table(&buf, NULL);
591 blobmsg_add_u32(&buf, "expires", atoi(ts) - now);
592 blobmsg_add_string(&buf, "macaddr", mac);
593 blobmsg_add_string(&buf, "ipaddr", addr);
595 if (strcmp(name, "*"))
596 blobmsg_add_string(&buf, "hostname", name);
598 blobmsg_close_table(&buf, d);
604 blobmsg_close_array(&buf, c);
605 ubus_send_reply(ctx, req, buf.head);
611 rpc_luci2_network_leases6(struct ubus_context *ctx, struct ubus_object *obj,
612 struct ubus_request_data *req, const char *method,
613 struct blob_attr *msg)
618 char *ts, *mac, *addr, *name, *duid;
619 time_t now = time(NULL);
621 blob_buf_init(&buf, 0);
622 c = blobmsg_open_array(&buf, "leases");
624 leases = fopen("/tmp/hosts/6relayd", "r");
628 while (fgets(line, sizeof(line) - 1, leases))
630 if (strncmp(line, "# ", 2))
633 strtok(line + 2, " \t"); /* iface */
635 duid = strtok(NULL, " \t");
637 strtok(NULL, " \t"); /* iaid */
639 name = strtok(NULL, " \t");
640 ts = strtok(NULL, " \t");
642 strtok(NULL, " \t"); /* id */
643 strtok(NULL, " \t"); /* length */
645 addr = strtok(NULL, " \t\n");
650 d = blobmsg_open_table(&buf, NULL);
652 blobmsg_add_u32(&buf, "expires", atoi(ts) - now);
653 blobmsg_add_string(&buf, "duid", duid);
654 blobmsg_add_string(&buf, "ip6addr", addr);
656 if (strcmp(name, "-"))
657 blobmsg_add_string(&buf, "hostname", name);
659 blobmsg_close_array(&buf, d);
666 leases = dnsmasq_leasefile();
671 while (fgets(line, sizeof(line) - 1, leases))
673 ts = strtok(line, " \t");
674 mac = strtok(NULL, " \t");
675 addr = strtok(NULL, " \t");
676 name = strtok(NULL, " \t");
677 duid = strtok(NULL, " \t\n");
679 if (!ts || !mac || !addr || !duid)
682 if (!strchr(addr, ':'))
685 d = blobmsg_open_table(&buf, NULL);
687 blobmsg_add_u32(&buf, "expires", atoi(ts) - now);
688 blobmsg_add_string(&buf, "macaddr", mac);
689 blobmsg_add_string(&buf, "ip6addr", addr);
691 if (strcmp(name, "*"))
692 blobmsg_add_string(&buf, "hostname", name);
694 if (strcmp(duid, "*"))
695 blobmsg_add_string(&buf, "duid", name);
697 blobmsg_close_table(&buf, d);
704 blobmsg_close_array(&buf, c);
705 ubus_send_reply(ctx, req, buf.head);
711 rpc_luci2_network_ct_count(struct ubus_context *ctx, struct ubus_object *obj,
712 struct ubus_request_data *req, const char *method,
713 struct blob_attr *msg)
718 blob_buf_init(&buf, 0);
720 if ((f = fopen("/proc/sys/net/netfilter/nf_conntrack_count", "r")) != NULL)
722 if (fgets(line, sizeof(line) - 1, f))
723 blobmsg_add_u32(&buf, "count", atoi(line));
728 if ((f = fopen("/proc/sys/net/netfilter/nf_conntrack_max", "r")) != NULL)
730 if (fgets(line, sizeof(line) - 1, f))
731 blobmsg_add_u32(&buf, "limit", atoi(line));
736 ubus_send_reply(ctx, req, buf.head);
742 rpc_luci2_network_ct_table(struct ubus_context *ctx, struct ubus_object *obj,
743 struct ubus_request_data *req, const char *method,
744 struct blob_attr *msg)
752 blob_buf_init(&buf, 0);
753 c = blobmsg_open_array(&buf, "entries");
755 if ((f = fopen("/proc/net/nf_conntrack", "r")) != NULL)
757 while (fgets(line, sizeof(line) - 1, f))
759 d = blobmsg_open_table(&buf, NULL);
760 memset(seen, 0, sizeof(seen));
762 for (i = 0, p = strtok(line, " "); p; i++, p = strtok(NULL, " "))
765 blobmsg_add_u8(&buf, "ipv6", !strcmp(p, "ipv6"));
767 blobmsg_add_u32(&buf, "protocol", atoi(p));
769 blobmsg_add_u32(&buf, "expires", atoi(p));
775 if (!seen[0] && !strncmp(p, "src=", 4))
777 blobmsg_add_string(&buf, "src", p + 4);
780 else if (!seen[1] && !strncmp(p, "dst=", 4))
782 blobmsg_add_string(&buf, "dest", p + 4);
785 else if (!seen[2] && !strncmp(p, "sport=", 6))
787 blobmsg_add_u32(&buf, "sport", atoi(p + 6));
790 else if (!seen[3] && !strncmp(p, "dport=", 6))
792 blobmsg_add_u32(&buf, "dport", atoi(p + 6));
795 else if (!strncmp(p, "packets=", 8))
797 blobmsg_add_u32(&buf,
798 seen[4] ? "tx_packets" : "rx_packets",
802 else if (!strncmp(p, "bytes=", 6))
804 blobmsg_add_u32(&buf,
805 seen[5] ? "tx_bytes" : "rx_bytes",
812 blobmsg_close_table(&buf, d);
818 blobmsg_close_array(&buf, c);
819 ubus_send_reply(ctx, req, buf.head);
825 rpc_luci2_network_arp_table(struct ubus_context *ctx, struct ubus_object *obj,
826 struct ubus_request_data *req, const char *method,
827 struct blob_attr *msg)
831 char *addr, *mac, *dev, line[128];
833 blob_buf_init(&buf, 0);
834 c = blobmsg_open_array(&buf, "entries");
836 if ((f = fopen("/proc/net/arp", "r")) != NULL)
838 /* skip header line */
839 fgets(line, sizeof(line) - 1, f);
841 while (fgets(line, sizeof(line) - 1, f))
843 addr = strtok(line, " \t");
845 strtok(NULL, " \t"); /* HW type */
846 strtok(NULL, " \t"); /* Flags */
848 mac = strtok(NULL, " \t");
850 strtok(NULL, " \t"); /* Mask */
852 dev = strtok(NULL, " \t\n");
857 d = blobmsg_open_table(&buf, NULL);
858 blobmsg_add_string(&buf, "ipaddr", addr);
859 blobmsg_add_string(&buf, "macaddr", mac);
860 blobmsg_add_string(&buf, "device", dev);
861 blobmsg_close_table(&buf, d);
867 blobmsg_close_array(&buf, c);
868 ubus_send_reply(ctx, req, buf.head);
874 put_hexaddr(const char *name, const char *s, const char *m)
878 char as[sizeof("255.255.255.255/32\0")];
880 a.s_addr = strtoul(s, NULL, 16);
881 inet_ntop(AF_INET, &a, as, sizeof(as));
885 for (a.s_addr = ntohl(strtoul(m, NULL, 16)), bits = 0;
886 a.s_addr & 0x80000000;
890 sprintf(as + strlen(as), "/%u", bits);
893 blobmsg_add_string(&buf, name, as);
897 rpc_luci2_network_routes(struct ubus_context *ctx, struct ubus_object *obj,
898 struct ubus_request_data *req, const char *method,
899 struct blob_attr *msg)
903 char *dst, *dmask, *next, *metric, *device;
907 if (!(routes = fopen("/proc/net/route", "r")))
908 return rpc_errno_status();
910 blob_buf_init(&buf, 0);
911 c = blobmsg_open_array(&buf, "routes");
913 /* skip header line */
914 fgets(line, sizeof(line) - 1, routes);
916 while (fgets(line, sizeof(line) - 1, routes))
918 device = strtok(line, "\t ");
919 dst = strtok(NULL, "\t ");
920 next = strtok(NULL, "\t ");
922 strtok(NULL, "\t "); /* flags */
923 strtok(NULL, "\t "); /* refcount */
924 strtok(NULL, "\t "); /* usecount */
926 metric = strtok(NULL, "\t ");
927 dmask = strtok(NULL, "\t ");
932 d = blobmsg_open_table(&buf, NULL);
934 put_hexaddr("target", dst, dmask);
935 put_hexaddr("nexthop", next, NULL);
937 n = strtoul(metric, NULL, 10);
938 blobmsg_add_u32(&buf, "metric", n);
940 blobmsg_add_string(&buf, "device", device);
942 blobmsg_close_table(&buf, d);
945 blobmsg_close_array(&buf, c);
948 ubus_send_reply(ctx, req, buf.head);
953 put_hex6addr(const char *name, const char *s, const char *m)
957 char as[INET6_ADDRSTRLEN + sizeof("/128")];
960 (((x) <= '9') ? ((x) - '0') : \
961 (((x) <= 'F') ? ((x) - 'A' + 10) : \
964 for (i = 0; i < 16; i++, s += 2)
965 a.s6_addr[i] = (16 * hex(*s)) + hex(*(s+1));
967 inet_ntop(AF_INET6, &a, as, sizeof(as));
970 sprintf(as + strlen(as), "/%lu", strtoul(m, NULL, 16));
972 blobmsg_add_string(&buf, name, as);
976 rpc_luci2_network_routes6(struct ubus_context *ctx, struct ubus_object *obj,
977 struct ubus_request_data *req, const char *method,
978 struct blob_attr *msg)
982 char *src, *smask, *dst, *dmask, *next, *metric, *flags, *device;
986 if (!(routes = fopen("/proc/net/ipv6_route", "r")))
987 return rpc_errno_status();
989 blob_buf_init(&buf, 0);
990 c = blobmsg_open_array(&buf, "routes");
992 while (fgets(line, sizeof(line) - 1, routes))
994 dst = strtok(line, " ");
995 dmask = strtok(NULL, " ");
996 src = strtok(NULL, " ");
997 smask = strtok(NULL, " ");
998 next = strtok(NULL, " ");
999 metric = strtok(NULL, " ");
1001 strtok(NULL, " "); /* refcount */
1002 strtok(NULL, " "); /* usecount */
1004 flags = strtok(NULL, " ");
1005 device = strtok(NULL, " \n");
1010 n = strtoul(flags, NULL, 16);
1015 d = blobmsg_open_table(&buf, NULL);
1017 put_hex6addr("target", dst, dmask);
1018 put_hex6addr("source", src, smask);
1019 put_hex6addr("nexthop", next, NULL);
1021 n = strtoul(metric, NULL, 16);
1022 blobmsg_add_u32(&buf, "metric", n);
1024 blobmsg_add_string(&buf, "device", device);
1026 blobmsg_close_table(&buf, d);
1029 blobmsg_close_array(&buf, c);
1032 ubus_send_reply(ctx, req, buf.head);
1037 int rpc_luci2_api_init(struct ubus_context *ctx)
1041 static const struct ubus_method luci2_system_methods[] = {
1042 UBUS_METHOD_NOARG("syslog", rpc_luci2_system_log),
1043 UBUS_METHOD_NOARG("dmesg", rpc_luci2_system_dmesg),
1044 UBUS_METHOD_NOARG("process_list", rpc_luci2_process_list),
1045 UBUS_METHOD("process_signal", rpc_luci2_process_signal,
1047 UBUS_METHOD_NOARG("init_list", rpc_luci2_init_list),
1048 UBUS_METHOD("init_action", rpc_luci2_init_action,
1050 UBUS_METHOD_NOARG("sshkeys_get", rpc_luci2_sshkeys_get),
1051 UBUS_METHOD("sshkeys_set", rpc_luci2_sshkeys_set,
1055 static struct ubus_object_type luci2_system_type =
1056 UBUS_OBJECT_TYPE("luci-rpc-luci2-system", luci2_system_methods);
1058 static struct ubus_object system_obj = {
1059 .name = "luci2.system",
1060 .type = &luci2_system_type,
1061 .methods = luci2_system_methods,
1062 .n_methods = ARRAY_SIZE(luci2_system_methods),
1066 static const struct ubus_method luci2_network_methods[] = {
1067 UBUS_METHOD_NOARG("conntrack_count", rpc_luci2_network_ct_count),
1068 UBUS_METHOD_NOARG("conntrack_table", rpc_luci2_network_ct_table),
1069 UBUS_METHOD_NOARG("arp_table", rpc_luci2_network_arp_table),
1070 UBUS_METHOD_NOARG("dhcp_leases", rpc_luci2_network_leases),
1071 UBUS_METHOD_NOARG("dhcp6_leases", rpc_luci2_network_leases6),
1072 UBUS_METHOD_NOARG("routes", rpc_luci2_network_routes),
1073 UBUS_METHOD_NOARG("routes6", rpc_luci2_network_routes6),
1076 static struct ubus_object_type luci2_network_type =
1077 UBUS_OBJECT_TYPE("luci-rpc-luci2-network", luci2_network_methods);
1079 static struct ubus_object network_obj = {
1080 .name = "luci2.network",
1081 .type = &luci2_network_type,
1082 .methods = luci2_network_methods,
1083 .n_methods = ARRAY_SIZE(luci2_network_methods),
1086 cursor = uci_alloc_context();
1089 return UBUS_STATUS_UNKNOWN_ERROR;
1091 rv |= ubus_add_object(ctx, &system_obj);
1092 rv |= ubus_add_object(ctx, &network_obj);