xref: /openbsd-src/sys/net/bfd.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: bfd.h,v 1.9 2016/09/20 10:41:43 phessler Exp $	*/
2 
3 /*
4  * Copyright (c) 2016 Peter Hessler <phessler@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * Support for Bi-directional Forwarding Detection (RFC 5880 / 5881)
21  */
22 
23 #ifndef _NET_BFD_H_
24 #define _NET_BFD_H_
25 
26 /* Public Interface */
27 
28 #define BFD_MODE_ASYNC			1
29 #define BFD_MODE_DEMAND			2
30 
31 /* Diagnostic Code (RFC 5880 Page 8) */
32 #define BFD_DIAG_NONE			0
33 #define BFD_DIAG_EXPIRED		1
34 #define BFD_DIAG_ECHO_FAILED		2
35 #define BFD_DIAG_NEIGHBOR_SIGDOWN	3
36 #define BFD_DIAG_FIB_RESET		4
37 #define BFD_DIAG_PATH_DOWN		5
38 #define BFD_DIAG_CONCAT_PATH_DOWN	6
39 #define BFD_DIAG_ADMIN_DOWN		7
40 #define BFD_DIAG_CONCAT_REVERSE_DOWN	8
41 
42 /* State (RFC 5880 Page 8) */
43 #define BFD_STATE_ADMINDOWN		0
44 #define BFD_STATE_DOWN			1
45 #define BFD_STATE_INIT			2
46 #define BFD_STATE_UP			3
47 
48 /* Flags (RFC 5880 Page 8) */
49 #define BFD_FLAG_P			0x20
50 #define BFD_FLAG_F			0x10
51 #define BFD_FLAG_C			0x08
52 #define BFD_FLAG_A			0x04
53 #define BFD_FLAG_D			0x02
54 #define BFD_FLAG_M			0x01
55 
56 struct bfd_msghdr {
57 	unsigned short	bm_msglen;
58 	unsigned char	bm_version;
59 	unsigned char	bm_type;
60 	unsigned short	bm_hdrlen;
61 	int		bm_addrs;
62 	/* above matches rtm_msghdr */
63 
64 	uint16_t	bm_mode;
65 	uint32_t	bm_mintx;
66 	uint32_t	bm_minrx;
67 	uint32_t	bm_minecho;
68 	uint16_t	bm_multiplier;
69 
70 	time_t		bm_uptime;
71 	time_t		bm_lastuptime;
72 	int		bm_state;
73 	int		bm_remotestate;
74 	int		bm_laststate;
75 	int		bm_error;
76 
77 	uint32_t	bm_localdiscr;
78 	uint32_t	bm_localdiag;
79 	uint32_t	bm_remotediscr;
80 	uint32_t	bm_remotediag;
81 };
82 
83 #ifdef _KERNEL
84 /* state machine from RFC 5880 6.8.1*/
85 struct bfd_neighbor {
86 	uint32_t	bn_lstate;		/* SessionState */
87 	uint32_t	bn_rstate;		/* RemoteSessionState */
88 	uint32_t	bn_ldiscr;		/* LocalDiscr */
89 	uint32_t	bn_rdiscr;		/* RemoteDiscr */
90 	uint32_t	bn_ldiag;		/* LocalDiag */
91 	uint32_t	bn_rdiag;		/* RemoteDiag */
92 	uint32_t	bn_mintx;		/* DesiredMinTxInterval */
93 	uint32_t	bn_req_minrx;		/* RequiredMinRxInterval */
94 	uint32_t	bn_rminrx;		/* RemoteMinRxInterval */
95 	uint32_t	bn_demand;		/* DemandMode */
96 	uint32_t	bn_rdemand;		/* RemoteDemandMode */
97 	uint32_t	bn_mult;		/* DetectMult */
98 	uint32_t	bn_authtype;		/* AuthType */
99 	uint32_t	bn_rauthseq;		/* RcvAuthSeq */
100 	uint32_t	bn_lauthseq;		/* XmitAuthSeq */
101 	uint32_t	bn_authseqknown;	/* AuthSeqKnown */
102 };
103 
104 struct bfd_config {
105 	TAILQ_ENTRY(bfd_config)	 bc_entry;
106 	struct socket		*bc_so;
107 	struct socket		*bc_soecho;
108 	struct socket		*bc_sosend;
109 	struct rtentry		*bc_rt;
110 	struct bfd_neighbor	*bc_neighbor;
111 	struct timeval		*bc_time;
112 	struct task		 bc_bfd_task;
113 	struct task		 bc_bfd_send_task;
114 	struct timeout		 bc_timo_rx;
115 	struct timeout		 bc_timo_tx;
116 	time_t			 bc_lastuptime;
117 	int			 bc_laststate;
118 	int			 bc_state;
119 	int			 bc_mode;
120 	int			 bc_poll;
121 	int			 bc_error;
122 	int			 bc_minrx;
123 	int			 bc_mintx;
124 	int			 bc_minecho;
125 	int			 bc_multiplier;
126 };
127 
128 int		 bfdset(struct rtentry *);
129 void		 bfdclear(struct rtentry *);
130 void		 bfdinit(void);
131 
132 #endif /* _KERNEL */
133 
134 #endif /* _NET_BFD_H_ */
135