2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 *------------------------------------------------------------------
17 * un.c - SRv6 Masquerading Proxy (AM) function
18 *------------------------------------------------------------------
21 #include <vnet/vnet.h>
22 #include <vnet/adj/adj.h>
23 #include <vnet/plugin/plugin.h>
24 #include <vpp/app/version.h>
25 #include <srv6-un/un.h>
27 unsigned char function_name[] = "SRv6-uN";
28 unsigned char keyword_str[] = "uN(32b+16b)";
29 unsigned char def_str[] = "SRv6 uSID uN";
30 unsigned char params_str[] = "";
31 u8 prefix_length = 48;
33 srv6_un_main_t srv6_un_main;
35 /*****************************************/
36 /* SRv6 LocalSID instantiation and removal functions */
38 srv6_un_localsid_creation_fn (ip6_sr_localsid_t * localsid)
40 srv6_un_localsid_t *ls_mem = localsid->plugin_mem;
47 srv6_un_localsid_removal_fn (ip6_sr_localsid_t * localsid)
51 /* Clean up local SID memory */
52 clib_mem_free (localsid->plugin_mem);
57 /**********************************/
58 /* SRv6 LocalSID format functions */
60 * Prints nicely the parameters of a localsid
61 * Example: print "Table 5"
64 format_srv6_un_localsid (u8 * s, va_list * args)
66 srv6_un_localsid_t *ls_mem = va_arg (*args, void *);
68 return (format (s, "Shift:\t\t%u", ls_mem->shift));
72 * Process the parameters of a localsid
73 * Example: process from:
74 * sr localsid address cafe::1 behavior new_srv6_localsid 5
75 * everything from behavior on... so in this case 'new_srv6_localsid 5'
76 * Notice that it MUST match the keyword_str and params_str defined above.
79 unformat_srv6_un_localsid (unformat_input_t * input, va_list * args)
81 void **plugin_mem_p = va_arg (*args, void **);
82 srv6_un_localsid_t *ls_mem;
84 if (unformat (input, "uN(32b+16b)"))
86 /* Allocate a portion of memory */
87 ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
89 /* Set to zero the memory */
90 clib_memset (ls_mem, 0, sizeof *ls_mem);
92 /* Dont forget to add it to the localsid */
93 *plugin_mem_p = ls_mem;
99 /*************************/
100 /* SRv6 LocalSID FIB DPO */
102 format_srv6_un_dpo (u8 * s, va_list * args)
104 index_t index = va_arg (*args, index_t);
105 CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
107 return (format (s, "SR: shift-and-forward 16b:[%u]", index));
111 srv6_un_dpo_lock (dpo_id_t * dpo)
116 srv6_un_dpo_unlock (dpo_id_t * dpo)
120 const static dpo_vft_t srv6_un_vft = {
121 .dv_lock = srv6_un_dpo_lock,
122 .dv_unlock = srv6_un_dpo_unlock,
123 .dv_format = format_srv6_un_dpo,
126 const static char *const srv6_un_ip6_nodes[] = {
131 const static char *const *const srv6_un_nodes[DPO_PROTO_NUM] = {
132 [DPO_PROTO_IP6] = srv6_un_ip6_nodes,
135 /**********************/
136 static clib_error_t *
137 srv6_un_init (vlib_main_t * vm)
139 srv6_un_main_t *sm = &srv6_un_main;
143 sm->vnet_main = vnet_get_main ();
146 sm->srv6_un16_dpo_type =
147 dpo_register_new_type (&srv6_un_vft, srv6_un_nodes);
149 /* Register SRv6 LocalSID */
150 rv = sr_localsid_register_function (vm,
156 &sm->srv6_un16_dpo_type,
157 format_srv6_un_localsid,
158 unformat_srv6_un_localsid,
159 srv6_un_localsid_creation_fn,
160 srv6_un_localsid_removal_fn);
162 clib_error_return (0, "SRv6 LocalSID function could not be registered.");
164 sm->srv6_localsid_behavior_id = rv;
171 VLIB_INIT_FUNCTION (srv6_un_init);
173 VLIB_PLUGIN_REGISTER () = {
174 .version = VPP_BUILD_VER,
175 .description = "Segment Routing Shift And Forward uN 16b",
180 * fd.io coding-style-patch-verification: ON
183 * eval: (c-set-style "gnu")