]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #12199 from tewok/frr-routes-table-columns
authorRuss White <russ@riw.us>
Wed, 26 Oct 2022 13:48:41 +0000 (09:48 -0400)
committerGitHub <noreply@github.com>
Wed, 26 Oct 2022 13:48:41 +0000 (09:48 -0400)
bgpd: fixed misaligned columns in BGP routes table

12 files changed:
bgpd/bgp_evpn_vty.c
bgpd/bgp_packet.c
bgpd/bgp_route.c
bgpd/bgp_vty.c
bgpd/bgpd.c
isisd/isis_te.c
lib/if.c
lib/if.h
lib/zclient.c
vtysh/vtysh_config.c
zebra/interface.c
zebra/zapi_msg.c

index 24fa2b2a539df123ee6c685fb54f0837e04fe723..c0ad72dc3389de27f9e895b48ebff539f6b135f9 100644 (file)
@@ -5866,13 +5866,6 @@ static int parse_rtlist(struct bgp *bgp, struct vty *vty, int argc,
                 * the ecommunity parser.
                 */
                if ((argv[i]->arg)[0] == '*') {
-                       if (!is_import) {
-                               vty_out(vty,
-                                       "%% Wildcard '*' only applicable for import\n");
-                               ret = CMD_WARNING;
-                               continue;
-                       }
-
                        (argv[i]->arg)[0] = '0';
                        is_wildcard = true;
                }
@@ -5950,6 +5943,16 @@ DEFUN (bgp_evpn_vrf_rt,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (rt_type != RT_TYPE_IMPORT) {
+               for (int i = 2; i < argc; i++) {
+                       if ((argv[i]->arg)[0] == '*') {
+                               vty_out(vty,
+                                       "%% Wildcard '*' only applicable for import\n");
+                               return CMD_WARNING_CONFIG_FAILED;
+                       }
+               }
+       }
+
        /* Add/update the import route-target */
        if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_IMPORT)
                tmp_ret = parse_rtlist(bgp, vty, argc, argv, 2, true, true);
@@ -6056,6 +6059,16 @@ DEFUN (no_bgp_evpn_vrf_rt,
                }
        }
 
+       if (rt_type != RT_TYPE_IMPORT) {
+               for (int i = 3; i < argc; i++) {
+                       if ((argv[i]->arg)[0] == '*') {
+                               vty_out(vty,
+                                       "%% Wildcard '*' only applicable for import\n");
+                               return CMD_WARNING_CONFIG_FAILED;
+                       }
+               }
+       }
+
        if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_IMPORT)
                tmp_ret = parse_rtlist(bgp, vty, argc, argv, 3, false, true);
 
index 8ae31bf2e695ac56044428435322f9210ed9cf38..769f9613da852d1511b4702181cb75cd02aa03de 100644 (file)
@@ -124,6 +124,7 @@ static void bgp_packet_add(struct peer *peer, struct stream *s)
 {
        intmax_t delta;
        uint32_t holdtime;
+       intmax_t sendholdtime;
 
        frr_with_mutex (&peer->io_mtx) {
                /* if the queue is empty, reset the "last OK" timestamp to
@@ -136,8 +137,14 @@ static void bgp_packet_add(struct peer *peer, struct stream *s)
                stream_fifo_push(peer->obuf, s);
 
                delta = monotime(NULL) - peer->last_sendq_ok;
-               holdtime = atomic_load_explicit(&peer->holdtime,
-                                               memory_order_relaxed);
+
+               if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER))
+                       holdtime = atomic_load_explicit(&peer->holdtime,
+                                                       memory_order_relaxed);
+               else
+                       holdtime = peer->bgp->default_holdtime;
+
+               sendholdtime = holdtime * 2;
 
                /* Note that when we're here, we're adding some packet to the
                 * OutQ.  That includes keepalives when there is nothing to
@@ -149,18 +156,18 @@ static void bgp_packet_add(struct peer *peer, struct stream *s)
                 */
                if (!holdtime) {
                        /* no holdtime, do nothing. */
-               } else if (delta > 2 * (intmax_t)holdtime) {
+               } else if (delta > sendholdtime) {
                        flog_err(
                                EC_BGP_SENDQ_STUCK_PROPER,
-                               "%s has not made any SendQ progress for 2 holdtimes, terminating session",
-                               peer->host);
+                               "%pBP has not made any SendQ progress for 2 holdtimes (%jds), terminating session",
+                               peer, sendholdtime);
                        BGP_EVENT_ADD(peer, TCP_fatal_error);
                } else if (delta > (intmax_t)holdtime &&
                           monotime(NULL) - peer->last_sendq_warn > 5) {
                        flog_warn(
                                EC_BGP_SENDQ_STUCK_WARN,
-                               "%s has not made any SendQ progress for 1 holdtime, peer overloaded?",
-                               peer->host);
+                               "%pBP has not made any SendQ progress for 1 holdtime (%us), peer overloaded?",
+                               peer, holdtime);
                        peer->last_sendq_warn = monotime(NULL);
                }
        }
index 50567f43206d0604b25c8c3955e0a07585b0452a..693616e6d59fe7b7b104183f368dd5390745497c 100644 (file)
@@ -4000,6 +4000,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
        bool force_evpn_import = false;
        safi_t orig_safi = safi;
        bool leak_success = true;
+       int allowas_in = 0;
 
        if (frrtrace_enabled(frr_bgp, process_update)) {
                char pfxprint[PREFIX2STR_BUFFER];
@@ -4045,6 +4046,10 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
            && peer != bgp->peer_self)
                bgp_adj_in_set(dest, peer, attr, addpath_id);
 
+       /* Update permitted loop count */
+       if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN))
+               allowas_in = peer->allowas_in[afi][safi];
+
        /* Check previously received route. */
        for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
                if (pi->peer == peer && pi->type == type
@@ -4054,8 +4059,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
 
        /* AS path local-as loop check. */
        if (peer->change_local_as) {
-               if (peer->allowas_in[afi][safi])
-                       aspath_loop_count = peer->allowas_in[afi][safi];
+               if (allowas_in)
+                       aspath_loop_count = allowas_in;
                else if (!CHECK_FLAG(peer->flags,
                                     PEER_FLAG_LOCAL_AS_NO_PREPEND))
                        aspath_loop_count = 1;
@@ -4078,11 +4083,10 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
 
        /* AS path loop check. */
        if (do_loop_check) {
-               if (aspath_loop_check(attr->aspath, bgp->as)
-                           > peer->allowas_in[afi][safi]
-                   || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
-                       && aspath_loop_check(attr->aspath, bgp->confed_id)
-                                  > peer->allowas_in[afi][safi])) {
+               if (aspath_loop_check(attr->aspath, bgp->as) > allowas_in ||
+                   (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) &&
+                    (aspath_loop_check(attr->aspath, bgp->confed_id) >
+                     allowas_in))) {
                        peer->stat_pfx_aspath_loop++;
                        reason = "as-path contains our own AS;";
                        goto filtered;
index f380460a95731d64ce4a58e11ff6fcc5ddea265e..ec0fcd8f11985709fa57412e3f8c8a34de3bd8be 100644 (file)
@@ -12282,6 +12282,16 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
                                json_addr,
                                "privateAsNumsRemovedInUpdatesToNbr");
 
+               if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
+                       if (CHECK_FLAG(p->af_flags[afi][safi],
+                                      PEER_FLAG_ALLOWAS_IN_ORIGIN))
+                               json_object_boolean_true_add(json_addr,
+                                                            "allowAsInOrigin");
+                       else
+                               json_object_int_add(json_addr, "allowAsInCount",
+                                                   p->allowas_in[afi][safi]);
+               }
+
                if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
                        json_object_boolean_true_add(
                                json_addr,
@@ -12598,6 +12608,17 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
                        vty_out(vty,
                                "  Private AS numbers removed in updates to this neighbor\n");
 
+               if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
+                       if (CHECK_FLAG(p->af_flags[afi][safi],
+                                      PEER_FLAG_ALLOWAS_IN_ORIGIN))
+                               vty_out(vty,
+                                       "  Local AS allowed as path origin\n");
+                       else
+                               vty_out(vty,
+                                       "  Local AS allowed in path, %d occurrences\n",
+                                       p->allowas_in[afi][safi]);
+               }
+
                if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
                        vty_out(vty, "  %s\n",
                                bgp_addpath_names(p->addpath_type[afi][safi])
index 40e6c90dfcec23e379445582d211869a181d50c7..005d6b309217784f01d619ce1c45ac9f3afb8a12 100644 (file)
@@ -4272,9 +4272,9 @@ static const struct peer_flag_action peer_flag_action_list[] = {
        {PEER_FLAG_TIMER_CONNECT, 0, peer_change_none},
        {PEER_FLAG_TIMER_DELAYOPEN, 0, peer_change_none},
        {PEER_FLAG_PASSWORD, 0, peer_change_none},
-       {PEER_FLAG_LOCAL_AS, 0, peer_change_none},
-       {PEER_FLAG_LOCAL_AS_NO_PREPEND, 0, peer_change_none},
-       {PEER_FLAG_LOCAL_AS_REPLACE_AS, 0, peer_change_none},
+       {PEER_FLAG_LOCAL_AS, 0, peer_change_reset},
+       {PEER_FLAG_LOCAL_AS_NO_PREPEND, 0, peer_change_reset},
+       {PEER_FLAG_LOCAL_AS_REPLACE_AS, 0, peer_change_reset},
        {PEER_FLAG_UPDATE_SOURCE, 0, peer_change_none},
        {PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE, 0, peer_change_none},
        {PEER_FLAG_EXTENDED_OPT_PARAMS, 0, peer_change_reset},
@@ -6160,18 +6160,8 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
        (void)peer_sort(peer);
 
        /* Check if handling a regular peer. */
-       if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
-               /* Send notification or reset peer depending on state. */
-               if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
-                       peer->last_reset = PEER_DOWN_LOCAL_AS_CHANGE;
-                       bgp_notify_send(peer, BGP_NOTIFY_CEASE,
-                                       BGP_NOTIFY_CEASE_CONFIG_CHANGE);
-               } else
-                       bgp_session_reset(peer);
-
-               /* Skip peer-group mechanics for regular peers. */
+       if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP))
                return 0;
-       }
 
        /*
         * Set flag and configuration on all peer-group members, unless they are
@@ -6200,14 +6190,6 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
                COND_FLAG(member->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS,
                          replace_as);
                member->change_local_as = as;
-
-               /* Send notification or stop peer depending on state. */
-               if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) {
-                       member->last_reset = PEER_DOWN_LOCAL_AS_CHANGE;
-                       bgp_notify_send(member, BGP_NOTIFY_CEASE,
-                                       BGP_NOTIFY_CEASE_CONFIG_CHANGE);
-               } else
-                       BGP_EVENT_ADD(member, BGP_Stop);
        }
 
        return 0;
index 0093279cde362e3d8f636230c37a35f449104848..155d1e6fed5a1d60923b369211dc5a1d68215b6e 100644 (file)
@@ -66,6 +66,8 @@
 
 DEFINE_MTYPE_STATIC(ISISD, ISIS_MPLS_TE,    "ISIS MPLS_TE parameters");
 
+static void isis_mpls_te_circuit_ip_update(struct isis_circuit *circuit);
+
 /*------------------------------------------------------------------------*
  * Following are control functions for MPLS-TE parameters management.
  *------------------------------------------------------------------------*/
@@ -111,9 +113,13 @@ void isis_mpls_te_create(struct isis_area *area)
        if (area->mta->ted)
                isis_te_init_ted(area);
 
-       /* Update Extended TLVs according to Interface link parameters */
-       for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
+       /* Update Extended TLVs according to Interface link parameters
+        * and neighbor IP addresses
+        */
+       for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
                isis_link_params_update(circuit, circuit->interface);
+               isis_mpls_te_circuit_ip_update(circuit);
+       }
 }
 
 /**
@@ -132,7 +138,7 @@ void isis_mpls_te_disable(struct isis_area *area)
        area->mta->status = disable;
 
        /* Remove Link State Database */
-       ls_ted_del_all(&area->mta->ted);
+       ls_ted_clean(area->mta->ted);
 
        /* Disable Extended SubTLVs on all circuit */
        for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
@@ -336,16 +342,12 @@ void isis_link_params_update(struct isis_circuit *circuit,
        return;
 }
 
-static int isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
-                                      bool global)
+static int _isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
+                                       bool global)
 {
        struct isis_circuit *circuit;
        struct isis_ext_subtlvs *ext;
 
-       /* Sanity Check */
-       if (!adj || !adj->circuit)
-               return 0;
-
        circuit = adj->circuit;
 
        /* Check that MPLS TE is enabled */
@@ -366,6 +368,12 @@ static int isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
                }
                break;
        case AF_INET6:
+               /* Nothing to do for link-local addresses - ie. not global.
+                * https://datatracker.ietf.org/doc/html/rfc6119#section-3.1.1
+                * Because the IPv6 traffic engineering TLVs present in LSPs are
+                * propagated across networks, they MUST NOT use link-local
+                * addresses.
+                */
                if (!global)
                        return 0;
 
@@ -381,22 +389,32 @@ static int isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
                return 0;
        }
 
-       /* Update LSP */
-       lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
-
        return 0;
 }
 
-static int isis_mpls_te_adj_ip_disabled(struct isis_adjacency *adj, int family,
-                                       bool global)
+static int isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
+                                      bool global)
 {
-       struct isis_circuit *circuit;
-       struct isis_ext_subtlvs *ext;
+       int ret;
 
        /* Sanity Check */
-       if (!adj || !adj->circuit || !adj->circuit->ext)
+       if (!adj || !adj->circuit)
                return 0;
 
+       ret = _isis_mpls_te_adj_ip_enabled(adj, family, global);
+
+       /* Update LSP */
+       lsp_regenerate_schedule(adj->circuit->area, adj->circuit->is_type, 0);
+
+       return ret;
+}
+
+static int _isis_mpls_te_adj_ip_disabled(struct isis_adjacency *adj, int family,
+                                        bool global)
+{
+       struct isis_circuit *circuit;
+       struct isis_ext_subtlvs *ext;
+
        circuit = adj->circuit;
 
        /* Check that MPLS TE is enabled */
@@ -422,12 +440,59 @@ static int isis_mpls_te_adj_ip_disabled(struct isis_adjacency *adj, int family,
                return 0;
        }
 
+       return 0;
+}
+
+static int isis_mpls_te_adj_ip_disabled(struct isis_adjacency *adj, int family,
+                                       bool global)
+{
+       int ret;
+
+       /* Sanity Check */
+       if (!adj || !adj->circuit || !adj->circuit->ext)
+               return 0;
+
+       ret = _isis_mpls_te_adj_ip_disabled(adj, family, global);
+
        /* Update LSP */
-       lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
+       lsp_regenerate_schedule(adj->circuit->area, adj->circuit->is_type, 0);
 
-       return 0;
+       return ret;
 }
 
+static void isis_mpls_te_circuit_ip_update(struct isis_circuit *circuit)
+{
+       struct isis_adjacency *adj;
+
+       /* https://datatracker.ietf.org/doc/html/rfc6119#section-3.2.3
+        * This sub-TLV of the Extended IS Reachability TLV is used for point-
+        * to-point links
+        */
+       if (circuit->circ_type != CIRCUIT_T_P2P)
+               return;
+
+       adj = circuit->u.p2p.neighbor;
+
+       if (!adj)
+               return;
+
+       /* Nothing to do for link-local addresses.
+        * https://datatracker.ietf.org/doc/html/rfc6119#section-3.1.1
+        * Because the IPv6 traffic engineering TLVs present in LSPs are
+        * propagated across networks, they MUST NOT use link-local addresses.
+        */
+       if (adj->ipv4_address_count > 0)
+               _isis_mpls_te_adj_ip_enabled(adj, AF_INET, false);
+       else
+               _isis_mpls_te_adj_ip_disabled(adj, AF_INET, false);
+
+       if (adj->global_ipv6_count > 0)
+               _isis_mpls_te_adj_ip_enabled(adj, AF_INET6, true);
+       else
+               _isis_mpls_te_adj_ip_disabled(adj, AF_INET6, true);
+}
+
+
 int isis_mpls_te_update(struct interface *ifp)
 {
        struct isis_circuit *circuit;
index fa4fdb82d38af2f01bba2717f256af4e1a7d0a91..deb0690dcf12c0eab5d4b648b6d4d70199d865dc 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -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);
index 1c948b875a458a6e178f087042ef70eb3d8aa80a..478a90d63a7cf7d4d422da362a8448d8427ff9c5 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -588,6 +588,8 @@ struct connected *connected_get_linklocal(struct interface *ifp);
 
 /* link parameters */
 struct if_link_params *if_link_params_get(struct interface *);
+struct if_link_params *if_link_params_enable(struct interface *ifp);
+struct if_link_params *if_link_params_init(struct interface *ifp);
 void if_link_params_free(struct interface *);
 
 /* Northbound. */
index 8ec82ab7bb91c5bd0f3def83b7e981e7f3f0af0e..f5d45b40ef871a2403052ebf1e7c1ca2744e1f95 100644 (file)
@@ -2299,13 +2299,22 @@ static int zclient_handle_error(ZAPI_CALLBACK_ARGS)
        return 0;
 }
 
-static int link_params_set_value(struct stream *s, struct if_link_params *iflp)
+static int link_params_set_value(struct stream *s, struct interface *ifp)
 {
+       uint8_t link_params_enabled;
+       struct if_link_params *iflp;
+       uint32_t bwclassnum;
+
+       iflp = if_link_params_get(ifp);
 
        if (iflp == NULL)
-               return -1;
+               iflp = if_link_params_init(ifp);
 
-       uint32_t bwclassnum;
+       STREAM_GETC(s, link_params_enabled);
+       if (!link_params_enabled) {
+               if_link_params_free(ifp);
+               return 0;
+       }
 
        STREAM_GETL(s, iflp->lp_status);
        STREAM_GETL(s, iflp->te_metric);
@@ -2346,9 +2355,9 @@ struct interface *zebra_interface_link_params_read(struct stream *s,
                                                   bool *changed)
 {
        struct if_link_params *iflp;
-       struct if_link_params iflp_copy;
+       struct if_link_params iflp_prev;
        ifindex_t ifindex;
-       bool params_changed = false;
+       bool iflp_prev_set;
 
        STREAM_GETL(s, ifindex);
 
@@ -2361,22 +2370,32 @@ struct interface *zebra_interface_link_params_read(struct stream *s,
                return NULL;
        }
 
-       if (ifp->link_params == NULL)
-               params_changed = true;
-
-       if ((iflp = if_link_params_get(ifp)) == NULL)
-               return NULL;
-
-       memcpy(&iflp_copy, iflp, sizeof(iflp_copy));
+       iflp = if_link_params_get(ifp);
+       if (iflp) {
+               iflp_prev_set = true;
+               memcpy(&iflp_prev, ifp->link_params, sizeof(iflp_prev));
+       } else
+               iflp_prev_set = false;
 
-       if (link_params_set_value(s, iflp) != 0)
+       /* read the link_params from stream
+        * Free ifp->link_params if the stream has no params
+        * to means that link-params are not enabled on links.
+        */
+       if (link_params_set_value(s, ifp) != 0)
                goto stream_failure;
 
-       if (memcmp(&iflp_copy, iflp, sizeof(iflp_copy)))
-               params_changed = true;
+       if (changed == NULL)
+               return ifp;
 
-       if (changed)
-               *changed = params_changed;
+       if (iflp_prev_set && iflp) {
+               if (memcmp(&iflp_prev, iflp, sizeof(iflp_prev)))
+                       *changed = true;
+               else
+                       *changed = false;
+       } else if (!iflp_prev_set && !iflp)
+               *changed = false;
+       else
+               *changed = true;
 
        return ifp;
 
@@ -2415,10 +2434,8 @@ static void zebra_interface_if_set_value(struct stream *s,
        /* Read Traffic Engineering status */
        link_params_status = stream_getc(s);
        /* Then, Traffic Engineering parameters if any */
-       if (link_params_status) {
-               struct if_link_params *iflp = if_link_params_get(ifp);
-               link_params_set_value(s, iflp);
-       }
+       if (link_params_status)
+               link_params_set_value(s, ifp);
 
        nexthop_group_interface_state_change(ifp, old_ifindex);
 
@@ -2435,12 +2452,20 @@ size_t zebra_interface_link_params_write(struct stream *s,
        struct if_link_params *iflp;
        int i;
 
-       if (s == NULL || ifp == NULL || ifp->link_params == NULL)
+       if (s == NULL || ifp == NULL)
                return 0;
 
        iflp = ifp->link_params;
        w = 0;
 
+       /* encode if link_params is enabled */
+       if (iflp) {
+               w += stream_putc(s, true);
+       } else {
+               w += stream_putc(s, false);
+               return w;
+       }
+
        w += stream_putl(s, iflp->lp_status);
 
        w += stream_putl(s, iflp->te_metric);
index d98f83dbf6d6f32482a1ca2b0caf2de9d661087b..0f28b49f72474e401ee325f623c1af7086b32bf2 100644 (file)
@@ -652,18 +652,21 @@ int vtysh_read_config(const char *config_default_dir, bool dry_run)
  */
 void vtysh_config_write(void)
 {
+       const char *name;
        char line[512];
 
-       if (cmd_hostname_get()) {
-               snprintf(line, sizeof(line), "hostname %s", cmd_hostname_get());
+       name = cmd_hostname_get();
+       if (name && name[0] != '\0') {
+               snprintf(line, sizeof(line), "hostname %s", name);
                vtysh_config_parse_line(NULL, line);
        }
 
-       if (cmd_domainname_get()) {
-               snprintf(line, sizeof(line), "domainname %s",
-                        cmd_domainname_get());
+       name = cmd_domainname_get();
+       if (name && name[0] != '\0') {
+               snprintf(line, sizeof(line), "domainname %s", name);
                vtysh_config_parse_line(NULL, line);
        }
+
        if (vtysh_write_integrated == WRITE_INTEGRATED_NO)
                vtysh_config_parse_line(NULL,
                                        "no service integrated-vtysh-config");
index c674b499ac82ad6ec4e30506300262ab653630ec..5d62ec071f472f9c9593f083809ebc6165f187b8 100644 (file)
@@ -3279,14 +3279,8 @@ DEFUN (link_params_enable,
                        "Link-params: enable TE link parameters on interface %s",
                        ifp->name);
 
-       if (!if_link_params_get(ifp)) {
-               if (IS_ZEBRA_DEBUG_EVENT || IS_ZEBRA_DEBUG_MPLS)
-                       zlog_debug(
-                               "Link-params: failed to init TE link parameters  %s",
-                               ifp->name);
-
-               return CMD_WARNING_CONFIG_FAILED;
-       }
+       if (!if_link_params_get(ifp))
+               if_link_params_enable(ifp);
 
        /* force protocols to update LINK STATE due to parameters change */
        if (if_is_operative(ifp))
@@ -3330,6 +3324,9 @@ DEFUN (link_params_metric,
 
        metric = strtoul(argv[idx_number]->arg, NULL, 10);
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update TE metric if needed */
        link_param_cmd_set_uint32(ifp, &iflp->te_metric, LP_TE_METRIC, metric);
 
@@ -3370,17 +3367,20 @@ DEFUN (link_params_maxbw,
 
        /* Check that Maximum bandwidth is not lower than other bandwidth
         * parameters */
-       if ((bw <= iflp->max_rsv_bw) || (bw <= iflp->unrsv_bw[0])
-           || (bw <= iflp->unrsv_bw[1]) || (bw <= iflp->unrsv_bw[2])
-           || (bw <= iflp->unrsv_bw[3]) || (bw <= iflp->unrsv_bw[4])
-           || (bw <= iflp->unrsv_bw[5]) || (bw <= iflp->unrsv_bw[6])
-           || (bw <= iflp->unrsv_bw[7]) || (bw <= iflp->ava_bw)
-           || (bw <= iflp->res_bw) || (bw <= iflp->use_bw)) {
+       if (iflp && ((bw <= iflp->max_rsv_bw) || (bw <= iflp->unrsv_bw[0]) ||
+                    (bw <= iflp->unrsv_bw[1]) || (bw <= iflp->unrsv_bw[2]) ||
+                    (bw <= iflp->unrsv_bw[3]) || (bw <= iflp->unrsv_bw[4]) ||
+                    (bw <= iflp->unrsv_bw[5]) || (bw <= iflp->unrsv_bw[6]) ||
+                    (bw <= iflp->unrsv_bw[7]) || (bw <= iflp->ava_bw) ||
+                    (bw <= iflp->res_bw) || (bw <= iflp->use_bw))) {
                vty_out(vty,
                        "Maximum Bandwidth could not be lower than others bandwidth\n");
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Maximum Bandwidth if needed */
        link_param_cmd_set_float(ifp, &iflp->max_bw, LP_MAX_BW, bw);
 
@@ -3406,13 +3406,16 @@ DEFUN (link_params_max_rsv_bw,
 
        /* Check that bandwidth is not greater than maximum bandwidth parameter
         */
-       if (bw > iflp->max_bw) {
+       if (iflp && bw > iflp->max_bw) {
                vty_out(vty,
                        "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
                        iflp->max_bw);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Maximum Reservable Bandwidth if needed */
        link_param_cmd_set_float(ifp, &iflp->max_rsv_bw, LP_MAX_RSV_BW, bw);
 
@@ -3448,13 +3451,16 @@ DEFUN (link_params_unrsv_bw,
 
        /* Check that bandwidth is not greater than maximum bandwidth parameter
         */
-       if (bw > iflp->max_bw) {
+       if (iflp && bw > iflp->max_bw) {
                vty_out(vty,
                        "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
                        iflp->max_bw);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Unreserved Bandwidth if needed */
        link_param_cmd_set_float(ifp, &iflp->unrsv_bw[priority], LP_UNRSV_BW,
                                 bw);
@@ -3479,6 +3485,9 @@ DEFUN (link_params_admin_grp,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Administrative Group if needed */
        link_param_cmd_set_uint32(ifp, &iflp->admin_grp, LP_ADM_GRP, value);
 
@@ -3521,6 +3530,9 @@ DEFUN (link_params_inter_as,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        as = strtoul(argv[idx_number]->arg, NULL, 10);
 
        /* Update Remote IP and Remote AS fields if needed */
@@ -3548,6 +3560,9 @@ DEFUN (no_link_params_inter_as,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct if_link_params *iflp = if_link_params_get(ifp);
 
+       if (!iflp)
+               return CMD_SUCCESS;
+
        /* Reset Remote IP and AS neighbor */
        iflp->rmt_as = 0;
        iflp->rmt_ip.s_addr = 0;
@@ -3595,13 +3610,17 @@ DEFUN (link_params_delay,
                 * Therefore, it is also allowed that the average
                 * delay be equal to the min delay or max delay.
                 */
-               if (IS_PARAM_SET(iflp, LP_MM_DELAY)
-                   && (delay < iflp->min_delay || delay > iflp->max_delay)) {
+               if (iflp && IS_PARAM_SET(iflp, LP_MM_DELAY) &&
+                   (delay < iflp->min_delay || delay > iflp->max_delay)) {
                        vty_out(vty,
                                "Average delay should be in range Min (%d) - Max (%d) delay\n",
                                iflp->min_delay, iflp->max_delay);
                        return CMD_WARNING_CONFIG_FAILED;
                }
+
+               if (!iflp)
+                       iflp = if_link_params_enable(ifp);
+
                /* Update delay if value is not set or change */
                if (IS_PARAM_UNSET(iflp, LP_DELAY) || iflp->av_delay != delay) {
                        iflp->av_delay = delay;
@@ -3626,6 +3645,10 @@ DEFUN (link_params_delay,
                                low, high);
                        return CMD_WARNING_CONFIG_FAILED;
                }
+
+               if (!iflp)
+                       iflp = if_link_params_enable(ifp);
+
                /* Update Delays if needed */
                if (IS_PARAM_UNSET(iflp, LP_DELAY)
                    || IS_PARAM_UNSET(iflp, LP_MM_DELAY)
@@ -3656,6 +3679,9 @@ DEFUN (no_link_params_delay,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct if_link_params *iflp = if_link_params_get(ifp);
 
+       if (!iflp)
+               return CMD_SUCCESS;
+
        /* Unset Delays */
        iflp->av_delay = 0;
        UNSET_PARAM(iflp, LP_DELAY);
@@ -3683,6 +3709,9 @@ DEFUN (link_params_delay_var,
 
        value = strtoul(argv[idx_number]->arg, NULL, 10);
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Delay Variation if needed */
        link_param_cmd_set_uint32(ifp, &iflp->delay_var, LP_DELAY_VAR, value);
 
@@ -3723,6 +3752,9 @@ DEFUN (link_params_pkt_loss,
        if (fval > MAX_PKT_LOSS)
                fval = MAX_PKT_LOSS;
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Packet Loss if needed */
        link_param_cmd_set_float(ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval);
 
@@ -3762,13 +3794,16 @@ DEFUN (link_params_res_bw,
 
        /* Check that bandwidth is not greater than maximum bandwidth parameter
         */
-       if (bw > iflp->max_bw) {
+       if (iflp && bw > iflp->max_bw) {
                vty_out(vty,
                        "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
                        iflp->max_bw);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Residual Bandwidth if needed */
        link_param_cmd_set_float(ifp, &iflp->res_bw, LP_RES_BW, bw);
 
@@ -3808,13 +3843,16 @@ DEFUN (link_params_ava_bw,
 
        /* Check that bandwidth is not greater than maximum bandwidth parameter
         */
-       if (bw > iflp->max_bw) {
+       if (iflp && bw > iflp->max_bw) {
                vty_out(vty,
                        "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
                        iflp->max_bw);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Residual Bandwidth if needed */
        link_param_cmd_set_float(ifp, &iflp->ava_bw, LP_AVA_BW, bw);
 
@@ -3854,13 +3892,16 @@ DEFUN (link_params_use_bw,
 
        /* Check that bandwidth is not greater than maximum bandwidth parameter
         */
-       if (bw > iflp->max_bw) {
+       if (iflp && bw > iflp->max_bw) {
                vty_out(vty,
                        "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
                        iflp->max_bw);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
+       if (!iflp)
+               iflp = if_link_params_enable(ifp);
+
        /* Update Utilized Bandwidth if needed */
        link_param_cmd_set_float(ifp, &iflp->use_bw, LP_USE_BW, bw);
 
index 761ba789b87afb1ab3193956ec67432477444a6a..4d7ad21bf367d5e4b3b4b62aa4fd42aade3116f5 100644 (file)
@@ -232,11 +232,6 @@ int zsend_interface_link_params(struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       if (!ifp->link_params) {
-               stream_free(s);
-               return 0;
-       }
-
        zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf->vrf_id);
 
        /* Add Interface Index */