1cbe25aabSNeale Ranns/*
2cbe25aabSNeale Ranns * Copyright (c) 2015-2019 Cisco and/or its affiliates.
3cbe25aabSNeale Ranns * Licensed under the Apache License, Version 2.0 (the "License");
4cbe25aabSNeale Ranns * you may not use this file except in compliance with the License.
5cbe25aabSNeale Ranns * You may obtain a copy of the License at:
6cbe25aabSNeale Ranns *
7cbe25aabSNeale Ranns *     http://www.apache.org/licenses/LICENSE-2.0
8cbe25aabSNeale Ranns *
9cbe25aabSNeale Ranns * Unless required by applicable law or agreed to in writing, software
10cbe25aabSNeale Ranns * distributed under the License is distributed on an "AS IS" BASIS,
11cbe25aabSNeale Ranns * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cbe25aabSNeale Ranns * See the License for the specific language governing permissions and
13cbe25aabSNeale Ranns * limitations under the License.
14cbe25aabSNeale Ranns */
15cbe25aabSNeale Ranns
16cbe25aabSNeale Ranns#include <vnet/ip/ip46_address.h>
17cbe25aabSNeale Ranns
18cbe25aabSNeale Rannsu8 *
19cbe25aabSNeale Rannsformat_ip46_type (u8 * s, va_list * args)
20cbe25aabSNeale Ranns{
21cbe25aabSNeale Ranns  ip46_type_t type = va_arg (*args, ip46_type_t);
22cbe25aabSNeale Ranns
23cbe25aabSNeale Ranns  switch (type)
24cbe25aabSNeale Ranns    {
25cbe25aabSNeale Ranns    case IP46_TYPE_IP4:
26cbe25aabSNeale Ranns      return (format (s, "ip4"));
27cbe25aabSNeale Ranns    case IP46_TYPE_IP6:
28cbe25aabSNeale Ranns      return (format (s, "ip6"));
29cbe25aabSNeale Ranns    case IP46_TYPE_ANY:
30cbe25aabSNeale Ranns      return (format (s, "any"));
31cbe25aabSNeale Ranns    }
32cbe25aabSNeale Ranns
33cbe25aabSNeale Ranns  return (format (s, "unknown"));
34cbe25aabSNeale Ranns}
35cbe25aabSNeale Ranns
36cbe25aabSNeale Rannsvoid
37cbe25aabSNeale Rannsip4_address_increment (ip4_address_t * i)
38cbe25aabSNeale Ranns{
39cbe25aabSNeale Ranns  u32 t = clib_net_to_host_u32 (i->as_u32);
40cbe25aabSNeale Ranns  t++;
41cbe25aabSNeale Ranns  i->as_u32 = clib_net_to_host_u32 (t);
42cbe25aabSNeale Ranns}
43cbe25aabSNeale Ranns
44cbe25aabSNeale Rannsvoid
45cbe25aabSNeale Rannsip6_address_increment (ip6_address_t * i)
46cbe25aabSNeale Ranns{
47cbe25aabSNeale Ranns  u64 tmp = clib_net_to_host_u64 (i->as_u64[1]);
48cbe25aabSNeale Ranns
49cbe25aabSNeale Ranns  tmp++;
50cbe25aabSNeale Ranns  i->as_u64[1] = clib_host_to_net_u64 (tmp);
51cbe25aabSNeale Ranns
52cbe25aabSNeale Ranns  if (!tmp)
53cbe25aabSNeale Ranns    {
54cbe25aabSNeale Ranns      tmp = clib_net_to_host_u64 (i->as_u64[0]);
55cbe25aabSNeale Ranns      tmp++;
56cbe25aabSNeale Ranns      i->as_u64[0] = clib_host_to_net_u64 (tmp);
57cbe25aabSNeale Ranns    }
58cbe25aabSNeale Ranns}
59cbe25aabSNeale Ranns
60cbe25aabSNeale Rannsvoid
61cbe25aabSNeale Rannsip46_address_increment (ip46_type_t type, ip46_address_t * ip)
62cbe25aabSNeale Ranns{
63cbe25aabSNeale Ranns  if (IP46_TYPE_IP4 == type ||
64cbe25aabSNeale Ranns      (IP46_TYPE_ANY == type && ip46_address_is_ip4 (ip)))
65cbe25aabSNeale Ranns    ip4_address_increment (&ip->ip4);
66cbe25aabSNeale Ranns  else
67cbe25aabSNeale Ranns    ip6_address_increment (&ip->ip6);
68cbe25aabSNeale Ranns}
69cbe25aabSNeale Ranns
70cbe25aabSNeale Ranns/*
71cbe25aabSNeale Ranns * fd.io coding-style-patch-verification: ON
72cbe25aabSNeale Ranns *
73cbe25aabSNeale Ranns * Local Variables:
74cbe25aabSNeale Ranns * eval: (c-set-style "gnu")
75cbe25aabSNeale Ranns * End:
76cbe25aabSNeale Ranns */