Skip to content

Commit 9c4e157

Browse files
author
Volodymyr Huti
committed
eigrp: reimplement passive-interface [default] command
Maintain a vector of mappings [if_name -> if_passive]. Otherwise, if topo is not already convereged, configuration does not apply, since iface is missing from the iface list. Fixes: #11301 Signed-off-by: Volodymyr Huti <v.huti@vyos.io>
1 parent a95b83c commit 9c4e157

8 files changed

+270
-59
lines changed

eigrpd/eigrp_cli.c

+47-5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ void eigrp_cli_show_router_id(struct vty *vty, const struct lyd_node *dnode,
120120
vty_out(vty, " eigrp router-id %s\n", router_id);
121121
}
122122

123+
/*
124+
* XPath: /frr-eigrpd:eigrpd/instance/passive-default
125+
*/
126+
DEFPY_YANG(
127+
eigrp_passive_default,
128+
eigrp_passive_default_cmd,
129+
"[no] passive-interface default",
130+
NO_STR
131+
"Suppress routing updates on an interface\n"
132+
"default for all interfaces\n")
133+
{
134+
nb_cli_enqueue_change(vty, "./passive-default", NB_OP_MODIFY,
135+
no ? "false" : "true");
136+
137+
return nb_cli_apply_changes(vty, NULL);
138+
}
139+
123140
/*
124141
* XPath: /frr-eigrpd:eigrpd/instance/passive-interface
125142
*/
@@ -131,12 +148,19 @@ DEFPY_YANG(
131148
"Suppress routing updates on an interface\n"
132149
"Interface to suppress on\n")
133150
{
134-
if (no)
135-
nb_cli_enqueue_change(vty, "./passive-interface",
136-
NB_OP_DESTROY, ifname);
137-
else
151+
bool passive_default =
152+
yang_dnode_get_bool(vty->candidate_config->dnode, "%s%s",
153+
VTY_CURR_XPATH, "/passive-default");
154+
155+
if (passive_default) {
156+
nb_cli_enqueue_change(vty, "./non-passive-interface",
157+
no ? NB_OP_CREATE : NB_OP_DESTROY,
158+
ifname);
159+
} else {
138160
nb_cli_enqueue_change(vty, "./passive-interface",
139-
NB_OP_CREATE, ifname);
161+
no ? NB_OP_DESTROY : NB_OP_CREATE,
162+
ifname);
163+
}
140164

141165
return nb_cli_apply_changes(vty, NULL);
142166
}
@@ -150,6 +174,15 @@ void eigrp_cli_show_passive_interface(struct vty *vty,
150174
vty_out(vty, " passive-interface %s\n", ifname);
151175
}
152176

177+
void eigrp_cli_show_non_passive_interface(struct vty *vty,
178+
const struct lyd_node *dnode,
179+
bool show_defaults)
180+
{
181+
const char *ifname = yang_dnode_get_string(dnode, NULL);
182+
183+
vty_out(vty, "no passive-interface %s\n", ifname);
184+
}
185+
153186
/*
154187
* XPath: /frr-eigrpd:eigrpd/instance/active-time
155188
*/
@@ -826,6 +859,14 @@ void eigrp_cli_show_keychain(struct vty *vty, const struct lyd_node *dnode,
826859
keychain);
827860
}
828861

862+
void eigrpd_cli_show_passive_default(struct vty *vty, const struct lyd_node *dnode,
863+
bool show_defaults)
864+
{
865+
if (!yang_dnode_get_bool(dnode, NULL))
866+
vty_out(vty, " no");
867+
868+
vty_out(vty, " passive-interface default\n");
869+
}
829870

830871
/*
831872
* CLI installation procedures.
@@ -865,6 +906,7 @@ eigrp_cli_init(void)
865906
install_element(EIGRP_NODE, &eigrp_router_id_cmd);
866907
install_element(EIGRP_NODE, &no_eigrp_router_id_cmd);
867908
install_element(EIGRP_NODE, &eigrp_passive_interface_cmd);
909+
install_element(EIGRP_NODE, &eigrp_passive_default_cmd);
868910
install_element(EIGRP_NODE, &eigrp_timers_active_cmd);
869911
install_element(EIGRP_NODE, &no_eigrp_timers_active_cmd);
870912
install_element(EIGRP_NODE, &eigrp_variance_cmd);

eigrpd/eigrp_cli.h

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ extern void eigrp_cli_show_authentication(struct vty *vty,
6161
extern void eigrp_cli_show_keychain(struct vty *vty,
6262
const struct lyd_node *dnode,
6363
bool show_defaults);
64+
void eigrpd_cli_show_passive_default(struct vty *vty,
65+
const struct lyd_node *dnode,
66+
bool show_defaults);
67+
void eigrp_cli_show_non_passive_interface(struct vty *vty,
68+
const struct lyd_node *dnode,
69+
bool show_defaults);
6470
extern void eigrp_cli_init(void);
6571

6672
#endif /*EIGRP_CLI_H_ */

eigrpd/eigrp_interface.c

+109-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "network.h"
2626
#include "command.h"
2727
#include "stream.h"
28-
#include "log.h"
28+
#include "zlog.h"
2929
#include "keychain.h"
3030
#include "vrf.h"
3131

@@ -44,6 +44,9 @@
4444
#include "eigrpd/eigrp_metric.h"
4545

4646
DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF, "EIGRP interface");
47+
DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF_STRING, "EIGRP Interface String");
48+
49+
static void eigrp_passive_interface_apply(struct interface *ifp);
4750

4851
int eigrp_if_new_hook(struct interface *ifp)
4952
{
@@ -114,6 +117,7 @@ static int eigrp_ifp_create(struct interface *ifp)
114117

115118
ei->params.type = eigrp_default_iftype(ifp);
116119

120+
eigrp_passive_interface_apply(ifp);
117121
eigrp_if_update(ifp);
118122

119123
return 0;
@@ -154,6 +158,7 @@ static int eigrp_ifp_up(struct interface *ifp)
154158
return 0;
155159
}
156160

161+
eigrp_passive_interface_apply(ifp);
157162
eigrp_if_up(ifp->info);
158163

159164
return 0;
@@ -368,6 +373,109 @@ bool eigrp_if_is_passive(struct eigrp_interface *ei)
368373
return true;
369374
}
370375

376+
377+
/* Utility function for looking up passive interface settings. */
378+
static int eigrp_passive_nondefault_lookup(struct eigrp *eigrp, const char *ifname)
379+
{
380+
unsigned int i;
381+
char *str;
382+
383+
for (i = 0; i < vector_active(eigrp->passive_nondefault); i++) {
384+
str = vector_slot(eigrp->passive_nondefault, i);
385+
if (str && strmatch(str, ifname))
386+
return i;
387+
}
388+
return -1;
389+
}
390+
391+
static void eigrp_passive_interface_apply(struct interface *ifp)
392+
{
393+
struct eigrp_interface *ei = ifp->info;
394+
struct eigrp *eigrp;
395+
int ifidx;
396+
397+
if (!ei || !ei->eigrp)
398+
return;
399+
400+
eigrp = ei->eigrp;
401+
ifidx = (eigrp_passive_nondefault_lookup(eigrp, ifp->name));
402+
ei->params.passive_interface = (ifidx < 0) ? eigrp->passive_interface_default
403+
: !eigrp->passive_interface_default;
404+
if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
405+
zlog_debug("interface %s: passive = %d", ifp->name,
406+
ei->params.passive_interface);
407+
408+
}
409+
410+
static void eigrp_passive_interface_apply_all(struct eigrp *eigrp)
411+
{
412+
struct interface *ifp;
413+
struct vrf *vrf;
414+
415+
vrf = vrf_lookup_by_id(eigrp->vrf_id);
416+
FOR_ALL_INTERFACES (vrf, ifp)
417+
eigrp_passive_interface_apply(ifp);
418+
}
419+
420+
421+
/* Passive interface. */
422+
int eigrp_passive_nondefault_set(struct eigrp *eigrp, const char *ifname)
423+
{
424+
if (eigrp_passive_nondefault_lookup(eigrp, ifname) >= 0)
425+
/*
426+
* Don't return an error, this can happen after changing
427+
* 'passive-default'.
428+
*/
429+
return NB_OK;
430+
431+
vector_set(eigrp->passive_nondefault,
432+
XSTRDUP(MTYPE_EIGRP_IF_STRING, ifname));
433+
434+
eigrp_passive_interface_apply_all(eigrp);
435+
436+
return NB_OK;
437+
}
438+
439+
int eigrp_passive_nondefault_unset(struct eigrp *eigrp, const char *ifname)
440+
{
441+
int i;
442+
char *str;
443+
444+
i = eigrp_passive_nondefault_lookup(eigrp, ifname);
445+
if (i < 0)
446+
/*
447+
* Don't return an error, this can happen after changing
448+
* 'passive-default'.
449+
*/
450+
return NB_OK;
451+
452+
str = vector_slot(eigrp->passive_nondefault, i);
453+
XFREE(MTYPE_EIGRP_IF_STRING, str);
454+
vector_unset(eigrp->passive_nondefault, i);
455+
456+
eigrp_passive_interface_apply_all(eigrp);
457+
458+
return NB_OK;
459+
}
460+
461+
462+
/* Free all configured eigrp passive-interface settings. */
463+
void eigrp_passive_nondefault_clean(struct eigrp *eigrp)
464+
{
465+
unsigned int i;
466+
char *str;
467+
468+
for (i = 0; i < vector_active(eigrp->passive_nondefault); i++) {
469+
str = vector_slot(eigrp->passive_nondefault, i);
470+
if (str) {
471+
XFREE(MTYPE_EIGRP_IF_STRING, str);
472+
vector_slot(eigrp->passive_nondefault, i) = NULL;
473+
}
474+
}
475+
eigrp_passive_interface_apply_all(eigrp);
476+
}
477+
478+
371479
void eigrp_if_set_multicast(struct eigrp_interface *ei)
372480
{
373481
if (!eigrp_if_is_passive(ei)) {

eigrpd/eigrp_interface.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ extern void eigrp_if_free(struct eigrp_interface *, int);
3232
extern int eigrp_if_down(struct eigrp_interface *);
3333
extern void eigrp_if_stream_unset(struct eigrp_interface *);
3434

35-
extern struct eigrp_interface *eigrp_if_lookup_by_local_addr(struct eigrp *,
36-
struct interface *,
37-
struct in_addr);
35+
extern void eigrp_passive_nondefault_clean(struct eigrp *);
36+
extern int eigrp_passive_nondefault_set(struct eigrp *eigrp, const char *ifname);
37+
extern int eigrp_passive_nondefault_unset(struct eigrp *eigrp, const char *ifname);
38+
39+
extern struct eigrp_interface *eigrp_if_lookup_by_local_addr(struct eigrp *eigrp,
40+
struct interface *ifp,
41+
struct in_addr address);
3842
extern struct eigrp_interface *eigrp_if_lookup_by_name(struct eigrp *,
3943
const char *);
4044

0 commit comments

Comments
 (0)