Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | static inline u8 *format_vl_api_ip6_address_t (u8 * s, va_list * args); |
| 20 | static inline u8 *format_vl_api_ip4_address_t (u8 * s, va_list * args); |
| 21 | |
| 22 | #include <vnet/ip/format.h> |
Ole Troan | 2a1ca78 | 2019-09-19 01:08:30 +0200 | [diff] [blame] | 23 | #include <vnet/ip/ip_types.api_types.h> |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 24 | |
| 25 | static inline u8 * |
| 26 | format_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 | |
| 34 | static inline u8 * |
| 35 | format_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 | |
| 43 | static inline u8 * |
| 44 | format_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 | |
| 52 | static inline u8 * |
| 53 | format_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 | |
| 61 | static inline u8 * |
| 62 | format_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 Ranns | f932f97 | 2020-04-22 16:02:47 +0000 | [diff] [blame] | 67 | switch (a->af) { |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 68 | 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 Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 73 | return format (s, "unknown-af"); |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static inline u8 * |
| 77 | format_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 Troan | 75761b9 | 2019-09-11 17:49:08 +0200 | [diff] [blame] | 85 | static inline u8 * |
| 86 | format_vl_api_address_with_prefix_t (u8 * s, va_list * args) |
| 87 | { |
| 88 | return format_vl_api_prefix_t (s, args); |
| 89 | } |
| 90 | |
Jakub Grajciar | b28a81e | 2019-09-23 10:42:19 +0200 | [diff] [blame] | 91 | static inline u8 * |
| 92 | format_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 | |
| 97 | static inline u8 * |
| 98 | format_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 Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 103 | #endif |