]>
git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_advertise.c
1 /* BGP advertisement and adjacency
2 Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #include "bgpd/bgpd.h"
32 #include "bgpd/bgp_table.h"
33 #include "bgpd/bgp_route.h"
34 #include "bgpd/bgp_advertise.h"
35 #include "bgpd/bgp_attr.h"
36 #include "bgpd/bgp_debug.h"
37 #include "bgpd/bgp_aspath.h"
38 #include "bgpd/bgp_packet.h"
39 #include "bgpd/bgp_fsm.h"
40 #include "bgpd/bgp_mplsvpn.h"
41 #include "bgpd/bgp_updgrp.h"
43 /* BGP advertise attribute is used for pack same attribute update into
44 one packet. To do that we maintain attribute hash in struct
46 struct bgp_advertise_attr
*
49 return (struct bgp_advertise_attr
*)
50 XCALLOC (MTYPE_BGP_ADVERTISE_ATTR
, sizeof (struct bgp_advertise_attr
));
54 baa_free (struct bgp_advertise_attr
*baa
)
56 XFREE (MTYPE_BGP_ADVERTISE_ATTR
, baa
);
60 baa_hash_alloc (void *p
)
62 struct bgp_advertise_attr
* ref
= (struct bgp_advertise_attr
*) p
;
63 struct bgp_advertise_attr
*baa
;
66 baa
->attr
= ref
->attr
;
71 baa_hash_key (void *p
)
73 struct bgp_advertise_attr
* baa
= (struct bgp_advertise_attr
*) p
;
75 return attrhash_key_make (baa
->attr
);
79 baa_hash_cmp (const void *p1
, const void *p2
)
81 const struct bgp_advertise_attr
* baa1
= p1
;
82 const struct bgp_advertise_attr
* baa2
= p2
;
84 return attrhash_cmp (baa1
->attr
, baa2
->attr
);
87 /* BGP update and withdraw information is stored in BGP advertise
88 structure. This structure is referred from BGP adjacency
90 struct bgp_advertise
*
91 bgp_advertise_new (void)
93 return (struct bgp_advertise
*)
94 XCALLOC (MTYPE_BGP_ADVERTISE
, sizeof (struct bgp_advertise
));
98 bgp_advertise_free (struct bgp_advertise
*adv
)
101 bgp_info_unlock (adv
->binfo
); /* bgp_advertise bgp_info reference */
102 XFREE (MTYPE_BGP_ADVERTISE
, adv
);
106 bgp_advertise_add (struct bgp_advertise_attr
*baa
,
107 struct bgp_advertise
*adv
)
109 adv
->next
= baa
->adv
;
111 baa
->adv
->prev
= adv
;
116 bgp_advertise_delete (struct bgp_advertise_attr
*baa
,
117 struct bgp_advertise
*adv
)
120 adv
->next
->prev
= adv
->prev
;
122 adv
->prev
->next
= adv
->next
;
124 baa
->adv
= adv
->next
;
127 struct bgp_advertise_attr
*
128 bgp_advertise_intern (struct hash
*hash
, struct attr
*attr
)
130 struct bgp_advertise_attr ref
;
131 struct bgp_advertise_attr
*baa
;
133 ref
.attr
= bgp_attr_intern (attr
);
134 baa
= (struct bgp_advertise_attr
*) hash_get (hash
, &ref
, baa_hash_alloc
);
141 bgp_advertise_unintern (struct hash
*hash
, struct bgp_advertise_attr
*baa
)
146 if (baa
->refcnt
&& baa
->attr
)
147 bgp_attr_unintern (&baa
->attr
);
152 hash_release (hash
, baa
);
153 bgp_attr_unintern (&baa
->attr
);
160 bgp_adj_out_lookup (struct peer
*peer
, struct bgp_node
*rn
,
161 u_int32_t addpath_tx_id
)
163 struct bgp_adj_out
*adj
;
169 for (adj
= rn
->adj_out
; adj
; adj
= adj
->next
)
170 SUBGRP_FOREACH_PEER(adj
->subgroup
, paf
)
171 if (paf
->peer
== peer
)
173 afi
= SUBGRP_AFI (adj
->subgroup
);
174 safi
= SUBGRP_SAFI (adj
->subgroup
);
175 addpath_capable
= bgp_addpath_encode_tx (peer
, afi
, safi
);
177 /* Match on a specific addpath_tx_id if we are using addpath for this
178 * peer and if an addpath_tx_id was specified */
179 if (addpath_capable
&& addpath_tx_id
&& adj
->addpath_tx_id
!= addpath_tx_id
)
183 ? (adj
->adv
->baa
? 1 : 0)
184 : (adj
->attr
? 1 : 0));
192 bgp_adj_in_set (struct bgp_node
*rn
, struct peer
*peer
, struct attr
*attr
,
193 u_int32_t addpath_id
)
195 struct bgp_adj_in
*adj
;
197 for (adj
= rn
->adj_in
; adj
; adj
= adj
->next
)
199 if (adj
->peer
== peer
&& adj
->addpath_rx_id
== addpath_id
)
201 if (adj
->attr
!= attr
)
203 bgp_attr_unintern (&adj
->attr
);
204 adj
->attr
= bgp_attr_intern (attr
);
209 adj
= XCALLOC (MTYPE_BGP_ADJ_IN
, sizeof (struct bgp_adj_in
));
210 adj
->peer
= peer_lock (peer
); /* adj_in peer reference */
211 adj
->attr
= bgp_attr_intern (attr
);
212 adj
->addpath_rx_id
= addpath_id
;
213 BGP_ADJ_IN_ADD (rn
, adj
);
218 bgp_adj_in_remove (struct bgp_node
*rn
, struct bgp_adj_in
*bai
)
220 bgp_attr_unintern (&bai
->attr
);
221 BGP_ADJ_IN_DEL (rn
, bai
);
222 peer_unlock (bai
->peer
); /* adj_in peer reference */
223 XFREE (MTYPE_BGP_ADJ_IN
, bai
);
227 bgp_adj_in_unset (struct bgp_node
*rn
, struct peer
*peer
,
228 u_int32_t addpath_id
)
230 struct bgp_adj_in
*adj
;
231 struct bgp_adj_in
*adj_next
;
240 adj_next
= adj
->next
;
242 if (adj
->peer
== peer
&& adj
->addpath_rx_id
== addpath_id
)
244 bgp_adj_in_remove (rn
, adj
);
245 bgp_unlock_node (rn
);
255 bgp_sync_init (struct peer
*peer
)
259 struct bgp_synchronize
*sync
;
261 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
262 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
264 sync
= XCALLOC (MTYPE_BGP_SYNCHRONISE
,
265 sizeof (struct bgp_synchronize
));
266 BGP_ADV_FIFO_INIT (&sync
->update
);
267 BGP_ADV_FIFO_INIT (&sync
->withdraw
);
268 BGP_ADV_FIFO_INIT (&sync
->withdraw_low
);
269 peer
->sync
[afi
][safi
] = sync
;
270 peer
->hash
[afi
][safi
] = hash_create (baa_hash_key
, baa_hash_cmp
);
275 bgp_sync_delete (struct peer
*peer
)
280 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
281 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
283 if (peer
->sync
[afi
][safi
])
284 XFREE (MTYPE_BGP_SYNCHRONISE
, peer
->sync
[afi
][safi
]);
285 peer
->sync
[afi
][safi
] = NULL
;
287 if (peer
->hash
[afi
][safi
])
288 hash_free (peer
->hash
[afi
][safi
]);
289 peer
->hash
[afi
][safi
] = NULL
;