2 * Copyright (c) 2016 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 void ip46_prefix_normalize(ip46_address_t *prefix, u8 plen)
21 prefix->as_u64[0] = 0;
22 prefix->as_u64[1] = 0;
23 } else if (plen <= 64) {
24 prefix->as_u64[0] &= clib_host_to_net_u64(0xffffffffffffffffL << (64 - plen));
25 prefix->as_u64[1] = 0;
27 prefix->as_u64[1] &= clib_host_to_net_u64(0xffffffffffffffffL << (128 - plen));
32 uword unformat_ip46_prefix (unformat_input_t * input, va_list * args)
34 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
35 u8 *len = va_arg (*args, u8 *);
36 ip46_type_t type = va_arg (*args, ip46_type_t);
39 if ((type != IP46_TYPE_IP6) && unformat(input, "%U/%u", unformat_ip4_address, &ip46->ip4, &l)) {
43 ip46->pad[0] = ip46->pad[1] = ip46->pad[2] = 0;
44 } else if ((type != IP46_TYPE_IP4) && unformat(input, "%U/%u", unformat_ip6_address, &ip46->ip6, &l)) {
54 u8 *format_ip46_prefix (u8 * s, va_list * args)
56 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
57 u32 len = va_arg (*args, u32); //va_arg cannot use u8 or u16
58 ip46_type_t type = va_arg (*args, ip46_type_t);
61 if (type == IP46_TYPE_IP4)
63 else if (type == IP46_TYPE_IP6)
66 is_ip4 = (len >= 96) && ip46_address_is_ip4(ip46);
69 format(s, "%U/%d", format_ip4_address, &ip46->ip4, len - 96):
70 format(s, "%U/%d", format_ip6_address, &ip46->ip6, len);