Re: bgpd: print AS range

2016-07-13 Thread Sebastian Benoit
Hei,

i finally commited this.

Thank you.

Denis Fondras(open...@ledeuns.net) on 2016.06.05 11:02:31 +0200:
> On Sun, Jun 05, 2016 at 10:28:05AM +0200, Sebastian Benoit wrote:
> > hei,
> > 
> > thanks! i forgot that we print the config.
> > 
> > ok benno@, with whitespace fixed.
> > 
> 
> 
> Index: printconf.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
> retrieving revision 1.96
> diff -u -p -r1.96 printconf.c
> --- printconf.c   21 Sep 2015 09:47:15 -  1.96
> +++ printconf.c   5 Jun 2016 09:00:18 -
> @@ -41,8 +41,9 @@ void print_peer(struct peer_config *, 
>  const char   *print_auth_alg(u_int8_t);
>  const char   *print_enc_alg(u_int8_t);
>  void  print_announce(struct peer_config *, const char *);
> +void  print_as(struct filter_rule *);
>  void  print_rule(struct peer *, struct filter_rule *);
> -const char *  mrt_type(enum mrt_type);
> +const char   *mrt_type(enum mrt_type);
>  void  print_mrt(struct bgpd_config *, u_int32_t, u_int32_t,
>   const char *, const char *);
>  void  print_groups(struct bgpd_config *, struct peer *);
> @@ -506,6 +507,26 @@ print_announce(struct peer_config *p, co
>   printf("%s\tannounce %s\n", c, aid2str(aid));
>  }
>  
> +void print_as(struct filter_rule *r)
> +{
> + switch(r->match.as.op) {
> + case OP_RANGE:
> + printf("%s - ", log_as(r->match.as.as_min));
> + printf("%s ", log_as(r->match.as.as_max));
> + break;  
> + case OP_XRANGE:
> + printf("%s >< ", log_as(r->match.as.as_min));
> + printf("%s ", log_as(r->match.as.as_max));
> + break;
> + case OP_NE:
> + printf("!= %s ", log_as(r->match.as.as));
> + break;
> + default:
> + printf("%s ", log_as(r->match.as.as));
> + break;
> + }
> +}
> +
>  void
>  print_rule(struct peer *peer_l, struct filter_rule *r)
>  {
> @@ -577,15 +598,16 @@ print_rule(struct peer *peer_l, struct f
>  
>   if (r->match.as.type) {
>   if (r->match.as.type == AS_ALL)
> - printf("AS %s ", log_as(r->match.as.as));
> + printf("AS ");
>   else if (r->match.as.type == AS_SOURCE)
> - printf("source-as %s ", log_as(r->match.as.as));
> + printf("source-as ");
>   else if (r->match.as.type == AS_TRANSIT)
> - printf("transit-as %s ", log_as(r->match.as.as));
> + printf("transit-as ");
>   else if (r->match.as.type == AS_PEER)
> - printf("peer-as %s ", log_as(r->match.as.as));
> + printf("peer-as ");
>   else
> - printf("unfluffy-as %s ", log_as(r->match.as.as));
> + printf("unfluffy-as ");
> + print_as(r);
>   }
>  
>   if (r->match.aslen.type) {
> 

-- 



Re: bgpd: print AS range

2016-06-05 Thread Denis Fondras
On Sun, Jun 05, 2016 at 10:28:05AM +0200, Sebastian Benoit wrote:
> hei,
> 
> thanks! i forgot that we print the config.
> 
> ok benno@, with whitespace fixed.
> 


Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.96
diff -u -p -r1.96 printconf.c
--- printconf.c 21 Sep 2015 09:47:15 -  1.96
+++ printconf.c 5 Jun 2016 09:00:18 -
@@ -41,8 +41,9 @@ void   print_peer(struct peer_config *, 
 const char *print_auth_alg(u_int8_t);
 const char *print_enc_alg(u_int8_t);
 voidprint_announce(struct peer_config *, const char *);
+voidprint_as(struct filter_rule *);
 voidprint_rule(struct peer *, struct filter_rule *);
-const char *mrt_type(enum mrt_type);
+const char *mrt_type(enum mrt_type);
 voidprint_mrt(struct bgpd_config *, u_int32_t, u_int32_t,
const char *, const char *);
 voidprint_groups(struct bgpd_config *, struct peer *);
@@ -506,6 +507,26 @@ print_announce(struct peer_config *p, co
printf("%s\tannounce %s\n", c, aid2str(aid));
 }
 
+void print_as(struct filter_rule *r)
+{
+   switch(r->match.as.op) {
+   case OP_RANGE:
+   printf("%s - ", log_as(r->match.as.as_min));
+   printf("%s ", log_as(r->match.as.as_max));
+   break;  
+   case OP_XRANGE:
+   printf("%s >< ", log_as(r->match.as.as_min));
+   printf("%s ", log_as(r->match.as.as_max));
+   break;
+   case OP_NE:
+   printf("!= %s ", log_as(r->match.as.as));
+   break;
+   default:
+   printf("%s ", log_as(r->match.as.as));
+   break;
+   }
+}
+
 void
 print_rule(struct peer *peer_l, struct filter_rule *r)
 {
@@ -577,15 +598,16 @@ print_rule(struct peer *peer_l, struct f
 
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
-   printf("AS %s ", log_as(r->match.as.as));
+   printf("AS ");
else if (r->match.as.type == AS_SOURCE)
-   printf("source-as %s ", log_as(r->match.as.as));
+   printf("source-as ");
else if (r->match.as.type == AS_TRANSIT)
-   printf("transit-as %s ", log_as(r->match.as.as));
+   printf("transit-as ");
else if (r->match.as.type == AS_PEER)
-   printf("peer-as %s ", log_as(r->match.as.as));
+   printf("peer-as ");
else
-   printf("unfluffy-as %s ", log_as(r->match.as.as));
+   printf("unfluffy-as ");
+   print_as(r);
}
 
if (r->match.aslen.type) {



Re: bgpd: print AS range

2016-06-05 Thread Sebastian Benoit
hei,

thanks! i forgot that we print the config.

ok benno@, with whitespace fixed.

Denis Fondras(open...@ledeuns.net) on 2016.06.05 10:06:29 +0200:
> > This didn't quite work, as log_as will override itself when used twice
> > in the same printf.
> > 
> 
> I should not have sent this late at night...
> 
> 
> Index: printconf.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
> retrieving revision 1.96
> diff -u -p -r1.96 printconf.c
> --- printconf.c   21 Sep 2015 09:47:15 -  1.96
> +++ printconf.c   5 Jun 2016 08:00:59 -
> @@ -41,8 +41,9 @@ void print_peer(struct peer_config *, 
>  const char   *print_auth_alg(u_int8_t);
>  const char   *print_enc_alg(u_int8_t);
>  void  print_announce(struct peer_config *, const char *);
> +void  print_as(struct filter_rule *);
>  void  print_rule(struct peer *, struct filter_rule *);
> -const char *  mrt_type(enum mrt_type);
> +const char   *mrt_type(enum mrt_type);
>  void  print_mrt(struct bgpd_config *, u_int32_t, u_int32_t,
>   const char *, const char *);
>  void  print_groups(struct bgpd_config *, struct peer *);
> @@ -506,6 +507,26 @@ print_announce(struct peer_config *p, co
>   printf("%s\tannounce %s\n", c, aid2str(aid));
>  }
>  
> +void print_as(struct filter_rule *r)
> +{
> + switch(r->match.as.op) {
> + case OP_RANGE:
> +printf("%s - ", log_as(r->match.as.as_min));

whitespace

> + printf("%s ", log_as(r->match.as.as_max));
> + break;  
> + case OP_XRANGE:
> + printf("%s >< ", log_as(r->match.as.as_min));
> + printf("%s ", log_as(r->match.as.as_max));
> + break;
> + case OP_NE:
> + printf("!= %s ", log_as(r->match.as.as));
> + break;
> + default:
> + printf("%s ", log_as(r->match.as.as));
> + break;
> + }
> +}
> +
>  void
>  print_rule(struct peer *peer_l, struct filter_rule *r)
>  {
> @@ -577,15 +598,16 @@ print_rule(struct peer *peer_l, struct f
>  
>   if (r->match.as.type) {
>   if (r->match.as.type == AS_ALL)
> - printf("AS %s ", log_as(r->match.as.as));
> + printf("AS ");
>   else if (r->match.as.type == AS_SOURCE)
> - printf("source-as %s ", log_as(r->match.as.as));
> + printf("source-as ");
>   else if (r->match.as.type == AS_TRANSIT)
> - printf("transit-as %s ", log_as(r->match.as.as));
> + printf("transit-as ");
>   else if (r->match.as.type == AS_PEER)
> - printf("peer-as %s ", log_as(r->match.as.as));
> + printf("peer-as ");
>   else
> - printf("unfluffy-as %s ", log_as(r->match.as.as));
> + printf("unfluffy-as ");
> + print_as(r);
>   }
>  
>   if (r->match.aslen.type) {
> 

-- 



Re: bgpd: print AS range

2016-06-05 Thread Denis Fondras
> This didn't quite work, as log_as will override itself when used twice
> in the same printf.
> 

I should not have sent this late at night...


Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.96
diff -u -p -r1.96 printconf.c
--- printconf.c 21 Sep 2015 09:47:15 -  1.96
+++ printconf.c 5 Jun 2016 08:00:59 -
@@ -41,8 +41,9 @@ void   print_peer(struct peer_config *, 
 const char *print_auth_alg(u_int8_t);
 const char *print_enc_alg(u_int8_t);
 voidprint_announce(struct peer_config *, const char *);
+voidprint_as(struct filter_rule *);
 voidprint_rule(struct peer *, struct filter_rule *);
-const char *mrt_type(enum mrt_type);
+const char *mrt_type(enum mrt_type);
 voidprint_mrt(struct bgpd_config *, u_int32_t, u_int32_t,
const char *, const char *);
 voidprint_groups(struct bgpd_config *, struct peer *);
@@ -506,6 +507,26 @@ print_announce(struct peer_config *p, co
printf("%s\tannounce %s\n", c, aid2str(aid));
 }
 
+void print_as(struct filter_rule *r)
+{
+   switch(r->match.as.op) {
+   case OP_RANGE:
+printf("%s - ", log_as(r->match.as.as_min));
+   printf("%s ", log_as(r->match.as.as_max));
+   break;  
+   case OP_XRANGE:
+   printf("%s >< ", log_as(r->match.as.as_min));
+   printf("%s ", log_as(r->match.as.as_max));
+   break;
+   case OP_NE:
+   printf("!= %s ", log_as(r->match.as.as));
+   break;
+   default:
+   printf("%s ", log_as(r->match.as.as));
+   break;
+   }
+}
+
 void
 print_rule(struct peer *peer_l, struct filter_rule *r)
 {
@@ -577,15 +598,16 @@ print_rule(struct peer *peer_l, struct f
 
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
-   printf("AS %s ", log_as(r->match.as.as));
+   printf("AS ");
else if (r->match.as.type == AS_SOURCE)
-   printf("source-as %s ", log_as(r->match.as.as));
+   printf("source-as ");
else if (r->match.as.type == AS_TRANSIT)
-   printf("transit-as %s ", log_as(r->match.as.as));
+   printf("transit-as ");
else if (r->match.as.type == AS_PEER)
-   printf("peer-as %s ", log_as(r->match.as.as));
+   printf("peer-as ");
else
-   printf("unfluffy-as %s ", log_as(r->match.as.as));
+   printf("unfluffy-as ");
+   print_as(r);
}
 
if (r->match.aslen.type) {



Re: bgpd: print AS range

2016-06-04 Thread Peter Hessler
This didn't quite work, as log_as will override itself when used twice
in the same printf.

I also fixed some knf bits.

On 2016 Jun 04 (Sat) at 22:13:07 +0200 (+0200), Denis Fondras wrote:
:With the support of AS range filtering, we need to print the configuration
:accordingly.
:
:Before :
:# bgpd -dnv
:[...]
:deny from any AS 0
:deny from any AS 0 
:deny from any AS 65535
:deny from any AS 0
:deny from any AS 0
:deny from any AS 0
:deny from any AS 4294967295 
:
:After :
:# bgpd -dnv
:[...]
:deny from any AS 64496 - 64496 
:deny from any AS 64512 - 64512 
:deny from any AS 65535 
:deny from any AS 65536 - 65536 
:deny from any AS 65552 - 65552 
:deny from any AS 42 - 42 
:deny from any AS 4294967295 
:

After:
# bgpd -nvv
[...]
deny from any AS 23456 
deny from any AS 64496 - 64511 
deny from any AS 64512 - 65534 
deny from any AS 65535 
deny from any AS 65536 - 65551 
deny from any AS 65552 - 131071 
deny from any AS 42 - 4294967294 
deny from any AS 4294967295 



Index: printconf.c
===
RCS file: /cvs/openbsd/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.96
diff -u -p -u -p -r1.96 printconf.c
--- printconf.c 21 Sep 2015 09:47:15 -  1.96
+++ printconf.c 4 Jun 2016 21:11:46 -
@@ -41,6 +41,7 @@ void   print_peer(struct peer_config *, 
 const char *print_auth_alg(u_int8_t);
 const char *print_enc_alg(u_int8_t);
 voidprint_announce(struct peer_config *, const char *);
+voidprint_as(struct filter_rule *);
 voidprint_rule(struct peer *, struct filter_rule *);
 const char *mrt_type(enum mrt_type);
 voidprint_mrt(struct bgpd_config *, u_int32_t, u_int32_t,
@@ -507,6 +508,27 @@ print_announce(struct peer_config *p, co
 }
 
 void
+print_as(struct filter_rule *r)
+{
+   switch(r->match.as.op) {
+   case OP_RANGE:
+   printf("%s - ", log_as(r->match.as.as_min));
+   printf("%s ", log_as(r->match.as.as_max));
+   break;
+   case OP_XRANGE:
+   printf("%s >< ", log_as(r->match.as.as_min));
+   printf("%s ", log_as(r->match.as.as_max));
+   break;
+   case OP_NE:
+   printf("!= %s ", log_as(r->match.as.as));
+   break;
+   default:
+   printf("%s ", log_as(r->match.as.as));
+   break;
+   }
+}
+
+void
 print_rule(struct peer *peer_l, struct filter_rule *r)
 {
struct peer *p;
@@ -577,15 +599,16 @@ print_rule(struct peer *peer_l, struct f
 
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
-   printf("AS %s ", log_as(r->match.as.as));
+   printf("AS ");
else if (r->match.as.type == AS_SOURCE)
-   printf("source-as %s ", log_as(r->match.as.as));
+   printf("source-as ");
else if (r->match.as.type == AS_TRANSIT)
-   printf("transit-as %s ", log_as(r->match.as.as));
+   printf("transit-as ");
else if (r->match.as.type == AS_PEER)
-   printf("peer-as %s ", log_as(r->match.as.as));
+   printf("peer-as ");
else
-   printf("unfluffy-as %s ", log_as(r->match.as.as));
+   printf("unfluffy-as ");
+   print_as(r);
}
 
if (r->match.aslen.type) {


-- 
Join in the new game that's sweeping the country.  It's called
"Bureaucracy".  Everybody stands in a circle.  The first person to do
anything loses.



Re: bgpd: print AS range

2016-06-04 Thread Stuart Henderson
On 2016/06/04 22:13, Denis Fondras wrote:
> With the support of AS range filtering, we need to print the configuration
> accordingly.

OK sthen@

>   if (r->match.as.type) {
>   if (r->match.as.type == AS_ALL)
> - printf("AS %s ", log_as(r->match.as.as));
> + printf("AS ");
>   else if (r->match.as.type == AS_SOURCE)
> - printf("source-as %s ", log_as(r->match.as.as));
> + printf("source-as ");
>   else if (r->match.as.type == AS_TRANSIT)
> - printf("transit-as %s ", log_as(r->match.as.as));
> + printf("transit-as ");
>   else if (r->match.as.type == AS_PEER)
> - printf("peer-as %s ", log_as(r->match.as.as));
> + printf("peer-as ");
>   else
> - printf("unfluffy-as %s ", log_as(r->match.as.as));
> + printf("unfluffy-as ");

makes a change from king bula :)



bgpd: print AS range

2016-06-04 Thread Denis Fondras
With the support of AS range filtering, we need to print the configuration
accordingly.

Before :
# bgpd -dnv
[...]
deny from any AS 0
deny from any AS 0 
deny from any AS 65535
deny from any AS 0
deny from any AS 0
deny from any AS 0
deny from any AS 4294967295 

After :
# bgpd -dnv
[...]
deny from any AS 64496 - 64496 
deny from any AS 64512 - 64512 
deny from any AS 65535 
deny from any AS 65536 - 65536 
deny from any AS 65552 - 65552 
deny from any AS 42 - 42 
deny from any AS 4294967295 


Index: printconf.c
===
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.96
diff -u -p -r1.96 printconf.c
--- printconf.c 21 Sep 2015 09:47:15 -  1.96
+++ printconf.c 4 Jun 2016 20:06:52 -
@@ -41,6 +41,7 @@ void   print_peer(struct peer_config *, 
 const char *print_auth_alg(u_int8_t);
 const char *print_enc_alg(u_int8_t);
 voidprint_announce(struct peer_config *, const char *);
+voidprint_as(struct filter_rule *);
 voidprint_rule(struct peer *, struct filter_rule *);
 const char *mrt_type(enum mrt_type);
 voidprint_mrt(struct bgpd_config *, u_int32_t, u_int32_t,
@@ -506,6 +507,26 @@ print_announce(struct peer_config *p, co
printf("%s\tannounce %s\n", c, aid2str(aid));
 }
 
+void print_as(struct filter_rule *r)
+{
+   switch(r->match.as.op) {
+   case OP_RANGE:
+printf("%s - %s ", log_as(r->match.as.as_min),
+   log_as(r->match.as.as_max));
+break;  
+case OP_XRANGE:
+printf("%s >< %s ", log_as(r->match.as.as_min),
+   log_as(r->match.as.as_max));
+break;
+case OP_NE:
+printf("!= %s ", log_as(r->match.as.as));
+break;
+default:
+printf("%s ", log_as(r->match.as.as));
+break;
+   }
+}
+
 void
 print_rule(struct peer *peer_l, struct filter_rule *r)
 {
@@ -577,15 +598,16 @@ print_rule(struct peer *peer_l, struct f
 
if (r->match.as.type) {
if (r->match.as.type == AS_ALL)
-   printf("AS %s ", log_as(r->match.as.as));
+   printf("AS ");
else if (r->match.as.type == AS_SOURCE)
-   printf("source-as %s ", log_as(r->match.as.as));
+   printf("source-as ");
else if (r->match.as.type == AS_TRANSIT)
-   printf("transit-as %s ", log_as(r->match.as.as));
+   printf("transit-as ");
else if (r->match.as.type == AS_PEER)
-   printf("peer-as %s ", log_as(r->match.as.as));
+   printf("peer-as ");
else
-   printf("unfluffy-as %s ", log_as(r->match.as.as));
+   printf("unfluffy-as ");
+   print_as(r);
}
 
if (r->match.aslen.type) {