Lines Matching +full:ip +full:- +full:addr
4 * SPDX-License-Identifier: Apache-2.0
77 * Peer (inner) tunnel IP address.
82 * Local (inner) tunnel IP address. This will be set
124 if (!ctx->in_use) { in net_capture_foreach()
128 info.capture_dev = ctx->dev; in net_capture_foreach()
129 info.capture_iface = ctx->capture_iface; in net_capture_foreach()
130 info.tunnel_iface = ctx->tunnel_iface; in net_capture_foreach()
131 info.peer = &ctx->peer; in net_capture_foreach()
132 info.local = &ctx->local; in net_capture_foreach()
133 info.is_enabled = ctx->is_enabled; in net_capture_foreach()
152 if (ctx->in_use) { in alloc_capture_dev()
157 ctx->in_use = true; in alloc_capture_dev()
195 struct sockaddr *addr, int *addr_len) in setup_iface() argument
199 if (!net_ipaddr_parse(ipaddr, strlen(ipaddr), addr)) { in setup_iface()
202 return -EINVAL; in setup_iface()
205 if (IS_ENABLED(CONFIG_NET_IPV6) && addr->sa_family == AF_INET6) { in setup_iface()
210 ifaddr = net_if_ipv6_addr_add(iface, &net_sin6(addr)->sin6_addr, in setup_iface()
215 return -EINVAL; in setup_iface()
220 } else if (IS_ENABLED(CONFIG_NET_IPV4) && addr->sa_family == AF_INET) { in setup_iface()
226 ifaddr = net_if_ipv4_addr_add(iface, &net_sin(addr)->sin_addr, in setup_iface()
231 return -EINVAL; in setup_iface()
238 &net_sin(addr)->sin_addr, in setup_iface()
243 return -EINVAL; in setup_iface()
249 static int cleanup_iface(struct net_if *iface, struct sockaddr *addr) in cleanup_iface() argument
251 int ret = -EINVAL; in cleanup_iface()
253 if (IS_ENABLED(CONFIG_NET_IPV6) && addr->sa_family == AF_INET6) { in cleanup_iface()
254 ret = net_if_ipv6_addr_rm(iface, &net_sin6(addr)->sin6_addr); in cleanup_iface()
257 net_sprint_ipv6_addr(&net_sin6(addr)->sin6_addr), in cleanup_iface()
259 ret = -EINVAL; in cleanup_iface()
264 } else if (IS_ENABLED(CONFIG_NET_IPV4) && addr->sa_family == AF_INET) { in cleanup_iface()
265 ret = net_if_ipv4_addr_rm(iface, &net_sin(addr)->sin_addr); in cleanup_iface()
268 net_sprint_ipv4_addr(&net_sin(addr)->sin_addr), in cleanup_iface()
296 ret = -EINVAL; in net_capture_setup()
303 ret = -EINVAL; in net_capture_setup()
310 ret = -EINVAL; in net_capture_setup()
316 &net_sin6(&remote)->sin6_addr); in net_capture_setup()
319 &net_sin6(&remote)->sin6_addr); in net_capture_setup()
321 mtu = orig_mtu - sizeof(struct net_ipv6_hdr) - in net_capture_setup()
325 &net_sin(&remote)->sin_addr); in net_capture_setup()
328 &net_sin(&remote)->sin_addr); in net_capture_setup()
330 mtu = orig_mtu - sizeof(struct net_ipv4_hdr) - in net_capture_setup()
334 ret = -EINVAL; in net_capture_setup()
340 ret = -ENETUNREACH; in net_capture_setup()
360 ret = -ENOENT; in net_capture_setup()
384 NET_ERR("Cannot set IP address %s to tunnel interface", in net_capture_setup()
392 ret = -EINVAL; in net_capture_setup()
398 ret = -ENOMEM; in net_capture_setup()
405 ctx->context = context; in net_capture_setup()
406 net_context_setup_pools(ctx->context, get_net_pkt, get_net_buf); in net_capture_setup()
408 ctx->tunnel_iface = ipip_iface; in net_capture_setup()
409 *dev = ctx->dev; in net_capture_setup()
411 memcpy(&ctx->peer, &peer, local_addr_len); in net_capture_setup()
412 memcpy(&ctx->local, &local, local_addr_len); in net_capture_setup()
414 if (net_sin(&ctx->peer)->sin_port == 0) { in net_capture_setup()
415 net_sin(&ctx->peer)->sin_port = htons(DEFAULT_PORT); in net_capture_setup()
418 if (net_sin(&ctx->local)->sin_port == 0) { in net_capture_setup()
419 net_sin(&ctx->local)->sin_port = htons(DEFAULT_PORT); in net_capture_setup()
422 ret = net_virtual_interface_attach(ctx->tunnel_iface, remote_iface); in net_capture_setup()
423 if (ret < 0 && ret != -EALREADY) { in net_capture_setup()
427 (void)net_capture_cleanup(ctx->dev); in net_capture_setup()
449 struct net_capture *ctx = dev->data; in capture_cleanup()
452 (void)net_virtual_interface_attach(ctx->tunnel_iface, NULL); in capture_cleanup()
454 if (ctx->context) { in capture_cleanup()
455 net_context_put(ctx->context); in capture_cleanup()
458 (void)cleanup_iface(ctx->tunnel_iface, &ctx->local); in capture_cleanup()
460 ctx->tunnel_iface = NULL; in capture_cleanup()
461 ctx->in_use = false; in capture_cleanup()
468 struct net_capture *ctx = dev->data; in capture_is_enabled()
470 return ctx->is_enabled ? true : false; in capture_is_enabled()
475 struct net_capture *ctx = dev->data; in capture_enable()
477 if (ctx->is_enabled) { in capture_enable()
478 return -EALREADY; in capture_enable()
484 if (ctx->tunnel_iface == iface) { in capture_enable()
485 return -EINVAL; in capture_enable()
488 ctx->capture_iface = iface; in capture_enable()
489 ctx->is_enabled = true; in capture_enable()
493 net_if_up(ctx->tunnel_iface); in capture_enable()
500 struct net_capture *ctx = dev->data; in capture_disable()
501 struct net_if *iface = ctx->capture_iface; in capture_disable()
503 ctx->capture_iface = NULL; in capture_disable()
504 ctx->is_enabled = false; in capture_disable()
506 net_if_down(ctx->tunnel_iface); in capture_disable()
519 int ret = -ENOENT; in net_capture_pkt_with_status()
525 return -EALREADY; in net_capture_pkt_with_status()
534 if (!ctx->in_use || !ctx->is_enabled || in net_capture_pkt_with_status()
535 ctx->capture_iface != iface) { in net_capture_pkt_with_status()
550 orig_slab = pkt->slab; in net_capture_pkt_with_status()
551 pkt->slab = get_net_pkt(); in net_capture_pkt_with_status()
555 pkt->slab = orig_slab; in net_capture_pkt_with_status()
559 net_stats_update_processing_error(ctx->tunnel_iface); in net_capture_pkt_with_status()
560 ret = -ENOMEM; in net_capture_pkt_with_status()
566 net_pkt_set_iface(captured, ctx->tunnel_iface); in net_capture_pkt_with_status()
569 ret = net_capture_send(ctx->dev, ctx->tunnel_iface, captured); in net_capture_pkt_with_status()
594 struct net_capture *ctx = dev->data; in capture_dev_init()
598 sys_slist_find_and_remove(&net_capture_devlist, &ctx->node); in capture_dev_init()
599 sys_slist_prepend(&net_capture_devlist, &ctx->node); in capture_dev_init()
601 ctx->dev = dev; in capture_dev_init()
602 ctx->init_done = true; in capture_dev_init()
612 struct net_capture *ctx = dev->data; in capture_send()
614 struct net_pkt *ip; in capture_send() local
618 if (!ctx->in_use) { in capture_send()
619 return -ENOENT; in capture_send()
622 if (IS_ENABLED(CONFIG_NET_IPV4) && ctx->local.sa_family == AF_INET) { in capture_send()
624 } else if (IS_ENABLED(CONFIG_NET_IPV6) && ctx->local.sa_family == AF_INET6) { in capture_send()
627 return -EINVAL; in capture_send()
632 /* Add IP and UDP header */ in capture_send()
633 ip = net_pkt_alloc_from_slab(ctx->context->tx_slab(), PKT_ALLOC_TIME); in capture_send()
634 if (!ip) { in capture_send()
635 return -ENOMEM; in capture_send()
638 net_pkt_set_context(ip, ctx->context); in capture_send()
639 net_pkt_set_family(ip, ctx->local.sa_family); in capture_send()
640 net_pkt_set_iface(ip, ctx->tunnel_iface); in capture_send()
642 ret = net_pkt_alloc_buffer(ip, len, IPPROTO_UDP, PKT_ALLOC_TIME); in capture_send()
644 net_pkt_unref(ip); in capture_send()
648 if (IS_ENABLED(CONFIG_NET_IPV4) && ctx->local.sa_family == AF_INET) { in capture_send()
649 net_pkt_set_ipv4_ttl(ip, in capture_send()
650 net_if_ipv4_get_ttl(ctx->tunnel_iface)); in capture_send()
652 ret = net_ipv4_create(ip, &net_sin(&ctx->local)->sin_addr, in capture_send()
653 &net_sin(&ctx->peer)->sin_addr); in capture_send()
654 } else if (IS_ENABLED(CONFIG_NET_IPV6) && ctx->local.sa_family == AF_INET6) { in capture_send()
655 ret = net_ipv6_create(ip, &net_sin6(&ctx->local)->sin6_addr, in capture_send()
656 &net_sin6(&ctx->peer)->sin6_addr); in capture_send()
662 net_pkt_unref(ip); in capture_send()
666 (void)net_udp_create(ip, net_sin(&ctx->local)->sin_port, in capture_send()
667 net_sin(&ctx->peer)->sin_port); in capture_send()
669 net_buf_frag_add(ip->buffer, pkt->buffer); in capture_send()
670 pkt->buffer = ip->buffer; in capture_send()
671 ip->buffer = NULL; in capture_send()
672 net_pkt_unref(ip); in capture_send()
679 net_pkt_set_iface(pkt, ctx->tunnel_iface); in capture_send()
680 net_pkt_set_family(pkt, ctx->local.sa_family); in capture_send()
685 if (IS_ENABLED(CONFIG_NET_IPV4) && ctx->local.sa_family == AF_INET) { in capture_send()
690 } else if (IS_ENABLED(CONFIG_NET_IPV6) && ctx->local.sa_family == AF_INET6) { in capture_send()
710 verdict = net_if_send_data(ctx->tunnel_iface, pkt); in capture_send()
712 ret = -EIO; in capture_send()