endif
EXTRA_DIST += \
- SERVICES \
aclocal.m4 \
update-autotools \
m4/README.txt \
See doc/developer/workflow.rst for information on contributing.
-Free RRRouting is free software. See the file COPYING for copying conditions.
+See the file COPYING for copying conditions.
Public email discussion can be found at https://lists.frrouting.org/listinfo
+++ /dev/null
-# As long as this software is in alpha testing it is not yet included
-# in /etc/services files. This means that you may need to add the following
-# lines into your /etc/services file on your hosts.
-#
-# --- Please add this to your /etc/services ---
-
-#
-# GNU Zebra services
-#
-
-zebrasrv 2600/tcp
-zebra 2601/tcp
-ripd 2602/tcp
-ripng 2603/tcp
-ospfd 2604/tcp
-bgpd 2605/tcp
-ospf6d 2606/tcp
-ospfapi 2607/tcp
-isisd 2608/tcp
-babeld 2609/tcp
-nhrpd 2610/tcp
-pimd 2611/tcp
-ldpd 2612/tcp
-eigrpd 2613/tcp
if (com == NULL || com->size == 0)
str = "";
else
- str = lcommunity_str(com);
+ str = lcommunity_str(com, false);
/* Regular expression match. */
if (regexec(reg, str, 0, NULL, 0) == 0)
entry->any = (str ? 0 : 1);
entry->u.lcom = lcom;
entry->reg = regex;
- if (lcom)
- entry->config = lcommunity_lcom2str(
- lcom, LCOMMUNITY_FORMAT_COMMUNITY_LIST);
- else if (regex)
- entry->config = XSTRDUP(MTYPE_COMMUNITY_LIST_CONFIG, str);
- else
- entry->config = NULL;
+ entry->config =
+ (regex ? XSTRDUP(MTYPE_COMMUNITY_LIST_CONFIG, str) : NULL);
/* Do not put duplicated community entry. */
if (community_list_dup_check(list, entry))
sizeof(struct ecommunity));
}
+void ecommunity_strfree(char **s)
+{
+ XFREE(MTYPE_ECOMMUNITY_STR, *s);
+}
+
/* Allocate ecommunities. */
void ecommunity_free(struct ecommunity **ecom)
{
extern unsigned int ecommunity_hash_make(void *);
extern struct ecommunity *ecommunity_str2com(const char *, int, int);
extern char *ecommunity_ecom2str(struct ecommunity *, int, int);
+extern void ecommunity_strfree(char **s);
extern int ecommunity_match(const struct ecommunity *,
const struct ecommunity *);
extern char *ecommunity_str(struct ecommunity *);
return strcmp(ecom1->str, ecom2->str);
}
+static void evpn_xxport_delete_ecomm(void *val)
+{
+ struct ecommunity *ecomm = val;
+ ecommunity_free(&ecomm);
+}
+
/*
* Mask off global-admin field of specified extended community (RT),
* just retain the local-admin field.
struct ecommunity_val eval;
struct ecommunity *ecomadd;
+ if (bgp->advertise_autort_rfc8365)
+ vni |= EVPN_AUTORT_VXLAN;
encode_route_target_as((bgp->as & 0xFFFF), vni, &eval);
ecomadd = ecommunity_new();
update_routes_for_vni(bgp_def, vpn);
}
+/*
+ * Handle autort change for a given VNI.
+ */
+static void update_autort_vni(struct hash_backet *backet, struct bgp *bgp)
+{
+ struct bgpevpn *vpn = backet->data;
+
+ if (!vpn) {
+ zlog_warn("%s: VNI hash entry for VNI not found", __PRETTY_FUNCTION__);
+ return;
+ }
+
+ if (!is_import_rt_configured(vpn)) {
+ if (is_vni_live(vpn))
+ bgp_evpn_uninstall_routes(bgp, vpn);
+ bgp_evpn_unmap_vni_from_its_rts(bgp, vpn);
+ list_delete_all_node(vpn->import_rtl);
+ bgp_evpn_derive_auto_rt_import(bgp, vpn);
+ if (is_vni_live(vpn))
+ bgp_evpn_install_routes(bgp, vpn);
+ }
+ if (!is_export_rt_configured(vpn)) {
+ list_delete_all_node(vpn->export_rtl);
+ bgp_evpn_derive_auto_rt_export(bgp, vpn);
+ if (is_vni_live(vpn))
+ bgp_evpn_handle_export_rt_change(bgp, vpn);
+ }
+}
+
/*
* Public functions.
*/
struct ecommunity *ecom, *ecom_auto;
struct ecommunity_val eval;
+ if (bgp->advertise_autort_rfc8365)
+ vni |= EVPN_AUTORT_VXLAN;
encode_route_target_as((bgp->as & 0xFFFF), vni, &eval);
ecom_auto = ecommunity_new();
}
}
+/*
+ * Handle change to auto-RT algorithm - update and advertise local routes.
+ */
+void bgp_evpn_handle_autort_change(struct bgp *bgp)
+{
+ hash_iterate(bgp->vnihash,
+ (void (*)(struct hash_backet *,
+ void*))update_autort_vni,
+ bgp);
+}
+
/*
* Handle change to export RT - update and advertise local routes.
*/
/* Initialize route-target import and export lists */
vpn->import_rtl = list_new();
vpn->import_rtl->cmp = (int (*)(void *, void *))evpn_route_target_cmp;
+ vpn->import_rtl->del = evpn_xxport_delete_ecomm;
vpn->export_rtl = list_new();
vpn->export_rtl->cmp = (int (*)(void *, void *))evpn_route_target_cmp;
+ vpn->export_rtl->del = evpn_xxport_delete_ecomm;
bf_assign_index(bm->rd_idspace, vpn->rd_id);
derive_rd_rt_for_vni(bgp, vpn);
bgp->vrf_import_rtl = list_new();
bgp->vrf_import_rtl->cmp =
(int (*)(void *, void *))evpn_route_target_cmp;
-
+ bgp->vrf_import_rtl->del = evpn_xxport_delete_ecomm;
bgp->vrf_export_rtl = list_new();
bgp->vrf_export_rtl->cmp =
(int (*)(void *, void *))evpn_route_target_cmp;
+ bgp->vrf_export_rtl->del = evpn_xxport_delete_ecomm;
bgp->l2vnis = list_new();
bgp->l2vnis->cmp = (int (*)(void *, void *))vni_hash_cmp;
}
#include "bgpd.h"
#define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
+#define EVPN_AUTORT_VXLAN 0x10000000
static inline int is_evpn_enabled(void)
{
struct ecommunity *ecomdel);
extern int bgp_evpn_handle_export_rt_change(struct bgp *bgp,
struct bgpevpn *vpn);
+extern void bgp_evpn_handle_autort_change(struct bgp *bgp);
extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw);
extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn,
int withdraw);
bgp_zebra_advertise_all_vni(bgp, bgp->advertise_all_vni);
bgp_evpn_cleanup_on_disable(bgp);
}
+
+/*
+ * EVPN - use RFC8365 to auto-derive RT
+ */
+static void evpn_set_advertise_autort_rfc8365(struct bgp *bgp)
+{
+ bgp->advertise_autort_rfc8365 = 1;
+ bgp_evpn_handle_autort_change(bgp);
+}
+
+/*
+ * EVPN - don't use RFC8365 to auto-derive RT
+ */
+static void evpn_unset_advertise_autort_rfc8365(struct bgp *bgp)
+{
+ bgp->advertise_autort_rfc8365 = 0;
+ bgp_evpn_handle_autort_change(bgp);
+}
#endif /* HAVE_CUMULUS */
static void write_vni_config(struct vty *vty, struct bgpevpn *vpn)
return CMD_SUCCESS;
}
+DEFUN (bgp_evpn_advertise_autort_rfc8365,
+ bgp_evpn_advertise_autort_rfc8365_cmd,
+ "autort rfc8365-compatible",
+ "Auto-derivation of RT\n"
+ "Auto-derivation of RT using RFC8365\n")
+{
+ struct bgp *bgp = VTY_GET_CONTEXT(bgp);
+
+ if (!bgp)
+ return CMD_WARNING;
+ evpn_set_advertise_autort_rfc8365(bgp);
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_bgp_evpn_advertise_autort_rfc8365,
+ no_bgp_evpn_advertise_autort_rfc8365_cmd,
+ "no autort rfc8365-compatible",
+ NO_STR
+ "Auto-derivation of RT\n"
+ "Auto-derivation of RT using RFC8365\n")
+{
+ struct bgp *bgp = VTY_GET_CONTEXT(bgp);
+
+ if (!bgp)
+ return CMD_WARNING;
+ evpn_unset_advertise_autort_rfc8365(bgp);
+ return CMD_SUCCESS;
+}
+
DEFUN (bgp_evpn_default_originate,
bgp_evpn_default_originate_cmd,
"default-originate <ipv4 | ipv6>",
if (bgp->advertise_all_vni)
vty_out(vty, " advertise-all-vni\n");
+ if (bgp->advertise_autort_rfc8365)
+ vty_out(vty, " autort rfc8365-compatible\n");
+
if (bgp->advertise_gw_macip)
vty_out(vty, " advertise-default-gw\n");
#if defined(HAVE_CUMULUS)
install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_all_vni_cmd);
install_element(BGP_EVPN_NODE, &no_bgp_evpn_advertise_all_vni_cmd);
+ install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_autort_rfc8365_cmd);
+ install_element(BGP_EVPN_NODE, &no_bgp_evpn_advertise_autort_rfc8365_cmd);
install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_default_gw_cmd);
install_element(BGP_EVPN_NODE, &no_bgp_evpn_advertise_default_gw_cmd);
install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_type5_cmd);
BGP_FLOWSPEC_NLRI_STRING_MAX,
"EC{%s}",
s == NULL ? "none" : s);
+
+ if (s)
+ ecommunity_strfree(&s);
}
snprintf(local_string, BGP_FLOWSPEC_NLRI_STRING_MAX,
"FS Rx %s %s %s %s", withdraw ?
return new;
}
-/* Retrun string representation of communities attribute. */
-char *lcommunity_str(struct lcommunity *lcom)
-{
- if (!lcom->str)
- lcom->str =
- lcommunity_lcom2str(lcom, LCOMMUNITY_FORMAT_DISPLAY);
- return lcom->str;
-}
-
/* Merge two Large Communities Attribute structure. */
struct lcommunity *lcommunity_merge(struct lcommunity *lcom1,
struct lcommunity *lcom2)
return lcom1;
}
+static void set_lcommunity_string(struct lcommunity *lcom, bool make_json)
+{
+ int i;
+ int len;
+ bool first = 1;
+ char *str_buf;
+ char *str_pnt;
+ uint8_t *pnt;
+ uint32_t global, local1, local2;
+ json_object *json_lcommunity_list = NULL;
+ json_object *json_string = NULL;
+
+#define LCOMMUNITY_STR_DEFAULT_LEN 32
+
+ if (!lcom)
+ return;
+
+ if (make_json) {
+ lcom->json = json_object_new_object();
+ json_lcommunity_list = json_object_new_array();
+ }
+
+ if (lcom->size == 0) {
+ str_buf = XMALLOC(MTYPE_LCOMMUNITY_STR, 1);
+ str_buf[0] = '\0';
+
+ if (make_json) {
+ json_object_string_add(lcom->json, "string", "");
+ json_object_object_add(lcom->json, "list",
+ json_lcommunity_list);
+ }
+
+ lcom->str = str_buf;
+ return;
+ }
+
+ str_buf = str_pnt =
+ XMALLOC(MTYPE_LCOMMUNITY_STR,
+ (LCOMMUNITY_STR_DEFAULT_LEN * lcom->size) + 1);
+
+ for (i = 0; i < lcom->size; i++) {
+ if (first)
+ first = 0;
+ else
+ *str_pnt++ = ' ';
+
+ pnt = lcom->val + (i * LCOMMUNITY_SIZE);
+ pnt = ptr_get_be32(pnt, &global);
+ pnt = ptr_get_be32(pnt, &local1);
+ pnt = ptr_get_be32(pnt, &local2);
+ (void)pnt;
+
+ len = sprintf(str_pnt, "%u:%u:%u", global, local1, local2);
+ if (make_json) {
+ json_string = json_object_new_string(str_pnt);
+ json_object_array_add(json_lcommunity_list,
+ json_string);
+ }
+
+ str_pnt += len;
+ }
+
+ str_buf =
+ XREALLOC(MTYPE_LCOMMUNITY_STR, str_buf, str_pnt - str_buf + 1);
+
+ if (make_json) {
+ json_object_string_add(lcom->json, "string", str_buf);
+ json_object_object_add(lcom->json, "list",
+ json_lcommunity_list);
+ }
+
+ lcom->str = str_buf;
+}
+
/* Intern Large Communities Attribute. */
struct lcommunity *lcommunity_intern(struct lcommunity *lcom)
{
find->refcnt++;
if (!find->str)
- find->str =
- lcommunity_lcom2str(find, LCOMMUNITY_FORMAT_DISPLAY);
+ set_lcommunity_string(find, false);
return find;
}
}
}
+/* Retrun string representation of communities attribute. */
+char *lcommunity_str(struct lcommunity *lcom, bool make_json)
+{
+ if (!lcom)
+ return NULL;
+
+ if (make_json && !lcom->json && lcom->str)
+ XFREE(MTYPE_LCOMMUNITY_STR, lcom->str);
+
+ if (!lcom->str)
+ set_lcommunity_string(lcom, make_json);
+
+ return lcom->str;
+}
+
/* Utility function to make hash key. */
unsigned int lcommunity_hash_make(void *arg)
{
return 0;
}
-/* Convert large community attribute to string.
- The large coms will be in 65535:65531:0 format.
-*/
-char *lcommunity_lcom2str(struct lcommunity *lcom, int format)
-{
- int i;
- uint8_t *pnt;
-#define LCOMMUNITY_STR_DEFAULT_LEN 40
- int str_size;
- int str_pnt;
- char *str_buf;
- int len = 0;
- int first = 1;
- uint32_t globaladmin, localdata1, localdata2;
-
- if (lcom->size == 0) {
- str_buf = XMALLOC(MTYPE_LCOMMUNITY_STR, 1);
- str_buf[0] = '\0';
- return str_buf;
- }
-
- /* Prepare buffer. */
- str_buf = XMALLOC(MTYPE_LCOMMUNITY_STR, LCOMMUNITY_STR_DEFAULT_LEN + 1);
- str_size = LCOMMUNITY_STR_DEFAULT_LEN + 1;
- str_pnt = 0;
-
- for (i = 0; i < lcom->size; i++) {
- /* Make it sure size is enough. */
- while (str_pnt + LCOMMUNITY_STR_DEFAULT_LEN >= str_size) {
- str_size *= 2;
- str_buf = XREALLOC(MTYPE_LCOMMUNITY_STR, str_buf,
- str_size);
- }
-
- /* Space between each value. */
- if (!first)
- str_buf[str_pnt++] = ' ';
-
- pnt = lcom->val + (i * LCOMMUNITY_SIZE);
-
- pnt = ptr_get_be32(pnt, &globaladmin);
- pnt = ptr_get_be32(pnt, &localdata1);
- pnt = ptr_get_be32(pnt, &localdata2);
- (void)pnt; /* consume value */
-
- len = sprintf(str_buf + str_pnt, "%u:%u:%u", globaladmin,
- localdata1, localdata2);
- str_pnt += len;
- first = 0;
- }
- return str_buf;
-}
-
int lcommunity_match(const struct lcommunity *lcom1,
const struct lcommunity *lcom2)
{
#ifndef _QUAGGA_BGP_LCOMMUNITY_H
#define _QUAGGA_BGP_LCOMMUNITY_H
-/* Extended communities attribute string format. */
-#define LCOMMUNITY_FORMAT_ROUTE_MAP 0
-#define LCOMMUNITY_FORMAT_COMMUNITY_LIST 1
-#define LCOMMUNITY_FORMAT_DISPLAY 2
+#include "lib/json.h"
/* Large Communities value is twelve octets long. */
#define LCOMMUNITY_SIZE 12
/* Large Communities value. */
uint8_t *val;
+ /* Large Communities as a json object */
+ json_object *json;
+
/* Human readable format string. */
char *str;
};
extern unsigned int lcommunity_hash_make(void *);
extern struct hash *lcommunity_hash(void);
extern struct lcommunity *lcommunity_str2com(const char *);
-extern char *lcommunity_lcom2str(struct lcommunity *, int);
extern int lcommunity_match(const struct lcommunity *,
const struct lcommunity *);
-extern char *lcommunity_str(struct lcommunity *);
+extern char *lcommunity_str(struct lcommunity *, bool make_json);
extern int lcommunity_include(struct lcommunity *lcom, uint8_t *ptr);
extern void lcommunity_del_val(struct lcommunity *lcom, uint8_t *ptr);
#endif /* _QUAGGA_BGP_LCOMMUNITY_H */
if (nexthop_self_flag)
bgp_info_set_flag(bn, new, BGP_INFO_ANNC_NH_SELF);
+ bgp_info_extra_get(new);
+
if (num_labels)
setlabels(new, label, num_labels);
- bgp_info_extra_get(new);
new->extra->parent = bgp_info_lock(parent);
if (bgp_orig)
struct bgp *bgp_nexthop = bgp;
int nh_valid;
- if (new->extra && new->extra->bgp_orig)
+ if (new->extra->bgp_orig)
bgp_nexthop = new->extra->bgp_orig;
/*
static void bgp_unlink_nexthop_check(struct bgp_nexthop_cache *bnc)
{
- if (LIST_EMPTY(&(bnc->paths)) && !bnc->nht_info) {
+ if (LIST_EMPTY(&(bnc->paths)) && bnc->nht_info) {
if (BGP_DEBUG(nht, NHT)) {
char buf[PREFIX2STR_BUFFER];
zlog_debug("bgp_unlink_nexthop: freeing bnc %s",
? true
: false;
bool nexthop_othervrf = false;
- vrf_id_t nexthop_vrfid;
+ vrf_id_t nexthop_vrfid = VRF_DEFAULT;
const char *nexthop_vrfname = "Default";
if (json_paths)
json_object *json_cluster_list = NULL;
json_object *json_cluster_list_list = NULL;
json_object *json_ext_community = NULL;
- json_object *json_lcommunity = NULL;
json_object *json_last_update = NULL;
json_object *json_pmsi = NULL;
json_object *json_nexthop_global = NULL;
/* Line 6 display Large community */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) {
if (json_paths) {
- json_lcommunity = json_object_new_object();
- json_object_string_add(json_lcommunity,
- "string",
- attr->lcommunity->str);
+ if (!attr->lcommunity->json)
+ lcommunity_str(attr->lcommunity, true);
+ json_object_lock(attr->lcommunity->json);
json_object_object_add(json_path,
"largeCommunity",
- json_lcommunity);
+ attr->lcommunity->json);
} else {
vty_out(vty, " Large Community: %s\n",
attr->lcommunity->str);
void *object)
{
struct access_list *alist;
- /* struct prefix_ipv4 match; */
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET) {
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL)
return RMAP_NOMATCH;
struct bgp_info *bgp_info;
struct prefix_ipv4 p;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET) {
bgp_info = object;
p.family = AF_INET;
p.prefix = bgp_info->attr->nexthop;
struct peer *peer;
struct prefix_ipv4 p;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET) {
bgp_info = object;
peer = bgp_info->peer;
{
struct prefix_list *plist;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET) {
plist = prefix_list_lookup(AFI_IP, (char *)rule);
if (plist == NULL)
return RMAP_NOMATCH;
struct bgp_info *bgp_info;
struct prefix_ipv4 p;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET) {
bgp_info = object;
p.family = AF_INET;
p.prefix = bgp_info->attr->nexthop;
struct peer *peer;
struct prefix_ipv4 p;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET) {
bgp_info = object;
peer = bgp_info->peer;
{
struct access_list *alist;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET6) {
alist = access_list_lookup(AFI_IP6, (char *)rule);
if (alist == NULL)
return RMAP_NOMATCH;
{
struct prefix_list *plist;
- if (type == RMAP_BGP) {
+ if (type == RMAP_BGP && prefix->family == AF_INET6) {
plist = prefix_list_lookup(AFI_IP6, (char *)rule);
if (plist == NULL)
return RMAP_NOMATCH;
const char *arg)
{
int ret;
+ bool found = false;
struct peer *peer;
struct listnode *node, *nnode;
/* Clear all neighbors. */
/*
* Pass along pointer to next node to peer_clear() when walking all
- * nodes
- * on the BGP instance as that may get freed if it is a doppelganger
+ * nodes on the BGP instance as that may get freed if it is a
+ * doppelganger
*/
if (sort == clear_all) {
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
+ if (!peer->afc[afi][safi])
+ continue;
+
if (stype == BGP_CLEAR_SOFT_NONE)
ret = peer_clear(peer, &nnode);
- else if (peer->afc[afi][safi])
- ret = peer_clear_soft(peer, afi, safi, stype);
else
- ret = 0;
+ ret = peer_clear_soft(peer, afi, safi, stype);
if (ret < 0)
bgp_clear_vty_error(vty, peer, afi, safi, ret);
+ else
+ found = true;
}
/* This is to apply read-only mode on this clear. */
if (stype == BGP_CLEAR_SOFT_NONE)
bgp->update_delay_over = 0;
+ if (!found)
+ vty_out(vty, "%%BGP: No %s peer configured",
+ afi_safi_print(afi, safi));
+
return CMD_SUCCESS;
}
- /* Clear specified neighbors. */
+ /* Clear specified neighbor. */
if (sort == clear_peer) {
union sockunion su;
- int ret;
/* Make sockunion for lookup. */
ret = str2sockunion(arg, &su);
}
}
- if (stype == BGP_CLEAR_SOFT_NONE)
+ if (!peer->afc[afi][safi])
+ ret = BGP_ERR_AF_UNCONFIGURED;
+ else if (stype == BGP_CLEAR_SOFT_NONE)
ret = peer_clear(peer, NULL);
else
ret = peer_clear_soft(peer, afi, safi, stype);
return CMD_SUCCESS;
}
- /* Clear all peer-group members. */
+ /* Clear all neighbors belonging to a specific peer-group. */
if (sort == clear_group) {
struct peer_group *group;
}
for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
- if (stype == BGP_CLEAR_SOFT_NONE) {
- peer_clear(peer, NULL);
- continue;
- }
-
if (!peer->afc[afi][safi])
continue;
- ret = peer_clear_soft(peer, afi, safi, stype);
+ if (stype == BGP_CLEAR_SOFT_NONE)
+ ret = peer_clear(peer, NULL);
+ else
+ ret = peer_clear_soft(peer, afi, safi, stype);
if (ret < 0)
bgp_clear_vty_error(vty, peer, afi, safi, ret);
+ else
+ found = true;
}
+
+ if (!found)
+ vty_out(vty,
+ "%%BGP: No %s peer belonging to peer-group %s is configured\n",
+ afi_safi_print(afi, safi), arg);
+
return CMD_SUCCESS;
}
+ /* Clear all external (eBGP) neighbors. */
if (sort == clear_external) {
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (peer->sort == BGP_PEER_IBGP)
continue;
+ if (!peer->afc[afi][safi])
+ continue;
+
if (stype == BGP_CLEAR_SOFT_NONE)
ret = peer_clear(peer, &nnode);
else
if (ret < 0)
bgp_clear_vty_error(vty, peer, afi, safi, ret);
+ else
+ found = true;
}
+
+ if (!found)
+ vty_out(vty,
+ "%%BGP: No external %s peer is configured\n",
+ afi_safi_print(afi, safi));
+
return CMD_SUCCESS;
}
+ /* Clear all neighbors belonging to a specific AS. */
if (sort == clear_as) {
- as_t as;
- int find = 0;
-
- as = strtoul(arg, NULL, 10);
+ as_t as = strtoul(arg, NULL, 10);
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (peer->as != as)
continue;
- find = 1;
- if (stype == BGP_CLEAR_SOFT_NONE)
+ if (!peer->afc[afi][safi])
+ ret = BGP_ERR_AF_UNCONFIGURED;
+ else if (stype == BGP_CLEAR_SOFT_NONE)
ret = peer_clear(peer, &nnode);
else
ret = peer_clear_soft(peer, afi, safi, stype);
if (ret < 0)
bgp_clear_vty_error(vty, peer, afi, safi, ret);
+ else
+ found = true;
}
- if (!find)
+
+ if (!found)
vty_out(vty,
- "%%BGP: No peer is configured with AS %s\n",
- arg);
+ "%%BGP: No %s peer is configured with AS %s\n",
+ afi_safi_print(afi, safi), arg);
+
return CMD_SUCCESS;
}
lcom = (struct lcommunity *)backet->data;
vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
- lcommunity_str(lcom));
+ lcommunity_str(lcom, false));
}
/* Show BGP's community internal data. */
return CMD_SUCCESS;
}
+/* Return configuration string of community-list entry. */
+static const char *community_list_config_str(struct community_entry *entry)
+{
+ const char *str;
+
+ if (entry->any)
+ str = "";
+ else {
+ if (entry->style == COMMUNITY_LIST_STANDARD)
+ str = community_str(entry->u.com, false);
+ else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
+ str = lcommunity_str(entry->u.lcom, false);
+ else
+ str = entry->config;
+ }
+ return str;
+}
+
static void community_list_show(struct vty *vty, struct community_list *list)
{
struct community_entry *entry;
else
vty_out(vty, " %s %s\n",
community_direct_str(entry->direct),
- entry->style == COMMUNITY_LIST_STANDARD
- ? community_str(entry->u.com, false)
- : entry->config);
+ community_list_config_str(entry));
}
}
else
vty_out(vty, " %s %s\n",
community_direct_str(entry->direct),
- entry->style == EXTCOMMUNITY_LIST_STANDARD
- ? entry->u.ecom->str
- : entry->config);
+ community_list_config_str(entry));
}
}
else
vty_out(vty, " %s %s\n",
community_direct_str(entry->direct),
- entry->style == EXTCOMMUNITY_LIST_STANDARD
- ? entry->u.ecom->str
- : entry->config);
+ community_list_config_str(entry));
}
}
return CMD_SUCCESS;
}
-/* Return configuration string of community-list entry. */
-static const char *community_list_config_str(struct community_entry *entry)
-{
- const char *str;
-
- if (entry->any)
- str = "";
- else {
- if (entry->style == COMMUNITY_LIST_STANDARD)
- str = community_str(entry->u.com, false);
- else
- str = entry->config;
- }
- return str;
-}
-
/* Display community-list and extcommunity-list configuration. */
static int community_list_config_write(struct vty *vty)
{
uint8_t response_keep;
uint32_t first;
uint32_t last;
+ uint8_t proto;
+ unsigned short instance;
s = zclient->ibuf;
+ STREAM_GETC(s, proto);
+ STREAM_GETW(s, instance);
STREAM_GETC(s, response_keep);
STREAM_GETL(s, first);
STREAM_GETL(s, last);
+ if (zclient->redist_default != proto) {
+ zlog_err("Got LM msg with wrong proto %u", proto);
+ return;
+ }
+ if (zclient->instance != instance) {
+ zlog_err("Got LM msg with wrong instance %u", proto);
+ return;
+ }
+
if (first > last ||
first < MPLS_LABEL_UNRESERVED_MIN ||
last > MPLS_LABEL_UNRESERVED_MAX) {
/* EVPN enable - advertise local VNIs and their MACs etc. */
int advertise_all_vni;
+ /* EVPN - use RFC 8365 to auto-derive RT */
+ int advertise_autort_rfc8365;
+
/* Hash table of Import RTs to EVIs */
struct hash *import_rt_hash;
manpages/index.rst \
manpages/isisd.rst \
manpages/ldpd.rst \
- manpages/Makefile \
+ manpages/Makefile.am \
manpages/mtracebis.rst \
manpages/nhrpd.rst \
manpages/ospf6d.rst \
developer/index.rst \
developer/ldpd-basic-test-setup.md \
developer/library.rst \
- developer/Makefile \
+ developer/Makefile.in \
developer/memtypes.rst \
developer/modules.rst \
developer/next-hop-tracking.rst \
user/babeld.rst \
user/basic.rst \
user/bgp.rst \
+ user/bugs.rst \
user/conf.py \
user/eigrpd.rst \
user/filter.rst \
+ user/getting-started.rst \
user/glossary.rst \
user/index.rst \
user/installation.rst \
user/ipv6.rst \
user/isisd.rst \
user/kernel.rst \
- user/Makefile \
+ user/Makefile.am \
user/nhrpd.rst \
user/ospf6d.rst \
user/ospfd.rst \
user/routemap.rst \
user/routeserver.rst \
user/rpki.rst \
+ user/setup.rst \
user/sharp.rst \
user/snmp.rst \
user/snmptrap.rst \
/_templates
/_build
-!/Makefile.in
--- /dev/null
+# This is necessary to support VPATH builds.
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+# This variable is used as the documentation source location in frr-sphinx.mk
+SOURCESDIR = @srcdir@
+
+include @srcdir@/../frr-sphinx.mk
+++ /dev/null
-# This is necessary to support VPATH builds.
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-# This variable is used as the documentation source location in frr-sphinx.mk
-SOURCESDIR = @srcdir@
-
-include @srcdir@/../frr-sphinx.mk
Ubuntu 18.04LTS
===============================================
-Install required packages
+Install dependencies
-------------------------
+Required packages
+^^^^^^^^^^^^^^^^^
-Add packages:
+::
+
+ sudo apt-get install \
+ git \
+ autoconf \
+ automake \
+ libtool \
+ make \
+ gawk \
+ libreadline-dev \
+ texinfo \
+ pkg-config \
+ libpam0g-dev \
+ libjson-c-dev \
+ bison \
+ flex \
+ python-pytest \
+ libc-ares-dev \
+ python3-dev \
+ libsystemd-dev \
+ python-ipaddr \
+ python3-sphinx
+
+Optional packages
+^^^^^^^^^^^^^^^^^
+
+Dependencies for additional functionality can be installed as-desired.
+
+Protobuf
+~~~~~~~~
::
- apt-get install git autoconf automake libtool make gawk libreadline-dev \
- texinfo pkg-config libpam0g-dev libjson-c-dev bison flex \
- python-pytest libc-ares-dev python3-dev libsystemd-dev python-ipaddr \
- python3-sphinx
+ sudo apt-get install \
+ protobuf-c-compiler \
+ libprotobuf-c-dev
+
+ZeroMQ
+~~~~~~
+
+::
+
+ sudo apt-get install \
+ libzmq5 \
+ libzmq3-dev
Get FRR, compile it and install it (from Git)
---------------------------------------------
--gecos "FRR suite" --shell /sbin/nologin frr
sudo usermod -a -G frrvty frr
-Download Source, configure and compile it
+Download source
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-(You may prefer different options on configure statement. These are just
-an example.)
-
::
git clone https://github.com/frrouting/frr.git frr
+
+Configure
+^^^^^^^^^
+Options below are provided as an example.
+
+.. seealso:: *Installation* section of user guide
+
+::
+
cd frr
./bootstrap.sh
./configure \
--enable-systemd=yes \
--with-pkg-git-version \
--with-pkg-extra-version=-MyOwnFRRVersion
+
+If optional packages were installed, the associated feature may now be
+enabled.
+
+.. option:: --enable-protobuf
+
+Enable support for protobuf transport
+
+.. option:: --enable-zeromq
+
+Enable support for ZeroMQ transport
+
+Compile
+^^^^^^^
+
+::
+
make
make check
sudo make install
Create empty FRR configuration files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Although not strictly necessary, it's good practice to create empty
+configuration files _before_ starting FRR. This assures that the permissions
+are correct. If the files are not already present, FRR will create them.
+
+It's also important to consider _which_ files to create. FRR supports writing
+configuration to a monolithic file, ``/etc/frr/frr.conf``, which is not
+recommended
+.. seealso:: *VTYSH* section of user guide
+
+The presence of ``/etc/frr/frr.conf`` on startup implicitly configures FRR to
+ignore daemon-specific configuration files.
+
+Daemon-specific configuration
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
::
sudo install -m 755 -o frr -g frr -d /var/log/frr
sudo install -m 640 -o frr -g frr /dev/null /etc/frr/pimd.conf
sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ldpd.conf
sudo install -m 640 -o frr -g frr /dev/null /etc/frr/nhrpd.conf
- sudo install -m 640 -o frr -g frrvty /dev/null /etc/frr/vtysh.conf
+
+Monolithic configuration
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ sudo install -m 755 -o frr -g frr -d /var/log/frr
+ sudo install -m 775 -o frr -g frrvty -d /etc/frr
+ sudo install -m 640 -o frr -g frr /dev/null /etc/frr/frr.conf
Enable IPv4 & IPv6 forwarding
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# based on Router Advertisements for this host
net.ipv6.conf.all.forwarding=1
-Enable MPLS Forwarding (with Linux Kernel >= 4.5)
+Add MPLS kernel modules
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Ubuntu 18.04 ships with kernel 4.15. MPLS modules are present by default.
+To enable, add the following lines to ``/etc/modules-load.d/modules.conf``:
+
+::
+
+ # Load MPLS Kernel Modules
+ mpls_router
+ mpls_iptunnel
+
+**Reboot** or use ``sysctl -p`` to apply the same config to the running
+system
+
+Enable MPLS Forwarding
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Edit ``/etc/sysctl.conf`` and the following lines. Make sure to add a
net.mpls.conf.eth2.input=1
net.mpls.platform_labels=100000
-Add MPLS kernel modules
-^^^^^^^^^^^^^^^^^^^^^^^
-
-Add the following lines to ``/etc/modules-load.d/modules.conf``:
-
-::
-
- # Load MPLS Kernel Modules
- mpls-router
- mpls-iptunnel
-
-**Reboot** or use ``sysctl -p`` to apply the same config to the running
-system
-
Install the systemd service (if rebooted from last step, change directory back to frr directory)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/_templates
/_build
-!/Makefile.in
--- /dev/null
+# This is necessary to support VPATH builds.
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+# This variable is used as the documentation source location in frr-sphinx.mk
+SOURCESDIR = @srcdir@
+
+include @srcdir@/../frr-sphinx.mk
+
+# -----------------------------------------------------------------------------
+# Automake requires that 3rd-party Makefiles recognize these targets.
+# -----------------------------------------------------------------------------
+# install
+# install-data
+# install-exec
+# uninstall
+# install-dvi
+# install-html
+# install-info
+# install-ps
+# install-pdf
+# installdirs
+# check
+# installcheck
+# mostlyclean
+# clean
+# distclean
+# maintainer-clean
+# dvi
+# pdf
+# ps
+# info
+# html
+# tags
+# ctags
+
+# These targets are automatically generated by Sphinx but conflict with
+# implicitly defined Automake rules, so we manually override them to nothing.
+# The other option is deleting the Sphinx-generated rules, which suppresses the
+# warning but kinda screws up the symmetry between Makefiles.
+info: ;
+html: ;
+
+all: man
+
+install-data: man
+
+install: install-data
+++ /dev/null
-# This is necessary to support VPATH builds.
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-# This variable is used as the documentation source location in frr-sphinx.mk
-SOURCESDIR = @srcdir@
-
-include @srcdir@/../frr-sphinx.mk
-
-# -----------------------------------------------------------------------------
-# Automake requires that 3rd-party Makefiles recognize these targets.
-# -----------------------------------------------------------------------------
-# install
-# install-data
-# install-exec
-# uninstall
-# install-dvi
-# install-html
-# install-info
-# install-ps
-# install-pdf
-# installdirs
-# check
-# installcheck
-# mostlyclean
-# clean
-# distclean
-# maintainer-clean
-# dvi
-# pdf
-# ps
-# info
-# html
-# tags
-# ctags
-
-# ignore these targets
-EMPTY_AUTOMAKE_TARGETS = dvi pdf ps tags ctags distdir installdirs check installcheck install-dvi install-ps install-html install-pdf install-info install-exec
-.PHONY: $(EMPTY_AUTOMAKE_TARGETS)
-$(EMPTY_AUTOMAKE_TARGETS):
-
-# These targets are automatically generated by Sphinx but conflict with
-# implicitly defined Automake rules, so we manually override them to nothing.
-# The other option is deleting the Sphinx-generated rules, which suppresses the
-# warning but kinda screws up the symmetry between Makefiles.
-info: ;
-html: ;
-
-all: man
-
-install-data: man
-
-install: install-data
-
-mostlyclean distclean maintainer-clean: clean
/_templates
/_build
-!/Makefile.in
--- /dev/null
+# This is necessary to support VPATH builds.
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+# This variable is used as the documentation source location in frr-sphinx.mk
+SOURCESDIR = @srcdir@
+
+include @srcdir@/../frr-sphinx.mk
+
+# -----------------------------------------------------------------------------
+# Automake requires that 3rd-party Makefiles recognize these targets.
+# -----------------------------------------------------------------------------
+# install
+# install-data
+# install-exec
+# uninstall
+# install-dvi
+# install-html
+# install-info
+# install-ps
+# install-pdf
+# installdirs
+# check
+# installcheck
+# mostlyclean
+# clean
+# distclean
+# maintainer-clean
+# dvi
+# pdf
+# ps
+# info
+# html
+# tags
+# ctags
+
+# When building 'all', the logic is that we want to make docs that are easily
+# readable by the person that just built them. Technically the reST source is
+# readable in its own right, but we'll also build info and html because those
+# offer sequentially better reading experiences. PDF is not built by default
+# because it takes quite a while.
+all: info
+
+# info and html already have built-in sphinx rules; pdf goes to latexpdf
+pdf: latexpdf
+
+# install user manual as info file
+install-info: info
+ install -d ${DESTDIR}${infodir}
+ gzip < _build/texinfo/frr.info > ${DESTDIR}${infodir}/frr.info.gz
+ install-info _build/texinfo/frr.info ${DESTDIR}${infodir}/dir
+
+install-data: install-info
+
+install: install-data
+++ /dev/null
-# This is necessary to support VPATH builds.
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-# This variable is used as the documentation source location in frr-sphinx.mk
-SOURCESDIR = @srcdir@
-
-include @srcdir@/../frr-sphinx.mk
-
-# -----------------------------------------------------------------------------
-# Automake requires that 3rd-party Makefiles recognize these targets.
-# -----------------------------------------------------------------------------
-# install
-# install-data
-# install-exec
-# uninstall
-# install-dvi
-# install-html
-# install-info
-# install-ps
-# install-pdf
-# installdirs
-# check
-# installcheck
-# mostlyclean
-# clean
-# distclean
-# maintainer-clean
-# dvi
-# pdf
-# ps
-# info
-# html
-# tags
-# ctags
-
-# ignore these targets
-EMPTY_AUTOMAKE_TARGETS = dvi ps tags ctags distdir install-exec install-dvi install-ps installdirs check installcheck install-html install-pdf install-data install
-.PHONY: $(EMPTY_AUTOMAKE_TARGETS)
-$(EMPTY_AUTOMAKE_TARGETS):
-
-# When building 'all', the logic is that we want to make docs that are easily
-# readable by the person that just built them. Technically the reST source is
-# readable in its own right, but we'll also build info and html because those
-# offer sequentially better reading experiences. PDF is not built by default
-# because it takes quite a while.
-all: info
-
-# info and html already have built-in sphinx rules; pdf goes to latexpdf
-pdf: latexpdf
-
-# install user manual as info file
-install-info: info
- install -d ${DESTDIR}${infodir}
- gzip < _build/texinfo/frr.info > ${DESTDIR}${infodir}/frr.info.gz
- install-info _build/texinfo/frr.info ${DESTDIR}${infodir}/dir
-
-install-data: install-info
-
-install: install-data
-
-mostlyclean distclean maintainer-clean: clean
--- /dev/null
+***************
+Getting Started
+***************
+
+.. toctree::
+ :maxdepth: 2
+
+ installation
+ setup
:maxdepth: 2
overview
- installation
+ getting-started
basic
vtysh
filter
.. _installation:
-************
Installation
-************
+============
.. index:: How to install FRR
.. index:: Installation
.. index:: Building the system
.. index:: Making FRR
-Several distributions provide packages for FRR. Check your distribution's
-repositories to find out if a suitable version is available.
+This section covers the basics of building, installing and setting up FRR.
-FRR depends on various libraries depending on your operating system.
+From Packages
+-------------
-After installing these dependencies, change to the frr source directory and
-issue the following commands:
+The project publishes packages for Red Hat, Centos, Debian and Ubuntu on the
+`GitHub releases <https://github.com/FRRouting/frr/releases>`_. page. External
+contributors offer packages for many other platforms including \*BSD, Alpine,
+Gentoo, Docker, and others. There is currently no documentation on how to use
+those but we hope to add it soon.
-::
+From Snapcraft
+--------------
- $ ./bootstrap.sh
- $ ./configure
- $ make
- $ make install
+In addition to traditional packages the project also builds and publishes
+universal Snap images, available at https://snapcraft.io/frr.
+From Source
+-----------
-.. _configure-the-software:
+Building FRR from source is the best way to ensure you have the latest features
+and bug fixes. Details for each supported platform, including dependency
+package listings, permissions, and other gotchas, are in the developer's
+documentation. This section provides a brief overview on the process.
-Configure the Software
-======================
+Getting the Source
+^^^^^^^^^^^^^^^^^^
+FRR's source is available on the project
+`GitHub page <https://github.com/FRRouting/frr>`_.
-.. _the-configure-script:
+.. code-block:: shell
-The Configure Script
---------------------
+ git clone https://github.com/FRRouting/frr.git
-.. index:: Configuration options
+When building from Git there are several branches to choose from. The
+``master`` branch is the primary development branch. It should be considered
+unstable. Each release has its own branch named ``stable/X.X``, where ``X.X``
+is the release version.
-.. index:: Options for configuring
+In addition, release tarballs are published on the GitHub releases page
+`here <https://github.com/FRRouting/frr/releases>`_.
-.. index:: Build options
+Configuration
+^^^^^^^^^^^^^
+.. index:: Configuration options
+.. index:: Options for configuring
+.. index:: Build options
.. index:: Distribution configuration
-
.. index:: Options to `./configure`
-FRR has an excellent configure script which automatically detects most
-host configurations. There are several additional configure options to
-customize the build to include or exclude specific features and dependencies.
+FRR has an excellent configure script which automatically detects most host
+configurations. There are several additional configure options to customize the
+build to include or exclude specific features and dependencies.
+
+First, update the build system. Change into your FRR source directory and issue:
+
+.. code-block:: shell
+
+ ./bootstrap.sh
+
+This will install any missing build scripts and update the Autotools
+configuration. Once this is done you can move on to choosing your configuration
+options from the list below.
+
+.. _frr-configuration:
.. program:: configure
.. _least-privilege-support:
Least-Privilege Support
------------------------
+"""""""""""""""""""""""
.. index:: FRR Least-Privileges
-
.. index:: FRR Privileges
Additionally, you may configure zebra to drop its elevated privileges
raise these capabilities for brief periods. On systems without libcap, FRR will
run as the user specified and only raise its UID to 0 for brief periods.
-.. _linux-notes:
-
Linux Notes
------------
-
-.. index:: Configuring FRR
+"""""""""""
.. index:: Building on Linux boxes
-
.. index:: Linux configurations
-There are several options available only to GNU/Linux systems [#]_.
-If you use GNU/Linux, make sure that the current kernel configuration is what
-you want. FRR will run with any kernel configuration but some recommendations
-do exist.
-
-
-- :makevar:`CONFIG_NETLINK`
- Kernel/User Netlink socket. This is a brand new feature which enables an
- advanced interface between the Linux kernel and zebra (:ref:`kernel-interface`).
-- :makevar:`CONFIG_RTNETLINK`
- Routing messages.
- This makes it possible to receive Netlink routing messages. If you
- specify this option, *zebra* can detect routing information
- updates directly from the kernel (:ref:`kernel-interface`).
-- :makevar:`CONFIG_IP_MULTICAST`
- IP: multicasting.
- This option should be specified when you use *ripd* (:ref:`rip`) or
- *ospfd* (:ref:`ospfv2`) because these protocols use multicast.
-
-IPv6 support has been added in GNU/Linux kernel version 2.2. If you
-try to use the FRR IPv6 feature on a GNU/Linux kernel, please
-make sure the following libraries have been installed. Please note that
-these libraries will not be needed when you uses GNU C library 2.1
-or upper.
-
-- inet6-apps
-
- The `inet6-apps` package includes basic IPv6 related libraries such
- as `inet_ntop` and `inet_pton`. Some basic IPv6 programs such
- as *ping*, *ftp*, and *inetd* are also
- included. The `inet-apps` can be found at
- `ftp://ftp.inner.net/pub/ipv6/ <ftp://ftp.inner.net/pub/ipv6/>`_.
-
-- net-tools
-
- The `net-tools` package provides an IPv6 enabled interface and routing
- utility. It contains *ifconfig*, *route*, *netstat*, and other tools.
- `net-tools` may be found at http://www.tazenda.demon.co.uk/phil/net-tools/.
-
-.. _build-the-software:
-
-Build the Software
-==================
-
-After configuring the software, you will need to compile it for your system.
-Simply issue the command *make* in the root of the source directory and the
-software will be compiled. Cliff Notes versions of different compilation
-examples can be found in the Developer's Manual Appendix. If you have *any*
-problems at this stage, please send a bug report :ref:`bug-reports`.
-
-::
-
- $ ./bootstrap.sh
- $ ./configure <appropriate to your system>
- $ make
-
+There are several options available only to GNU/Linux systems. If you use
+GNU/Linux, make sure that the current kernel configuration is what you want.
+FRR will run with any kernel configuration but some recommendations do exist.
-Install the Software
-====================
+:makevar:`CONFIG_NETLINK`
+ Kernel/User Netlink socket. This is a enables an advanced interface between
+ the Linux kernel and *zebra* (:ref:`kernel-interface`).
-Installing the software to your system consists of copying the compiled
-programs and supporting files to a standard location. After the
-installation process has completed, these files have been copied
-from your work directory to :file:`/usr/local/bin`, and :file:`/usr/local/etc`.
+:makevar:`CONFIG_RTNETLINK`
+ This makes it possible to receive Netlink routing messages. If you specify
+ this option, *zebra* can detect routing information updates directly from
+ the kernel (:ref:`kernel-interface`).
-To install the FRR suite, issue the following command at your shell
-prompt:::
+:makevar:`CONFIG_IP_MULTICAST`
+ This option enables IP multicast and should be specified when you use *ripd*
+ (:ref:`rip`) or *ospfd* (:ref:`ospfv2`) because these protocols use
+ multicast.
- $ make install
+Building
+^^^^^^^^
-FRR daemons have their own terminal interface or VTY. After
-installation, you have to setup each beast's port number to connect to
-them. Please add the following entries to :file:`/etc/services`.
+Once you have chosen your configure options, run the configure script and pass
+the options you chose:
-::
+.. code-block:: shell
- zebrasrv 2600/tcp # zebra service
- zebra 2601/tcp # zebra vty
- ripd 2602/tcp # RIPd vty
- ripngd 2603/tcp # RIPngd vty
- ospfd 2604/tcp # OSPFd vty
- bgpd 2605/tcp # BGPd vty
- ospf6d 2606/tcp # OSPF6d vty
- ospfapi 2607/tcp # ospfapi
- isisd 2608/tcp # ISISd vty
- nhrpd 2610/tcp # nhrpd vty
- pimd 2611/tcp # PIMd vty
+ ./configure \
+ --prefix=/usr \
+ --enable-exampledir=/usr/share/doc/frr/examples/ \
+ --localstatedir=/var/run/frr \
+ --sbindir=/usr/lib/frr \
+ --sysconfdir=/etc/frr \
+ --enable-pimd \
+ --enable-watchfrr \
+ ...
+After configuring the software, you are ready to build and install it for your
+system.
-If you use a FreeBSD newer than 2.2.8, the above entries are already
-added to :file:`/etc/services` so there is no need to add it. If you
-specify a port number when starting the daemon, these entries may not be
-needed.
+.. code-block:: shell
-You may need to make changes to the config files in
-|INSTALL_PREFIX_ETC|. :ref:`config-commands`.
+ make && sudo make install
-.. [#] GNU/Linux has very flexible kernel configuration features.
+If everything finishes successfully, FRR should be installed. You should now
+skip to the section on :ref:`basic-setup`.
FRR is distributed under the GNU General Public License.
+FRR is a fork of `Quagga <http://www.quagga.net/>`_.
+
.. _about-frr:
About FRR
The official FRR website is located at |PACKAGE_URL| and contains further
information, as well as links to additional resources.
-FRR is a fork of `Quagga <http://www.quagga.net/>`_.
+Several distributions provide packages for FRR. Check your distribution's
+repositories to find out if a suitable version is available.
Mailing Lists
=============
interface name specified if the neighbor was specified
in this manner.
+.. index:: match source-protocol PROTOCOL_NAME
+.. clicmd:: match source-protocol PROTOCOL_NAME
+
+ This is a ZEBRA specific match command. Matches the
+ originating protocol specified.
+
+.. index:: match source-instance NUMBER
+.. clicmd:: match source-instance NUMBER
+
+ This is a ZEBRA specific match command. The number is a range from (0-255).
+ Matches the originating protocols instance specified.
+
.. _route-map-set-command:
Route Map Set Command
--- /dev/null
+.. _basic-setup:
+
+Basic Setup
+============
+
+After installing FRR, some basic configuration must be completed before it is
+ready to use.
+
+Daemons File
+------------
+After a fresh install, starting FRR will do nothing. This is because daemons
+must be explicitly enabled by editing a file in your configuration directory.
+This file is usually located at :file:`/etc/frr/daemons` and determines which
+daemons are activated when issuing a service start / stop command via init or
+systemd. The file initially looks like this:
+
+::
+
+ zebra=no
+ bgpd=no
+ ospfd=no
+ ospf6d=no
+ ripd=no
+ ripngd=no
+ isisd=no
+ pimd=no
+ ldpd=no
+ nhrpd=no
+ eigrpd=no
+ babeld=no
+ sharpd=no
+ pbrd=no
+
+To enable a particular daemon, simply change the corresponding 'no' to 'yes'.
+Subsequent service restarts should start the daemon.
+
+Daemons Configuration File
+--------------------------
+There is another file that controls the default options passed to daemons when
+starting FRR as a service. This file is located in your configuration
+directory, usually at :file:`/etc/frr/daemons.conf`.
+
+This file has several parts. Here is an example:
+
+::
+
+ #
+ # If this option is set the /etc/init.d/frr script automatically loads
+ # the config via "vtysh -b" when the servers are started.
+ # Check /etc/pam.d/frr if you intend to use "vtysh"!
+ #
+ vtysh_enable=yes
+ zebra_options=" -r -s 90000000 --daemon -A 127.0.0.1"
+ bgpd_options=" --daemon -A 127.0.0.1"
+ ospfd_options=" --daemon -A 127.0.0.1"
+ ospf6d_options=" --daemon -A ::1"
+ ripd_options=" --daemon -A 127.0.0.1"
+ ripngd_options=" --daemon -A ::1"
+ isisd_options=" --daemon -A 127.0.0.1"
+ pimd_options=" --daemon -A 127.0.0.1"
+ ldpd_options=" --daemon -A 127.0.0.1"
+ nhrpd_options=" --daemon -A 127.0.0.1"
+ eigrpd_options=" --daemon -A 127.0.0.1"
+ babeld_options=" --daemon -A 127.0.0.1"
+ sharpd_options=" --daemon -A 127.0.0.1"
+ pbrd_options=" --daemon -A 127.0.0.1"
+
+ # The list of daemons to watch is automatically generated by the init script.
+ watchfrr_enable=yes
+ watchfrr_options=(-d -r /usr/sbin/servicebBfrrbBrestartbB%s -s /usr/sbin/servicebBfrrbBstartbB%s -k /usr/sbin/servicebBfrrbBstopbB%s -b bB)
+
+ # If valgrind_enable is 'yes' the frr daemons will be started via valgrind.
+ # The use case for doing so is tracking down memory leaks, etc in frr.
+ valgrind_enable=no
+ valgrind=/usr/bin/valgrind
+
+Breaking this file down:
+
+::
+
+ vtysh_enable=yes
+
+As the comment says, this causes :ref:`VTYSH <vty-shell>` to apply
+configuration when starting the daemons. This is useful for a variety of
+reasons touched on in the VTYSH documentation and should generally be enabled.
+
+::
+
+ zebra_options=" -r -s 90000000 --daemon -A 127.0.0.1"
+ bgpd_options=" --daemon -A 127.0.0.1"
+ ...
+
+The next set of lines controls what options are passed to daemons when started
+from the service script. Usually daemons will have ``--daemon`` and ``-A
+<address>`` specified in order to daemonize and listen for VTY commands on a
+particular address.
+
+::
+
+ # The list of daemons to watch is automatically generated by the init script.
+ watchfrr_enable=yes
+ watchfrr_options=(-d -r /usr/sbin/servicebBfrrbBrestartbB%s -s /usr/sbin/servicebBfrrbBstartbB%s -k /usr/sbin/servicebBfrrbBstopbB%s -b bB)
+
+Options for the ``watchfrr``, the watchdog daemon.
+
+::
+
+ valgrind_enable=no
+ valgrind=/usr/bin/valgrind
+
+Whether or not to start FRR daemons under Valgrind. This is primarily useful
+for gathering information for bug reports and for developers.
+``valgrind_enable`` should be ``no`` for production use.
+
+Services
+--------
+FRR daemons have their own terminal interface or VTY. After installation, it's
+a good idea to setup each daemon's port number to connect to them. To do this
+add the following entries to :file:`/etc/services`.
+
+::
+
+ zebrasrv 2600/tcp # zebra service
+ zebra 2601/tcp # zebra vty
+ ripd 2602/tcp # RIPd vty
+ ripngd 2603/tcp # RIPngd vty
+ ospfd 2604/tcp # OSPFd vty
+ bgpd 2605/tcp # BGPd vty
+ ospf6d 2606/tcp # OSPF6d vty
+ ospfapi 2607/tcp # ospfapi
+ isisd 2608/tcp # ISISd vty
+ babeld 2609/tcp # BABELd vty
+ nhrpd 2610/tcp # nhrpd vty
+ pimd 2611/tcp # PIMd vty
+ ldpd 2612/tcp # LDPd vty
+ eigprd 2613/tcp # EIGRPd vty
+
+
+If you use a FreeBSD newer than 2.2.8, the above entries are already added to
+:file:`/etc/services` so there is no need to add it. If you specify a port
+number when starting the daemon, these entries may not be needed.
+
+You may need to make changes to the config files in |INSTALL_PREFIX_ETC|.
+
+systemd
+-------
+Although not installed when installing from source, FRR provides a service file
+for use with ``systemd``. It is located in :file:`tools/frr.service` in the Git
+repository. If ``systemctl status frr.service`` indicates that the FRR service
+is not found, copy the service file from the Git repository into your preferred
+location. A good place is usually ``/etc/systemd/system/``.
+
+After issuing a ``systemctl daemon-reload``, you should be able to start the
+FRR service via ``systemctl start frr``. If this fails, or no daemons are
+started. check the ``journalctl`` logs for an indication of what went wrong.
.. seealso:: :ref:`vrf`
+.. option:: --v6-rr-semantics
+
+ The linux kernel is receiving the ability to use the same route
+ replacement semantics for v6 that v4 uses. If you are using a
+ kernel that supports this functionality then run *Zebra* with this
+ option and we will use Route Replace Semantics instead of delete
+ than add.
+
.. _interface-commands:
Interface Commands
bool warned = false;
if (host.password) {
- vty_out(vty,
- "Please be aware that removing the password is a security risk and "
- "you should think twice about this command\n");
- warned = true;
+ if (!vty_shell_serv(vty)) {
+ vty_out(vty, NO_PASSWD_CMD_WARNING);
+ warned = true;
+ }
XFREE(MTYPE_HOST, host.password);
}
host.password = NULL;
if (host.password_encrypt) {
- if (!warned)
- vty_out(vty,
- "Please be aware that removing the password is a security risk "
- "and you should think twice about this command\n");
+ if (!warned && !vty_shell_serv(vty))
+ vty_out(vty, NO_PASSWD_CMD_WARNING);
XFREE(MTYPE_HOST, host.password_encrypt);
}
host.password_encrypt = NULL;
bool warned = false;
if (host.enable) {
- vty_out(vty,
- "Please be aware that removing the password is a security risk and "
- "you should think twice about this command\n");
- warned = true;
+ if (!vty_shell_serv(vty)) {
+ vty_out(vty, NO_PASSWD_CMD_WARNING);
+ warned = true;
+ }
XFREE(MTYPE_HOST, host.enable);
}
host.enable = NULL;
if (host.enable_encrypt) {
- if (!warned)
- vty_out(vty,
- "Please be aware that removing the password is a security risk "
- "and you should think twice about this command\n");
+ if (!warned && !vty_shell_serv(vty))
+ vty_out(vty, NO_PASSWD_CMD_WARNING);
XFREE(MTYPE_HOST, host.enable_encrypt);
}
host.enable_encrypt = NULL;
#define CONF_BACKUP_EXT ".sav"
+/* Command warnings. */
+#define NO_PASSWD_CMD_WARNING \
+ "Please be aware that removing the password is a security risk and you should think twice about this command.\n"
+
/* IPv4 only machine should not accept IPv6 address for peer's IP
address. So we replace VTY command string like below. */
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
#include <zebra.h>
#include <stddef.h>
+#include <pthread.h>
#include "stream.h"
#include "memory.h"
struct stream_fifo *new;
new = XCALLOC(MTYPE_STREAM_FIFO, sizeof(struct stream_fifo));
+ pthread_mutex_init(&new->mtx, NULL);
return new;
}
fifo->tail = s;
fifo->tail->next = NULL;
- fifo->count++;
+ atomic_fetch_add_explicit(&fifo->count, 1, memory_order_release);
+}
+
+void stream_fifo_push_safe(struct stream_fifo *fifo, struct stream *s)
+{
+ pthread_mutex_lock(&fifo->mtx);
+ {
+ stream_fifo_push(fifo, s);
+ }
+ pthread_mutex_unlock(&fifo->mtx);
}
/* Delete first stream from fifo. */
if (fifo->head == NULL)
fifo->tail = NULL;
- fifo->count--;
+ atomic_fetch_sub_explicit(&fifo->count, 1,
+ memory_order_release);
/* ensure stream is scrubbed of references to this fifo */
s->next = NULL;
return s;
}
-/* Return first fifo entry. */
+struct stream *stream_fifo_pop_safe(struct stream_fifo *fifo)
+{
+ struct stream *ret;
+
+ pthread_mutex_lock(&fifo->mtx);
+ {
+ ret = stream_fifo_pop(fifo);
+ }
+ pthread_mutex_unlock(&fifo->mtx);
+
+ return ret;
+}
+
struct stream *stream_fifo_head(struct stream_fifo *fifo)
{
return fifo->head;
}
+struct stream *stream_fifo_head_safe(struct stream_fifo *fifo)
+{
+ struct stream *ret;
+
+ pthread_mutex_lock(&fifo->mtx);
+ {
+ ret = stream_fifo_head(fifo);
+ }
+ pthread_mutex_unlock(&fifo->mtx);
+
+ return ret;
+}
+
void stream_fifo_clean(struct stream_fifo *fifo)
{
struct stream *s;
stream_free(s);
}
fifo->head = fifo->tail = NULL;
- fifo->count = 0;
+ atomic_store_explicit(&fifo->count, 0, memory_order_release);
+}
+
+void stream_fifo_clean_safe(struct stream_fifo *fifo)
+{
+ pthread_mutex_lock(&fifo->mtx);
+ {
+ stream_fifo_clean(fifo);
+ }
+ pthread_mutex_unlock(&fifo->mtx);
+}
+
+size_t stream_fifo_count_safe(struct stream_fifo *fifo)
+{
+ return atomic_load_explicit(&fifo->count, memory_order_acquire);
}
void stream_fifo_free(struct stream_fifo *fifo)
{
stream_fifo_clean(fifo);
+ pthread_mutex_destroy(&fifo->mtx);
XFREE(MTYPE_STREAM_FIFO, fifo);
}
#ifndef _ZEBRA_STREAM_H
#define _ZEBRA_STREAM_H
+#include <pthread.h>
+
+#include "frratomic.h"
#include "mpls.h"
#include "prefix.h"
/* First in first out queue structure. */
struct stream_fifo {
- size_t count;
+ /* lock for mt-safe operations */
+ pthread_mutex_t mtx;
+
+ /* number of streams in this fifo */
+ _Atomic size_t count;
struct stream *head;
struct stream *tail;
/* deprecated */
extern uint8_t *stream_pnt(struct stream *);
-/* Stream fifo. */
+/*
+ * Operations on struct stream_fifo.
+ *
+ * Each function has a safe variant, which ensures that the operation performed
+ * is atomic with respect to the operations performed by all other safe
+ * variants. In other words, the safe variants lock the stream_fifo's mutex
+ * before performing their action. These are provided for convenience when
+ * using stream_fifo in a multithreaded context, to alleviate the need for the
+ * caller to implement their own synchronization around the stream_fifo.
+ *
+ * The following functions do not have safe variants. The caller must ensure
+ * that these operations are performed safely in a multithreaded context:
+ * - stream_fifo_new
+ * - stream_fifo_free
+ */
+
+/*
+ * Create a new stream_fifo.
+ *
+ * Returns:
+ * newly created stream_fifo
+ */
extern struct stream_fifo *stream_fifo_new(void);
+
+/*
+ * Push a stream onto a stream_fifo.
+ *
+ * fifo
+ * the stream_fifo to push onto
+ *
+ * s
+ * the stream to push onto the stream_fifo
+ */
extern void stream_fifo_push(struct stream_fifo *fifo, struct stream *s);
+extern void stream_fifo_push_safe(struct stream_fifo *fifo, struct stream *s);
+
+/*
+ * Pop a stream off a stream_fifo.
+ *
+ * fifo
+ * the stream_fifo to pop from
+ *
+ * Returns:
+ * the next stream in the stream_fifo
+ */
extern struct stream *stream_fifo_pop(struct stream_fifo *fifo);
+extern struct stream *stream_fifo_pop_safe(struct stream_fifo *fifo);
+
+/*
+ * Retrieve the next stream from a stream_fifo without popping it.
+ *
+ * fifo
+ * the stream_fifo to operate on
+ *
+ * Returns:
+ * the next stream that would be returned from stream_fifo_pop
+ */
extern struct stream *stream_fifo_head(struct stream_fifo *fifo);
+extern struct stream *stream_fifo_head_safe(struct stream_fifo *fifo);
+
+/*
+ * Remove all streams from a stream_fifo.
+ *
+ * fifo
+ * the stream_fifo to clean
+ */
extern void stream_fifo_clean(struct stream_fifo *fifo);
+extern void stream_fifo_clean_safe(struct stream_fifo *fifo);
+
+/*
+ * Retrieve number of streams on a stream_fifo.
+ *
+ * fifo
+ * the stream_fifo to retrieve the count for
+ *
+ * Returns:
+ * the number of streams on the stream_fifo
+ */
+extern size_t stream_fifo_count_safe(struct stream_fifo *fifo);
+
+/*
+ * Free a stream_fifo.
+ *
+ * Calls stream_fifo_clean, then deinitializes the stream_fifo and frees it.
+ *
+ * fifo
+ * the stream_fifo to free
+ */
extern void stream_fifo_free(struct stream_fifo *fifo);
/* This is here because "<< 24" is particularly problematic in C.
return 0;
}
-static void zapi_encode_prefix(struct stream *s,
- struct prefix *p,
- uint8_t family)
+static void zapi_encode_prefix(struct stream *s, struct prefix *p,
+ uint8_t family)
{
struct prefix any;
stream_put(s, &p->u.prefix, prefix_blen(p));
}
-int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s,
- struct pbr_rule *zrule)
+int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s, struct pbr_rule *zrule)
{
stream_reset(s);
zclient_create_header(s, cmd, zrule->vrf_id);
zapi_encode_prefix(s, &(zrule->filter.src_ip),
zrule->filter.src_ip.family);
- stream_putw(s, zrule->filter.src_port); /* src port */
+ stream_putw(s, zrule->filter.src_port); /* src port */
zapi_encode_prefix(s, &(zrule->filter.dst_ip),
zrule->filter.src_ip.family);
- stream_putw(s, zrule->filter.dst_port); /* dst port */
- stream_putw(s, zrule->filter.fwmark); /* fwmark */
+ stream_putw(s, zrule->filter.dst_port); /* dst port */
+ stream_putw(s, zrule->filter.fwmark); /* fwmark */
stream_putl(s, zrule->action.table);
stream_putl(s, zrule->ifindex);
STREAM_GETL(s, ifi);
if (zclient_debug)
- zlog_debug("%s: %u %u %u %u", __PRETTY_FUNCTION__,
- seq, prio, uni, ifi);
+ zlog_debug("%s: %u %u %u %u", __PRETTY_FUNCTION__, seq, prio,
+ uni, ifi);
*seqno = seq;
*priority = prio;
*unique = uni;
return false;
}
-bool zapi_ipset_notify_decode(struct stream *s,
- uint32_t *unique,
- enum zapi_ipset_notify_owner *note)
+bool zapi_ipset_notify_decode(struct stream *s, uint32_t *unique,
+ enum zapi_ipset_notify_owner *note)
{
uint32_t uni;
return false;
}
-bool zapi_ipset_entry_notify_decode(struct stream *s,
- uint32_t *unique,
- char *ipset_name,
- enum zapi_ipset_entry_notify_owner *note)
+bool zapi_ipset_entry_notify_decode(struct stream *s, uint32_t *unique,
+ char *ipset_name,
+ enum zapi_ipset_entry_notify_owner *note)
{
uint32_t uni;
STREAM_GETL(s, uni);
- STREAM_GET(ipset_name, s,
- ZEBRA_IPSET_NAME_SIZE);
+ STREAM_GET(ipset_name, s, ZEBRA_IPSET_NAME_SIZE);
if (zclient_debug)
zlog_debug("%s: %u", __PRETTY_FUNCTION__, uni);
*/
if (znh->label_num) {
nexthop_add_labels(n, ZEBRA_LSP_NONE, znh->label_num,
- znh->labels);
+ znh->labels);
}
return n;
if (nhr->nexthops[i].label_num)
STREAM_GET(&nhr->nexthops[i].labels[0], s,
nhr->nexthops[i].label_num
- * sizeof(mpls_label_t));
+ * sizeof(mpls_label_t));
}
return true;
zlog_warn(
"warning: interface %s address %s "
"with peer flag set, but no peer address!",
- ifp->name, prefix2str(ifc->address, buf,
- sizeof buf));
+ ifp->name,
+ prefix2str(ifc->address, buf,
+ sizeof buf));
UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
}
}
uint8_t result;
if (zclient_debug)
- zlog_debug("Connecting to Label Manager");
+ zlog_debug("Connecting to Label Manager (LM)");
if (zclient->sock < 0)
return -1;
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("%s: can't write to zclient->sock", __func__);
+ zlog_err("Can't write to zclient sock");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("%s: zclient->sock connection closed", __func__);
+ zlog_err("Zclient sock closed");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (zclient_debug)
- zlog_debug("%s: Label manager connect request (%d bytes) sent",
- __func__, ret);
+ zlog_debug("LM connect request sent (%d bytes)", ret);
/* read response */
if (zclient_read_sync_response(zclient, ZEBRA_LABEL_MANAGER_CONNECT)
!= 0)
return -1;
- /* result */
s = zclient->ibuf;
+
+ /* read instance and proto */
+ uint8_t proto = stream_getc(s);
+ uint16_t instance = stream_getw(s);
+
+ /* sanity */
+ if (proto != zclient->redist_default)
+ zlog_err(
+ "Wrong proto (%u) in LM connect response. Should be %u",
+ proto, zclient->redist_default);
+ if (instance != zclient->instance)
+ zlog_err(
+ "Wrong instId (%u) in LM connect response. Should be %u",
+ instance, zclient->instance);
+
+ /* result code */
result = stream_getc(s);
if (zclient_debug)
- zlog_debug(
- "%s: Label Manager connect response received, result %u",
- __func__, result);
+ zlog_debug("LM connect-response received, result %u", result);
return (int)result;
}
* @param chunk_size Amount of labels requested
* @result 0 on success, -1 otherwise
*/
-int zclient_send_get_label_chunk(
- struct zclient *zclient,
- uint8_t keep,
- uint32_t chunk_size)
+int zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
+ uint32_t chunk_size)
{
struct stream *s;
stream_reset(s);
zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, VRF_DEFAULT);
+ /* proto */
+ stream_putc(s, zclient->redist_default);
+ /* instance */
+ stream_putw(s, zclient->instance);
stream_putc(s, keep);
stream_putl(s, chunk_size);
s = zclient->obuf;
stream_reset(s);
zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, VRF_DEFAULT);
+ /* proto */
+ stream_putc(s, zclient->redist_default);
+ /* instance */
+ stream_putw(s, zclient->instance);
/* keep */
stream_putc(s, keep);
/* chunk size */
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("%s: can't write to zclient->sock", __func__);
+ zlog_err("Can't write to zclient sock");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("%s: zclient->sock connection closed", __func__);
+ zlog_err("Zclient sock closed");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (zclient_debug)
- zlog_debug("%s: Label chunk request (%d bytes) sent", __func__,
- ret);
+ zlog_debug("Label chunk request (%d bytes) sent", ret);
/* read response */
if (zclient_read_sync_response(zclient, ZEBRA_GET_LABEL_CHUNK) != 0)
return -1;
+ /* parse response */
s = zclient->ibuf;
+
+ /* read proto and instance */
+ uint8_t proto = stream_getc(s);
+ uint16_t instance = stream_getw(s);
+
+ /* sanities */
+ if (proto != zclient->redist_default)
+ zlog_err("Wrong proto (%u) in get chunk response. Should be %u",
+ proto, zclient->redist_default);
+ if (instance != zclient->instance)
+ zlog_err("Wrong instId (%u) in get chunk response Should be %u",
+ instance, zclient->instance);
+
/* keep */
response_keep = stream_getc(s);
/* start and end labels */
/* not owning this response */
if (keep != response_keep) {
zlog_err(
- "%s: Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
- __func__, *start, *end, keep, response_keep);
+ "Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
+ *start, *end, keep, response_keep);
}
/* sanity */
if (*start > *end || *start < MPLS_LABEL_UNRESERVED_MIN
|| *end > MPLS_LABEL_UNRESERVED_MAX) {
- zlog_err("%s: Invalid Label chunk: %u - %u", __func__, *start,
- *end);
+ zlog_err("Invalid Label chunk: %u - %u", *start, *end);
return -1;
}
if (zclient_debug)
- zlog_debug("Label Chunk assign: %u - %u (%u) ", *start, *end,
+ zlog_debug("Label Chunk assign: %u - %u (%u)", *start, *end,
response_keep);
return 0;
struct stream *s;
if (zclient_debug)
- zlog_debug("Releasing Label Chunk");
+ zlog_debug("Releasing Label Chunk %u - %u", start, end);
if (zclient->sock < 0)
return -1;
stream_reset(s);
zclient_create_header(s, ZEBRA_RELEASE_LABEL_CHUNK, VRF_DEFAULT);
+ /* proto */
+ stream_putc(s, zclient->redist_default);
+ /* instance */
+ stream_putw(s, zclient->instance);
/* start */
stream_putl(s, start);
/* end */
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("%s: can't write to zclient->sock", __func__);
+ zlog_err("Can't write to zclient sock");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("%s: zclient->sock connection closed", __func__);
+ zlog_err("Zclient sock connection closed");
close(zclient->sock);
zclient->sock = -1;
return -1;
return -1;
if (zclient_debug)
- zlog_debug("%s: Table manager connect request sent",
- __func__);
+ zlog_debug("%s: Table manager connect request sent", __func__);
/* read response */
if (zclient_read_sync_response(zclient, ZEBRA_TABLE_MANAGER_CONNECT)
case ZEBRA_GET_LABEL_CHUNK:
if (zclient->label_chunk)
(*zclient->label_chunk)(command, zclient, length,
- vrf_id);
+ vrf_id);
break;
case ZEBRA_IPSET_NOTIFY_OWNER:
if (zclient->ipset_notify_owner)
listnode_delete(old_route->nh_list,
rnh);
ospf6_nexthop_delete(rnh);
- route_updated = true;
}
}
listnode_delete(old_route->paths, o_path);
ospf6_path_free(o_path);
+ route_updated = true;
/* Current route's path (adv_router info) is similar
* to route being added.
* Update FIB with effective NHs.
*/
if (listcount(old_route->paths)) {
+ for (ALL_LIST_ELEMENTS(old_route->paths,
+ anode, anext, o_path)) {
+ ospf6_merge_nexthops(
+ old_route->nh_list,
+ o_path->nh_list);
+ }
+ /* Update RIB/FIB with effective
+ * nh_list
+ */
+ if (ospf6->route_table->hook_add)
+ (*ospf6->route_table->hook_add)
+ (old_route);
+
if (old_route->path.origin.id
== route->path.origin.id
&& old_route->path.origin.adv_router
old_route->path.origin.adv_router =
h_path->origin.adv_router;
}
-
- if (route_updated) {
- for (ALL_LIST_ELEMENTS(old_route->paths,
- anode, anext,
- o_path)) {
- ospf6_merge_nexthops(
- old_route->nh_list,
- o_path->nh_list);
- }
- /* Update RIB/FIB with effective
- * nh_list
- */
- if (ospf6->route_table->hook_add)
- (*ospf6->route_table->hook_add)(
- old_route);
- break;
- }
+ break;
} else {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
prefix2str(&old_route->prefix, buf,
/* Add a nh_list to new ecmp path */
ospf6_copy_nexthops(ecmp_path->nh_list,
route->nh_list);
- /* Merge nexthop to existing route's nh_list */
- ospf6_route_merge_nexthops(old_route, route);
-
- /* Update RIB/FIB */
- if (ospf6->route_table->hook_add)
- (*ospf6->route_table->hook_add)(
- old_route);
/* Add the new path to route's path list */
listnode_add_sort(old_route->paths, ecmp_path);
listcount(old_route->nh_list));
}
} else {
- for (ALL_LIST_ELEMENTS_RO(o_path->nh_list,
- nnode, nh)) {
- for (ALL_LIST_ELEMENTS(
- old_route->nh_list, rnode,
- rnext, rnh)) {
- if (!ospf6_nexthop_is_same(rnh,
- nh))
- continue;
-
- listnode_delete(
- old_route->nh_list,
- rnh);
- ospf6_nexthop_delete(rnh);
- }
- }
list_delete_all_node(o_path->nh_list);
ospf6_copy_nexthops(o_path->nh_list,
route->nh_list);
+ }
- /* Merge nexthop to existing route's nh_list */
- ospf6_route_merge_nexthops(old_route, route);
+ /* Reset nexthop lists, rebuild from brouter table
+ * for each adv. router.
+ */
+ list_delete_all_node(old_route->nh_list);
- if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&route->prefix, buf,
- sizeof(buf));
- zlog_debug(
- "%s: existing route %s with effective nh count %u",
- __PRETTY_FUNCTION__, buf,
- old_route->nh_list
- ? listcount(
- old_route
- ->nh_list)
- : 0);
+ for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode,
+ o_path)) {
+ struct ospf6_route *asbr_entry;
+
+ asbr_entry = ospf6_route_lookup(
+ &o_path->ls_prefix,
+ ospf6->brouter_table);
+ if (asbr_entry == NULL) {
+ if (IS_OSPF6_DEBUG_EXAMIN(
+ AS_EXTERNAL)) {
+ prefix2str(&old_route->prefix,
+ buf, sizeof(buf));
+ zlog_debug("%s: ls_prfix %s asbr_entry not found.",
+ __PRETTY_FUNCTION__,
+ buf);
+ }
+ continue;
}
+ ospf6_route_merge_nexthops(old_route,
+ asbr_entry);
+ }
- /* Update RIB/FIB */
- if (ospf6->route_table->hook_add)
- (*ospf6->route_table->hook_add)(
- old_route);
+ if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
+ prefix2str(&route->prefix, buf, sizeof(buf));
+ zlog_debug("%s: route %s with effective paths %u nh %u",
+ __PRETTY_FUNCTION__, buf,
+ old_route->paths ?
+ listcount(old_route->paths) : 0,
+ old_route->nh_list ?
+ listcount(old_route->nh_list) : 0);
}
+
+ /* Update RIB/FIB */
+ if (ospf6->route_table->hook_add)
+ (*ospf6->route_table->hook_add)(old_route);
+
/* Delete the new route its info added to existing
* route.
*/
route->path.origin.type = lsa->header->type;
route->path.origin.id = lsa->header->id;
route->path.origin.adv_router = lsa->header->adv_router;
-
route->path.prefix_options = external->prefix.prefix_options;
+ memcpy(&route->path.ls_prefix, &asbr_id, sizeof(struct prefix));
+
if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_E)) {
route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
route->path.metric_type = 2;
zlog_info(" options: %s router-bits: %s metric-type: %d metric: %d/%d",
options, capa, brouter->path.metric_type, brouter->path.cost,
brouter->path.u.cost_e2);
+ zlog_info(" paths %u nh %u", listcount(brouter->paths),
+ listcount(brouter->nh_list));
}
void ospf6_intra_brouter_calculation(struct ospf6_area *oa)
pbr_nht_install_nexthop_group(pnhgc, nhgc->nhg);
}
-/*
- * Since we are writing into the name field which is PBR_MAP_NAMELEN
- * size, we are expecting this to field to be at max 100 bytes.
- * Newer compilers understand that the %s portion may be up to
- * 100 bytes( because of the size of the string. The %u portion
- * is expected to be 10 bytes. So in `theory` there are situations
- * where we might truncate. The reality this is never going to
- * happen( who is going to create a nexthop group name that is
- * over say 30 characters? ). As such we are expecting the
- * calling function to subtract 10 from the size_t l before
- * we pass it in to get around this new gcc fun.
- */
char *pbr_nht_nexthop_make_name(char *name, size_t l,
uint32_t seqno, char *buffer)
{
struct pbr_nexthop_cache lookup;
memset(&find, 0, sizeof(find));
- pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_MAP_NAMELEN - 10,
+ pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_NHC_NAMELEN,
pbrms->seqno, find.name);
if (!pbrms->internal_nhg_name)
pbrms->internal_nhg_name = XSTRDUP(MTYPE_TMP, find.name);
#include "pbr_map.h"
+#define PBR_NHC_NAMELEN PBR_MAP_NAMELEN + 10
+
struct pbr_nexthop_group_cache {
- char name[PBR_MAP_NAMELEN];
+ char name[PBR_NHC_NAMELEN];
uint32_t table_id;
if (pbrms->nhg)
nh = nexthop_exists(pbrms->nhg, &nhop);
else {
- char buf[PBR_MAP_NAMELEN];
+ char buf[PBR_NHC_NAMELEN];
if (no) {
vty_out(vty, "No nexthops to delete");
pbrms->internal_nhg_name =
XSTRDUP(MTYPE_TMP,
pbr_nht_nexthop_make_name(pbrms->parent->name,
- PBR_MAP_NAMELEN - 10,
+ PBR_NHC_NAMELEN,
pbrms->seqno,
buf));
nh = NULL;
%defattr(-,root,root)
%doc */*.sample* AUTHORS COPYING
%doc doc/mpls
-%doc ChangeLog NEWS README SERVICES
+%doc ChangeLog NEWS README
%if 0%{?frr_user:1}
%dir %attr(751,%frr_user,%frr_user) %{_sysconfdir}
%dir %attr(750,%frr_user,%frr_user) /var/log/frr
vrf_init(NULL, NULL, NULL, NULL);
+ route_map_init();
+
sharp_zebra_init();
/* Get configuration file. */
DEFPY (install_routes,
install_routes_cmd,
- "sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes",
+ "sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes [instance (0-255)$instance]",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"
"Address to start /32 generation at\n"
"Nexthop to use\n"
"Nexthop address\n"
- "How many to create\n")
+ "How many to create\n"
+ "Instance to use\n"
+ "Instance\n")
{
int i;
struct prefix p;
temp = ntohl(p.u.prefix4.s_addr);
for (i = 0; i < routes; i++) {
- route_add(&p, &nhop);
+ route_add(&p, (uint8_t)instance, &nhop);
p.u.prefix4.s_addr = htonl(++temp);
}
DEFPY (remove_routes,
remove_routes_cmd,
- "sharp remove routes A.B.C.D$start (1-1000000)$routes",
+ "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]",
"Sharp Routing Protocol\n"
"Remove some routes\n"
"Routes to remove\n"
"Starting spot\n"
- "Routes to uniinstall\n")
+ "Routes to uniinstall\n"
+ "instance to use\n"
+ "Value of instance\n")
{
int i;
struct prefix p;
uint32_t temp;
-
total_routes = routes;
removed_routes = 0;
temp = ntohl(p.u.prefix4.s_addr);
for (i = 0; i < routes; i++) {
- route_delete(&p);
+ route_delete(&p, (uint8_t)instance);
p.u.prefix4.s_addr = htonl(++temp);
}
zclient_send_vrf_label(zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
}
-void route_add(struct prefix *p, struct nexthop *nh)
+void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
{
struct zapi_route api;
struct zapi_nexthop *api_nh;
memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_SHARP;
+ api.instance = instance;
api.safi = SAFI_UNICAST;
memcpy(&api.prefix, p, sizeof(*p));
zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
}
-void route_delete(struct prefix *p)
+void route_delete(struct prefix *p, uint8_t instance)
{
struct zapi_route api;
api.vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_SHARP;
api.safi = SAFI_UNICAST;
+ api.instance = instance;
memcpy(&api.prefix, p, sizeof(*p));
zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
extern void sharp_zebra_init(void);
extern void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label);
-extern void route_add(struct prefix *p, struct nexthop *nh);
-extern void route_delete(struct prefix *p);
+extern void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh);
+extern void route_delete(struct prefix *p, uint8_t instance);
extern void sharp_zebra_nexthop_watch(struct prefix *p, bool watch);
#endif
lib/test_ttable.refout \
lib/test_zlog.py \
lib/test_graph.py \
+ lib/test_graph.refout \
ospf6d/test_lsdb.py \
ospf6d/test_lsdb.in \
ospf6d/test_lsdb.refout \
if (user_mode) {
if (strncmp("en", vector_slot(vline, 0), 2) == 0) {
+ cmd_free_strvec(vline);
fprintf(stdout, "%% Command not allowed: enable\n");
return CMD_WARNING;
}
return (retcode);
}
-/* We don't care about the point of the cursor when '?' is typed. */
-static int vtysh_rl_describe(void)
+/*
+ * Function processes cli commands terminated with '?' character when entered
+ * through either 'vtysh' or 'vtysh -c' interfaces.
+ */
+static int vtysh_process_questionmark(const char *input, int input_len)
{
- int ret;
+ int ret, width = 0;
unsigned int i;
- vector vline;
- vector describe;
- int width;
+ vector vline, describe;
struct cmd_token *token;
- vline = cmd_make_strvec(rl_line_buffer);
+ if (!input)
+ return 1;
+
+ vline = cmd_make_strvec(input);
/* In case of '> ?'. */
if (vline == NULL) {
vline = vector_init(1);
vector_set(vline, NULL);
- } else if (rl_end && isspace((int)rl_line_buffer[rl_end - 1]))
+ } else if (input_len && isspace((int)input[input_len - 1]))
vector_set(vline, NULL);
- fprintf(stdout, "\n");
-
describe = cmd_describe_command(vline, vty, &ret);
/* Ambiguous and no match error. */
cmd_free_strvec(vline);
vector_free(describe);
fprintf(stdout, "%% Ambiguous command.\n");
- rl_on_new_line();
return 0;
break;
case CMD_ERR_NO_MATCH:
if (describe)
vector_free(describe);
fprintf(stdout, "%% There is no matched command.\n");
- rl_on_new_line();
return 0;
break;
}
cmd_free_strvec(vline);
vector_free(describe);
+ return 0;
+}
+
+/*
+ * Entry point for user commands terminated with '?' character and typed through
+ * the usual vtysh's stdin interface. This is the function being registered with
+ * readline() api's.
+ */
+static int vtysh_rl_describe(void)
+{
+ int ret;
+
+ fprintf(stdout, "\n");
+
+ ret = vtysh_process_questionmark(rl_line_buffer, rl_end);
rl_on_new_line();
- return 0;
+ return ret;
+}
+
+/*
+ * Function in charged of processing vtysh instructions terminating with '?'
+ * character and received through the 'vtysh -c' interface. If user's
+ * instruction is well-formatted, we will call the same processing routine
+ * utilized by the traditional vtysh's stdin interface.
+ */
+int vtysh_execute_command_questionmark(char *input)
+{
+ int input_len, qmark_count = 0;
+ const char *str;
+
+ if (!(input && *input))
+ return 1;
+
+ /* Finding out question_mark count and strlen */
+ for (str = input; *str; ++str) {
+ if (*str == '?')
+ qmark_count++;
+ }
+ input_len = str - input;
+
+ /*
+ * Verify that user's input terminates in '?' and that patterns such as
+ * 'cmd ? subcmd ?' are prevented.
+ */
+ if (qmark_count != 1 || input[input_len - 1] != '?')
+ return 1;
+
+ /*
+ * Questionmark-processing function is not expecting to receive '?'
+ * character in input string.
+ */
+ input[input_len - 1] = '\0';
+
+ return vtysh_process_questionmark(input, input_len - 1);
}
/* Result of cmd_complete_command() call will be stored here
"no password", NO_STR
"Modify the terminal connection password\n")
{
+ vty_out(vty, NO_PASSWD_CMD_WARNING);
+
return CMD_SUCCESS;
}
"Modify enable password parameters\n"
"Assign the privileged level password\n")
{
+ vty_out(vty, NO_PASSWD_CMD_WARNING);
+
return CMD_SUCCESS;
}
int vtysh_execute(const char *);
int vtysh_execute_no_pager(const char *);
+int vtysh_execute_command_questionmark(char *input);
char *vtysh_prompt(void);
if (logfile)
log_it(cmd->line);
- ret = vtysh_execute_no_pager(cmd->line);
+ /*
+ * Parsing logic for regular commands will be different than
+ * for those commands requiring further processing, such as
+ * cli instructions terminating with question-mark character.
+ */
+ if (!vtysh_execute_command_questionmark(cmd->line))
+ ret = CMD_SUCCESS;
+ else
+ ret = vtysh_execute_no_pager(cmd->line);
+
if (!no_error
&& !(ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON
|| ret == CMD_WARNING))
* it will be a proxy to relay messages to external label manager
* This zclient thus is to connect to it
*/
-static struct stream *ibuf;
static struct stream *obuf;
static struct zclient *zclient;
bool lm_is_external;
XFREE(MTYPE_LM_CHUNK, val);
}
-static int relay_response_back(struct zserv *zserv)
+static int relay_response_back(void)
{
int ret = 0;
struct stream *src, *dst;
uint8_t version;
vrf_id_t vrf_id;
uint16_t resp_cmd;
+ uint8_t proto;
+ const char *proto_str;
+ unsigned short instance;
+ struct zserv *zserv;
+ /* input buffer with msg from label manager */
src = zclient->ibuf;
- dst = obuf;
stream_reset(src);
+ /* parse header */
ret = zclient_read_header(src, zclient->sock, &size, &marker, &version,
&vrf_id, &resp_cmd);
if (ret < 0 && errno != EAGAIN) {
- zlog_err("%s: Error reading Label Manager response: %s",
- __func__, strerror(errno));
+ zlog_err("Error reading Label Manager response: %s",
+ strerror(errno));
return -1;
}
- zlog_debug("%s: Label Manager response received, %d bytes", __func__,
- size);
+ zlog_debug("Label Manager response received, %d bytes", size);
if (size == 0)
return -1;
- /* send response back */
+ /* Get the 'proto' field of the message */
+ proto = stream_getc(src);
+
+ /* Get the 'instance' field of the message */
+ instance = stream_getw(src);
+
+ proto_str = zebra_route_string(proto);
+
+ /* lookup the client to relay the msg to */
+ zserv = zebra_find_client(proto, instance);
+ if (!zserv) {
+ zlog_err(
+ "Error relaying LM response: can't find client %s, instance %u",
+ proto_str, instance);
+ return -1;
+ }
+ zlog_debug("Found client to relay LM response to client %s instance %u",
+ proto_str, instance);
+
+ /* copy msg into output buffer */
+ dst = obuf;
stream_copy(dst, src);
- ret = writen(zserv->sock, src->data, stream_get_endp(src));
+
+ /* send response back */
+ ret = writen(zserv->sock, dst->data, stream_get_endp(dst));
if (ret <= 0) {
- zlog_err("%s: Error sending Label Manager response back: %s",
- __func__, strerror(errno));
+ zlog_err("Error relaying LM response to %s instance %u: %s",
+ proto_str, instance, strerror(errno));
return -1;
}
- zlog_debug("%s: Label Manager response (%d bytes) sent back", __func__,
- ret);
+ zlog_debug("Relayed LM response (%d bytes) to %s instance %u", ret,
+ proto_str, instance);
return 0;
}
static int lm_zclient_read(struct thread *t)
{
- struct zserv *zserv;
int ret;
- /* Get socket to zebra. */
- zserv = THREAD_ARG(t);
zclient->t_read = NULL;
/* read response and send it back */
- ret = relay_response_back(zserv);
+ ret = relay_response_back();
return ret;
}
zclient_create_header(s, cmd, vrf_id);
+ /* proto */
+ stream_putc(s, zserv->proto);
+ /* instance */
+ stream_putw(s, zserv->instance);
/* result */
stream_putc(s, 1);
* @return 0 on success, -1 otherwise
*/
int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
- vrf_id_t vrf_id)
+ struct stream *msg, vrf_id_t vrf_id)
{
- struct stream *src, *dst;
+ struct stream *dst;
int ret = 0;
+ uint8_t proto;
+ const char *proto_str;
+ unsigned short instance;
if (zclient->sock < 0) {
- zlog_err(
- "%s: Error relaying label chunk request: no zclient socket",
- __func__);
+ zlog_err("Unable to relay LM request: no socket");
reply_error(cmd, zserv, vrf_id);
return -1;
}
+ /* peek msg to get proto and instance id. This zebra, which acts as
+ * a proxy needs to have such values for each client in order to
+ * relay responses back to it.
+ */
+
+ /* Get the 'proto' field of incoming msg */
+ proto = stream_getc(msg);
+
+ /* Get the 'instance' field of incoming msg */
+ instance = stream_getw(msg);
+
+ /* stringify proto */
+ proto_str = zebra_route_string(proto);
+
+ /* check & set client proto if unset */
+ if (zserv->proto && zserv->proto != proto) {
+ zlog_warn("Client proto(%u) != msg proto(%u)", zserv->proto,
+ proto);
+ return -1;
+ }
+
+ /* check & set client instance if unset */
+ if (zserv->instance && zserv->instance != instance) {
+ zlog_err("Client instance(%u) != msg instance(%u)",
+ zserv->instance, instance);
+ return -1;
+ }
+
+ /* recall proto and instance */
+ zserv->instance = instance;
+ zserv->proto = proto;
+
/* in case there's any incoming message enqueued, read and forward it */
while (ret == 0)
- ret = relay_response_back(zserv);
+ ret = relay_response_back();
- /* Send request to external label manager */
- src = ibuf;
+ /* get the msg buffer used toward the 'master' Label Manager */
dst = zclient->obuf;
- stream_copy(dst, src);
+ /* copy the message */
+ stream_copy(dst, msg);
+ /* Send request to external label manager */
ret = writen(zclient->sock, dst->data, stream_get_endp(dst));
if (ret <= 0) {
- zlog_err("%s: Error relaying label chunk request: %s", __func__,
- strerror(errno));
+ zlog_err("Error relaying LM request from %s instance %u: %s",
+ proto_str, instance, strerror(errno));
reply_error(cmd, zserv, vrf_id);
return -1;
}
- zlog_debug("%s: Label chunk request relayed. %d bytes sent", __func__,
- ret);
+ zlog_debug("Relayed LM request (%d bytes) from %s instance %u", ret,
+ proto_str, instance);
+
/* Release label chunk has no response */
if (cmd == ZEBRA_RELEASE_LABEL_CHUNK)
/* make sure we listen to the response */
if (!zclient->t_read)
- thread_add_read(zclient->master, lm_zclient_read, zserv,
+ thread_add_read(zclient->master, lm_zclient_read, NULL,
zclient->sock, &zclient->t_read);
return 0;
{
/* this is an actual label manager */
if (!lm_zserv_path) {
- zlog_debug("Initializing own label manager");
+ zlog_debug("Initializing internal label manager");
lm_is_external = false;
lbl_mgr.lc_list = list_new();
lbl_mgr.lc_list->del = delete_label_chunk;
lm_zclient_init(lm_zserv_path);
}
- ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
obuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
hook_register(zapi_client_close, release_daemon_label_chunks);
void label_manager_close()
{
list_delete_and_null(&lbl_mgr.lc_list);
- stream_free(ibuf);
stream_free(obuf);
}
bool lm_is_external;
int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
- vrf_id_t vrf_id);
+ struct stream *msg, vrf_id_t vrf_id);
void label_manager_init(char *lm_zserv_path);
struct label_manager_chunk *assign_label_chunk(uint8_t proto,
unsigned short instance,
/* Don't delete kernel route. */
int keep_kernel_mode = 0;
+bool v6_rr_semantics = false;
+
#ifdef HAVE_NETLINK
/* Receive buffer size for netlink socket */
uint32_t nl_rcvbufsize = 4194304;
#endif /* HAVE_NETLINK */
+#define OPTION_V6_RR_SEMANTICS 2000
/* Command line options. */
-struct option longopts[] = {{"batch", no_argument, NULL, 'b'},
- {"allow_delete", no_argument, NULL, 'a'},
- {"keep_kernel", no_argument, NULL, 'k'},
- {"socket", required_argument, NULL, 'z'},
- {"ecmp", required_argument, NULL, 'e'},
- {"label_socket", no_argument, NULL, 'l'},
- {"retain", no_argument, NULL, 'r'},
+struct option longopts[] = {
+ {"batch", no_argument, NULL, 'b'},
+ {"allow_delete", no_argument, NULL, 'a'},
+ {"keep_kernel", no_argument, NULL, 'k'},
+ {"socket", required_argument, NULL, 'z'},
+ {"ecmp", required_argument, NULL, 'e'},
+ {"label_socket", no_argument, NULL, 'l'},
+ {"retain", no_argument, NULL, 'r'},
#ifdef HAVE_NETLINK
- {"vrfwnetns", no_argument, NULL, 'n'},
- {"nl-bufsize", required_argument, NULL, 's'},
+ {"vrfwnetns", no_argument, NULL, 'n'},
+ {"nl-bufsize", required_argument, NULL, 's'},
+ {"v6-rr-semantics", no_argument, NULL, OPTION_V6_RR_SEMANTICS},
#endif /* HAVE_NETLINK */
- {0}};
+ {0}};
zebra_capabilities_t _caps_p[] = {
ZCAP_NET_ADMIN, ZCAP_SYS_ADMIN, ZCAP_NET_RAW,
#endif
,
longopts,
- " -b, --batch Runs in batch mode\n"
- " -a, --allow_delete Allow other processes to delete zebra routes\n"
- " -z, --socket Set path of zebra socket\n"
- " -e, --ecmp Specify ECMP to use.\n"
- " -l, --label_socket Socket to external label manager\n"
- " -k, --keep_kernel Don't delete old routes which installed by zebra.\n"
- " -r, --retain When program terminates, retain added route by zebra.\n"
+ " -b, --batch Runs in batch mode\n"
+ " -a, --allow_delete Allow other processes to delete zebra routes\n"
+ " -z, --socket Set path of zebra socket\n"
+ " -e, --ecmp Specify ECMP to use.\n"
+ " -l, --label_socket Socket to external label manager\n"
+ " -k, --keep_kernel Don't delete old routes which installed by zebra.\n"
+ " -r, --retain When program terminates, retain added route by zebra.\n"
#ifdef HAVE_NETLINK
- " -n, --vrfwnetns Set VRF with NetNS\n"
- " -s, --nl-bufsize Set netlink receive buffer size\n"
+ " -n, --vrfwnetns Set VRF with NetNS\n"
+ " -s, --nl-bufsize Set netlink receive buffer size\n"
+ " --v6-rr-semantics Use v6 RR semantics\n"
#endif /* HAVE_NETLINK */
#if defined(HANDLE_ZAPI_FUZZING)
- " -c <file> Bypass normal startup use this file for tetsting of zapi"
+ " -c <file> Bypass normal startup use this file for tetsting of zapi"
#endif
- );
+ );
while (1) {
int opt = frr_getopt(argc, argv, NULL);
logicalrouter_configure_backend(
LOGICALROUTER_BACKEND_OFF);
break;
+ case OPTION_V6_RR_SEMANTICS:
+ v6_rr_semantics = true;
+ break;
#endif /* HAVE_NETLINK */
#if defined(HANDLE_ZAPI_FUZZING)
case 'c':
afi = family2afi(rn->p.family);
if (rmap_name)
ret = zebra_import_table_route_map_check(
- afi, re->type, &rn->p, re->ng.nexthop, re->vrf_id,
- re->tag, rmap_name);
+ afi, re->type, re->instance, &rn->p, re->ng.nexthop,
+ re->vrf_id, re->tag, rmap_name);
if (ret != RMAP_MATCH) {
UNSET_FLAG(re->flags, ZEBRA_FLAG_SELECTED);
extern pid_t pid;
+extern bool v6_rr_semantics;
#endif /*_ZEBRA_RIB_H */
struct zebra_ns *zns = zebra_ns_lookup(ns_id);
- memset(&req.n, 0, sizeof(req.n));
- memset(&req.ndm, 0, sizeof(req.ndm));
+ memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
struct zebra_ns *zns;
zns = zvrf->zns;
- memset(&req.n, 0, sizeof(req.n));
- memset(&req.ndm, 0, sizeof(req.ndm));
+ memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
assert(old || new);
if (new) {
- if (p->family == AF_INET)
+ if (p->family == AF_INET || v6_rr_semantics)
ret = netlink_route_multipath(RTM_NEWROUTE, p, src_p,
new, (old) ? 1 : 0);
else {
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
zns = zvrf->zns;
- memset(&req.n, 0, sizeof(req.n));
- memset(&req.ndm, 0, sizeof(req.ndm));
+ memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
return -1;
}
- memset(&req.n, 0, sizeof(req.n));
- memset(&req.ndm, 0, sizeof(req.ndm));
+ memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
zns = zvrf->zns;
- memset(&req.n, 0, sizeof(req.n));
- memset(&req.ndm, 0, sizeof(req.ndm));
+ memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, vrf_id);
if (lmc) {
+ /* proto */
+ stream_putc(s, lmc->proto);
+ /* instance */
+ stream_putw(s, lmc->instance);
/* keep */
stream_putc(s, lmc->keep);
/* start and end labels */
zclient_create_header(s, ZEBRA_LABEL_MANAGER_CONNECT, vrf_id);
+ /* proto */
+ stream_putc(s, client->proto);
+
+ /* instance */
+ stream_putw(s, client->instance);
+
/* result */
stream_putc(s, result);
stream_failure:
return;
}
+static int msg_client_id_mismatch(const char *op, struct zserv *client,
+ uint8_t proto, unsigned int instance)
+{
+ if (proto != client->proto) {
+ zlog_err("%s: msg vs client proto mismatch, client=%u msg=%u",
+ op, client->proto, proto);
+ /* TODO: fail when BGP sets proto and instance */
+ /* return 1; */
+ }
+
+ if (instance != client->instance) {
+ zlog_err(
+ "%s: msg vs client instance mismatch, client=%u msg=%u",
+ op, client->instance, instance);
+ /* TODO: fail when BGP sets proto and instance */
+ /* return 1; */
+ }
+
+ return 0;
+}
static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
vrf_id_t vrf_id)
uint8_t keep;
uint32_t size;
struct label_manager_chunk *lmc;
+ uint8_t proto;
+ unsigned short instance;
/* Get input stream. */
s = msg;
/* Get data. */
+ STREAM_GETC(s, proto);
+ STREAM_GETW(s, instance);
STREAM_GETC(s, keep);
STREAM_GETL(s, size);
+ /* detect client vs message (proto,instance) mismatch */
+ if (msg_client_id_mismatch("Get-label-chunk", client, proto, instance))
+ return;
+
lmc = assign_label_chunk(client->proto, client->instance, keep, size);
if (!lmc)
- zlog_err("%s: Unable to assign Label Chunk of size %u",
- __func__, size);
+ zlog_err(
+ "Unable to assign Label Chunk of size %u to %s instance %u",
+ size, zebra_route_string(client->proto),
+ client->instance);
else
- zlog_debug("Assigned Label Chunk %u - %u to %u", lmc->start,
- lmc->end, keep);
+ zlog_debug("Assigned Label Chunk %u - %u to %s instance %u",
+ lmc->start, lmc->end,
+ zebra_route_string(client->proto), client->instance);
/* send response back */
zsend_assign_label_chunk_response(client, vrf_id, lmc);
{
struct stream *s;
uint32_t start, end;
+ uint8_t proto;
+ unsigned short instance;
/* Get input stream. */
s = msg;
/* Get data. */
+ STREAM_GETC(s, proto);
+ STREAM_GETW(s, instance);
STREAM_GETL(s, start);
STREAM_GETL(s, end);
+ /* detect client vs message (proto,instance) mismatch */
+ if (msg_client_id_mismatch("Release-label-chunk", client, proto,
+ instance))
+ return;
+
release_label_chunk(client->proto, client->instance, start, end);
stream_failure:
/* external label manager */
if (lm_is_external)
- zread_relay_label_manager_request(hdr->command, client,
+ zread_relay_label_manager_request(hdr->command, client, msg,
zvrf_id(zvrf));
/* this is a label manager */
else {
memset(&nexthop->rmap_src.ipv6, 0, sizeof(union g_addr));
/* It'll get set if required inside */
- ret = zebra_route_map_check(family, re->type, p, nexthop,
+ ret = zebra_route_map_check(family, re->type, re->instance, p, nexthop,
nexthop->vrf_id, re->tag);
if (ret == RMAP_DENYMATCH) {
if (IS_ZEBRA_DEBUG_RIB) {
struct nexthop *nexthop;
vrf_id_t vrf_id;
uint32_t source_protocol;
+ uint8_t instance;
int metric;
route_tag_t tag;
};
DEFUN (match_source_protocol,
match_source_protocol_cmd,
- "match source-protocol <bgp|ospf|rip|ripng|isis|ospf6|pim|nhrp|eigrp|babel|connected|system|kernel|static>",
+ "match source-protocol <bgp|ospf|rip|ripng|isis|ospf6|pim|nhrp|eigrp|babel|connected|system|kernel|static|sharp>",
MATCH_STR
"Match protocol via which the route was learnt\n"
"BGP protocol\n"
"Routes from directly connected peer\n"
"Routes from system configuration\n"
"Routes from kernel\n"
- "Statically configured routes\n")
+ "Statically configured routes\n"
+ "SHARP process\n")
{
char *proto = argv[2]->text;
int i;
DEFUN (no_match_source_protocol,
no_match_source_protocol_cmd,
- "no match source-protocol [<bgp|ospf|rip|ripng|isis|ospf6|pim|nhrp|eigrp|babel|connected|system|kernel|static>]",
+ "no match source-protocol [<bgp|ospf|rip|ripng|isis|ospf6|pim|nhrp|eigrp|babel|connected|system|kernel|static|sharp>]",
NO_STR
MATCH_STR
"No match protocol via which the route was learnt\n"
"Routes from directly connected peer\n"
"Routes from system configuration\n"
"Routes from kernel\n"
- "Statically configured routes\n")
+ "Statically configured routes\n"
+ "SHARP process\n")
{
char *proto = (argc == 4) ? argv[3]->text : NULL;
return zebra_route_match_delete(vty, "source-protocol", proto,
RMAP_EVENT_MATCH_DELETED);
}
+DEFUN (match_source_instance,
+ match_source_instance_cmd,
+ "match source-instance (0-255)",
+ MATCH_STR
+ "Match the protocol's instance number\n"
+ "The instance number\n")
+{
+ char *instance = argv[2]->arg;
+
+ return zebra_route_match_add(vty, "source-instance", instance,
+ RMAP_EVENT_MATCH_ADDED);
+}
+
+DEFUN (no_match_source_instance,
+ no_match_source_instance_cmd,
+ "no match source-instance [(0-255)]",
+ NO_STR MATCH_STR
+ "Match the protocol's instance number\n"
+ "The instance number\n")
+{
+ char *instance = (argc == 4) ? argv[3]->arg : NULL;
+
+ return zebra_route_match_delete(vty, "source-instance", instance,
+ RMAP_EVENT_MATCH_ADDED);
+}
+
/* set functions */
DEFUN (set_src,
"source-protocol", route_match_source_protocol,
route_match_source_protocol_compile, route_match_source_protocol_free};
+/* `source-instance` */
+static route_map_result_t route_match_source_instance(void *rule,
+ struct prefix *prefix,
+ route_map_object_t type,
+ void *object)
+{
+ uint8_t *instance = (uint8_t *)rule;
+ struct nh_rmap_obj *nh_data;
+
+ if (type != RMAP_ZEBRA)
+ return RMAP_NOMATCH;
+
+ nh_data = (struct nh_rmap_obj *)object;
+ if (!nh_data)
+ return RMAP_DENYMATCH;
+
+ return (nh_data->instance == *instance) ? RMAP_MATCH : RMAP_NOMATCH;
+}
+
+static void *route_match_source_instance_compile(const char *arg)
+{
+ uint8_t *instance;
+ int i;
+
+ i = atoi(arg);
+ instance = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t));
+
+ *instance = i;
+
+ return instance;
+}
+
+static void route_match_source_instance_free(void *rule)
+{
+ XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
+}
+
+static struct route_map_rule_cmd route_match_source_instance_cmd = {
+ "source-instance", route_match_source_instance,
+ route_match_source_instance_compile, route_match_source_instance_free};
+
/* `set src A.B.C.D' */
/* Set src. */
}
route_map_result_t zebra_route_map_check(int family, int rib_type,
- struct prefix *p,
+ uint8_t instance, struct prefix *p,
struct nexthop *nexthop,
vrf_id_t vrf_id, route_tag_t tag)
{
nh_obj.nexthop = nexthop;
nh_obj.vrf_id = vrf_id;
nh_obj.source_protocol = rib_type;
+ nh_obj.instance = instance;
nh_obj.metric = 0;
nh_obj.tag = tag;
}
route_map_result_t
-zebra_import_table_route_map_check(int family, int re_type, struct prefix *p,
- struct nexthop *nexthop, vrf_id_t vrf_id,
- route_tag_t tag, const char *rmap_name)
+zebra_import_table_route_map_check(int family, int re_type, uint8_t instance,
+ struct prefix *p, struct nexthop *nexthop,
+ vrf_id_t vrf_id, route_tag_t tag,
+ const char *rmap_name)
{
struct route_map *rmap = NULL;
route_map_result_t ret = RMAP_DENYMATCH;
nh_obj.nexthop = nexthop;
nh_obj.vrf_id = vrf_id;
nh_obj.source_protocol = re_type;
+ nh_obj.instance = instance;
nh_obj.metric = 0;
nh_obj.tag = tag;
nh_obj.nexthop = nexthop;
nh_obj.vrf_id = nexthop->vrf_id;
nh_obj.source_protocol = re->type;
+ nh_obj.instance = re->instance;
nh_obj.metric = re->metric;
nh_obj.tag = re->tag;
route_map_install_match(&route_match_ipv6_address_prefix_len_cmd);
route_map_install_match(&route_match_ip_nexthop_prefix_len_cmd);
route_map_install_match(&route_match_source_protocol_cmd);
+ route_map_install_match(&route_match_source_instance_cmd);
+
/* */
route_map_install_set(&route_set_src_cmd);
/* */
install_element(RMAP_NODE, &no_match_ip_address_prefix_len_cmd);
install_element(RMAP_NODE, &match_source_protocol_cmd);
install_element(RMAP_NODE, &no_match_source_protocol_cmd);
+ install_element(RMAP_NODE, &match_source_instance_cmd);
+ install_element(RMAP_NODE, &no_match_source_instance_cmd);
+
/* */
install_element(RMAP_NODE, &set_src_cmd);
install_element(RMAP_NODE, &no_set_src_cmd);
extern void zebra_route_map_write_delay_timer(struct vty *);
extern route_map_result_t
-zebra_import_table_route_map_check(int family, int rib_type, struct prefix *p,
- struct nexthop *nexthop, vrf_id_t vrf_id,
- route_tag_t tag, const char *rmap_name);
-extern route_map_result_t zebra_route_map_check(int family, int rib_type,
- struct prefix *p,
- struct nexthop *nexthop,
- vrf_id_t vrf_id,
- route_tag_t tag);
+zebra_import_table_route_map_check(int family, int rib_type, uint8_t instance,
+ struct prefix *p, struct nexthop *nexthop,
+ vrf_id_t vrf_id, route_tag_t tag,
+ const char *rmap_name);
+extern route_map_result_t
+zebra_route_map_check(int family, int rib_type, uint8_t instance,
+ struct prefix *p, struct nexthop *nexthop,
+ vrf_id_t vrf_id, route_tag_t tag);
extern route_map_result_t
zebra_nht_route_map_check(int family, int client_proto, struct prefix *p,
struct route_entry *, struct nexthop *nexthop);
/* definitions */
-
/* static function declarations */
static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p,
uint16_t cmd);
int uninstall);
/* Private functions */
+static int host_rb_entry_compare(const struct host_rb_entry *hle1,
+ const struct host_rb_entry *hle2)
+{
+ if (hle1->p.family < hle2->p.family)
+ return -1;
+
+ if (hle1->p.family > hle2->p.family)
+ return 1;
+
+ if (hle1->p.prefixlen < hle2->p.prefixlen)
+ return -1;
+
+ if (hle1->p.prefixlen > hle2->p.prefixlen)
+ return 1;
+
+ if (hle1->p.family == AF_INET) {
+ if (hle1->p.u.prefix4.s_addr < hle2->p.u.prefix4.s_addr)
+ return -1;
+
+ if (hle1->p.u.prefix4.s_addr > hle2->p.u.prefix4.s_addr)
+ return 1;
+
+ return 0;
+ } else {
+ zlog_warn("%s: Unexpected family type: %d", __PRETTY_FUNCTION__,
+ hle1->p.family);
+ return 0;
+ }
+}
+RB_GENERATE(host_rb_tree_entry, host_rb_entry, hl_entry, host_rb_entry_compare);
+
+static uint32_t rb_host_count(struct host_rb_tree_entry *hrbe)
+{
+ struct host_rb_entry *hle;
+ uint32_t count = 0;
+
+ RB_FOREACH (hle, host_rb_tree_entry, hrbe)
+ count++;
+
+ return count;
+}
/*
* Return number of valid MACs in a VNI's MAC hash table - all
{
char buf1[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
- struct listnode *node = NULL;
- struct prefix *p = NULL;
json_object *json_hosts = NULL;
+ struct host_rb_entry *hle;
if (!json) {
vty_out(vty, "Ip: %s\n",
ipaddr2str(&n->ip, buf2, sizeof(buf2)));
vty_out(vty, " RMAC: %s\n",
prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
- vty_out(vty, " Refcount: %d\n", listcount(n->host_list));
+ vty_out(vty, " Refcount: %d\n",
+ rb_host_count(&n->host_rb));
vty_out(vty, " Prefixes:\n");
- for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p))
+ RB_FOREACH (hle, host_rb_tree_entry, &n->host_rb)
vty_out(vty, " %s\n",
- prefix2str(p, buf2, sizeof(buf2)));
+ prefix2str(&hle->p, buf2, sizeof(buf2)));
} else {
json_hosts = json_object_new_array();
json_object_string_add(
json_object_string_add(
json, "routerMac",
prefix_mac2str(&n->emac, buf2, sizeof(buf2)));
- json_object_int_add(json, "refCount", listcount(n->host_list));
- for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p))
+ json_object_int_add(json, "refCount",
+ rb_host_count(&n->host_rb));
+ RB_FOREACH (hle, host_rb_tree_entry, &n->host_rb)
json_object_array_add(json_hosts,
json_object_new_string(prefix2str(
- p, buf2, sizeof(buf2))));
+ &hle->p, buf2, sizeof(buf2))));
json_object_object_add(json, "prefixList", json_hosts);
}
}
{
char buf1[ETHER_ADDR_STRLEN];
char buf2[PREFIX_STRLEN];
- struct listnode *node = NULL;
- struct prefix *p = NULL;
json_object *json_hosts = NULL;
+ struct host_rb_entry *hle;
if (!json) {
vty_out(vty, "MAC: %s\n",
prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1)));
vty_out(vty, " Remote VTEP: %s\n",
inet_ntoa(zrmac->fwd_info.r_vtep_ip));
- vty_out(vty, " Refcount: %d\n", listcount(zrmac->host_list));
+ vty_out(vty, " Refcount: %d\n", rb_host_count(&zrmac->host_rb));
vty_out(vty, " Prefixes:\n");
- for (ALL_LIST_ELEMENTS_RO(zrmac->host_list, node, p))
+ RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb)
vty_out(vty, " %s\n",
- prefix2str(p, buf2, sizeof(buf2)));
+ prefix2str(&hle->p, buf2, sizeof(buf2)));
} else {
json_hosts = json_object_new_array();
json_object_string_add(
json_object_string_add(json, "vtepIp",
inet_ntoa(zrmac->fwd_info.r_vtep_ip));
json_object_int_add(json, "refCount",
- listcount(zrmac->host_list));
- for (ALL_LIST_ELEMENTS_RO(zrmac->host_list, node, p))
- json_object_array_add(json_hosts,
- json_object_new_string(prefix2str(
- p, buf2, sizeof(buf2))));
+ rb_host_count(&zrmac->host_rb));
+ RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb)
+ json_object_array_add(
+ json_hosts,
+ json_object_new_string(prefix2str(
+ &hle->p, buf2, sizeof(buf2))));
json_object_object_add(json, "prefixList", json_hosts);
}
}
zebra_vxlan_process_l3vni_oper_down(zl3vni);
}
-static int is_host_present_in_host_list(struct list *list, struct prefix *host)
+static void rb_find_or_add_host(struct host_rb_tree_entry *hrbe,
+ struct prefix *host)
{
- struct listnode *node = NULL;
- struct prefix *p = NULL;
+ struct host_rb_entry lookup;
+ struct host_rb_entry *hle;
- for (ALL_LIST_ELEMENTS_RO(list, node, p)) {
- if (prefix_same(p, host))
- return 1;
- }
- return 0;
-}
+ memset(&lookup, 0, sizeof(lookup));
+ memcpy(&lookup.p, host, sizeof(*host));
-static void host_list_add_host(struct list *list, struct prefix *host)
-{
- struct prefix *p = NULL;
+ hle = RB_FIND(host_rb_tree_entry, hrbe, &lookup);
+ if (hle)
+ return;
- p = XCALLOC(MTYPE_HOST_PREFIX, sizeof(struct prefix));
- memcpy(p, host, sizeof(struct prefix));
+ hle = XCALLOC(MTYPE_HOST_PREFIX, sizeof(struct host_rb_entry));
+ memcpy(hle, &lookup, sizeof(lookup));
- listnode_add_sort(list, p);
+ RB_INSERT(host_rb_tree_entry, hrbe, hle);
}
-static void host_list_delete_host(struct list *list, struct prefix *host)
+static void rb_delete_host(struct host_rb_tree_entry *hrbe, struct prefix *host)
{
- struct listnode *node = NULL, *nnode = NULL, *node_to_del = NULL;
- struct prefix *p = NULL;
+ struct host_rb_entry lookup;
+ struct host_rb_entry *hle;
- for (ALL_LIST_ELEMENTS(list, node, nnode, p)) {
- if (prefix_same(p, host)) {
- XFREE(MTYPE_HOST_PREFIX, p);
- node_to_del = node;
- }
- }
+ memset(&lookup, 0, sizeof(lookup));
+ memcpy(&lookup.p, host, sizeof(*host));
+
+ hle = RB_FIND(host_rb_tree_entry, hrbe, &lookup);
+ if (hle)
+ RB_REMOVE(host_rb_tree_entry, hrbe, hle);
- if (node_to_del)
- list_delete_node(list, node_to_del);
+ return;
}
/*
zrmac = hash_get(zl3vni->rmac_table, &tmp_rmac, zl3vni_rmac_alloc);
assert(zrmac);
- zrmac->host_list = list_new();
- zrmac->host_list->cmp = (int (*)(void *, void *))prefix_cmp;
+ RB_INIT(host_rb_tree_entry, &zrmac->host_rb);
SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE);
SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC);
static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac)
{
zebra_mac_t *tmp_rmac;
+ struct host_rb_entry *hle;
- if (zrmac->host_list)
- list_delete_and_null(&zrmac->host_list);
- zrmac->host_list = NULL;
+ while (!RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) {
+ hle = RB_ROOT(host_rb_tree_entry, &zrmac->host_rb);
+
+ RB_REMOVE(host_rb_tree_entry, &zrmac->host_rb, hle);
+ XFREE(MTYPE_HOST_PREFIX, hle);
+ }
tmp_rmac = hash_release(zl3vni->rmac_table, zrmac);
if (tmp_rmac)
zl3vni_rmac_install(zl3vni, zrmac);
}
- if (!is_host_present_in_host_list(zrmac->host_list, host_prefix))
- host_list_add_host(zrmac->host_list, host_prefix);
+ rb_find_or_add_host(&zrmac->host_rb, host_prefix);
+
return 0;
}
static void zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac,
struct prefix *host_prefix)
{
- host_list_delete_host(zrmac->host_list, host_prefix);
- if (list_isempty(zrmac->host_list)) {
+ rb_delete_host(&zrmac->host_rb, host_prefix);
+ if (RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) {
/* uninstall from kernel */
zl3vni_rmac_uninstall(zl3vni, zrmac);
n = hash_get(zl3vni->nh_table, &tmp_n, zl3vni_nh_alloc);
assert(n);
- n->host_list = list_new();
- n->host_list->cmp = (int (*)(void *, void *))prefix_cmp;
+ RB_INIT(host_rb_tree_entry, &n->host_rb);
memcpy(&n->emac, mac, ETH_ALEN);
SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
static int zl3vni_nh_del(zebra_l3vni_t *zl3vni, zebra_neigh_t *n)
{
zebra_neigh_t *tmp_n;
+ struct host_rb_entry *hle;
- if (n->host_list)
- list_delete_and_null(&n->host_list);
- n->host_list = NULL;
+ while (!RB_EMPTY(host_rb_tree_entry, &n->host_rb)) {
+ hle = RB_ROOT(host_rb_tree_entry, &n->host_rb);
+
+ RB_REMOVE(host_rb_tree_entry, &n->host_rb, hle);
+ XFREE(MTYPE_HOST_PREFIX, hle);
+ }
tmp_n = hash_release(zl3vni->nh_table, n);
if (tmp_n)
zl3vni_nh_install(zl3vni, nh);
}
- if (!is_host_present_in_host_list(nh->host_list, host_prefix))
- host_list_add_host(nh->host_list, host_prefix);
+ rb_find_or_add_host(&nh->host_rb, host_prefix);
return 0;
}
static void zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni, zebra_neigh_t *nh,
struct prefix *host_prefix)
{
- host_list_delete_host(nh->host_list, host_prefix);
- if (list_isempty(nh->host_list)) {
+ rb_delete_host(&nh->host_rb, host_prefix);
+ if (RB_EMPTY(host_rb_tree_entry, &nh->host_rb)) {
/* uninstall from kernel */
zl3vni_nh_uninstall(zl3vni, nh);
memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN);
}
+struct host_rb_entry {
+ RB_ENTRY(host_rb_entry) hl_entry;
+
+ struct prefix p;
+};
+
+RB_HEAD(host_rb_tree_entry, host_rb_entry);
+RB_PROTOTYPE(host_rb_tree_entry, host_rb_entry, hl_entry,
+ host_rb_entry_compare);
/*
* MAC hash table.
*
struct list *neigh_list;
/* list of hosts pointing to this remote RMAC */
- struct list *host_list;
+ struct host_rb_tree_entry host_rb;
};
/*
struct in_addr r_vtep_ip;
/* list of hosts pointing to this remote NH entry */
- struct list *host_list;
+ struct host_rb_tree_entry host_rb;
};
/*