summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPeter Hessler <phessler@cvs.openbsd.org>2017-01-19 23:18:30 +0000
committerPeter Hessler <phessler@cvs.openbsd.org>2017-01-19 23:18:30 +0000
commita946d7032236cadd7387a4bbdf7b0d1df6bd5a0f (patch)
tree8b5e7c22a54449628d8c2e28d3a3d31875e90ff4 /sys
parent1309bbf159e50db75ae5f992927c9bedaee6bd59 (diff)
add hooks so we can query the current state of a BFD session
bfd session details are visible with "route -n get 192.0.2.1 -bfd" OK mpi@ deraadt@ claudio@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/bfd.c37
-rw-r--r--sys/net/bfd.h74
-rw-r--r--sys/net/route.h6
-rw-r--r--sys/net/rtsock.c39
4 files changed, 110 insertions, 46 deletions
diff --git a/sys/net/bfd.c b/sys/net/bfd.c
index 3cdca323133..3438c12a97b 100644
--- a/sys/net/bfd.c
+++ b/sys/net/bfd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bfd.c,v 1.46 2017/01/19 10:19:39 phessler Exp $ */
+/* $OpenBSD: bfd.c,v 1.47 2017/01/19 23:18:29 phessler Exp $ */
/*
* Copyright (c) 2016 Peter Hessler <phessler@openbsd.org>
@@ -312,6 +312,41 @@ bfd_lookup(struct rtentry *rt)
return (NULL);
}
+struct sockaddr *
+bfd2sa(struct rtentry *rt, struct sockaddr_bfd *sa_bfd)
+{
+ struct bfd_config *bfd;
+
+ bfd = bfd_lookup(rt);
+
+ if (bfd == NULL)
+ return (NULL);
+
+ memset(sa_bfd, 0, sizeof(*sa_bfd));
+ sa_bfd->bs_len = sizeof(*sa_bfd);
+ sa_bfd->bs_family = bfd->bc_rt->rt_dest->sa_family;
+
+ sa_bfd->bs_mode = bfd->bc_mode;
+ sa_bfd->bs_mintx = bfd->bc_mintx;
+ sa_bfd->bs_minrx = bfd->bc_minrx;
+ sa_bfd->bs_minecho = bfd->bc_minecho;
+ sa_bfd->bs_multiplier = bfd->bc_multiplier;
+
+ sa_bfd->bs_uptime = bfd->bc_time->tv_sec;
+ sa_bfd->bs_lastuptime = bfd->bc_lastuptime;
+ sa_bfd->bs_state = bfd->bc_state;
+ sa_bfd->bs_remotestate = bfd->bc_neighbor->bn_rstate;
+ sa_bfd->bs_laststate = bfd->bc_laststate;
+ sa_bfd->bs_error = bfd->bc_error;
+
+ sa_bfd->bs_localdiscr = bfd->bc_neighbor->bn_ldiscr;
+ sa_bfd->bs_localdiag = bfd->bc_neighbor->bn_ldiag;
+ sa_bfd->bs_remotediscr = bfd->bc_neighbor->bn_rdiscr;
+ sa_bfd->bs_remotediag = bfd->bc_neighbor->bn_rdiag;
+
+ return ((struct sockaddr *)sa_bfd);
+}
+
/*
* End of public interfaces.
*
diff --git a/sys/net/bfd.h b/sys/net/bfd.h
index eb196671b08..ea7bfeb0bda 100644
--- a/sys/net/bfd.h
+++ b/sys/net/bfd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bfd.h,v 1.9 2016/09/20 10:41:43 phessler Exp $ */
+/* $OpenBSD: bfd.h,v 1.10 2017/01/19 23:18:29 phessler Exp $ */
/*
* Copyright (c) 2016 Peter Hessler <phessler@openbsd.org>
@@ -53,31 +53,55 @@
#define BFD_FLAG_D 0x02
#define BFD_FLAG_M 0x01
+struct sockaddr_bfd {
+ uint8_t bs_len; /* total length */
+ uint8_t bs_family; /* address family */
+ /* above matches sockaddr_storage */
+
+ /* Sorted for bit boundaries */
+ uint16_t bs_mode;
+ uint32_t bs_localdiscr;
+
+ int64_t bs_uptime;
+
+ int64_t bs_lastuptime;
+
+ uint32_t bs_mintx;
+ uint32_t bs_minrx;
+
+ uint32_t bs_minecho;
+ uint32_t bs_localdiag;
+
+ uint32_t bs_remotediscr;
+ uint32_t bs_remotediag;
+
+ uint16_t bs_multiplier;
+ uint16_t bs_pad0;
+ int bs_state;
+ int bs_remotestate;
+ int bs_laststate;
+ int bs_error;
+
+ /* add padding to reach a power of two */
+ uint64_t bs_pad1;
+};
+
struct bfd_msghdr {
- unsigned short bm_msglen;
- unsigned char bm_version;
- unsigned char bm_type;
- unsigned short bm_hdrlen;
+ uint16_t bm_msglen;
+ uint8_t bm_version;
+ uint8_t bm_type;
+ uint16_t bm_hdrlen;
+ uint16_t bm_index;
+
+ uint16_t bm_tableid;
+ uint8_t bm_priority;
+ uint8_t bm_mpls;
int bm_addrs;
- /* above matches rtm_msghdr */
-
- uint16_t bm_mode;
- uint32_t bm_mintx;
- uint32_t bm_minrx;
- uint32_t bm_minecho;
- uint16_t bm_multiplier;
-
- time_t bm_uptime;
- time_t bm_lastuptime;
- int bm_state;
- int bm_remotestate;
- int bm_laststate;
- int bm_error;
-
- uint32_t bm_localdiscr;
- uint32_t bm_localdiag;
- uint32_t bm_remotediscr;
- uint32_t bm_remotediag;
+ int bm_flags;
+ /* above matches rt_msghdr */
+ uint16_t bm_pad0; /* for 4 byte boundary */
+
+ struct sockaddr_bfd bm_sa; /* bfd msg for userland */
};
#ifdef _KERNEL
@@ -125,6 +149,8 @@ struct bfd_config {
int bc_multiplier;
};
+struct sockaddr *bfd2sa(struct rtentry *, struct sockaddr_bfd *);
+
int bfdset(struct rtentry *);
void bfdclear(struct rtentry *);
void bfdinit(void);
diff --git a/sys/net/route.h b/sys/net/route.h
index 43a6aefdcd1..660a91e465a 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.h,v 1.150 2017/01/19 02:55:18 phessler Exp $ */
+/* $OpenBSD: route.h,v 1.151 2017/01/19 23:18:29 phessler Exp $ */
/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
/*
@@ -259,6 +259,7 @@ struct rt_msghdr {
#define RTA_SRC 0x100 /* source sockaddr present */
#define RTA_SRCMASK 0x200 /* source netmask present */
#define RTA_LABEL 0x400 /* route label present */
+#define RTA_BFD 0x800 /* bfd present */
/*
* Index offsets for sockaddr array for alternate internal encoding.
@@ -274,7 +275,8 @@ struct rt_msghdr {
#define RTAX_SRC 8 /* source sockaddr present */
#define RTAX_SRCMASK 9 /* source netmask present */
#define RTAX_LABEL 10 /* route label present */
-#define RTAX_MAX 11 /* size of array to allocate */
+#define RTAX_BFD 11 /* bfd present */
+#define RTAX_MAX 12 /* size of array to allocate */
/*
* setsockopt defines used for the filtering.
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index d56a8f5cbea..7e6c0132bea 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.212 2016/12/20 18:33:43 bluhm Exp $ */
+/* $OpenBSD: rtsock.c,v 1.213 2017/01/19 23:18:29 phessler Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -472,6 +472,9 @@ route_output(struct mbuf *m, ...)
struct rawcb *rp = NULL;
struct sockaddr_rtlabel sa_rl;
struct sockaddr_in6 sa_mask;
+#ifdef BFD
+ struct sockaddr_bfd sa_bfd;
+#endif
#ifdef MPLS
struct sockaddr_mpls sa_mpls, *psa_mpls;
#endif
@@ -705,6 +708,10 @@ report:
rt_plen2mask(rt, &sa_mask);
info.rti_info[RTAX_LABEL] =
rtlabel_id2sa(rt->rt_labelid, &sa_rl);
+#ifdef BFD
+ if (rt->rt_flags & RTF_BFD)
+ info.rti_info[RTAX_BFD] = bfd2sa(rt, &sa_bfd);
+#endif
#ifdef MPLS
if (rt->rt_flags & RTF_MPLS) {
bzero(&sa_mpls, sizeof(sa_mpls));
@@ -1355,6 +1362,7 @@ void
rt_bfdmsg(struct bfd_config *bfd)
{
struct bfd_msghdr *bfdm;
+ struct sockaddr_bfd sa_bfd;
struct mbuf *m;
struct rt_addrinfo info;
@@ -1368,26 +1376,12 @@ rt_bfdmsg(struct bfd_config *bfd)
if (m == NULL)
return;
bfdm = mtod(m, struct bfd_msghdr *);
+ bfdm->bm_addrs = info.rti_addrs;
- bfdm->bm_mode = bfd->bc_mode;
- bfdm->bm_mintx = bfd->bc_mintx;
- bfdm->bm_minrx = bfd->bc_minrx;
- bfdm->bm_minecho = bfd->bc_minecho;
- bfdm->bm_multiplier = bfd->bc_multiplier;
-
- bfdm->bm_uptime = bfd->bc_time->tv_sec;
- bfdm->bm_lastuptime = bfd->bc_lastuptime;
- bfdm->bm_state = bfd->bc_state;
- bfdm->bm_remotestate = bfd->bc_neighbor->bn_rstate;
- bfdm->bm_laststate = bfd->bc_laststate;
- bfdm->bm_error = bfd->bc_error;
-
- bfdm->bm_localdiscr = bfd->bc_neighbor->bn_ldiscr;
- bfdm->bm_localdiag = bfd->bc_neighbor->bn_ldiag;
- bfdm->bm_remotediscr = bfd->bc_neighbor->bn_rdiscr;
- bfdm->bm_remotediag = bfd->bc_neighbor->bn_rdiag;
+ bfd2sa(bfd->bc_rt, &sa_bfd);
+ memcpy(&bfdm->bm_sa, &sa_bfd, sizeof(sa_bfd));
- route_proto.sp_protocol = 0;
+ route_proto.sp_protocol = info.rti_info[RTAX_DST]->sa_family;
route_input(m, &route_proto, &route_src, &route_dst);
}
#endif /* BFD */
@@ -1402,6 +1396,9 @@ sysctl_dumpentry(struct rtentry *rt, void *v, unsigned int id)
int error = 0, size;
struct rt_addrinfo info;
struct ifnet *ifp;
+#ifdef BFD
+ struct sockaddr_bfd sa_bfd;
+#endif
#ifdef MPLS
struct sockaddr_mpls sa_mpls;
#endif
@@ -1436,6 +1433,10 @@ sysctl_dumpentry(struct rtentry *rt, void *v, unsigned int id)
}
if_put(ifp);
info.rti_info[RTAX_LABEL] = rtlabel_id2sa(rt->rt_labelid, &sa_rl);
+#ifdef BFD
+ if (rt->rt_flags & RTF_BFD)
+ info.rti_info[RTAX_BFD] = bfd2sa(rt, &sa_bfd);
+#endif
#ifdef MPLS
if (rt->rt_flags & RTF_MPLS) {
bzero(&sa_mpls, sizeof(sa_mpls));