procd: Add cached and available to memory table
[oweals/procd.git] / system.c
1 /*
2  * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3  * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License version 2.1
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include <sys/utsname.h>
16 #ifdef linux
17 #include <sys/sysinfo.h>
18 #endif
19 #include <sys/ioctl.h>
20 #include <sys/types.h>
21 #include <sys/reboot.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <signal.h>
25 #include <unistd.h>
26 #include <stdlib.h>
27
28 #include <json-c/json_tokener.h>
29 #include <libubox/blobmsg_json.h>
30 #include <libubox/uloop.h>
31
32 #include "procd.h"
33 #include "sysupgrade.h"
34 #include "watchdog.h"
35
36 static struct blob_buf b;
37 static int notify;
38 static struct ubus_context *_ctx;
39
40 static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
41                  struct ubus_request_data *req, const char *method,
42                  struct blob_attr *msg)
43 {
44         void *c;
45         char line[256];
46         char *key, *val, *next;
47         struct utsname utsname;
48         FILE *f;
49
50         blob_buf_init(&b, 0);
51
52         if (uname(&utsname) >= 0)
53         {
54                 blobmsg_add_string(&b, "kernel", utsname.release);
55                 blobmsg_add_string(&b, "hostname", utsname.nodename);
56         }
57
58         if ((f = fopen("/proc/cpuinfo", "r")) != NULL)
59         {
60                 while(fgets(line, sizeof(line), f))
61                 {
62                         key = strtok(line, "\t:");
63                         val = strtok(NULL, "\t\n");
64
65                         if (!key || !val)
66                                 continue;
67
68                         if (!strcasecmp(key, "system type") ||
69                             !strcasecmp(key, "processor") ||
70                             !strcasecmp(key, "cpu") ||
71                             !strcasecmp(key, "model name"))
72                         {
73                                 strtoul(val + 2, &key, 0);
74
75                                 if (key == (val + 2) || *key != 0)
76                                 {
77                                         blobmsg_add_string(&b, "system", val + 2);
78                                         break;
79                                 }
80                         }
81                 }
82
83                 fclose(f);
84         }
85
86         if ((f = fopen("/tmp/sysinfo/model", "r")) != NULL ||
87             (f = fopen("/proc/device-tree/model", "r")) != NULL)
88         {
89                 if (fgets(line, sizeof(line), f))
90                 {
91                         val = strtok(line, "\t\n");
92
93                         if (val)
94                                 blobmsg_add_string(&b, "model", val);
95                 }
96
97                 fclose(f);
98         }
99         else if ((f = fopen("/proc/cpuinfo", "r")) != NULL)
100         {
101                 while(fgets(line, sizeof(line), f))
102                 {
103                         key = strtok(line, "\t:");
104                         val = strtok(NULL, "\t\n");
105
106                         if (!key || !val)
107                                 continue;
108
109                         if (!strcasecmp(key, "machine") ||
110                             !strcasecmp(key, "hardware"))
111                         {
112                                 blobmsg_add_string(&b, "model", val + 2);
113                                 break;
114                         }
115                 }
116
117                 fclose(f);
118         }
119
120         if ((f = fopen("/tmp/sysinfo/board_name", "r")) != NULL)
121         {
122                 if (fgets(line, sizeof(line), f))
123                 {
124                         val = strtok(line, "\t\n");
125
126                         if (val)
127                                 blobmsg_add_string(&b, "board_name", val);
128                 }
129
130                 fclose(f);
131         }
132         else if ((f = fopen("/proc/device-tree/compatible", "r")) != NULL)
133         {
134                 if (fgets(line, sizeof(line), f))
135                 {
136                         val = strtok(line, "\t\n");
137
138                         if (val)
139                         {
140                                 next = val;
141                                 while ((next = strchr(next, ',')) != NULL)
142                                 {
143                                         *next = '-';
144                                         next++;
145                                 }
146
147                                 blobmsg_add_string(&b, "board_name", val);
148                         }
149                 }
150
151                 fclose(f);
152         }
153
154         if ((f = fopen("/etc/openwrt_release", "r")) != NULL)
155         {
156                 c = blobmsg_open_table(&b, "release");
157
158                 while (fgets(line, sizeof(line), f))
159                 {
160                         char *dest;
161                         char ch;
162
163                         key = line;
164                         val = strchr(line, '=');
165                         if (!val)
166                                 continue;
167
168                         *(val++) = 0;
169
170                         if (!strcasecmp(key, "DISTRIB_ID"))
171                                 key = "distribution";
172                         else if (!strcasecmp(key, "DISTRIB_RELEASE"))
173                                 key = "version";
174                         else if (!strcasecmp(key, "DISTRIB_REVISION"))
175                                 key = "revision";
176                         else if (!strcasecmp(key, "DISTRIB_CODENAME"))
177                                 key = "codename";
178                         else if (!strcasecmp(key, "DISTRIB_TARGET"))
179                                 key = "target";
180                         else if (!strcasecmp(key, "DISTRIB_DESCRIPTION"))
181                                 key = "description";
182                         else
183                                 continue;
184
185                         dest = blobmsg_alloc_string_buffer(&b, key, strlen(val));
186                         if (!dest) {
187                                 ERROR("Failed to allocate blob.\n");
188                                 continue;
189                         }
190
191                         while (val && (ch = *(val++)) != 0) {
192                                 switch (ch) {
193                                 case '\'':
194                                 case '"':
195                                         next = strchr(val, ch);
196                                         if (next)
197                                                 *next = 0;
198
199                                         strcpy(dest, val);
200
201                                         if (next)
202                                                 val = next + 1;
203
204                                         dest += strlen(dest);
205                                         break;
206                                 case '\\':
207                                         *(dest++) = *(val++);
208                                         break;
209                                 }
210                         }
211                         blobmsg_add_string_buffer(&b);
212                 }
213
214                 blobmsg_close_array(&b, c);
215
216                 fclose(f);
217         }
218
219         ubus_send_reply(ctx, req, b.head);
220
221         return UBUS_STATUS_OK;
222 }
223
224 static int system_info(struct ubus_context *ctx, struct ubus_object *obj,
225                 struct ubus_request_data *req, const char *method,
226                 struct blob_attr *msg)
227 {
228         time_t now;
229         struct tm *tm;
230 #ifdef linux
231         struct sysinfo info;
232         void *c;
233         char line[256];
234         char *key, *val;
235         unsigned long long available, cached;
236         FILE *f;
237
238         if (sysinfo(&info))
239                 return UBUS_STATUS_UNKNOWN_ERROR;
240
241         if ((f = fopen("/proc/meminfo", "r")) == NULL)
242                 return UBUS_STATUS_UNKNOWN_ERROR;
243
244         /* if linux < 3.14 MemAvailable is not in meminfo */
245         available = 0;
246         cached = 0;
247
248         while (fgets(line, sizeof(line), f))
249         {
250                 key = strtok(line, " :");
251                 val = strtok(NULL, " ");
252
253                 if (!key || !val)
254                         continue;
255
256                 if (!strcasecmp(key, "MemAvailable"))
257                         available = 1024 * atoll(val);
258                 else if (!strcasecmp(key, "Cached"))
259                         cached = 1024 * atoll(val);
260         }
261
262         fclose(f);
263 #endif
264
265         now = time(NULL);
266
267         if (!(tm = localtime(&now)))
268                 return UBUS_STATUS_UNKNOWN_ERROR;
269
270         blob_buf_init(&b, 0);
271
272         blobmsg_add_u32(&b, "localtime", now + tm->tm_gmtoff);
273
274 #ifdef linux
275         blobmsg_add_u32(&b, "uptime",    info.uptime);
276
277         c = blobmsg_open_array(&b, "load");
278         blobmsg_add_u32(&b, NULL, info.loads[0]);
279         blobmsg_add_u32(&b, NULL, info.loads[1]);
280         blobmsg_add_u32(&b, NULL, info.loads[2]);
281         blobmsg_close_array(&b, c);
282
283         c = blobmsg_open_table(&b, "memory");
284         blobmsg_add_u64(&b, "total",
285                         (uint64_t)info.mem_unit * (uint64_t)info.totalram);
286         blobmsg_add_u64(&b, "free",
287                         (uint64_t)info.mem_unit * (uint64_t)info.freeram);
288         blobmsg_add_u64(&b, "shared",
289                         (uint64_t)info.mem_unit * (uint64_t)info.sharedram);
290         blobmsg_add_u64(&b, "buffered",
291                         (uint64_t)info.mem_unit * (uint64_t)info.bufferram);
292         blobmsg_add_u64(&b, "available", available);
293         blobmsg_add_u64(&b, "cached", cached);
294         blobmsg_close_table(&b, c);
295
296         c = blobmsg_open_table(&b, "swap");
297         blobmsg_add_u64(&b, "total",
298                         (uint64_t)info.mem_unit * (uint64_t)info.totalswap);
299         blobmsg_add_u64(&b, "free",
300                         (uint64_t)info.mem_unit * (uint64_t)info.freeswap);
301         blobmsg_close_table(&b, c);
302 #endif
303
304         ubus_send_reply(ctx, req, b.head);
305
306         return UBUS_STATUS_OK;
307 }
308
309 static int system_reboot(struct ubus_context *ctx, struct ubus_object *obj,
310                          struct ubus_request_data *req, const char *method,
311                          struct blob_attr *msg)
312 {
313         procd_shutdown(RB_AUTOBOOT);
314         return 0;
315 }
316
317 enum {
318         WDT_FREQUENCY,
319         WDT_TIMEOUT,
320         WDT_MAGICCLOSE,
321         WDT_STOP,
322         __WDT_MAX
323 };
324
325 static const struct blobmsg_policy watchdog_policy[__WDT_MAX] = {
326         [WDT_FREQUENCY] = { .name = "frequency", .type = BLOBMSG_TYPE_INT32 },
327         [WDT_TIMEOUT] = { .name = "timeout", .type = BLOBMSG_TYPE_INT32 },
328         [WDT_MAGICCLOSE] = { .name = "magicclose", .type = BLOBMSG_TYPE_BOOL },
329         [WDT_STOP] = { .name = "stop", .type = BLOBMSG_TYPE_BOOL },
330 };
331
332 static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj,
333                         struct ubus_request_data *req, const char *method,
334                         struct blob_attr *msg)
335 {
336         struct blob_attr *tb[__WDT_MAX];
337         const char *status;
338
339         if (!msg)
340                 return UBUS_STATUS_INVALID_ARGUMENT;
341
342         blobmsg_parse(watchdog_policy, __WDT_MAX, tb, blob_data(msg), blob_len(msg));
343         if (tb[WDT_FREQUENCY]) {
344                 unsigned int timeout = tb[WDT_TIMEOUT] ? blobmsg_get_u32(tb[WDT_TIMEOUT]) :
345                                                 watchdog_timeout(0);
346                 unsigned int freq = blobmsg_get_u32(tb[WDT_FREQUENCY]);
347
348                 if (freq) {
349                         if (freq > timeout / 2)
350                                 freq = timeout / 2;
351                         watchdog_frequency(freq);
352                 }
353         }
354
355         if (tb[WDT_TIMEOUT]) {
356                 unsigned int timeout = blobmsg_get_u32(tb[WDT_TIMEOUT]);
357                 unsigned int frequency = watchdog_frequency(0);
358
359                 if (timeout <= frequency)
360                         timeout = frequency * 2;
361                  watchdog_timeout(timeout);
362         }
363
364         if (tb[WDT_MAGICCLOSE])
365                 watchdog_set_magicclose(blobmsg_get_bool(tb[WDT_MAGICCLOSE]));
366
367         if (tb[WDT_STOP])
368                 watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP]));
369
370         if (watchdog_fd() == NULL)
371                 status = "offline";
372         else if (watchdog_get_stopped())
373                 status = "stopped";
374         else
375                 status = "running";
376
377         blob_buf_init(&b, 0);
378         blobmsg_add_string(&b, "status", status);
379         blobmsg_add_u32(&b, "timeout", watchdog_timeout(0));
380         blobmsg_add_u32(&b, "frequency", watchdog_frequency(0));
381         blobmsg_add_u8(&b, "magicclose", watchdog_get_magicclose());
382         ubus_send_reply(ctx, req, b.head);
383
384         return 0;
385 }
386
387 enum {
388         SIGNAL_PID,
389         SIGNAL_NUM,
390         __SIGNAL_MAX
391 };
392
393 static const struct blobmsg_policy signal_policy[__SIGNAL_MAX] = {
394         [SIGNAL_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
395         [SIGNAL_NUM] = { .name = "signum", .type = BLOBMSG_TYPE_INT32 },
396 };
397
398 static int proc_signal(struct ubus_context *ctx, struct ubus_object *obj,
399                         struct ubus_request_data *req, const char *method,
400                         struct blob_attr *msg)
401 {
402         struct blob_attr *tb[__SIGNAL_MAX];
403
404         if (!msg)
405                 return UBUS_STATUS_INVALID_ARGUMENT;
406
407         blobmsg_parse(signal_policy, __SIGNAL_MAX, tb, blob_data(msg), blob_len(msg));
408         if (!tb[SIGNAL_PID || !tb[SIGNAL_NUM]])
409                 return UBUS_STATUS_INVALID_ARGUMENT;
410
411         kill(blobmsg_get_u32(tb[SIGNAL_PID]), blobmsg_get_u32(tb[SIGNAL_NUM]));
412
413         return 0;
414 }
415
416 /**
417  * validate_firmware_image_call - perform validation & store result in global b
418  *
419  * @file: firmware image path
420  */
421 static int validate_firmware_image_call(const char *file)
422 {
423         const char *path = "/usr/libexec/validate_firmware_image";
424         json_object *jsobj = NULL;
425         json_tokener *tok;
426         char buf[64];
427         ssize_t len;
428         int fds[2];
429         int err;
430         int fd;
431
432         if (pipe(fds))
433                 return -errno;
434
435         switch (fork()) {
436         case -1:
437                 return -errno;
438         case 0:
439                 /* Set stdin & stderr to /dev/null */
440                 fd = open("/dev/null", O_RDWR);
441                 if (fd >= 0) {
442                         dup2(fd, 0);
443                         dup2(fd, 2);
444                         close(fd);
445                 }
446
447                 /* Set stdout to the shared pipe */
448                 dup2(fds[1], 1);
449                 close(fds[0]);
450                 close(fds[1]);
451
452                 execl(path, path, file, NULL);
453                 exit(errno);
454         }
455
456         /* Parent process */
457
458         tok = json_tokener_new();
459         if (!tok) {
460                 close(fds[0]);
461                 close(fds[1]);
462                 return -ENOMEM;
463         }
464
465         blob_buf_init(&b, 0);
466         while ((len = read(fds[0], buf, sizeof(buf)))) {
467                 jsobj = json_tokener_parse_ex(tok, buf, len);
468
469                 if (json_tokener_get_error(tok) == json_tokener_success)
470                         break;
471                 else if (json_tokener_get_error(tok) == json_tokener_continue)
472                         continue;
473                 else
474                         fprintf(stderr, "Failed to parse JSON: %d\n",
475                                 json_tokener_get_error(tok));
476         }
477
478         close(fds[0]);
479         close(fds[1]);
480
481         err = -ENOENT;
482         if (jsobj) {
483                 if (json_object_get_type(jsobj) == json_type_object) {
484                         blobmsg_add_object(&b, jsobj);
485                         err = 0;
486                 }
487
488                 json_object_put(jsobj);
489         }
490
491         json_tokener_free(tok);
492
493         return err;
494 }
495
496 enum {
497         VALIDATE_FIRMWARE_IMAGE_PATH,
498         __VALIDATE_FIRMWARE_IMAGE_MAX,
499 };
500
501 static const struct blobmsg_policy validate_firmware_image_policy[__VALIDATE_FIRMWARE_IMAGE_MAX] = {
502         [VALIDATE_FIRMWARE_IMAGE_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
503 };
504
505 static int validate_firmware_image(struct ubus_context *ctx,
506                                    struct ubus_object *obj,
507                                    struct ubus_request_data *req,
508                                    const char *method, struct blob_attr *msg)
509 {
510         struct blob_attr *tb[__VALIDATE_FIRMWARE_IMAGE_MAX];
511
512         if (!msg)
513                 return UBUS_STATUS_INVALID_ARGUMENT;
514
515         blobmsg_parse(validate_firmware_image_policy, __VALIDATE_FIRMWARE_IMAGE_MAX, tb, blob_data(msg), blob_len(msg));
516         if (!tb[VALIDATE_FIRMWARE_IMAGE_PATH])
517                 return UBUS_STATUS_INVALID_ARGUMENT;
518
519         if (validate_firmware_image_call(blobmsg_get_string(tb[VALIDATE_FIRMWARE_IMAGE_PATH])))
520                 return UBUS_STATUS_UNKNOWN_ERROR;
521
522         ubus_send_reply(ctx, req, b.head);
523
524         return UBUS_STATUS_OK;
525 }
526
527 enum {
528         SYSUPGRADE_PATH,
529         SYSUPGRADE_FORCE,
530         SYSUPGRADE_BACKUP,
531         SYSUPGRADE_PREFIX,
532         SYSUPGRADE_COMMAND,
533         SYSUPGRADE_OPTIONS,
534         __SYSUPGRADE_MAX
535 };
536
537 static const struct blobmsg_policy sysupgrade_policy[__SYSUPGRADE_MAX] = {
538         [SYSUPGRADE_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
539         [SYSUPGRADE_FORCE] = { .name = "force", .type = BLOBMSG_TYPE_BOOL },
540         [SYSUPGRADE_BACKUP] = { .name = "backup", .type = BLOBMSG_TYPE_STRING },
541         [SYSUPGRADE_PREFIX] = { .name = "prefix", .type = BLOBMSG_TYPE_STRING },
542         [SYSUPGRADE_COMMAND] = { .name = "command", .type = BLOBMSG_TYPE_STRING },
543         [SYSUPGRADE_OPTIONS] = { .name = "options", .type = BLOBMSG_TYPE_TABLE },
544 };
545
546 static void sysupgrade_error(struct ubus_context *ctx,
547                              struct ubus_request_data *req,
548                              const char *message)
549 {
550         void *c;
551
552         blob_buf_init(&b, 0);
553
554         c = blobmsg_open_table(&b, "error");
555         blobmsg_add_string(&b, "message", message);
556         blobmsg_close_table(&b, c);
557
558         ubus_send_reply(ctx, req, b.head);
559 }
560
561 static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj,
562                       struct ubus_request_data *req, const char *method,
563                       struct blob_attr *msg)
564 {
565         enum {
566                 VALIDATION_VALID,
567                 VALIDATION_FORCEABLE,
568                 VALIDATION_ALLOW_BACKUP,
569                 __VALIDATION_MAX
570         };
571         static const struct blobmsg_policy validation_policy[__VALIDATION_MAX] = {
572                 [VALIDATION_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_BOOL },
573                 [VALIDATION_FORCEABLE] = { .name = "forceable", .type = BLOBMSG_TYPE_BOOL },
574                 [VALIDATION_ALLOW_BACKUP] = { .name = "allow_backup", .type = BLOBMSG_TYPE_BOOL },
575         };
576         struct blob_attr *validation[__VALIDATION_MAX];
577         struct blob_attr *tb[__SYSUPGRADE_MAX];
578         bool valid, forceable, allow_backup;
579
580         if (!msg)
581                 return UBUS_STATUS_INVALID_ARGUMENT;
582
583         blobmsg_parse(sysupgrade_policy, __SYSUPGRADE_MAX, tb, blob_data(msg), blob_len(msg));
584         if (!tb[SYSUPGRADE_PATH] || !tb[SYSUPGRADE_PREFIX])
585                 return UBUS_STATUS_INVALID_ARGUMENT;
586
587         if (validate_firmware_image_call(blobmsg_get_string(tb[SYSUPGRADE_PATH]))) {
588                 sysupgrade_error(ctx, req, "Firmware image couldn't be validated");
589                 return UBUS_STATUS_UNKNOWN_ERROR;
590         }
591
592         blobmsg_parse(validation_policy, __VALIDATION_MAX, validation, blob_data(b.head), blob_len(b.head));
593
594         valid = validation[VALIDATION_VALID] && blobmsg_get_bool(validation[VALIDATION_VALID]);
595         forceable = validation[VALIDATION_FORCEABLE] && blobmsg_get_bool(validation[VALIDATION_FORCEABLE]);
596         allow_backup = validation[VALIDATION_ALLOW_BACKUP] && blobmsg_get_bool(validation[VALIDATION_ALLOW_BACKUP]);
597
598         if (!valid) {
599                 if (!forceable) {
600                         sysupgrade_error(ctx, req, "Firmware image is broken and cannot be installed");
601                         return UBUS_STATUS_NOT_SUPPORTED;
602                 } else if (!tb[SYSUPGRADE_FORCE] || !blobmsg_get_bool(tb[SYSUPGRADE_FORCE])) {
603                         sysupgrade_error(ctx, req, "Firmware image is invalid");
604                         return UBUS_STATUS_NOT_SUPPORTED;
605                 }
606         } else if (!allow_backup && tb[SYSUPGRADE_BACKUP]) {
607                 sysupgrade_error(ctx, req, "Firmware image doesn't allow preserving a backup");
608                 return UBUS_STATUS_NOT_SUPPORTED;
609         }
610
611         sysupgrade_exec_upgraded(blobmsg_get_string(tb[SYSUPGRADE_PREFIX]),
612                                  blobmsg_get_string(tb[SYSUPGRADE_PATH]),
613                                  tb[SYSUPGRADE_BACKUP] ? blobmsg_get_string(tb[SYSUPGRADE_BACKUP]) : NULL,
614                                  tb[SYSUPGRADE_COMMAND] ? blobmsg_get_string(tb[SYSUPGRADE_COMMAND]) : NULL,
615                                  tb[SYSUPGRADE_OPTIONS]);
616
617         /* sysupgrade_exec_upgraded() will never return unless something has gone wrong */
618         return UBUS_STATUS_UNKNOWN_ERROR;
619 }
620
621 static void
622 procd_subscribe_cb(struct ubus_context *ctx, struct ubus_object *obj)
623 {
624         notify = obj->has_subscribers;
625 }
626
627
628 static const struct ubus_method system_methods[] = {
629         UBUS_METHOD_NOARG("board", system_board),
630         UBUS_METHOD_NOARG("info",  system_info),
631         UBUS_METHOD_NOARG("reboot", system_reboot),
632         UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
633         UBUS_METHOD("signal", proc_signal, signal_policy),
634         UBUS_METHOD("validate_firmware_image", validate_firmware_image, validate_firmware_image_policy),
635         UBUS_METHOD("sysupgrade", sysupgrade, sysupgrade_policy),
636 };
637
638 static struct ubus_object_type system_object_type =
639         UBUS_OBJECT_TYPE("system", system_methods);
640
641 static struct ubus_object system_object = {
642         .name = "system",
643         .type = &system_object_type,
644         .methods = system_methods,
645         .n_methods = ARRAY_SIZE(system_methods),
646         .subscribe_cb = procd_subscribe_cb,
647 };
648
649 void
650 procd_bcast_event(char *event, struct blob_attr *msg)
651 {
652         int ret;
653
654         if (!notify)
655                 return;
656
657         ret = ubus_notify(_ctx, &system_object, event, msg, -1);
658         if (ret)
659                 fprintf(stderr, "Failed to notify log: %s\n", ubus_strerror(ret));
660 }
661
662 void ubus_init_system(struct ubus_context *ctx)
663 {
664         int ret;
665
666         _ctx = ctx;
667         ret = ubus_add_object(ctx, &system_object);
668         if (ret)
669                 ERROR("Failed to add object: %s\n", ubus_strerror(ret));
670 }