]>
git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/vnc_export_table.c
3 * Copyright 2009-2016, LabN Consulting, L.L.C.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "lib/zebra.h"
23 #include "lib/prefix.h"
24 #include "lib/agg_table.h"
25 #include "lib/memory.h"
28 #include "bgpd/bgpd.h"
29 #include "bgpd/bgp_route.h"
31 #include "bgpd/rfapi/vnc_export_table.h"
32 #include "bgpd/rfapi/rfapi_private.h"
33 #include "bgpd/rfapi/rfapi_import.h"
34 #include "bgpd/rfapi/vnc_debug.h"
36 struct agg_node
*vnc_etn_get(struct bgp
*bgp
, vnc_export_type_t type
,
37 const struct prefix
*p
)
39 struct agg_table
*t
= NULL
;
40 struct agg_node
*rn
= NULL
;
43 if (!bgp
|| !bgp
->rfapi
)
46 afi
= family2afi(p
->family
);
47 assert(afi
== AFI_IP
|| afi
== AFI_IP6
);
51 if (!bgp
->rfapi
->rt_export_bgp
[afi
])
52 bgp
->rfapi
->rt_export_bgp
[afi
] = agg_table_init();
53 t
= bgp
->rfapi
->rt_export_bgp
[afi
];
56 case EXPORT_TYPE_ZEBRA
:
57 if (!bgp
->rfapi
->rt_export_zebra
[afi
])
58 bgp
->rfapi
->rt_export_zebra
[afi
] = agg_table_init();
59 t
= bgp
->rfapi
->rt_export_zebra
[afi
];
64 rn
= agg_node_get(t
, p
);
68 struct agg_node
*vnc_etn_lookup(struct bgp
*bgp
, vnc_export_type_t type
,
69 const struct prefix
*p
)
71 struct agg_table
*t
= NULL
;
72 struct agg_node
*rn
= NULL
;
75 if (!bgp
|| !bgp
->rfapi
)
78 afi
= family2afi(p
->family
);
79 assert(afi
== AFI_IP
|| afi
== AFI_IP6
);
83 if (!bgp
->rfapi
->rt_export_bgp
[afi
])
84 bgp
->rfapi
->rt_export_bgp
[afi
] = agg_table_init();
85 t
= bgp
->rfapi
->rt_export_bgp
[afi
];
88 case EXPORT_TYPE_ZEBRA
:
89 if (!bgp
->rfapi
->rt_export_zebra
[afi
])
90 bgp
->rfapi
->rt_export_zebra
[afi
] = agg_table_init();
91 t
= bgp
->rfapi
->rt_export_zebra
[afi
];
96 rn
= agg_node_lookup(t
, p
);
100 struct vnc_export_info
*vnc_eti_get(struct bgp
*bgp
, vnc_export_type_t etype
,
101 const struct prefix
*p
, struct peer
*peer
,
102 uint8_t type
, uint8_t subtype
)
104 struct agg_node
*etn
;
105 struct vnc_export_info
*eti
;
107 etn
= vnc_etn_get(bgp
, etype
, p
);
110 for (eti
= etn
->info
; eti
; eti
= eti
->next
) {
111 if (peer
== eti
->peer
&& type
== eti
->type
112 && subtype
== eti
->subtype
) {
119 agg_unlock_node(etn
);
121 eti
= XCALLOC(MTYPE_RFAPI_ETI
, sizeof(struct vnc_export_info
));
127 eti
->subtype
= subtype
;
128 eti
->next
= etn
->info
;
135 void vnc_eti_delete(struct vnc_export_info
*goner
)
137 struct agg_node
*etn
;
138 struct vnc_export_info
*eti
;
139 struct vnc_export_info
*eti_prev
= NULL
;
143 for (eti
= etn
->info
; eti
; eti_prev
= eti
, eti
= eti
->next
) {
149 vnc_zlog_debug_verbose("%s: COULDN'T FIND ETI", __func__
);
154 eti_prev
->next
= goner
->next
;
156 etn
->info
= goner
->next
;
159 peer_unlock(eti
->peer
);
161 XFREE(MTYPE_RFAPI_ETI
, goner
);
163 agg_unlock_node(etn
);
166 struct vnc_export_info
*vnc_eti_checktimer(struct bgp
*bgp
,
167 vnc_export_type_t etype
,
168 const struct prefix
*p
,
169 struct peer
*peer
, uint8_t type
,
172 struct agg_node
*etn
;
173 struct vnc_export_info
*eti
;
175 etn
= vnc_etn_lookup(bgp
, etype
, p
);
179 for (eti
= etn
->info
; eti
; eti
= eti
->next
) {
180 if (peer
== eti
->peer
&& type
== eti
->type
181 && subtype
== eti
->subtype
) {
187 agg_unlock_node(etn
);
189 if (eti
&& eti
->timer
)