3 * Copyright (C) 2016 Cumulus Networks, Inc.
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; see the file COPYING; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 enum pim_msdp_peer_state
{
31 /* SA and KA TLVs are processed; rest ignored */
33 PIM_MSDP_V4_SOURCE_ACTIVE
= 1,
34 PIM_MSDP_V4_SOURCE_ACTIVE_REQUEST
,
35 PIM_MSDP_V4_SOURCE_ACTIVE_RESPONSE
,
38 PIM_MSDP_TRACEROUTE_PROGRESS
,
39 PIM_MSDP_TRACEROUTE_REPLY
,
42 /* MSDP error codes */
44 PIM_MSDP_ERR_NONE
= 0,
45 PIM_MSDP_ERR_OOM
= -1,
46 PIM_MSDP_ERR_PEER_EXISTS
= -2,
47 PIM_MSDP_ERR_MAX_MESH_GROUPS
= -3,
48 PIM_MSDP_ERR_NO_PEER
= -4,
49 PIM_MSDP_ERR_MG_MBR_EXISTS
= -5,
50 PIM_MSDP_ERR_NO_MG
= -6,
51 PIM_MSDP_ERR_NO_MG_MBR
= -7,
52 PIM_MSDP_ERR_SIP_EQ_DIP
= -8,
55 #define PIM_MSDP_STATE_STRLEN 16
56 #define PIM_MSDP_UPTIME_STRLEN 80
57 #define PIM_MSDP_TIMER_STRLEN 12
58 #define PIM_MSDP_TCP_PORT 639
59 #define PIM_MSDP_SOCKET_SNDBUF_SIZE 65536
61 enum pim_msdp_sa_flags
{
62 PIM_MSDP_SAF_NONE
= 0,
63 /* There are two cases where we can pickup an active source locally -
64 * 1. We are RP and got a source-register from the FHR
65 * 2. We are RP and FHR and learnt a new directly connected source on a
67 PIM_MSDP_SAF_LOCAL
= (1 << 0),
68 /* We got this in the MSDP SA TLV from a peer (and this passed peer-RPF
70 PIM_MSDP_SAF_PEER
= (1 << 1),
71 PIM_MSDP_SAF_REF
= (PIM_MSDP_SAF_LOCAL
| PIM_MSDP_SAF_PEER
),
72 PIM_MSDP_SAF_STALE
= (1 << 2) /* local entries can get kicked out on
73 * misc pim events such as RP change */
78 char sg_str
[PIM_SG_LEN
];
79 struct in_addr rp
; /* Last RP address associated with this SA */
80 struct in_addr peer
; /* last peer from who we heard this SA */
81 enum pim_msdp_sa_flags flags
;
83 /* rfc-3618 is missing default value for SA-hold-down-Period. pulled
84 * this number from industry-standards */
85 #define PIM_MSDP_SA_HOLD_TIME ((3*60)+30)
86 struct thread
*sa_state_timer
; // 5.6
89 struct pim_upstream
*up
;
92 enum pim_msdp_peer_flags
{
93 PIM_MSDP_PEERF_NONE
= 0,
94 PIM_MSDP_PEERF_LISTENER
= (1 << 0),
95 #define PIM_MSDP_PEER_IS_LISTENER(mp) (mp->flags & PIM_MSDP_PEERF_LISTENER)
96 PIM_MSDP_PEERF_SA_JUST_SENT
= (1 << 1)
99 struct pim_msdp_peer
{
101 struct in_addr local
;
103 char *mesh_group_name
;
104 char key_str
[INET_ADDRSTRLEN
];
107 enum pim_msdp_peer_state state
;
108 enum pim_msdp_peer_flags flags
;
110 /* TCP socket info */
111 union sockunion su_local
;
112 union sockunion su_peer
;
115 /* protocol timers */
116 #define PIM_MSDP_PEER_HOLD_TIME 75
117 struct thread
*hold_timer
; // 5.4
118 #define PIM_MSDP_PEER_KA_TIME 60
119 struct thread
*ka_timer
; // 5.5
120 #define PIM_MSDP_PEER_CONNECT_RETRY_TIME 30
121 struct thread
*cr_timer
; // 5.6
123 /* packet thread and buffers */
124 uint32_t packet_size
;
126 struct stream_fifo
*obuf
;
127 struct thread
*t_read
;
128 struct thread
*t_write
;
131 uint32_t conn_attempts
;
133 uint32_t sa_cnt
; /* number of SAs attributed to this peer */
134 #define PIM_MSDP_PEER_LAST_RESET_STR 20
135 char last_reset
[PIM_MSDP_PEER_LAST_RESET_STR
];
148 struct pim_msdp_mg_mbr
{
149 struct in_addr mbr_ip
;
150 struct pim_msdp_peer
*mp
;
153 /* PIM MSDP mesh-group */
155 char *mesh_group_name
;
156 struct in_addr src_ip
;
158 struct list
*mbr_list
;
161 enum pim_msdp_flags
{
163 PIM_MSDPF_ENABLE
= (1 << 0),
164 PIM_MSDPF_LISTENER
= (1 << 1)
167 struct pim_msdp_listener
{
170 struct thread
*thread
;
174 enum pim_msdp_flags flags
;
175 struct thread_master
*master
;
176 struct pim_msdp_listener listener
;
177 uint32_t rejected_accepts
;
180 struct hash
*peer_hash
;
181 struct list
*peer_list
;
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
;
190 /* keep a scratch pad for building SA TLVs */
191 struct stream
*work_obuf
;
193 struct in_addr originator_id
;
195 /* currently only one mesh-group is supported - so just stash it here */
196 struct pim_msdp_mg
*mg
;
199 #define PIM_MSDP_PEER_READ_ON(mp) THREAD_READ_ON(msdp->master, mp->t_read, pim_msdp_read, mp, mp->fd);
200 #define PIM_MSDP_PEER_WRITE_ON(mp) THREAD_WRITE_ON(msdp->master, mp->t_write, pim_msdp_write, mp, mp->fd);
202 #define PIM_MSDP_PEER_READ_OFF(mp) THREAD_READ_OFF(mp->t_read)
203 #define PIM_MSDP_PEER_WRITE_OFF(mp) THREAD_WRITE_OFF(mp->t_write)
205 extern struct pim_msdp
*msdp
;
206 void pim_msdp_init(struct thread_master
*master
);
207 void pim_msdp_exit(void);
208 enum pim_msdp_err
pim_msdp_peer_add(struct in_addr peer
, struct in_addr local
, const char *mesh_group_name
, struct pim_msdp_peer
**mp_p
);
209 enum pim_msdp_err
pim_msdp_peer_del(struct in_addr peer_addr
);
210 char *pim_msdp_state_dump(enum pim_msdp_peer_state state
, char *buf
, int buf_size
);
211 struct pim_msdp_peer
*pim_msdp_peer_find(struct in_addr peer_addr
);
212 void pim_msdp_peer_established(struct pim_msdp_peer
*mp
);
213 void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer
*mp
);
214 void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer
*mp
, bool chg_state
);
215 void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer
*mp
, const char *rc_str
);
216 int pim_msdp_write(struct thread
*thread
);
217 char *pim_msdp_peer_key_dump(struct pim_msdp_peer
*mp
, char *buf
, int buf_size
, bool long_format
);
218 int pim_msdp_config_write(struct vty
*vty
);
219 void pim_msdp_peer_pkt_txed(struct pim_msdp_peer
*mp
);
220 void pim_msdp_sa_ref(struct pim_msdp_peer
*mp
, struct prefix_sg
*sg
, struct in_addr rp
);
221 void pim_msdp_sa_local_update(struct pim_upstream
*up
);
222 void pim_msdp_sa_local_del(struct prefix_sg
*sg
);
223 void pim_msdp_i_am_rp_changed(void);
224 bool pim_msdp_peer_rpf_check(struct pim_msdp_peer
*mp
, struct in_addr rp
);
225 void pim_msdp_up_join_state_changed(struct pim_upstream
*xg_up
);
226 void pim_msdp_up_xg_del(struct prefix_sg
*sg
);
227 enum pim_msdp_err
pim_msdp_mg_mbr_add(const char *mesh_group_name
, struct in_addr mbr_ip
);
228 enum pim_msdp_err
pim_msdp_mg_mbr_del(const char *mesh_group_name
, struct in_addr mbr_ip
);
229 enum pim_msdp_err
pim_msdp_mg_src_del(const char *mesh_group_name
);
230 enum pim_msdp_err
pim_msdp_mg_src_add(const char *mesh_group_name
, struct in_addr src_ip
);
231 enum pim_msdp_err
pim_msdp_mg_del(const char *mesh_group_name
);