Line data Source code
1 : /* 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 : 18 : static void 19 0 : send_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 0 : rmp = vl_msg_api_alloc (sizeof (*rmp)); 25 0 : clib_memset (rmp, 0, sizeof (*rmp)); 26 0 : rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_PT_IFACE_DETAILS); 27 : 28 0 : rmp->sw_if_index = ntohl (t->iface); 29 0 : rmp->id = ntohs (t->id); 30 0 : rmp->ingress_load = t->ingress_load; 31 0 : rmp->egress_load = t->egress_load; 32 0 : rmp->tts_template = t->tts_template; 33 : 34 0 : rmp->context = context; 35 : 36 0 : vl_api_send_msg (reg, (u8 *) rmp); 37 0 : } 38 : 39 : static void 40 0 : vl_api_sr_pt_iface_dump_t_handler (vl_api_sr_pt_iface_dump_t *mp) 41 : { 42 : vl_api_registration_t *reg; 43 0 : sr_pt_main_t *pt = &sr_pt_main; 44 : sr_pt_iface_t *t; 45 : 46 0 : reg = vl_api_client_index_to_registration (mp->client_index); 47 0 : if (!reg) 48 0 : return; 49 : 50 0 : pool_foreach (t, pt->sr_pt_iface) 51 : { 52 0 : send_sr_pt_iface_details (t, reg, mp->context); 53 : } 54 : } 55 : 56 : static void 57 0 : vl_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 0 : int rv = 0; 61 : 62 0 : VALIDATE_SW_IF_INDEX (mp); 63 : 64 0 : rv = sr_pt_add_iface (ntohl (mp->sw_if_index), ntohs (mp->id), 65 0 : mp->ingress_load, mp->egress_load, mp->tts_template); 66 : 67 0 : BAD_SW_IF_INDEX_LABEL; 68 0 : REPLY_MACRO (VL_API_SR_PT_IFACE_ADD_REPLY); 69 : } 70 : 71 : static void 72 0 : vl_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 0 : int rv = 0; 76 : 77 0 : VALIDATE_SW_IF_INDEX (mp); 78 : 79 0 : rv = sr_pt_del_iface (ntohl (mp->sw_if_index)); 80 : 81 0 : BAD_SW_IF_INDEX_LABEL; 82 0 : REPLY_MACRO (VL_API_SR_PT_IFACE_DEL_REPLY); 83 : } 84 : 85 : #include <vnet/srv6/sr_pt.api.c> 86 : static clib_error_t * 87 575 : sr_pt_api_hookup (vlib_main_t *vm) 88 : { 89 : /* 90 : * Set up the (msg_name, crc, message-id) table 91 : */ 92 575 : REPLY_MSG_ID_BASE = setup_message_id_table (); 93 : 94 575 : return 0; 95 : } 96 : 97 12095 : VLIB_API_INIT_FUNCTION (sr_pt_api_hookup);