]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_snmp.c
Merge pull request #5703 from ton31337/feature/limit_outgoing_prefixes
[mirror_frr.git] / bgpd / bgp_snmp.c
index 0700e0ac242e63003431c82ee1d934ba1e611aee..f31f8cd31bdb5beeb8572c88087f17f1d56b8504 100644 (file)
@@ -46,7 +46,7 @@
 
 /* BGP TRAP. */
 #define BGPESTABLISHED                 1
-#define BGPBACKWARDTRANSITION          2       
+#define BGPBACKWARDTRANSITION          2
 
 /* BGP MIB bgpVersion. */
 #define BGPVERSION                           0
@@ -674,14 +674,15 @@ static uint8_t *bgpRcvdPathAttrTable(struct variable *v, oid name[],
        return NULL;
 }
 
-static struct bgp_info *bgp4PathAttrLookup(struct variable *v, oid name[],
-                                          size_t *length, struct bgp *bgp,
-                                          struct prefix_ipv4 *addr, int exact)
+static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[],
+                                               size_t *length, struct bgp *bgp,
+                                               struct prefix_ipv4 *addr,
+                                               int exact)
 {
        oid *offset;
        int offsetlen;
-       struct bgp_info *binfo;
-       struct bgp_info *min;
+       struct bgp_path_info *path;
+       struct bgp_path_info *min;
        struct bgp_node *rn;
        union sockunion su;
        unsigned int len;
@@ -714,9 +715,10 @@ static struct bgp_info *bgp4PathAttrLookup(struct variable *v, oid name[],
                if (rn) {
                        bgp_unlock_node(rn);
 
-                       for (binfo = rn->info; binfo; binfo = binfo->next)
-                               if (sockunion_same(&binfo->peer->su, &su))
-                                       return binfo;
+                       for (path = bgp_node_get_bgp_path_info(rn); path;
+                            path = path->next)
+                               if (sockunion_same(&path->peer->su, &su))
+                                       return path;
                }
        } else {
                offset = name + v->namelen;
@@ -761,22 +763,23 @@ static struct bgp_info *bgp4PathAttrLookup(struct variable *v, oid name[],
                do {
                        min = NULL;
 
-                       for (binfo = rn->info; binfo; binfo = binfo->next) {
-                               if (binfo->peer->su.sin.sin_family == AF_INET
+                       for (path = bgp_node_get_bgp_path_info(rn); path;
+                            path = path->next) {
+                               if (path->peer->su.sin.sin_family == AF_INET
                                    && ntohl(paddr.s_addr)
-                                              < ntohl(binfo->peer->su.sin
+                                              < ntohl(path->peer->su.sin
                                                               .sin_addr
                                                               .s_addr)) {
                                        if (min) {
-                                               if (ntohl(binfo->peer->su.sin
+                                               if (ntohl(path->peer->su.sin
                                                                  .sin_addr
                                                                  .s_addr)
                                                    < ntohl(min->peer->su.sin
                                                                    .sin_addr
                                                                    .s_addr))
-                                                       min = binfo;
+                                                       min = path;
                                        } else
-                                               min = binfo;
+                                               min = path;
                                }
                        }
 
@@ -812,7 +815,7 @@ static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[],
                                  WriteMethod **write_method)
 {
        struct bgp *bgp;
-       struct bgp_info *binfo;
+       struct bgp_path_info *path;
        struct prefix_ipv4 addr;
 
        bgp = bgp_get_default();
@@ -824,13 +827,13 @@ static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[],
                return NULL;
        memset(&addr, 0, sizeof(struct prefix_ipv4));
 
-       binfo = bgp4PathAttrLookup(v, name, length, bgp, &addr, exact);
-       if (!binfo)
+       path = bgp4PathAttrLookup(v, name, length, bgp, &addr, exact);
+       if (!path)
                return NULL;
 
        switch (v->magic) {
        case BGP4PATHATTRPEER: /* 1 */
-               return SNMP_IPADDRESS(binfo->peer->su.sin.sin_addr);
+               return SNMP_IPADDRESS(path->peer->su.sin.sin_addr);
                break;
        case BGP4PATHATTRIPADDRPREFIXLEN: /* 2 */
                return SNMP_INTEGER(addr.prefixlen);
@@ -839,28 +842,28 @@ static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[],
                return SNMP_IPADDRESS(addr.prefix);
                break;
        case BGP4PATHATTRORIGIN: /* 4 */
-               return SNMP_INTEGER(binfo->attr->origin);
+               return SNMP_INTEGER(path->attr->origin);
                break;
        case BGP4PATHATTRASPATHSEGMENT: /* 5 */
-               return aspath_snmp_pathseg(binfo->attr->aspath, var_len);
+               return aspath_snmp_pathseg(path->attr->aspath, var_len);
                break;
        case BGP4PATHATTRNEXTHOP: /* 6 */
-               return SNMP_IPADDRESS(binfo->attr->nexthop);
+               return SNMP_IPADDRESS(path->attr->nexthop);
                break;
        case BGP4PATHATTRMULTIEXITDISC: /* 7 */
-               return SNMP_INTEGER(binfo->attr->med);
+               return SNMP_INTEGER(path->attr->med);
                break;
        case BGP4PATHATTRLOCALPREF: /* 8 */
-               return SNMP_INTEGER(binfo->attr->local_pref);
+               return SNMP_INTEGER(path->attr->local_pref);
                break;
        case BGP4PATHATTRATOMICAGGREGATE: /* 9 */
                return SNMP_INTEGER(1);
                break;
        case BGP4PATHATTRAGGREGATORAS: /* 10 */
-               return SNMP_INTEGER(binfo->attr->aggregator_as);
+               return SNMP_INTEGER(path->attr->aggregator_as);
                break;
        case BGP4PATHATTRAGGREGATORADDR: /* 11 */
-               return SNMP_IPADDRESS(binfo->attr->aggregator_addr);
+               return SNMP_IPADDRESS(path->attr->aggregator_addr);
                break;
        case BGP4PATHATTRCALCLOCALPREF: /* 12 */
                return SNMP_INTEGER(-1);
@@ -868,7 +871,7 @@ static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[],
        case BGP4PATHATTRBEST: /* 13 */
 #define BGP4_PathAttrBest_false 1
 #define BGP4_PathAttrBest_true  2
-               if (CHECK_FLAG(binfo->flags, BGP_INFO_SELECTED))
+               if (CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
                        return SNMP_INTEGER(BGP4_PathAttrBest_true);
                else
                        return SNMP_INTEGER(BGP4_PathAttrBest_false);
@@ -891,17 +894,20 @@ static int bgpTrapEstablished(struct peer *peer)
        struct in_addr addr;
        oid index[sizeof(oid) * IN_ADDR_SIZE];
 
+       /* Check if this peer just went to Established */
+       if ((peer->last_major_event != OpenConfirm) || !(peer_established(peer)))
+               return 0;
+
        ret = inet_aton(peer->host, &addr);
        if (ret == 0)
                return 0;
 
        oid_copy_addr(index, &addr, IN_ADDR_SIZE);
 
-       smux_trap(bgp_variables, sizeof bgp_variables / sizeof(struct variable),
-                 bgp_trap_oid, sizeof bgp_trap_oid / sizeof(oid), bgp_oid,
+       smux_trap(bgp_variables, array_size(bgp_variables), bgp_trap_oid,
+                 array_size(bgp_trap_oid), bgp_oid,
                  sizeof bgp_oid / sizeof(oid), index, IN_ADDR_SIZE,
-                 bgpTrapList, sizeof bgpTrapList / sizeof(struct trap_object),
-                 BGPESTABLISHED);
+                 bgpTrapList, array_size(bgpTrapList), BGPESTABLISHED);
        return 0;
 }
 
@@ -917,11 +923,10 @@ static int bgpTrapBackwardTransition(struct peer *peer)
 
        oid_copy_addr(index, &addr, IN_ADDR_SIZE);
 
-       smux_trap(bgp_variables, sizeof bgp_variables / sizeof(struct variable),
-                 bgp_trap_oid, sizeof bgp_trap_oid / sizeof(oid), bgp_oid,
+       smux_trap(bgp_variables, array_size(bgp_variables), bgp_trap_oid,
+                 array_size(bgp_trap_oid), bgp_oid,
                  sizeof bgp_oid / sizeof(oid), index, IN_ADDR_SIZE,
-                 bgpTrapList, sizeof bgpTrapList / sizeof(struct trap_object),
-                 BGPBACKWARDTRANSITION);
+                 bgpTrapList, array_size(bgpTrapList), BGPBACKWARDTRANSITION);
        return 0;
 }
 
@@ -934,7 +939,7 @@ static int bgp_snmp_init(struct thread_master *tm)
 
 static int bgp_snmp_module_init(void)
 {
-       hook_register(peer_established, bgpTrapEstablished);
+       hook_register(peer_status_changed, bgpTrapEstablished);
        hook_register(peer_backward_transition, bgpTrapBackwardTransition);
        hook_register(frr_late_init, bgp_snmp_init);
        return 0;