]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_msdp.h
pimd: Get show run to display vrf sub mode
[mirror_frr.git] / pimd / pim_msdp.h
1 /*
2 * IP MSDP for Quagga
3 * Copyright (C) 2016 Cumulus Networks, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #ifndef PIM_MSDP_H
20 #define PIM_MSDP_H
21
22 enum pim_msdp_peer_state {
23 PIM_MSDP_DISABLED,
24 PIM_MSDP_INACTIVE,
25 PIM_MSDP_LISTEN,
26 PIM_MSDP_CONNECTING,
27 PIM_MSDP_ESTABLISHED
28 };
29
30 /* SA and KA TLVs are processed; rest ignored */
31 enum pim_msdp_tlv {
32 PIM_MSDP_V4_SOURCE_ACTIVE = 1,
33 PIM_MSDP_V4_SOURCE_ACTIVE_REQUEST,
34 PIM_MSDP_V4_SOURCE_ACTIVE_RESPONSE,
35 PIM_MSDP_KEEPALIVE,
36 PIM_MSDP_RESERVED,
37 PIM_MSDP_TRACEROUTE_PROGRESS,
38 PIM_MSDP_TRACEROUTE_REPLY,
39 };
40
41 /* MSDP error codes */
42 enum pim_msdp_err {
43 PIM_MSDP_ERR_NONE = 0,
44 PIM_MSDP_ERR_OOM = -1,
45 PIM_MSDP_ERR_PEER_EXISTS = -2,
46 PIM_MSDP_ERR_MAX_MESH_GROUPS = -3,
47 PIM_MSDP_ERR_NO_PEER = -4,
48 PIM_MSDP_ERR_MG_MBR_EXISTS = -5,
49 PIM_MSDP_ERR_NO_MG = -6,
50 PIM_MSDP_ERR_NO_MG_MBR = -7,
51 PIM_MSDP_ERR_SIP_EQ_DIP = -8,
52 };
53
54 #define PIM_MSDP_STATE_STRLEN 16
55 #define PIM_MSDP_UPTIME_STRLEN 80
56 #define PIM_MSDP_TIMER_STRLEN 12
57 #define PIM_MSDP_TCP_PORT 639
58 #define PIM_MSDP_SOCKET_SNDBUF_SIZE 65536
59
60 enum pim_msdp_sa_flags {
61 PIM_MSDP_SAF_NONE = 0,
62 /* There are two cases where we can pickup an active source locally -
63 * 1. We are RP and got a source-register from the FHR
64 * 2. We are RP and FHR and learnt a new directly connected source on a
65 * DR interface */
66 PIM_MSDP_SAF_LOCAL = (1 << 0),
67 /* We got this in the MSDP SA TLV from a peer (and this passed peer-RPF
68 * checks) */
69 PIM_MSDP_SAF_PEER = (1 << 1),
70 PIM_MSDP_SAF_REF = (PIM_MSDP_SAF_LOCAL | PIM_MSDP_SAF_PEER),
71 PIM_MSDP_SAF_STALE = (1 << 2), /* local entries can get kicked out on
72 * misc pim events such as RP change */
73 PIM_MSDP_SAF_UP_DEL_IN_PROG = (1 << 3)
74 };
75
76 struct pim_msdp_sa {
77 struct pim_instance *pim;
78
79 struct prefix_sg sg;
80 char sg_str[PIM_SG_LEN];
81 struct in_addr rp; /* Last RP address associated with this SA */
82 struct in_addr peer; /* last peer from who we heard this SA */
83 enum pim_msdp_sa_flags flags;
84
85 /* rfc-3618 is missing default value for SA-hold-down-Period. pulled
86 * this number from industry-standards */
87 #define PIM_MSDP_SA_HOLD_TIME ((3*60)+30)
88 struct thread *sa_state_timer; // 5.6
89 int64_t uptime;
90
91 struct pim_upstream *up;
92 };
93
94 enum pim_msdp_peer_flags {
95 PIM_MSDP_PEERF_NONE = 0,
96 PIM_MSDP_PEERF_LISTENER = (1 << 0),
97 #define PIM_MSDP_PEER_IS_LISTENER(mp) (mp->flags & PIM_MSDP_PEERF_LISTENER)
98 PIM_MSDP_PEERF_SA_JUST_SENT = (1 << 1)
99 };
100
101 struct pim_msdp_peer {
102 struct pim_instance *pim;
103
104 /* configuration */
105 struct in_addr local;
106 struct in_addr peer;
107 char *mesh_group_name;
108 char key_str[INET_ADDRSTRLEN];
109
110 /* state */
111 enum pim_msdp_peer_state state;
112 enum pim_msdp_peer_flags flags;
113
114 /* TCP socket info */
115 union sockunion su_local;
116 union sockunion su_peer;
117 int fd;
118
119 /* protocol timers */
120 #define PIM_MSDP_PEER_HOLD_TIME 75
121 struct thread *hold_timer; // 5.4
122 /* $FRR indent$ */
123 /* clang-format off */
124 #define PIM_MSDP_PEER_KA_TIME 60
125 struct thread *ka_timer; // 5.5
126 /* $FRR indent$ */
127 /* clang-format off */
128 #define PIM_MSDP_PEER_CONNECT_RETRY_TIME 30
129 struct thread *cr_timer; // 5.6
130
131 /* packet thread and buffers */
132 uint32_t packet_size;
133 struct stream *ibuf;
134 struct stream_fifo *obuf;
135 struct thread *t_read;
136 struct thread *t_write;
137
138 /* stats */
139 uint32_t conn_attempts;
140 uint32_t est_flaps;
141 uint32_t sa_cnt; /* number of SAs attributed to this peer */
142 /* $FRR indent$ */
143 /* clang-format off */
144 #define PIM_MSDP_PEER_LAST_RESET_STR 20
145 char last_reset[PIM_MSDP_PEER_LAST_RESET_STR];
146
147 /* packet stats */
148 uint32_t ka_tx_cnt;
149 uint32_t sa_tx_cnt;
150 uint32_t ka_rx_cnt;
151 uint32_t sa_rx_cnt;
152 uint32_t unk_rx_cnt;
153
154 /* timestamps */
155 int64_t uptime;
156 };
157
158 struct pim_msdp_mg_mbr {
159 struct in_addr mbr_ip;
160 struct pim_msdp_peer *mp;
161 };
162
163 /* PIM MSDP mesh-group */
164 struct pim_msdp_mg {
165 char *mesh_group_name;
166 struct in_addr src_ip;
167 uint32_t mbr_cnt;
168 struct list *mbr_list;
169 };
170
171 enum pim_msdp_flags {
172 PIM_MSDPF_NONE = 0,
173 PIM_MSDPF_ENABLE = (1 << 0),
174 PIM_MSDPF_LISTENER = (1 << 1)
175 };
176
177 struct pim_msdp_listener {
178 int fd;
179 union sockunion su;
180 struct thread *thread;
181 };
182
183 struct pim_msdp {
184 enum pim_msdp_flags flags;
185 struct thread_master *master;
186 struct pim_msdp_listener listener;
187 uint32_t rejected_accepts;
188
189 /* MSDP peer info */
190 struct hash *peer_hash;
191 struct list *peer_list;
192
193 /* MSDP active-source info */
194 #define PIM_MSDP_SA_ADVERTISMENT_TIME 60
195 struct thread *sa_adv_timer; // 5.6
196 struct hash *sa_hash;
197 struct list *sa_list;
198 uint32_t local_cnt;
199
200 /* keep a scratch pad for building SA TLVs */
201 struct stream *work_obuf;
202
203 struct in_addr originator_id;
204
205 /* currently only one mesh-group is supported - so just stash it here */
206 struct pim_msdp_mg *mg;
207 };
208
209 #define PIM_MSDP_PEER_READ_ON(mp) \
210 thread_add_read(mp->pim->msdp.master, pim_msdp_read, mp, mp->fd, \
211 &mp->t_read)
212
213 #define PIM_MSDP_PEER_WRITE_ON(mp) \
214 thread_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \
215 &mp->t_write)
216
217 #define PIM_MSDP_PEER_READ_OFF(mp) THREAD_READ_OFF(mp->t_read)
218 #define PIM_MSDP_PEER_WRITE_OFF(mp) THREAD_WRITE_OFF(mp->t_write)
219
220 // struct pim_msdp *msdp;
221 struct pim_instance;
222 void pim_msdp_init(struct thread_master *master, struct pim_instance *pim);
223 void pim_msdp_exit(struct pim_instance *pim);
224 enum pim_msdp_err pim_msdp_peer_add(struct pim_instance *pim,
225 struct in_addr peer, struct in_addr local,
226 const char *mesh_group_name,
227 struct pim_msdp_peer **mp_p);
228 enum pim_msdp_err pim_msdp_peer_del(struct pim_instance *pim,
229 struct in_addr peer_addr);
230 char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
231 int buf_size);
232 struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
233 struct in_addr peer_addr);
234 void pim_msdp_peer_established(struct pim_msdp_peer *mp);
235 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp);
236 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state);
237 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str);
238 int pim_msdp_write(struct thread *thread);
239 char *pim_msdp_peer_key_dump(struct pim_msdp_peer *mp, char *buf, int buf_size,
240 bool long_format);
241 int pim_msdp_config_write(struct vty *vty);
242 int pim_msdp_config_write_helper(struct pim_instance *pim, struct vty *vty);
243 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer *mp);
244 void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
245 struct prefix_sg *sg, struct in_addr rp);
246 void pim_msdp_sa_local_update(struct pim_upstream *up);
247 void pim_msdp_sa_local_del(struct pim_instance *pim, struct prefix_sg *sg);
248 void pim_msdp_i_am_rp_changed(struct pim_instance *pim);
249 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp);
250 void pim_msdp_up_join_state_changed(struct pim_upstream *xg_up);
251 void pim_msdp_up_del(struct pim_instance *pim, struct prefix_sg *sg);
252 enum pim_msdp_err pim_msdp_mg_mbr_add(struct pim_instance *pim,
253 const char *mesh_group_name,
254 struct in_addr mbr_ip);
255 enum pim_msdp_err pim_msdp_mg_mbr_del(struct pim_instance *pim,
256 const char *mesh_group_name,
257 struct in_addr mbr_ip);
258 enum pim_msdp_err pim_msdp_mg_src_del(struct pim_instance *pim,
259 const char *mesh_group_name);
260 enum pim_msdp_err pim_msdp_mg_src_add(struct pim_instance *pim,
261 const char *mesh_group_name,
262 struct in_addr src_ip);
263 enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim,
264 const char *mesh_group_name);
265 #endif