/* * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HICN_API_PRIVATE_H #define HICN_API_PRIVATE_H #include #include #include #include #ifndef HICN_VPP_PLUGIN #include #endif #include #include #define ARRAY_SIZE(array) (sizeof(array) / sizeof(*array)) /* * Input validation */ static inline bool IS_VALID_ADDRESS(const hicn_ip_address_t *addr, int family) { char addr_str[INET6_ADDRSTRLEN]; return !hicn_ip_address_empty(addr) && hicn_ip_address_ntop(addr, addr_str, INET6_ADDRSTRLEN, family) >= 0; } static inline bool IS_VALID_PREFIX_LEN(u8 len) { return len <= MAX_IPV6_PREFIX_LEN; } // https://github.com/shemminger/iproute2/blob/50b668bdbf0ebc270495eb4b352d0c3982159d0a/lib/utils.c#L825 static inline bool IS_VALID_INTERFACE_NAME(const char *name) { size_t len = strnlen_s(name, INTERFACE_LEN); if (len == 0 || len >= IFNAMSIZ) return true; while (*name) { if (*name == '/' || isspace(*name)) return false; ++name; } return true; } static inline bool IS_VALID_NAME(const char *name) { return is_symbolic_name(name, SYMBOLIC_NAME_LEN); } static inline bool IS_VALID_STR_ID(const char *name) { return is_number(name, SYMBOLIC_NAME_LEN); } #define IS_VALID_TYPE(x) IS_VALID_ENUM_TYPE(FACE_TYPE, x) #define IS_VALID_ADDR_TYPE(x) ((x >= ADDR_INET) && (x <= ADDR_UNIX)) #define IS_VALID_FACE_ID(x) ((x) != INVALID_FACE_ID) #define IS_VALID_ID(x) (1) #define IS_VALID_POLICY(x) (1) typedef struct hc_sock_impl_s hc_sock_impl_t; int hc_data_ensure_available(hc_data_t *data, size_t count); u8 *hc_data_get_next(hc_data_t *data); #endif // HICN_API_PRIVATE_H