uint8_t ipv4prefix[6]; //!< IPv4 prefix (should be struct?).
struct in6_addr ipv6addr; //!< IPv6 Address.
uint8_t ipv6prefix[18]; //!< IPv6 prefix (should be struct?).
+
+ fr_ipaddr_t ipaddr2; //!< IPv4/6 address/prefix.
+
uint8_t ifid[8]; //!< IPv6 interface ID (should be struct?).
uint8_t ether[6]; //!< Ethernet (MAC) address.
/*
* Parsing
*/
+int value_box_from_ipaddr(value_box_t *dst, fr_ipaddr_t const *ipaddr);
+
int value_box_from_str(TALLOC_CTX *ctx, value_box_t *dst,
- PW_TYPE *src_type, fr_dict_attr_t const *src_enumv,
- char const *src, ssize_t src_len, char quote);
+ PW_TYPE *src_type, fr_dict_attr_t const *src_enumv,
+ char const *src, ssize_t src_len, char quote);
/*
* Printing
return 0;
}
+/** Assign a #value_box_t value from an #fr_ipaddr_t
+ *
+ * Automatically determines the type of the value box from the ipaddr address family
+ * and the length of the prefix field.
+ *
+ * @param[in] dst to assign ipaddr to.
+ * @param[in] ipaddr to copy address from.
+ * @return
+ * - 0 on success.
+ * - -1 on failure.
+ */
+int value_box_from_ipaddr(value_box_t *dst, fr_ipaddr_t const *ipaddr)
+{
+ PW_TYPE type;
+
+ switch (ipaddr->af) {
+ case AF_INET:
+ if (ipaddr->prefix > 32) {
+ fr_strerror_printf("Invalid IPv6 prefix length %i", ipaddr->prefix);
+ return -1;
+ }
+
+ if (ipaddr->prefix == 32) {
+ type = PW_TYPE_IPV4_ADDR;
+ } else {
+ type = PW_TYPE_IPV4_PREFIX;
+ }
+ break;
+
+ case AF_INET6:
+ if (ipaddr->prefix > 128) {
+ fr_strerror_printf("Invalid IPv6 prefix length %i", ipaddr->prefix);
+ return -1;
+ }
+
+ if (ipaddr->prefix == 128) {
+ type = PW_TYPE_IPV6_ADDR;
+ } else {
+ type = PW_TYPE_IPV6_PREFIX;
+ }
+ break;
+
+ default:
+ fr_strerror_printf("Invalid address family %i", ipaddr->af);
+ return -1;
+ }
+
+ dst->type = type;
+ dst->tainted = false; /* Discuss? */
+ dst->datum.ipaddr2 = *ipaddr;
+ dst->length = 0; /* Length doesn't make sense for fixed length types */
+
+ return 0;
+}
+
/** Convert string value to a value_box_t type
*
* @todo Should take taint param.