]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_msdp.h
Merge pull request #10770 from chiragshah6/evpn_dev3
[mirror_frr.git] / pimd / pim_msdp.h
CommitLineData
11128587 1/*
2a333e0f 2 * IP MSDP for Quagga
11128587 3 * Copyright (C) 2016 Cumulus Networks, Inc.
11128587
DS
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 *
896014f4
DL
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
11128587
DS
18 */
19#ifndef PIM_MSDP_H
20#define PIM_MSDP_H
21
e2809e61
RZ
22#include "lib/openbsd-queue.h"
23
2a333e0f 24enum pim_msdp_peer_state {
d62a17ae 25 PIM_MSDP_DISABLED,
26 PIM_MSDP_INACTIVE,
27 PIM_MSDP_LISTEN,
28 PIM_MSDP_CONNECTING,
29 PIM_MSDP_ESTABLISHED
2a333e0f 30};
11128587 31
2a333e0f 32/* SA and KA TLVs are processed; rest ignored */
33enum pim_msdp_tlv {
d62a17ae 34 PIM_MSDP_V4_SOURCE_ACTIVE = 1,
35 PIM_MSDP_V4_SOURCE_ACTIVE_REQUEST,
36 PIM_MSDP_V4_SOURCE_ACTIVE_RESPONSE,
37 PIM_MSDP_KEEPALIVE,
38 PIM_MSDP_RESERVED,
39 PIM_MSDP_TRACEROUTE_PROGRESS,
40 PIM_MSDP_TRACEROUTE_REPLY,
2a333e0f 41};
42
43/* MSDP error codes */
44enum pim_msdp_err {
d62a17ae 45 PIM_MSDP_ERR_NONE = 0,
46 PIM_MSDP_ERR_OOM = -1,
47 PIM_MSDP_ERR_PEER_EXISTS = -2,
48 PIM_MSDP_ERR_MAX_MESH_GROUPS = -3,
49 PIM_MSDP_ERR_NO_PEER = -4,
50 PIM_MSDP_ERR_MG_MBR_EXISTS = -5,
51 PIM_MSDP_ERR_NO_MG = -6,
52 PIM_MSDP_ERR_NO_MG_MBR = -7,
53 PIM_MSDP_ERR_SIP_EQ_DIP = -8,
2a333e0f 54};
55
56#define PIM_MSDP_STATE_STRLEN 16
2a333e0f 57#define PIM_MSDP_UPTIME_STRLEN 80
977d71cc 58#define PIM_MSDP_TIMER_STRLEN 12
2a333e0f 59#define PIM_MSDP_TCP_PORT 639
60#define PIM_MSDP_SOCKET_SNDBUF_SIZE 65536
61
3c72d654 62enum pim_msdp_sa_flags {
d62a17ae 63 PIM_MSDP_SAF_NONE = 0,
64 /* There are two cases where we can pickup an active source locally -
65 * 1. We are RP and got a source-register from the FHR
66 * 2. We are RP and FHR and learnt a new directly connected source on a
67 * DR interface */
68 PIM_MSDP_SAF_LOCAL = (1 << 0),
69 /* We got this in the MSDP SA TLV from a peer (and this passed peer-RPF
70 * checks) */
71 PIM_MSDP_SAF_PEER = (1 << 1),
72 PIM_MSDP_SAF_REF = (PIM_MSDP_SAF_LOCAL | PIM_MSDP_SAF_PEER),
73 PIM_MSDP_SAF_STALE = (1 << 2), /* local entries can get kicked out on
2ad78035 74 * misc pim events such as RP change */
d62a17ae 75 PIM_MSDP_SAF_UP_DEL_IN_PROG = (1 << 3)
3c72d654 76};
77
78struct pim_msdp_sa {
472ad383
DS
79 struct pim_instance *pim;
80
6fff2cc6 81 pim_sgaddr sg;
d62a17ae 82 char sg_str[PIM_SG_LEN];
83 struct in_addr rp; /* Last RP address associated with this SA */
84 struct in_addr peer; /* last peer from who we heard this SA */
85 enum pim_msdp_sa_flags flags;
86
87/* rfc-3618 is missing default value for SA-hold-down-Period. pulled
88 * this number from industry-standards */
3c72d654 89#define PIM_MSDP_SA_HOLD_TIME ((3*60)+30)
d62a17ae 90 struct thread *sa_state_timer; // 5.6
91 int64_t uptime;
7667c556 92
d62a17ae 93 struct pim_upstream *up;
3c72d654 94};
95
2a333e0f 96enum pim_msdp_peer_flags {
d62a17ae 97 PIM_MSDP_PEERF_NONE = 0,
98 PIM_MSDP_PEERF_LISTENER = (1 << 0),
3c72d654 99#define PIM_MSDP_PEER_IS_LISTENER(mp) (mp->flags & PIM_MSDP_PEERF_LISTENER)
0ce04a08
RZ
100 PIM_MSDP_PEERF_SA_JUST_SENT = (1 << 1),
101 /** Flag to signalize that peer belongs to a group. */
102 PIM_MSDP_PEERF_IN_GROUP = (1 << 2),
2a333e0f 103};
104
105struct pim_msdp_peer {
472ad383
DS
106 struct pim_instance *pim;
107
d62a17ae 108 /* configuration */
109 struct in_addr local;
110 struct in_addr peer;
111 char *mesh_group_name;
112 char key_str[INET_ADDRSTRLEN];
113
114 /* state */
115 enum pim_msdp_peer_state state;
116 enum pim_msdp_peer_flags flags;
117
118 /* TCP socket info */
119 union sockunion su_local;
120 union sockunion su_peer;
121 int fd;
122
123/* protocol timers */
2a333e0f 124#define PIM_MSDP_PEER_HOLD_TIME 75
d62a17ae 125 struct thread *hold_timer; // 5.4
2a333e0f 126#define PIM_MSDP_PEER_KA_TIME 60
9d303b37 127 struct thread *ka_timer; // 5.5
2a333e0f 128#define PIM_MSDP_PEER_CONNECT_RETRY_TIME 30
9d303b37 129 struct thread *cr_timer; // 5.6
d62a17ae 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 */
977d71cc 142#define PIM_MSDP_PEER_LAST_RESET_STR 20
d62a17ae 143 char last_reset[PIM_MSDP_PEER_LAST_RESET_STR];
977d71cc 144
d62a17ae 145 /* packet stats */
146 uint32_t ka_tx_cnt;
147 uint32_t sa_tx_cnt;
148 uint32_t ka_rx_cnt;
149 uint32_t sa_rx_cnt;
150 uint32_t unk_rx_cnt;
2a333e0f 151
d62a17ae 152 /* timestamps */
153 int64_t uptime;
2a333e0f 154};
155
977d71cc 156struct pim_msdp_mg_mbr {
d62a17ae 157 struct in_addr mbr_ip;
158 struct pim_msdp_peer *mp;
977d71cc 159};
160
161/* PIM MSDP mesh-group */
162struct pim_msdp_mg {
d62a17ae 163 char *mesh_group_name;
164 struct in_addr src_ip;
165 uint32_t mbr_cnt;
166 struct list *mbr_list;
e2809e61
RZ
167
168 /** Belongs to PIM instance list. */
169 SLIST_ENTRY(pim_msdp_mg) mg_entry;
977d71cc 170};
171
e2809e61
RZ
172SLIST_HEAD(pim_mesh_group_list, pim_msdp_mg);
173
2a333e0f 174enum pim_msdp_flags {
d62a17ae 175 PIM_MSDPF_NONE = 0,
176 PIM_MSDPF_ENABLE = (1 << 0),
177 PIM_MSDPF_LISTENER = (1 << 1)
2a333e0f 178};
179
180struct pim_msdp_listener {
d62a17ae 181 int fd;
182 union sockunion su;
183 struct thread *thread;
2a333e0f 184};
11128587 185
2a333e0f 186struct pim_msdp {
d62a17ae 187 enum pim_msdp_flags flags;
188 struct thread_master *master;
189 struct pim_msdp_listener listener;
190 uint32_t rejected_accepts;
3c72d654 191
d62a17ae 192 /* MSDP peer info */
193 struct hash *peer_hash;
194 struct list *peer_list;
3c72d654 195
d62a17ae 196/* MSDP active-source info */
3c72d654 197#define PIM_MSDP_SA_ADVERTISMENT_TIME 60
d62a17ae 198 struct thread *sa_adv_timer; // 5.6
199 struct hash *sa_hash;
200 struct list *sa_list;
201 uint32_t local_cnt;
3c72d654 202
d62a17ae 203 /* keep a scratch pad for building SA TLVs */
204 struct stream *work_obuf;
3c72d654 205
d62a17ae 206 struct in_addr originator_id;
977d71cc 207
e2809e61
RZ
208 /** List of mesh groups. */
209 struct pim_mesh_group_list mglist;
622fd3f1
RZ
210
211 /** MSDP global hold time period. */
212 uint32_t hold_time;
213 /** MSDP global keep alive period. */
214 uint32_t keep_alive;
215 /** MSDP global connection retry period. */
216 uint32_t connection_retry;
11128587
DS
217};
218
d62a17ae 219#define PIM_MSDP_PEER_READ_ON(mp) \
472ad383 220 thread_add_read(mp->pim->msdp.master, pim_msdp_read, mp, mp->fd, \
2ad78035 221 &mp->t_read)
ffa2c898 222
d62a17ae 223#define PIM_MSDP_PEER_WRITE_ON(mp) \
472ad383 224 thread_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \
2ad78035 225 &mp->t_write)
2a333e0f 226
50478845
MS
227#define PIM_MSDP_PEER_READ_OFF(mp) thread_cancel(&mp->t_read)
228#define PIM_MSDP_PEER_WRITE_OFF(mp) thread_cancel(&mp->t_write)
2a333e0f 229
cda1f5e0 230#if PIM_IPV != 6
2ad78035
DS
231// struct pim_msdp *msdp;
232struct pim_instance;
64c86530 233void pim_msdp_init(struct pim_instance *pim, struct thread_master *master);
2ad78035 234void pim_msdp_exit(struct pim_instance *pim);
d62a17ae 235char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
236 int buf_size);
472ad383
DS
237struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
238 struct in_addr peer_addr);
2a333e0f 239void pim_msdp_peer_established(struct pim_msdp_peer *mp);
240void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp);
241void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state);
242void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str);
cc9f21da 243void pim_msdp_write(struct thread *thread);
84f25989
DS
244int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty,
245 const char *spaces);
8c70c9e2
RZ
246bool pim_msdp_peer_config_write(struct vty *vty, struct pim_instance *pim,
247 const char *spaces);
3c72d654 248void pim_msdp_peer_pkt_txed(struct pim_msdp_peer *mp);
472ad383 249void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
6fff2cc6 250 pim_sgaddr *sg, struct in_addr rp);
1bf16443 251void pim_msdp_sa_local_update(struct pim_upstream *up);
6fff2cc6 252void pim_msdp_sa_local_del(struct pim_instance *pim, pim_sgaddr *sg);
472ad383 253void pim_msdp_i_am_rp_changed(struct pim_instance *pim);
3c72d654 254bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp);
1eca8576
DS
255void pim_msdp_up_join_state_changed(struct pim_instance *pim,
256 struct pim_upstream *xg_up);
6fff2cc6 257void pim_msdp_up_del(struct pim_instance *pim, pim_sgaddr *sg);
472ad383
DS
258enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim,
259 const char *mesh_group_name);
e2809e61
RZ
260
261/**
262 * Allocates a new mesh group data structure under PIM instance.
263 */
264struct pim_msdp_mg *pim_msdp_mg_new(struct pim_instance *pim,
265 const char *mesh_group_name);
266/**
267 * Deallocates mesh group data structure under PIM instance.
268 */
269void pim_msdp_mg_free(struct pim_instance *pim, struct pim_msdp_mg **mgp);
270
271/**
272 * Change the source address of a mesh group peers. It will do the following:
273 * - Close all peers TCP connections
274 * - Recreate peers data structure
275 * - Start TCP connections with new local address.
276 */
fb35f654
RZ
277void pim_msdp_mg_src_add(struct pim_instance *pim, struct pim_msdp_mg *mg,
278 struct in_addr *ai);
e2809e61
RZ
279
280/**
281 * Add new peer to mesh group and starts the connection if source address is
282 * configured.
283 */
fb35f654
RZ
284struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_add(struct pim_instance *pim,
285 struct pim_msdp_mg *mg,
286 struct in_addr *ia);
e2809e61
RZ
287
288/**
289 * Stops the connection and removes the peer data structures.
290 */
fb35f654 291void pim_msdp_mg_mbr_del(struct pim_msdp_mg *mg, struct pim_msdp_mg_mbr *mbr);
e2809e61 292
56697b3e 293/**
c72d97a5
RZ
294 * Allocates MSDP peer data structure, adds peer to group name
295 * `mesh_group_name` and starts state machine. If no group name is provided then
296 * the peer will work standalone.
56697b3e
RZ
297 *
298 * \param pim PIM instance
299 * \param peer_addr peer address
300 * \param local_addr local listening address
0ce04a08 301 * \param mesh_group_name mesh group name (or `NULL` for peers without group).
56697b3e 302 */
c72d97a5 303struct pim_msdp_peer *pim_msdp_peer_add(struct pim_instance *pim,
56697b3e
RZ
304 const struct in_addr *peer_addr,
305 const struct in_addr *local_addr,
306 const char *mesh_group_name);
307
308/**
309 * Stops peer state machine and free memory.
310 */
c72d97a5 311void pim_msdp_peer_del(struct pim_msdp_peer **mp);
56697b3e
RZ
312
313/**
314 * Changes peer source address.
315 *
316 * NOTE:
317 * This will cause the connection to drop and start again.
318 */
319void pim_msdp_peer_change_source(struct pim_msdp_peer *mp,
320 const struct in_addr *addr);
321
cda1f5e0
DL
322#else /* PIM_IPV == 6 */
323static inline void pim_msdp_init(struct pim_instance *pim,
324 struct thread_master *master)
325{
326}
327
328static inline void pim_msdp_exit(struct pim_instance *pim)
329{
330}
331
332static inline void pim_msdp_i_am_rp_changed(struct pim_instance *pim)
333{
334}
335
336static inline void pim_msdp_up_join_state_changed(struct pim_instance *pim,
337 struct pim_upstream *xg_up)
338{
339}
340
341static inline void pim_msdp_up_del(struct pim_instance *pim, pim_sgaddr *sg)
342{
343}
344
345static inline void pim_msdp_sa_local_update(struct pim_upstream *up)
346{
347}
348
349static inline void pim_msdp_sa_local_del(struct pim_instance *pim,
350 pim_sgaddr *sg)
351{
352}
353
354static inline int pim_msdp_config_write(struct pim_instance *pim,
355 struct vty *vty, const char *spaces)
356{
357 return 0;
358}
359
360static inline bool pim_msdp_peer_config_write(struct vty *vty,
361 struct pim_instance *pim,
362 const char *spaces)
363{
364 return false;
365}
366#endif /* PIM_IPV == 6 */
367
11128587 368#endif