DEFINE_MTYPE_STATIC(BGPD, MARTIAN_STRING, "BGP Martian Address Intf String");
-static void bgp_ipv6_address_add(struct bgp *bgp, struct connected *ifc,
- struct prefix *p);
-static void bgp_ipv6_address_del(struct bgp *bgp, struct connected *ifc,
- struct prefix *p);
-
char *bnc_str(struct bgp_nexthop_cache *bnc, char *buf, int size)
{
prefix2str(&(bnc->node->p), buf, size);
XFREE(MTYPE_TIP_ADDR, addr);
}
-static unsigned int bgp_tip_hash_key_make(void *p)
+static unsigned int bgp_tip_hash_key_make(const void *p)
{
const struct tip_addr *addr = p;
/* BGP own address structure */
struct bgp_addr {
- struct in_addr addr;
+ struct prefix *p;
struct list *ifp_name_list;
};
struct bgp_addr *addr = (struct bgp_addr *)bucket->data;
char *name;
struct listnode *node;
-
- vty_out(vty, "addr: %s, count: %d : ", inet_ntoa(addr->addr),
- addr->ifp_name_list->count);
+ char str[INET6_ADDRSTRLEN] = {0};
+
+ if (addr->p->family == AF_INET) {
+ vty_out(vty, "addr: %s, count: %d : ", inet_ntop(AF_INET,
+ &(addr->p->u.prefix4),
+ str, INET_ADDRSTRLEN),
+ addr->ifp_name_list->count);
+ } else if (addr->p->family == AF_INET6) {
+ vty_out(vty, "addr: %s, count: %d : ", inet_ntop(AF_INET6,
+ &(addr->p->u.prefix6),
+ str, INET6_ADDRSTRLEN),
+ addr->ifp_name_list->count);
+ }
for (ALL_LIST_ELEMENTS_RO(addr->ifp_name_list, node, name)) {
vty_out(vty, " %s,", name);
static void *bgp_address_hash_alloc(void *p)
{
- const struct in_addr *val = (const struct in_addr *)p;
- struct bgp_addr *addr;
+ struct bgp_addr *copy_addr = p;
+ struct bgp_addr *addr = NULL;
addr = XMALLOC(MTYPE_BGP_ADDR, sizeof(struct bgp_addr));
- addr->addr.s_addr = val->s_addr;
+ addr->p = prefix_new();
+ prefix_copy(addr->p, copy_addr->p);
addr->ifp_name_list = list_new();
addr->ifp_name_list->del = bgp_address_hash_string_del;
{
struct bgp_addr *addr = data;
+ prefix_free(&addr->p);
list_delete(&addr->ifp_name_list);
XFREE(MTYPE_BGP_ADDR, addr);
}
-static unsigned int bgp_address_hash_key_make(void *p)
+static unsigned int bgp_address_hash_key_make(const void *p)
{
const struct bgp_addr *addr = p;
- return jhash_1word(addr->addr.s_addr, 0);
+ return prefix_hash_key((const void *)(addr->p));
}
static bool bgp_address_hash_cmp(const void *p1, const void *p2)
const struct bgp_addr *addr1 = p1;
const struct bgp_addr *addr2 = p2;
- return addr1->addr.s_addr == addr2->addr.s_addr;
+ return prefix_same(addr1->p, addr2->p);
}
void bgp_address_init(struct bgp *bgp)
{
bgp->address_hash =
hash_create(bgp_address_hash_key_make, bgp_address_hash_cmp,
- "BGP Address Hash");
+ "BGP Connected Address Hash");
}
void bgp_address_destroy(struct bgp *bgp)
struct listnode *node;
char *name;
- tmp.addr = p->u.prefix4;
+ tmp.p = p;
+
+ if (tmp.p->family == AF_INET)
+ tmp.p->prefixlen = IPV4_MAX_BITLEN;
+ else if (tmp.p->family == AF_INET6)
+ tmp.p->prefixlen = IPV6_MAX_BITLEN;
addr = hash_get(bgp->address_hash, &tmp, bgp_address_hash_alloc);
struct listnode *node;
char *name;
- tmp.addr = p->u.prefix4;
+ tmp.p = p;
+
+ if (tmp.p->family == AF_INET)
+ tmp.p->prefixlen = IPV4_MAX_BITLEN;
+ else if (tmp.p->family == AF_INET6)
+ tmp.p->prefixlen = IPV6_MAX_BITLEN;
addr = hash_lookup(bgp->address_hash, &tmp);
/* may have been deleted earlier by bgp_interface_down() */
if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6))
return;
- bgp_ipv6_address_add(bgp, ifc, addr);
+ bgp_address_add(bgp, ifc, addr);
rn = bgp_node_get(bgp->connected_table[AFI_IP6],
(struct prefix *)&p);
if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6))
return;
- bgp_ipv6_address_del(bgp, ifc, addr);
+ bgp_address_del(bgp, ifc, addr);
rn = bgp_node_lookup(bgp->connected_table[AFI_IP6],
(struct prefix *)&p);
}
}
-int bgp_nexthop_self(struct bgp *bgp, struct in_addr nh_addr)
-{
- struct bgp_addr tmp, *addr;
- struct tip_addr tmp_tip, *tip;
-
- tmp.addr = nh_addr;
+int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, uint8_t sub_type,
+ struct attr *attr, struct bgp_node *rn)
+{
+ struct prefix p = {0};
+ afi_t new_afi = afi;
+ struct bgp_addr tmp_addr = {0}, *addr = NULL;
+ struct tip_addr tmp_tip, *tip = NULL;
+
+ bool is_bgp_static_route = ((type == ZEBRA_ROUTE_BGP)
+ && (sub_type == BGP_ROUTE_STATIC))
+ ? true
+ : false;
+
+ if (!is_bgp_static_route)
+ new_afi = BGP_ATTR_NEXTHOP_AFI_IP6(attr) ? AFI_IP6 : AFI_IP;
+
+ switch (new_afi) {
+ case AFI_IP:
+ p.family = AF_INET;
+ if (is_bgp_static_route) {
+ p.u.prefix4 = rn->p.u.prefix4;
+ p.prefixlen = rn->p.prefixlen;
+ } else {
+ /* Here we need to find out which nexthop to be used*/
+ if (attr->flag &
+ ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) {
+
+ p.u.prefix4 = attr->nexthop;
+ p.prefixlen = IPV4_MAX_BITLEN;
+
+ } else if ((attr->mp_nexthop_len) &&
+ ((attr->mp_nexthop_len ==
+ BGP_ATTR_NHLEN_IPV4) ||
+ (attr->mp_nexthop_len ==
+ BGP_ATTR_NHLEN_VPNV4))) {
+ p.u.prefix4 =
+ attr->mp_nexthop_global_in;
+ p.prefixlen = IPV4_MAX_BITLEN;
+ } else
+ return 0;
+ }
+ break;
+ case AFI_IP6:
+ p.family = AF_INET6;
+
+ if (is_bgp_static_route) {
+ p.u.prefix6 = rn->p.u.prefix6;
+ p.prefixlen = rn->p.prefixlen;
+ } else {
+ p.u.prefix6 = attr->mp_nexthop_global;
+ p.prefixlen = IPV6_MAX_BITLEN;
+ }
+ break;
+ default:
+ break;
+ }
- addr = hash_lookup(bgp->address_hash, &tmp);
+ tmp_addr.p = &p;
+ addr = hash_lookup(bgp->address_hash, &tmp_addr);
if (addr)
return 1;
- tmp_tip.addr = nh_addr;
- tip = hash_lookup(bgp->tip_hash, &tmp_tip);
- if (tip)
- return 1;
+ if (new_afi == AFI_IP) {
+ memset(&tmp_tip, 0, sizeof(struct tip_addr));
+ tmp_tip.addr = attr->nexthop;
+
+ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) {
+ tmp_tip.addr = attr->nexthop;
+ } else if ((attr->mp_nexthop_len) &&
+ ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4)
+ || (attr->mp_nexthop_len ==
+ BGP_ATTR_NHLEN_VPNV4))) {
+ tmp_tip.addr = attr->mp_nexthop_global_in;
+ }
+
+ tip = hash_lookup(bgp->tip_hash, &tmp_tip);
+ if (tip)
+ return 1;
+ }
return 0;
}
return (ret);
}
+int bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer)
+{
+ struct bgp_node *rn1;
+ struct bgp_node *rn2;
+ struct prefix p;
+ int ret;
+
+ p.family = AF_INET6;
+ p.prefixlen = IPV6_MAX_BITLEN;
+ p.u.prefix6 = nexthop;
+
+ rn1 = bgp_node_match(peer->bgp->connected_table[AFI_IP6], &p);
+ if (!rn1)
+ return 0;
+
+ p.family = AF_INET6;
+ p.prefixlen = IPV6_MAX_BITLEN;
+ p.u.prefix6 = peer->su.sin6.sin6_addr;
+
+ rn2 = bgp_node_match(peer->bgp->connected_table[AFI_IP6], &p);
+ if (!rn2) {
+ bgp_unlock_node(rn1);
+ return 0;
+ }
+
+ ret = (rn1 == rn2) ? 1 : 0;
+
+ bgp_unlock_node(rn1);
+ bgp_unlock_node(rn2);
+
+ return ret;
+}
+
+int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop,
+ struct update_subgroup *subgrp)
+{
+ struct bgp_node *rn1 = NULL, *rn2 = NULL;
+ struct peer_af *paf = NULL;
+ struct prefix p = {0}, np = {0};
+ struct bgp *bgp = NULL;
+
+ np.family = AF_INET6;
+ np.prefixlen = IPV6_MAX_BITLEN;
+ np.u.prefix6 = nexthop;
+
+ p.family = AF_INET;
+ p.prefixlen = IPV6_MAX_BITLEN;
+
+ bgp = SUBGRP_INST(subgrp);
+ rn1 = bgp_node_match(bgp->connected_table[AFI_IP6], &np);
+ if (!rn1)
+ return 0;
+
+ SUBGRP_FOREACH_PEER (subgrp, paf) {
+
+ p.u.prefix6 = paf->peer->su.sin6.sin6_addr;
+ rn2 = bgp_node_match(bgp->connected_table[AFI_IP6], &p);
+ if (rn1 == rn2) {
+ bgp_unlock_node(rn1);
+ bgp_unlock_node(rn2);
+ return 1;
+ }
+
+ if (rn2)
+ bgp_unlock_node(rn2);
+ }
+
+ bgp_unlock_node(rn1);
+ return 0;
+}
+
int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop,
struct update_subgroup *subgrp)
{
continue;
for (rn = bgp_table_top(table[afi]); rn;
rn = bgp_route_next(rn)) {
+ struct peer *peer;
+
bnc = bgp_node_get_bgp_nexthop_info(rn);
if (!bnc)
continue;
+ peer = (struct peer *)bnc->nht_info;
if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)) {
vty_out(vty,
- " %s valid [IGP metric %d], #paths %d\n",
+ " %s valid [IGP metric %d], #paths %d",
inet_ntop(rn->p.family,
&rn->p.u.prefix, buf,
sizeof(buf)),
bnc->metric, bnc->path_count);
+ if (peer)
+ vty_out(vty, ", peer %s", peer->host);
+ vty_out(vty, "\n");
if (!detail)
continue;
bgp_show_nexthops_detail(vty, bgp, bnc);
} else {
- vty_out(vty, " %s invalid\n",
+ vty_out(vty, " %s invalid",
inet_ntop(rn->p.family,
&rn->p.u.prefix, buf,
sizeof(buf)));
+ if (peer)
+ vty_out(vty, ", peer %s", peer->host);
+ vty_out(vty, "\n");
if (CHECK_FLAG(bnc->flags,
BGP_NEXTHOP_CONNECTED))
vty_out(vty, " Must be Connected\n");
bgp->import_check_table[afi] = NULL;
}
}
-
-static void *bgp_ipv6_address_hash_alloc(void *p)
-{
- const struct in6_addr *v6addr = (const struct in6_addr *)p;
- struct bgp_addrv6 *addr;
-
- addr = XMALLOC(MTYPE_BGP_ADDR, sizeof(struct bgp_addrv6));
- addr->addrv6 = *v6addr;
-
- addr->ifp_name_list = list_new();
- addr->ifp_name_list->del = bgp_address_hash_string_del;
-
- return addr;
-}
-
-static void bgp_ipv6_address_hash_free(void *data)
-{
- struct bgp_addrv6 *v6addr = data;
-
- list_delete(&v6addr->ifp_name_list);
- XFREE(MTYPE_BGP_ADDR, v6addr);
-}
-
-static unsigned int bgp_ipv6_address_hash_key_make(void *p)
-{
- const struct bgp_addrv6 *v6 = p;
-
- return __ipv6_addr_jhash(&v6->addrv6, 0);
-}
-
-static bool bgp_ipv6_address_hash_cmp(const void *p1,
- const void *p2)
-{
- const struct bgp_addrv6 *addr1 = p1;
- const struct bgp_addrv6 *addr2 = p2;
-
- return(!memcmp(&addr1->addrv6, &addr2->addrv6,
- sizeof(struct in6_addr)));
-}
-
-void bgp_ipv6_address_init(struct bgp *bgp)
-{
- bgp->ipv6_address_hash = hash_create(bgp_ipv6_address_hash_key_make,
- bgp_ipv6_address_hash_cmp,
- "BGP IPV6 Address Hash");
-}
-
-void bgp_ipv6_address_destroy(struct bgp *bgp)
-{
- if (bgp->ipv6_address_hash == NULL)
- return;
- hash_clean(bgp->ipv6_address_hash,
- bgp_ipv6_address_hash_free);
-
- hash_free(bgp->ipv6_address_hash);
- bgp->ipv6_address_hash = NULL;
-}
-
-static void bgp_ipv6_address_add(struct bgp *bgp, struct connected *ifc,
- struct prefix *p)
-{
- struct bgp_addrv6 tmp = {0};
- struct bgp_addrv6 *addr = NULL;
- struct listnode *node = NULL;
- char *name = 0;
-
- tmp.addrv6 = p->u.prefix6;
-
- addr = hash_get(bgp->ipv6_address_hash, &tmp,
- bgp_ipv6_address_hash_alloc);
- if (!addr)
- return;
-
- for (ALL_LIST_ELEMENTS_RO(addr->ifp_name_list, node, name)) {
- if (strcmp(ifc->ifp->name, name) == 0)
- break;
- }
-
- if (!node) {
- name = XSTRDUP(MTYPE_MARTIAN_STRING, ifc->ifp->name);
- listnode_add(addr->ifp_name_list, name);
- }
-}
-
-
-static void bgp_ipv6_address_del(struct bgp *bgp, struct connected *ifc,
- struct prefix *p)
-{
- struct bgp_addrv6 tmp;
- struct bgp_addrv6 *addr;
- struct listnode *node;
- char *name;
-
-
- tmp.addrv6 = p->u.prefix6;
-
- addr = hash_lookup(bgp->ipv6_address_hash, &tmp);
- /* may have been deleted earlier by bgp_interface_down() */
- if (addr == NULL)
- return;
-
- for (ALL_LIST_ELEMENTS_RO(addr->ifp_name_list, node, name)) {
- if (strcmp(ifc->ifp->name, name) == 0)
- break;
- }
-
- if (node) {
- list_delete_node(addr->ifp_name_list, node);
- XFREE(MTYPE_MARTIAN_STRING, name);
- }
-
- if (addr->ifp_name_list->count == 0) {
- hash_release(bgp->ipv6_address_hash, addr);
- list_delete(&addr->ifp_name_list);
- XFREE(MTYPE_BGP_ADDR, addr);
- }
-}
-int bgp_nexthop_self_ipv6(struct bgp *bgp, struct in6_addr *addr)
-{
- struct bgp_addrv6 tmp;
-
- tmp.addrv6 = *addr;
- return (!!hash_lookup(bgp->ipv6_address_hash, &tmp));
-}