2 * Copyright (C) 2016 by Open Source Routing.
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 static void ldp_af_iface_config_write(struct vty
*, int);
36 static void ldp_af_config_write(struct vty
*, int, struct ldpd_conf
*,
37 struct ldpd_af_conf
*);
38 static void ldp_l2vpn_pw_config_write(struct vty
*, struct l2vpn_pw
*);
39 static int ldp_vty_get_af(struct vty
*);
40 static int ldp_iface_is_configured(struct ldpd_conf
*, const char *);
41 static int ldp_vty_nbr_session_holdtime(struct vty
*, struct vty_arg
*[]);
42 static int ldp_vty_af_session_holdtime(struct vty
*, struct vty_arg
*[]);
44 struct cmd_node ldp_node
=
51 struct cmd_node ldp_ipv4_node
=
54 "%s(config-ldp-af)# ",
58 struct cmd_node ldp_ipv6_node
=
61 "%s(config-ldp-af)# ",
65 struct cmd_node ldp_ipv4_iface_node
=
68 "%s(config-ldp-af-if)# ",
72 struct cmd_node ldp_ipv6_iface_node
=
75 "%s(config-ldp-af-if)# ",
79 struct cmd_node ldp_l2vpn_node
=
86 struct cmd_node ldp_pseudowire_node
=
89 "%s(config-l2vpn-pw)# ",
94 ldp_get_address(const char *str
, int *af
, union ldpd_addr
*addr
)
96 memset(addr
, 0, sizeof(*addr
));
98 if (inet_pton(AF_INET
, str
, &addr
->v4
) == 1) {
103 if (inet_pton(AF_INET6
, str
, &addr
->v6
) == 1) {
112 ldp_af_iface_config_write(struct vty
*vty
, int af
)
117 RB_FOREACH(iface
, iface_head
, &ldpd_conf
->iface_tree
) {
118 ia
= iface_af_get(iface
, af
);
122 vty_out(vty
, " !%s", VTY_NEWLINE
);
123 vty_out(vty
, " interface %s%s", iface
->name
, VTY_NEWLINE
);
125 if (ia
->hello_holdtime
!= LINK_DFLT_HOLDTIME
&&
126 ia
->hello_holdtime
!= 0)
127 vty_out(vty
, " discovery hello holdtime %u%s",
128 ia
->hello_holdtime
, VTY_NEWLINE
);
129 if (ia
->hello_interval
!= DEFAULT_HELLO_INTERVAL
&&
130 ia
->hello_interval
!= 0)
131 vty_out(vty
, " discovery hello interval %u%s",
132 ia
->hello_interval
, VTY_NEWLINE
);
137 ldp_af_config_write(struct vty
*vty
, int af
, struct ldpd_conf
*conf
,
138 struct ldpd_af_conf
*af_conf
)
142 if (!(af_conf
->flags
& F_LDPD_AF_ENABLED
))
145 vty_out(vty
, " !%s", VTY_NEWLINE
);
146 vty_out(vty
, " address-family %s%s", af_name(af
), VTY_NEWLINE
);
148 if (af_conf
->lhello_holdtime
!= LINK_DFLT_HOLDTIME
&&
149 af_conf
->lhello_holdtime
!= 0 )
150 vty_out(vty
, " discovery hello holdtime %u%s",
151 af_conf
->lhello_holdtime
, VTY_NEWLINE
);
152 if (af_conf
->lhello_interval
!= DEFAULT_HELLO_INTERVAL
&&
153 af_conf
->lhello_interval
!= 0)
154 vty_out(vty
, " discovery hello interval %u%s",
155 af_conf
->lhello_interval
, VTY_NEWLINE
);
157 if (af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) {
158 vty_out(vty
, " discovery targeted-hello accept");
159 if (af_conf
->acl_thello_accept_from
[0] != '\0')
160 vty_out(vty
, " from %s",
161 af_conf
->acl_thello_accept_from
);
162 vty_out(vty
, "%s", VTY_NEWLINE
);
165 if (af_conf
->thello_holdtime
!= TARGETED_DFLT_HOLDTIME
&&
166 af_conf
->thello_holdtime
!= 0)
167 vty_out(vty
, " discovery targeted-hello holdtime %u%s",
168 af_conf
->thello_holdtime
, VTY_NEWLINE
);
169 if (af_conf
->thello_interval
!= DEFAULT_HELLO_INTERVAL
&&
170 af_conf
->thello_interval
!= 0)
171 vty_out(vty
, " discovery targeted-hello interval %u%s",
172 af_conf
->thello_interval
, VTY_NEWLINE
);
174 if (ldp_addrisset(af
, &af_conf
->trans_addr
))
175 vty_out(vty
, " discovery transport-address %s%s",
176 log_addr(af
, &af_conf
->trans_addr
), VTY_NEWLINE
);
178 vty_out(vty
, " ! Incomplete config, specify a discovery "
179 "transport-address%s", VTY_NEWLINE
);
181 if ((af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
) ||
182 af_conf
->acl_label_allocate_for
[0] != '\0') {
183 vty_out(vty
, " label local allocate");
184 if (af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
)
185 vty_out(vty
, " host-routes");
187 vty_out(vty
, " for %s",
188 af_conf
->acl_label_allocate_for
);
189 vty_out(vty
, "%s", VTY_NEWLINE
);
192 if (af_conf
->acl_label_advertise_for
[0] != '\0' ||
193 af_conf
->acl_label_advertise_to
[0] != '\0') {
194 vty_out(vty
, " label local advertise");
195 if (af_conf
->acl_label_advertise_to
[0] != '\0')
196 vty_out(vty
, " to %s",
197 af_conf
->acl_label_advertise_to
);
198 if (af_conf
->acl_label_advertise_for
[0] != '\0')
199 vty_out(vty
, " for %s",
200 af_conf
->acl_label_advertise_for
);
201 vty_out(vty
, "%s", VTY_NEWLINE
);
204 if (af_conf
->flags
& F_LDPD_AF_EXPNULL
) {
205 vty_out(vty
, " label local advertise explicit-null");
206 if (af_conf
->acl_label_expnull_for
[0] != '\0')
207 vty_out(vty
, " for %s",
208 af_conf
->acl_label_expnull_for
);
209 vty_out(vty
, "%s", VTY_NEWLINE
);
212 if (af_conf
->acl_label_accept_for
[0] != '\0' ||
213 af_conf
->acl_label_accept_from
[0] != '\0') {
214 vty_out(vty
, " label remote accept");
215 if (af_conf
->acl_label_accept_from
[0] != '\0')
216 vty_out(vty
, " from %s",
217 af_conf
->acl_label_accept_from
);
218 if (af_conf
->acl_label_accept_for
[0] != '\0')
219 vty_out(vty
, " for %s",
220 af_conf
->acl_label_accept_for
);
221 vty_out(vty
, "%s", VTY_NEWLINE
);
224 if (af_conf
->flags
& F_LDPD_AF_NO_GTSM
)
225 vty_out(vty
, " ttl-security disable%s", VTY_NEWLINE
);
227 if (af_conf
->keepalive
!= DEFAULT_KEEPALIVE
)
228 vty_out(vty
, " session holdtime %u%s", af_conf
->keepalive
,
231 RB_FOREACH(tnbr
, tnbr_head
, &ldpd_conf
->tnbr_tree
) {
232 if (tnbr
->af
== af
) {
233 vty_out(vty
, " !%s", VTY_NEWLINE
);
234 vty_out(vty
, " neighbor %s targeted%s",
235 log_addr(tnbr
->af
, &tnbr
->addr
), VTY_NEWLINE
);
239 ldp_af_iface_config_write(vty
, af
);
241 vty_out(vty
, " !%s", VTY_NEWLINE
);
245 ldp_config_write(struct vty
*vty
)
247 struct nbr_params
*nbrp
;
249 if (!(ldpd_conf
->flags
& F_LDPD_ENABLED
))
252 vty_out(vty
, "mpls ldp%s", VTY_NEWLINE
);
254 if (ldpd_conf
->rtr_id
.s_addr
!= 0)
255 vty_out(vty
, " router-id %s%s",
256 inet_ntoa(ldpd_conf
->rtr_id
), VTY_NEWLINE
);
258 if (ldpd_conf
->lhello_holdtime
!= LINK_DFLT_HOLDTIME
&&
259 ldpd_conf
->lhello_holdtime
!= 0)
260 vty_out(vty
, " discovery hello holdtime %u%s",
261 ldpd_conf
->lhello_holdtime
, VTY_NEWLINE
);
262 if (ldpd_conf
->lhello_interval
!= DEFAULT_HELLO_INTERVAL
&&
263 ldpd_conf
->lhello_interval
!= 0)
264 vty_out(vty
, " discovery hello interval %u%s",
265 ldpd_conf
->lhello_interval
, VTY_NEWLINE
);
267 if (ldpd_conf
->thello_holdtime
!= TARGETED_DFLT_HOLDTIME
&&
268 ldpd_conf
->thello_holdtime
!= 0)
269 vty_out(vty
, " discovery targeted-hello holdtime %u%s",
270 ldpd_conf
->thello_holdtime
, VTY_NEWLINE
);
271 if (ldpd_conf
->thello_interval
!= DEFAULT_HELLO_INTERVAL
&&
272 ldpd_conf
->thello_interval
!= 0)
273 vty_out(vty
, " discovery targeted-hello interval %u%s",
274 ldpd_conf
->thello_interval
, VTY_NEWLINE
);
276 if (ldpd_conf
->trans_pref
== DUAL_STACK_LDPOV4
)
277 vty_out(vty
, " dual-stack transport-connection prefer ipv4%s",
280 if (ldpd_conf
->flags
& F_LDPD_DS_CISCO_INTEROP
)
281 vty_out(vty
, " dual-stack cisco-interop%s", VTY_NEWLINE
);
283 RB_FOREACH(nbrp
, nbrp_head
, &ldpd_conf
->nbrp_tree
) {
284 if (nbrp
->flags
& F_NBRP_KEEPALIVE
)
285 vty_out(vty
, " neighbor %s session holdtime %u%s",
286 inet_ntoa(nbrp
->lsr_id
), nbrp
->keepalive
,
289 if (nbrp
->flags
& F_NBRP_GTSM
) {
290 if (nbrp
->gtsm_enabled
)
291 vty_out(vty
, " neighbor %s ttl-security hops "
292 "%u%s", inet_ntoa(nbrp
->lsr_id
),
293 nbrp
->gtsm_hops
, VTY_NEWLINE
);
295 vty_out(vty
, " neighbor %s ttl-security "
296 "disable%s", inet_ntoa(nbrp
->lsr_id
),
300 if (nbrp
->auth
.method
== AUTH_MD5SIG
)
301 vty_out(vty
, " neighbor %s password %s%s",
302 inet_ntoa(nbrp
->lsr_id
), nbrp
->auth
.md5key
,
306 ldp_af_config_write(vty
, AF_INET
, ldpd_conf
, &ldpd_conf
->ipv4
);
307 ldp_af_config_write(vty
, AF_INET6
, ldpd_conf
, &ldpd_conf
->ipv6
);
308 vty_out(vty
, " !%s", VTY_NEWLINE
);
309 vty_out(vty
, "!%s", VTY_NEWLINE
);
315 ldp_l2vpn_pw_config_write(struct vty
*vty
, struct l2vpn_pw
*pw
)
317 int missing_lsrid
= 0;
318 int missing_pwid
= 0;
320 vty_out(vty
, " !%s", VTY_NEWLINE
);
321 vty_out(vty
, " member pseudowire %s%s", pw
->ifname
, VTY_NEWLINE
);
323 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
)
324 vty_out(vty
, " neighbor lsr-id %s%s", inet_ntoa(pw
->lsr_id
),
329 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
330 vty_out(vty
, " neighbor address %s%s", log_addr(pw
->af
,
331 &pw
->addr
), VTY_NEWLINE
);
334 vty_out(vty
, " pw-id %u%s", pw
->pwid
, VTY_NEWLINE
);
338 if (!(pw
->flags
& F_PW_CWORD_CONF
))
339 vty_out(vty
, " control-word exclude%s", VTY_NEWLINE
);
341 if (!(pw
->flags
& F_PW_STATUSTLV_CONF
))
342 vty_out(vty
, " pw-status disable%s", VTY_NEWLINE
);
345 vty_out(vty
, " ! Incomplete config, specify a neighbor "
346 "lsr-id%s", VTY_NEWLINE
);
348 vty_out(vty
, " ! Incomplete config, specify a pw-id%s",
353 ldp_l2vpn_config_write(struct vty
*vty
)
356 struct l2vpn_if
*lif
;
359 RB_FOREACH(l2vpn
, l2vpn_head
, &ldpd_conf
->l2vpn_tree
) {
360 vty_out(vty
, "l2vpn %s type vpls%s", l2vpn
->name
, VTY_NEWLINE
);
362 if (l2vpn
->pw_type
!= DEFAULT_PW_TYPE
)
363 vty_out(vty
, " vc type ethernet-tagged%s", VTY_NEWLINE
);
365 if (l2vpn
->mtu
!= DEFAULT_L2VPN_MTU
)
366 vty_out(vty
, " mtu %u%s", l2vpn
->mtu
, VTY_NEWLINE
);
368 if (l2vpn
->br_ifname
[0] != '\0')
369 vty_out(vty
, " bridge %s%s", l2vpn
->br_ifname
,
372 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
373 vty_out(vty
, " member interface %s%s", lif
->ifname
,
376 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
377 ldp_l2vpn_pw_config_write(vty
, pw
);
378 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
379 ldp_l2vpn_pw_config_write(vty
, pw
);
381 vty_out(vty
, " !%s", VTY_NEWLINE
);
382 vty_out(vty
, "!%s", VTY_NEWLINE
);
389 ldp_vty_get_af(struct vty
*vty
)
393 case LDP_IPV4_IFACE_NODE
:
396 case LDP_IPV6_IFACE_NODE
:
399 fatalx("ldp_vty_get_af: unexpected node");
404 ldp_iface_is_configured(struct ldpd_conf
*xconf
, const char *ifname
)
408 if (if_lookup_name(xconf
, ifname
))
411 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
412 if (l2vpn_if_find(l2vpn
, ifname
))
414 if (l2vpn_pw_find(l2vpn
, ifname
))
422 ldp_vty_mpls_ldp(struct vty
*vty
, struct vty_arg
*args
[])
426 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
429 vty_conf
->flags
&= ~F_LDPD_ENABLED
;
431 vty
->node
= LDP_NODE
;
432 vty_conf
->flags
|= F_LDPD_ENABLED
;
435 ldp_reload(vty_conf
);
437 return (CMD_SUCCESS
);
441 ldp_vty_address_family(struct vty
*vty
, struct vty_arg
*args
[])
443 struct ldpd_af_conf
*af_conf
;
448 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
449 af_str
= vty_get_arg_value(args
, "address-family");
451 if (strcmp(af_str
, "ipv4") == 0) {
453 af_conf
= &vty_conf
->ipv4
;
454 } else if (strcmp(af_str
, "ipv6") == 0) {
456 af_conf
= &vty_conf
->ipv6
;
458 return (CMD_WARNING
);
461 af_conf
->flags
&= ~F_LDPD_AF_ENABLED
;
462 ldp_reload(vty_conf
);
463 return (CMD_SUCCESS
);
468 vty
->node
= LDP_IPV4_NODE
;
471 vty
->node
= LDP_IPV6_NODE
;
474 fatalx("ldp_vty_address_family: unknown af");
476 af_conf
->flags
|= F_LDPD_AF_ENABLED
;
478 ldp_reload(vty_conf
);
480 return (CMD_SUCCESS
);
484 ldp_vty_disc_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
486 struct ldpd_af_conf
*af_conf
;
492 enum hello_type hello_type
;
493 const char *seconds_str
;
494 const char *hello_type_str
;
497 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
498 seconds_str
= vty_get_arg_value(args
, "seconds");
499 hello_type_str
= vty_get_arg_value(args
, "hello_type");
501 secs
= strtol(seconds_str
, &ep
, 10);
502 if (*ep
!= '\0' || secs
< MIN_HOLDTIME
|| secs
> MAX_HOLDTIME
) {
503 vty_out(vty
, "%% Invalid holdtime%s", VTY_NEWLINE
);
504 return (CMD_WARNING
);
507 if (hello_type_str
[0] == 'h')
508 hello_type
= HELLO_LINK
;
510 hello_type
= HELLO_TARGETED
;
515 switch (hello_type
) {
517 vty_conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
520 vty_conf
->thello_holdtime
=
521 TARGETED_DFLT_HOLDTIME
;
525 switch (hello_type
) {
527 vty_conf
->lhello_holdtime
= secs
;
530 vty_conf
->thello_holdtime
= secs
;
534 ldp_reload(vty_conf
);
538 af
= ldp_vty_get_af(vty
);
539 af_conf
= ldp_af_conf_get(vty_conf
, af
);
542 switch (hello_type
) {
544 af_conf
->lhello_holdtime
= 0;
547 af_conf
->thello_holdtime
= 0;
551 switch (hello_type
) {
553 af_conf
->lhello_holdtime
= secs
;
556 af_conf
->thello_holdtime
= secs
;
560 ldp_reload(vty_conf
);
562 case LDP_IPV4_IFACE_NODE
:
563 case LDP_IPV6_IFACE_NODE
:
564 af
= ldp_vty_get_af(vty
);
565 iface
= VTY_GET_CONTEXT(iface
);
566 VTY_CHECK_CONTEXT(iface
);
568 ia
= iface_af_get(iface
, af
);
570 ia
->hello_holdtime
= 0;
572 ia
->hello_holdtime
= secs
;
574 ldp_reload(vty_conf
);
577 fatalx("ldp_vty_disc_holdtime: unexpected node");
580 return (CMD_SUCCESS
);
584 ldp_vty_disc_interval(struct vty
*vty
, struct vty_arg
*args
[])
586 struct ldpd_af_conf
*af_conf
;
592 enum hello_type hello_type
;
593 const char *seconds_str
;
594 const char *hello_type_str
;
597 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
598 seconds_str
= vty_get_arg_value(args
, "seconds");
599 hello_type_str
= vty_get_arg_value(args
, "hello_type");
601 secs
= strtol(seconds_str
, &ep
, 10);
602 if (*ep
!= '\0' || secs
< MIN_HELLO_INTERVAL
||
603 secs
> MAX_HELLO_INTERVAL
) {
604 vty_out(vty
, "%% Invalid interval%s", VTY_NEWLINE
);
605 return (CMD_WARNING
);
608 if (hello_type_str
[0] == 'h')
609 hello_type
= HELLO_LINK
;
611 hello_type
= HELLO_TARGETED
;
616 switch (hello_type
) {
618 vty_conf
->lhello_interval
= LINK_DFLT_HOLDTIME
;
621 vty_conf
->thello_interval
=
622 TARGETED_DFLT_HOLDTIME
;
626 switch (hello_type
) {
628 vty_conf
->lhello_interval
= secs
;
631 vty_conf
->thello_interval
= secs
;
635 ldp_reload(vty_conf
);
639 af
= ldp_vty_get_af(vty
);
640 af_conf
= ldp_af_conf_get(vty_conf
, af
);
643 switch (hello_type
) {
645 af_conf
->lhello_interval
= 0;
648 af_conf
->thello_interval
= 0;
652 switch (hello_type
) {
654 af_conf
->lhello_interval
= secs
;
657 af_conf
->thello_interval
= secs
;
661 ldp_reload(vty_conf
);
663 case LDP_IPV4_IFACE_NODE
:
664 case LDP_IPV6_IFACE_NODE
:
665 af
= ldp_vty_get_af(vty
);
666 iface
= VTY_GET_CONTEXT(iface
);
667 VTY_CHECK_CONTEXT(iface
);
669 ia
= iface_af_get(iface
, af
);
671 ia
->hello_interval
= 0;
673 ia
->hello_interval
= secs
;
675 ldp_reload(vty_conf
);
678 fatalx("ldp_vty_disc_interval: unexpected node");
681 return (CMD_SUCCESS
);
685 ldp_vty_targeted_hello_accept(struct vty
*vty
, struct vty_arg
*args
[])
687 struct ldpd_af_conf
*af_conf
;
689 const char *acl_from_str
;
692 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
693 acl_from_str
= vty_get_arg_value(args
, "from_acl");
695 af
= ldp_vty_get_af(vty
);
696 af_conf
= ldp_af_conf_get(vty_conf
, af
);
699 af_conf
->flags
&= ~F_LDPD_AF_THELLO_ACCEPT
;
700 af_conf
->acl_thello_accept_from
[0] = '\0';
702 af_conf
->flags
|= F_LDPD_AF_THELLO_ACCEPT
;
704 strlcpy(af_conf
->acl_thello_accept_from
, acl_from_str
,
705 sizeof(af_conf
->acl_thello_accept_from
));
707 af_conf
->acl_thello_accept_from
[0] = '\0';
710 ldp_reload(vty_conf
);
712 return (CMD_SUCCESS
);
716 ldp_vty_nbr_session_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
720 struct in_addr lsr_id
;
721 struct nbr_params
*nbrp
;
722 const char *seconds_str
;
723 const char *lsr_id_str
;
726 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
727 seconds_str
= vty_get_arg_value(args
, "seconds");
728 lsr_id_str
= vty_get_arg_value(args
, "lsr_id");
730 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
731 bad_addr_v4(lsr_id
)) {
732 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
733 return (CMD_WARNING
);
736 secs
= strtol(seconds_str
, &ep
, 10);
737 if (*ep
!= '\0' || secs
< MIN_KEEPALIVE
|| secs
> MAX_KEEPALIVE
) {
738 vty_out(vty
, "%% Invalid holdtime%s", VTY_NEWLINE
);
739 return (CMD_SUCCESS
);
742 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
746 return (CMD_SUCCESS
);
749 nbrp
->flags
&= ~F_NBRP_KEEPALIVE
;
752 nbrp
= nbr_params_new(lsr_id
);
753 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
754 QOBJ_REG(nbrp
, nbr_params
);
755 } else if (nbrp
->keepalive
== secs
)
756 return (CMD_SUCCESS
);
758 nbrp
->keepalive
= secs
;
759 nbrp
->flags
|= F_NBRP_KEEPALIVE
;
762 ldp_reload(vty_conf
);
764 return (CMD_SUCCESS
);
768 ldp_vty_af_session_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
770 struct ldpd_af_conf
*af_conf
;
774 const char *seconds_str
;
777 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
778 seconds_str
= vty_get_arg_value(args
, "seconds");
780 secs
= strtol(seconds_str
, &ep
, 10);
781 if (*ep
!= '\0' || secs
< MIN_KEEPALIVE
|| secs
> MAX_KEEPALIVE
) {
782 vty_out(vty
, "%% Invalid holdtime%s", VTY_NEWLINE
);
783 return (CMD_SUCCESS
);
786 af
= ldp_vty_get_af(vty
);
787 af_conf
= ldp_af_conf_get(vty_conf
, af
);
790 af_conf
->keepalive
= DEFAULT_KEEPALIVE
;
792 af_conf
->keepalive
= secs
;
794 ldp_reload(vty_conf
);
796 return (CMD_SUCCESS
);
800 ldp_vty_session_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
804 return (ldp_vty_nbr_session_holdtime(vty
, args
));
807 return (ldp_vty_af_session_holdtime(vty
, args
));
809 fatalx("ldp_vty_session_holdtime: unexpected node");
814 ldp_vty_interface(struct vty
*vty
, struct vty_arg
*args
[])
822 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
823 ifname
= vty_get_arg_value(args
, "ifname");
825 af
= ldp_vty_get_af(vty
);
826 iface
= if_lookup_name(vty_conf
, ifname
);
830 return (CMD_SUCCESS
);
832 ia
= iface_af_get(iface
, af
);
833 if (ia
->enabled
== 0)
834 return (CMD_SUCCESS
);
837 ia
->hello_holdtime
= 0;
838 ia
->hello_interval
= 0;
840 ldp_reload(vty_conf
);
842 return (CMD_SUCCESS
);
846 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
847 vty_out(vty
, "%% Interface is already in use%s",
849 return (CMD_SUCCESS
);
852 iface
= if_new(ifname
);
853 ia
= iface_af_get(iface
, af
);
855 RB_INSERT(iface_head
, &vty_conf
->iface_tree
, iface
);
856 QOBJ_REG(iface
, iface
);
858 ldp_reload(vty_conf
);
860 ia
= iface_af_get(iface
, af
);
863 ldp_reload(vty_conf
);
869 VTY_PUSH_CONTEXT(LDP_IPV4_IFACE_NODE
, iface
);
872 VTY_PUSH_CONTEXT(LDP_IPV6_IFACE_NODE
, iface
);
878 return (CMD_SUCCESS
);
882 ldp_vty_trans_addr(struct vty
*vty
, struct vty_arg
*args
[])
884 struct ldpd_af_conf
*af_conf
;
886 const char *addr_str
;
889 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
890 addr_str
= vty_get_arg_value(args
, "addr");
892 af
= ldp_vty_get_af(vty
);
893 af_conf
= ldp_af_conf_get(vty_conf
, af
);
896 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
898 if (inet_pton(af
, addr_str
, &af_conf
->trans_addr
) != 1 ||
899 bad_addr(af
, &af_conf
->trans_addr
)) {
900 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
901 return (CMD_SUCCESS
);
905 ldp_reload(vty_conf
);
907 return (CMD_SUCCESS
);
911 ldp_vty_neighbor_targeted(struct vty
*vty
, struct vty_arg
*args
[])
914 union ldpd_addr addr
;
916 const char *addr_str
;
919 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
920 addr_str
= vty_get_arg_value(args
, "addr");
922 af
= ldp_vty_get_af(vty
);
924 if (inet_pton(af
, addr_str
, &addr
) != 1 ||
925 bad_addr(af
, &addr
)) {
926 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
927 return (CMD_WARNING
);
929 if (af
== AF_INET6
&& IN6_IS_SCOPE_EMBED(&addr
.v6
)) {
930 vty_out(vty
, "%% Address can not be link-local%s", VTY_NEWLINE
);
931 return (CMD_WARNING
);
934 tnbr
= tnbr_find(vty_conf
, af
, &addr
);
938 return (CMD_SUCCESS
);
941 RB_REMOVE(tnbr_head
, &vty_conf
->tnbr_tree
, tnbr
);
944 ldp_reload(vty_conf
);
946 return (CMD_SUCCESS
);
950 return (CMD_SUCCESS
);
952 tnbr
= tnbr_new(af
, &addr
);
953 tnbr
->flags
|= F_TNBR_CONFIGURED
;
954 RB_INSERT(tnbr_head
, &vty_conf
->tnbr_tree
, tnbr
);
955 QOBJ_REG(tnbr
, tnbr
);
957 ldp_reload(vty_conf
);
959 return (CMD_SUCCESS
);
963 ldp_vty_label_advertise(struct vty
*vty
, struct vty_arg
*args
[])
965 struct ldpd_af_conf
*af_conf
;
967 const char *acl_to_str
;
968 const char *acl_for_str
;
971 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
972 acl_to_str
= vty_get_arg_value(args
, "to_acl");
973 acl_for_str
= vty_get_arg_value(args
, "for_acl");
975 af
= ldp_vty_get_af(vty
);
976 af_conf
= ldp_af_conf_get(vty_conf
, af
);
979 af_conf
->acl_label_advertise_to
[0] = '\0';
980 af_conf
->acl_label_advertise_for
[0] = '\0';
983 strlcpy(af_conf
->acl_label_advertise_to
, acl_to_str
,
984 sizeof(af_conf
->acl_label_advertise_to
));
986 af_conf
->acl_label_advertise_to
[0] = '\0';
988 strlcpy(af_conf
->acl_label_advertise_for
, acl_for_str
,
989 sizeof(af_conf
->acl_label_advertise_for
));
991 af_conf
->acl_label_advertise_for
[0] = '\0';
994 ldp_reload(vty_conf
);
996 return (CMD_SUCCESS
);
1000 ldp_vty_label_allocate(struct vty
*vty
, struct vty_arg
*args
[])
1002 struct ldpd_af_conf
*af_conf
;
1004 const char *acl_for_str
;
1005 const char *host_routes_str
;
1008 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1009 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1010 host_routes_str
= vty_get_arg_value(args
, "host-routes");
1012 af
= ldp_vty_get_af(vty
);
1013 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1015 af_conf
->flags
&= ~F_LDPD_AF_ALLOCHOSTONLY
;
1016 af_conf
->acl_label_allocate_for
[0] = '\0';
1018 if (host_routes_str
)
1019 af_conf
->flags
|= F_LDPD_AF_ALLOCHOSTONLY
;
1021 strlcpy(af_conf
->acl_label_allocate_for
, acl_for_str
,
1022 sizeof(af_conf
->acl_label_allocate_for
));
1025 ldp_reload(vty_conf
);
1027 return (CMD_SUCCESS
);
1031 ldp_vty_label_expnull(struct vty
*vty
, struct vty_arg
*args
[])
1033 struct ldpd_af_conf
*af_conf
;
1035 const char *acl_for_str
;
1038 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1039 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1041 af
= ldp_vty_get_af(vty
);
1042 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1045 af_conf
->flags
&= ~F_LDPD_AF_EXPNULL
;
1046 af_conf
->acl_label_expnull_for
[0] = '\0';
1048 af_conf
->flags
|= F_LDPD_AF_EXPNULL
;
1050 strlcpy(af_conf
->acl_label_expnull_for
, acl_for_str
,
1051 sizeof(af_conf
->acl_label_expnull_for
));
1053 af_conf
->acl_label_expnull_for
[0] = '\0';
1056 ldp_reload(vty_conf
);
1058 return (CMD_SUCCESS
);
1062 ldp_vty_label_accept(struct vty
*vty
, struct vty_arg
*args
[])
1064 struct ldpd_af_conf
*af_conf
;
1066 const char *acl_from_str
;
1067 const char *acl_for_str
;
1070 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1071 acl_from_str
= vty_get_arg_value(args
, "from_acl");
1072 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1074 af
= ldp_vty_get_af(vty
);
1075 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1078 af_conf
->acl_label_accept_from
[0] = '\0';
1079 af_conf
->acl_label_accept_for
[0] = '\0';
1082 strlcpy(af_conf
->acl_label_accept_from
, acl_from_str
,
1083 sizeof(af_conf
->acl_label_accept_from
));
1085 af_conf
->acl_label_accept_from
[0] = '\0';
1087 strlcpy(af_conf
->acl_label_accept_for
, acl_for_str
,
1088 sizeof(af_conf
->acl_label_accept_for
));
1090 af_conf
->acl_label_accept_for
[0] = '\0';
1093 ldp_reload(vty_conf
);
1095 return (CMD_SUCCESS
);
1099 ldp_vty_ttl_security(struct vty
*vty
, struct vty_arg
*args
[])
1101 struct ldpd_af_conf
*af_conf
;
1105 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1107 af
= ldp_vty_get_af(vty
);
1108 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1111 af_conf
->flags
&= ~F_LDPD_AF_NO_GTSM
;
1113 af_conf
->flags
|= F_LDPD_AF_NO_GTSM
;
1115 ldp_reload(vty_conf
);
1117 return (CMD_SUCCESS
);
1121 ldp_vty_router_id(struct vty
*vty
, struct vty_arg
*args
[])
1123 const char *addr_str
;
1126 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1127 addr_str
= vty_get_arg_value(args
, "addr");
1130 vty_conf
->rtr_id
.s_addr
= INADDR_ANY
;
1132 if (inet_pton(AF_INET
, addr_str
, &vty_conf
->rtr_id
) != 1 ||
1133 bad_addr_v4(vty_conf
->rtr_id
)) {
1134 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1135 return (CMD_SUCCESS
);
1139 ldp_reload(vty_conf
);
1141 return (CMD_SUCCESS
);
1145 ldp_vty_ds_cisco_interop(struct vty
*vty
, struct vty_arg
*args
[])
1149 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1152 vty_conf
->flags
&= ~F_LDPD_DS_CISCO_INTEROP
;
1154 vty_conf
->flags
|= F_LDPD_DS_CISCO_INTEROP
;
1156 ldp_reload(vty_conf
);
1158 return (CMD_SUCCESS
);
1162 ldp_vty_trans_pref_ipv4(struct vty
*vty
, struct vty_arg
*args
[])
1166 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1169 vty_conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1171 vty_conf
->trans_pref
= DUAL_STACK_LDPOV4
;
1173 ldp_reload(vty_conf
);
1175 return (CMD_SUCCESS
);
1179 ldp_vty_neighbor_password(struct vty
*vty
, struct vty_arg
*args
[])
1181 struct in_addr lsr_id
;
1182 size_t password_len
;
1183 struct nbr_params
*nbrp
;
1184 const char *lsr_id_str
;
1185 const char *password_str
;
1188 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1189 lsr_id_str
= vty_get_arg_value(args
, "lsr_id");
1190 password_str
= vty_get_arg_value(args
, "password");
1192 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
1193 bad_addr_v4(lsr_id
)) {
1194 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1195 return (CMD_WARNING
);
1198 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
1202 return (CMD_SUCCESS
);
1204 memset(&nbrp
->auth
, 0, sizeof(nbrp
->auth
));
1205 nbrp
->auth
.method
= AUTH_NONE
;
1208 nbrp
= nbr_params_new(lsr_id
);
1209 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1210 QOBJ_REG(nbrp
, nbr_params
);
1211 } else if (nbrp
->auth
.method
== AUTH_MD5SIG
&&
1212 strcmp(nbrp
->auth
.md5key
, password_str
) == 0)
1213 return (CMD_SUCCESS
);
1215 password_len
= strlcpy(nbrp
->auth
.md5key
, password_str
,
1216 sizeof(nbrp
->auth
.md5key
));
1217 if (password_len
>= sizeof(nbrp
->auth
.md5key
))
1218 vty_out(vty
, "%% password has been truncated to %zu "
1219 "characters.", sizeof(nbrp
->auth
.md5key
) - 1);
1220 nbrp
->auth
.md5key_len
= password_len
;
1221 nbrp
->auth
.method
= AUTH_MD5SIG
;
1224 ldp_reload(vty_conf
);
1226 return (CMD_SUCCESS
);
1230 ldp_vty_neighbor_ttl_security(struct vty
*vty
, struct vty_arg
*args
[])
1232 struct in_addr lsr_id
;
1233 struct nbr_params
*nbrp
;
1236 const char *lsr_id_str
;
1237 const char *hops_str
;
1240 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1241 lsr_id_str
= vty_get_arg_value(args
, "lsr_id");
1242 hops_str
= vty_get_arg_value(args
, "hops");
1244 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
1245 bad_addr_v4(lsr_id
)) {
1246 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1247 return (CMD_WARNING
);
1251 hops
= strtol(hops_str
, &ep
, 10);
1252 if (*ep
!= '\0' || hops
< 1 || hops
> 254) {
1253 vty_out(vty
, "%% Invalid hop count%s", VTY_NEWLINE
);
1254 return (CMD_SUCCESS
);
1258 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
1262 return (CMD_SUCCESS
);
1264 nbrp
->flags
&= ~(F_NBRP_GTSM
|F_NBRP_GTSM_HOPS
);
1265 nbrp
->gtsm_enabled
= 0;
1266 nbrp
->gtsm_hops
= 0;
1269 nbrp
= nbr_params_new(lsr_id
);
1270 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1271 QOBJ_REG(nbrp
, nbr_params
);
1274 nbrp
->flags
|= F_NBRP_GTSM
;
1275 nbrp
->flags
&= ~F_NBRP_GTSM_HOPS
;
1277 nbrp
->gtsm_enabled
= 1;
1278 nbrp
->gtsm_hops
= hops
;
1279 nbrp
->flags
|= F_NBRP_GTSM_HOPS
;
1281 nbrp
->gtsm_enabled
= 0;
1284 ldp_reload(vty_conf
);
1286 return (CMD_SUCCESS
);
1290 ldp_vty_l2vpn(struct vty
*vty
, struct vty_arg
*args
[])
1292 struct l2vpn
*l2vpn
;
1293 struct l2vpn_if
*lif
;
1294 struct l2vpn_pw
*pw
;
1295 const char *name_str
;
1298 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1299 name_str
= vty_get_arg_value(args
, "name");
1301 l2vpn
= l2vpn_find(vty_conf
, name_str
);
1305 return (CMD_SUCCESS
);
1307 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
1309 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
1311 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
1314 RB_REMOVE(l2vpn_head
, &vty_conf
->l2vpn_tree
, l2vpn
);
1317 ldp_reload(vty_conf
);
1319 return (CMD_SUCCESS
);
1323 VTY_PUSH_CONTEXT(LDP_L2VPN_NODE
, l2vpn
);
1324 return (CMD_SUCCESS
);
1327 l2vpn
= l2vpn_new(name_str
);
1328 l2vpn
->type
= L2VPN_TYPE_VPLS
;
1329 RB_INSERT(l2vpn_head
, &vty_conf
->l2vpn_tree
, l2vpn
);
1330 QOBJ_REG(l2vpn
, l2vpn
);
1332 VTY_PUSH_CONTEXT(LDP_L2VPN_NODE
, l2vpn
);
1334 ldp_reload(vty_conf
);
1336 return (CMD_SUCCESS
);
1340 ldp_vty_l2vpn_bridge(struct vty
*vty
, struct vty_arg
*args
[])
1342 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1346 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1347 ifname
= vty_get_arg_value(args
, "ifname");
1350 memset(l2vpn
->br_ifname
, 0, sizeof(l2vpn
->br_ifname
));
1352 strlcpy(l2vpn
->br_ifname
, ifname
, sizeof(l2vpn
->br_ifname
));
1354 ldp_reload(vty_conf
);
1356 return (CMD_SUCCESS
);
1360 ldp_vty_l2vpn_mtu(struct vty
*vty
, struct vty_arg
*args
[])
1362 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1365 const char *mtu_str
;
1368 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1369 mtu_str
= vty_get_arg_value(args
, "mtu");
1371 mtu
= strtol(mtu_str
, &ep
, 10);
1372 if (*ep
!= '\0' || mtu
< MIN_L2VPN_MTU
|| mtu
> MAX_L2VPN_MTU
) {
1373 vty_out(vty
, "%% Invalid MTU%s", VTY_NEWLINE
);
1374 return (CMD_WARNING
);
1378 l2vpn
->mtu
= DEFAULT_L2VPN_MTU
;
1382 ldp_reload(vty_conf
);
1384 return (CMD_SUCCESS
);
1388 ldp_vty_l2vpn_pwtype(struct vty
*vty
, struct vty_arg
*args
[])
1390 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1392 const char *type_str
;
1395 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1396 type_str
= vty_get_arg_value(args
, "type");
1398 if (strcmp(type_str
, "ethernet") == 0)
1399 pw_type
= PW_TYPE_ETHERNET
;
1401 pw_type
= PW_TYPE_ETHERNET_TAGGED
;
1404 l2vpn
->pw_type
= DEFAULT_PW_TYPE
;
1406 l2vpn
->pw_type
= pw_type
;
1408 ldp_reload(vty_conf
);
1410 return (CMD_SUCCESS
);
1414 ldp_vty_l2vpn_interface(struct vty
*vty
, struct vty_arg
*args
[])
1416 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1417 struct l2vpn_if
*lif
;
1421 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1422 ifname
= vty_get_arg_value(args
, "ifname");
1424 lif
= l2vpn_if_find(l2vpn
, ifname
);
1428 return (CMD_SUCCESS
);
1431 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1434 ldp_reload(vty_conf
);
1436 return (CMD_SUCCESS
);
1440 return (CMD_SUCCESS
);
1442 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
1443 vty_out(vty
, "%% Interface is already in use%s", VTY_NEWLINE
);
1444 return (CMD_SUCCESS
);
1447 lif
= l2vpn_if_new(l2vpn
, ifname
);
1448 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1449 QOBJ_REG(lif
, l2vpn_if
);
1451 ldp_reload(vty_conf
);
1453 return (CMD_SUCCESS
);
1457 ldp_vty_l2vpn_pseudowire(struct vty
*vty
, struct vty_arg
*args
[])
1459 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1460 struct l2vpn_pw
*pw
;
1464 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1465 ifname
= vty_get_arg_value(args
, "ifname");
1467 pw
= l2vpn_pw_find(l2vpn
, ifname
);
1471 return (CMD_SUCCESS
);
1474 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1475 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1477 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1480 ldp_reload(vty_conf
);
1482 return (CMD_SUCCESS
);
1486 VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE
, pw
);
1487 return (CMD_SUCCESS
);
1490 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
1491 vty_out(vty
, "%% Interface is already in use%s", VTY_NEWLINE
);
1492 return (CMD_SUCCESS
);
1495 pw
= l2vpn_pw_new(l2vpn
, ifname
);
1496 pw
->flags
= F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
;
1497 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1498 QOBJ_REG(pw
, l2vpn_pw
);
1500 VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE
, pw
);
1502 ldp_reload(vty_conf
);
1504 return (CMD_SUCCESS
);
1508 ldp_vty_l2vpn_pw_cword(struct vty
*vty
, struct vty_arg
*args
[])
1510 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1511 const char *preference_str
;
1514 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1515 preference_str
= vty_get_arg_value(args
, "preference");
1518 pw
->flags
|= F_PW_CWORD_CONF
;
1520 if (preference_str
[0] == 'e')
1521 pw
->flags
&= ~F_PW_CWORD_CONF
;
1523 pw
->flags
|= F_PW_CWORD_CONF
;
1526 ldp_reload(vty_conf
);
1528 return (CMD_SUCCESS
);
1532 ldp_vty_l2vpn_pw_nbr_addr(struct vty
*vty
, struct vty_arg
*args
[])
1534 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1536 union ldpd_addr addr
;
1537 const char *addr_str
;
1540 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1541 addr_str
= vty_get_arg_value(args
, "addr");
1543 if (ldp_get_address(addr_str
, &af
, &addr
) == -1 ||
1544 bad_addr(af
, &addr
)) {
1545 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1546 return (CMD_WARNING
);
1551 memset(&pw
->addr
, 0, sizeof(pw
->addr
));
1552 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1556 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1559 ldp_reload(vty_conf
);
1561 return (CMD_SUCCESS
);
1565 ldp_vty_l2vpn_pw_nbr_id(struct vty
*vty
, struct vty_arg
*args
[])
1567 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1568 struct in_addr lsr_id
;
1569 const char *lsr_id_str
;
1572 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1573 lsr_id_str
= vty_get_arg_value(args
, "lsr-id");
1575 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
1576 bad_addr_v4(lsr_id
)) {
1577 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1578 return (CMD_WARNING
);
1582 pw
->lsr_id
.s_addr
= INADDR_ANY
;
1584 pw
->lsr_id
= lsr_id
;
1586 ldp_reload(vty_conf
);
1588 return (CMD_SUCCESS
);
1592 ldp_vty_l2vpn_pw_pwid(struct vty
*vty
, struct vty_arg
*args
[])
1594 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1597 const char *pwid_str
;
1600 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1601 pwid_str
= vty_get_arg_value(args
, "pwid");
1603 pwid
= strtol(pwid_str
, &ep
, 10);
1604 if (*ep
!= '\0' || pwid
< MIN_PWID_ID
|| pwid
> MAX_PWID_ID
) {
1605 vty_out(vty
, "%% Invalid pw-id%s", VTY_NEWLINE
);
1606 return (CMD_WARNING
);
1614 ldp_reload(vty_conf
);
1616 return (CMD_SUCCESS
);
1620 ldp_vty_l2vpn_pw_pwstatus(struct vty
*vty
, struct vty_arg
*args
[])
1622 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1625 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1628 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1630 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1632 ldp_reload(vty_conf
);
1634 return (CMD_SUCCESS
);
1638 iface_new_api(struct ldpd_conf
*conf
, const char *name
)
1640 const char *ifname
= name
;
1641 struct iface
*iface
;
1643 if (ldp_iface_is_configured(conf
, ifname
))
1646 iface
= if_new(name
);
1647 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1648 QOBJ_REG(iface
, iface
);
1653 iface_del_api(struct ldpd_conf
*conf
, struct iface
*iface
)
1656 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1661 tnbr_new_api(struct ldpd_conf
*conf
, int af
, union ldpd_addr
*addr
)
1665 if (af
== AF_INET6
&& IN6_IS_SCOPE_EMBED(&addr
->v6
))
1668 if (tnbr_find(conf
, af
, addr
))
1671 tnbr
= tnbr_new(af
, addr
);
1672 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1673 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1674 QOBJ_REG(tnbr
, tnbr
);
1679 tnbr_del_api(struct ldpd_conf
*conf
, struct tnbr
*tnbr
)
1682 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1687 nbrp_new_api(struct ldpd_conf
*conf
, struct in_addr lsr_id
)
1689 struct nbr_params
*nbrp
;
1691 if (nbr_params_find(conf
, lsr_id
))
1694 nbrp
= nbr_params_new(lsr_id
);
1695 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1696 QOBJ_REG(nbrp
, nbr_params
);
1701 nbrp_del_api(struct ldpd_conf
*conf
, struct nbr_params
*nbrp
)
1704 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1709 l2vpn_new_api(struct ldpd_conf
*conf
, const char *name
)
1711 struct l2vpn
*l2vpn
;
1713 if (l2vpn_find(conf
, name
))
1716 l2vpn
= l2vpn_new(name
);
1717 l2vpn
->type
= L2VPN_TYPE_VPLS
;
1718 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1719 QOBJ_REG(l2vpn
, l2vpn
);
1724 l2vpn_del_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
)
1726 struct l2vpn_if
*lif
;
1727 struct l2vpn_pw
*pw
;
1729 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1731 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1734 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1736 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1739 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1741 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1745 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1750 l2vpn_if_new_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
,
1753 struct l2vpn_if
*lif
;
1755 if (ldp_iface_is_configured(conf
, ifname
))
1758 lif
= l2vpn_if_new(l2vpn
, ifname
);
1759 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1760 QOBJ_REG(lif
, l2vpn_if
);
1765 l2vpn_if_del_api(struct l2vpn
*l2vpn
, struct l2vpn_if
*lif
)
1768 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1773 l2vpn_pw_new_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
,
1776 struct l2vpn_pw
*pw
;
1778 if (ldp_iface_is_configured(conf
, ifname
))
1781 pw
= l2vpn_pw_new(l2vpn
, ifname
);
1782 pw
->flags
= F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
;
1783 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1784 QOBJ_REG(pw
, l2vpn_pw
);
1789 l2vpn_pw_del_api(struct l2vpn
*l2vpn
, struct l2vpn_pw
*pw
)
1792 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);