FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
urpf_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 
16 #include <urpf/urpf.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vnet/ip/ip_types_api.h>
19 
20 #include <vpp/app/version.h>
21 
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 
25 /* define message IDs */
26 #include <vnet/format_fns.h>
27 #include <urpf/urpf.api_enum.h>
28 #include <urpf/urpf.api_types.h>
29 
30 /**
31  * Base message ID fot the plugin
32  */
34 #define REPLY_MSG_ID_BASE urpf_base_msg_id
35 
37 
38 static int
39 urpf_mode_decode (vl_api_urpf_mode_t in, urpf_mode_t * out)
40 {
41  if (0)
42  ;
43 #define _(a,b) \
44  else if (URPF_API_MODE_##a == in) \
45  { \
46  *out = URPF_MODE_##a; \
47  return (0); \
48  }
50 #undef _
51  return (VNET_API_ERROR_INVALID_VALUE);
52 }
53 
54 static void
56 {
57  vl_api_urpf_update_reply_t *rmp;
60  int rv = 0;
61 
63 
64  rv = urpf_mode_decode (mp->mode, &mode);
65 
66  if (rv)
67  goto done;
68 
69  rv = ip_address_family_decode (mp->af, &af);
70 
71  if (rv)
72  goto done;
73 
74  urpf_update (mode, htonl (mp->sw_if_index), af,
75  (mp->is_input ? VLIB_RX : VLIB_TX));
76 
78 done:
79  REPLY_MACRO (VL_API_URPF_UPDATE_REPLY);
80 }
81 
82 #include <urpf/urpf.api.c>
83 
84 static clib_error_t *
86 {
87  /* Ask for a correctly-sized block of API message decode slots */
89 
90  return 0;
91 }
92 
94 
95 /* *INDENT-OFF* */
97  .version = VPP_BUILD_VER,
98  .description = "Unicast Reverse Path Forwarding (uRPF)",
99 };
100 /* *INDENT-ON* */
101 
102 /*
103  * fd.io coding-style-patch-verification: ON
104  *
105  * Local Variables:
106  * eval: (c-set-style "gnu")
107  * End:
108  */
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
api.h
vl_api_urpf_update_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: urpf.api:50
urpf_api_init
static clib_error_t * urpf_api_init(vlib_main_t *vm)
Definition: urpf_api.c:85
urpf_update
void urpf_update(urpf_mode_t mode, u32 sw_if_index, ip_address_family_t af, vlib_dir_t dir)
Definition: urpf.c:99
urpf_mode_decode
static int urpf_mode_decode(vl_api_urpf_mode_t in, urpf_mode_t *out)
Definition: urpf_api.c:39
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
vl_api_urpf_update_t::af
vl_api_address_family_t af
Definition: urpf.api:49
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
urpf.h
vl_api_urpf_update_t::is_input
bool is_input[default=true]
Definition: urpf.api:47
urpf_base_msg_id
static u32 urpf_base_msg_id
Base message ID fot the plugin.
Definition: urpf_api.c:33
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
ip_address_family_decode
int ip_address_family_decode(vl_api_address_family_t af, ip_address_family_t *out)
Conversion functions to/from (decode/encode) API types to VPP internal types.
Definition: ip_types_api.c:34
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
foreach_urpf_mode
@ foreach_urpf_mode
Definition: urpf.h:29
vl_api_urpf_update_t::mode
vl_api_urpf_mode_t mode
Definition: urpf.api:48
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
plugin.h
format_fns.h
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
urpf_mode_t
enum urpf_mode_t_ urpf_mode_t
api_helper_macros.h
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
rv
int __clib_unused rv
Definition: application.c:491
vl_api_urpf_update_t
Enable uRPF on a given interface in a given direction.
Definition: urpf.api:43
ip_types_api.h
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
vl_api_urpf_update_t_handler
static void vl_api_urpf_update_t_handler(vl_api_urpf_update_t *mp)
Definition: urpf_api.c:55
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t