FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
ip46_address.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019 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/ip46_address.h>
17 
18 u8 *
19 format_ip46_type (u8 * s, va_list * args)
20 {
21  ip46_type_t type = va_arg (*args, ip46_type_t);
22 
23  switch (type)
24  {
25  case IP46_TYPE_IP4:
26  return (format (s, "ip4"));
27  case IP46_TYPE_IP6:
28  return (format (s, "ip6"));
29  case IP46_TYPE_ANY:
30  return (format (s, "any"));
31  }
32 
33  return (format (s, "unknown"));
34 }
35 
36 void
38 {
39  u32 t = clib_net_to_host_u32 (i->as_u32);
40  t++;
41  i->as_u32 = clib_net_to_host_u32 (t);
42 }
43 
44 void
45 ip6_address_increment (ip6_address_t * i)
46 {
47  u64 tmp = clib_net_to_host_u64 (i->as_u64[1]);
48 
49  tmp++;
50  i->as_u64[1] = clib_host_to_net_u64 (tmp);
51 
52  if (!tmp)
53  {
54  tmp = clib_net_to_host_u64 (i->as_u64[0]);
55  tmp++;
56  i->as_u64[0] = clib_host_to_net_u64 (tmp);
57  }
58 }
59 
60 void
62 {
63  if (IP46_TYPE_IP4 == type ||
64  (IP46_TYPE_ANY == type && ip46_address_is_ip4 (ip)))
65  ip4_address_increment (&ip->ip4);
66  else
67  ip6_address_increment (&ip->ip6);
68 }
69 
70 /*
71  * fd.io coding-style-patch-verification: ON
72  *
73  * Local Variables:
74  * eval: (c-set-style "gnu")
75  * End:
76  */
void ip46_address_increment(ip46_type_t type, ip46_address_t *ip)
Definition: ip46_address.c:61
unsigned long u64
Definition: types.h:89
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
unsigned char u8
Definition: types.h:56
void ip6_address_increment(ip6_address_t *i)
Definition: ip46_address.c:45
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
void ip4_address_increment(ip4_address_t *i)
Definition: ip46_address.c:37
vl_api_address_t ip
Definition: l2.api:501
u8 * format_ip46_type(u8 *s, va_list *args)
Definition: ip46_address.c:19
ip46_type_t
Definition: ip46_address.h:22