FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
dslite_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * dslite_api.c - DS-Lite API
4  *
5  * Copyright (c) 2019 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 #include <vnet/ip/ip_types_api.h>
20 #include <nat/dslite/dslite.h>
21 #include <nat/dslite/dslite.api_enum.h>
22 #include <nat/dslite/dslite.api_types.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/fib/fib_table.h>
25 #include <vlibmemory/api.h>
26 
27 #define REPLY_MSG_ID_BASE dm->msg_id_base
29 
30 static void
32 {
33  vl_api_dslite_set_aftr_addr_reply_t *rmp;
35  int rv = 0;
36  ip6_address_t ip6_addr;
37  ip4_address_t ip4_addr;
38 
39  memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
40  memcpy (&ip4_addr.as_u8, mp->ip4_addr, 4);
41 
42  rv = dslite_set_aftr_ip6_addr (dm, &ip6_addr);
43  if (rv == 0)
44  rv = dslite_set_aftr_ip4_addr (dm, &ip4_addr);
45 
46  REPLY_MACRO (VL_API_DSLITE_SET_AFTR_ADDR_REPLY);
47 }
48 
49 static void
51 {
54  int rv = 0;
55 
56  /* *INDENT-OFF* */
57  REPLY_MACRO2 (VL_API_DSLITE_GET_AFTR_ADDR_REPLY,
58  ({
59  memcpy (rmp->ip4_addr, &dm->aftr_ip4_addr.as_u8, 4);
60  memcpy (rmp->ip6_addr, &dm->aftr_ip6_addr.as_u8, 16);
61  }))
62  /* *INDENT-ON* */
63 }
64 
65 static void
67 {
68  vl_api_dslite_set_b4_addr_reply_t *rmp;
70  int rv = 0;
71  ip6_address_t ip6_addr;
72  ip4_address_t ip4_addr;
73 
74  memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
75  memcpy (&ip4_addr.as_u8, mp->ip4_addr, 4);
76 
77  rv = dslite_set_b4_ip6_addr (dm, &ip6_addr);
78  if (rv == 0)
79  rv = dslite_set_b4_ip4_addr (dm, &ip4_addr);
80 
81  REPLY_MACRO (VL_API_DSLITE_SET_B4_ADDR_REPLY);
82 }
83 
84 static void
86 {
89  int rv = 0;
90 
91  /* *INDENT-OFF* */
92  REPLY_MACRO2 (VL_API_DSLITE_GET_B4_ADDR_REPLY,
93  ({
94  memcpy (rmp->ip4_addr, &dm->b4_ip4_addr.as_u8, 4);
95  memcpy (rmp->ip6_addr, &dm->b4_ip6_addr.as_u8, 16);
96  }))
97  /* *INDENT-ON* */
98 }
99 
100 static void
103 {
104  vl_api_dslite_add_del_pool_addr_range_reply_t *rmp;
105  dslite_main_t *dm = &dslite_main;
106  int rv = 0;
107  ip4_address_t this_addr;
108  u32 start_host_order, end_host_order;
109  int count;
110  u32 *tmp;
111 
112  tmp = (u32 *) mp->start_addr;
113  start_host_order = clib_host_to_net_u32 (tmp[0]);
114  tmp = (u32 *) mp->end_addr;
115  end_host_order = clib_host_to_net_u32 (tmp[0]);
116 
117  // TODO:
118  // end_host_order < start_host_order
119 
120  count = (end_host_order - start_host_order) + 1;
121  memcpy (&this_addr.as_u8, mp->start_addr, 4);
122 
123  rv = nat_add_del_ip4_pool_addrs (&dm->pool, this_addr, count, mp->is_add, 0);
124 
125  REPLY_MACRO (VL_API_DSLITE_ADD_DEL_POOL_ADDR_RANGE_REPLY);
126 }
127 
128 static void
131 {
132  dslite_main_t *dm = &dslite_main;
134 
135  rmp = vl_msg_api_alloc (sizeof (*rmp));
136 
137  clib_memset (rmp, 0, sizeof (*rmp));
138 
139  rmp->_vl_msg_id = ntohs (VL_API_DSLITE_ADDRESS_DETAILS + dm->msg_id_base);
140  clib_memcpy (rmp->ip_address, &(a->addr), 4);
141  rmp->context = context;
142 
143  vl_api_send_msg (reg, (u8 *) rmp);
144 }
145 
146 static void
148 {
150  dslite_main_t *dm = &dslite_main;
152 
154  if (!reg)
155  return;
156 
157  /* *INDENT-OFF* */
158  vec_foreach (a, dm->pool.pool_addr)
159  {
161  }
162  /* *INDENT-ON* */
163 }
164 
165 /* API definitions */
166 #include <vnet/format_fns.h>
167 #include <nat/dslite/dslite.api.c>
168 
169 /* Set up the API message handling tables */
170 clib_error_t *
172 {
173  dslite_main_t *dm = &dslite_main;
174 
176  return 0;
177 }
vl_api_dslite_get_aftr_addr_reply_t
Response to get AFTR IPv6 and IPv4 addresses.
Definition: dslite.api:94
tmp
u32 * tmp
Definition: interface_output.c:1096
nat_ip4_pool_addr_s
Definition: alloc.h:40
dslite_api_hookup
clib_error_t * dslite_api_hookup(vlib_main_t *vm)
Definition: dslite_api.c:171
vl_api_dslite_address_dump_t
Dump DS-Lite addresses.
Definition: dslite.api:52
vl_api_dslite_get_b4_addr_reply_t
Response to get B4 IPv6 and IPv4 addresses.
Definition: dslite.api:129
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
vl_api_dslite_get_aftr_addr_t
Get AFTR IPv6 and IPv4 addresses.
Definition: dslite.api:83
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
dslite_set_aftr_ip6_addr
int dslite_set_aftr_ip6_addr(dslite_main_t *dm, ip6_address_t *addr)
Definition: dslite.c:141
vl_api_dslite_set_aftr_addr_t
Set AFTR IPv6 and IPv4 addresses.
Definition: dslite.api:72
dslite.h
dslite_main_t
Definition: dslite.h:103
vl_api_dslite_address_dump_t::client_index
u32 client_index
Definition: dslite.api:53
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
vl_api_dslite_set_aftr_addr_t_handler
static void vl_api_dslite_set_aftr_addr_t_handler(vl_api_dslite_set_aftr_addr_t *mp)
Definition: dslite_api.c:31
dslite_main_t::pool
nat_ip4_pool_t pool
Definition: dslite.h:115
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_dslite_get_b4_addr_t_handler
static void vl_api_dslite_get_b4_addr_t_handler(vl_api_dslite_get_b4_addr_t *mp)
Definition: dslite_api.c:85
fib_table.h
vl_api_dslite_set_b4_addr_t_handler
static void vl_api_dslite_set_b4_addr_t_handler(vl_api_dslite_set_b4_addr_t *mp)
Definition: dslite_api.c:66
vl_api_dslite_get_b4_addr_t
Get B4 IPv6 and IPv4 addresses.
Definition: dslite.api:118
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vl_api_dslite_get_b4_addr_reply_t::ip4_addr
vl_api_ip4_address_t ip4_addr
Definition: dslite.api:132
vl_api_dslite_set_aftr_addr_t::ip6_addr
vl_api_ip6_address_t ip6_addr
Definition: dslite.api:76
vl_api_dslite_address_details_t
DS-Lite address details response.
Definition: dslite.api:61
dslite_main_t::aftr_ip6_addr
ip6_address_t aftr_ip6_addr
Definition: dslite.h:105
vl_api_dslite_set_b4_addr_t::ip6_addr
vl_api_ip6_address_t ip6_addr
Definition: dslite.api:111
dslite_main_t::msg_id_base
u16 msg_id_base
Definition: dslite.h:131
vl_api_dslite_add_del_pool_addr_range_t::end_addr
vl_api_ip4_address_t end_addr
Definition: dslite.api:44
send_dslite_address_details
static void send_dslite_address_details(nat_ip4_pool_addr_t *a, vl_api_registration_t *reg, u32 context)
Definition: dslite_api.c:129
count
u8 count
Definition: dhcp.api:208
dslite_set_b4_ip4_addr
int dslite_set_b4_ip4_addr(dslite_main_t *dm, ip4_address_t *addr)
Definition: dslite.c:220
dslite_main_t::aftr_ip4_addr
ip4_address_t aftr_ip4_addr
Definition: dslite.h:106
vl_api_dslite_get_aftr_addr_reply_t::ip6_addr
vl_api_ip6_address_t ip6_addr
Definition: dslite.api:98
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
vl_api_dslite_add_del_pool_addr_range_t::is_add
bool is_add
Definition: dslite.api:45
vl_api_dslite_address_dump_t_handler
static void vl_api_dslite_address_dump_t_handler(vl_api_dslite_address_dump_t *mp)
Definition: dslite_api.c:147
dslite_set_aftr_ip4_addr
int dslite_set_aftr_ip4_addr(dslite_main_t *dm, ip4_address_t *addr)
Definition: dslite.c:180
vl_api_dslite_get_aftr_addr_reply_t::ip4_addr
vl_api_ip4_address_t ip4_addr
Definition: dslite.api:97
vl_api_dslite_address_details_t::ip_address
vl_api_ip4_address_t ip_address
Definition: dslite.api:63
vl_api_dslite_add_del_pool_addr_range_t::start_addr
vl_api_ip4_address_t start_addr
Definition: dslite.api:43
vl_api_dslite_get_aftr_addr_t_handler
static void vl_api_dslite_get_aftr_addr_t_handler(vl_api_dslite_get_aftr_addr_t *mp)
Definition: dslite_api.c:50
ip4_address_t
Definition: ip4_packet.h:50
vl_api_dslite_get_b4_addr_reply_t::ip6_addr
vl_api_ip6_address_t ip6_addr
Definition: dslite.api:133
ip4_address_t::as_u8
u8 as_u8[4]
Definition: ip4_packet.h:55
nat_ip4_pool_s::pool_addr
nat_ip4_pool_addr_t * pool_addr
Definition: alloc.h:64
format_fns.h
ip.h
u32
unsigned int u32
Definition: types.h:88
vl_api_dslite_set_aftr_addr_t::ip4_addr
vl_api_ip4_address_t ip4_addr
Definition: dslite.api:75
dslite_main_t::b4_ip6_addr
ip6_address_t b4_ip6_addr
Definition: dslite.h:107
api_helper_macros.h
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
vl_api_dslite_add_del_pool_addr_range_t_handler
static void vl_api_dslite_add_del_pool_addr_range_t_handler(vl_api_dslite_add_del_pool_addr_range_t *mp)
Definition: dslite_api.c:102
dslite_set_b4_ip6_addr
int dslite_set_b4_ip6_addr(dslite_main_t *dm, ip6_address_t *addr)
Definition: dslite.c:187
vl_api_dslite_set_b4_addr_t::ip4_addr
vl_api_ip4_address_t ip4_addr
Definition: dslite.api:110
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
nat_add_del_ip4_pool_addrs
int nat_add_del_ip4_pool_addrs(nat_ip4_pool_t *pool, ip4_address_t addr, u32 count, u8 is_add, void *opaque)
Definition: alloc.c:76
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
dslite_main_t::b4_ip4_addr
ip4_address_t b4_ip4_addr
Definition: dslite.h:108
context
u32 context
Definition: ip.api:852
rv
int __clib_unused rv
Definition: application.c:491
vl_api_dslite_address_details_t::context
u32 context
Definition: dslite.api:62
dslite_main
dslite_main_t dslite_main
Definition: dslite.c:21
vl_api_dslite_set_b4_addr_t
Set B4 IPv6 and IPv4 addresses.
Definition: dslite.api:107
vl_api_dslite_add_del_pool_addr_range_t
Add/delete address range to DS-Lite pool.
Definition: dslite.api:40
ip_types_api.h
vl_api_dslite_address_dump_t::context
u32 context
Definition: dslite.api:54
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199