gbp: migrate old MULTIARCH macros to VLIB_NODE_FN
[vpp.git] / src / plugins / gbp / gbp_fwd.c
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <plugins/gbp/gbp.h>
16 #include <vnet/l2/l2_input.h>
17 #include <plugins/gbp/gbp_learn.h>
18
19 /**
20  * Grouping of global data for the GBP source EPG classification feature
21  */
22 typedef struct gbp_fwd_main_t_
23 {
24   /**
25    * Next nodes for L2 output features
26    */
27   u32 l2_input_feat_next[32];
28 } gbp_fwd_main_t;
29
30 static gbp_fwd_main_t gbp_fwd_main;
31
32 gbp_policy_main_t gbp_policy_main;
33
34 void
35 gbp_learn_enable (u32 sw_if_index, gbb_learn_mode_t mode)
36 {
37   if (GBP_LEARN_MODE_L2 == mode)
38     {
39       l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_GBP_LEARN, 1);
40     }
41   else
42     {
43       vnet_feature_enable_disable ("ip4-unicast",
44                                    "gbp-learn-ip4", sw_if_index, 1, 0, 0);
45       vnet_feature_enable_disable ("ip6-unicast",
46                                    "gbp-learn-ip6", sw_if_index, 1, 0, 0);
47     }
48 }
49
50 void
51 gbp_learn_disable (u32 sw_if_index, gbb_learn_mode_t mode)
52 {
53   if (GBP_LEARN_MODE_L2 == mode)
54     {
55       l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_GBP_LEARN, 0);
56     }
57   else
58     {
59       vnet_feature_enable_disable ("ip4-unicast",
60                                    "gbp-learn-ip4", sw_if_index, 0, 0, 0);
61       vnet_feature_enable_disable ("ip6-unicast",
62                                    "gbp-learn-ip6", sw_if_index, 0, 0, 0);
63     }
64 }
65
66 static clib_error_t *
67 gbp_fwd_init (vlib_main_t * vm)
68 {
69   gbp_fwd_main_t *gpm = &gbp_fwd_main;
70   vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "gbp-fwd");
71
72   /* Initialize the feature next-node indices */
73   feat_bitmap_init_next_nodes (vm,
74                                node->index,
75                                L2INPUT_N_FEAT,
76                                l2input_get_feat_names (),
77                                gpm->l2_input_feat_next);
78
79   return 0;
80 }
81
82 VLIB_INIT_FUNCTION (gbp_fwd_init);
83
84 /*
85  * fd.io coding-style-patch-verification: ON
86  *
87  * Local Variables:
88  * eval: (c-set-style "gnu")
89  * End:
90  */