1 #include <stdio.h> /* TODO: remove this --jlr */
4 #include <event2/event.h>
15 #include <trp_internal.h>
16 #include <trp_ptable.h>
17 #include <trp_rtable.h>
18 #include <tr_config.h>
24 /* data for event callbacks */
25 struct tr_trps_event_cookie {
31 /* callback to schedule event to process messages */
32 static void tr_trps_mq_cb(TR_MQ *mq, void *arg)
34 struct event *mq_ev=(struct event *)arg;
35 event_active(mq_ev, 0, 0);
38 static void msg_free_helper(void *p)
40 tr_msg_free_decoded((TR_MSG *)p);
42 /* takes a TR_MSG and puts it in a TR_MQ_MSG for processing by the main thread */
43 static TRP_RC tr_trps_msg_handler(TRPS_INSTANCE *trps,
47 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
48 TR_MQ_MSG *mq_msg=NULL;
50 /* n.b., conn is available here, but do not hold onto the reference
51 * because it may be cleaned up if the originating connection goes
52 * down before the message is processed */
53 mq_msg=tr_mq_msg_new(tmp_ctx, TR_MQMSG_MSG_RECEIVED);
57 tr_mq_msg_set_payload(mq_msg, (void *)tr_msg, msg_free_helper);
58 trps_mq_append(trps, mq_msg);
59 talloc_free(tmp_ctx); /* cleans up the message if it did not get appended correctly */
64 static int tr_trps_gss_handler(gss_name_t client_name, gss_buffer_t gss_name,
67 struct tr_trps_event_cookie *cookie=(struct tr_trps_event_cookie *)cookie_in;
68 TRPS_INSTANCE *trps = cookie->trps;
69 TR_CFG_MGR *cfg_mgr = cookie->cfg_mgr;
70 TR_NAME name={gss_name->value, gss_name->length};
72 tr_debug("tr_trps_gss_handler()");
74 if ((!client_name) || (!gss_name) || (!trps) || (!cfg_mgr)) {
75 tr_debug("tr_trps_gss_handler: Bad parameters.");
79 /* look up the TRPS peer matching the GSS name */
80 if (NULL==trps_get_peer(trps, &name)) {
81 tr_warning("tr_trps_gss_handler: Connection attempt from unknown peer (GSS name: %.*s).", name.len, name.buf);
85 tr_debug("Client's GSS Name: %.*s", name.len, name.buf);
89 /* data passed to thread */
90 struct trps_thread_data {
94 /* thread to handle GSS connections from peers */
95 static void *tr_trps_thread(void *arg)
97 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
98 struct trps_thread_data *thread_data=talloc_get_type_abort(arg, struct trps_thread_data);
99 TRP_CONNECTION *conn=thread_data->conn;
100 TRPS_INSTANCE *trps=thread_data->trps;
103 tr_debug("tr_trps_thread: started");
104 trps_handle_connection(trps, conn);
106 msg=tr_mq_msg_new(tmp_ctx, TR_MQMSG_TRPS_DISCONNECTED);
107 tr_mq_msg_set_payload(msg, (void *)conn, NULL); /* do not pass a free routine */
109 tr_err("tr_trps_thread: error allocating TR_MQ_MSG");
111 trps_mq_append(trps, msg);
113 tr_debug("tr_trps_thread: exit");
114 talloc_free(tmp_ctx);
118 /* called when a connection to the TRPS port is received */
119 static void tr_trps_event_cb(int listener, short event, void *arg)
121 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
122 TRPS_INSTANCE *trps = talloc_get_type_abort(arg, TRPS_INSTANCE); /* aborts on wrong type */
123 TRP_CONNECTION *conn=NULL;
124 TR_NAME *gssname=NULL;
126 struct trps_thread_data *thread_data=NULL;
128 if (0==(event & EV_READ)) {
129 tr_debug("tr_trps_event_cb: unexpected event on TRPS socket (event=0x%X)", event);
131 /* create a thread to handle this connection */
132 asprintf(&name, "trustrouter@%s", trps->hostname);
133 gssname=tr_new_name(name);
134 free(name); name=NULL;
135 conn=trp_connection_accept(tmp_ctx, listener, gssname);
137 /* need to monitor this fd and trigger events when read becomes possible */
138 thread_data=talloc(conn, struct trps_thread_data);
139 if (thread_data==NULL) {
140 tr_err("tr_trps_event_cb: unable to allocate trps_thread_data");
141 talloc_free(tmp_ctx);
144 thread_data->conn=conn;
145 thread_data->trps=trps;
146 trps_add_connection(trps, conn); /* remember the connection */
147 pthread_create(trp_connection_get_thread(conn), NULL, tr_trps_thread, thread_data);
150 talloc_free(tmp_ctx);
153 static void tr_trps_cleanup_conn(TRPS_INSTANCE *trps, TRP_CONNECTION *conn)
155 /* everything belonging to the thread is in the TRP_CONNECTION
156 * associated with it */
157 tr_debug("tr_trps_cleanup_conn: freeing %p", conn);
158 /* pthread_join(*trp_connection_get_thread(conn), NULL); -- removed while debugging, put back!!! --jlr */
159 trps_remove_connection(trps, conn);
160 talloc_report_full(conn, stderr);
161 trp_connection_free(conn);
162 tr_debug("tr_trps_cleanup_conn: deleted connection");
165 static void tr_trps_cleanup_trpc(TRPS_INSTANCE *trps, TRPC_INSTANCE *trpc)
167 pthread_join(*trp_connection_get_thread(trpc_get_conn(trpc)), NULL);
168 trps_remove_trpc(trps, trpc);
170 tr_debug("tr_trps_cleanup_trpc: deleted connection");
173 static void tr_trps_print_route_table(TRPS_INSTANCE *trps, FILE *f)
175 char *table=trp_rtable_to_str(NULL, trps->rtable, " | ", NULL);
177 fprintf(f, "Unable to print route table.\n");
179 fprintf(f, "%s\n", table);
184 static void tr_trps_process_mq(int socket, short event, void *arg)
186 TRPS_INSTANCE *trps=talloc_get_type_abort(arg, TRPS_INSTANCE);
190 talloc_report_full(trps->mq, stderr);
191 msg=trps_mq_pop(trps);
193 s=tr_mq_msg_get_message(msg);
194 if (0==strcmp(s, TR_MQMSG_TRPS_DISCONNECTED)) {
195 tr_trps_cleanup_conn(trps,
196 talloc_get_type_abort(tr_mq_msg_get_payload(msg),
199 else if (0==strcmp(s, TR_MQMSG_TRPC_DISCONNECTED)) {
200 /* trpc connection died */
201 tr_trps_cleanup_trpc(trps,
202 talloc_get_type_abort(tr_mq_msg_get_payload(msg),
206 else if (0==strcmp(s, TR_MQMSG_MSG_RECEIVED)) {
207 if (trps_handle_tr_msg(trps, tr_mq_msg_get_payload(msg))!=TRP_SUCCESS)
208 tr_notice("tr_trps_process_mq: error handling message.");
210 tr_trps_print_route_table(trps, stderr);
214 tr_notice("tr_trps_process_mq: unknown message '%s' received.", tr_mq_msg_get_message(msg));
217 msg=trps_mq_pop(trps);
221 static void tr_trps_update(int listener, short event, void *arg)
223 struct tr_trps_event_cookie *cookie=talloc_get_type_abort(arg, struct tr_trps_event_cookie);
224 TRPS_INSTANCE *trps=cookie->trps;
225 struct event *ev=cookie->ev;
227 tr_debug("tr_trps_update: sending scheduled route updates.");
228 trps_update(trps, TRP_UPDATE_SCHEDULED);
229 event_add(ev, &(trps->update_interval));
232 static void tr_trps_sweep(int listener, short event, void *arg)
234 struct tr_trps_event_cookie *cookie=talloc_get_type_abort(arg, struct tr_trps_event_cookie);
235 TRPS_INSTANCE *trps=cookie->trps;
236 struct event *ev=cookie->ev;
238 tr_debug("tr_trps_sweep: sweeping routes.");
239 trps_sweep_routes(trps);
240 tr_trps_print_route_table(trps, stderr);
241 /* schedule the event to run again */
242 event_add(ev, &(trps->sweep_interval));
245 static void tr_connection_update(int listener, short event, void *arg)
247 struct tr_trps_event_cookie *cookie=talloc_get_type_abort(arg, struct tr_trps_event_cookie);
248 TRPS_INSTANCE *trps=cookie->trps;
249 struct event *ev=cookie->ev;
251 tr_debug("tr_connection_update: checking peer connections.");
252 tr_connect_to_peers(trps);
253 /* schedule the event to run again */
254 event_add(ev, &(trps->connect_interval));
257 static int tr_trps_events_destructor(void *obj)
259 TR_TRPS_EVENTS *ev=talloc_get_type_abort(obj, TR_TRPS_EVENTS);
261 event_free(ev->mq_ev);
262 if (ev->connect_ev!=NULL)
263 event_free(ev->connect_ev);
264 if (ev->update_ev!=NULL)
265 event_free(ev->update_ev);
266 if (ev->sweep_ev!=NULL)
267 event_free(ev->sweep_ev);
270 static TR_TRPS_EVENTS *tr_trps_events_new(TALLOC_CTX *mem_ctx)
272 TR_TRPS_EVENTS *ev=talloc(mem_ctx, TR_TRPS_EVENTS);
274 ev->listen_ev=talloc(ev, struct tr_socket_event);
279 if (ev->listen_ev==NULL) {
283 talloc_set_destructor((void *)ev, tr_trps_events_destructor);
289 static void tr_trps_events_free(TR_TRPS_EVENTS *ev)
294 /* Configure the trps instance and set up its event handler.
295 * Fills in trps_ev, which should be allocated by caller. */
296 TRP_RC tr_trps_event_init(struct event_base *base, TR_INSTANCE *tr)
298 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
299 struct tr_socket_event *listen_ev=NULL;
300 struct tr_trps_event_cookie *trps_cookie=NULL;
301 struct tr_trps_event_cookie *connection_cookie=NULL;
302 struct tr_trps_event_cookie *update_cookie=NULL;
303 struct tr_trps_event_cookie *sweep_cookie=NULL;
304 struct timeval zero_time={0,0};
305 TRP_RC retval=TRP_ERROR;
307 if (tr->events != NULL) {
308 tr_notice("tr_trps_event_init: tr->events was not null. Freeing before reallocating..");
309 tr_trps_events_free(tr->events);
312 tr->events=tr_trps_events_new(tmp_ctx);
313 if (tr->events == NULL) {
314 tr_debug("tr_trps_event_init: unable to allocate event handles.");
319 /* get convenient handles */
320 listen_ev=tr->events->listen_ev;
322 /* Create the cookie for callbacks. It will end up part of the trps context, so it will
323 * be cleaned up when trps is freed by talloc_free. */
324 trps_cookie=talloc(tr->events, struct tr_trps_event_cookie);
325 if (trps_cookie == NULL) {
326 tr_debug("tr_trps_event_init: Unable to allocate trps_cookie.");
328 tr_trps_events_free(tr->events);
332 trps_cookie->trps=tr->trps;
333 trps_cookie->cfg_mgr=tr->cfg_mgr;
335 /* get a trps listener */
336 listen_ev->sock_fd=trps_get_listener(tr->trps,
339 tr->cfg_mgr->active->internal->hostname,
340 tr->cfg_mgr->active->internal->trps_port,
341 (void *)trps_cookie);
342 if (listen_ev->sock_fd < 0) {
343 tr_crit("Error opening TRP server socket.");
345 tr_trps_events_free(tr->events);
349 trps_cookie->ev=listen_ev->ev; /* in case it needs to frob the event */
352 listen_ev->ev=event_new(base,
357 event_add(listen_ev->ev, NULL);
359 /* now set up message queue processing event, only triggered by
361 tr->events->mq_ev=event_new(base,
366 tr_mq_set_notify_cb(tr->trps->mq, tr_trps_mq_cb, tr->events->mq_ev);
368 /* now set up the peer connection timer event */
369 connection_cookie=talloc(tr->events, struct tr_trps_event_cookie);
370 if (connection_cookie == NULL) {
371 tr_debug("tr_trps_event_init: Unable to allocate connection_cookie.");
373 tr_trps_events_free(tr->events);
377 connection_cookie->trps=tr->trps;
378 connection_cookie->cfg_mgr=tr->cfg_mgr;
379 tr->events->connect_ev=event_new(base, -1, EV_TIMEOUT, tr_connection_update, (void *)connection_cookie);
380 connection_cookie->ev=tr->events->connect_ev; /* in case it needs to frob the event */
381 /* The first time, do this immediately. Thereafter, it will retrigger every trps->connect_interval */
382 event_add(tr->events->connect_ev, &zero_time);
384 /* now set up the route update timer event */
385 update_cookie=talloc(tr->events, struct tr_trps_event_cookie);
386 if (update_cookie == NULL) {
387 tr_debug("tr_trps_event_init: Unable to allocate update_cookie.");
389 tr_trps_events_free(tr->events);
393 update_cookie->trps=tr->trps;
394 update_cookie->cfg_mgr=tr->cfg_mgr;
395 tr->events->update_ev=event_new(base, -1, EV_TIMEOUT, tr_trps_update, (void *)update_cookie);
396 update_cookie->ev=tr->events->update_ev; /* in case it needs to frob the event */
397 event_add(tr->events->update_ev, &(tr->trps->update_interval));
399 /* now set up the route table sweep timer event */
400 sweep_cookie=talloc(tr->events, struct tr_trps_event_cookie);
401 if (sweep_cookie == NULL) {
402 tr_debug("tr_trps_event_init: Unable to allocate sweep_cookie.");
404 tr_trps_events_free(tr->events);
408 sweep_cookie->trps=tr->trps;
409 sweep_cookie->cfg_mgr=tr->cfg_mgr;
410 tr->events->sweep_ev=event_new(base, -1, EV_TIMEOUT, tr_trps_sweep, (void *)sweep_cookie);
411 sweep_cookie->ev=tr->events->sweep_ev; /* in case it needs to frob the event */
412 event_add(tr->events->sweep_ev, &(tr->trps->sweep_interval));
414 talloc_steal(tr, tr->events);
418 talloc_free(tmp_ctx);
423 struct trpc_notify_cb_data {
426 pthread_mutex_t mutex;
429 static void tr_trpc_mq_cb(TR_MQ *mq, void *arg)
431 struct trpc_notify_cb_data *cb_data=(struct trpc_notify_cb_data *) arg;
432 pthread_mutex_lock(&(cb_data->mutex));
433 if (!cb_data->msg_ready) {
434 cb_data->msg_ready=1;
435 pthread_cond_signal(&(cb_data->cond));
437 pthread_mutex_unlock(&(cb_data->mutex));
440 /* data passed to thread */
441 struct trpc_thread_data {
445 static void *tr_trpc_thread(void *arg)
447 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
448 struct trpc_thread_data *thread_data=talloc_get_type_abort(arg, struct trpc_thread_data);
449 TRPC_INSTANCE *trpc=thread_data->trpc;
450 TRPS_INSTANCE *trps=thread_data->trps;
453 const char *msg_type=NULL;
454 char *encoded_msg=NULL;
456 struct trpc_notify_cb_data cb_data={0,
457 PTHREAD_COND_INITIALIZER,
458 PTHREAD_MUTEX_INITIALIZER};
460 tr_debug("tr_trpc_thread: started");
462 /* set up the mq for receiving */
463 pthread_mutex_lock(&(cb_data.mutex)); /* hold this lock until we enter the main loop */
465 tr_mq_lock(trpc->mq);
466 tr_mq_set_notify_cb(trpc->mq, tr_trpc_mq_cb, (void *) &cb_data);
467 tr_mq_unlock(trpc->mq);
469 rc=trpc_connect(trpc);
470 /* talloc_report_full(trpc, stderr);*/
471 if (rc!=TRP_SUCCESS) {
472 /* was tr_notice --jlr */
473 fprintf(stderr, "tr_trpc_thread: failed to initiate connection to %s:%d.",
474 trpc_get_server(trpc),
475 trpc_get_port(trpc));
478 tr_debug("tr_trpc_thread: connected to peer %s", trpc->conn->peer->buf);
481 pthread_cond_wait(&(cb_data.cond), &(cb_data.mutex));
482 /* verify the condition */
483 if (cb_data.msg_ready) {
484 msg=trpc_mq_pop(trpc);
486 /* no message in the queue */
487 tr_err("tr_trpc_thread: notified of msg, but queue empty");
491 msg_type=tr_mq_msg_get_message(msg);
493 if (0==strcmp(msg_type, TR_MQMSG_ABORT)) {
495 break; /* exit loop */
497 else if (0==strcmp(msg_type, TR_MQMSG_TRPC_SEND)) {
498 encoded_msg=tr_mq_msg_get_payload(msg);
499 if (encoded_msg==NULL)
500 tr_notice("tr_trpc_thread: null outgoing TRP message.");
502 rc = trpc_send_msg(trpc, encoded_msg);
503 if (rc!=TRP_SUCCESS) {
504 tr_notice("tr_trpc_thread: trpc_send_msg failed.");
511 tr_notice("tr_trpc_thread: unknown message '%s' received.", msg_type);
518 tr_debug("tr_trpc_thread: exiting.");
519 msg=tr_mq_msg_new(tmp_ctx, TR_MQMSG_TRPC_DISCONNECTED);
520 tr_mq_msg_set_payload(msg, (void *)trpc, NULL); /* do not pass a free routine */
522 tr_err("tr_trpc_thread: error allocating TR_MQ_MSG");
524 trps_mq_append(trps, msg);
526 talloc_free(tmp_ctx);
530 /* convert an IDP realm into routing table entries. Outputs number in *n_routes */
531 static TRP_ROUTE **tr_make_local_routes(TALLOC_CTX *mem_ctx,
536 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
538 TRP_ROUTE *new_entry=NULL;
539 TRP_ROUTE **entries=NULL;
540 size_t n_apcs=0, ii=0;
548 for (apc=realm->apcs, n_apcs=0; apc!=NULL; apc=apc->next,n_apcs++) {}
550 entries=talloc_array(tmp_ctx, TRP_ROUTE *, n_apcs);
551 for (apc=realm->apcs,ii=0; apc!=NULL; apc=apc->next, ii++) {
552 new_entry=trp_route_new(entries);
553 if (new_entry==NULL) {
554 tr_crit("tr_make_local_routes: unable to allocate entry.");
555 talloc_free(entries);
558 trp_route_set_apc(new_entry, tr_dup_name(apc->id));
559 trp_route_set_realm(new_entry, tr_dup_name(realm->realm_id));
560 trp_route_set_peer(new_entry, tr_new_name("")); /* no peer, it's us */
561 trp_route_set_metric(new_entry, 0);
562 trp_route_set_trust_router(new_entry, tr_new_name(trust_router));
563 trp_route_set_next_hop(new_entry, tr_new_name(""));
564 trp_route_set_local(new_entry, 1);
565 entries[ii]=new_entry;
568 talloc_steal(mem_ctx, entries);
571 talloc_free(tmp_ctx);
575 struct tr_trpc_status_change_cookie {
580 static void tr_trpc_status_change(TRP_CONNECTION *conn, void *cookie)
582 struct tr_trpc_status_change_cookie *cook=talloc_get_type_abort(cookie, struct tr_trpc_status_change_cookie);
583 TRP_PEER *peer=cook->peer;
584 TR_NAME *gssname=trp_peer_get_gssname(peer);
586 if (trp_connection_get_status(conn)==TRP_CONNECTION_UP)
587 tr_debug("tr_trpc_status_change: connection to %.*s now up.", gssname->len, gssname->buf);
589 tr_debug("tr_trpc_status_change: connection to %.*s now down.", gssname->len, gssname->buf);
592 /* starts a trpc thread to connect to server:port */
593 TRP_RC tr_trpc_initiate(TRPS_INSTANCE *trps, TRP_PEER *peer)
595 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
596 TRPC_INSTANCE *trpc=NULL;
597 TRP_CONNECTION *conn=NULL;
598 struct trpc_thread_data *thread_data=NULL;
599 struct tr_trpc_status_change_cookie *status_change_cookie=NULL;
602 tr_debug("tr_trpc_initiate entered");
603 trpc=trpc_new(tmp_ctx);
605 tr_crit("tr_trpc_initiate: could not allocate TRPC_INSTANCE.");
609 tr_debug("tr_trpc_initiate: allocated trpc");
611 conn=trp_connection_new(trpc);
613 tr_crit("tr_trpc_initiate: could not allocate TRP_CONNECTION.");
618 status_change_cookie=talloc(conn, struct tr_trpc_status_change_cookie);
619 if (status_change_cookie==NULL) {
620 tr_crit("tr_trpc_initiate: could not allocate connection status cookie.");
624 status_change_cookie->trps=trps;
625 status_change_cookie->trpc=trpc;
626 status_change_cookie->peer=peer;
627 conn->status_change_cookie=status_change_cookie;
628 status_change_cookie=NULL;
629 conn->status_change_cb=tr_trpc_status_change;
631 trpc_set_conn(trpc, conn);
632 trpc_set_server(trpc, talloc_strdup(trpc, trp_peer_get_server(peer)));
633 trpc_set_port(trpc, trp_peer_get_port(peer));
634 trpc_set_gssname(trpc, trp_peer_dup_gssname(peer));
635 tr_debug("tr_trpc_initiate: allocated connection");
638 thread_data=talloc(trpc, struct trpc_thread_data);
639 if (thread_data==NULL) {
640 tr_crit("tr_trpc_initiate: could not allocate struct trpc_thread_data.");
644 thread_data->trpc=trpc;
645 thread_data->trps=trps;
647 trps_add_trpc(trps, trpc); /* must add before starting thread */
648 pthread_create(trp_connection_get_thread(conn), NULL, tr_trpc_thread, thread_data);
650 tr_debug("tr_trpc_initiate: started trpc thread");
654 talloc_report_full(tmp_ctx, stderr);
655 talloc_free(tmp_ctx);
659 /* Add local routes to the route table. */
660 TRP_RC tr_add_local_routes(TRPS_INSTANCE *trps, TR_CFG *cfg)
662 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
663 TR_IDP_REALM *cur=NULL;
664 TRP_ROUTE **local_routes=NULL;
667 char *trust_router_name=talloc_asprintf(tmp_ctx, "%s:%d", cfg->internal->hostname, cfg->internal->trps_port);
669 /* determine our trust router name */
670 if (trust_router_name==NULL)
673 for (cur=cfg->idp_realms; cur!=NULL; cur=cur->next) {
674 local_routes=tr_make_local_routes(tmp_ctx, cur, trust_router_name, &n_routes);
675 for (ii=0; ii<n_routes; ii++)
676 trps_add_route(trps, local_routes[ii]);
678 talloc_free(local_routes);
683 talloc_free(tmp_ctx);
687 /* decide how often to attempt to connect to a peer */
688 static int tr_conn_attempt_due(TRPS_INSTANCE *trps, TRP_PEER *peer, struct timespec *when)
690 return 1; /* currently make an attempt every cycle */
693 /* open missing connections to peers */
694 TRP_RC tr_connect_to_peers(TRPS_INSTANCE *trps)
696 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
697 TRP_PTABLE_ITER *iter=trp_ptable_iter_new(tmp_ctx);
699 struct timespec curtime={0,0};
702 if (clock_gettime(CLOCK_REALTIME, &curtime)) {
703 tr_err("tr_connect_to_peers: failed to read time.");
708 for (peer=trp_ptable_iter_first(iter, trps->ptable);
710 peer=trp_ptable_iter_next(iter))
712 if (trps_find_trpc(trps, peer)==NULL) {
713 tr_debug("tr_connect_to_peers: %.*s missing connection.",
714 trp_peer_get_gssname(peer)->len, trp_peer_get_gssname(peer)->buf);
715 /* has it been long enough since we last tried? */
716 if (tr_conn_attempt_due(trps, peer, &curtime)) {
717 trp_peer_set_last_conn_attempt(peer, &curtime); /* we are trying again now */
718 if (tr_trpc_initiate(trps, peer)!=TRP_SUCCESS) {
719 tr_err("tr_connect_to_peers: unable to initiate TRP connection to %s:%u.",
720 trp_peer_get_server(peer),
721 trp_peer_get_port(peer));
729 trp_ptable_iter_free(iter);
730 talloc_free(tmp_ctx);
735 /* Called by the config manager after a change to the active configuration.
736 * Updates configuration of objects that do not know about the config manager. */
737 void tr_config_changed(TR_CFG *new_cfg, void *cookie)
739 TR_INSTANCE *tr=talloc_get_type_abort(cookie, TR_INSTANCE);
740 TRPS_INSTANCE *trps=tr->trps;
742 tr->cfgwatch->poll_interval.tv_sec=new_cfg->internal->cfg_poll_interval;
743 tr->cfgwatch->poll_interval.tv_usec=0;
745 tr->cfgwatch->settling_time.tv_sec=new_cfg->internal->cfg_settling_time;
746 tr->cfgwatch->settling_time.tv_usec=0;
748 trps_set_connect_interval(trps, new_cfg->internal->trp_connect_interval);
749 trps_set_update_interval(trps, new_cfg->internal->trp_update_interval);
750 trps_set_sweep_interval(trps, new_cfg->internal->trp_sweep_interval);
751 trps_clear_rtable(trps); /* should we do this every time??? */
752 tr_add_local_routes(trps, new_cfg); /* should we do this every time??? */
753 trps_update_active_routes(trps); /* find new routes */
754 trps_update(trps, TRP_UPDATE_TRIGGERED); /* send any triggered routes */
755 tr_trps_print_route_table(trps, stderr);