]>
git.proxmox.com Git - mirror_frr.git/blob - pbrd/pbr_vrf.c
3 * Copyright (C) 2019 Cumulus Networks, Inc.
6 * FRR 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 * FRR 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 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
25 #include "pbr_memory.h"
27 #include "pbr_debug.h"
29 #include "pbr_zebra.h"
31 DEFINE_MTYPE_STATIC(PBRD
, PBR_MAP_VRF
, "PBR Map VRF");
33 static struct pbr_vrf
*pbr_vrf_alloc(void)
35 struct pbr_vrf
*pbr_vrf
;
37 pbr_vrf
= XCALLOC(MTYPE_PBR_MAP_VRF
, sizeof(struct pbr_vrf
));
42 static void pbr_vrf_free(struct pbr_vrf
*pbr_vrf
)
44 XFREE(MTYPE_PBR_MAP_VRF
, pbr_vrf
);
47 static int pbr_vrf_new(struct vrf
*vrf
)
49 struct pbr_vrf
*pbr_vrf
;
51 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
53 pbr_vrf
= pbr_vrf_alloc();
60 static int pbr_vrf_enable(struct vrf
*vrf
)
62 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
64 pbr_nht_vrf_update(vrf
->info
);
65 pbr_map_vrf_update(vrf
->info
);
70 static int pbr_vrf_disable(struct vrf
*vrf
)
72 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
74 pbr_map_vrf_update(vrf
->info
);
79 static int pbr_vrf_delete(struct vrf
*vrf
)
81 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
84 * Make sure vrf is always marked disabled first so we handle
87 assert(!vrf_is_enabled(vrf
));
89 pbr_vrf_free(vrf
->info
);
95 struct pbr_vrf
*pbr_vrf_lookup_by_name(const char *name
)
100 name
= VRF_DEFAULT_NAME
;
102 vrf
= vrf_lookup_by_name(name
);
104 return ((struct pbr_vrf
*)vrf
->info
);
109 bool pbr_vrf_is_enabled(const struct pbr_vrf
*pbr_vrf
)
111 return vrf_is_enabled(pbr_vrf
->vrf
) ? true : false;
114 bool pbr_vrf_is_valid(const struct pbr_vrf
*pbr_vrf
)
116 if (vrf_is_backend_netns())
122 return pbr_vrf_is_enabled(pbr_vrf
);
125 void pbr_vrf_init(void)
127 vrf_init(pbr_vrf_new
, pbr_vrf_enable
, pbr_vrf_disable
, pbr_vrf_delete
,
131 void pbr_vrf_terminate(void)
134 struct interface
*ifp
;
136 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
137 FOR_ALL_INTERFACES (vrf
, ifp
)