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