blob: 5bd58ad3b819145b3a11de2a983b388aaadb4909 [file] [log] [blame]
Ole Troan33a58172019-09-04 09:12:29 +02001/*
2 * Copyright (c) 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#ifndef included_ip_format_fns_h
17#define included_ip_format_fns_h
18
19static inline u8 *format_vl_api_ip6_address_t (u8 * s, va_list * args);
20static inline u8 *format_vl_api_ip4_address_t (u8 * s, va_list * args);
21
22#include <vnet/ip/format.h>
Ole Troan2a1ca782019-09-19 01:08:30 +020023#include <vnet/ip/ip_types.api_types.h>
Ole Troan33a58172019-09-04 09:12:29 +020024
25static inline u8 *
26format_vl_api_ip6_address_t (u8 * s, va_list * args)
27{
28 vl_api_ip6_address_t *a = va_arg (*args, vl_api_ip6_address_t *);
29 u32 indent __attribute__((unused)) = va_arg (*args, u32);
30
31 return format (s, "%U", format_ip6_address, a);
32}
33
34static inline u8 *
35format_vl_api_ip6_prefix_t (u8 * s, va_list * args)
36{
37 vl_api_ip6_prefix_t *a = va_arg (*args, vl_api_ip6_prefix_t *);
38 u32 indent __attribute__((unused)) = va_arg (*args, u32);
39
40 return format (s, "%U/%u", format_ip6_address, &a->address, a->len);
41}
42
43static inline u8 *
44format_vl_api_ip4_address_t (u8 * s, va_list * args)
45{
46 vl_api_ip4_address_t *a = va_arg (*args, vl_api_ip4_address_t *);
47 u32 indent __attribute__((unused)) = va_arg (*args, u32);
48
49 return format (s, "%U", format_ip4_address, a);
50}
51
52static inline u8 *
53format_vl_api_ip4_prefix_t (u8 * s, va_list * args)
54{
55 vl_api_ip4_prefix_t *a = va_arg (*args, vl_api_ip4_prefix_t *);
56 u32 indent __attribute__((unused)) = va_arg (*args, u32);
57
58 return format (s, "%U/%u", format_ip4_address, &a->address, a->len);
59}
60
61static inline u8 *
62format_vl_api_address_t (u8 * s, va_list * args)
63{
64 vl_api_address_t *a = va_arg (*args, vl_api_address_t *);
65 u32 indent __attribute__((unused)) = va_arg (*args, u32);
66
Neale Rannsf932f972020-04-22 16:02:47 +000067 switch (a->af) {
Ole Troan33a58172019-09-04 09:12:29 +020068 case ADDRESS_IP4:
69 return format(s, "%U", format_ip4_address, &a->un.ip4);
70 case ADDRESS_IP6:
71 return format(s, "%U", format_ip6_address, &a->un.ip6);
72 }
Neale Rannsefd7bc22019-11-11 08:32:34 +000073 return format (s, "unknown-af");
Ole Troan33a58172019-09-04 09:12:29 +020074}
75
76static inline u8 *
77format_vl_api_prefix_t (u8 * s, va_list * args)
78{
79 vl_api_prefix_t *a = va_arg (*args, vl_api_prefix_t *);
80 u32 indent __attribute__((unused)) = va_arg (*args, u32);
81
82 return format (s, "%U/%u", format_vl_api_address_t, &a->address, indent, a->len);
83}
84
Ole Troan75761b92019-09-11 17:49:08 +020085static inline u8 *
86format_vl_api_address_with_prefix_t (u8 * s, va_list * args)
87{
88 return format_vl_api_prefix_t (s, args);
89}
90
Jakub Grajciarb28a81e2019-09-23 10:42:19 +020091static inline u8 *
92format_vl_api_ip4_address_with_prefix_t (u8 * s, va_list * args)
93{
94 return format_vl_api_ip4_prefix_t (s, args);
95}
96
97static inline u8 *
98format_vl_api_ip6_address_with_prefix_t (u8 * s, va_list * args)
99{
100 return format_vl_api_ip6_prefix_t (s, args);
101}
102
Ole Troan33a58172019-09-04 09:12:29 +0200103#endif