3 * Copyright (C) 2018 Cumulus Networks, Inc.
6 * This program 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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
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 "srcdest_table.h"
26 #include "northbound_cli.h"
28 #include "static_vrf.h"
29 #include "static_routes.h"
30 #include "static_zebra.h"
32 DEFINE_MTYPE_STATIC(STATIC
, STATIC_RTABLE_INFO
, "Static Route Table Info");
34 static struct static_vrf
*static_vrf_alloc(void)
36 struct route_table
*table
;
37 struct static_vrf
*svrf
;
38 struct stable_info
*info
;
42 svrf
= XCALLOC(MTYPE_STATIC_RTABLE_INFO
, sizeof(struct static_vrf
));
44 for (afi
= AFI_IP
; afi
<= AFI_IP6
; afi
++) {
45 for (safi
= SAFI_UNICAST
; safi
<= SAFI_MULTICAST
; safi
++) {
47 table
= srcdest_table_init();
49 table
= route_table_init();
51 info
= XCALLOC(MTYPE_STATIC_RTABLE_INFO
,
52 sizeof(struct stable_info
));
56 route_table_set_info(table
, info
);
58 table
->cleanup
= zebra_stable_node_cleanup
;
59 svrf
->stable
[afi
][safi
] = table
;
65 static int static_vrf_new(struct vrf
*vrf
)
67 struct static_vrf
*svrf
;
69 svrf
= static_vrf_alloc();
76 static int static_vrf_enable(struct vrf
*vrf
)
78 static_zebra_vrf_register(vrf
);
80 static_fixup_vrf_ids(vrf
->info
);
85 static int static_vrf_disable(struct vrf
*vrf
)
87 static_zebra_vrf_unregister(vrf
);
91 static int static_vrf_delete(struct vrf
*vrf
)
93 struct route_table
*table
;
94 struct static_vrf
*svrf
;
100 for (afi
= AFI_IP
; afi
<= AFI_IP6
; afi
++) {
101 for (safi
= SAFI_UNICAST
; safi
<= SAFI_MULTICAST
; safi
++) {
102 table
= svrf
->stable
[afi
][safi
];
103 info
= route_table_get_info(table
);
104 route_table_finish(table
);
105 XFREE(MTYPE_STATIC_RTABLE_INFO
, info
);
106 svrf
->stable
[afi
][safi
] = NULL
;
109 XFREE(MTYPE_STATIC_RTABLE_INFO
, svrf
);
113 /* Lookup the static routing table in a VRF. */
114 struct route_table
*static_vrf_static_table(afi_t afi
, safi_t safi
,
115 struct static_vrf
*svrf
)
120 if (afi
>= AFI_MAX
|| safi
>= SAFI_MAX
)
123 return svrf
->stable
[afi
][safi
];
126 struct static_vrf
*static_vrf_lookup_by_name(const char *name
)
131 name
= VRF_DEFAULT_NAME
;
133 vrf
= vrf_lookup_by_name(name
);
135 return ((struct static_vrf
*)vrf
->info
);
140 static int static_vrf_config_write(struct vty
*vty
)
142 struct lyd_node
*dnode
;
145 dnode
= yang_dnode_get(running_config
->dnode
, "/frr-routing:routing");
147 nb_cli_show_dnode_cmds(vty
, dnode
, false);
154 void static_vrf_init(void)
156 vrf_init(static_vrf_new
, static_vrf_enable
, static_vrf_disable
,
159 vrf_cmd_init(static_vrf_config_write
);
162 void static_vrf_terminate(void)