Re: bgpd show status of set tables

2020-12-29 Thread Sebastian Benoit
reads ok, benno@

Claudio Jeker(cje...@diehard.n-r-g.com) on 2020.12.29 10:33:53 +0100:
> On Thu, Dec 10, 2020 at 02:42:49PM +0100, Claudio Jeker wrote:
> > On Thu, Dec 03, 2020 at 10:59:29PM +0100, Claudio Jeker wrote:
> > > The use of roa-set, prefix-set and as-set is fairly common in bgpd.
> > > Still sometimes it is not exactly clear how old the data in those tables
> > > is. This diff is a first step at inproving inspection by adding
> > >   bgpctl show sets
> > > 
> > > Sample output is:
> > > Type   Name #IPv4   #Ipv6 #ASnum Last 
> > > Change
> > > ROARPKI ROA158810   26257  -
> > > 00:00:07
> > > ASNUM  asns_AS15600 -   - 26
> > > 01:19:10
> > > PREFIX p4_AS21040   8   0  -
> > > 01:19:10
> > > 
> > > I just did a bgpctl reload with a new roa table (generated by rpki-client)
> > > but the as-set and prefix-set did not change during this reload.
> > > The output also includes the number of entries in the tables but in the
> > > case of roa-set the number of unique prefixes is counted. So the number is
> > > a bit under the count from rpki-client because e.g.
> > > 1.32.219.0/24 source-as 4842
> > > 1.32.219.0/24 source-as 138570
> > > are counted as 1 right now (instead of 2 prefixes).
> > > 
> > > More statistics can be added if their calculation is easy.
> > 
> > Am I the only one interested in knowing how old my set data is?
> 
> Any feedback on this? This should help people to detect issues where
> rpki-client or bgpq3 fail to produce updates.
> 
> -- 
> :wq Claudio
> 
> PS: apply diff in /usr/src/usr.sbin
> 
> Index: bgpctl/bgpctl.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
> retrieving revision 1.263
> diff -u -p -r1.263 bgpctl.c
> --- bgpctl/bgpctl.c   10 May 2020 13:38:46 -  1.263
> +++ bgpctl/bgpctl.c   3 Dec 2020 20:17:14 -
> @@ -213,6 +213,9 @@ main(int argc, char *argv[])
>   case SHOW_INTERFACE:
>   imsg_compose(ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0);
>   break;
> + case SHOW_SET:
> + imsg_compose(ibuf, IMSG_CTL_SHOW_SET, 0, 0, -1, NULL, 0);
> + break;
>   case SHOW_NEIGHBOR:
>   case SHOW_NEIGHBOR_TIMERS:
>   case SHOW_NEIGHBOR_TERSE:
> @@ -393,6 +396,7 @@ show(struct imsg *imsg, struct parse_res
>   struct ctl_timer*t;
>   struct ctl_show_interface   *iface;
>   struct ctl_show_nexthop *nh;
> + struct ctl_show_set *set;
>   struct kroute_full  *kf;
>   struct ktable   *kt;
>   struct ctl_show_rib  rib;
> @@ -466,6 +470,10 @@ show(struct imsg *imsg, struct parse_res
>   memcpy(, imsg->data, sizeof(hash));
>   output->rib_hash();
>   break;
> + case IMSG_CTL_SHOW_SET:
> + set = imsg->data;
> + output->set(set);
> + break;
>   case IMSG_CTL_RESULT:
>   if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(rescode)) {
>   warnx("got IMSG_CTL_RESULT with wrong len");
> @@ -974,6 +982,23 @@ fmt_ext_community(u_int8_t *data)
>   log_ext_subtype(type, subtype),
>   (unsigned long long)be64toh(ext));
>   return buf;
> + }
> +}
> +
> +const char *
> +fmt_set_type(struct ctl_show_set *set)
> +{
> + switch (set->type) {
> + case ROA_SET:
> + return "ROA";
> + case PREFIX_SET:
> + return "PREFIX";
> + case ORIGIN_SET:
> + return "ORIGIN";
> + case ASNUM_SET:
> + return "ASNUM";
> + default:
> + return "BULA";
>   }
>  }
>  
> Index: bgpctl/bgpctl.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.h,v
> retrieving revision 1.7
> diff -u -p -r1.7 bgpctl.h
> --- bgpctl/bgpctl.h   2 May 2020 14:33:33 -   1.7
> +++ bgpctl/bgpctl.h   3 Dec 2020 20:12:34 -
> @@ -30,6 +30,7 @@ struct output {
>   struct parse_result *);
>   void(*rib_hash)(struct rde_hashstats *);
>   void(*rib_mem)(struct rde_memstats *);
> + void(*set)(struct ctl_show_set *);
>   void(*result)(u_int);
>   void(*tail)(void);
>  };
> @@ -53,3 +54,4 @@ const char  *fmt_attr(u_int8_t, int);
>  const char   *fmt_community(u_int16_t, u_int16_t);
>  const char   *fmt_large_community(u_int32_t, u_int32_t, u_int32_t);
>  const char   *fmt_ext_community(u_int8_t *);
> +const char   *fmt_set_type(struct ctl_show_set *);
> Index: bgpctl/output.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/output.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 output.c
> --- bgpctl/output.c   21 Oct 2020 06:52:45 -  1.10
> +++ 

Re: bgpd show status of set tables

2020-12-29 Thread Claudio Jeker
On Thu, Dec 10, 2020 at 02:42:49PM +0100, Claudio Jeker wrote:
> On Thu, Dec 03, 2020 at 10:59:29PM +0100, Claudio Jeker wrote:
> > The use of roa-set, prefix-set and as-set is fairly common in bgpd.
> > Still sometimes it is not exactly clear how old the data in those tables
> > is. This diff is a first step at inproving inspection by adding
> > bgpctl show sets
> > 
> > Sample output is:
> > Type   Name #IPv4   #Ipv6 #ASnum Last Change
> > ROARPKI ROA158810   26257  -00:00:07
> > ASNUM  asns_AS15600 -   - 2601:19:10
> > PREFIX p4_AS21040   8   0  -01:19:10
> > 
> > I just did a bgpctl reload with a new roa table (generated by rpki-client)
> > but the as-set and prefix-set did not change during this reload.
> > The output also includes the number of entries in the tables but in the
> > case of roa-set the number of unique prefixes is counted. So the number is
> > a bit under the count from rpki-client because e.g.
> > 1.32.219.0/24 source-as 4842
> > 1.32.219.0/24 source-as 138570
> > are counted as 1 right now (instead of 2 prefixes).
> > 
> > More statistics can be added if their calculation is easy.
> 
> Am I the only one interested in knowing how old my set data is?

Any feedback on this? This should help people to detect issues where
rpki-client or bgpq3 fail to produce updates.

-- 
:wq Claudio

PS: apply diff in /usr/src/usr.sbin

Index: bgpctl/bgpctl.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.263
diff -u -p -r1.263 bgpctl.c
--- bgpctl/bgpctl.c 10 May 2020 13:38:46 -  1.263
+++ bgpctl/bgpctl.c 3 Dec 2020 20:17:14 -
@@ -213,6 +213,9 @@ main(int argc, char *argv[])
case SHOW_INTERFACE:
imsg_compose(ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0);
break;
+   case SHOW_SET:
+   imsg_compose(ibuf, IMSG_CTL_SHOW_SET, 0, 0, -1, NULL, 0);
+   break;
case SHOW_NEIGHBOR:
case SHOW_NEIGHBOR_TIMERS:
case SHOW_NEIGHBOR_TERSE:
@@ -393,6 +396,7 @@ show(struct imsg *imsg, struct parse_res
struct ctl_timer*t;
struct ctl_show_interface   *iface;
struct ctl_show_nexthop *nh;
+   struct ctl_show_set *set;
struct kroute_full  *kf;
struct ktable   *kt;
struct ctl_show_rib  rib;
@@ -466,6 +470,10 @@ show(struct imsg *imsg, struct parse_res
memcpy(, imsg->data, sizeof(hash));
output->rib_hash();
break;
+   case IMSG_CTL_SHOW_SET:
+   set = imsg->data;
+   output->set(set);
+   break;
case IMSG_CTL_RESULT:
if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(rescode)) {
warnx("got IMSG_CTL_RESULT with wrong len");
@@ -974,6 +982,23 @@ fmt_ext_community(u_int8_t *data)
log_ext_subtype(type, subtype),
(unsigned long long)be64toh(ext));
return buf;
+   }
+}
+
+const char *
+fmt_set_type(struct ctl_show_set *set)
+{
+   switch (set->type) {
+   case ROA_SET:
+   return "ROA";
+   case PREFIX_SET:
+   return "PREFIX";
+   case ORIGIN_SET:
+   return "ORIGIN";
+   case ASNUM_SET:
+   return "ASNUM";
+   default:
+   return "BULA";
}
 }
 
Index: bgpctl/bgpctl.h
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.h,v
retrieving revision 1.7
diff -u -p -r1.7 bgpctl.h
--- bgpctl/bgpctl.h 2 May 2020 14:33:33 -   1.7
+++ bgpctl/bgpctl.h 3 Dec 2020 20:12:34 -
@@ -30,6 +30,7 @@ struct output {
struct parse_result *);
void(*rib_hash)(struct rde_hashstats *);
void(*rib_mem)(struct rde_memstats *);
+   void(*set)(struct ctl_show_set *);
void(*result)(u_int);
void(*tail)(void);
 };
@@ -53,3 +54,4 @@ const char*fmt_attr(u_int8_t, int);
 const char *fmt_community(u_int16_t, u_int16_t);
 const char *fmt_large_community(u_int32_t, u_int32_t, u_int32_t);
 const char *fmt_ext_community(u_int8_t *);
+const char *fmt_set_type(struct ctl_show_set *);
Index: bgpctl/output.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/output.c,v
retrieving revision 1.10
diff -u -p -r1.10 output.c
--- bgpctl/output.c 21 Oct 2020 06:52:45 -  1.10
+++ bgpctl/output.c 3 Dec 2020 20:53:36 -
@@ -77,6 +77,10 @@ show_head(struct parse_result *res)
"flags", "ovs", "destination", "gateway", "lpref", "med",
"aspath origin");
break;
+   

Re: bgpd show status of set tables

2020-12-10 Thread Claudio Jeker
On Thu, Dec 03, 2020 at 10:59:29PM +0100, Claudio Jeker wrote:
> The use of roa-set, prefix-set and as-set is fairly common in bgpd.
> Still sometimes it is not exactly clear how old the data in those tables
> is. This diff is a first step at inproving inspection by adding
>   bgpctl show sets
> 
> Sample output is:
> Type   Name #IPv4   #Ipv6 #ASnum Last Change
> ROARPKI ROA158810   26257  -00:00:07
> ASNUM  asns_AS15600 -   - 2601:19:10
> PREFIX p4_AS21040   8   0  -01:19:10
> 
> I just did a bgpctl reload with a new roa table (generated by rpki-client)
> but the as-set and prefix-set did not change during this reload.
> The output also includes the number of entries in the tables but in the
> case of roa-set the number of unique prefixes is counted. So the number is
> a bit under the count from rpki-client because e.g.
> 1.32.219.0/24 source-as 4842
> 1.32.219.0/24 source-as 138570
> are counted as 1 right now (instead of 2 prefixes).
> 
> More statistics can be added if their calculation is easy.

Am I the only one interested in knowing how old my set data is?

-- 
:wq Claudio

> PS: apply diff in /usr/src/usr.sbin

Index: bgpd/bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.405
diff -u -p -r1.405 bgpd.h
--- bgpd/bgpd.h 5 Nov 2020 11:52:59 -   1.405
+++ bgpd/bgpd.h 3 Dec 2020 20:15:30 -
@@ -254,12 +254,15 @@ struct trie_head {
struct tentry_v6*root_v6;
int  match_default_v4;
int  match_default_v6;
+   size_t   v4_cnt;
+   size_t   v6_cnt;
 };
 
 struct rde_prefixset {
charname[SET_NAME_LEN];
struct trie_headth;
SIMPLEQ_ENTRY(rde_prefixset)entry;
+   time_t  lastchange;
int dirty;
 };
 SIMPLEQ_HEAD(rde_prefixset_head, rde_prefixset);
@@ -465,6 +468,7 @@ enum imsg_type {
IMSG_CTL_SHOW_TIMER,
IMSG_CTL_LOG_VERBOSE,
IMSG_CTL_SHOW_FIB_TABLES,
+   IMSG_CTL_SHOW_SET,
IMSG_CTL_TERMINATE,
IMSG_NETWORK_ADD,
IMSG_NETWORK_ASPATH,
@@ -696,6 +700,20 @@ struct ctl_show_nexthop {
u_int8_tkrvalid;
 };
 
+struct ctl_show_set {
+   charname[SET_NAME_LEN];
+   time_t  lastchange;
+   size_t  v4_cnt;
+   size_t  v6_cnt;
+   size_t  as_cnt;
+   enum {
+   ASNUM_SET,
+   PREFIX_SET,
+   ORIGIN_SET,
+   ROA_SET,
+   }   type;
+};
+
 struct ctl_neighbor {
struct bgpd_addraddr;
chardescr[PEER_DESCR_LEN];
@@ -1049,6 +1067,7 @@ struct as_set {
char name[SET_NAME_LEN];
SIMPLEQ_ENTRY(as_set)entry;
struct set_table*set;
+   time_t   lastchange;
int  dirty;
 };
 
@@ -1283,6 +1302,7 @@ void   set_prep(struct set_table *);
 void   *set_match(const struct set_table *, u_int32_t);
 int set_equal(const struct set_table *,
const struct set_table *);
+size_t  set_nmemb(const struct set_table *);
 
 /* rde_trie.c */
 inttrie_add(struct trie_head *, struct bgpd_addr *, u_int8_t, u_int8_t,
Index: bgpd/control.c
===
RCS file: /cvs/src/usr.sbin/bgpd/control.c,v
retrieving revision 1.101
diff -u -p -r1.101 control.c
--- bgpd/control.c  5 Nov 2020 11:28:11 -   1.101
+++ bgpd/control.c  3 Dec 2020 17:07:58 -
@@ -280,6 +280,7 @@ control_dispatch_msg(struct pollfd *pfd,
case IMSG_CTL_SHOW_NETWORK:
case IMSG_CTL_SHOW_RIB:
case IMSG_CTL_SHOW_RIB_PREFIX:
+   case IMSG_CTL_SHOW_SET:
break;
default:
/* clear imsg type to prevent processing */
@@ -496,6 +497,7 @@ control_dispatch_msg(struct pollfd *pfd,
c->terminate = 1;
/* FALLTHROUGH */
case IMSG_CTL_SHOW_RIB_MEM:
+   case IMSG_CTL_SHOW_SET:
c->ibuf.pid = imsg.hdr.pid;
imsg_ctl_rde(imsg.hdr.type, imsg.hdr.pid,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
Index: bgpd/rde.c
===