Lines Matching +full:data +full:- +full:role
1 /* udp.c - UDP specific code for echo server */
7 * SPDX-License-Identifier: Apache-2.0
29 IS_ENABLED(CONFIG_USERSPACE) ? K_USER : 0, -1);
34 IS_ENABLED(CONFIG_USERSPACE) ? K_USER : 0, -1);
36 static int start_udp_proto(struct data *data, struct sockaddr *bind_addr, in start_udp_proto() argument
43 data->udp.sock = socket(bind_addr->sa_family, SOCK_DGRAM, in start_udp_proto()
46 data->udp.sock = socket(bind_addr->sa_family, SOCK_DGRAM, IPPROTO_UDP); in start_udp_proto()
48 if (data->udp.sock < 0) { in start_udp_proto()
49 NET_ERR("Failed to create UDP socket (%s): %d", data->proto, in start_udp_proto()
51 return -errno; in start_udp_proto()
61 int role = TLS_DTLS_ROLE_SERVER; in start_udp_proto() local
63 ret = setsockopt(data->udp.sock, SOL_TLS, TLS_SEC_TAG_LIST, in start_udp_proto()
66 NET_ERR("Failed to set UDP secure option (%s): %d", data->proto, in start_udp_proto()
68 ret = -errno; in start_udp_proto()
71 /* Set role to DTLS server. */ in start_udp_proto()
72 ret = setsockopt(data->udp.sock, SOL_TLS, TLS_DTLS_ROLE, in start_udp_proto()
73 &role, sizeof(role)); in start_udp_proto()
75 NET_ERR("Failed to set DTLS role secure option (%s): %d", in start_udp_proto()
76 data->proto, errno); in start_udp_proto()
77 ret = -errno; in start_udp_proto()
81 if (bind_addr->sa_family == AF_INET6) { in start_udp_proto()
84 (void)setsockopt(data->udp.sock, IPPROTO_IPV6, in start_udp_proto()
93 (void)setsockopt(data->udp.sock, IPPROTO_IPV6, IPV6_V6ONLY, in start_udp_proto()
97 ret = bind(data->udp.sock, bind_addr, bind_addrlen); in start_udp_proto()
99 NET_ERR("Failed to bind UDP socket (%s): %d", data->proto, in start_udp_proto()
101 ret = -errno; in start_udp_proto()
107 static int process_udp(struct data *data) in process_udp() argument
115 MY_PORT, data->proto); in process_udp()
119 received = recvfrom(data->udp.sock, data->udp.recv_buffer, in process_udp()
120 sizeof(data->udp.recv_buffer), 0, in process_udp()
125 NET_ERR("UDP (%s): Connection error %d", data->proto, in process_udp()
127 ret = -errno; in process_udp()
130 atomic_add(&data->udp.bytes_received, received); in process_udp()
133 ret = sendto(data->udp.sock, data->udp.recv_buffer, received, 0, in process_udp()
136 NET_ERR("UDP (%s): Failed to send %d", data->proto, in process_udp()
138 ret = -errno; in process_udp()
142 if (++data->udp.counter % 1000 == 0U) { in process_udp()
143 NET_INFO("%s UDP: Sent %u packets", data->proto, in process_udp()
144 data->udp.counter); in process_udp()
148 data->proto, received); in process_udp()
205 struct data *data = CONTAINER_OF(dwork, struct data, udp.stats_print); in print_stats() local
206 int total_received = atomic_get(&data->udp.bytes_received); in print_stats()
210 LOG_INF("%s UDP: Received %d B/sec", data->proto, in print_stats()
213 LOG_INF("%s UDP: Received %d KiB/sec", data->proto, in print_stats()
217 atomic_set(&data->udp.bytes_received, 0); in print_stats()
220 k_work_reschedule(&data->udp.stats_print, K_SECONDS(STATS_TIMER)); in print_stats()