blob: b0b67a210fbf237a07946cf46bcfb40981246e1c [file] [log] [blame]
Julian Klaiberb79d09b2022-11-08 08:44:06 +01001/* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2022 Cisco Systems, Inc.
3 */
4
5#include <vnet/vnet.h>
6#include <vlibmemory/api.h>
7#include <vnet/srv6/sr_pt.h>
8
9#include <vnet/interface.h>
10#include <vnet/api_errno.h>
11
12#include <vnet/srv6/sr_pt.api_enum.h>
13#include <vnet/srv6/sr_pt.api_types.h>
14
15#define REPLY_MSG_ID_BASE sr_pt_main.msg_id_base
16#include <vlibapi/api_helper_macros.h>
17
18static void
19send_sr_pt_iface_details (sr_pt_iface_t *t, vl_api_registration_t *reg,
20 u32 context)
21{
22 vl_api_sr_pt_iface_details_t *rmp;
23
24 rmp = vl_msg_api_alloc (sizeof (*rmp));
25 clib_memset (rmp, 0, sizeof (*rmp));
26 rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_PT_IFACE_DETAILS);
27
28 rmp->sw_if_index = ntohl (t->iface);
29 rmp->id = ntohs (t->id);
30 rmp->ingress_load = t->ingress_load;
31 rmp->egress_load = t->egress_load;
32 rmp->tts_template = t->tts_template;
33
34 rmp->context = context;
35
36 vl_api_send_msg (reg, (u8 *) rmp);
37}
38
39static void
40vl_api_sr_pt_iface_dump_t_handler (vl_api_sr_pt_iface_dump_t *mp)
41{
42 vl_api_registration_t *reg;
43 sr_pt_main_t *pt = &sr_pt_main;
44 sr_pt_iface_t *t;
45
46 reg = vl_api_client_index_to_registration (mp->client_index);
47 if (!reg)
48 return;
49
50 pool_foreach (t, pt->sr_pt_iface)
51 {
52 send_sr_pt_iface_details (t, reg, mp->context);
53 }
54}
55
56static void
57vl_api_sr_pt_iface_add_t_handler (vl_api_sr_pt_iface_add_t *mp)
58{
59 vl_api_sr_pt_iface_add_reply_t *rmp;
60 int rv = 0;
61
62 VALIDATE_SW_IF_INDEX (mp);
63
64 rv = sr_pt_add_iface (ntohl (mp->sw_if_index), ntohs (mp->id),
65 mp->ingress_load, mp->egress_load, mp->tts_template);
66
67 BAD_SW_IF_INDEX_LABEL;
68 REPLY_MACRO (VL_API_SR_PT_IFACE_ADD_REPLY);
69}
70
71static void
72vl_api_sr_pt_iface_del_t_handler (vl_api_sr_pt_iface_del_t *mp)
73{
74 vl_api_sr_pt_iface_del_reply_t *rmp;
75 int rv = 0;
76
77 VALIDATE_SW_IF_INDEX (mp);
78
79 rv = sr_pt_del_iface (ntohl (mp->sw_if_index));
80
81 BAD_SW_IF_INDEX_LABEL;
82 REPLY_MACRO (VL_API_SR_PT_IFACE_DEL_REPLY);
83}
84
85#include <vnet/srv6/sr_pt.api.c>
86static clib_error_t *
87sr_pt_api_hookup (vlib_main_t *vm)
88{
89 /*
90 * Set up the (msg_name, crc, message-id) table
91 */
92 REPLY_MSG_ID_BASE = setup_message_id_table ();
93
94 return 0;
95}
96
97VLIB_API_INIT_FUNCTION (sr_pt_api_hookup);