+static int
+parse_tunnel_ip(const char *value, bool accept_mcast, bool *flow,
+ struct in6_addr *ipv6, uint16_t *protocol)
+{
+ if (!strcmp(value, "flow")) {
+ *flow = true;
+ *protocol = 0;
+ return 0;
+ }
+ if (addr_is_ipv6(value)) {
+ if (lookup_ipv6(value, ipv6)) {
+ return ENOENT;
+ }
+ if (!accept_mcast && ipv6_addr_is_multicast(ipv6)) {
+ return EINVAL;
+ }
+ *protocol = ETH_TYPE_IPV6;
+ } else {
+ struct in_addr ip;
+ if (lookup_ip(value, &ip)) {
+ return ENOENT;
+ }
+ if (!accept_mcast && ip_is_multicast(ip.s_addr)) {
+ return EINVAL;
+ }
+ in6_addr_set_mapped_ipv4(ipv6, ip.s_addr);
+ *protocol = ETH_TYPE_IP;
+ }
+ return 0;
+}
+