4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
11 #include "nest/bird.h"
12 #include "nest/protocol.h"
13 #include "lib/resource.h"
14 #include "lib/lists.h"
15 #include "lib/event.h"
16 #include "lib/timer.h"
17 #include "lib/string.h"
18 #include "conf/conf.h"
19 #include "nest/route.h"
20 #include "nest/iface.h"
22 #include "filter/filter.h"
27 static list protocol_list
;
28 struct protocol
*class_to_protocol
[PROTOCOL__MAX
];
30 #define PD(pr, msg, args...) do { if (pr->debug & D_STATES) { log(L_TRACE "%s: " msg, pr->name , ## args); } } while(0)
32 static timer
*proto_shutdown_timer
;
33 static timer
*gr_wait_timer
;
40 static int graceful_restart_state
;
41 static u32 graceful_restart_locks
;
43 static char *p_states
[] = { "DOWN", "START", "UP", "STOP" };
44 static char *c_states
[] = { "DOWN", "START", "UP", "FLUSHING" };
46 extern struct protocol proto_unix_iface
;
48 static void proto_shutdown_loop(timer
*);
49 static void proto_rethink_goal(struct proto
*p
);
50 static char *proto_state_name(struct proto
*p
);
51 static void channel_verify_limits(struct channel
*c
);
52 static inline void channel_reset_limit(struct channel_limit
*l
);
55 static inline int proto_is_done(struct proto
*p
)
56 { return (p
->proto_state
== PS_DOWN
) && (p
->active_channels
== 0); }
58 static inline int channel_is_active(struct channel
*c
)
59 { return (c
->channel_state
== CS_START
) || (c
->channel_state
== CS_UP
); }
62 proto_log_state_change(struct proto
*p
)
64 if (p
->debug
& D_STATES
)
66 char *name
= proto_state_name(p
);
67 if (name
!= p
->last_state_name_announced
)
69 p
->last_state_name_announced
= name
;
70 PD(p
, "State changed to %s", proto_state_name(p
));
74 p
->last_state_name_announced
= NULL
;
78 struct channel_config
*
79 proto_cf_find_channel(struct proto_config
*pc
, uint net_type
)
81 struct channel_config
*cc
;
83 WALK_LIST(cc
, pc
->channels
)
84 if (cc
->net_type
== net_type
)
91 * proto_find_channel_by_table - find channel connected to a routing table
92 * @p: protocol instance
95 * Returns pointer to channel or NULL
98 proto_find_channel_by_table(struct proto
*p
, struct rtable
*t
)
102 WALK_LIST(c
, p
->channels
)
110 * proto_find_channel_by_name - find channel by its name
111 * @p: protocol instance
114 * Returns pointer to channel or NULL
117 proto_find_channel_by_name(struct proto
*p
, const char *n
)
121 WALK_LIST(c
, p
->channels
)
122 if (!strcmp(c
->name
, n
))
129 * proto_add_channel - connect protocol to a routing table
130 * @p: protocol instance
131 * @cf: channel configuration
133 * This function creates a channel between the protocol instance @p and the
134 * routing table specified in the configuration @cf, making the protocol hear
135 * all changes in the table and allowing the protocol to update routes in the
138 * The channel is linked in the protocol channel list and when active also in
139 * the table channel list. Channels are allocated from the global resource pool
140 * (@proto_pool) and they are automatically freed when the protocol is removed.
144 proto_add_channel(struct proto
*p
, struct channel_config
*cf
)
146 struct channel
*c
= mb_allocz(proto_pool
, cf
->channel
->channel_size
);
149 c
->channel
= cf
->channel
;
151 c
->table
= cf
->table
->table
;
153 c
->in_filter
= cf
->in_filter
;
154 c
->out_filter
= cf
->out_filter
;
155 c
->rx_limit
= cf
->rx_limit
;
156 c
->in_limit
= cf
->in_limit
;
157 c
->out_limit
= cf
->out_limit
;
159 c
->net_type
= cf
->net_type
;
160 c
->ra_mode
= cf
->ra_mode
;
161 c
->preference
= cf
->preference
;
162 c
->merge_limit
= cf
->merge_limit
;
163 c
->in_keep_filtered
= cf
->in_keep_filtered
;
165 c
->channel_state
= CS_DOWN
;
166 c
->export_state
= ES_DOWN
;
167 c
->last_state_change
= current_time();
168 c
->last_tx_filter_change
= current_time();
171 CALL(c
->channel
->init
, c
, cf
);
173 add_tail(&p
->channels
, &c
->n
);
175 PD(p
, "Channel %s connected to table %s", c
->name
, c
->table
->name
);
181 proto_remove_channel(struct proto
*p
, struct channel
*c
)
183 ASSERT(c
->channel_state
== CS_DOWN
);
185 PD(p
, "Channel %s removed", c
->name
);
193 proto_start_channels(struct proto
*p
)
196 WALK_LIST(c
, p
->channels
)
198 channel_set_state(c
, CS_UP
);
202 proto_pause_channels(struct proto
*p
)
205 WALK_LIST(c
, p
->channels
)
206 if (!c
->disabled
&& channel_is_active(c
))
207 channel_set_state(c
, CS_START
);
211 proto_stop_channels(struct proto
*p
)
214 WALK_LIST(c
, p
->channels
)
215 if (!c
->disabled
&& channel_is_active(c
))
216 channel_set_state(c
, CS_FLUSHING
);
220 proto_remove_channels(struct proto
*p
)
223 WALK_LIST_FIRST(c
, p
->channels
)
224 proto_remove_channel(p
, c
);
228 channel_schedule_feed(struct channel
*c
, int initial
)
230 // DBG("%s: Scheduling meal\n", p->name);
231 ASSERT(c
->channel_state
== CS_UP
);
233 c
->export_state
= ES_FEEDING
;
234 c
->refeeding
= !initial
;
236 ev_schedule(c
->feed_event
);
240 channel_feed_loop(void *ptr
)
242 struct channel
*c
= ptr
;
244 if (c
->export_state
!= ES_FEEDING
)
248 if (c
->proto
->feed_begin
)
249 c
->proto
->feed_begin(c
, !c
->refeeding
);
251 // DBG("Feeding protocol %s continued\n", p->name);
252 if (!rt_feed_channel(c
))
254 ev_schedule(c
->feed_event
);
258 // DBG("Feeding protocol %s finished\n", p->name);
259 c
->export_state
= ES_READY
;
260 // proto_log_state_change(p);
262 if (c
->proto
->feed_end
)
263 c
->proto
->feed_end(c
);
268 channel_start_export(struct channel
*c
)
270 ASSERT(c
->channel_state
== CS_UP
);
271 ASSERT(c
->export_state
== ES_DOWN
);
273 channel_schedule_feed(c
, 1); /* Sets ES_FEEDING */
277 channel_stop_export(struct channel
*c
)
279 /* Need to abort feeding */
280 if (c
->export_state
== ES_FEEDING
)
281 rt_feed_channel_abort(c
);
283 c
->export_state
= ES_DOWN
;
284 c
->stats
.exp_routes
= 0;
288 /* Called by protocol for reload from in_table */
290 channel_schedule_reload(struct channel
*c
)
292 ASSERT(c
->channel_state
== CS_UP
);
294 rt_reload_channel_abort(c
);
295 ev_schedule(c
->reload_event
);
299 channel_reload_loop(void *ptr
)
301 struct channel
*c
= ptr
;
303 if (!rt_reload_channel(c
))
305 ev_schedule(c
->reload_event
);
311 channel_reset_import(struct channel
*c
)
313 /* Need to abort feeding */
314 ev_postpone(c
->reload_event
);
315 rt_reload_channel_abort(c
);
317 rt_prune_sync(c
->in_table
, 1);
320 /* Called by protocol to activate in_table */
322 channel_setup_in_table(struct channel
*c
)
324 struct rtable_config
*cf
= mb_allocz(c
->proto
->pool
, sizeof(struct rtable_config
));
326 cf
->addr_type
= c
->net_type
;
328 c
->in_table
= mb_allocz(c
->proto
->pool
, sizeof(struct rtable
));
329 rt_setup(c
->proto
->pool
, c
->in_table
, cf
);
331 c
->reload_event
= ev_new_init(c
->proto
->pool
, channel_reload_loop
, c
);
336 channel_do_start(struct channel
*c
)
338 rt_lock_table(c
->table
);
339 add_tail(&c
->table
->channels
, &c
->table_node
);
340 c
->proto
->active_channels
++;
342 c
->feed_event
= ev_new_init(c
->proto
->pool
, channel_feed_loop
, c
);
344 channel_reset_limit(&c
->rx_limit
);
345 channel_reset_limit(&c
->in_limit
);
346 channel_reset_limit(&c
->out_limit
);
348 CALL(c
->channel
->start
, c
);
352 channel_do_flush(struct channel
*c
)
354 rt_schedule_prune(c
->table
);
358 channel_graceful_restart_unlock(c
);
360 CALL(c
->channel
->shutdown
, c
);
364 channel_do_down(struct channel
*c
)
366 ASSERT(!c
->feed_active
&& !c
->reload_active
);
368 rem_node(&c
->table_node
);
369 rt_unlock_table(c
->table
);
370 c
->proto
->active_channels
--;
372 if ((c
->stats
.imp_routes
+ c
->stats
.filt_routes
) != 0)
373 log(L_ERR
"%s: Channel %s is down but still has some routes", c
->proto
->name
, c
->name
);
375 memset(&c
->stats
, 0, sizeof(struct proto_stats
));
378 c
->reload_event
= NULL
;
380 CALL(c
->channel
->cleanup
, c
);
382 /* Schedule protocol shutddown */
383 if (proto_is_done(c
->proto
))
384 ev_schedule(c
->proto
->event
);
388 channel_set_state(struct channel
*c
, uint state
)
390 uint cs
= c
->channel_state
;
391 uint es
= c
->export_state
;
393 DBG("%s reporting channel %s state transition %s -> %s\n", c
->proto
->name
, c
->name
, c_states
[cs
], c_states
[state
]);
397 c
->channel_state
= state
;
398 c
->last_state_change
= current_time();
403 ASSERT(cs
== CS_DOWN
|| cs
== CS_UP
);
409 channel_stop_export(c
);
411 if (c
->in_table
&& (cs
== CS_UP
))
412 channel_reset_import(c
);
417 ASSERT(cs
== CS_DOWN
|| cs
== CS_START
);
422 if (!c
->gr_wait
&& c
->proto
->rt_notify
)
423 channel_start_export(c
);
428 ASSERT(cs
== CS_START
|| cs
== CS_UP
);
431 channel_stop_export(c
);
433 if (c
->in_table
&& (cs
== CS_UP
))
434 channel_reset_import(c
);
440 ASSERT(cs
== CS_FLUSHING
);
448 // XXXX proto_log_state_change(c);
452 * channel_request_feeding - request feeding routes to the channel
455 * Sometimes it is needed to send again all routes to the channel. This is
456 * called feeding and can be requested by this function. This would cause
457 * channel export state transition to ES_FEEDING (during feeding) and when
458 * completed, it will switch back to ES_READY. This function can be called
459 * even when feeding is already running, in that case it is restarted.
462 channel_request_feeding(struct channel
*c
)
464 ASSERT(c
->channel_state
== CS_UP
);
466 /* Do nothing if we are still waiting for feeding */
467 if (c
->export_state
== ES_DOWN
)
470 /* If we are already feeding, we want to restart it */
471 if (c
->export_state
== ES_FEEDING
)
473 /* Unless feeding is in initial state */
477 rt_feed_channel_abort(c
);
480 channel_reset_limit(&c
->out_limit
);
482 /* Hack: reset exp_routes during refeed, and do not decrease it later */
483 c
->stats
.exp_routes
= 0;
485 channel_schedule_feed(c
, 0); /* Sets ES_FEEDING */
486 // proto_log_state_change(c);
490 channel_reloadable(struct channel
*c
)
492 return c
->proto
->reload_routes
&& c
->reloadable
;
496 channel_request_reload(struct channel
*c
)
498 ASSERT(c
->channel_state
== CS_UP
);
499 ASSERT(channel_reloadable(c
));
501 c
->proto
->reload_routes(c
);
504 * Should this be done before reload_routes() hook?
505 * Perhaps, but routes are updated asynchronously.
507 channel_reset_limit(&c
->rx_limit
);
508 channel_reset_limit(&c
->in_limit
);
511 const struct channel_class channel_basic
= {
512 .channel_size
= sizeof(struct channel
),
513 .config_size
= sizeof(struct channel_config
)
517 channel_config_new(const struct channel_class
*cc
, const char *name
, uint net_type
, struct proto_config
*proto
)
519 struct channel_config
*cf
= NULL
;
520 struct rtable_config
*tab
= NULL
;
524 if (!net_val_match(net_type
, proto
->protocol
->channel_mask
))
525 cf_error("Unsupported channel type");
527 if (proto
->net_type
&& (net_type
!= proto
->net_type
))
528 cf_error("Different channel type");
530 tab
= new_config
->def_tables
[net_type
];
536 cf
= cfg_allocz(cc
->config_size
);
541 cf
->out_filter
= FILTER_REJECT
;
543 cf
->net_type
= net_type
;
544 cf
->ra_mode
= RA_OPTIMAL
;
545 cf
->preference
= proto
->protocol
->preference
;
547 add_tail(&proto
->channels
, &cf
->n
);
553 channel_config_get(const struct channel_class
*cc
, const char *name
, uint net_type
, struct proto_config
*proto
)
555 struct channel_config
*cf
;
557 /* We are using name as token, so no strcmp() */
558 WALK_LIST(cf
, proto
->channels
)
559 if (cf
->name
== name
)
561 /* Allow to redefine channel only if inherited from template */
562 if (cf
->parent
== proto
)
563 cf_error("Multiple %s channels", name
);
569 return channel_config_new(cc
, name
, net_type
, proto
);
572 struct channel_config
*
573 channel_copy_config(struct channel_config
*src
, struct proto_config
*proto
)
575 struct channel_config
*dst
= cfg_alloc(src
->channel
->config_size
);
577 memcpy(dst
, src
, src
->channel
->config_size
);
578 add_tail(&proto
->channels
, &dst
->n
);
579 CALL(src
->channel
->copy_config
, dst
, src
);
585 static int reconfigure_type
; /* Hack to propagate type info to channel_reconfigure() */
588 channel_reconfigure(struct channel
*c
, struct channel_config
*cf
)
590 /* FIXME: better handle these changes, also handle in_keep_filtered */
591 if ((c
->table
!= cf
->table
->table
) || (cf
->ra_mode
&& (c
->ra_mode
!= cf
->ra_mode
)))
594 /* Note that filter_same() requires arguments in (new, old) order */
595 int import_changed
= !filter_same(cf
->in_filter
, c
->in_filter
);
596 int export_changed
= !filter_same(cf
->out_filter
, c
->out_filter
);
598 if (c
->preference
!= cf
->preference
)
601 if (c
->merge_limit
!= cf
->merge_limit
)
604 /* Reconfigure channel fields */
605 c
->in_filter
= cf
->in_filter
;
606 c
->out_filter
= cf
->out_filter
;
607 c
->rx_limit
= cf
->rx_limit
;
608 c
->in_limit
= cf
->in_limit
;
609 c
->out_limit
= cf
->out_limit
;
611 // c->ra_mode = cf->ra_mode;
612 c
->merge_limit
= cf
->merge_limit
;
613 c
->preference
= cf
->preference
;
614 c
->in_keep_filtered
= cf
->in_keep_filtered
;
616 channel_verify_limits(c
);
619 c
->last_tx_filter_change
= current_time();
621 /* Execute channel-specific reconfigure hook */
622 if (c
->channel
->reconfigure
&& !c
->channel
->reconfigure(c
, cf
))
625 /* If the channel is not open, it has no routes and we cannot reload it anyways */
626 if (c
->channel_state
!= CS_UP
)
629 if (reconfigure_type
== RECONFIG_SOFT
)
632 log(L_INFO
"Channel %s.%s changed import", c
->proto
->name
, c
->name
);
635 log(L_INFO
"Channel %s.%s changed export", c
->proto
->name
, c
->name
);
640 /* Route reload may be not supported */
641 if (import_changed
&& !channel_reloadable(c
))
644 if (import_changed
|| export_changed
)
645 log(L_INFO
"Reloading channel %s.%s", c
->proto
->name
, c
->name
);
648 channel_request_reload(c
);
651 channel_request_feeding(c
);
658 proto_configure_channel(struct proto
*p
, struct channel
**pc
, struct channel_config
*cf
)
660 struct channel
*c
= *pc
;
664 /* We could add the channel, but currently it would just stay in down state
665 until protocol is restarted, so it is better to force restart anyways. */
666 if (p
->proto_state
!= PS_DOWN
)
668 log(L_INFO
"Cannot add channel %s.%s", p
->name
, cf
->name
);
672 *pc
= proto_add_channel(p
, cf
);
676 if (c
->channel_state
!= CS_DOWN
)
678 log(L_INFO
"Cannot remove channel %s.%s", c
->proto
->name
, c
->name
);
682 proto_remove_channel(p
, c
);
687 if (!channel_reconfigure(c
, cf
))
689 log(L_INFO
"Cannot reconfigure channel %s.%s", c
->proto
->name
, c
->name
);
699 proto_event(void *ptr
)
701 struct proto
*p
= ptr
;
711 if (p
->proto
== &proto_unix_iface
)
716 if (proto_is_done(p
))
718 if (p
->proto
->cleanup
)
719 p
->proto
->cleanup(p
);
722 proto_log_state_change(p
);
723 proto_rethink_goal(p
);
729 * proto_new - create a new protocol instance
730 * @c: protocol configuration
732 * When a new configuration has been read in, the core code starts
733 * initializing all the protocol instances configured by calling their
734 * init() hooks with the corresponding instance configuration. The initialization
735 * code of the protocol is expected to create a new instance according to the
736 * configuration by calling this function and then modifying the default settings
737 * to values wanted by the protocol.
740 proto_new(struct proto_config
*cf
)
742 struct proto
*p
= mb_allocz(proto_pool
, cf
->protocol
->proto_size
);
745 p
->debug
= cf
->debug
;
746 p
->mrtdump
= cf
->mrtdump
;
748 p
->proto
= cf
->protocol
;
749 p
->net_type
= cf
->net_type
;
750 p
->disabled
= cf
->disabled
;
751 p
->hash_key
= random_u32();
754 init_list(&p
->channels
);
759 static struct proto
*
760 proto_init(struct proto_config
*c
, node
*n
)
762 struct protocol
*pr
= c
->protocol
;
763 struct proto
*p
= pr
->init(c
);
765 p
->proto_state
= PS_DOWN
;
766 p
->last_state_change
= current_time();
768 insert_node(&p
->n
, n
);
770 p
->event
= ev_new_init(proto_pool
, proto_event
, p
);
772 PD(p
, "Initializing%s", p
->disabled
? " [disabled]" : "");
778 proto_start(struct proto
*p
)
780 /* Here we cannot use p->cf->name since it won't survive reconfiguration */
781 p
->pool
= rp_new(proto_pool
, p
->proto
->name
);
783 if (graceful_restart_state
== GRS_INIT
)
789 * proto_config_new - create a new protocol configuration
790 * @pr: protocol the configuration will belong to
791 * @class: SYM_PROTO or SYM_TEMPLATE
793 * Whenever the configuration file says that a new instance
794 * of a routing protocol should be created, the parser calls
795 * proto_config_new() to create a configuration entry for this
796 * instance (a structure staring with the &proto_config header
797 * containing all the generic items followed by protocol-specific
798 * ones). Also, the configuration entry gets added to the list
799 * of protocol instances kept in the configuration.
801 * The function is also used to create protocol templates (when class
802 * SYM_TEMPLATE is specified), the only difference is that templates
803 * are not added to the list of protocol instances and therefore not
804 * initialized during protos_commit()).
807 proto_config_new(struct protocol
*pr
, int class)
809 struct proto_config
*cf
= cfg_allocz(pr
->config_size
);
811 if (class == SYM_PROTO
)
812 add_tail(&new_config
->protos
, &cf
->n
);
814 cf
->global
= new_config
;
818 cf
->debug
= new_config
->proto_default_debug
;
819 cf
->mrtdump
= new_config
->proto_default_mrtdump
;
821 init_list(&cf
->channels
);
828 * proto_copy_config - copy a protocol configuration
829 * @dest: destination protocol configuration
830 * @src: source protocol configuration
832 * Whenever a new instance of a routing protocol is created from the
833 * template, proto_copy_config() is called to copy a content of
834 * the source protocol configuration to the new protocol configuration.
835 * Name, class and a node in protos list of @dest are kept intact.
836 * copy_config() protocol hook is used to copy protocol-specific data.
839 proto_copy_config(struct proto_config
*dest
, struct proto_config
*src
)
841 struct channel_config
*cc
;
846 if (dest
->protocol
!= src
->protocol
)
847 cf_error("Can't copy configuration from a different protocol type");
849 if (dest
->protocol
->copy_config
== NULL
)
850 cf_error("Inheriting configuration for %s is not supported", src
->protocol
->name
);
852 DBG("Copying configuration from %s to %s\n", src
->name
, dest
->name
);
855 * Copy struct proto_config here. Keep original node, class and name.
856 * protocol-specific config copy is handled by protocol copy_config() hook
860 old_class
= dest
->class;
861 old_name
= dest
->name
;
863 memcpy(dest
, src
, src
->protocol
->config_size
);
866 dest
->class = old_class
;
867 dest
->name
= old_name
;
868 init_list(&dest
->channels
);
870 WALK_LIST(cc
, src
->channels
)
871 channel_copy_config(cc
, dest
);
873 /* FIXME: allow for undefined copy_config */
874 dest
->protocol
->copy_config(dest
, src
);
878 * protos_preconfig - pre-configuration processing
879 * @c: new configuration
881 * This function calls the preconfig() hooks of all routing
882 * protocols available to prepare them for reading of the new
886 protos_preconfig(struct config
*c
)
890 init_list(&c
->protos
);
891 DBG("Protocol preconfig:");
892 WALK_LIST(p
, protocol_list
)
903 proto_reconfigure(struct proto
*p
, struct proto_config
*oc
, struct proto_config
*nc
, int type
)
905 /* If the protocol is DOWN, we just restart it */
906 if (p
->proto_state
== PS_DOWN
)
909 /* If there is a too big change in core attributes, ... */
910 if ((nc
->protocol
!= oc
->protocol
) ||
911 (nc
->net_type
!= oc
->net_type
) ||
912 (nc
->disabled
!= p
->disabled
) ||
913 (nc
->vrf
!= oc
->vrf
))
917 p
->debug
= nc
->debug
;
918 p
->mrtdump
= nc
->mrtdump
;
919 reconfigure_type
= type
;
921 /* Execute protocol specific reconfigure hook */
922 if (!p
->proto
->reconfigure
|| !p
->proto
->reconfigure(p
, nc
))
925 DBG("\t%s: same\n", oc
->name
);
926 PD(p
, "Reconfigured");
933 * protos_commit - commit new protocol configuration
934 * @new: new configuration
935 * @old: old configuration or %NULL if it's boot time config
936 * @force_reconfig: force restart of all protocols (used for example
937 * when the router ID changes)
938 * @type: type of reconfiguration (RECONFIG_SOFT or RECONFIG_HARD)
940 * Scan differences between @old and @new configuration and adjust all
941 * protocol instances to conform to the new configuration.
943 * When a protocol exists in the new configuration, but it doesn't in the
944 * original one, it's immediately started. When a collision with the other
945 * running protocol would arise, the new protocol will be temporarily stopped
946 * by the locking mechanism.
948 * When a protocol exists in the old configuration, but it doesn't in the
949 * new one, it's shut down and deleted after the shutdown completes.
951 * When a protocol exists in both configurations, the core decides
952 * whether it's possible to reconfigure it dynamically - it checks all
953 * the core properties of the protocol (changes in filters are ignored
954 * if type is RECONFIG_SOFT) and if they match, it asks the
955 * reconfigure() hook of the protocol to see if the protocol is able
956 * to switch to the new configuration. If it isn't possible, the
957 * protocol is shut down and a new instance is started with the new
958 * configuration after the shutdown is completed.
961 protos_commit(struct config
*new, struct config
*old
, int force_reconfig
, int type
)
963 struct proto_config
*oc
, *nc
;
969 DBG("protos_commit:\n");
972 WALK_LIST(oc
, old
->protos
)
975 sym
= cf_find_symbol(new, oc
->name
);
976 if (sym
&& sym
->class == SYM_PROTO
&& !new->shutdown
)
978 /* Found match, let's check if we can smoothly switch to new configuration */
979 /* No need to check description */
983 /* We will try to reconfigure protocol p */
984 if (! force_reconfig
&& proto_reconfigure(p
, oc
, nc
, type
))
987 /* Unsuccessful, we will restart it */
988 if (!p
->disabled
&& !nc
->disabled
)
989 log(L_INFO
"Restarting protocol %s", p
->name
);
990 else if (p
->disabled
&& !nc
->disabled
)
991 log(L_INFO
"Enabling protocol %s", p
->name
);
992 else if (!p
->disabled
&& nc
->disabled
)
993 log(L_INFO
"Disabling protocol %s", p
->name
);
995 p
->down_code
= nc
->disabled
? PDC_CF_DISABLE
: PDC_CF_RESTART
;
998 else if (!new->shutdown
)
1000 log(L_INFO
"Removing protocol %s", p
->name
);
1001 p
->down_code
= PDC_CF_REMOVE
;
1004 else /* global shutdown */
1006 p
->down_code
= PDC_CMD_SHUTDOWN
;
1010 p
->reconfiguring
= 1;
1011 config_add_obstacle(old
);
1012 proto_rethink_goal(p
);
1016 struct proto
*first_dev_proto
= NULL
;
1018 n
= NODE
&(proto_list
.head
);
1019 WALK_LIST(nc
, new->protos
)
1022 /* Not a first-time configuration */
1024 log(L_INFO
"Adding protocol %s", nc
->name
);
1026 p
= proto_init(nc
, n
);
1029 if (p
->proto
== &proto_unix_iface
)
1030 first_dev_proto
= p
;
1035 DBG("Protocol start\n");
1037 /* Start device protocol first */
1038 if (first_dev_proto
)
1039 proto_rethink_goal(first_dev_proto
);
1041 /* Determine router ID for the first time - it has to be here and not in
1042 global_commit() because it is postponed after start of device protocol */
1043 if (!config
->router_id
)
1045 config
->router_id
= if_choose_router_id(config
->router_id_from
, 0);
1046 if (!config
->router_id
)
1047 die("Cannot determine router ID, please configure it manually");
1050 /* Start all new protocols */
1051 WALK_LIST_DELSAFE(p
, n
, proto_list
)
1052 proto_rethink_goal(p
);
1056 proto_rethink_goal(struct proto
*p
)
1061 if (p
->reconfiguring
&& !p
->active
)
1063 struct proto_config
*nc
= p
->cf_new
;
1064 node
*n
= p
->n
.prev
;
1065 DBG("%s has shut down for reconfiguration\n", p
->name
);
1066 p
->cf
->proto
= NULL
;
1067 config_del_obstacle(p
->cf
->global
);
1068 proto_remove_channels(p
);
1071 mb_free(p
->message
);
1075 p
= proto_init(nc
, n
);
1078 /* Determine what state we want to reach */
1079 if (p
->disabled
|| p
->reconfiguring
)
1090 DBG("Kicking %s up\n", p
->name
);
1093 proto_notify_state(p
, (q
->start
? q
->start(p
) : PS_UP
));
1098 if (p
->proto_state
== PS_START
|| p
->proto_state
== PS_UP
)
1101 DBG("Kicking %s down\n", p
->name
);
1102 PD(p
, "Shutting down");
1103 proto_notify_state(p
, (q
->shutdown
? q
->shutdown(p
) : PS_DOWN
));
1110 * DOC: Graceful restart recovery
1112 * Graceful restart of a router is a process when the routing plane (e.g. BIRD)
1113 * restarts but both the forwarding plane (e.g kernel routing table) and routing
1114 * neighbors keep proper routes, and therefore uninterrupted packet forwarding
1117 * BIRD implements graceful restart recovery by deferring export of routes to
1118 * protocols until routing tables are refilled with the expected content. After
1119 * start, protocols generate routes as usual, but routes are not propagated to
1120 * them, until protocols report that they generated all routes. After that,
1121 * graceful restart recovery is finished and the export (and the initial feed)
1122 * to protocols is enabled.
1124 * When graceful restart recovery need is detected during initialization, then
1125 * enabled protocols are marked with @gr_recovery flag before start. Such
1126 * protocols then decide how to proceed with graceful restart, participation is
1127 * voluntary. Protocols could lock the recovery for each channel by function
1128 * channel_graceful_restart_lock() (state stored in @gr_lock flag), which means
1129 * that they want to postpone the end of the recovery until they converge and
1130 * then unlock it. They also could set @gr_wait before advancing to %PS_UP,
1131 * which means that the core should defer route export to that channel until
1132 * the end of the recovery. This should be done by protocols that expect their
1133 * neigbors to keep the proper routes (kernel table, BGP sessions with BGP
1134 * graceful restart capability).
1136 * The graceful restart recovery is finished when either all graceful restart
1137 * locks are unlocked or when graceful restart wait timer fires.
1141 static void graceful_restart_done(timer
*t
);
1144 * graceful_restart_recovery - request initial graceful restart recovery
1146 * Called by the platform initialization code if the need for recovery
1147 * after graceful restart is detected during boot. Have to be called
1148 * before protos_commit().
1151 graceful_restart_recovery(void)
1153 graceful_restart_state
= GRS_INIT
;
1157 * graceful_restart_init - initialize graceful restart
1159 * When graceful restart recovery was requested, the function starts an active
1160 * phase of the recovery and initializes graceful restart wait timer. The
1161 * function have to be called after protos_commit().
1164 graceful_restart_init(void)
1166 if (!graceful_restart_state
)
1169 log(L_INFO
"Graceful restart started");
1171 if (!graceful_restart_locks
)
1173 graceful_restart_done(NULL
);
1177 graceful_restart_state
= GRS_ACTIVE
;
1178 gr_wait_timer
= tm_new_init(proto_pool
, graceful_restart_done
, NULL
, 0, 0);
1179 tm_start(gr_wait_timer
, config
->gr_wait S
);
1183 * graceful_restart_done - finalize graceful restart
1186 * When there are no locks on graceful restart, the functions finalizes the
1187 * graceful restart recovery. Protocols postponing route export until the end of
1188 * the recovery are awakened and the export to them is enabled. All other
1189 * related state is cleared. The function is also called when the graceful
1190 * restart wait timer fires (but there are still some locks).
1193 graceful_restart_done(timer
*t UNUSED
)
1195 log(L_INFO
"Graceful restart done");
1196 graceful_restart_state
= GRS_DONE
;
1199 WALK_LIST(p
, proto_list
)
1201 if (!p
->gr_recovery
)
1205 WALK_LIST(c
, p
->channels
)
1207 /* Resume postponed export of routes */
1208 if ((c
->channel_state
== CS_UP
) && c
->gr_wait
&& c
->proto
->rt_notify
)
1209 channel_start_export(c
);
1219 graceful_restart_locks
= 0;
1223 graceful_restart_show_status(void)
1225 if (graceful_restart_state
!= GRS_ACTIVE
)
1228 cli_msg(-24, "Graceful restart recovery in progress");
1229 cli_msg(-24, " Waiting for %d channels to recover", graceful_restart_locks
);
1230 cli_msg(-24, " Wait timer is %t/%u", tm_remains(gr_wait_timer
), config
->gr_wait
);
1234 * channel_graceful_restart_lock - lock graceful restart by channel
1235 * @p: channel instance
1237 * This function allows a protocol to postpone the end of graceful restart
1238 * recovery until it converges. The lock is removed when the protocol calls
1239 * channel_graceful_restart_unlock() or when the channel is closed.
1241 * The function have to be called during the initial phase of graceful restart
1242 * recovery and only for protocols that are part of graceful restart (i.e. their
1243 * @gr_recovery is set), which means it should be called from protocol start
1247 channel_graceful_restart_lock(struct channel
*c
)
1249 ASSERT(graceful_restart_state
== GRS_INIT
);
1250 ASSERT(c
->proto
->gr_recovery
);
1256 graceful_restart_locks
++;
1260 * channel_graceful_restart_unlock - unlock graceful restart by channel
1261 * @p: channel instance
1263 * This function unlocks a lock from channel_graceful_restart_lock(). It is also
1264 * automatically called when the lock holding protocol went down.
1267 channel_graceful_restart_unlock(struct channel
*c
)
1273 graceful_restart_locks
--;
1275 if ((graceful_restart_state
== GRS_ACTIVE
) && !graceful_restart_locks
)
1276 tm_start(gr_wait_timer
, 0);
1282 * protos_dump_all - dump status of all protocols
1284 * This function dumps status of all existing protocol instances to the
1285 * debug output. It involves printing of general status information
1286 * such as protocol states, its position on the protocol lists
1287 * and also calling of a dump() hook of the protocol to print
1291 protos_dump_all(void)
1293 debug("Protocols:\n");
1296 WALK_LIST(p
, proto_list
)
1298 debug(" protocol %s state %s\n", p
->name
, p_states
[p
->proto_state
]);
1301 WALK_LIST(c
, p
->channels
)
1303 debug("\tTABLE %s\n", c
->table
->name
);
1305 debug("\tInput filter: %s\n", filter_name(c
->in_filter
));
1307 debug("\tOutput filter: %s\n", filter_name(c
->out_filter
));
1310 if (p
->proto
->dump
&& (p
->proto_state
!= PS_DOWN
))
1316 * proto_build - make a single protocol available
1319 * After the platform specific initialization code uses protos_build()
1320 * to add all the standard protocols, it should call proto_build() for
1321 * all platform specific protocols to inform the core that they exist.
1324 proto_build(struct protocol
*p
)
1326 add_tail(&protocol_list
, &p
->n
);
1328 ASSERT(!class_to_protocol
[p
->class]);
1329 class_to_protocol
[p
->class] = p
;
1332 /* FIXME: convert this call to some protocol hook */
1333 extern void bfd_init_all(void);
1336 * protos_build - build a protocol list
1338 * This function is called during BIRD startup to insert
1339 * all standard protocols to the global protocol list. Insertion
1340 * of platform specific protocols (such as the kernel syncer)
1341 * is in the domain of competence of the platform dependent
1347 init_list(&proto_list
);
1348 init_list(&protocol_list
);
1350 proto_build(&proto_device
);
1352 proto_build(&proto_radv
);
1355 proto_build(&proto_rip
);
1357 #ifdef CONFIG_STATIC
1358 proto_build(&proto_static
);
1361 proto_build(&proto_mrt
);
1364 proto_build(&proto_ospf
);
1367 proto_build(&proto_pipe
);
1370 proto_build(&proto_bgp
);
1373 proto_build(&proto_bfd
);
1377 proto_build(&proto_babel
);
1380 proto_build(&proto_rpki
);
1383 proto_build(&proto_perf
);
1386 proto_pool
= rp_new(&root_pool
, "Protocols");
1387 proto_shutdown_timer
= tm_new(proto_pool
);
1388 proto_shutdown_timer
->hook
= proto_shutdown_loop
;
1392 /* Temporary hack to propagate restart to BGP */
1396 proto_shutdown_loop(timer
*t UNUSED
)
1398 struct proto
*p
, *p_next
;
1400 WALK_LIST_DELSAFE(p
, p_next
, proto_list
)
1403 proto_restart
= (p
->down_sched
== PDS_RESTART
);
1406 proto_rethink_goal(p
);
1410 proto_rethink_goal(p
);
1416 proto_schedule_down(struct proto
*p
, byte restart
, byte code
)
1418 /* Does not work for other states (even PS_START) */
1419 ASSERT(p
->proto_state
== PS_UP
);
1421 /* Scheduled restart may change to shutdown, but not otherwise */
1422 if (p
->down_sched
== PDS_DISABLE
)
1425 p
->down_sched
= restart
? PDS_RESTART
: PDS_DISABLE
;
1426 p
->down_code
= code
;
1427 tm_start_max(proto_shutdown_timer
, restart
? 250 MS
: 0);
1431 * proto_set_message - set administrative message to protocol
1434 * @len: message length (-1 for NULL-terminated string)
1436 * The function sets administrative message (string) related to protocol state
1437 * change. It is called by the nest code for manual enable/disable/restart
1438 * commands all routes to the protocol, and by protocol-specific code when the
1439 * protocol state change is initiated by the protocol. Using NULL message clears
1440 * the last message. The message string may be either NULL-terminated or with an
1444 proto_set_message(struct proto
*p
, char *msg
, int len
)
1446 mb_free(p
->message
);
1458 p
->message
= mb_alloc(proto_pool
, len
+ 1);
1459 memcpy(p
->message
, msg
, len
);
1460 p
->message
[len
] = 0;
1465 channel_limit_name(struct channel_limit
*l
)
1467 const char *actions
[] = {
1468 [PLA_WARN
] = "warn",
1469 [PLA_BLOCK
] = "block",
1470 [PLA_RESTART
] = "restart",
1471 [PLA_DISABLE
] = "disable",
1474 return actions
[l
->action
];
1478 * channel_notify_limit: notify about limit hit and take appropriate action
1480 * @l: limit being hit
1481 * @dir: limit direction (PLD_*)
1482 * @rt_count: the number of routes
1484 * The function is called by the route processing core when limit @l
1485 * is breached. It activates the limit and tooks appropriate action
1486 * according to @l->action.
1489 channel_notify_limit(struct channel
*c
, struct channel_limit
*l
, int dir
, u32 rt_count
)
1491 const char *dir_name
[PLD_MAX
] = { "receive", "import" , "export" };
1492 const byte dir_down
[PLD_MAX
] = { PDC_RX_LIMIT_HIT
, PDC_IN_LIMIT_HIT
, PDC_OUT_LIMIT_HIT
};
1493 struct proto
*p
= c
->proto
;
1495 if (l
->state
== PLS_BLOCKED
)
1498 /* For warning action, we want the log message every time we hit the limit */
1499 if (!l
->state
|| ((l
->action
== PLA_WARN
) && (rt_count
== l
->limit
)))
1500 log(L_WARN
"Protocol %s hits route %s limit (%d), action: %s",
1501 p
->name
, dir_name
[dir
], l
->limit
, channel_limit_name(l
));
1506 l
->state
= PLS_ACTIVE
;
1510 l
->state
= PLS_BLOCKED
;
1515 l
->state
= PLS_BLOCKED
;
1516 if (p
->proto_state
== PS_UP
)
1517 proto_schedule_down(p
, l
->action
== PLA_RESTART
, dir_down
[dir
]);
1523 channel_verify_limits(struct channel
*c
)
1525 struct channel_limit
*l
;
1526 u32 all_routes
= c
->stats
.imp_routes
+ c
->stats
.filt_routes
;
1529 if (l
->action
&& (all_routes
> l
->limit
))
1530 channel_notify_limit(c
, l
, PLD_RX
, all_routes
);
1533 if (l
->action
&& (c
->stats
.imp_routes
> l
->limit
))
1534 channel_notify_limit(c
, l
, PLD_IN
, c
->stats
.imp_routes
);
1537 if (l
->action
&& (c
->stats
.exp_routes
> l
->limit
))
1538 channel_notify_limit(c
, l
, PLD_OUT
, c
->stats
.exp_routes
);
1542 channel_reset_limit(struct channel_limit
*l
)
1545 l
->state
= PLS_INITIAL
;
1549 proto_do_start(struct proto
*p
)
1553 ev_schedule(p
->event
);
1557 proto_do_up(struct proto
*p
)
1559 if (!p
->main_source
)
1561 p
->main_source
= rt_get_source(p
, 0);
1562 rt_lock_source(p
->main_source
);
1565 proto_start_channels(p
);
1569 proto_do_pause(struct proto
*p
)
1571 proto_pause_channels(p
);
1575 proto_do_stop(struct proto
*p
)
1581 ev_schedule(p
->event
);
1585 rt_unlock_source(p
->main_source
);
1586 p
->main_source
= NULL
;
1589 proto_stop_channels(p
);
1593 proto_do_down(struct proto
*p
)
1600 /* Shutdown is finished in the protocol event */
1601 if (proto_is_done(p
))
1602 ev_schedule(p
->event
);
1608 * proto_notify_state - notify core about protocol state change
1609 * @p: protocol the state of which has changed
1610 * @ps: the new status
1612 * Whenever a state of a protocol changes due to some event internal
1613 * to the protocol (i.e., not inside a start() or shutdown() hook),
1614 * it should immediately notify the core about the change by calling
1615 * proto_notify_state() which will write the new state to the &proto
1616 * structure and take all the actions necessary to adapt to the new
1617 * state. State change to PS_DOWN immediately frees resources of protocol
1618 * and might execute start callback of protocol; therefore,
1619 * it should be used at tail positions of protocol callbacks.
1622 proto_notify_state(struct proto
*p
, uint state
)
1624 uint ps
= p
->proto_state
;
1626 DBG("%s reporting state transition %s -> %s\n", p
->name
, p_states
[ps
], p_states
[state
]);
1630 p
->proto_state
= state
;
1631 p
->last_state_change
= current_time();
1636 ASSERT(ps
== PS_DOWN
|| ps
== PS_UP
);
1645 ASSERT(ps
== PS_DOWN
|| ps
== PS_START
);
1654 ASSERT(ps
== PS_START
|| ps
== PS_UP
);
1667 bug("%s: Invalid state %d", p
->name
, ps
);
1670 proto_log_state_change(p
);
1678 proto_state_name(struct proto
*p
)
1680 switch (p
->proto_state
)
1682 case PS_DOWN
: return p
->active
? "flush" : "down";
1683 case PS_START
: return "start";
1684 case PS_UP
: return "up";
1685 case PS_STOP
: return "stop";
1686 default: return "???";
1691 channel_show_stats(struct channel
*c
)
1693 struct proto_stats
*s
= &c
->stats
;
1695 if (c
->in_keep_filtered
)
1696 cli_msg(-1006, " Routes: %u imported, %u filtered, %u exported, %u preferred",
1697 s
->imp_routes
, s
->filt_routes
, s
->exp_routes
, s
->pref_routes
);
1699 cli_msg(-1006, " Routes: %u imported, %u exported, %u preferred",
1700 s
->imp_routes
, s
->exp_routes
, s
->pref_routes
);
1702 cli_msg(-1006, " Route change stats: received rejected filtered ignored accepted");
1703 cli_msg(-1006, " Import updates: %10u %10u %10u %10u %10u",
1704 s
->imp_updates_received
, s
->imp_updates_invalid
,
1705 s
->imp_updates_filtered
, s
->imp_updates_ignored
,
1706 s
->imp_updates_accepted
);
1707 cli_msg(-1006, " Import withdraws: %10u %10u --- %10u %10u",
1708 s
->imp_withdraws_received
, s
->imp_withdraws_invalid
,
1709 s
->imp_withdraws_ignored
, s
->imp_withdraws_accepted
);
1710 cli_msg(-1006, " Export updates: %10u %10u %10u --- %10u",
1711 s
->exp_updates_received
, s
->exp_updates_rejected
,
1712 s
->exp_updates_filtered
, s
->exp_updates_accepted
);
1713 cli_msg(-1006, " Export withdraws: %10u --- --- --- %10u",
1714 s
->exp_withdraws_received
, s
->exp_withdraws_accepted
);
1718 channel_show_limit(struct channel_limit
*l
, const char *dsc
)
1723 cli_msg(-1006, " %-16s%d%s", dsc
, l
->limit
, l
->state
? " [HIT]" : "");
1724 cli_msg(-1006, " Action: %s", channel_limit_name(l
));
1728 channel_show_info(struct channel
*c
)
1730 cli_msg(-1006, " Channel %s", c
->name
);
1731 cli_msg(-1006, " State: %s", c_states
[c
->channel_state
]);
1732 cli_msg(-1006, " Table: %s", c
->table
->name
);
1733 cli_msg(-1006, " Preference: %d", c
->preference
);
1734 cli_msg(-1006, " Input filter: %s", filter_name(c
->in_filter
));
1735 cli_msg(-1006, " Output filter: %s", filter_name(c
->out_filter
));
1737 if (graceful_restart_state
== GRS_ACTIVE
)
1738 cli_msg(-1006, " GR recovery: %s%s",
1739 c
->gr_lock
? " pending" : "",
1740 c
->gr_wait
? " waiting" : "");
1742 channel_show_limit(&c
->rx_limit
, "Receive limit:");
1743 channel_show_limit(&c
->in_limit
, "Import limit:");
1744 channel_show_limit(&c
->out_limit
, "Export limit:");
1746 if (c
->channel_state
!= CS_DOWN
)
1747 channel_show_stats(c
);
1751 proto_cmd_show(struct proto
*p
, uintptr_t verbose
, int cnt
)
1753 byte buf
[256], tbuf
[TM_DATETIME_BUFFER_SIZE
];
1755 /* First protocol - show header */
1757 cli_msg(-2002, "%-10s %-10s %-10s %-6s %-12s %s",
1758 "Name", "Proto", "Table", "State", "Since", "Info");
1761 if (p
->proto
->get_status
)
1762 p
->proto
->get_status(p
, buf
);
1763 tm_format_time(tbuf
, &config
->tf_proto
, p
->last_state_change
);
1764 cli_msg(-1002, "%-10s %-10s %-10s %-6s %-12s %s",
1767 p
->main_channel
? p
->main_channel
->table
->name
: "---",
1768 proto_state_name(p
),
1775 cli_msg(-1006, " Description: %s", p
->cf
->dsc
);
1777 cli_msg(-1006, " Message: %s", p
->message
);
1778 if (p
->cf
->router_id
)
1779 cli_msg(-1006, " Router ID: %R", p
->cf
->router_id
);
1781 cli_msg(-1006, " VRF: %s", p
->vrf
->name
);
1783 if (p
->proto
->show_proto_info
)
1784 p
->proto
->show_proto_info(p
);
1788 WALK_LIST(c
, p
->channels
)
1789 channel_show_info(c
);
1797 proto_cmd_disable(struct proto
*p
, uintptr_t arg
, int cnt UNUSED
)
1801 cli_msg(-8, "%s: already disabled", p
->name
);
1805 log(L_INFO
"Disabling protocol %s", p
->name
);
1807 p
->down_code
= PDC_CMD_DISABLE
;
1808 proto_set_message(p
, (char *) arg
, -1);
1809 proto_rethink_goal(p
);
1810 cli_msg(-9, "%s: disabled", p
->name
);
1814 proto_cmd_enable(struct proto
*p
, uintptr_t arg
, int cnt UNUSED
)
1818 cli_msg(-10, "%s: already enabled", p
->name
);
1822 log(L_INFO
"Enabling protocol %s", p
->name
);
1824 proto_set_message(p
, (char *) arg
, -1);
1825 proto_rethink_goal(p
);
1826 cli_msg(-11, "%s: enabled", p
->name
);
1830 proto_cmd_restart(struct proto
*p
, uintptr_t arg
, int cnt UNUSED
)
1834 cli_msg(-8, "%s: already disabled", p
->name
);
1838 log(L_INFO
"Restarting protocol %s", p
->name
);
1840 p
->down_code
= PDC_CMD_RESTART
;
1841 proto_set_message(p
, (char *) arg
, -1);
1842 proto_rethink_goal(p
);
1844 proto_rethink_goal(p
);
1845 cli_msg(-12, "%s: restarted", p
->name
);
1849 proto_cmd_reload(struct proto
*p
, uintptr_t dir
, int cnt UNUSED
)
1855 cli_msg(-8, "%s: already disabled", p
->name
);
1859 /* If the protocol in not UP, it has no routes */
1860 if (p
->proto_state
!= PS_UP
)
1863 /* All channels must support reload */
1864 if (dir
!= CMD_RELOAD_OUT
)
1865 WALK_LIST(c
, p
->channels
)
1866 if (!channel_reloadable(c
))
1868 cli_msg(-8006, "%s: reload failed", p
->name
);
1872 log(L_INFO
"Reloading protocol %s", p
->name
);
1874 /* re-importing routes */
1875 if (dir
!= CMD_RELOAD_OUT
)
1876 WALK_LIST(c
, p
->channels
)
1877 channel_request_reload(c
);
1879 /* re-exporting routes */
1880 if (dir
!= CMD_RELOAD_IN
)
1881 WALK_LIST(c
, p
->channels
)
1882 channel_request_feeding(c
);
1884 cli_msg(-15, "%s: reloading", p
->name
);
1888 proto_cmd_debug(struct proto
*p
, uintptr_t mask
, int cnt UNUSED
)
1894 proto_cmd_mrtdump(struct proto
*p
, uintptr_t mask
, int cnt UNUSED
)
1900 proto_apply_cmd_symbol(struct symbol
*s
, void (* cmd
)(struct proto
*, uintptr_t, int), uintptr_t arg
)
1902 if (s
->class != SYM_PROTO
)
1904 cli_msg(9002, "%s is not a protocol", s
->name
);
1908 cmd(s
->proto
->proto
, arg
, 0);
1913 proto_apply_cmd_patt(char *patt
, void (* cmd
)(struct proto
*, uintptr_t, int), uintptr_t arg
)
1918 WALK_LIST(p
, proto_list
)
1919 if (!patt
|| patmatch(patt
, p
->name
))
1923 cli_msg(8003, "No protocols match");
1929 proto_apply_cmd(struct proto_spec ps
, void (* cmd
)(struct proto
*, uintptr_t, int),
1930 int restricted
, uintptr_t arg
)
1932 if (restricted
&& cli_access_restricted())
1936 proto_apply_cmd_patt(ps
.ptr
, cmd
, arg
);
1938 proto_apply_cmd_symbol(ps
.ptr
, cmd
, arg
);
1942 proto_get_named(struct symbol
*sym
, struct protocol
*pr
)
1944 struct proto
*p
, *q
;
1948 if (sym
->class != SYM_PROTO
)
1949 cf_error("%s: Not a protocol", sym
->name
);
1951 p
= sym
->proto
->proto
;
1952 if (!p
|| p
->proto
!= pr
)
1953 cf_error("%s: Not a %s protocol", sym
->name
, pr
->name
);
1958 WALK_LIST(q
, proto_list
)
1959 if ((q
->proto
== pr
) && (q
->proto_state
!= PS_DOWN
))
1962 cf_error("There are multiple %s protocols running", pr
->name
);
1966 cf_error("There is no %s protocol running", pr
->name
);