]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_msdp.h
pimd: rework MSDP northbound integration
[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 #include "lib/openbsd-queue.h"
23
24 enum pim_msdp_peer_state {
25 PIM_MSDP_DISABLED,
26 PIM_MSDP_INACTIVE,
27 PIM_MSDP_LISTEN,
28 PIM_MSDP_CONNECTING,
29 PIM_MSDP_ESTABLISHED
30 };
31
32 /* SA and KA TLVs are processed; rest ignored */
33 enum pim_msdp_tlv {
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,
41 };
42
43 /* MSDP error codes */
44 enum pim_msdp_err {
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,
54 };
55
56 #define PIM_MSDP_STATE_STRLEN 16
57 #define PIM_MSDP_UPTIME_STRLEN 80
58 #define PIM_MSDP_TIMER_STRLEN 12
59 #define PIM_MSDP_TCP_PORT 639
60 #define PIM_MSDP_SOCKET_SNDBUF_SIZE 65536
61
62 enum pim_msdp_sa_flags {
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
74 * misc pim events such as RP change */
75 PIM_MSDP_SAF_UP_DEL_IN_PROG = (1 << 3)
76 };
77
78 struct pim_msdp_sa {
79 struct pim_instance *pim;
80
81 struct prefix_sg sg;
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 */
89 #define PIM_MSDP_SA_HOLD_TIME ((3*60)+30)
90 struct thread *sa_state_timer; // 5.6
91 int64_t uptime;
92
93 struct pim_upstream *up;
94 };
95
96 enum pim_msdp_peer_flags {
97 PIM_MSDP_PEERF_NONE = 0,
98 PIM_MSDP_PEERF_LISTENER = (1 << 0),
99 #define PIM_MSDP_PEER_IS_LISTENER(mp) (mp->flags & PIM_MSDP_PEERF_LISTENER)
100 PIM_MSDP_PEERF_SA_JUST_SENT = (1 << 1)
101 };
102
103 struct pim_msdp_peer {
104 struct pim_instance *pim;
105
106 /* configuration */
107 struct in_addr local;
108 struct in_addr peer;
109 char *mesh_group_name;
110 char key_str[INET_ADDRSTRLEN];
111
112 /* state */
113 enum pim_msdp_peer_state state;
114 enum pim_msdp_peer_flags flags;
115
116 /* TCP socket info */
117 union sockunion su_local;
118 union sockunion su_peer;
119 int fd;
120
121 /* protocol timers */
122 #define PIM_MSDP_PEER_HOLD_TIME 75
123 struct thread *hold_timer; // 5.4
124 #define PIM_MSDP_PEER_KA_TIME 60
125 struct thread *ka_timer; // 5.5
126 #define PIM_MSDP_PEER_CONNECT_RETRY_TIME 30
127 struct thread *cr_timer; // 5.6
128
129 /* packet thread and buffers */
130 uint32_t packet_size;
131 struct stream *ibuf;
132 struct stream_fifo *obuf;
133 struct thread *t_read;
134 struct thread *t_write;
135
136 /* stats */
137 uint32_t conn_attempts;
138 uint32_t est_flaps;
139 uint32_t sa_cnt; /* number of SAs attributed to this peer */
140 #define PIM_MSDP_PEER_LAST_RESET_STR 20
141 char last_reset[PIM_MSDP_PEER_LAST_RESET_STR];
142
143 /* packet stats */
144 uint32_t ka_tx_cnt;
145 uint32_t sa_tx_cnt;
146 uint32_t ka_rx_cnt;
147 uint32_t sa_rx_cnt;
148 uint32_t unk_rx_cnt;
149
150 /* timestamps */
151 int64_t uptime;
152 };
153
154 struct pim_msdp_mg_mbr {
155 struct in_addr mbr_ip;
156 struct pim_msdp_peer *mp;
157 };
158
159 /* PIM MSDP mesh-group */
160 struct pim_msdp_mg {
161 char *mesh_group_name;
162 struct in_addr src_ip;
163 uint32_t mbr_cnt;
164 struct list *mbr_list;
165
166 /** Belongs to PIM instance list. */
167 SLIST_ENTRY(pim_msdp_mg) mg_entry;
168 };
169
170 SLIST_HEAD(pim_mesh_group_list, pim_msdp_mg);
171
172 enum pim_msdp_flags {
173 PIM_MSDPF_NONE = 0,
174 PIM_MSDPF_ENABLE = (1 << 0),
175 PIM_MSDPF_LISTENER = (1 << 1)
176 };
177
178 struct pim_msdp_listener {
179 int fd;
180 union sockunion su;
181 struct thread *thread;
182 };
183
184 struct pim_msdp {
185 enum pim_msdp_flags flags;
186 struct thread_master *master;
187 struct pim_msdp_listener listener;
188 uint32_t rejected_accepts;
189
190 /* MSDP peer info */
191 struct hash *peer_hash;
192 struct list *peer_list;
193
194 /* MSDP active-source info */
195 #define PIM_MSDP_SA_ADVERTISMENT_TIME 60
196 struct thread *sa_adv_timer; // 5.6
197 struct hash *sa_hash;
198 struct list *sa_list;
199 uint32_t local_cnt;
200
201 /* keep a scratch pad for building SA TLVs */
202 struct stream *work_obuf;
203
204 struct in_addr originator_id;
205
206 /** List of mesh groups. */
207 struct pim_mesh_group_list mglist;
208 };
209
210 #define PIM_MSDP_PEER_READ_ON(mp) \
211 thread_add_read(mp->pim->msdp.master, pim_msdp_read, mp, mp->fd, \
212 &mp->t_read)
213
214 #define PIM_MSDP_PEER_WRITE_ON(mp) \
215 thread_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \
216 &mp->t_write)
217
218 #define PIM_MSDP_PEER_READ_OFF(mp) thread_cancel(&mp->t_read)
219 #define PIM_MSDP_PEER_WRITE_OFF(mp) thread_cancel(&mp->t_write)
220
221 // struct pim_msdp *msdp;
222 struct pim_instance;
223 void pim_msdp_init(struct pim_instance *pim, struct thread_master *master);
224 void pim_msdp_exit(struct pim_instance *pim);
225 char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
226 int buf_size);
227 struct pim_msdp_peer *pim_msdp_peer_find(struct pim_instance *pim,
228 struct in_addr peer_addr);
229 void pim_msdp_peer_established(struct pim_msdp_peer *mp);
230 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp);
231 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state);
232 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str);
233 int pim_msdp_write(struct thread *thread);
234 char *pim_msdp_peer_key_dump(struct pim_msdp_peer *mp, char *buf, int buf_size,
235 bool long_format);
236 int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty,
237 const char *spaces);
238 bool pim_msdp_peer_config_write(struct vty *vty, struct pim_instance *pim,
239 const char *spaces);
240 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer *mp);
241 void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
242 struct prefix_sg *sg, struct in_addr rp);
243 void pim_msdp_sa_local_update(struct pim_upstream *up);
244 void pim_msdp_sa_local_del(struct pim_instance *pim, struct prefix_sg *sg);
245 void pim_msdp_i_am_rp_changed(struct pim_instance *pim);
246 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp);
247 void pim_msdp_up_join_state_changed(struct pim_instance *pim,
248 struct pim_upstream *xg_up);
249 void pim_msdp_up_del(struct pim_instance *pim, struct prefix_sg *sg);
250 enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim,
251 const char *mesh_group_name);
252
253 /**
254 * Allocates a new mesh group data structure under PIM instance.
255 */
256 struct pim_msdp_mg *pim_msdp_mg_new(struct pim_instance *pim,
257 const char *mesh_group_name);
258 /**
259 * Deallocates mesh group data structure under PIM instance.
260 */
261 void pim_msdp_mg_free(struct pim_instance *pim, struct pim_msdp_mg **mgp);
262
263 /**
264 * Change the source address of a mesh group peers. It will do the following:
265 * - Close all peers TCP connections
266 * - Recreate peers data structure
267 * - Start TCP connections with new local address.
268 */
269 void pim_msdp_mg_src_add(struct pim_instance *pim, struct pim_msdp_mg *mg,
270 struct in_addr *ai);
271
272 /**
273 * Add new peer to mesh group and starts the connection if source address is
274 * configured.
275 */
276 struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_add(struct pim_instance *pim,
277 struct pim_msdp_mg *mg,
278 struct in_addr *ia);
279
280 /**
281 * Stops the connection and removes the peer data structures.
282 */
283 void pim_msdp_mg_mbr_del(struct pim_msdp_mg *mg, struct pim_msdp_mg_mbr *mbr);
284
285 #define MSDP_SOLO_PEER_GROUP_NAME "default"
286
287 /**
288 * Allocates MSDP peer data structure and starts state machine.
289 *
290 * \param pim PIM instance
291 * \param peer_addr peer address
292 * \param local_addr local listening address
293 * \param mesh_group_name mesh group name (or `MSDP_SOLO_PEER_GROUP_NAME` for
294 * peers without group).
295 */
296 struct pim_msdp_peer *pim_msdp_peer_new(struct pim_instance *pim,
297 const struct in_addr *peer_addr,
298 const struct in_addr *local_addr,
299 const char *mesh_group_name);
300
301 /**
302 * Stops peer state machine and free memory.
303 */
304 void pim_msdp_peer_do_del(struct pim_msdp_peer **mp);
305
306 /**
307 * Changes peer source address.
308 *
309 * NOTE:
310 * This will cause the connection to drop and start again.
311 */
312 void pim_msdp_peer_change_source(struct pim_msdp_peer *mp,
313 const struct in_addr *addr);
314
315 #endif