]>
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 DEFINE_MTYPE_STATIC(PBRD
, PBR_MAP_VRF
, "PBR Map VRF")
31 static struct pbr_vrf
*pbr_vrf_alloc(void)
33 struct pbr_vrf
*pbr_vrf
;
35 pbr_vrf
= XCALLOC(MTYPE_PBR_MAP_VRF
, sizeof(struct pbr_vrf
));
40 static void pbr_vrf_free(struct pbr_vrf
*pbr_vrf
)
42 XFREE(MTYPE_PBR_MAP_VRF
, pbr_vrf
);
45 static int pbr_vrf_new(struct vrf
*vrf
)
47 struct pbr_vrf
*pbr_vrf
;
49 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
51 pbr_vrf
= pbr_vrf_alloc();
58 static int pbr_vrf_enable(struct vrf
*vrf
)
60 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
62 pbr_map_vrf_update(vrf
->info
);
67 static int pbr_vrf_disable(struct vrf
*vrf
)
69 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
71 pbr_map_vrf_update(vrf
->info
);
76 static int pbr_vrf_delete(struct vrf
*vrf
)
78 DEBUGD(&pbr_dbg_event
, "%s: %u (%s)", __func__
, vrf
->vrf_id
, vrf
->name
);
81 * Make sure vrf is always marked disabled first so we handle
84 assert(!vrf_is_enabled(vrf
));
86 pbr_vrf_free(vrf
->info
);
92 struct pbr_vrf
*pbr_vrf_lookup_by_id(vrf_id_t vrf_id
)
96 vrf
= vrf_lookup_by_id(vrf_id
);
98 return ((struct pbr_vrf
*)vrf
->info
);
103 struct pbr_vrf
*pbr_vrf_lookup_by_name(const char *name
)
108 name
= VRF_DEFAULT_NAME
;
110 vrf
= vrf_lookup_by_name(name
);
112 return ((struct pbr_vrf
*)vrf
->info
);
117 bool pbr_vrf_is_enabled(const struct pbr_vrf
*pbr_vrf
)
119 return vrf_is_enabled(pbr_vrf
->vrf
) ? true : false;
122 bool pbr_vrf_is_valid(const struct pbr_vrf
*pbr_vrf
)
124 if (vrf_is_backend_netns())
130 return pbr_vrf_is_enabled(pbr_vrf
);
133 void pbr_vrf_init(void)
135 vrf_init(pbr_vrf_new
, pbr_vrf_enable
, pbr_vrf_disable
, pbr_vrf_delete
,