FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
ip_types_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <vnet/ip/ip_types_api.h>
17 
18 #define vl_typedefs /* define message structures */
19 #include <vnet/vnet_all_api_h.h>
20 #undef vl_typedefs
21 
22 #define vl_endianfun /* define message structures */
23 #include <vnet/vnet_all_api_h.h>
24 #undef vl_endianfun
25 
26 /* instantiate all the print functions we know about */
27 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
28 #define vl_printfun
29 #include <vnet/vnet_all_api_h.h>
30 #undef vl_printfun
31 
32 
33 void
34 ip_address_decode (const vl_api_address_t * in, ip46_address_t * out)
35 {
36  switch (in->af)
37  {
38  case ADDRESS_IP4:
39  memset (out, 0, sizeof (*out));
40  clib_memcpy (&out->ip4, &in->un.ip4, sizeof (out->ip4));
41  break;
42  case ADDRESS_IP6:
43  clib_memcpy (&out->ip6, &in->un.ip6, sizeof (out->ip6));
44  break;
45  }
46 }
47 
48 void
49 ip_address_encode (const ip46_address_t * in, vl_api_address_t * out)
50 {
51  if (ip46_address_is_ip4 (in))
52  {
53  memset (out, 0, sizeof (*out));
54  out->af = ADDRESS_IP4;
55  clib_memcpy (&out->un.ip4, &in->ip4, sizeof (out->un.ip4));
56  }
57  else
58  {
59  out->af = ADDRESS_IP6;
60  clib_memcpy (&out->un.ip6, &in->ip6, sizeof (out->un.ip6));
61  }
62 }
63 
64 void
65 ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
66 {
67  switch (in->address.af)
68  {
69  case ADDRESS_IP4:
71  break;
72  case ADDRESS_IP6:
74  break;
75  }
76  out->fp_len = in->address_length;
77  ip_address_decode (&in->address, &out->fp_addr);
78 }
79 
80 void
81 ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out)
82 {
83  switch (in->fp_proto)
84  {
85  case FIB_PROTOCOL_IP4:
86  out->address.af = ADDRESS_IP4;
87  break;
88  case FIB_PROTOCOL_IP6:
89  out->address.af = ADDRESS_IP6;
90  break;
91  case FIB_PROTOCOL_MPLS:
92  ASSERT (0);
93  break;
94  }
95  out->address_length = in->fp_len;
96  ip_address_encode (&in->fp_addr, &out->address);
97 }
98 
99 /*
100  * fd.io coding-style-patch-verification: ON
101  *
102  * Local Variables:
103  * eval: (c-set-style "gnu")
104  * End:
105  */
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:202
void ip_prefix_decode(const vl_api_prefix_t *in, fib_prefix_t *out)
Definition: ip_types_api.c:65
void ip_address_encode(const ip46_address_t *in, vl_api_address_t *out)
Definition: ip_types_api.c:49
Aggregrate type for a prefix.
Definition: fib_types.h:193
u16 fp_len
The mask length.
Definition: fib_types.h:197
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:216
#define ip46_address_is_ip4(ip46)
Definition: ip6_packet.h:81
#define clib_memcpy(a, b, c)
Definition: string.h:75
#define ASSERT(truth)
void ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Definition: ip_types_api.c:34
void ip_prefix_encode(const fib_prefix_t *in, vl_api_prefix_t *out)
Definition: ip_types_api.c:81