diff options
| author | Louis Scalbert <louis.scalbert@6wind.com> | 2022-10-14 17:57:17 +0200 |
|---|---|---|
| committer | Louis Scalbert <louis.scalbert@6wind.com> | 2022-10-17 11:02:56 +0200 |
| commit | 2e2dc4f024312b7351b3d7e964fed42895fd123e (patch) | |
| tree | 8bb5893fb45a61f42b7e34460703aeaaaa7b7a96 /lib/if.c | |
| parent | fd30c2467a9a3afc615923af64f5de91937d268f (diff) | |
lib,zebra: do not enable link-params when a link-params command fails
A given interface has no enabled link-params context. If a link-params
configuration command fails, the link-params is wrongly enabled:
> r4(config-link-params)# no enable
> r4(config-link-params)# delay
> (0-16777215) Average delay in micro-second as decimal (0...16777215)
> r4(config-link-params)# delay 50 min 300 max 500
> Average delay should be comprise between Min (300) and Max (500) delay
> r4(config-link-params)# do sh run zebra
> (...)
> interface eth-rt1
> link-params
> enable
> exit-link-params
link-params are enabled if and only if the interface structure has a
valid link_params pointer. Before checking the command validity,
if_link_params_get() is called to retrieve the link-params pointer.
However, this function initializes the pointer if it is NULL.
Only use if_link_params_get() to retrieve the pointer to avoid
confusion. In command setting functions, initialize the link_params
pointer if needed only after the validation of the command.
Fixes: 16f1b9e ("Update Traffic Engineering Support for OSPFD")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Diffstat (limited to 'lib/if.c')
| -rw-r--r-- | lib/if.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -1095,13 +1095,15 @@ const char *if_link_type_str(enum zebra_link_type llt) struct if_link_params *if_link_params_get(struct interface *ifp) { - int i; + return ifp->link_params; +} - if (ifp->link_params != NULL) - return ifp->link_params; +struct if_link_params *if_link_params_enable(struct interface *ifp) +{ + struct if_link_params *iflp; + int i; - struct if_link_params *iflp = - XCALLOC(MTYPE_IF_LINK_PARAMS, sizeof(struct if_link_params)); + iflp = if_link_params_init(ifp); /* Compute default bandwidth based on interface */ iflp->default_bw = @@ -1129,6 +1131,20 @@ struct if_link_params *if_link_params_get(struct interface *ifp) return iflp; } +struct if_link_params *if_link_params_init(struct interface *ifp) +{ + struct if_link_params *iflp = if_link_params_get(ifp); + + if (iflp) + return iflp; + + iflp = XCALLOC(MTYPE_IF_LINK_PARAMS, sizeof(struct if_link_params)); + + ifp->link_params = iflp; + + return iflp; +} + void if_link_params_free(struct interface *ifp) { XFREE(MTYPE_IF_LINK_PARAMS, ifp->link_params); |
