sta-info: add last_connected field
[project/usteer.git] / remote.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
18 */
19
20 #define _GNU_SOURCE
21
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <net/if.h>
26 #include <arpa/inet.h>
27 #include <errno.h>
28 #include <unistd.h>
29
30 #include <libubox/vlist.h>
31 #include <libubox/avl-cmp.h>
32 #include <libubox/usock.h>
33 #include "usteer.h"
34 #include "remote.h"
35 #include "node.h"
36
37 static uint32_t local_id;
38 static struct uloop_fd remote_fd;
39 static struct uloop_timeout remote_timer;
40 static struct uloop_timeout reload_timer;
41
42 static struct blob_buf buf;
43 static uint32_t msg_seq;
44
45 struct interface {
46 struct vlist_node node;
47 int ifindex;
48 };
49
50 static void
51 interfaces_update_cb(struct vlist_tree *tree,
52 struct vlist_node *node_new,
53 struct vlist_node *node_old);
54
55 static int remote_host_cmp(const void *k1, const void *k2, void *ptr)
56 {
57 unsigned long v1 = (unsigned long) k1;
58 unsigned long v2 = (unsigned long) k2;
59
60 return v2 - v1;
61 }
62
63 static VLIST_TREE(interfaces, avl_strcmp, interfaces_update_cb, true, true);
64 LIST_HEAD(remote_nodes);
65 AVL_TREE(remote_hosts, remote_host_cmp, false, NULL);
66
67 static const char *
68 interface_name(struct interface *iface)
69 {
70 return iface->node.avl.key;
71 }
72
73 static void
74 interface_check(struct interface *iface)
75 {
76 iface->ifindex = if_nametoindex(interface_name(iface));
77 uloop_timeout_set(&reload_timer, 1);
78 }
79
80 static void
81 interface_init(struct interface *iface)
82 {
83 interface_check(iface);
84 }
85
86 static void
87 interface_free(struct interface *iface)
88 {
89 avl_delete(&interfaces.avl, &iface->node.avl);
90 free(iface);
91 }
92
93 static void
94 interfaces_update_cb(struct vlist_tree *tree,
95 struct vlist_node *node_new,
96 struct vlist_node *node_old)
97 {
98 struct interface *iface;
99
100 if (node_new && node_old) {
101 iface = container_of(node_new, struct interface, node);
102 free(iface);
103 iface = container_of(node_old, struct interface, node);
104 interface_check(iface);
105 } else if (node_old) {
106 iface = container_of(node_old, struct interface, node);
107 interface_free(iface);
108 } else {
109 iface = container_of(node_new, struct interface, node);
110 interface_init(iface);
111 }
112 }
113
114 void usteer_interface_add(const char *name)
115 {
116 struct interface *iface;
117 char *name_buf;
118
119 iface = calloc_a(sizeof(*iface), &name_buf, strlen(name) + 1);
120 strcpy(name_buf, name);
121 vlist_add(&interfaces, &iface->node, name_buf);
122 }
123
124 void config_set_interfaces(struct blob_attr *data)
125 {
126 struct blob_attr *cur;
127 int rem;
128
129 if (!data)
130 return;
131
132 if (!blobmsg_check_attr_list(data, BLOBMSG_TYPE_STRING))
133 return;
134
135 vlist_update(&interfaces);
136 blobmsg_for_each_attr(cur, data, rem) {
137 usteer_interface_add(blobmsg_data(cur));
138 }
139 vlist_flush(&interfaces);
140 }
141
142 void config_get_interfaces(struct blob_buf *buf)
143 {
144 struct interface *iface;
145 void *c;
146
147 c = blobmsg_open_array(buf, "interfaces");
148 vlist_for_each_element(&interfaces, iface, node) {
149 blobmsg_add_string(buf, NULL, interface_name(iface));
150 }
151 blobmsg_close_array(buf, c);
152 }
153
154 static void
155 interface_add_station(struct usteer_remote_node *node, struct blob_attr *data)
156 {
157 struct sta *sta;
158 struct sta_info *si;
159 struct apmsg_sta msg;
160 bool create;
161
162 if (!parse_apmsg_sta(&msg, data)) {
163 MSG(DEBUG, "Cannot parse station in message\n");
164 return;
165 }
166
167 if (msg.timeout <= 0) {
168 MSG(DEBUG, "Refuse to add an already expired station entry\n");
169 return;
170 }
171
172 sta = usteer_sta_get(msg.addr, true);
173 if (!sta)
174 return;
175
176 si = usteer_sta_info_get(sta, &node->node, &create);
177 if (!si)
178 return;
179
180 si->connected = msg.connected;
181 si->signal = msg.signal;
182 si->seen = current_time - msg.seen;
183 si->last_connected = current_time - msg.last_connected;
184 usteer_sta_info_update_timeout(si, msg.timeout);
185 }
186
187 static void
188 remote_node_free(struct usteer_remote_node *node)
189 {
190 struct usteer_remote_host *host = node->host;
191
192 list_del(&node->list);
193 list_del(&node->host_list);
194 usteer_sta_node_cleanup(&node->node);
195 free(node);
196
197 if (!list_empty(&host->nodes))
198 return;
199
200 avl_delete(&remote_hosts, &host->avl);
201 free(host->addr);
202 free(host);
203 }
204
205 static struct usteer_remote_host *
206 interface_get_host(const char *addr, unsigned long id)
207 {
208 struct usteer_remote_host *host;
209
210 host = avl_find_element(&remote_hosts, (void *)id, host, avl);
211 if (host)
212 goto out;
213
214 host = calloc(1, sizeof(*host));
215 host->avl.key = (void *)id;
216 INIT_LIST_HEAD(&host->nodes);
217 avl_insert(&remote_hosts, &host->avl);
218
219 out:
220 if (host->addr && !strcmp(host->addr, addr))
221 return host;
222
223 free(host->addr);
224 host->addr = strdup(addr);
225
226 return host;
227 }
228
229 static struct usteer_remote_node *
230 interface_get_node(struct usteer_remote_host *host, const char *name)
231 {
232 struct usteer_remote_node *node;
233 int addr_len = strlen(host->addr);
234 char *buf;
235
236 list_for_each_entry(node, &host->nodes, host_list)
237 if (!strcmp(node->name, name))
238 return node;
239
240 node = calloc_a(sizeof(*node), &buf, addr_len + 1 + strlen(name) + 1);
241 node->node.type = NODE_TYPE_REMOTE;
242
243 sprintf(buf, "%s#%s", host->addr, name);
244 node->node.avl.key = buf;
245 node->name = buf + addr_len + 1;
246 node->host = host;
247 INIT_LIST_HEAD(&node->node.sta_info);
248
249 list_add_tail(&node->list, &remote_nodes);
250 list_add_tail(&node->host_list, &host->nodes);
251
252 return node;
253 }
254
255 static void
256 interface_add_node(struct usteer_remote_host *host, struct blob_attr *data)
257 {
258 struct usteer_remote_node *node;
259 struct apmsg_node msg;
260 struct blob_attr *cur;
261 int rem;
262
263 if (!parse_apmsg_node(&msg, data)) {
264 MSG(DEBUG, "Cannot parse node in message\n");
265 return;
266 }
267
268 node = interface_get_node(host, msg.name);
269 node->check = 0;
270 node->node.freq = msg.freq;
271 node->node.n_assoc = msg.n_assoc;
272 node->node.max_assoc = msg.max_assoc;
273 node->node.noise = msg.noise;
274 node->node.load = msg.load;
275
276 memcpy(node->node.bssid, msg.bssid, sizeof(node->node.bssid));
277
278 snprintf(node->node.ssid, sizeof(node->node.ssid), "%s", msg.ssid);
279 usteer_node_set_blob(&node->node.rrm_nr, msg.rrm_nr);
280 usteer_node_set_blob(&node->node.node_info, msg.node_info);
281
282 blob_for_each_attr(cur, msg.stations, rem)
283 interface_add_station(node, cur);
284 }
285
286 static void
287 interface_recv_msg(struct interface *iface, char *addr_str, void *buf, int len)
288 {
289 struct usteer_remote_host *host;
290 struct blob_attr *data = buf;
291 struct apmsg msg;
292 struct blob_attr *cur;
293 int rem;
294
295 if (blob_pad_len(data) != len) {
296 MSG(DEBUG, "Invalid message length (header: %d, real: %d)\n", blob_pad_len(data), len);
297 return;
298 }
299
300 if (!parse_apmsg(&msg, data)) {
301 MSG(DEBUG, "Missing fields in message\n");
302 return;
303 }
304
305 if (msg.id == local_id)
306 return;
307
308 MSG(NETWORK, "Received message on %s (id=%08x->%08x seq=%d len=%d)\n",
309 interface_name(iface), msg.id, local_id, msg.seq, len);
310
311 host = interface_get_host(addr_str, msg.id);
312 usteer_node_set_blob(&host->host_info, msg.host_info);
313
314 blob_for_each_attr(cur, msg.nodes, rem)
315 interface_add_node(host, cur);
316 }
317
318 static struct interface *
319 interface_find_by_ifindex(int index)
320 {
321 struct interface *iface;
322
323 vlist_for_each_element(&interfaces, iface, node) {
324 if (iface->ifindex == index)
325 return iface;
326 }
327
328 return NULL;
329 }
330
331 static void
332 interface_recv_v4(struct uloop_fd *u, unsigned int events)
333 {
334 static char buf[APMGR_BUFLEN];
335 static char cmsg_buf[( CMSG_SPACE(sizeof(struct in_pktinfo)) + sizeof(int)) + 1];
336 static struct sockaddr_in sin;
337 char addr_str[INET_ADDRSTRLEN];
338 static struct iovec iov = {
339 .iov_base = buf,
340 .iov_len = sizeof(buf)
341 };
342 static struct msghdr msg = {
343 .msg_name = &sin,
344 .msg_namelen = sizeof(sin),
345 .msg_iov = &iov,
346 .msg_iovlen = 1,
347 .msg_control = cmsg_buf,
348 .msg_controllen = sizeof(cmsg_buf),
349 };
350 struct cmsghdr *cmsg;
351 int len;
352
353 do {
354 struct in_pktinfo *pkti = NULL;
355 struct interface *iface;
356
357 len = recvmsg(u->fd, &msg, 0);
358 if (len < 0) {
359 switch (errno) {
360 case EAGAIN:
361 return;
362 case EINTR:
363 continue;
364 default:
365 perror("recvmsg");
366 uloop_fd_delete(u);
367 return;
368 }
369 }
370
371 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
372 if (cmsg->cmsg_type != IP_PKTINFO)
373 continue;
374
375 pkti = (struct in_pktinfo *) CMSG_DATA(cmsg);
376 }
377
378 if (!pkti) {
379 MSG(DEBUG, "Received packet without ifindex\n");
380 continue;
381 }
382
383 iface = interface_find_by_ifindex(pkti->ipi_ifindex);
384 if (!iface) {
385 MSG(DEBUG, "Received packet from unconfigured interface %d\n", pkti->ipi_ifindex);
386 continue;
387 }
388
389 inet_ntop(AF_INET, &sin.sin_addr, addr_str, sizeof(addr_str));
390
391 interface_recv_msg(iface, addr_str, buf, len);
392 } while (1);
393 }
394
395
396 static void interface_recv_v6(struct uloop_fd *u, unsigned int events){
397 static char buf[APMGR_BUFLEN];
398 static char cmsg_buf[( CMSG_SPACE(sizeof(struct in6_pktinfo)) + sizeof(int)) + 1];
399 static struct sockaddr_in6 sin;
400 static struct iovec iov = {
401 .iov_base = buf,
402 .iov_len = sizeof(buf)
403 };
404 static struct msghdr msg = {
405 .msg_name = &sin,
406 .msg_namelen = sizeof(sin),
407 .msg_iov = &iov,
408 .msg_iovlen = 1,
409 .msg_control = cmsg_buf,
410 .msg_controllen = sizeof(cmsg_buf),
411 };
412 struct cmsghdr *cmsg;
413 char addr_str[INET6_ADDRSTRLEN];
414 int len;
415
416 do {
417 struct in6_pktinfo *pkti = NULL;
418 struct interface *iface;
419
420 len = recvmsg(u->fd, &msg, 0);
421 if (len < 0) {
422 switch (errno) {
423 case EAGAIN:
424 return;
425 case EINTR:
426 continue;
427 default:
428 perror("recvmsg");
429 uloop_fd_delete(u);
430 return;
431 }
432 }
433
434 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
435 if (cmsg->cmsg_type != IPV6_PKTINFO)
436 continue;
437
438 pkti = (struct in6_pktinfo *) CMSG_DATA(cmsg);
439 }
440
441 if (!pkti) {
442 MSG(DEBUG, "Received packet without ifindex\n");
443 continue;
444 }
445
446 iface = interface_find_by_ifindex(pkti->ipi6_ifindex);
447 if (!iface) {
448 MSG(DEBUG, "Received packet from unconfigured interface %d\n", pkti->ipi6_ifindex);
449 continue;
450 }
451
452 inet_ntop(AF_INET6, &sin.sin6_addr, addr_str, sizeof(addr_str));
453 if (sin.sin6_addr.s6_addr[0] == 0) {
454 /* IPv4 mapped address. Ignore. */
455 continue;
456 }
457
458 interface_recv_msg(iface, addr_str, buf, len);
459 } while (1);
460 }
461
462 static void interface_send_msg_v4(struct interface *iface, struct blob_attr *data)
463 {
464 static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
465 static struct sockaddr_in a;
466 static struct iovec iov;
467 static struct msghdr m = {
468 .msg_name = (struct sockaddr *) &a,
469 .msg_namelen = sizeof(a),
470 .msg_iov = &iov,
471 .msg_iovlen = 1,
472 .msg_control = cmsg_data,
473 .msg_controllen = CMSG_LEN(sizeof(struct in_pktinfo)),
474 };
475 struct in_pktinfo *pkti;
476 struct cmsghdr *cmsg;
477
478 a.sin_family = AF_INET;
479 a.sin_port = htons(APMGR_PORT);
480 a.sin_addr.s_addr = ~0;
481
482 memset(cmsg_data, 0, sizeof(cmsg_data));
483 cmsg = CMSG_FIRSTHDR(&m);
484 cmsg->cmsg_len = m.msg_controllen;
485 cmsg->cmsg_level = IPPROTO_IP;
486 cmsg->cmsg_type = IP_PKTINFO;
487
488 pkti = (struct in_pktinfo *) CMSG_DATA(cmsg);
489 pkti->ipi_ifindex = iface->ifindex;
490
491 iov.iov_base = data;
492 iov.iov_len = blob_pad_len(data);
493
494 if (sendmsg(remote_fd.fd, &m, 0) < 0)
495 perror("sendmsg");
496 }
497
498
499 static void interface_send_msg_v6(struct interface *iface, struct blob_attr *data) {
500 static struct sockaddr_in6 groupSock = {};
501
502 groupSock.sin6_family = AF_INET6;
503 inet_pton(AF_INET6, APMGR_V6_MCAST_GROUP, &groupSock.sin6_addr);
504 groupSock.sin6_port = htons(APMGR_PORT);
505
506 setsockopt(remote_fd.fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &iface->ifindex, sizeof(iface->ifindex));
507
508 if (sendto(remote_fd.fd, data, blob_pad_len(data), 0, (const struct sockaddr *)&groupSock, sizeof(groupSock)) < 0)
509 perror("sendmsg");
510 }
511
512 static void interface_send_msg(struct interface *iface, struct blob_attr *data){
513 if (config.ipv6) {
514 interface_send_msg_v6(iface, data);
515 } else {
516 interface_send_msg_v4(iface, data);
517 }
518 }
519
520 static void usteer_send_sta_info(struct sta_info *sta)
521 {
522 int seen = current_time - sta->seen;
523 int last_connected = !!sta->connected ? 0 : current_time - sta->last_connected;
524 void *c;
525
526 c = blob_nest_start(&buf, 0);
527 blob_put(&buf, APMSG_STA_ADDR, sta->sta->addr, 6);
528 blob_put_int8(&buf, APMSG_STA_CONNECTED, !!sta->connected);
529 blob_put_int32(&buf, APMSG_STA_SIGNAL, sta->signal);
530 blob_put_int32(&buf, APMSG_STA_SEEN, seen);
531 blob_put_int32(&buf, APMSG_STA_LAST_CONNECTED, last_connected);
532 blob_put_int32(&buf, APMSG_STA_TIMEOUT, config.local_sta_timeout - seen);
533 blob_nest_end(&buf, c);
534 }
535
536 static void usteer_send_node(struct usteer_node *node, struct sta_info *sta)
537 {
538 void *c, *s, *r;
539
540 c = blob_nest_start(&buf, 0);
541
542 blob_put_string(&buf, APMSG_NODE_NAME, usteer_node_name(node));
543 blob_put_string(&buf, APMSG_NODE_SSID, node->ssid);
544 blob_put_int32(&buf, APMSG_NODE_FREQ, node->freq);
545 blob_put_int32(&buf, APMSG_NODE_NOISE, node->noise);
546 blob_put_int32(&buf, APMSG_NODE_LOAD, node->load);
547 blob_put_int32(&buf, APMSG_NODE_N_ASSOC, node->n_assoc);
548 blob_put_int32(&buf, APMSG_NODE_MAX_ASSOC, node->max_assoc);
549 blob_put(&buf, APMSG_NODE_BSSID, node->bssid, sizeof(node->bssid));
550 if (node->rrm_nr) {
551 r = blob_nest_start(&buf, APMSG_NODE_RRM_NR);
552 blobmsg_add_field(&buf, BLOBMSG_TYPE_ARRAY, "",
553 blobmsg_data(node->rrm_nr),
554 blobmsg_data_len(node->rrm_nr));
555 blob_nest_end(&buf, r);
556 }
557
558 if (node->node_info)
559 blob_put(&buf, APMSG_NODE_NODE_INFO,
560 blob_data(node->node_info),
561 blob_len(node->node_info));
562
563 s = blob_nest_start(&buf, APMSG_NODE_STATIONS);
564
565 if (sta) {
566 usteer_send_sta_info(sta);
567 } else {
568 list_for_each_entry(sta, &node->sta_info, node_list)
569 usteer_send_sta_info(sta);
570 }
571
572 blob_nest_end(&buf, s);
573
574 blob_nest_end(&buf, c);
575 }
576
577 static void
578 usteer_check_timeout(void)
579 {
580 struct usteer_remote_node *node, *tmp;
581 int timeout = config.remote_node_timeout;
582
583 list_for_each_entry_safe(node, tmp, &remote_nodes, list) {
584 if (node->check++ > timeout)
585 remote_node_free(node);
586 }
587 }
588
589 static void *
590 usteer_update_init(void)
591 {
592 blob_buf_init(&buf, 0);
593 blob_put_int32(&buf, APMSG_ID, local_id);
594 blob_put_int32(&buf, APMSG_SEQ, ++msg_seq);
595 if (host_info_blob)
596 blob_put(&buf, APMSG_HOST_INFO,
597 blob_data(host_info_blob),
598 blob_len(host_info_blob));
599
600 return blob_nest_start(&buf, APMSG_NODES);
601 }
602
603 static void
604 usteer_update_send(void *c)
605 {
606 struct interface *iface;
607
608 blob_nest_end(&buf, c);
609
610 vlist_for_each_element(&interfaces, iface, node)
611 interface_send_msg(iface, buf.head);
612 }
613
614 void
615 usteer_send_sta_update(struct sta_info *si)
616 {
617 void *c = usteer_update_init();
618 usteer_send_node(si->node, si);
619 usteer_update_send(c);
620 }
621
622 static void
623 usteer_send_update_timer(struct uloop_timeout *t)
624 {
625 struct usteer_node *node;
626 void *c;
627
628 usteer_update_time();
629 uloop_timeout_set(t, config.remote_update_interval);
630
631 if (!avl_is_empty(&local_nodes) || host_info_blob) {
632 c = usteer_update_init();
633 for_each_local_node(node)
634 usteer_send_node(node, NULL);
635
636 usteer_update_send(c);
637 }
638 usteer_check_timeout();
639 }
640
641 static int
642 usteer_init_local_id(void)
643 {
644 FILE *f;
645
646 f = fopen("/dev/urandom", "r");
647 if (!f) {
648 perror("fopen(/dev/urandom)");
649 return -1;
650 }
651
652 if (fread(&local_id, sizeof(local_id), 1, f) < 1)
653 return -1;
654
655 fclose(f);
656 return 0;
657 }
658
659 static int usteer_create_v4_socket() {
660 int yes = 1;
661 int fd;
662
663 fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK |
664 USOCK_NUMERIC | USOCK_IPV4ONLY,
665 "0.0.0.0", APMGR_PORT_STR);
666 if (fd < 0) {
667 perror("usock");
668 return - 1;
669 }
670
671 if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0)
672 perror("setsockopt(IP_PKTINFO)");
673
674 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes)) < 0)
675 perror("setsockopt(SO_BROADCAST)");
676
677 return fd;
678 }
679
680
681 static int usteer_create_v6_socket() {
682 struct interface *iface;
683 struct ipv6_mreq group;
684 int yes = 1;
685 int fd;
686
687 fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK |
688 USOCK_NUMERIC | USOCK_IPV6ONLY,
689 "::", APMGR_PORT_STR);
690 if (fd < 0) {
691 perror("usock");
692 return fd;
693 }
694
695 if (!inet_pton(AF_INET6, APMGR_V6_MCAST_GROUP, &group.ipv6mr_multiaddr.s6_addr))
696 perror("inet_pton(AF_INET6)");
697
698 /* Membership has to be added for every interface we listen on. */
699 vlist_for_each_element(&interfaces, iface, node) {
700 group.ipv6mr_interface = iface->ifindex;
701 if(setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (char *)&group, sizeof group) < 0)
702 perror("setsockopt(IPV6_ADD_MEMBERSHIP)");
703 }
704
705 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0)
706 perror("setsockopt(IPV6_RECVPKTINFO)");
707
708 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes)) < 0)
709 perror("setsockopt(SO_BROADCAST)");
710
711 return fd;
712 }
713
714 static void usteer_reload_timer(struct uloop_timeout *t) {
715 /* Remove uloop descriptor */
716 if (remote_fd.fd && remote_fd.registered) {
717 uloop_fd_delete(&remote_fd);
718 close(remote_fd.fd);
719 }
720
721 if (config.ipv6) {
722 remote_fd.fd = usteer_create_v6_socket();
723 remote_fd.cb = interface_recv_v6;
724 } else {
725 remote_fd.fd = usteer_create_v4_socket();
726 remote_fd.cb = interface_recv_v4;
727 }
728
729 if (remote_fd.fd < 0)
730 return;
731
732 uloop_fd_add(&remote_fd, ULOOP_READ);
733 }
734
735 int usteer_interface_init(void)
736 {
737 if (usteer_init_local_id())
738 return -1;
739
740 remote_timer.cb = usteer_send_update_timer;
741 remote_timer.cb(&remote_timer);
742
743 reload_timer.cb = usteer_reload_timer;
744 reload_timer.cb(&reload_timer);
745
746 return 0;
747 }