blob: 184392e036d2f3e37161ef37557ac9728d28fc66 [file] [log] [blame]
Neale Rannscbe25aa2019-09-30 10:53:31 +00001/*
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
18u8 *
19format_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
36void
37ip4_address_increment (ip4_address_t * i)
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
44void
45ip6_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
60void
61ip46_address_increment (ip46_type_t type, ip46_address_t * ip)
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 */