Re: bgpd fix mrt table dumps

2019-06-23 Thread Sebastian Benoit
Claudio Jeker(cje...@diehard.n-r-g.com) on 2019.06.22 10:30:46 +0200:
> Once again I broke mrt table dumps a bit. This time by not dumping the

sorry about that.

> community data anymore. Add this back by adding the needed code in
> rde_community.c and some other minor adjustments.
> 
> With this the just commited regress test passes again :)

and i checked the dumps, and the code looks ok.

> -- 
> :wq Claudio
> 
> Index: mrt.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v
> retrieving revision 1.95
> diff -u -p -r1.95 mrt.c
> --- mrt.c 22 Jun 2019 05:44:05 -  1.95
> +++ mrt.c 22 Jun 2019 06:34:50 -
> @@ -34,7 +34,8 @@
>  #include "mrt.h"
>  #include "log.h"
>  
> -int mrt_attr_dump(struct ibuf *, struct rde_aspath *, struct bgpd_addr *, 
> int);
> +int mrt_attr_dump(struct ibuf *, struct rde_aspath *, struct rde_community *,
> +struct bgpd_addr *, int);
>  int mrt_dump_entry_mp(struct mrt *, struct prefix *, u_int16_t,
>  struct rde_peer*);
>  int mrt_dump_entry(struct mrt *, struct prefix *, u_int16_t, struct 
> rde_peer*);
> @@ -143,8 +144,8 @@ fail:
>  }
>  
>  int
> -mrt_attr_dump(struct ibuf *buf, struct rde_aspath *a, struct bgpd_addr 
> *nexthop,
> -int v2)
> +mrt_attr_dump(struct ibuf *buf, struct rde_aspath *a, struct rde_community 
> *c,
> +struct bgpd_addr *nexthop, int v2)
>  {
>   struct attr *oa;
>   u_char  *pdata;
> @@ -188,6 +189,10 @@ mrt_attr_dump(struct ibuf *buf, struct r
>   if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_LOCALPREF, &tmp, 4) == -1)
>   return (-1);
>  
> + /* communities */
> + if (community_writebuf(buf, c) == -1)
> + return (-1);
> +
>   /* dump all other path attributes without modification */
>   for (l = 0; l < a->others_len; l++) {
>   if ((oa = a->others[l]) == NULL)
> @@ -272,7 +277,8 @@ mrt_dump_entry_mp(struct mrt *mrt, struc
>   return (-1);
>   }
>  
> - if (mrt_attr_dump(buf, prefix_aspath(p), NULL, 0) == -1) {
> + if (mrt_attr_dump(buf, prefix_aspath(p), prefix_communities(p),
> + NULL, 0) == -1) {
>   log_warnx("mrt_dump_entry_mp: mrt_attr_dump error");
>   goto fail;
>   }
> @@ -401,7 +407,8 @@ mrt_dump_entry(struct mrt *mrt, struct p
>   nh = &addr;
>   } else
>   nh = &nexthop->exit_nexthop;
> - if (mrt_attr_dump(buf, prefix_aspath(p), nh, 0) == -1) {
> + if (mrt_attr_dump(buf, prefix_aspath(p), prefix_communities(p),
> + nh, 0) == -1) {
>   log_warnx("mrt_dump_entry: mrt_attr_dump error");
>   ibuf_free(buf);
>   return (-1);
> @@ -529,7 +536,8 @@ mrt_dump_entry_v2(struct mrt *mrt, struc
>   log_warn("%s: ibuf_dynamic", __func__);
>   return (-1);
>   }
> - if (mrt_attr_dump(tbuf, prefix_aspath(p), nh, 1) == -1) {
> + if (mrt_attr_dump(tbuf, prefix_aspath(p), prefix_communities(p),
> + nh, 1) == -1) {
>   log_warnx("%s: mrt_attr_dump error", __func__);
>   ibuf_free(buf);
>   return (-1);
> @@ -641,7 +649,7 @@ mrt_dump_peer(struct ibuf *buf, struct r
>   goto fail;
>   }
>   break;
> - case AID_UNSPEC: /* XXX special handling for peer_self? */
> + case AID_UNSPEC: /* XXX special handling for peerself? */
>   DUMP_NLONG(buf, 0);
>   break;
>   default:
> Index: rde.h
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
> retrieving revision 1.217
> diff -u -p -r1.217 rde.h
> --- rde.h 22 Jun 2019 05:44:05 -  1.217
> +++ rde.h 22 Jun 2019 06:34:50 -
> @@ -395,20 +395,21 @@ u_char  *aspath_override(struct aspath *
>   u_int16_t *);
>  int   aspath_lenmatch(struct aspath *, enum aslen_spec, u_int);
>  
> -int   community_match(struct rde_community *, struct community *,
> +int  community_match(struct rde_community *, struct community *,
>   struct rde_peer *);
> -int   community_set(struct rde_community *, struct community *,
> +int  community_set(struct rde_community *, struct community *,
>   struct rde_peer *);
> -void  community_delete(struct rde_community *, struct community *,
> +void community_delete(struct rde_community *, struct community *,
>   struct rde_peer *);
>  
> -int   community_add(struct rde_community *, int, void *, size_t);
> -int   community_large_add(struct rde_community *, int, void *, size_t);
> -int   community_ext_add(struct rde_community *, int, void *, size_t);
> +int  community_add(struct rde_community *, int, void *, size_t);
> +int  community_large_add(struct rde_community *, int, void *, size_t);
> +int  community_ext_add(struct rde_community *, 

bgpd fix mrt table dumps

2019-06-22 Thread Claudio Jeker
Once again I broke mrt table dumps a bit. This time by not dumping the
community data anymore. Add this back by adding the needed code in
rde_community.c and some other minor adjustments.

With this the just commited regress test passes again :)
-- 
:wq Claudio

Index: mrt.c
===
RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v
retrieving revision 1.95
diff -u -p -r1.95 mrt.c
--- mrt.c   22 Jun 2019 05:44:05 -  1.95
+++ mrt.c   22 Jun 2019 06:34:50 -
@@ -34,7 +34,8 @@
 #include "mrt.h"
 #include "log.h"
 
-int mrt_attr_dump(struct ibuf *, struct rde_aspath *, struct bgpd_addr *, int);
+int mrt_attr_dump(struct ibuf *, struct rde_aspath *, struct rde_community *,
+struct bgpd_addr *, int);
 int mrt_dump_entry_mp(struct mrt *, struct prefix *, u_int16_t,
 struct rde_peer*);
 int mrt_dump_entry(struct mrt *, struct prefix *, u_int16_t, struct rde_peer*);
@@ -143,8 +144,8 @@ fail:
 }
 
 int
-mrt_attr_dump(struct ibuf *buf, struct rde_aspath *a, struct bgpd_addr 
*nexthop,
-int v2)
+mrt_attr_dump(struct ibuf *buf, struct rde_aspath *a, struct rde_community *c,
+struct bgpd_addr *nexthop, int v2)
 {
struct attr *oa;
u_char  *pdata;
@@ -188,6 +189,10 @@ mrt_attr_dump(struct ibuf *buf, struct r
if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_LOCALPREF, &tmp, 4) == -1)
return (-1);
 
+   /* communities */
+   if (community_writebuf(buf, c) == -1)
+   return (-1);
+
/* dump all other path attributes without modification */
for (l = 0; l < a->others_len; l++) {
if ((oa = a->others[l]) == NULL)
@@ -272,7 +277,8 @@ mrt_dump_entry_mp(struct mrt *mrt, struc
return (-1);
}
 
-   if (mrt_attr_dump(buf, prefix_aspath(p), NULL, 0) == -1) {
+   if (mrt_attr_dump(buf, prefix_aspath(p), prefix_communities(p),
+   NULL, 0) == -1) {
log_warnx("mrt_dump_entry_mp: mrt_attr_dump error");
goto fail;
}
@@ -401,7 +407,8 @@ mrt_dump_entry(struct mrt *mrt, struct p
nh = &addr;
} else
nh = &nexthop->exit_nexthop;
-   if (mrt_attr_dump(buf, prefix_aspath(p), nh, 0) == -1) {
+   if (mrt_attr_dump(buf, prefix_aspath(p), prefix_communities(p),
+   nh, 0) == -1) {
log_warnx("mrt_dump_entry: mrt_attr_dump error");
ibuf_free(buf);
return (-1);
@@ -529,7 +536,8 @@ mrt_dump_entry_v2(struct mrt *mrt, struc
log_warn("%s: ibuf_dynamic", __func__);
return (-1);
}
-   if (mrt_attr_dump(tbuf, prefix_aspath(p), nh, 1) == -1) {
+   if (mrt_attr_dump(tbuf, prefix_aspath(p), prefix_communities(p),
+   nh, 1) == -1) {
log_warnx("%s: mrt_attr_dump error", __func__);
ibuf_free(buf);
return (-1);
@@ -641,7 +649,7 @@ mrt_dump_peer(struct ibuf *buf, struct r
goto fail;
}
break;
-   case AID_UNSPEC: /* XXX special handling for peer_self? */
+   case AID_UNSPEC: /* XXX special handling for peerself? */
DUMP_NLONG(buf, 0);
break;
default:
Index: rde.h
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.217
diff -u -p -r1.217 rde.h
--- rde.h   22 Jun 2019 05:44:05 -  1.217
+++ rde.h   22 Jun 2019 06:34:50 -
@@ -395,20 +395,21 @@ u_char*aspath_override(struct aspath *
u_int16_t *);
 int aspath_lenmatch(struct aspath *, enum aslen_spec, u_int);
 
-int community_match(struct rde_community *, struct community *,
+intcommunity_match(struct rde_community *, struct community *,
struct rde_peer *);
-int community_set(struct rde_community *, struct community *,
+intcommunity_set(struct rde_community *, struct community *,
struct rde_peer *);
-voidcommunity_delete(struct rde_community *, struct community *,
+void   community_delete(struct rde_community *, struct community *,
struct rde_peer *);
 
-int community_add(struct rde_community *, int, void *, size_t);
-int community_large_add(struct rde_community *, int, void *, size_t);
-int community_ext_add(struct rde_community *, int, void *, size_t);
+intcommunity_add(struct rde_community *, int, void *, size_t);
+intcommunity_large_add(struct rde_community *, int, void *, size_t);
+intcommunity_ext_add(struct rde_community *, int, void *, size_t);
 
-int community_write(struct rde_community *, void *, u_int16_t);
-int community_large_write(struct rde_community *, void *, u_int16_t);
-int community_ext_write(struct rde_community *, int, void *, u_int16_t);

Re: bgpd fix mrt table dumps

2018-10-12 Thread Sebastian Benoit
ok

Claudio Jeker(cje...@diehard.n-r-g.com) on 2018.10.12 13:08:15 +0200:
> Some time ago I busted mrt dumps. This fixes them again.
> 
> Run the mrt rib_dump_r runner in the poll loop before checking for queued
> imsgs. This makes sure that data is produced and pushed out quickly. Only
> run the runner when the mrt state is not MRT_STATE_REMOVE (since that
> would restart the dump) and there are no queued messages.
> 
> -- 
> :wq Claudio
> 
> Index: rde.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
> retrieving revision 1.433
> diff -u -p -r1.433 rde.c
> --- rde.c 3 Oct 2018 11:36:39 -   1.433
> +++ rde.c 12 Oct 2018 07:45:15 -
> @@ -282,6 +281,11 @@ rde_main(int debug, int verbose)
>   i = PFD_PIPE_COUNT;
>   for (mctx = LIST_FIRST(&rde_mrts); mctx != 0; mctx = xmctx) {
>   xmctx = LIST_NEXT(mctx, entry);
> +
> + if (mctx->mrt.state != MRT_STATE_REMOVE &&
> + mctx->mrt.wbuf.queued == 0)
> + rib_dump_r(&mctx->ribctx);
> +
>   if (mctx->mrt.wbuf.queued) {
>   pfd[i].fd = mctx->mrt.wbuf.fd;
>   pfd[i].events = POLLOUT;
> 



bgpd fix mrt table dumps

2018-10-12 Thread Claudio Jeker
Some time ago I busted mrt dumps. This fixes them again.

Run the mrt rib_dump_r runner in the poll loop before checking for queued
imsgs. This makes sure that data is produced and pushed out quickly. Only
run the runner when the mrt state is not MRT_STATE_REMOVE (since that
would restart the dump) and there are no queued messages.

-- 
:wq Claudio

Index: rde.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.433
diff -u -p -r1.433 rde.c
--- rde.c   3 Oct 2018 11:36:39 -   1.433
+++ rde.c   12 Oct 2018 07:45:15 -
@@ -282,6 +281,11 @@ rde_main(int debug, int verbose)
i = PFD_PIPE_COUNT;
for (mctx = LIST_FIRST(&rde_mrts); mctx != 0; mctx = xmctx) {
xmctx = LIST_NEXT(mctx, entry);
+
+   if (mctx->mrt.state != MRT_STATE_REMOVE &&
+   mctx->mrt.wbuf.queued == 0)
+   rib_dump_r(&mctx->ribctx);
+
if (mctx->mrt.wbuf.queued) {
pfd[i].fd = mctx->mrt.wbuf.fd;
pfd[i].events = POLLOUT;