blob: a9a8cc0a444555766fd3e07fc97964dcae546dc1 [file] [log] [blame]
Pavel Kotucek6899a302017-06-08 08:46:10 +02001/*
2 *------------------------------------------------------------------
3 * p2p_ethernet_api.c - p2p ethernet api
4 *
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
Pavel Kotucek6899a302017-06-08 08:46:10 +020022#include <vnet/ethernet/p2p_ethernet.h>
23
Filip Tehlar41ff1eb2021-06-21 13:45:44 +000024#include <vnet/format_fns.h>
25#include <vnet/ethernet/p2p_ethernet.api_enum.h>
26#include <vnet/ethernet/p2p_ethernet.api_types.h>
Pavel Kotucek6899a302017-06-08 08:46:10 +020027
Filip Tehlar41ff1eb2021-06-21 13:45:44 +000028#define REPLY_MSG_ID_BASE p2p_main.msg_id_base
Pavel Kotucek6899a302017-06-08 08:46:10 +020029#include <vlibapi/api_helper_macros.h>
30
Pavel Kotucek6899a302017-06-08 08:46:10 +020031void
32vl_api_p2p_ethernet_add_t_handler (vl_api_p2p_ethernet_add_t * mp)
33{
34 vl_api_p2p_ethernet_add_reply_t *rmp;
35 vlib_main_t *vm = vlib_get_main ();
36 int rv;
37
38 u32 parent_if_index = htonl (mp->parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020039 u32 sub_id = htonl (mp->subif_id);
Dave Barach13f64ce2020-05-08 08:16:06 -040040 u32 p2pe_if_index = ~0;
Pavel Kotucek6899a302017-06-08 08:46:10 +020041 u8 remote_mac[6];
42
Dave Barachbdfe5952020-05-04 12:33:18 -040043 if (!vnet_sw_if_index_is_api_valid (parent_if_index))
44 {
45 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
46 goto bad_sw_if_index;
47 }
48 if (!vnet_sw_if_index_is_api_valid (sub_id))
49 {
50 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
51 goto bad_sw_if_index;
52 }
53
Pavel Kotucek6899a302017-06-08 08:46:10 +020054 clib_memcpy (remote_mac, mp->remote_mac, 6);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020055 rv =
56 p2p_ethernet_add_del (vm, parent_if_index, remote_mac, sub_id, 1,
57 &p2pe_if_index);
Pavel Kotucek6899a302017-06-08 08:46:10 +020058
Dave Barachbdfe5952020-05-04 12:33:18 -040059 BAD_SW_IF_INDEX_LABEL;
60
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020061 /* *INDENT-OFF* */
62 REPLY_MACRO2(VL_API_P2P_ETHERNET_ADD_REPLY,
63 ({
64 rmp->sw_if_index = htonl(p2pe_if_index);
65 }));
Dave Barachbdfe5952020-05-04 12:33:18 -040066
67
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020068 /* *INDENT-ON* */
Pavel Kotucek6899a302017-06-08 08:46:10 +020069}
70
71void
72vl_api_p2p_ethernet_del_t_handler (vl_api_p2p_ethernet_del_t * mp)
73{
74 vl_api_p2p_ethernet_del_reply_t *rmp;
75 vlib_main_t *vm = vlib_get_main ();
76 int rv;
77
78 u32 parent_if_index = htonl (mp->parent_if_index);
79 u8 remote_mac[6];
80
Dave Barachbdfe5952020-05-04 12:33:18 -040081 if (!vnet_sw_if_index_is_api_valid (parent_if_index))
82 {
83 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
84 goto bad_sw_if_index;
85 }
86
Pavel Kotucek6899a302017-06-08 08:46:10 +020087 clib_memcpy (remote_mac, mp->remote_mac, 6);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020088 rv = p2p_ethernet_add_del (vm, parent_if_index, remote_mac, ~0, 0, 0);
Pavel Kotucek6899a302017-06-08 08:46:10 +020089
Dave Barachbdfe5952020-05-04 12:33:18 -040090 BAD_SW_IF_INDEX_LABEL;
Pavel Kotucek6899a302017-06-08 08:46:10 +020091 REPLY_MACRO (VL_API_P2P_ETHERNET_DEL_REPLY);
92}
93
Filip Tehlar41ff1eb2021-06-21 13:45:44 +000094#include <vnet/ethernet/p2p_ethernet.api.c>
Pavel Kotucek6899a302017-06-08 08:46:10 +020095static clib_error_t *
96p2p_ethernet_api_hookup (vlib_main_t * vm)
97{
Pavel Kotucek6899a302017-06-08 08:46:10 +020098 /*
99 * Set up the (msg_name, crc, message-id) table
100 */
Filip Tehlar41ff1eb2021-06-21 13:45:44 +0000101 REPLY_MSG_ID_BASE = setup_message_id_table ();
Pavel Kotucek6899a302017-06-08 08:46:10 +0200102
103 return 0;
104}
105
106VLIB_API_INIT_FUNCTION (p2p_ethernet_api_hookup);
107
108/*
109 * fd.io coding-style-patch-verification: ON
110 *
111 * Local Variables:
112 * eval: (c-set-style "gnu")
113 * End:
114 */