db4b3354e21eb3732279fcbb16500d1f36dfc717
[project/netifd.git] / ubus.c
1 /*
2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
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 #define _GNU_SOURCE
15
16 #include <arpa/inet.h>
17 #include <string.h>
18 #include <stdio.h>
19
20 #include "netifd.h"
21 #include "interface.h"
22 #include "proto.h"
23 #include "ubus.h"
24 #include "system.h"
25 #include "wireless.h"
26
27 struct ubus_context *ubus_ctx = NULL;
28 static struct blob_buf b;
29 static const char *ubus_path;
30
31 /* global object */
32
33 static int
34 netifd_handle_restart(struct ubus_context *ctx, struct ubus_object *obj,
35 struct ubus_request_data *req, const char *method,
36 struct blob_attr *msg)
37 {
38 netifd_restart();
39 return 0;
40 }
41
42 static int
43 netifd_handle_reload(struct ubus_context *ctx, struct ubus_object *obj,
44 struct ubus_request_data *req, const char *method,
45 struct blob_attr *msg)
46 {
47 if (netifd_reload())
48 return UBUS_STATUS_NOT_FOUND;
49
50 return UBUS_STATUS_OK;
51 }
52
53 enum {
54 HR_TARGET,
55 HR_V6,
56 HR_INTERFACE,
57 __HR_MAX
58 };
59
60 static const struct blobmsg_policy route_policy[__HR_MAX] = {
61 [HR_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
62 [HR_V6] = { .name = "v6", .type = BLOBMSG_TYPE_BOOL },
63 [HR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
64 };
65
66 static int
67 netifd_add_host_route(struct ubus_context *ctx, struct ubus_object *obj,
68 struct ubus_request_data *req, const char *method,
69 struct blob_attr *msg)
70 {
71 struct blob_attr *tb[__HR_MAX];
72 struct interface *iface = NULL;
73 union if_addr a;
74 bool v6 = false;
75
76 blobmsg_parse(route_policy, __HR_MAX, tb, blob_data(msg), blob_len(msg));
77 if (!tb[HR_TARGET])
78 return UBUS_STATUS_INVALID_ARGUMENT;
79
80 if (tb[HR_V6])
81 v6 = blobmsg_get_bool(tb[HR_V6]);
82
83 if (tb[HR_INTERFACE])
84 iface = vlist_find(&interfaces, blobmsg_data(tb[HR_INTERFACE]), iface, node);
85
86 memset(&a, 0, sizeof(a));
87 if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(tb[HR_TARGET]), &a))
88 return UBUS_STATUS_INVALID_ARGUMENT;
89
90
91 iface = interface_ip_add_target_route(&a, v6, iface);
92 if (!iface)
93 return UBUS_STATUS_NOT_FOUND;
94
95 blob_buf_init(&b, 0);
96 blobmsg_add_string(&b, "interface", iface->name);
97 ubus_send_reply(ctx, req, b.head);
98
99 return 0;
100 }
101
102 static int
103 netifd_get_proto_handlers(struct ubus_context *ctx, struct ubus_object *obj,
104 struct ubus_request_data *req, const char *method,
105 struct blob_attr *msg)
106 {
107 blob_buf_init(&b, 0);
108 proto_dump_handlers(&b);
109 ubus_send_reply(ctx, req, b.head);
110
111 return 0;
112 }
113
114
115 enum {
116 DI_NAME,
117 __DI_MAX
118 };
119
120 static const struct blobmsg_policy dynamic_policy[__DI_MAX] = {
121 [DI_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
122 };
123
124 static int
125 netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj,
126 struct ubus_request_data *req, const char *method,
127 struct blob_attr *msg)
128 {
129 struct blob_attr *tb[__DI_MAX];
130 struct interface *iface;
131 struct blob_attr *config;
132
133 blobmsg_parse(dynamic_policy, __DI_MAX, tb, blob_data(msg), blob_len(msg));
134
135 if (!tb[DI_NAME])
136 return UBUS_STATUS_INVALID_ARGUMENT;
137
138 const char *name = blobmsg_get_string(tb[DI_NAME]);
139
140 iface = interface_alloc(name, msg, true);
141 if (!iface)
142 return UBUS_STATUS_UNKNOWN_ERROR;
143
144 config = blob_memdup(msg);
145 if (!config)
146 goto error;
147
148 if (!interface_add(iface, config))
149 goto error_free_config;
150
151 return UBUS_STATUS_OK;
152
153 error_free_config:
154 free(config);
155 error:
156 free(iface);
157 return UBUS_STATUS_UNKNOWN_ERROR;
158 }
159
160 enum {
161 NETNS_UPDOWN_JAIL,
162 NETNS_UPDOWN_PID,
163 NETNS_UPDOWN_START,
164 __NETNS_UPDOWN_MAX
165 };
166
167 static const struct blobmsg_policy netns_updown_policy[__NETNS_UPDOWN_MAX] = {
168 [NETNS_UPDOWN_JAIL] = { .name = "jail", .type = BLOBMSG_TYPE_STRING },
169 [NETNS_UPDOWN_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
170 [NETNS_UPDOWN_START] = { .name = "start", .type = BLOBMSG_TYPE_BOOL },
171 };
172
173 static int
174 netifd_netns_updown(struct ubus_context *ctx, struct ubus_object *obj,
175 struct ubus_request_data *req, const char *method,
176 struct blob_attr *msg)
177 {
178 struct blob_attr *tb[__NETNS_UPDOWN_MAX];
179 char *jail;
180 pid_t netns_pid;
181 bool start;
182
183 blobmsg_parse(netns_updown_policy, __NETNS_UPDOWN_MAX, tb, blob_data(msg), blob_len(msg));
184 if (!tb[NETNS_UPDOWN_JAIL] || !tb[NETNS_UPDOWN_PID])
185 return UBUS_STATUS_INVALID_ARGUMENT;
186
187 start = tb[NETNS_UPDOWN_START] && blobmsg_get_bool(tb[NETNS_UPDOWN_START]);
188 jail = blobmsg_get_string(tb[NETNS_UPDOWN_JAIL]);
189 netns_pid = blobmsg_get_u32(tb[NETNS_UPDOWN_PID]);
190
191 if (start)
192 interface_start_jail(jail, netns_pid);
193 else
194 interface_stop_jail(jail, netns_pid);
195
196 return UBUS_STATUS_OK;
197 }
198
199 static struct ubus_method main_object_methods[] = {
200 { .name = "restart", .handler = netifd_handle_restart },
201 { .name = "reload", .handler = netifd_handle_reload },
202 UBUS_METHOD("add_host_route", netifd_add_host_route, route_policy),
203 { .name = "get_proto_handlers", .handler = netifd_get_proto_handlers },
204 UBUS_METHOD("add_dynamic", netifd_add_dynamic, dynamic_policy),
205 UBUS_METHOD("netns_updown", netifd_netns_updown, netns_updown_policy),
206 };
207
208 static struct ubus_object_type main_object_type =
209 UBUS_OBJECT_TYPE("netifd", main_object_methods);
210
211 static struct ubus_object main_object = {
212 .name = "network",
213 .type = &main_object_type,
214 .methods = main_object_methods,
215 .n_methods = ARRAY_SIZE(main_object_methods),
216 };
217
218 enum {
219 DEV_NAME,
220 __DEV_MAX,
221 };
222
223 static const struct blobmsg_policy dev_policy[__DEV_MAX] = {
224 [DEV_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
225 };
226
227 static int
228 netifd_dev_status(struct ubus_context *ctx, struct ubus_object *obj,
229 struct ubus_request_data *req, const char *method,
230 struct blob_attr *msg)
231 {
232 struct device *dev = NULL;
233 struct blob_attr *tb[__DEV_MAX];
234
235 blobmsg_parse(dev_policy, __DEV_MAX, tb, blob_data(msg), blob_len(msg));
236
237 if (tb[DEV_NAME]) {
238 dev = device_find(blobmsg_data(tb[DEV_NAME]));
239 if (!dev)
240 return UBUS_STATUS_INVALID_ARGUMENT;
241 }
242
243 blob_buf_init(&b, 0);
244 device_dump_status(&b, dev);
245 ubus_send_reply(ctx, req, b.head);
246
247 return 0;
248 }
249
250 enum {
251 ALIAS_ATTR_ALIAS,
252 ALIAS_ATTR_DEV,
253 __ALIAS_ATTR_MAX,
254 };
255
256 static const struct blobmsg_policy alias_attrs[__ALIAS_ATTR_MAX] = {
257 [ALIAS_ATTR_ALIAS] = { "alias", BLOBMSG_TYPE_ARRAY },
258 [ALIAS_ATTR_DEV] = { "device", BLOBMSG_TYPE_STRING },
259 };
260
261 static int
262 netifd_handle_alias(struct ubus_context *ctx, struct ubus_object *obj,
263 struct ubus_request_data *req, const char *method,
264 struct blob_attr *msg)
265 {
266 struct device *dev = NULL;
267 struct blob_attr *tb[__ALIAS_ATTR_MAX];
268 struct blob_attr *cur;
269 int rem;
270
271 blobmsg_parse(alias_attrs, __ALIAS_ATTR_MAX, tb, blob_data(msg), blob_len(msg));
272
273 if (!tb[ALIAS_ATTR_ALIAS])
274 return UBUS_STATUS_INVALID_ARGUMENT;
275
276 if ((cur = tb[ALIAS_ATTR_DEV]) != NULL) {
277 dev = device_get(blobmsg_data(cur), true);
278 if (!dev)
279 return UBUS_STATUS_NOT_FOUND;
280 }
281
282 blobmsg_for_each_attr(cur, tb[ALIAS_ATTR_ALIAS], rem) {
283 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
284 goto error;
285
286 if (!blobmsg_check_attr(cur, false))
287 goto error;
288
289 alias_notify_device(blobmsg_data(cur), dev);
290 }
291 return 0;
292
293 error:
294 device_free_unused(dev);
295 return UBUS_STATUS_INVALID_ARGUMENT;
296 }
297
298 enum {
299 DEV_STATE_NAME,
300 DEV_STATE_DEFER,
301 __DEV_STATE_MAX,
302 };
303
304 static const struct blobmsg_policy dev_state_policy[__DEV_STATE_MAX] = {
305 [DEV_STATE_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
306 [DEV_STATE_DEFER] = { .name = "defer", .type = BLOBMSG_TYPE_BOOL },
307 };
308
309 static int
310 netifd_handle_set_state(struct ubus_context *ctx, struct ubus_object *obj,
311 struct ubus_request_data *req, const char *method,
312 struct blob_attr *msg)
313 {
314 struct device *dev = NULL;
315 struct blob_attr *tb[__DEV_STATE_MAX];
316 struct blob_attr *cur;
317
318 blobmsg_parse(dev_state_policy, __DEV_STATE_MAX, tb, blob_data(msg), blob_len(msg));
319
320 cur = tb[DEV_STATE_NAME];
321 if (!cur)
322 return UBUS_STATUS_INVALID_ARGUMENT;
323
324 dev = device_find(blobmsg_data(cur));
325 if (!dev)
326 return UBUS_STATUS_NOT_FOUND;
327
328 cur = tb[DEV_STATE_DEFER];
329 if (cur)
330 device_set_deferred(dev, !!blobmsg_get_u8(cur));
331
332 return 0;
333 }
334
335 static struct ubus_method dev_object_methods[] = {
336 UBUS_METHOD("status", netifd_dev_status, dev_policy),
337 UBUS_METHOD("set_alias", netifd_handle_alias, alias_attrs),
338 UBUS_METHOD("set_state", netifd_handle_set_state, dev_state_policy),
339 };
340
341 static struct ubus_object_type dev_object_type =
342 UBUS_OBJECT_TYPE("device", dev_object_methods);
343
344 static struct ubus_object dev_object = {
345 .name = "network.device",
346 .type = &dev_object_type,
347 .methods = dev_object_methods,
348 .n_methods = ARRAY_SIZE(dev_object_methods),
349 };
350
351 static void
352 netifd_ubus_add_fd(void)
353 {
354 ubus_add_uloop(ubus_ctx);
355 system_fd_set_cloexec(ubus_ctx->sock.fd);
356 }
357
358 static void
359 netifd_ubus_reconnect_timer(struct uloop_timeout *timeout)
360 {
361 static struct uloop_timeout retry = {
362 .cb = netifd_ubus_reconnect_timer,
363 };
364 int t = 2;
365
366 if (ubus_reconnect(ubus_ctx, ubus_path) != 0) {
367 DPRINTF("failed to reconnect, trying again in %d seconds\n", t);
368 uloop_timeout_set(&retry, t * 1000);
369 return;
370 }
371
372 DPRINTF("reconnected to ubus, new id: %08x\n", ubus_ctx->local_id);
373 netifd_ubus_add_fd();
374 }
375
376 static void
377 netifd_ubus_connection_lost(struct ubus_context *ctx)
378 {
379 netifd_ubus_reconnect_timer(NULL);
380 }
381
382 /* per-interface object */
383
384 static int
385 netifd_handle_up(struct ubus_context *ctx, struct ubus_object *obj,
386 struct ubus_request_data *req, const char *method,
387 struct blob_attr *msg)
388 {
389 struct interface *iface;
390
391 iface = container_of(obj, struct interface, ubus);
392 interface_set_up(iface);
393
394 return 0;
395 }
396
397 static int
398 netifd_handle_down(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 interface *iface;
403
404 iface = container_of(obj, struct interface, ubus);
405 interface_set_down(iface);
406
407 return 0;
408 }
409
410 static int
411 netifd_handle_renew(struct ubus_context *ctx, struct ubus_object *obj,
412 struct ubus_request_data *req, const char *method,
413 struct blob_attr *msg)
414 {
415 struct interface *iface;
416
417 iface = container_of(obj, struct interface, ubus);
418 interface_renew(iface);
419
420 return 0;
421 }
422
423 static void
424 netifd_add_interface_errors(struct blob_buf *b, struct interface *iface)
425 {
426 struct interface_error *error;
427 void *e, *e2, *e3;
428 int i;
429
430 e = blobmsg_open_array(b, "errors");
431 list_for_each_entry(error, &iface->errors, list) {
432 e2 = blobmsg_open_table(b, NULL);
433
434 blobmsg_add_string(b, "subsystem", error->subsystem);
435 blobmsg_add_string(b, "code", error->code);
436 if (error->data[0]) {
437 e3 = blobmsg_open_array(b, "data");
438 for (i = 0; error->data[i]; i++)
439 blobmsg_add_string(b, NULL, error->data[i]);
440 blobmsg_close_array(b, e3);
441 }
442
443 blobmsg_close_table(b, e2);
444 }
445 blobmsg_close_array(b, e);
446 }
447
448 static void
449 interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6, bool enabled)
450 {
451 struct device_addr *addr;
452 char *buf;
453 void *a;
454 int buflen = 128;
455 int af;
456
457 time_t now = system_get_rtime();
458 vlist_for_each_element(&ip->addr, addr, node) {
459 if (addr->enabled != enabled)
460 continue;
461
462 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4)
463 af = AF_INET;
464 else
465 af = AF_INET6;
466
467 if (af != (v6 ? AF_INET6 : AF_INET))
468 continue;
469
470 a = blobmsg_open_table(&b, NULL);
471
472 buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
473 inet_ntop(af, &addr->addr, buf, buflen);
474 blobmsg_add_string_buffer(&b);
475
476 blobmsg_add_u32(&b, "mask", addr->mask);
477
478 if (addr->point_to_point) {
479 buf = blobmsg_alloc_string_buffer(&b, "ptpaddress", buflen);
480 inet_ntop(af, &addr->point_to_point, buf, buflen);
481 blobmsg_add_string_buffer(&b);
482 }
483
484 if (addr->preferred_until) {
485 int preferred = addr->preferred_until - now;
486 if (preferred < 0)
487 preferred = 0;
488 blobmsg_add_u32(&b, "preferred", preferred);
489 }
490
491 if (addr->valid_until)
492 blobmsg_add_u32(&b, "valid", addr->valid_until - now);
493
494 if (addr->pclass)
495 blobmsg_add_string(&b, "class", addr->pclass);
496
497 blobmsg_close_table(&b, a);
498 }
499 }
500
501 static void
502 interface_ip_dump_neighbor_list(struct interface_ip_settings *ip, bool enabled)
503 {
504 struct device_neighbor *neighbor;
505 int buflen = 128;
506 char *buf;
507 void *r;
508 int af;
509
510 vlist_for_each_element(&ip->neighbor, neighbor, node) {
511 if (neighbor->enabled != enabled)
512 continue;
513
514 if ((neighbor->flags & DEVADDR_FAMILY) == DEVADDR_INET4)
515 af = AF_INET;
516 else
517 af = AF_INET6;
518
519 r = blobmsg_open_table(&b, NULL);
520
521 if (neighbor->flags & DEVNEIGH_MAC)
522 blobmsg_add_string(&b, "mac", format_macaddr(neighbor->macaddr));
523
524 buf = blobmsg_alloc_string_buffer(&b , "address", buflen);
525 inet_ntop(af, &neighbor->addr, buf, buflen);
526 blobmsg_add_string_buffer(&b);
527
528 if (neighbor->proxy)
529 blobmsg_add_u32(&b, "proxy", neighbor->proxy);
530
531 if (neighbor->router)
532 blobmsg_add_u32(&b, "router", neighbor->router);
533
534 blobmsg_close_table(&b, r);
535 }
536 }
537
538 static void
539 interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled)
540 {
541 struct device_route *route;
542 int buflen = 128;
543 char *buf;
544 void *r;
545 int af;
546
547 time_t now = system_get_rtime();
548 vlist_for_each_element(&ip->route, route, node) {
549 if (route->enabled != enabled)
550 continue;
551
552 if ((ip->no_defaultroute == enabled) && !route->mask)
553 continue;
554
555 if ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET4)
556 af = AF_INET;
557 else
558 af = AF_INET6;
559
560 r = blobmsg_open_table(&b, NULL);
561
562 buf = blobmsg_alloc_string_buffer(&b, "target", buflen);
563 inet_ntop(af, &route->addr, buf, buflen);
564 blobmsg_add_string_buffer(&b);
565
566 blobmsg_add_u32(&b, "mask", route->mask);
567
568 buf = blobmsg_alloc_string_buffer(&b, "nexthop", buflen);
569 inet_ntop(af, &route->nexthop, buf, buflen);
570 blobmsg_add_string_buffer(&b);
571
572 if (route->flags & DEVROUTE_TYPE)
573 blobmsg_add_u32(&b, "type", route->type);
574
575 if (route->flags & DEVROUTE_PROTO)
576 blobmsg_add_u32(&b, "proto", route->proto);
577
578 if (route->flags & DEVROUTE_MTU)
579 blobmsg_add_u32(&b, "mtu", route->mtu);
580
581 if (route->flags & DEVROUTE_METRIC)
582 blobmsg_add_u32(&b, "metric", route->metric);
583
584 if (route->flags & DEVROUTE_TABLE)
585 blobmsg_add_u32(&b, "table", route->table);
586
587 if (route->valid_until)
588 blobmsg_add_u32(&b, "valid", route->valid_until - now);
589
590 buf = blobmsg_alloc_string_buffer(&b, "source", buflen);
591 inet_ntop(af, &route->source, buf, buflen);
592 snprintf(buf + strlen(buf), buflen - strlen(buf), "/%u", route->sourcemask);
593 blobmsg_add_string_buffer(&b);
594
595 blobmsg_close_table(&b, r);
596 }
597 }
598
599
600 static void
601 interface_ip_dump_prefix_list(struct interface_ip_settings *ip)
602 {
603 struct device_prefix *prefix;
604 char *buf;
605 void *a, *c;
606 const int buflen = INET6_ADDRSTRLEN;
607
608 time_t now = system_get_rtime();
609 vlist_for_each_element(&ip->prefix, prefix, node) {
610 a = blobmsg_open_table(&b, NULL);
611
612 buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
613 inet_ntop(AF_INET6, &prefix->addr, buf, buflen);
614 blobmsg_add_string_buffer(&b);
615
616 blobmsg_add_u32(&b, "mask", prefix->length);
617
618 if (prefix->preferred_until) {
619 int preferred = prefix->preferred_until - now;
620 if (preferred < 0)
621 preferred = 0;
622 blobmsg_add_u32(&b, "preferred", preferred);
623 }
624
625 if (prefix->valid_until)
626 blobmsg_add_u32(&b, "valid", prefix->valid_until - now);
627
628 blobmsg_add_string(&b, "class", prefix->pclass);
629
630 c = blobmsg_open_table(&b, "assigned");
631 struct device_prefix_assignment *assign;
632 list_for_each_entry(assign, &prefix->assignments, head) {
633 if (!assign->name[0])
634 continue;
635
636 struct in6_addr addr = prefix->addr;
637 addr.s6_addr32[1] |= htonl(assign->assigned);
638
639 void *d = blobmsg_open_table(&b, assign->name);
640
641 buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
642 inet_ntop(AF_INET6, &addr, buf, buflen);
643 blobmsg_add_string_buffer(&b);
644
645 blobmsg_add_u32(&b, "mask", assign->length);
646
647 blobmsg_close_table(&b, d);
648 }
649 blobmsg_close_table(&b, c);
650
651 blobmsg_close_table(&b, a);
652 }
653 }
654
655
656 static void
657 interface_ip_dump_prefix_assignment_list(struct interface *iface)
658 {
659 void *a;
660 char *buf;
661 const int buflen = INET6_ADDRSTRLEN;
662 time_t now = system_get_rtime();
663
664 struct device_prefix *prefix;
665 list_for_each_entry(prefix, &prefixes, head) {
666 struct device_prefix_assignment *assign;
667 list_for_each_entry(assign, &prefix->assignments, head) {
668 if (strcmp(assign->name, iface->name))
669 continue;
670
671 struct in6_addr addr = prefix->addr;
672 addr.s6_addr32[1] |= htonl(assign->assigned);
673
674 a = blobmsg_open_table(&b, NULL);
675
676 buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
677 inet_ntop(AF_INET6, &addr, buf, buflen);
678 blobmsg_add_string_buffer(&b);
679
680 blobmsg_add_u32(&b, "mask", assign->length);
681
682 if (prefix->preferred_until) {
683 int preferred = prefix->preferred_until - now;
684 if (preferred < 0)
685 preferred = 0;
686 blobmsg_add_u32(&b, "preferred", preferred);
687 }
688
689 if (prefix->valid_until)
690 blobmsg_add_u32(&b, "valid", prefix->valid_until - now);
691
692 void *c = blobmsg_open_table(&b, "local-address");
693 if (assign->enabled) {
694 buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
695 inet_ntop(AF_INET6, &assign->addr, buf, buflen);
696 blobmsg_add_string_buffer(&b);
697
698 blobmsg_add_u32(&b, "mask", assign->length);
699 }
700 blobmsg_close_table(&b, c);
701
702 blobmsg_close_table(&b, a);
703 }
704 }
705 }
706
707 static void
708 interface_ip_dump_dns_server_list(struct interface_ip_settings *ip, bool enabled)
709 {
710 struct dns_server *dns;
711 int buflen = 128;
712 char *buf;
713
714 vlist_simple_for_each_element(&ip->dns_servers, dns, node) {
715 if (ip->no_dns == enabled)
716 continue;
717
718 buf = blobmsg_alloc_string_buffer(&b, NULL, buflen);
719 inet_ntop(dns->af, &dns->addr, buf, buflen);
720 blobmsg_add_string_buffer(&b);
721 }
722 }
723
724 static void
725 interface_ip_dump_dns_search_list(struct interface_ip_settings *ip, bool enabled)
726 {
727 struct dns_search_domain *dns;
728
729 vlist_simple_for_each_element(&ip->dns_search, dns, node) {
730 if (ip->no_dns == enabled)
731 continue;
732
733 blobmsg_add_string(&b, NULL, dns->name);
734 }
735 }
736
737 static void
738 netifd_dump_status(struct interface *iface)
739 {
740 struct interface_data *data;
741 struct device *dev;
742 void *a, *inactive;
743
744 blobmsg_add_u8(&b, "up", iface->state == IFS_UP);
745 blobmsg_add_u8(&b, "pending", iface->state == IFS_SETUP);
746 blobmsg_add_u8(&b, "available", iface->available);
747 blobmsg_add_u8(&b, "autostart", iface->autostart);
748 blobmsg_add_u8(&b, "dynamic", iface->dynamic);
749
750 if (iface->state == IFS_UP) {
751 time_t cur = system_get_rtime();
752 blobmsg_add_u32(&b, "uptime", cur - iface->start_time);
753 if (iface->l3_dev.dev)
754 blobmsg_add_string(&b, "l3_device", iface->l3_dev.dev->ifname);
755 }
756
757 if (iface->proto_handler)
758 blobmsg_add_string(&b, "proto", iface->proto_handler->name);
759
760 dev = iface->main_dev.dev;
761 if (dev && !dev->hidden && iface->proto_handler &&
762 !(iface->proto_handler->flags & PROTO_FLAG_NODEV))
763 blobmsg_add_string(&b, "device", dev->ifname);
764
765 if (iface->jail)
766 blobmsg_add_string(&b, "jail", iface->jail);
767
768 if (iface->jail_ifname)
769 blobmsg_add_string(&b, "jail_ifname", iface->jail_ifname);
770
771 if (iface->state == IFS_UP) {
772 if (iface->updated) {
773 a = blobmsg_open_array(&b, "updated");
774
775 if (iface->updated & IUF_ADDRESS)
776 blobmsg_add_string(&b, NULL, "addresses");
777 if (iface->updated & IUF_ROUTE)
778 blobmsg_add_string(&b, NULL, "routes");
779 if (iface->updated & IUF_PREFIX)
780 blobmsg_add_string(&b, NULL, "prefixes");
781 if (iface->updated & IUF_DATA)
782 blobmsg_add_string(&b, NULL, "data");
783
784 blobmsg_close_array(&b, a);
785 }
786
787 if (iface->ip4table)
788 blobmsg_add_u32(&b, "ip4table", iface->ip4table);
789 if (iface->ip6table)
790 blobmsg_add_u32(&b, "ip6table", iface->ip6table);
791 blobmsg_add_u32(&b, "metric", iface->metric);
792 blobmsg_add_u32(&b, "dns_metric", iface->dns_metric);
793 blobmsg_add_u8(&b, "delegation", !iface->proto_ip.no_delegation);
794 if (iface->assignment_weight)
795 blobmsg_add_u32(&b, "ip6weight", iface->assignment_weight);
796 a = blobmsg_open_array(&b, "ipv4-address");
797 interface_ip_dump_address_list(&iface->config_ip, false, true);
798 interface_ip_dump_address_list(&iface->proto_ip, false, true);
799 blobmsg_close_array(&b, a);
800 a = blobmsg_open_array(&b, "ipv6-address");
801 interface_ip_dump_address_list(&iface->config_ip, true, true);
802 interface_ip_dump_address_list(&iface->proto_ip, true, true);
803 blobmsg_close_array(&b, a);
804 a = blobmsg_open_array(&b, "ipv6-prefix");
805 interface_ip_dump_prefix_list(&iface->config_ip);
806 interface_ip_dump_prefix_list(&iface->proto_ip);
807 blobmsg_close_array(&b, a);
808 a = blobmsg_open_array(&b, "ipv6-prefix-assignment");
809 interface_ip_dump_prefix_assignment_list(iface);
810 blobmsg_close_array(&b, a);
811 a = blobmsg_open_array(&b, "route");
812 interface_ip_dump_route_list(&iface->config_ip, true);
813 interface_ip_dump_route_list(&iface->proto_ip, true);
814 blobmsg_close_array(&b, a);
815 a = blobmsg_open_array(&b, "dns-server");
816 interface_ip_dump_dns_server_list(&iface->config_ip, true);
817 interface_ip_dump_dns_server_list(&iface->proto_ip, true);
818 blobmsg_close_array(&b, a);
819 a = blobmsg_open_array(&b, "dns-search");
820 interface_ip_dump_dns_search_list(&iface->config_ip, true);
821 interface_ip_dump_dns_search_list(&iface->proto_ip, true);
822 blobmsg_close_array(&b, a);
823 a = blobmsg_open_array(&b, "neighbors");
824 interface_ip_dump_neighbor_list(&iface->config_ip, true);
825 interface_ip_dump_neighbor_list(&iface->proto_ip, true);
826 blobmsg_close_array(&b, a);
827
828 inactive = blobmsg_open_table(&b, "inactive");
829 a = blobmsg_open_array(&b, "ipv4-address");
830 interface_ip_dump_address_list(&iface->config_ip, false, false);
831 interface_ip_dump_address_list(&iface->proto_ip, false, false);
832 blobmsg_close_array(&b, a);
833 a = blobmsg_open_array(&b, "ipv6-address");
834 interface_ip_dump_address_list(&iface->config_ip, true, false);
835 interface_ip_dump_address_list(&iface->proto_ip, true, false);
836 blobmsg_close_array(&b, a);
837 a = blobmsg_open_array(&b, "route");
838 interface_ip_dump_route_list(&iface->config_ip, false);
839 interface_ip_dump_route_list(&iface->proto_ip, false);
840 blobmsg_close_array(&b, a);
841 a = blobmsg_open_array(&b, "dns-server");
842 interface_ip_dump_dns_server_list(&iface->config_ip, false);
843 interface_ip_dump_dns_server_list(&iface->proto_ip, false);
844 blobmsg_close_array(&b, a);
845 a = blobmsg_open_array(&b, "dns-search");
846 interface_ip_dump_dns_search_list(&iface->config_ip, false);
847 interface_ip_dump_dns_search_list(&iface->proto_ip, false);
848 blobmsg_close_array(&b, a);
849 a = blobmsg_open_array(&b, "neighbors");
850 interface_ip_dump_neighbor_list(&iface->config_ip, false);
851 interface_ip_dump_neighbor_list(&iface->proto_ip, false);
852 blobmsg_close_array(&b, a);
853 blobmsg_close_table(&b, inactive);
854 }
855
856 a = blobmsg_open_table(&b, "data");
857 avl_for_each_element(&iface->data, data, node)
858 blobmsg_add_blob(&b, data->data);
859
860 blobmsg_close_table(&b, a);
861
862 if (!list_empty(&iface->errors))
863 netifd_add_interface_errors(&b, iface);
864 }
865
866 static int
867 netifd_handle_status(struct ubus_context *ctx, struct ubus_object *obj,
868 struct ubus_request_data *req, const char *method,
869 struct blob_attr *msg)
870 {
871 struct interface *iface = container_of(obj, struct interface, ubus);
872
873 blob_buf_init(&b, 0);
874 netifd_dump_status(iface);
875 ubus_send_reply(ctx, req, b.head);
876
877 return 0;
878 }
879
880
881 static int
882 netifd_handle_dump(struct ubus_context *ctx, struct ubus_object *obj,
883 struct ubus_request_data *req, const char *method,
884 struct blob_attr *msg)
885 {
886 blob_buf_init(&b, 0);
887 void *a = blobmsg_open_array(&b, "interface");
888
889 struct interface *iface;
890 vlist_for_each_element(&interfaces, iface, node) {
891 void *i = blobmsg_open_table(&b, NULL);
892 blobmsg_add_string(&b, "interface", iface->name);
893 netifd_dump_status(iface);
894 blobmsg_close_table(&b, i);
895 }
896
897 blobmsg_close_array(&b, a);
898 ubus_send_reply(ctx, req, b.head);
899
900 return 0;
901 }
902
903 enum {
904 DEV_LINK_NAME,
905 DEV_LINK_EXT,
906 DEV_LINK_VLAN,
907 __DEV_LINK_MAX,
908 };
909
910 static const struct blobmsg_policy dev_link_policy[__DEV_LINK_MAX] = {
911 [DEV_LINK_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
912 [DEV_LINK_EXT] = { .name = "link-ext", .type = BLOBMSG_TYPE_BOOL },
913 [DEV_LINK_VLAN] = { .name = "vlan", .type = BLOBMSG_TYPE_ARRAY },
914 };
915
916 static int
917 netifd_iface_handle_device(struct ubus_context *ctx, struct ubus_object *obj,
918 struct ubus_request_data *req, const char *method,
919 struct blob_attr *msg)
920 {
921 struct blob_attr *tb[__DEV_LINK_MAX];
922 struct blob_attr *cur;
923 struct interface *iface;
924 bool add = !strncmp(method, "add", 3);
925 bool link_ext = true;
926
927 iface = container_of(obj, struct interface, ubus);
928
929 blobmsg_parse(dev_link_policy, __DEV_LINK_MAX, tb, blob_data(msg), blob_len(msg));
930
931 if (!tb[DEV_LINK_NAME])
932 return UBUS_STATUS_INVALID_ARGUMENT;
933
934 cur = tb[DEV_LINK_EXT];
935 if (cur)
936 link_ext = blobmsg_get_bool(cur);
937
938 return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]),
939 tb[DEV_LINK_VLAN], add, link_ext);
940 }
941
942
943 static int
944 netifd_iface_notify_proto(struct ubus_context *ctx, struct ubus_object *obj,
945 struct ubus_request_data *req, const char *method,
946 struct blob_attr *msg)
947 {
948 struct interface *iface;
949
950 iface = container_of(obj, struct interface, ubus);
951
952 if (!iface->proto || !iface->proto->notify)
953 return UBUS_STATUS_NOT_SUPPORTED;
954
955 return iface->proto->notify(iface->proto, msg);
956 }
957
958 static void
959 netifd_iface_do_remove(struct uloop_timeout *timeout)
960 {
961 struct interface *iface;
962
963 iface = container_of(timeout, struct interface, remove_timer);
964 vlist_delete(&interfaces, &iface->node);
965 }
966
967 static int
968 netifd_iface_remove(struct ubus_context *ctx, struct ubus_object *obj,
969 struct ubus_request_data *req, const char *method,
970 struct blob_attr *msg)
971 {
972 struct interface *iface;
973
974 iface = container_of(obj, struct interface, ubus);
975 if (iface->remove_timer.cb)
976 return UBUS_STATUS_INVALID_ARGUMENT;
977
978 iface->remove_timer.cb = netifd_iface_do_remove;
979 uloop_timeout_set(&iface->remove_timer, 100);
980 return 0;
981 }
982
983 static int
984 netifd_handle_iface_prepare(struct ubus_context *ctx, struct ubus_object *obj,
985 struct ubus_request_data *req, const char *method,
986 struct blob_attr *msg)
987 {
988 struct interface *iface;
989 struct device *dev, *bridge_dev = NULL;
990 const struct device_hotplug_ops *ops;
991
992 iface = container_of(obj, struct interface, ubus);
993 dev = iface->main_dev.dev;
994 if (!dev)
995 goto out;
996
997 ops = dev->hotplug_ops;
998 if (!ops)
999 goto out;
1000
1001 ops->prepare(dev, &bridge_dev);
1002
1003 out:
1004 blob_buf_init(&b, 0);
1005 if (bridge_dev)
1006 blobmsg_add_string(&b, "bridge", bridge_dev->ifname);
1007 ubus_send_reply(ctx, req, b.head);
1008
1009 return 0;
1010 }
1011
1012 static int
1013 netifd_handle_set_data(struct ubus_context *ctx, struct ubus_object *obj,
1014 struct ubus_request_data *req, const char *method,
1015 struct blob_attr *msg)
1016 {
1017 struct interface *iface;
1018
1019 iface = container_of(obj, struct interface, ubus);
1020
1021 return interface_parse_data(iface, msg);
1022 }
1023
1024 static struct ubus_method iface_object_methods[] = {
1025 { .name = "up", .handler = netifd_handle_up },
1026 { .name = "down", .handler = netifd_handle_down },
1027 { .name = "renew", .handler = netifd_handle_renew },
1028 { .name = "status", .handler = netifd_handle_status },
1029 { .name = "prepare", .handler = netifd_handle_iface_prepare },
1030 { .name = "dump", .handler = netifd_handle_dump },
1031 UBUS_METHOD("add_device", netifd_iface_handle_device, dev_link_policy ),
1032 UBUS_METHOD("remove_device", netifd_iface_handle_device, dev_link_policy ),
1033 { .name = "notify_proto", .handler = netifd_iface_notify_proto },
1034 { .name = "remove", .handler = netifd_iface_remove },
1035 { .name = "set_data", .handler = netifd_handle_set_data },
1036 };
1037
1038 static struct ubus_object_type iface_object_type =
1039 UBUS_OBJECT_TYPE("netifd_iface", iface_object_methods);
1040
1041
1042 static struct ubus_object iface_object = {
1043 .name = "network.interface",
1044 .type = &iface_object_type,
1045 .n_methods = ARRAY_SIZE(iface_object_methods),
1046 };
1047
1048 static void netifd_add_object(struct ubus_object *obj)
1049 {
1050 int ret = ubus_add_object(ubus_ctx, obj);
1051
1052 if (ret != 0)
1053 fprintf(stderr, "Failed to publish object '%s': %s\n", obj->name, ubus_strerror(ret));
1054 }
1055
1056 static const struct blobmsg_policy iface_policy = {
1057 .name = "interface",
1058 .type = BLOBMSG_TYPE_STRING,
1059 };
1060
1061 static int
1062 netifd_handle_iface(struct ubus_context *ctx, struct ubus_object *obj,
1063 struct ubus_request_data *req, const char *method,
1064 struct blob_attr *msg)
1065 {
1066 struct interface *iface;
1067 struct blob_attr *tb;
1068 int i;
1069
1070 blobmsg_parse(&iface_policy, 1, &tb, blob_data(msg), blob_len(msg));
1071 if (!tb)
1072 return UBUS_STATUS_INVALID_ARGUMENT;
1073
1074 iface = vlist_find(&interfaces, blobmsg_data(tb), iface, node);
1075 if (!iface)
1076 return UBUS_STATUS_NOT_FOUND;
1077
1078 for (i = 0; i < ARRAY_SIZE(iface_object_methods); i++) {
1079 ubus_handler_t cb;
1080
1081 if (strcmp(method, iface_object_methods[i].name) != 0)
1082 continue;
1083
1084 cb = iface_object_methods[i].handler;
1085 return cb(ctx, &iface->ubus, req, method, msg);
1086 }
1087
1088 return UBUS_STATUS_INVALID_ARGUMENT;
1089 }
1090
1091 static void netifd_add_iface_object(void)
1092 {
1093 struct ubus_method *methods;
1094 int i;
1095
1096 methods = calloc(1, sizeof(iface_object_methods));
1097 if (!methods)
1098 return;
1099
1100 memcpy(methods, iface_object_methods, sizeof(iface_object_methods));
1101 iface_object.methods = methods;
1102
1103 for (i = 0; i < ARRAY_SIZE(iface_object_methods); i++) {
1104 if (methods[i].handler == netifd_handle_dump)
1105 continue;
1106
1107 methods[i].handler = netifd_handle_iface;
1108 methods[i].policy = &iface_policy;
1109 methods[i].n_policy = 1;
1110 }
1111 netifd_add_object(&iface_object);
1112 }
1113
1114 static struct wireless_device *
1115 get_wdev(struct blob_attr *msg, int *ret)
1116 {
1117 struct blobmsg_policy wdev_policy = {
1118 .name = "device",
1119 .type = BLOBMSG_TYPE_STRING,
1120 };
1121 struct blob_attr *dev_attr;
1122 struct wireless_device *wdev = NULL;
1123
1124
1125 blobmsg_parse(&wdev_policy, 1, &dev_attr, blob_data(msg), blob_len(msg));
1126 if (!dev_attr) {
1127 *ret = UBUS_STATUS_INVALID_ARGUMENT;
1128 return NULL;
1129 }
1130
1131 wdev = vlist_find(&wireless_devices, blobmsg_data(dev_attr), wdev, node);
1132 if (!wdev) {
1133 *ret = UBUS_STATUS_NOT_FOUND;
1134 return NULL;
1135 }
1136
1137 *ret = 0;
1138 return wdev;
1139 }
1140
1141 static int
1142 netifd_handle_wdev_reconf(struct ubus_context *ctx, struct ubus_object *obj,
1143 struct ubus_request_data *req, const char *method,
1144 struct blob_attr *msg)
1145 {
1146 struct wireless_device *wdev;
1147 int ret;
1148
1149 wdev = get_wdev(msg, &ret);
1150 if (ret == UBUS_STATUS_NOT_FOUND)
1151 return ret;
1152
1153 if (wdev) {
1154 wireless_device_reconf(wdev);
1155 } else {
1156 vlist_for_each_element(&wireless_devices, wdev, node)
1157 wireless_device_reconf(wdev);
1158 }
1159
1160 return 0;
1161 }
1162
1163 static int
1164 netifd_handle_wdev_up(struct ubus_context *ctx, struct ubus_object *obj,
1165 struct ubus_request_data *req, const char *method,
1166 struct blob_attr *msg)
1167 {
1168 struct wireless_device *wdev;
1169 int ret;
1170
1171 wdev = get_wdev(msg, &ret);
1172 if (ret == UBUS_STATUS_NOT_FOUND)
1173 return ret;
1174
1175 if (wdev) {
1176 wireless_device_set_up(wdev);
1177 } else {
1178 vlist_for_each_element(&wireless_devices, wdev, node)
1179 wireless_device_set_up(wdev);
1180 }
1181
1182 return 0;
1183 }
1184
1185 static int
1186 netifd_handle_wdev_down(struct ubus_context *ctx, struct ubus_object *obj,
1187 struct ubus_request_data *req, const char *method,
1188 struct blob_attr *msg)
1189 {
1190 struct wireless_device *wdev;
1191 int ret;
1192
1193 wdev = get_wdev(msg, &ret);
1194 if (ret == UBUS_STATUS_NOT_FOUND)
1195 return ret;
1196
1197 if (wdev) {
1198 wireless_device_set_down(wdev);
1199 } else {
1200 vlist_for_each_element(&wireless_devices, wdev, node)
1201 wireless_device_set_down(wdev);
1202 }
1203
1204 return 0;
1205 }
1206
1207 static int
1208 netifd_handle_wdev_status(struct ubus_context *ctx, struct ubus_object *obj,
1209 struct ubus_request_data *req, const char *method,
1210 struct blob_attr *msg)
1211 {
1212 struct wireless_device *wdev;
1213 int ret;
1214
1215 wdev = get_wdev(msg, &ret);
1216 if (ret == UBUS_STATUS_NOT_FOUND)
1217 return ret;
1218
1219 blob_buf_init(&b, 0);
1220 if (wdev) {
1221 wireless_device_status(wdev, &b);
1222 } else {
1223 vlist_for_each_element(&wireless_devices, wdev, node)
1224 wireless_device_status(wdev, &b);
1225 }
1226 ubus_send_reply(ctx, req, b.head);
1227 return 0;
1228 }
1229
1230 static int
1231 netifd_handle_wdev_get_validate(struct ubus_context *ctx, struct ubus_object *obj,
1232 struct ubus_request_data *req, const char *method,
1233 struct blob_attr *msg)
1234 {
1235 struct wireless_device *wdev;
1236 int ret;
1237
1238 wdev = get_wdev(msg, &ret);
1239 if (ret == UBUS_STATUS_NOT_FOUND)
1240 return ret;
1241
1242 blob_buf_init(&b, 0);
1243 if (wdev) {
1244 wireless_device_get_validate(wdev, &b);
1245 } else {
1246 vlist_for_each_element(&wireless_devices, wdev, node)
1247 wireless_device_get_validate(wdev, &b);
1248 }
1249 ubus_send_reply(ctx, req, b.head);
1250 return 0;
1251 }
1252
1253 static int
1254 netifd_handle_wdev_notify(struct ubus_context *ctx, struct ubus_object *obj,
1255 struct ubus_request_data *req, const char *method,
1256 struct blob_attr *msg)
1257 {
1258 struct wireless_device *wdev;
1259 int ret;
1260
1261 wdev = get_wdev(msg, &ret);
1262 if (!wdev)
1263 return ret;
1264
1265 return wireless_device_notify(wdev, msg, req);
1266 }
1267
1268 static struct ubus_method wireless_object_methods[] = {
1269 { .name = "up", .handler = netifd_handle_wdev_up },
1270 { .name = "down", .handler = netifd_handle_wdev_down },
1271 { .name = "reconf", .handler = netifd_handle_wdev_reconf },
1272 { .name = "status", .handler = netifd_handle_wdev_status },
1273 { .name = "notify", .handler = netifd_handle_wdev_notify },
1274 { .name = "get_validate", .handler = netifd_handle_wdev_get_validate },
1275 };
1276
1277 static struct ubus_object_type wireless_object_type =
1278 UBUS_OBJECT_TYPE("netifd_iface", wireless_object_methods);
1279
1280
1281 static struct ubus_object wireless_object = {
1282 .name = "network.wireless",
1283 .type = &wireless_object_type,
1284 .methods = wireless_object_methods,
1285 .n_methods = ARRAY_SIZE(wireless_object_methods),
1286 };
1287
1288 int
1289 netifd_ubus_init(const char *path)
1290 {
1291 uloop_init();
1292 ubus_path = path;
1293
1294 ubus_ctx = ubus_connect(path);
1295 if (!ubus_ctx)
1296 return -EIO;
1297
1298 DPRINTF("connected as %08x\n", ubus_ctx->local_id);
1299 ubus_ctx->connection_lost = netifd_ubus_connection_lost;
1300 netifd_ubus_add_fd();
1301
1302 netifd_add_object(&main_object);
1303 netifd_add_object(&dev_object);
1304 netifd_add_object(&wireless_object);
1305 netifd_add_iface_object();
1306
1307 return 0;
1308 }
1309
1310 void
1311 netifd_ubus_done(void)
1312 {
1313 ubus_free(ubus_ctx);
1314 }
1315
1316 void
1317 netifd_ubus_interface_event(struct interface *iface, bool up)
1318 {
1319 blob_buf_init(&b, 0);
1320 blobmsg_add_string(&b, "action", up ? "ifup" : "ifdown");
1321 blobmsg_add_string(&b, "interface", iface->name);
1322 ubus_send_event(ubus_ctx, "network.interface", b.head);
1323 }
1324
1325 void
1326 netifd_ubus_interface_notify(struct interface *iface, bool up)
1327 {
1328 const char *event = (up) ? "interface.update" : "interface.down";
1329 blob_buf_init(&b, 0);
1330 blobmsg_add_string(&b, "interface", iface->name);
1331 netifd_dump_status(iface);
1332 ubus_notify(ubus_ctx, &iface_object, event, b.head, -1);
1333 ubus_notify(ubus_ctx, &iface->ubus, event, b.head, -1);
1334 }
1335
1336 void
1337 netifd_ubus_add_interface(struct interface *iface)
1338 {
1339 struct ubus_object *obj = &iface->ubus;
1340 char *name = NULL;
1341
1342 if (asprintf(&name, "%s.interface.%s", main_object.name, iface->name) == -1)
1343 return;
1344
1345 obj->name = name;
1346 obj->type = &iface_object_type;
1347 obj->methods = iface_object_methods;
1348 obj->n_methods = ARRAY_SIZE(iface_object_methods);
1349 if (ubus_add_object(ubus_ctx, &iface->ubus)) {
1350 DPRINTF("failed to publish ubus object for interface '%s'\n", iface->name);
1351 free(name);
1352 obj->name = NULL;
1353 }
1354 }
1355
1356 void
1357 netifd_ubus_remove_interface(struct interface *iface)
1358 {
1359 if (!iface->ubus.name)
1360 return;
1361
1362 ubus_remove_object(ubus_ctx, &iface->ubus);
1363 free((void *) iface->ubus.name);
1364 }