]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_msdp.h
f0a03f076b84d6c322a7e3cf442ded2e4bd70f99
[mirror_frr.git] / pimd / pim_msdp.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * IP MSDP for Quagga
4 * Copyright (C) 2016 Cumulus Networks, Inc.
5 */
6 #ifndef PIM_MSDP_H
7 #define PIM_MSDP_H
8
9 #include "lib/openbsd-queue.h"
10
11 enum pim_msdp_peer_state {
12 PIM_MSDP_DISABLED,
13 PIM_MSDP_INACTIVE,
14 PIM_MSDP_LISTEN,
15 PIM_MSDP_CONNECTING,
16 PIM_MSDP_ESTABLISHED
17 };
18
19 /* SA and KA TLVs are processed; rest ignored */
20 enum pim_msdp_tlv {
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,
28 };
29
30 /* MSDP error codes */
31 enum pim_msdp_err {
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,
41 };
42
43 #define PIM_MSDP_STATE_STRLEN 16
44 #define PIM_MSDP_UPTIME_STRLEN 80
45 #define PIM_MSDP_TIMER_STRLEN 12
46 #define PIM_MSDP_TCP_PORT 639
47 #define PIM_MSDP_SOCKET_SNDBUF_SIZE 65536
48
49 enum pim_msdp_sa_flags {
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
61 * misc pim events such as RP change */
62 PIM_MSDP_SAF_UP_DEL_IN_PROG = (1 << 3)
63 };
64
65 struct pim_msdp_sa {
66 struct pim_instance *pim;
67
68 pim_sgaddr sg;
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 */
76 #define PIM_MSDP_SA_HOLD_TIME ((3*60)+30)
77 struct thread *sa_state_timer; // 5.6
78 int64_t uptime;
79
80 struct pim_upstream *up;
81 };
82
83 enum pim_msdp_peer_flags {
84 PIM_MSDP_PEERF_NONE = 0,
85 PIM_MSDP_PEERF_LISTENER = (1 << 0),
86 #define PIM_MSDP_PEER_IS_LISTENER(mp) (mp->flags & PIM_MSDP_PEERF_LISTENER)
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),
90 };
91
92 struct pim_msdp_peer {
93 struct pim_instance *pim;
94
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 */
111 #define PIM_MSDP_PEER_HOLD_TIME 75
112 struct thread *hold_timer; // 5.4
113 #define PIM_MSDP_PEER_KA_TIME 60
114 struct thread *ka_timer; // 5.5
115 #define PIM_MSDP_PEER_CONNECT_RETRY_TIME 30
116 struct thread *cr_timer; // 5.6
117
118 /* packet thread and buffers */
119 uint32_t packet_size;
120 struct stream *ibuf;
121 struct stream_fifo *obuf;
122 struct thread *t_read;
123 struct thread *t_write;
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 */
129 #define PIM_MSDP_PEER_LAST_RESET_STR 20
130 char last_reset[PIM_MSDP_PEER_LAST_RESET_STR];
131
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;
138
139 /* timestamps */
140 int64_t uptime;
141 };
142
143 struct pim_msdp_mg_mbr {
144 struct in_addr mbr_ip;
145 struct pim_msdp_peer *mp;
146 };
147
148 /* PIM MSDP mesh-group */
149 struct pim_msdp_mg {
150 char *mesh_group_name;
151 struct in_addr src_ip;
152 uint32_t mbr_cnt;
153 struct list *mbr_list;
154
155 /** Belongs to PIM instance list. */
156 SLIST_ENTRY(pim_msdp_mg) mg_entry;
157 };
158
159 SLIST_HEAD(pim_mesh_group_list, pim_msdp_mg);
160
161 enum pim_msdp_flags {
162 PIM_MSDPF_NONE = 0,
163 PIM_MSDPF_ENABLE = (1 << 0),
164 PIM_MSDPF_LISTENER = (1 << 1)
165 };
166
167 struct pim_msdp_listener {
168 int fd;
169 union sockunion su;
170 struct thread *thread;
171 };
172
173 struct pim_msdp {
174 enum pim_msdp_flags flags;
175 struct thread_master *master;
176 struct pim_msdp_listener listener;
177 uint32_t rejected_accepts;
178
179 /* MSDP peer info */
180 struct hash *peer_hash;
181 struct list *peer_list;
182
183 /* MSDP active-source info */
184 #define PIM_MSDP_SA_ADVERTISMENT_TIME 60
185 struct thread *sa_adv_timer; // 5.6
186 struct hash *sa_hash;
187 struct list *sa_list;
188 uint32_t local_cnt;
189
190 /* keep a scratch pad for building SA TLVs */
191 struct stream *work_obuf;
192
193 struct in_addr originator_id;
194
195 /** List of mesh groups. */
196 struct pim_mesh_group_list mglist;
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;
204 };
205
206 #define PIM_MSDP_PEER_READ_ON(mp) \
207 thread_add_read(mp->pim->msdp.master, pim_msdp_read, mp, mp->fd, \
208 &mp->t_read)
209
210 #define PIM_MSDP_PEER_WRITE_ON(mp) \
211 thread_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \
212 &mp->t_write)
213
214 #define PIM_MSDP_PEER_READ_OFF(mp) thread_cancel(&mp->t_read)
215 #define PIM_MSDP_PEER_WRITE_OFF(mp) thread_cancel(&mp->t_write)
216
217 #if PIM_IPV != 6
218 // struct pim_msdp *msdp;
219 struct pim_instance;
220 void pim_msdp_init(struct pim_instance *pim, struct thread_master *master);
221 void pim_msdp_exit(struct pim_instance *pim);
222 char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
223 int buf_size);
224 struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
225 struct in_addr peer_addr);
226 void pim_msdp_peer_established(struct pim_msdp_peer *mp);
227 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp);
228 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state);
229 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str);
230 void pim_msdp_write(struct thread *thread);
231 int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty,
232 const char *spaces);
233 bool pim_msdp_peer_config_write(struct vty *vty, struct pim_instance *pim,
234 const char *spaces);
235 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer *mp);
236 void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
237 pim_sgaddr *sg, struct in_addr rp);
238 void pim_msdp_sa_local_update(struct pim_upstream *up);
239 void pim_msdp_sa_local_del(struct pim_instance *pim, pim_sgaddr *sg);
240 void pim_msdp_i_am_rp_changed(struct pim_instance *pim);
241 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp);
242 void pim_msdp_up_join_state_changed(struct pim_instance *pim,
243 struct pim_upstream *xg_up);
244 void pim_msdp_up_del(struct pim_instance *pim, pim_sgaddr *sg);
245 enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim,
246 const char *mesh_group_name);
247
248 /**
249 * Allocates a new mesh group data structure under PIM instance.
250 */
251 struct 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 */
256 void 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 */
264 void pim_msdp_mg_src_add(struct pim_instance *pim, struct pim_msdp_mg *mg,
265 struct in_addr *ai);
266
267 /**
268 * Add new peer to mesh group and starts the connection if source address is
269 * configured.
270 */
271 struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_add(struct pim_instance *pim,
272 struct pim_msdp_mg *mg,
273 struct in_addr *ia);
274
275 /**
276 * Stops the connection and removes the peer data structures.
277 */
278 void pim_msdp_mg_mbr_del(struct pim_msdp_mg *mg, struct pim_msdp_mg_mbr *mbr);
279
280 /**
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.
284 *
285 * \param pim PIM instance
286 * \param peer_addr peer address
287 * \param local_addr local listening address
288 * \param mesh_group_name mesh group name (or `NULL` for peers without group).
289 */
290 struct pim_msdp_peer *pim_msdp_peer_add(struct pim_instance *pim,
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 */
298 void pim_msdp_peer_del(struct pim_msdp_peer **mp);
299
300 /**
301 * Changes peer source address.
302 *
303 * NOTE:
304 * This will cause the connection to drop and start again.
305 */
306 void pim_msdp_peer_change_source(struct pim_msdp_peer *mp,
307 const struct in_addr *addr);
308
309 #else /* PIM_IPV == 6 */
310 static inline void pim_msdp_init(struct pim_instance *pim,
311 struct thread_master *master)
312 {
313 }
314
315 static inline void pim_msdp_exit(struct pim_instance *pim)
316 {
317 }
318
319 static inline void pim_msdp_i_am_rp_changed(struct pim_instance *pim)
320 {
321 }
322
323 static inline void pim_msdp_up_join_state_changed(struct pim_instance *pim,
324 struct pim_upstream *xg_up)
325 {
326 }
327
328 static inline void pim_msdp_up_del(struct pim_instance *pim, pim_sgaddr *sg)
329 {
330 }
331
332 static inline void pim_msdp_sa_local_update(struct pim_upstream *up)
333 {
334 }
335
336 static inline void pim_msdp_sa_local_del(struct pim_instance *pim,
337 pim_sgaddr *sg)
338 {
339 }
340
341 static inline int pim_msdp_config_write(struct pim_instance *pim,
342 struct vty *vty, const char *spaces)
343 {
344 return 0;
345 }
346
347 static 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
355 #endif