Re: BFD: route get and route monitor

2017-01-19 Thread Peter Hessler
On 2017 Jan 19 (Thu) at 06:26:25 +0100 (+0100), Peter Hessler wrote:
:On 2016 Dec 17 (Sat) at 14:05:40 +0100 (+0100), Peter Hessler wrote:
::On 2016 Sep 30 (Fri) at 10:16:19 +0200 (+0200), Peter Hessler wrote:
:::This diff makes route get and route monitor work.  sockaddr_bfd is so we
:::can play like the other RTAX_* indexes in rti_info of route messages.
:::
:
:In route(8), only say "up" or "down" for the state of BFD.  use -v or
:-bfd to get details that only matter to debug BFD.
:
:$ route -n get 203.0.113.9   
:   route to: 203.0.113.9
:destination: 203.0.113.9
:   mask: 255.255.255.255
:  interface: em1
: if address: 203.0.113.1
:   priority: 3 ()
:  flags: 
:BFD: up
: use   mtuexpire
:1402 0   922 
:sockaddrs: 
:
:I also fixed a number of things that mpi@ noticed.
:

And now with sockaddr_bfd (and bfd_msghdr for that matter) adjusted for
4 byte boundaries and sized to a power of two.


Index: sbin/route/Makefile
===
RCS file: /cvs/openbsd/src/sbin/route/Makefile,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 Makefile
--- sbin/route/Makefile 19 Jul 2013 14:41:46 -  1.13
+++ sbin/route/Makefile 17 Dec 2016 12:47:35 -
@@ -4,7 +4,7 @@ PROG=   route
 MAN=   route.8
 SRCS=  route.c show.c
 
-CFLAGS+=   -Wall
+CFLAGS+=   -Wall -DBFD
 
 route.o .depend lint tags: keywords.h
 
Index: sbin/route/route.c
===
RCS file: /cvs/openbsd/src/sbin/route/route.c,v
retrieving revision 1.194
diff -u -p -u -p -r1.194 route.c
--- sbin/route/route.c  17 Jan 2017 19:05:47 -  1.194
+++ sbin/route/route.c  19 Jan 2017 03:39:55 -
@@ -100,6 +100,7 @@ const char *bfd_state(unsigned int);
 const char *bfd_diag(unsigned int);
 const char *bfd_calc_uptime(time_t);
 voidprint_bfdmsg(struct rt_msghdr *);
+voidprint_sabfd(struct sockaddr_bfd *, int);
 #endif
 const char *get_linkstate(int, int);
 voidprint_rtmsg(struct rt_msghdr *, int);
@@ -1444,6 +1445,9 @@ print_getmsg(struct rt_msghdr *rtm, int 
struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
struct sockaddr_dl *ifp = NULL;
struct sockaddr_rtlabel *sa_rl = NULL;
+#ifdef BFD
+   struct sockaddr_bfd *sa_bfd = NULL;
+#endif
struct sockaddr *mpls = NULL;
struct sockaddr *sa;
char *cp;
@@ -1492,6 +1496,11 @@ print_getmsg(struct rt_msghdr *rtm, int 
case RTA_LABEL:
sa_rl = (struct sockaddr_rtlabel *)sa;
break;
+#ifdef BFD
+   case RTA_BFD:
+   sa_bfd = (struct sockaddr_bfd *)sa;
+   break;
+#endif
}
ADVANCE(cp, sa);
}
@@ -1524,6 +1533,10 @@ print_getmsg(struct rt_msghdr *rtm, int 
printf("\n");
if (sa_rl != NULL)
printf("  label: %s\n", sa_rl->sr_label);
+#ifdef BFD
+   if (sa_bfd)
+   print_sabfd(sa_bfd, rtm->rtm_fmask);
+#endif
 
 #define lock(f)((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' 
')
relative_expire = rtm->rtm_rmx.rmx_expire ?
@@ -1626,40 +1639,61 @@ void
 print_bfdmsg(struct rt_msghdr *rtm)
 {
struct bfd_msghdr *bfdm = (struct bfd_msghdr *)rtm;
+
+   printf("\n");
+   print_sabfd(>bm_sa, rtm->rtm_fmask);
+   pmsg_addrs(((char *)rtm + rtm->rtm_hdrlen), rtm->rtm_addrs);
+}
+
+void
+print_sabfd(struct sockaddr_bfd *sa_bfd, int fmask)
+{
struct timeval tv;
 
gettimeofday(, NULL);
 
-   printf(" mode ");
-   switch (bfdm->bm_mode) {
+   printf("BFD:");
+
+   /* only show the state, unless verbose or -bfd */
+   if (!verbose && ((fmask & RTF_BFD) != RTF_BFD)) {
+   printf(" %s\n", bfd_state(sa_bfd->bs_state));
+   return;
+   }
+
+   switch (sa_bfd->bs_mode) {
case BFD_MODE_ASYNC:
-   printf("async");
+   printf(" async");
break;
case BFD_MODE_DEMAND:
-   printf("demand");
+   printf(" demand");
break;
default:
-   printf("unknown %u", bfdm->bm_mode);
+   printf(" unknown %u", sa_bfd->bs_mode);
break;
}
-   printf(" state %s", bfd_state(bfdm->bm_state));
-   printf(" remotestate %s", bfd_state(bfdm->bm_remotestate));
-   printf(" laststate %s", bfd_state(bfdm->bm_laststate));
-
-   printf(" error %d", bfdm->bm_error);
-   printf(" localdiscr %u", bfdm->bm_localdiscr);
-   printf(" remotediscr %u", bfdm->bm_remotediscr);
-   printf(" localdiag %s", bfd_diag(bfdm->bm_localdiag));
-   

Re: BFD: route get and route monitor

2017-01-18 Thread Claudio Jeker
On Thu, Jan 19, 2017 at 06:26:25AM +0100, Peter Hessler wrote:
> On 2016 Dec 17 (Sat) at 14:05:40 +0100 (+0100), Peter Hessler wrote:
> :On 2016 Sep 30 (Fri) at 10:16:19 +0200 (+0200), Peter Hessler wrote:
> ::This diff makes route get and route monitor work.  sockaddr_bfd is so we
> ::can play like the other RTAX_* indexes in rti_info of route messages.
> ::
> 
> In route(8), only say "up" or "down" for the state of BFD.  use -v or
> -bfd to get details that only matter to debug BFD.
> 
> $ route -n get 203.0.113.9   
>route to: 203.0.113.9
> destination: 203.0.113.9
>mask: 255.255.255.255
>   interface: em1
>  if address: 203.0.113.1
>priority: 3 ()
>   flags: 
> BFD: up
>  use   mtuexpire
> 1402 0   922 
> sockaddrs: 
> 
> I also fixed a number of things that mpi@ noticed.
> 

You need to restructure sockaddr_bfd to be a) a power of 2 and b) so layed
out that there is no implicit padding on any arch. For example the 64bit
time_t values need to start on a 8byte offset.

Abusing sockaddrs for something that is only used on the routing socket
feels a but wrong but that is a different thing to fix.

> +struct sockaddr_bfd {
> + uint8_t bs_len; /* total length */
> + sa_family_t bs_family;  /* address family */
> + /* above matches sockaddr_storage */
> +
> + uint16_tbs_mode;
> + uint32_tbs_mintx;
> + uint32_tbs_minrx;
> + uint32_tbs_minecho;
> + uint16_tbs_multiplier;
> +
> + time_t  bs_uptime;
> + time_t  bs_lastuptime;
> + int bs_state;
> + int bs_remotestate;
> + int bs_laststate;
> + int bs_error;
> +
> + uint32_tbs_localdiscr;
> + uint32_tbs_localdiag;
> + uint32_tbs_remotediscr;
> + uint32_tbs_remotediag;
> +};
> +

-- 
:wq Claudio



Re: BFD: route get and route monitor

2017-01-18 Thread Peter Hessler
On 2016 Dec 17 (Sat) at 14:05:40 +0100 (+0100), Peter Hessler wrote:
:On 2016 Sep 30 (Fri) at 10:16:19 +0200 (+0200), Peter Hessler wrote:
::This diff makes route get and route monitor work.  sockaddr_bfd is so we
::can play like the other RTAX_* indexes in rti_info of route messages.
::

In route(8), only say "up" or "down" for the state of BFD.  use -v or
-bfd to get details that only matter to debug BFD.

$ route -n get 203.0.113.9   
   route to: 203.0.113.9
destination: 203.0.113.9
   mask: 255.255.255.255
  interface: em1
 if address: 203.0.113.1
   priority: 3 ()
  flags: 
BFD: up
 use   mtuexpire
1402 0   922 
sockaddrs: 

I also fixed a number of things that mpi@ noticed.


Index: sbin/route/Makefile
===
RCS file: /cvs/openbsd/src/sbin/route/Makefile,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 Makefile
--- sbin/route/Makefile 19 Jul 2013 14:41:46 -  1.13
+++ sbin/route/Makefile 17 Dec 2016 12:47:35 -
@@ -4,7 +4,7 @@ PROG=   route
 MAN=   route.8
 SRCS=  route.c show.c
 
-CFLAGS+=   -Wall
+CFLAGS+=   -Wall -DBFD
 
 route.o .depend lint tags: keywords.h
 
Index: sbin/route/route.c
===
RCS file: /cvs/openbsd/src/sbin/route/route.c,v
retrieving revision 1.194
diff -u -p -u -p -r1.194 route.c
--- sbin/route/route.c  17 Jan 2017 19:05:47 -  1.194
+++ sbin/route/route.c  19 Jan 2017 03:39:55 -
@@ -100,6 +100,7 @@ const char *bfd_state(unsigned int);
 const char *bfd_diag(unsigned int);
 const char *bfd_calc_uptime(time_t);
 voidprint_bfdmsg(struct rt_msghdr *);
+voidprint_sabfd(struct sockaddr_bfd *, int);
 #endif
 const char *get_linkstate(int, int);
 voidprint_rtmsg(struct rt_msghdr *, int);
@@ -1444,6 +1445,9 @@ print_getmsg(struct rt_msghdr *rtm, int 
struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
struct sockaddr_dl *ifp = NULL;
struct sockaddr_rtlabel *sa_rl = NULL;
+#ifdef BFD
+   struct sockaddr_bfd *sa_bfd = NULL;
+#endif
struct sockaddr *mpls = NULL;
struct sockaddr *sa;
char *cp;
@@ -1492,6 +1496,11 @@ print_getmsg(struct rt_msghdr *rtm, int 
case RTA_LABEL:
sa_rl = (struct sockaddr_rtlabel *)sa;
break;
+#ifdef BFD
+   case RTA_BFD:
+   sa_bfd = (struct sockaddr_bfd *)sa;
+   break;
+#endif
}
ADVANCE(cp, sa);
}
@@ -1524,6 +1533,10 @@ print_getmsg(struct rt_msghdr *rtm, int 
printf("\n");
if (sa_rl != NULL)
printf("  label: %s\n", sa_rl->sr_label);
+#ifdef BFD
+   if (sa_bfd)
+   print_sabfd(sa_bfd, rtm->rtm_fmask);
+#endif
 
 #define lock(f)((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' 
')
relative_expire = rtm->rtm_rmx.rmx_expire ?
@@ -1626,40 +1639,61 @@ void
 print_bfdmsg(struct rt_msghdr *rtm)
 {
struct bfd_msghdr *bfdm = (struct bfd_msghdr *)rtm;
+
+   printf("\n");
+   print_sabfd(>bm_sa, rtm->rtm_fmask);
+   pmsg_addrs(((char *)rtm + rtm->rtm_hdrlen), rtm->rtm_addrs);
+}
+
+void
+print_sabfd(struct sockaddr_bfd *sa_bfd, int fmask)
+{
struct timeval tv;
 
gettimeofday(, NULL);
 
-   printf(" mode ");
-   switch (bfdm->bm_mode) {
+   printf("BFD:");
+
+   /* only show the state, unless verbose or -bfd */
+   if (!verbose && ((fmask & RTF_BFD) != RTF_BFD)) {
+   printf(" %s\n", bfd_state(sa_bfd->bs_state));
+   return;
+   }
+
+   switch (sa_bfd->bs_mode) {
case BFD_MODE_ASYNC:
-   printf("async");
+   printf(" async");
break;
case BFD_MODE_DEMAND:
-   printf("demand");
+   printf(" demand");
break;
default:
-   printf("unknown %u", bfdm->bm_mode);
+   printf(" unknown %u", sa_bfd->bs_mode);
break;
}
-   printf(" state %s", bfd_state(bfdm->bm_state));
-   printf(" remotestate %s", bfd_state(bfdm->bm_remotestate));
-   printf(" laststate %s", bfd_state(bfdm->bm_laststate));
-
-   printf(" error %d", bfdm->bm_error);
-   printf(" localdiscr %u", bfdm->bm_localdiscr);
-   printf(" remotediscr %u", bfdm->bm_remotediscr);
-   printf(" localdiag %s", bfd_diag(bfdm->bm_localdiag));
-   printf(" remotediag %s", bfd_diag(bfdm->bm_remotediag));
-   printf(" uptime %s", bfd_calc_uptime(tv.tv_sec - bfdm->bm_uptime));
-   printf(" lastuptime %s", bfd_calc_uptime(bfdm->bm_lastuptime));
-
-   

Re: BFD: route get and route monitor

2017-01-12 Thread Hrvoje Popovski
On 23.12.2016. 16:57, Hrvoje Popovski wrote:
> On 21.12.2016. 23:15, Sebastian Benoit wrote:
>>> Hi,
>>>
>>> it seems that bfd is working with Force10 S4810 and Extreme Networks
>>> x460 switches. I can test it with cisco c6k5 if you want?
>>
>> Hei,
>>
>> i'm sure phessler (who might not read this for a couple of days) is happy
>> about any test you can do.
>>
>> And thanks for doing these tests!
>>
>> /Benno
> 
> Hi,
> 
> no bfd for me on Cisco c6k5. Will upgrade and report back.
> 
> Tnx for bfd, really great feature ...
> 
> 

Hi all,

at last i upgrade c6k5 and bfd is working

openbsd - 192.168.112.1

# route -n get 192.168.112.2 -bfd
   route to: 192.168.112.2
destination: 192.168.112.2
   mask: 255.255.255.255
  interface: ix1
 if address: 192.168.112.1
   priority: 3 ()
  flags: 
BFD: async state up remote up laststate down error 0
 diag none remote none
 discr 2428102669 remote 1
 uptime 34s last state time 26m30s
 mintx 75 minrx 75 minecho 0 multiplier 3
 use   mtuexpire
  55 0   626
sockaddrs: 



c6k5 - 192.168.112.2

c6k5#sh bfd neighbors details

IPv4 Sessions
NeighAddr  LD/RD RH/RS State Int
192.168.112.1   1/2428102669 UpUp
Gi6/1
Session state is UP and not using echo function.
Session Host: Software
OurAddr: 192.168.112.2
Handle: 1
Local Diag: 0, Demand mode: 0, Poll bit: 1
MinTxInt: 75, MinRxInt: 75, Multiplier: 3
Received MinRxInt: 75, Received Multiplier: 3
Holddown (hits): 2436(0), Hello (hits): 750(185)
Rx Count: 205, Rx Interval (ms) min/max/avg: 520/840/595 last: 564 ms ago
Tx Count: 186, Tx Interval (ms) min/max/avg: 568/752/661 last: 388 ms ago
Elapsed time watermarks: 0 0 (last: 0)
Registered protocols: IPv4 Static CEF
Uptime: 00:02:02
Last packet: Version: 1  - Diagnostic: 0
 State bit: Up   - Demand bit: 0
 Poll bit: 0 - Final bit: 0
 C bit: 0
 Multiplier: 3   - Length: 24
 My Discr.: 2428102669   - Your Discr.: 1
 Min tx interval: 75 - Min rx interval: 75
 Min Echo interval: 0



Re: BFD: route get and route monitor

2016-12-28 Thread Peter Hessler
On 2016 Dec 23 (Fri) at 16:57:27 +0100 (+0100), Hrvoje Popovski wrote:
:On 21.12.2016. 23:15, Sebastian Benoit wrote:
:>> Hi,
:>>
:>> it seems that bfd is working with Force10 S4810 and Extreme Networks
:>> x460 switches. I can test it with cisco c6k5 if you want?
:> 
:> Hei,
:> 
:> i'm sure phessler (who might not read this for a couple of days) is happy
:> about any test you can do.
:> 
:> And thanks for doing these tests!
:> 
:> /Benno
:
:Hi,
:
:no bfd for me on Cisco c6k5. Will upgrade and report back.
:
:Tnx for bfd, really great feature ...
:
:

Many thanks for the testing.  Can you get some packet captures of the
failing bfd with that Cisco and send them to me offline?  I'd really
like to see what they are doing.

Thanks!

-- 
What the world *really* needs is a good Automatic Bicycle Sharpener.



Re: BFD: route get and route monitor

2016-12-23 Thread Hrvoje Popovski
On 21.12.2016. 23:15, Sebastian Benoit wrote:
>> Hi,
>>
>> it seems that bfd is working with Force10 S4810 and Extreme Networks
>> x460 switches. I can test it with cisco c6k5 if you want?
> 
> Hei,
> 
> i'm sure phessler (who might not read this for a couple of days) is happy
> about any test you can do.
> 
> And thanks for doing these tests!
> 
> /Benno

Hi,

no bfd for me on Cisco c6k5. Will upgrade and report back.

Tnx for bfd, really great feature ...




Re: BFD: route get and route monitor

2016-12-21 Thread Sebastian Benoit
Hrvoje Popovski(hrv...@srce.hr) on 2016.12.21 22:03:56 +0100:
> On 17.12.2016. 14:05, Peter Hessler wrote:
> > Updated output, requested by Theo.  A normal get will show just the bfd
> > state, use "-bfd" to get all of the information.
> > 
> > OK?
> > 
> > $ route -n get 203.0.113.9
> >route to: 203.0.113.9
> > destination: 203.0.113.9
> >mask: 255.255.255.255
> >   interface: em1
> >  if address: 203.0.113.1
> >priority: 4 (connected)
> >   flags: 
> > BFD: async state up remote up
> >  use   mtuexpire
> >83924 0   133 
> > sockaddrs: 
> > 
> > $ route -n get 203.0.113.9 -bfd
> >route to: 203.0.113.9
> > destination: 203.0.113.9
> >mask: 255.255.255.255
> >   interface: em1
> >  if address: 203.0.113.1
> >priority: 4 (connected)
> >   flags: 
> > BFD: async state up remote up laststate down error 0
> >  diag none remote neighbor-down
> >  discr 186919089 remote 55
> >  uptime 05d 2h07m29s
> >  mintx 100 minrx 100 minecho 0 multiplier 3
> >  use   mtuexpire
> >83923 0   229 
> > sockaddrs: 
> 
> 
> Hi,
> 
> it seems that bfd is working with Force10 S4810 and Extreme Networks
> x460 switches. I can test it with cisco c6k5 if you want?

Hei,

i'm sure phessler (who might not read this for a couple of days) is happy
about any test you can do.

And thanks for doing these tests!

/Benno



Re: BFD: route get and route monitor

2016-12-21 Thread Hrvoje Popovski
On 17.12.2016. 14:05, Peter Hessler wrote:
> Updated output, requested by Theo.  A normal get will show just the bfd
> state, use "-bfd" to get all of the information.
> 
> OK?
> 
> $ route -n get 203.0.113.9
>route to: 203.0.113.9
> destination: 203.0.113.9
>mask: 255.255.255.255
>   interface: em1
>  if address: 203.0.113.1
>priority: 4 (connected)
>   flags: 
> BFD: async state up remote up
>  use   mtuexpire
>83924 0   133 
> sockaddrs: 
> 
> $ route -n get 203.0.113.9 -bfd
>route to: 203.0.113.9
> destination: 203.0.113.9
>mask: 255.255.255.255
>   interface: em1
>  if address: 203.0.113.1
>priority: 4 (connected)
>   flags: 
> BFD: async state up remote up laststate down error 0
>  diag none remote neighbor-down
>  discr 186919089 remote 55
>  uptime 05d 2h07m29s
>  mintx 100 minrx 100 minecho 0 multiplier 3
>  use   mtuexpire
>83923 0   229 
> sockaddrs: 


Hi,

it seems that bfd is working with Force10 S4810 and Extreme Networks
x460 switches. I can test it with cisco c6k5 if you want?
Thank you.

bsdtest box is connected in this way:

192.168.11.1 - bsdtest ix0
192.168.11.2 - Dell Force10 S4810 9.11(0.0)

192.168.112.1 - bsdtest ix1
192.168.112.2 - Extreme Networks X460-48t 15.5.3.4


BFD between OpenBSD - Force10 S4810

root@bsdtest:~
# route -n get 192.168.11.2 -bfd
   route to: 192.168.11.2
destination: 192.168.11.2
   mask: 255.255.255.255
  interface: ix0
 if address: 192.168.11.1
   priority: 3 ()
  flags: 
BFD: async state up remote up laststate down error 0
 diag none remote none
 discr 2137079205 remote 4
 uptime 07m26s last state time 01s
 mintx 100 minrx 100 minecho 0 multiplier 3
 use   mtuexpire
 113 0   628
sockaddrs: 

root@bsdtest:~
# route -n monitor

sockaddrs: 
 192.168.11.2 192.168.11.1
got message of size 128 on Wed Dec 21 21:55:15 2016
RTM_BFD: bidirectional forwarding detection: len 128
BFD: async state up remote up


S4810#sh bfd neighbors detail

Session Discriminator: 4
Neighbor Discriminator: 0
Local Addr: 192.168.11.2
Local MAC Addr: 00:01:e8:8a:ea:53
Remote Addr: 192.168.11.1
Remote MAC Addr: 00:25:90:5d:ca:38
Int: TenGigabitEthernet 0/3
State: Up
Configured parameters:
 TX:  200ms, RX:  200ms, Multiplier: 3
Neighbor parameters:
 TX:0ms, RX:0ms, Multiplier: 0
Actual parameters:
 TX: 1000ms, RX: 1000ms, Multiplier: 3
Role: Active
Delete session on Down: False
Client Registered: RTM
Uptime: 00:06:49
Statistics:
 Number of packets received from neighbor: 514
 Number of packets sent to neighbor: 465
 Number of state changes: 2
 Number of messages from IFA about port state change: 0
 Number of messages communicated b/w Manager and Agent: 4



BFD between OpenBSD and Extreme

root@bsdtest:~
# route -n get 192.168.112.2 -bfd
   route to: 192.168.112.2
destination: 192.168.112.2
   mask: 255.255.255.255
  interface: ix1
 if address: 192.168.112.1
   priority: 3 ()
  flags: 
BFD: async state up remote up laststate down error 0
 diag none remote none
 discr 3953390566 remote 2
 uptime 10m17s last state time 01s
 mintx 100 minrx 100 minecho 0 multiplier 3
 use   mtuexpire
  87 0   511
sockaddrs: 

root@bsdtest:~
# route -n monitor

sockaddrs: 
 192.168.112.2 192.168.112.1
got message of size 128 on Wed Dec 21 21:56:30 2016
RTM_BFD: bidirectional forwarding detection: len 128
BFD: async state up remote up



ExtTestFW.30 # sh bfd session detail
Neighbor   : 192.168.112.1   Local   : 192.168.112.2
VR-Name: VR-Default  Interface   : obfd
Session Type   : Single Hop  State   : Up
Detect Time: 3000 ms Age : 550 ms
Discriminator (local/remote): 2 / 3953390566
Demand Mode (local/remote)  : Off / Off
Poll (local/remote) : Off / Off
Tx Interval (local/remote)  : 1000 / 1000 ms
Rx Interval (local/remote)  : 1000 / 1000 ms
oper Tx Interval: 1000 ms
oper Rx Interval: 1000 ms
Multiplier (local/remote)   : 3 / 3
Local Diag  : 0 (No Diagnostic)
Remote Diag : 0 (No Diagnostic)
Authentication  : None
Clients : STATIC
Uptime  : 00 days 00 hours 10 minutes 29 seconds
Up Count: 2
Last Valid Packet Rx: 20:52:44.173792
Last Packet Tx  : 

Re: BFD: route get and route monitor

2016-12-17 Thread Peter Hessler
On 2016 Sep 30 (Fri) at 10:16:19 +0200 (+0200), Peter Hessler wrote:
:This diff makes route get and route monitor work.  sockaddr_bfd is so we
:can play like the other RTAX_* indexes in rti_info of route messages.
:
:OK?

Updated output, requested by Theo.  A normal get will show just the bfd
state, use "-bfd" to get all of the information.

OK?

$ route -n get 203.0.113.9
   route to: 203.0.113.9
destination: 203.0.113.9
   mask: 255.255.255.255
  interface: em1
 if address: 203.0.113.1
   priority: 4 (connected)
  flags: 
BFD: async state up remote up
 use   mtuexpire
   83924 0   133 
sockaddrs: 

$ route -n get 203.0.113.9 -bfd
   route to: 203.0.113.9
destination: 203.0.113.9
   mask: 255.255.255.255
  interface: em1
 if address: 203.0.113.1
   priority: 4 (connected)
  flags: 
BFD: async state up remote up laststate down error 0
 diag none remote neighbor-down
 discr 186919089 remote 55
 uptime 05d 2h07m29s
 mintx 100 minrx 100 minecho 0 multiplier 3
 use   mtuexpire
   83923 0   229 
sockaddrs: 


Index: sbin/route/Makefile
===
RCS file: /cvs/openbsd/src/sbin/route/Makefile,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 Makefile
--- sbin/route/Makefile 19 Jul 2013 14:41:46 -  1.13
+++ sbin/route/Makefile 17 Dec 2016 12:47:35 -
@@ -4,7 +4,7 @@ PROG=   route
 MAN=   route.8
 SRCS=  route.c show.c
 
-CFLAGS+=   -Wall
+CFLAGS+=   -Wall -DBFD
 
 route.o .depend lint tags: keywords.h
 
Index: sbin/route/route.c
===
RCS file: /cvs/openbsd/src/sbin/route/route.c,v
retrieving revision 1.193
diff -u -p -u -p -r1.193 route.c
--- sbin/route/route.c  13 Dec 2016 08:40:54 -  1.193
+++ sbin/route/route.c  17 Dec 2016 12:47:35 -
@@ -100,6 +100,7 @@ const char *bfd_state(unsigned int);
 const char *bfd_diag(unsigned int);
 const char *bfd_calc_uptime(time_t);
 voidprint_bfdmsg(struct rt_msghdr *);
+voidprint_sabfd(struct sockaddr_bfd *, int);
 #endif
 const char *get_linkstate(int, int);
 voidprint_rtmsg(struct rt_msghdr *, int);
@@ -1443,6 +1444,9 @@ print_getmsg(struct rt_msghdr *rtm, int 
struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
struct sockaddr_dl *ifp = NULL;
struct sockaddr_rtlabel *sa_rl = NULL;
+#ifdef BFD
+   struct sockaddr_bfd *sa_bfd = NULL;
+#endif
struct sockaddr *mpls = NULL;
struct sockaddr *sa;
char *cp;
@@ -1491,6 +1495,11 @@ print_getmsg(struct rt_msghdr *rtm, int 
case RTA_LABEL:
sa_rl = (struct sockaddr_rtlabel *)sa;
break;
+#ifdef BFD
+   case RTA_BFD:
+   sa_bfd = (struct sockaddr_bfd *)sa;
+   break;
+#endif
}
ADVANCE(cp, sa);
}
@@ -1523,6 +1532,10 @@ print_getmsg(struct rt_msghdr *rtm, int 
printf("\n");
if (sa_rl != NULL)
printf("  label: %s\n", sa_rl->sr_label);
+#ifdef BFD
+   if (sa_bfd)
+   print_sabfd(sa_bfd, rtm->rtm_fmask);
+#endif
 
 #define lock(f)((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' 
')
relative_expire = rtm->rtm_rmx.rmx_expire ?
@@ -1625,12 +1638,21 @@ void
 print_bfdmsg(struct rt_msghdr *rtm)
 {
struct bfd_msghdr *bfdm = (struct bfd_msghdr *)rtm;
+
+   printf("\n");
+   print_sabfd(>bm_sa, rtm->rtm_fmask);
+   pmsg_addrs(((char *)rtm + rtm->rtm_hdrlen), rtm->rtm_addrs);
+}
+
+void
+print_sabfd(struct sockaddr_bfd *sa_bfd, int fmask)
+{
struct timeval tv;
 
gettimeofday(, NULL);
 
-   printf(" mode ");
-   switch (bfdm->bm_mode) {
+   printf("BFD: ");
+   switch (sa_bfd->bs_mode) {
case BFD_MODE_ASYNC:
printf("async");
break;
@@ -1638,27 +1660,36 @@ print_bfdmsg(struct rt_msghdr *rtm)
printf("demand");
break;
default:
-   printf("unknown %u", bfdm->bm_mode);
+   printf("unknown %u", sa_bfd->bs_mode);
break;
}
-   printf(" state %s", bfd_state(bfdm->bm_state));
-   printf(" remotestate %s", bfd_state(bfdm->bm_remotestate));
-   printf(" laststate %s", bfd_state(bfdm->bm_laststate));
-
-   printf(" error %d", bfdm->bm_error);
-   printf(" localdiscr %u", bfdm->bm_localdiscr);
-   printf(" remotediscr %u", bfdm->bm_remotediscr);
-   printf(" localdiag %s", bfd_diag(bfdm->bm_localdiag));

Re: BFD: route get and route monitor

2016-12-13 Thread Peter Hessler
On 2016 Dec 05 (Mon) at 15:39:31 +0100 (+0100), Peter Hessler wrote:
:On 2016 Sep 30 (Fri) at 10:16:19 +0200 (+0200), Peter Hessler wrote:
::This diff makes route get and route monitor work.  sockaddr_bfd is so we
::can play like the other RTAX_* indexes in rti_info of route messages.
::
::OK?
::
::
::$ route -n monitor
::got message of size 128 on Wed Sep 28 21:35:32 2016
::RTM_BFD: bidirectional forwarding detection: len 128
::BFD mode async state down remotestate down laststate admindown error 0
::localdiscr 4002401056 remotediscr 0 localdiag none remotediag none
::uptime 04m46s lastuptime 00s mintx 100 minrx 1 minecho 0 multiplier 3
::
::sockaddrs: 
:: 192.168.50.1 192.168.50.61
::
::$ route -n get 192.168.50.1
::   route to: 192.168.50.1
::destination: 192.168.50.1
::   mask: 255.255.255.255
::  interface: vio0
:: if address: 192.168.50.61
::   priority: 4 (connected)
::  flags: 
::BFD mode async state down remotestate down laststate admindown error 0
::localdiscr 4002401056 remotediscr 0 localdiag none remotediag none
::uptime 05m13s lastuptime 00s mintx 100 minrx 1 minecho 0 multiplier 3
:: use   mtuexpire
::   8 0   879 
::sockaddrs: 
::
:
:Here is a new diff, generated against -current.  No changes to the code.
:
:OK?
:

ping

:
:Index: sbin/route/Makefile
:===
:RCS file: /cvs/src/sbin/route/Makefile,v
:retrieving revision 1.13
:diff -u -p -u -p -r1.13 Makefile
:--- sbin/route/Makefile19 Jul 2013 14:41:46 -  1.13
:+++ sbin/route/Makefile5 Dec 2016 10:34:48 -
:@@ -4,7 +4,7 @@ PROG=  route
: MAN=  route.8
: SRCS= route.c show.c
: 
:-CFLAGS+=  -Wall
:+CFLAGS+=  -Wall -DBFD
: 
: route.o .depend lint tags: keywords.h
: 
:Index: sbin/route/route.c
:===
:RCS file: /cvs/src/sbin/route/route.c,v
:retrieving revision 1.192
:diff -u -p -u -p -r1.192 route.c
:--- sbin/route/route.c 24 Sep 2016 19:36:49 -  1.192
:+++ sbin/route/route.c 5 Dec 2016 10:34:48 -
:@@ -100,6 +100,7 @@ const char *bfd_state(unsigned int);
: const char *bfd_diag(unsigned int);
: const char *bfd_calc_uptime(time_t);
: void   print_bfdmsg(struct rt_msghdr *);
:+void   print_sabfd(struct sockaddr_bfd *);
: #endif
: const char *get_linkstate(int, int);
: void   print_rtmsg(struct rt_msghdr *, int);
:@@ -1439,6 +1440,9 @@ print_getmsg(struct rt_msghdr *rtm, int 
:   struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
:   struct sockaddr_dl *ifp = NULL;
:   struct sockaddr_rtlabel *sa_rl = NULL;
:+#ifdef BFD
:+  struct sockaddr_bfd *sa_bfd = NULL;
:+#endif
:   struct sockaddr *mpls = NULL;
:   struct sockaddr *sa;
:   char *cp;
:@@ -1487,6 +1491,11 @@ print_getmsg(struct rt_msghdr *rtm, int 
:   case RTA_LABEL:
:   sa_rl = (struct sockaddr_rtlabel *)sa;
:   break;
:+#ifdef BFD
:+  case RTA_BFD:
:+  sa_bfd = (struct sockaddr_bfd *)sa;
:+  break;
:+#endif
:   }
:   ADVANCE(cp, sa);
:   }
:@@ -1519,6 +1528,10 @@ print_getmsg(struct rt_msghdr *rtm, int 
:   printf("\n");
:   if (sa_rl != NULL)
:   printf("  label: %s\n", sa_rl->sr_label);
:+#ifdef BFD
:+  if (sa_bfd)
:+  print_sabfd(sa_bfd);
:+#endif
: 
: #define lock(f)   ((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' 
')
:   relative_expire = rtm->rtm_rmx.rmx_expire ?
:@@ -1621,12 +1634,21 @@ void
: print_bfdmsg(struct rt_msghdr *rtm)
: {
:   struct bfd_msghdr *bfdm = (struct bfd_msghdr *)rtm;
:+
:+  printf("\n");
:+  print_sabfd(>bm_sa);
:+  pmsg_addrs(((char *)rtm + rtm->rtm_hdrlen), rtm->rtm_addrs);
:+}
:+
:+void
:+print_sabfd(struct sockaddr_bfd *sa_bfd)
:+{
:   struct timeval tv;
: 
:   gettimeofday(, NULL);
: 
:-  printf(" mode ");
:-  switch (bfdm->bm_mode) {
:+  printf("BFD mode ");
:+  switch (sa_bfd->bs_mode) {
:   case BFD_MODE_ASYNC:
:   printf("async");
:   break;
:@@ -1634,27 +1656,26 @@ print_bfdmsg(struct rt_msghdr *rtm)
:   printf("demand");
:   break;
:   default:
:-  printf("unknown %u", bfdm->bm_mode);
:+  printf("unknown %u", sa_bfd->bs_mode);
:   break;
:   }
:-  printf(" state %s", bfd_state(bfdm->bm_state));
:-  printf(" remotestate %s", bfd_state(bfdm->bm_remotestate));
:-  printf(" laststate %s", bfd_state(bfdm->bm_laststate));
:-
:-  printf(" error %d", bfdm->bm_error);
:-  printf(" localdiscr %u", 

Re: BFD: route get and route monitor

2016-12-05 Thread Peter Hessler
On 2016 Sep 30 (Fri) at 10:16:19 +0200 (+0200), Peter Hessler wrote:
:This diff makes route get and route monitor work.  sockaddr_bfd is so we
:can play like the other RTAX_* indexes in rti_info of route messages.
:
:OK?
:
:
:$ route -n monitor
:got message of size 128 on Wed Sep 28 21:35:32 2016
:RTM_BFD: bidirectional forwarding detection: len 128
:BFD mode async state down remotestate down laststate admindown error 0
:localdiscr 4002401056 remotediscr 0 localdiag none remotediag none
:uptime 04m46s lastuptime 00s mintx 100 minrx 1 minecho 0 multiplier 3
:
:sockaddrs: 
: 192.168.50.1 192.168.50.61
:
:$ route -n get 192.168.50.1
:   route to: 192.168.50.1
:destination: 192.168.50.1
:   mask: 255.255.255.255
:  interface: vio0
: if address: 192.168.50.61
:   priority: 4 (connected)
:  flags: 
:BFD mode async state down remotestate down laststate admindown error 0
:localdiscr 4002401056 remotediscr 0 localdiag none remotediag none
:uptime 05m13s lastuptime 00s mintx 100 minrx 1 minecho 0 multiplier 3
: use   mtuexpire
:   8 0   879 
:sockaddrs: 
:

Here is a new diff, generated against -current.  No changes to the code.

OK?


Index: sbin/route/Makefile
===
RCS file: /cvs/src/sbin/route/Makefile,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 Makefile
--- sbin/route/Makefile 19 Jul 2013 14:41:46 -  1.13
+++ sbin/route/Makefile 5 Dec 2016 10:34:48 -
@@ -4,7 +4,7 @@ PROG=   route
 MAN=   route.8
 SRCS=  route.c show.c
 
-CFLAGS+=   -Wall
+CFLAGS+=   -Wall -DBFD
 
 route.o .depend lint tags: keywords.h
 
Index: sbin/route/route.c
===
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.192
diff -u -p -u -p -r1.192 route.c
--- sbin/route/route.c  24 Sep 2016 19:36:49 -  1.192
+++ sbin/route/route.c  5 Dec 2016 10:34:48 -
@@ -100,6 +100,7 @@ const char *bfd_state(unsigned int);
 const char *bfd_diag(unsigned int);
 const char *bfd_calc_uptime(time_t);
 voidprint_bfdmsg(struct rt_msghdr *);
+voidprint_sabfd(struct sockaddr_bfd *);
 #endif
 const char *get_linkstate(int, int);
 voidprint_rtmsg(struct rt_msghdr *, int);
@@ -1439,6 +1440,9 @@ print_getmsg(struct rt_msghdr *rtm, int 
struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
struct sockaddr_dl *ifp = NULL;
struct sockaddr_rtlabel *sa_rl = NULL;
+#ifdef BFD
+   struct sockaddr_bfd *sa_bfd = NULL;
+#endif
struct sockaddr *mpls = NULL;
struct sockaddr *sa;
char *cp;
@@ -1487,6 +1491,11 @@ print_getmsg(struct rt_msghdr *rtm, int 
case RTA_LABEL:
sa_rl = (struct sockaddr_rtlabel *)sa;
break;
+#ifdef BFD
+   case RTA_BFD:
+   sa_bfd = (struct sockaddr_bfd *)sa;
+   break;
+#endif
}
ADVANCE(cp, sa);
}
@@ -1519,6 +1528,10 @@ print_getmsg(struct rt_msghdr *rtm, int 
printf("\n");
if (sa_rl != NULL)
printf("  label: %s\n", sa_rl->sr_label);
+#ifdef BFD
+   if (sa_bfd)
+   print_sabfd(sa_bfd);
+#endif
 
 #define lock(f)((rtm->rtm_rmx.rmx_locks & __CONCAT(RTV_,f)) ? 'L' : ' 
')
relative_expire = rtm->rtm_rmx.rmx_expire ?
@@ -1621,12 +1634,21 @@ void
 print_bfdmsg(struct rt_msghdr *rtm)
 {
struct bfd_msghdr *bfdm = (struct bfd_msghdr *)rtm;
+
+   printf("\n");
+   print_sabfd(>bm_sa);
+   pmsg_addrs(((char *)rtm + rtm->rtm_hdrlen), rtm->rtm_addrs);
+}
+
+void
+print_sabfd(struct sockaddr_bfd *sa_bfd)
+{
struct timeval tv;
 
gettimeofday(, NULL);
 
-   printf(" mode ");
-   switch (bfdm->bm_mode) {
+   printf("BFD mode ");
+   switch (sa_bfd->bs_mode) {
case BFD_MODE_ASYNC:
printf("async");
break;
@@ -1634,27 +1656,26 @@ print_bfdmsg(struct rt_msghdr *rtm)
printf("demand");
break;
default:
-   printf("unknown %u", bfdm->bm_mode);
+   printf("unknown %u", sa_bfd->bs_mode);
break;
}
-   printf(" state %s", bfd_state(bfdm->bm_state));
-   printf(" remotestate %s", bfd_state(bfdm->bm_remotestate));
-   printf(" laststate %s", bfd_state(bfdm->bm_laststate));
-
-   printf(" error %d", bfdm->bm_error);
-   printf(" localdiscr %u", bfdm->bm_localdiscr);
-   printf(" remotediscr %u", bfdm->bm_remotediscr);
-   printf(" localdiag %s", bfd_diag(bfdm->bm_localdiag));
-   printf(" remotediag %s",