| 1 | // SPDX-License-Identifier: BSD-2-Clausecxx . . $ `<file>/src/rta_thread.c`/ |
| 2 | /* |
| 3 | * Copyright (C) 2020-2025 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <pthread.h> |
| 9 | #include <signal.h> |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <unistd.h> |
| 14 | |
| 15 | #include <arpa/inet.h> |
| 16 | |
| 17 | #include <linux/if_ether.h> |
| 18 | #include <linux/if_link.h> |
| 19 | #include <linux/if_packet.h> |
| 20 | #include <linux/if_vlan.h> |
| 21 | |
| 22 | #include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 23 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 24 | #include "net.h"cxx . . $ `<file>/src/net.h`/ |
| 25 | #include "net_def.h"cxx . . $ `<file>/src/net_def.h`/ |
| 26 | #include "packet.h"cxx . . $ `<file>/src/packet.h`/ |
| 27 | #include "rta_thread.h"cxx . . $ `<file>/src/rta_thread.h`/ |
| 28 | #include "security.h"cxx . . $ `<file>/src/security.h`/ |
| 29 | #include "stat.h"cxx . . $ `<file>/src/stat.h`/ |
| 30 | #include "utils.h"cxx . . $ `<file>/src/utils.h`/ |
| 31 | #include "xdp.h"cxx . . $ `<file>/src/xdp.h`/ |
| 32 | |
| 33 | static void rta_initialize_framescxx . . $ rta_initialize_frames(e1a9c3903a216417).(struct thread_contextcxx . . $ thread_context# *thread_context, unsigned char *frame_data, |
| 34 | size_t num_frames, const unsigned char *source, |
| 35 | const unsigned char *destination) |
| 36 | { |
| 37 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 38 | size_t i; |
| 39 | |
| 40 | for (i = 0; i < num_frames; ++i) { |
| 41 | unsigned char *frame = frame_idxcxx . . $ frame_idx(9d0786fb5198b4b4).(frame_data, i); |
| 42 | size_t frame_length = MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!; |
| 43 | |
| 44 | /* |
| 45 | * In case both AF_XDP and Tx HW Timestamp are enabled the payload starts at: |
| 46 | * frame_data + sizeof(struct xsk_tx_metadata) |
| 47 | */ |
| 48 | #ifdef TX_TIMESTAMP |
| 49 | if (rta_config->xdp_enabled && rta_config->tx_hwtstamp_enabled) { |
| 50 | frame += sizeof(struct xsk_tx_metadata); |
| 51 | frame_length -= sizeof(struct xsk_tx_metadata); |
| 52 | } |
| 53 | #endif |
| 54 | |
| 55 | initialize_profinet_framecxx . . $ initialize_profinet_frame(305659cd59e50ce5).(rta_config->security_modecxx . . $ traffic_class_config#security_mode., frame, frame_length, source, |
| 56 | destination, rta_config->payload_patterncxx . . $ traffic_class_config#payload_pattern., |
| 57 | rta_config->payload_pattern_lengthcxx . . $ traffic_class_config#payload_pattern_length., |
| 58 | rta_config->vidcxx . . $ traffic_class_config#vid. | rta_config->pcpcxx . . $ traffic_class_config#pcp. << VLAN_PCP_SHIFTcxx . . $ `src/net_def.h:26:9`!, |
| 59 | thread_context->frame_idcxx . . $ thread_context#frame_id.); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | static int rta_send_messagescxx . . $ rta_send_messages(1230c857beb98e36).(struct thread_contextcxx . . $ thread_context# *thread_context, int socket_fd, |
| 64 | struct sockaddr_llcxx . . $ sockaddr_ll# *destination, unsigned char *frame_data, |
| 65 | size_t num_frames) |
| 66 | { |
| 67 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 68 | struct packet_send_requestcxx . . $ packet_send_request# send_req = { |
| 69 | .traffic_class = stat_frame_type_to_stringcxx . . $ stat_frame_type_to_string(413bfe925ee921da).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.), |
| 70 | .socket_fd = socket_fd, |
| 71 | .destination = destination, |
| 72 | .frame_data = frame_data, |
| 73 | .num_frames = num_frames, |
| 74 | .frame_length = rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length., |
| 75 | .duration = 0, |
| 76 | .tx_time_offset = 0, |
| 77 | .meta_data_offset = thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset., |
| 78 | .mirror_enabled = rta_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled., |
| 79 | .tx_time_enabled = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, |
| 80 | }; |
| 81 | |
| 82 | return packet_send_messagescxx . . $ packet_send_messages(db4d6f7226235983).(thread_context->packet_contextcxx . . $ thread_context#packet_context., &send_req); |
| 83 | } |
| 84 | |
| 85 | static int rta_send_framescxx . . $ rta_send_frames(bbb668e7d71a4c9).(struct thread_contextcxx . . $ thread_context# *thread_context, unsigned char *frame_data, |
| 86 | size_t num_frames, int socket_fd, struct sockaddr_llcxx . . $ sockaddr_ll# *destination) |
| 87 | { |
| 88 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 89 | int len, i; |
| 90 | |
| 91 | /* Send it */ |
| 92 | len = rta_send_messagescxx . . $ rta_send_messages(1230c857beb98e36).(thread_context, socket_fd, destination, frame_data, num_frames); |
| 93 | |
| 94 | for (i = 0; i < len; i++) { |
| 95 | uint64_tcxx . . $ uint64_t# sequence_counter; |
| 96 | |
| 97 | sequence_counter = get_sequence_countercxx . . $ get_sequence_counter(9512b04a879eebb0).(frame_data + i * rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length., |
| 98 | thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset., |
| 99 | rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 100 | |
| 101 | stat_frame_sentcxx . . $ stat_frame_sent(ca48c151307d73b6).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE., sequence_counter); |
| 102 | } |
| 103 | |
| 104 | return len; |
| 105 | } |
| 106 | |
| 107 | static int rta_gen_and_send_framescxx . . $ rta_gen_and_send_frames(2a5ba8d4c1205443).(struct thread_contextcxx . . $ thread_context# *thread_context, int socket_fd, |
| 108 | struct sockaddr_llcxx . . $ sockaddr_ll# *destination, uint64_tcxx . . $ uint64_t# sequence_counter_begin) |
| 109 | { |
| 110 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 111 | struct timespeccxx . . $ timespec# tx_time = {}; |
| 112 | int len, i; |
| 113 | |
| 114 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., &tx_time); |
| 115 | |
| 116 | for (i = 0; i < rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; i++) { |
| 117 | struct prepare_frame_configcxx . . $ prepare_frame_config# frame_config; |
| 118 | int err; |
| 119 | |
| 120 | frame_config.modecxx . . $ prepare_frame_config#mode. = rta_config->security_modecxx . . $ traffic_class_config#security_mode.; |
| 121 | frame_config.security_contextcxx . . $ prepare_frame_config#security_context. = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 122 | frame_config.iv_prefixcxx . . $ prepare_frame_config#iv_prefix. = (const unsigned char *)rta_config->security_iv_prefixcxx . . $ traffic_class_config#security_iv_prefix.; |
| 123 | frame_config.payload_patterncxx . . $ prepare_frame_config#payload_pattern. = thread_context->payload_patterncxx . . $ thread_context#payload_pattern.; |
| 124 | frame_config.payload_pattern_lengthcxx . . $ prepare_frame_config#payload_pattern_length. = thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length.; |
| 125 | frame_config.frame_datacxx . . $ prepare_frame_config#frame_data. = frame_idxcxx . . $ frame_idx(9d0786fb5198b4b4).(thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data., i); |
| 126 | frame_config.frame_lengthcxx . . $ prepare_frame_config#frame_length. = rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 127 | frame_config.num_frames_per_cyclecxx . . $ prepare_frame_config#num_frames_per_cycle. = rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 128 | frame_config.sequence_countercxx . . $ prepare_frame_config#sequence_counter. = sequence_counter_begin + i; |
| 129 | frame_config.tx_timestampcxx . . $ prepare_frame_config#tx_timestamp. = ts_to_nscxx . . $ ts_to_ns(3d5e857b70563169).(&tx_time); |
| 130 | frame_config.meta_data_offsetcxx . . $ prepare_frame_config#meta_data_offset. = thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset.; |
| 131 | |
| 132 | err = prepare_frame_for_txcxx . . $ prepare_frame_for_tx(f7c7fe1588440d5a).(&frame_config); |
| 133 | if (err) |
| 134 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaTx: Failed to prepare frame for Tx!\n"); |
| 135 | } |
| 136 | |
| 137 | /* Send it */ |
| 138 | len = rta_send_messagescxx . . $ rta_send_messages(1230c857beb98e36).(thread_context, socket_fd, destination, |
| 139 | thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data., rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 140 | |
| 141 | for (i = 0; i < len; i++) |
| 142 | stat_frame_sentcxx . . $ stat_frame_sent(ca48c151307d73b6).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE., sequence_counter_begin + i); |
| 143 | |
| 144 | return len; |
| 145 | } |
| 146 | |
| 147 | static void rta_gen_and_send_xdp_framescxx . . $ rta_gen_and_send_xdp_frames(dcf10771cc53a65b).(struct thread_contextcxx . . $ thread_context# *thread_context, |
| 148 | struct xdp_socketcxx . . $ xdp_socket# *xsk, uint64_tcxx . . $ uint64_t# sequence_counter, |
| 149 | uint32_tcxx . . $ uint32_t# *frame_number) |
| 150 | { |
| 151 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 152 | struct xdp_gen_configcxx . . $ xdp_gen_config# xdp; |
| 153 | |
| 154 | xdp.modecxx . . $ xdp_gen_config#mode. = rta_config->security_modecxx . . $ traffic_class_config#security_mode.; |
| 155 | xdp.security_contextcxx . . $ xdp_gen_config#security_context. = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 156 | xdp.iv_prefixcxx . . $ xdp_gen_config#iv_prefix. = (const unsigned char *)rta_config->security_iv_prefixcxx . . $ traffic_class_config#security_iv_prefix.; |
| 157 | xdp.payload_patterncxx . . $ xdp_gen_config#payload_pattern. = thread_context->payload_patterncxx . . $ thread_context#payload_pattern.; |
| 158 | xdp.payload_pattern_lengthcxx . . $ xdp_gen_config#payload_pattern_length. = thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length.; |
| 159 | xdp.frame_lengthcxx . . $ xdp_gen_config#frame_length. = rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 160 | xdp.num_frames_per_cyclecxx . . $ xdp_gen_config#num_frames_per_cycle. = rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 161 | xdp.frame_numbercxx . . $ xdp_gen_config#frame_number. = frame_number; |
| 162 | xdp.sequence_counter_begincxx . . $ xdp_gen_config#sequence_counter_begin. = sequence_counter; |
| 163 | xdp.meta_data_offsetcxx . . $ xdp_gen_config#meta_data_offset. = thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset.; |
| 164 | xdp.frame_typecxx . . $ xdp_gen_config#frame_type. = RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.; |
| 165 | xdp.tx_timecxx . . $ xdp_gen_config#tx_time. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 166 | |
| 167 | xdp_gen_and_send_framescxx . . $ xdp_gen_and_send_frames(312660e902b5d61d).(xsk, &xdp); |
| 168 | } |
| 169 | |
| 170 | static void *rta_tx_thread_routinecxx . . $ rta_tx_thread_routine(9f162e79bfc6c74).(void *data) |
| 171 | { |
| 172 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 173 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 174 | size_t received_frames_length = MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`! * rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 175 | struct security_contextcxx . . $ security_context# *security_context = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 176 | unsigned char *received_frames = thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.; |
| 177 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = rta_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 178 | pthread_mutex_tcxx . . $ pthread_mutex_t# *mutex = &thread_context->data_mutexcxx . . $ thread_context#data_mutex.; |
| 179 | pthread_cond_tcxx . . $ pthread_cond_t# *cond = &thread_context->data_cond_varcxx . . $ thread_context#data_cond_var.; |
| 180 | struct sockaddr_llcxx . . $ sockaddr_ll# destination; |
| 181 | unsigned char source[ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!]; |
| 182 | uint64_tcxx . . $ uint64_t# sequence_counter = 0; |
| 183 | unsigned int if_index; |
| 184 | int ret, socket_fd; |
| 185 | |
| 186 | socket_fd = thread_context->socket_fdcxx . . $ thread_context#socket_fd.; |
| 187 | |
| 188 | ret = get_interface_mac_addresscxx . . $ get_interface_mac_address(6007bd5416c53f30).(rta_config->interfacecxx . . $ traffic_class_config#interface., source, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 189 | if (ret < 0) { |
| 190 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaTx: Failed to get Source MAC address!\n"); |
| 191 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 192 | } |
| 193 | |
| 194 | if_index = if_nametoindexcxx . . $ if_nametoindex(c61c63047ce273de).(rta_config->interfacecxx . . $ traffic_class_config#interface.); |
| 195 | if (!if_index) { |
| 196 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaTx: if_nametoindex() failed!\n"); |
| 197 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 198 | } |
| 199 | |
| 200 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&destination, '\0', sizeof(destination)); |
| 201 | destination.sll_familycxx . . $ sockaddr_ll#sll_family. = PF_PACKETcxx . . $ `<external>/8962547315054503424/socket.h:61:9`!; |
| 202 | destination.sll_ifindexcxx . . $ sockaddr_ll#sll_ifindex. = if_index; |
| 203 | destination.sll_halencxx . . $ sockaddr_ll#sll_halen. = ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!; |
| 204 | memcpycxx . . $ memcpy(cc817cb175f282d).(destination.sll_addrcxx . . $ sockaddr_ll#sll_addr., rta_config->l2_destinationcxx . . $ traffic_class_config#l2_destination., ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 205 | |
| 206 | rta_initialize_framescxx . . $ rta_initialize_frames(e1a9c3903a216417).(thread_context, thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data., |
| 207 | rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle., source, rta_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 208 | |
| 209 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(security_context); |
| 210 | rta_initialize_framescxx . . $ rta_initialize_frames(e1a9c3903a216417).(thread_context, thread_context->payload_patterncxx . . $ thread_context#payload_pattern., 1, source, |
| 211 | rta_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 212 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. += |
| 213 | sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#); |
| 214 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length. = |
| 215 | rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length. - sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) - |
| 216 | sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#) - sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 217 | |
| 218 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 219 | struct timespeccxx . . $ timespec# timeout; |
| 220 | size_t num_frames; |
| 221 | |
| 222 | /* |
| 223 | * Wait until signalled. These RTA frames have to be sent after the RTC |
| 224 | * frames. Therefore, the RTC TxThread signals this one here. |
| 225 | */ |
| 226 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &timeout); |
| 227 | timeout.tv_seccxx . . $ timespec#tv_sec.++; |
| 228 | |
| 229 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(mutex); |
| 230 | ret = pthread_cond_timedwaitcxx . . $ pthread_cond_timedwait(d8fcb9edac03ad51).(cond, mutex, &timeout); |
| 231 | num_frames = thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available.; |
| 232 | thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available. = 0; |
| 233 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(mutex); |
| 234 | |
| 235 | /* In case of shutdown a signal may be missing. */ |
| 236 | if (ret == ETIMEDOUTcxx . . $ `<external>/17922322188510340118/errno.h:94:9`!) |
| 237 | continue; |
| 238 | |
| 239 | /* |
| 240 | * Send RtaFrames, two possibilites: |
| 241 | * a) Generate it, or |
| 242 | * b) Use received ones if mirror enabled |
| 243 | */ |
| 244 | if (!mirror_enabled) { |
| 245 | if (num_frames) { |
| 246 | rta_gen_and_send_framescxx . . $ rta_gen_and_send_frames(2a5ba8d4c1205443).(thread_context, socket_fd, &destination, |
| 247 | sequence_counter); |
| 248 | |
| 249 | sequence_counter += num_frames; |
| 250 | } |
| 251 | } else { |
| 252 | size_t len; |
| 253 | |
| 254 | ring_buffer_fetchcxx . . $ ring_buffer_fetch(e8bf408057bf6314).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer., received_frames, |
| 255 | received_frames_length, &len); |
| 256 | |
| 257 | /* Len should be a multiple of frame size */ |
| 258 | num_frames = len / rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 259 | rta_send_framescxx . . $ rta_send_frames(bbb668e7d71a4c9).(thread_context, received_frames, num_frames, socket_fd, |
| 260 | &destination); |
| 261 | |
| 262 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 263 | thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available. = 0; |
| 264 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 265 | } |
| 266 | |
| 267 | /* Signal next Tx thread */ |
| 268 | if (thread_context->nextcxx . . $ thread_context#next.) { |
| 269 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 270 | pthread_cond_signalcxx . . $ pthread_cond_signal(98095c34a2b0149d).(&thread_context->nextcxx . . $ thread_context#next.->data_cond_varcxx . . $ thread_context#data_cond_var.); |
| 271 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 272 | } |
| 273 | |
| 274 | if (thread_context->is_lastcxx . . $ thread_context#is_last.) |
| 275 | stat_updatecxx . . $ stat_update(49f6e7a06ebc5aa8).(); |
| 276 | } |
| 277 | |
| 278 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * This Tx thread routine differs to the standard one in terms of the sending interface. This one |
| 283 | * uses the AF_XDP user space interface. |
| 284 | */ |
| 285 | static void *rta_xdp_tx_thread_routinecxx . . $ rta_xdp_tx_thread_routine(9f162e79bfc6c74).(void *data) |
| 286 | { |
| 287 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 288 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 289 | struct security_contextcxx . . $ security_context# *security_context = thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.; |
| 290 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = rta_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 291 | uint32_tcxx . . $ uint32_t# frame_number = XSK_RING_PROD__DEFAULT_NUM_DESCScxx . . $ `src/xdp.h:30:9`!; |
| 292 | pthread_mutex_tcxx . . $ pthread_mutex_t# *mutex = &thread_context->data_mutexcxx . . $ thread_context#data_mutex.; |
| 293 | pthread_cond_tcxx . . $ pthread_cond_t# *cond = &thread_context->data_cond_varcxx . . $ thread_context#data_cond_var.; |
| 294 | unsigned char source[ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!]; |
| 295 | uint64_tcxx . . $ uint64_t# sequence_counter = 0; |
| 296 | unsigned char *frame_data; |
| 297 | struct xdp_socketcxx . . $ xdp_socket# *xsk; |
| 298 | size_t num_frames; |
| 299 | int ret; |
| 300 | |
| 301 | xsk = thread_context->xskcxx . . $ thread_context#xsk.; |
| 302 | xsk->tx_hwtscxx . . $ xdp_socket#tx_hwts..rttcxx . . $ xdp_tx_hwts#rtt. = &round_trip_contextscxx . . $ round_trip_contexts.[RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.]; |
| 303 | xsk->tx_hwtscxx . . $ xdp_socket#tx_hwts..frames_per_cyclecxx . . $ xdp_tx_hwts#frames_per_cycle. = rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 304 | |
| 305 | ret = get_interface_mac_addresscxx . . $ get_interface_mac_address(6007bd5416c53f30).(rta_config->interfacecxx . . $ traffic_class_config#interface., source, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 306 | if (ret < 0) { |
| 307 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaTx: Failed to get Source MAC address!\n"); |
| 308 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 309 | } |
| 310 | |
| 311 | /* First half of umem area is for Rx, the second half is for Tx. */ |
| 312 | frame_data = xsk_umem__get_datacxx . . $ xsk_umem__get_data(c096771c57425568).(xsk->umemcxx . . $ xdp_socket#umem..buffercxx . . $ xsk_umem_info#buffer., |
| 313 | XDP_FRAME_SIZEcxx . . $ `src/xdp.h:34:9`! * XSK_RING_PROD__DEFAULT_NUM_DESCScxx . . $ `src/xdp.h:30:9`!); |
| 314 | |
| 315 | /* Initialize all Tx frames */ |
| 316 | rta_initialize_framescxx . . $ rta_initialize_frames(e1a9c3903a216417).(thread_context, frame_data, XSK_RING_CONS__DEFAULT_NUM_DESCScxx . . $ `src/xdp.h:29:9`!, source, |
| 317 | rta_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 318 | |
| 319 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(security_context); |
| 320 | rta_initialize_framescxx . . $ rta_initialize_frames(e1a9c3903a216417).(thread_context, thread_context->payload_patterncxx . . $ thread_context#payload_pattern., 1, source, |
| 321 | rta_config->l2_destinationcxx . . $ traffic_class_config#l2_destination.); |
| 322 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. += |
| 323 | sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#); |
| 324 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length. = |
| 325 | rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length. - sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) - |
| 326 | sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#) - sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 327 | |
| 328 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 329 | struct timespeccxx . . $ timespec# timeout; |
| 330 | |
| 331 | /* |
| 332 | * Wait until signalled. These RTA frames have to be sent after the RTC |
| 333 | * frames. Therefore, the RTC TxThread signals this one here. |
| 334 | */ |
| 335 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &timeout); |
| 336 | timeout.tv_seccxx . . $ timespec#tv_sec.++; |
| 337 | |
| 338 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(mutex); |
| 339 | ret = pthread_cond_timedwaitcxx . . $ pthread_cond_timedwait(d8fcb9edac03ad51).(cond, mutex, &timeout); |
| 340 | num_frames = thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available.; |
| 341 | thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available. = 0; |
| 342 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(mutex); |
| 343 | |
| 344 | /* In case of shutdown a signal may be missing. */ |
| 345 | if (ret == ETIMEDOUTcxx . . $ `<external>/17922322188510340118/errno.h:94:9`!) |
| 346 | continue; |
| 347 | |
| 348 | /* |
| 349 | * Send RtaFrames, two possibilites: |
| 350 | * a) Generate it, or |
| 351 | * b) Use received ones if mirror enabled |
| 352 | */ |
| 353 | if (!mirror_enabled) { |
| 354 | if (num_frames) { |
| 355 | rta_gen_and_send_xdp_framescxx . . $ rta_gen_and_send_xdp_frames(dcf10771cc53a65b).(thread_context, xsk, sequence_counter, |
| 356 | &frame_number); |
| 357 | sequence_counter += num_frames; |
| 358 | } |
| 359 | } else { |
| 360 | unsigned int received; |
| 361 | uint64_tcxx . . $ uint64_t# i; |
| 362 | |
| 363 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 364 | |
| 365 | received = thread_context->received_framescxx . . $ thread_context#received_frames.; |
| 366 | |
| 367 | sequence_counter = thread_context->rx_sequence_countercxx . . $ thread_context#rx_sequence_counter. - received; |
| 368 | |
| 369 | /* |
| 370 | * The XDP receiver stored the frames within the umem area and populated the |
| 371 | * Tx ring. Now, the Tx ring can be committed to the kernel. Furthermore, |
| 372 | * already transmitted frames from last cycle can be recycled for Rx. |
| 373 | */ |
| 374 | |
| 375 | xsk_ring_prod__submitcxx . . $ xsk_ring_prod__submit(9991f52d60245542).(&xsk->txcxx . . $ xdp_socket#tx., received); |
| 376 | |
| 377 | if (received > 0) { |
| 378 | if (rta_config->tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled.) { |
| 379 | /* |
| 380 | * Once-per-cycle: record TX SW timestamp for the first |
| 381 | * packet in this cycle and count all frames |
| 382 | */ |
| 383 | stat_frames_sent_batchcxx . . $ stat_frames_sent_batch(1b9110cae93061b5).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE., sequence_counter, |
| 384 | received); |
| 385 | } else { |
| 386 | for (i = sequence_counter; i < sequence_counter + received; |
| 387 | ++i) |
| 388 | stat_frame_sentcxx . . $ stat_frame_sent(ca48c151307d73b6).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE., i); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | xsk->outstanding_txcxx . . $ xdp_socket#outstanding_tx. += received; |
| 393 | thread_context->received_framescxx . . $ thread_context#received_frames. = 0; |
| 394 | xdp_complete_txcxx . . $ xdp_complete_tx(5f53ef6b518fdd5d).(xsk); |
| 395 | |
| 396 | #ifdef TX_TIMESTAMP |
| 397 | if (received > 0 && rta_config->tx_hwtstamp_enabled) { |
| 398 | /* |
| 399 | * TX HW timestamp becomes available in the next cycle |
| 400 | * after the packet is transmitted. |
| 401 | * This is one cycle later than SW timestamp tracked |
| 402 | * using sequence_counter |
| 403 | */ |
| 404 | xsk->tx_hwts.seq_lagged = sequence_counter; |
| 405 | } |
| 406 | #endif |
| 407 | |
| 408 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 409 | } |
| 410 | |
| 411 | /* Signal next Tx thread */ |
| 412 | if (thread_context->nextcxx . . $ thread_context#next.) { |
| 413 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 414 | pthread_cond_signalcxx . . $ pthread_cond_signal(98095c34a2b0149d).(&thread_context->nextcxx . . $ thread_context#next.->data_cond_varcxx . . $ thread_context#data_cond_var.); |
| 415 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->nextcxx . . $ thread_context#next.->data_mutexcxx . . $ thread_context#data_mutex.); |
| 416 | } |
| 417 | |
| 418 | if (thread_context->is_lastcxx . . $ thread_context#is_last.) |
| 419 | stat_updatecxx . . $ stat_update(49f6e7a06ebc5aa8).(); |
| 420 | } |
| 421 | |
| 422 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 423 | } |
| 424 | |
| 425 | static void *rta_rx_thread_routinecxx . . $ rta_rx_thread_routine(9f162e79bfc6c74).(void *data) |
| 426 | { |
| 427 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 428 | const uint64_tcxx . . $ uint64_t# cycle_time_ns = app_configcxx . . $ app_config..application_base_cycle_time_nscxx . . $ application_config#application_base_cycle_time_ns.; |
| 429 | struct timespeccxx . . $ timespec# wakeup_time; |
| 430 | int socket_fd, ret; |
| 431 | |
| 432 | socket_fd = thread_context->socket_fdcxx . . $ thread_context#socket_fd.; |
| 433 | |
| 434 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 435 | |
| 436 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(app_configcxx . . $ app_config..application_rx_base_offset_nscxx . . $ application_config#application_rx_base_offset_ns., &wakeup_time); |
| 437 | if (ret) { |
| 438 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaRx: Failed to calculate thread start time: %s!\n", |
| 439 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 440 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 441 | } |
| 442 | |
| 443 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 444 | struct packet_receive_requestcxx . . $ packet_receive_request# recv_req = { |
| 445 | .traffic_class = thread_context->traffic_classcxx . . $ thread_context#traffic_class., |
| 446 | .socket_fd = socket_fd, |
| 447 | .receive_function = receive_profinet_framecxx . . $ receive_profinet_frame(ddfd8079f1f43689)., |
| 448 | .data = thread_context, |
| 449 | }; |
| 450 | |
| 451 | /* Wait until next period. */ |
| 452 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 453 | |
| 454 | do { |
| 455 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, |
| 456 | &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 457 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 458 | |
| 459 | if (ret) { |
| 460 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaRx: clock_nanosleep() failed: %s\n", |
| 461 | strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 462 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 463 | } |
| 464 | |
| 465 | /* Receive Rta frames. */ |
| 466 | packet_receive_messagescxx . . $ packet_receive_messages(dec9d97ca532b11c).(thread_context->packet_contextcxx . . $ thread_context#packet_context., &recv_req); |
| 467 | } |
| 468 | |
| 469 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 470 | } |
| 471 | |
| 472 | static void *rta_tx_generation_thread_routinecxx . . $ rta_tx_generation_thread_routine(9f162e79bfc6c74).(void *data) |
| 473 | { |
| 474 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 475 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 476 | uint64_tcxx . . $ uint64_t# num_frames = rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.; |
| 477 | uint64_tcxx . . $ uint64_t# cycle_time_ns = rta_config->burst_period_nscxx . . $ traffic_class_config#burst_period_ns.; |
| 478 | pthread_mutex_tcxx . . $ pthread_mutex_t# *mutex = &thread_context->data_mutexcxx . . $ thread_context#data_mutex.; |
| 479 | struct timespeccxx . . $ timespec# wakeup_time; |
| 480 | int ret; |
| 481 | |
| 482 | /* |
| 483 | * The RTA frames are generated by bursts with a certain period. This thread is responsible |
| 484 | * for generating it. |
| 485 | */ |
| 486 | |
| 487 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(0, &wakeup_time); |
| 488 | if (ret) { |
| 489 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., |
| 490 | "RtaTxGen: Failed to calculate thread start time: %s!\n", |
| 491 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 492 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 493 | } |
| 494 | |
| 495 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 496 | /* Wait until next period */ |
| 497 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 498 | |
| 499 | do { |
| 500 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, |
| 501 | &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 502 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 503 | |
| 504 | if (ret) { |
| 505 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaTxGen: clock_nanosleep() failed: %s\n", |
| 506 | strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 507 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 508 | } |
| 509 | |
| 510 | /* Generate frames */ |
| 511 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(mutex); |
| 512 | thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available. = num_frames; |
| 513 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(mutex); |
| 514 | } |
| 515 | |
| 516 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 517 | } |
| 518 | |
| 519 | static void *rta_xdp_rx_thread_routinecxx . . $ rta_xdp_rx_thread_routine(9f162e79bfc6c74).(void *data) |
| 520 | { |
| 521 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 522 | const long long cycle_time_ns = app_configcxx . . $ app_config..application_base_cycle_time_nscxx . . $ application_config#application_base_cycle_time_ns.; |
| 523 | const struct traffic_class_configcxx . . $ traffic_class_config# *rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 524 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = rta_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 525 | const size_t frame_length = rta_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 526 | struct xdp_socketcxx . . $ xdp_socket# *xsk = thread_context->xskcxx . . $ thread_context#xsk.; |
| 527 | struct timespeccxx . . $ timespec# wakeup_time; |
| 528 | int ret; |
| 529 | |
| 530 | prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 531 | |
| 532 | ret = get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(app_configcxx . . $ app_config..application_rx_base_offset_nscxx . . $ application_config#application_rx_base_offset_ns., &wakeup_time); |
| 533 | if (ret) { |
| 534 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaRx: Failed to calculate thread start time: %s!\n", |
| 535 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 536 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 537 | } |
| 538 | |
| 539 | while (!thread_context->stopcxx . . $ thread_context#stop.) { |
| 540 | unsigned int received; |
| 541 | |
| 542 | /* Wait until next period */ |
| 543 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&wakeup_time, cycle_time_ns); |
| 544 | |
| 545 | do { |
| 546 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, |
| 547 | &wakeup_time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 548 | } while (ret == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); |
| 549 | |
| 550 | if (ret) { |
| 551 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "RtaRx: clock_nanosleep() failed: %s\n", |
| 552 | strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 553 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 554 | } |
| 555 | |
| 556 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 557 | received = xdp_receive_framescxx . . $ xdp_receive_frames(a8ae63e30c683a9b).(xsk, frame_length, mirror_enabled, |
| 558 | receive_profinet_framecxx . . $ receive_profinet_frame(ddfd8079f1f43689)., thread_context, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 559 | thread_context->received_framescxx . . $ thread_context#received_frames. = received; |
| 560 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 561 | } |
| 562 | |
| 563 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 564 | } |
| 565 | |
| 566 | int rta_threads_createcxx . . $ rta_threads_create(8542e1c024f3ff56).(struct thread_contextcxx . . $ thread_context# *thread_context) |
| 567 | { |
| 568 | struct traffic_class_configcxx . . $ traffic_class_config# *rta_config; |
| 569 | int ret; |
| 570 | |
| 571 | if (!config_is_traffic_class_activecxx . . $ config_is_traffic_class_active(c5f7da30cbc0f4e9).("Rta")) |
| 572 | goto out; |
| 573 | |
| 574 | init_mutexcxx . . $ init_mutex(4f83bfebf4bb9c8b).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 575 | init_mutexcxx . . $ init_mutex(4f83bfebf4bb9c8b).(&thread_context->xdp_data_mutexcxx . . $ thread_context#xdp_data_mutex.); |
| 576 | init_condition_variablecxx . . $ init_condition_variable(23b56462c1e1452f).(&thread_context->data_cond_varcxx . . $ thread_context#data_cond_var.); |
| 577 | |
| 578 | thread_context->confcxx . . $ thread_context#conf. = rta_config = &app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.]; |
| 579 | thread_context->frame_typecxx . . $ thread_context#frame_type. = RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.; |
| 580 | thread_context->traffic_classcxx . . $ thread_context#traffic_class. = stat_frame_type_to_stringcxx . . $ stat_frame_type_to_string(413bfe925ee921da).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.); |
| 581 | thread_context->frame_idcxx . . $ thread_context#frame_id. = |
| 582 | rta_config->security_modecxx . . $ traffic_class_config#security_mode. == SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE. ? RTA_FRAMEIDcxx . . $ `src/net_def.h:47:9`! : RTA_SEC_FRAMEIDcxx . . $ `src/net_def.h:48:9`!; |
| 583 | |
| 584 | /* For XDP a AF_XDP socket is allocated. Otherwise a Linux raw socket is used. */ |
| 585 | if (!rta_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 586 | thread_context->packet_contextcxx . . $ thread_context#packet_context. = packet_initcxx . . $ packet_init(6f6262789a319935).(rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 587 | if (!thread_context->packet_contextcxx . . $ thread_context#packet_context.) { |
| 588 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate Rta packet context!\n"); |
| 589 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 590 | goto err_packet; |
| 591 | } |
| 592 | |
| 593 | thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data. = |
| 594 | calloccxx . . $ calloc(63a7bf2941bfcd7a).(rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle., MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!); |
| 595 | if (!thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data.) { |
| 596 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate RtaTxFrameData!\n"); |
| 597 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 598 | goto err_tx; |
| 599 | } |
| 600 | |
| 601 | thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data. = |
| 602 | calloccxx . . $ calloc(63a7bf2941bfcd7a).(rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle., MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!); |
| 603 | if (!thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.) { |
| 604 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate RtaRxFrameData!\n"); |
| 605 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 606 | goto err_rx; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!); |
| 611 | if (!thread_context->payload_patterncxx . . $ thread_context#payload_pattern.) { |
| 612 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate RtaPayloadPattern!\n"); |
| 613 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 614 | goto err_payload; |
| 615 | } |
| 616 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length. = MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!; |
| 617 | |
| 618 | /* For XDP a AF_XDP socket is allocated. Otherwise a Linux raw socket is used. */ |
| 619 | if (rta_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 620 | thread_context->socket_fdcxx . . $ thread_context#socket_fd. = 0; |
| 621 | thread_context->xskcxx . . $ thread_context#xsk. = xdp_open_socketcxx . . $ xdp_open_socket(ec858eaaf043e631).( |
| 622 | rta_config->interfacecxx . . $ traffic_class_config#interface., app_configcxx . . $ app_config..application_xdp_programcxx . . $ application_config#application_xdp_program., |
| 623 | rta_config->rx_queuecxx . . $ traffic_class_config#rx_queue., rta_config->xdp_skb_modecxx . . $ traffic_class_config#xdp_skb_mode., rta_config->xdp_zc_modecxx . . $ traffic_class_config#xdp_zc_mode., |
| 624 | rta_config->xdp_wakeup_modecxx . . $ traffic_class_config#xdp_wakeup_mode., rta_config->xdp_busy_poll_modecxx . . $ traffic_class_config#xdp_busy_poll_mode., falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, |
| 625 | rta_config->tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled.); |
| 626 | if (!thread_context->xskcxx . . $ thread_context#xsk.) { |
| 627 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rta Xdp socket!\n"); |
| 628 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 629 | goto err_socket; |
| 630 | } |
| 631 | } else { |
| 632 | thread_context->xskcxx . . $ thread_context#xsk. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 633 | thread_context->socket_fdcxx . . $ thread_context#socket_fd. = create_rta_socketcxx . . $ create_rta_socket(b126dc7c1de90089).(); |
| 634 | if (thread_context->socket_fdcxx . . $ thread_context#socket_fd. < 0) { |
| 635 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create RtaSocket!\n"); |
| 636 | ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 637 | goto err_socket; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /* Same as above. For XDP the umem area is used. */ |
| 642 | if (rta_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled. && !rta_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 643 | /* Per period the expectation is: RtaNumFramesPerCycle * MAX_FRAME */ |
| 644 | thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer. = |
| 645 | ring_buffer_allocatecxx . . $ ring_buffer_allocate(a00a27d6b402ebff).(MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`! * rta_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 646 | if (!thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer.) { |
| 647 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate Rta Mirror RingBuffer!\n"); |
| 648 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 649 | goto err_buffer; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if (rta_config->security_modecxx . . $ traffic_class_config#security_mode. != SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.) { |
| 654 | thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context. = security_initcxx . . $ security_init(5357658aae651c5a).( |
| 655 | rta_config->security_algorithmcxx . . $ traffic_class_config#security_algorithm., (unsigned char *)rta_config->security_keycxx . . $ traffic_class_config#security_key.); |
| 656 | if (!thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.) { |
| 657 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to initialize Tx security context!\n"); |
| 658 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 659 | goto err_tx_sec; |
| 660 | } |
| 661 | |
| 662 | thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context. = security_initcxx . . $ security_init(5357658aae651c5a).( |
| 663 | rta_config->security_algorithmcxx . . $ traffic_class_config#security_algorithm., (unsigned char *)rta_config->security_keycxx . . $ traffic_class_config#security_key.); |
| 664 | if (!thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.) { |
| 665 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to initialize Rx security context!\n"); |
| 666 | ret = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 667 | goto err_rx_sec; |
| 668 | } |
| 669 | } else { |
| 670 | thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 671 | thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 672 | } |
| 673 | |
| 674 | ret = create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(&thread_context->tx_task_idcxx . . $ thread_context#tx_task_id., "RtaTxThread", |
| 675 | rta_config->tx_thread_prioritycxx . . $ traffic_class_config#tx_thread_priority., rta_config->tx_thread_cpucxx . . $ traffic_class_config#tx_thread_cpu., |
| 676 | rta_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled. ? rta_xdp_tx_thread_routinecxx . . $ rta_xdp_tx_thread_routine(9f162e79bfc6c74). |
| 677 | : rta_tx_thread_routinecxx . . $ rta_tx_thread_routine(9f162e79bfc6c74)., |
| 678 | thread_context); |
| 679 | if (ret) { |
| 680 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rta Tx Thread!\n"); |
| 681 | goto err_thread; |
| 682 | } |
| 683 | |
| 684 | if (!rta_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.) { |
| 685 | ret = create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(&thread_context->tx_gen_task_idcxx . . $ thread_context#tx_gen_task_id., "RtaTxGenThread", |
| 686 | rta_config->tx_thread_prioritycxx . . $ traffic_class_config#tx_thread_priority., rta_config->tx_thread_cpucxx . . $ traffic_class_config#tx_thread_cpu., |
| 687 | rta_tx_generation_thread_routinecxx . . $ rta_tx_generation_thread_routine(9f162e79bfc6c74)., thread_context); |
| 688 | if (ret) { |
| 689 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rta TxGen Thread!\n"); |
| 690 | goto err_thread_txgen; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | ret = create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(&thread_context->rx_task_idcxx . . $ thread_context#rx_task_id., "RtaRxThread", |
| 695 | rta_config->rx_thread_prioritycxx . . $ traffic_class_config#rx_thread_priority., rta_config->rx_thread_cpucxx . . $ traffic_class_config#rx_thread_cpu., |
| 696 | rta_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled. ? rta_xdp_rx_thread_routinecxx . . $ rta_xdp_rx_thread_routine(9f162e79bfc6c74). |
| 697 | : rta_rx_thread_routinecxx . . $ rta_rx_thread_routine(9f162e79bfc6c74)., |
| 698 | thread_context); |
| 699 | if (ret) { |
| 700 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to create Rta Rx Thread!\n"); |
| 701 | goto err_thread_rx; |
| 702 | } |
| 703 | |
| 704 | thread_context->meta_data_offsetcxx . . $ thread_context#meta_data_offset. = |
| 705 | get_meta_data_offsetcxx . . $ get_meta_data_offset(16cb9e606c8e3615).(RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE., rta_config->security_modecxx . . $ traffic_class_config#security_mode.); |
| 706 | |
| 707 | out: |
| 708 | return 0; |
| 709 | |
| 710 | err_thread_rx: |
| 711 | thread_context->stopcxx . . $ thread_context#stop. = 1; |
| 712 | if (thread_context->tx_gen_task_idcxx . . $ thread_context#tx_gen_task_id.) |
| 713 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->tx_gen_task_idcxx . . $ thread_context#tx_gen_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 714 | err_thread_txgen: |
| 715 | thread_context->stopcxx . . $ thread_context#stop. = 1; |
| 716 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->tx_task_idcxx . . $ thread_context#tx_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 717 | err_thread: |
| 718 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 719 | err_rx_sec: |
| 720 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.); |
| 721 | err_tx_sec: |
| 722 | ring_buffer_freecxx . . $ ring_buffer_free(8f2cd700b00968de).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer.); |
| 723 | err_buffer: |
| 724 | if (thread_context->socket_fdcxx . . $ thread_context#socket_fd.) |
| 725 | closecxx . . $ close(7864480464b09eea).(thread_context->socket_fdcxx . . $ thread_context#socket_fd.); |
| 726 | if (thread_context->xskcxx . . $ thread_context#xsk.) |
| 727 | xdp_close_socketcxx . . $ xdp_close_socket(fc530d27d072e0f5).(thread_context->xskcxx . . $ thread_context#xsk., rta_config->interfacecxx . . $ traffic_class_config#interface., |
| 728 | rta_config->xdp_skb_modecxx . . $ traffic_class_config#xdp_skb_mode.); |
| 729 | err_socket: |
| 730 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->payload_patterncxx . . $ thread_context#payload_pattern.); |
| 731 | err_payload: |
| 732 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.); |
| 733 | err_rx: |
| 734 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data.); |
| 735 | err_tx: |
| 736 | packet_freecxx . . $ packet_free(b20c0f701b2a2d37).(thread_context->packet_contextcxx . . $ thread_context#packet_context.); |
| 737 | err_packet: |
| 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | void rta_threads_freecxx . . $ rta_threads_free(f7c2ab51214b7176).(struct thread_contextcxx . . $ thread_context# *thread_context) |
| 742 | { |
| 743 | struct traffic_class_configcxx . . $ traffic_class_config# *rta_config; |
| 744 | |
| 745 | if (!thread_context) |
| 746 | return; |
| 747 | |
| 748 | rta_config = thread_context->confcxx . . $ thread_context#conf.; |
| 749 | |
| 750 | if (thread_context->payload_patterncxx . . $ thread_context#payload_pattern.) { |
| 751 | thread_context->payload_patterncxx . . $ thread_context#payload_pattern. -= |
| 752 | sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#); |
| 753 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->payload_patterncxx . . $ thread_context#payload_pattern.); |
| 754 | } |
| 755 | |
| 756 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->tx_security_contextcxx . . $ thread_context#tx_security_context.); |
| 757 | security_exitcxx . . $ security_exit(180fdc1b6a791d79).(thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.); |
| 758 | |
| 759 | ring_buffer_freecxx . . $ ring_buffer_free(8f2cd700b00968de).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer.); |
| 760 | |
| 761 | packet_freecxx . . $ packet_free(b20c0f701b2a2d37).(thread_context->packet_contextcxx . . $ thread_context#packet_context.); |
| 762 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->tx_frame_datacxx . . $ thread_context#tx_frame_data.); |
| 763 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->rx_frame_datacxx . . $ thread_context#rx_frame_data.); |
| 764 | |
| 765 | if (thread_context->socket_fdcxx . . $ thread_context#socket_fd. > 0) |
| 766 | closecxx . . $ close(7864480464b09eea).(thread_context->socket_fdcxx . . $ thread_context#socket_fd.); |
| 767 | |
| 768 | if (thread_context->xskcxx . . $ thread_context#xsk.) |
| 769 | xdp_close_socketcxx . . $ xdp_close_socket(fc530d27d072e0f5).(thread_context->xskcxx . . $ thread_context#xsk., rta_config->interfacecxx . . $ traffic_class_config#interface., |
| 770 | rta_config->xdp_skb_modecxx . . $ traffic_class_config#xdp_skb_mode.); |
| 771 | } |
| 772 | |
| 773 | void rta_threads_wait_for_finishcxx . . $ rta_threads_wait_for_finish(f7c2ab51214b7176).(struct thread_contextcxx . . $ thread_context# *thread_context) |
| 774 | { |
| 775 | if (!thread_context) |
| 776 | return; |
| 777 | |
| 778 | if (thread_context->rx_task_idcxx . . $ thread_context#rx_task_id.) |
| 779 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->rx_task_idcxx . . $ thread_context#rx_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 780 | if (thread_context->tx_task_idcxx . . $ thread_context#tx_task_id.) |
| 781 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->tx_task_idcxx . . $ thread_context#tx_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 782 | if (thread_context->tx_gen_task_idcxx . . $ thread_context#tx_gen_task_id.) |
| 783 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->tx_gen_task_idcxx . . $ thread_context#tx_gen_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 784 | } |