1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #if !defined(_TRACE_NET_PROBE_COMMON_H) || defined(TRACE_HEADER_MULTI_READ) 4 #define _TRACE_NET_PROBE_COMMON_H 5 6 #define TP_STORE_ADDR_PORTS_V4(__entry, inet, sk) \ 7 do { \ 8 struct sockaddr_in *v4 = (void *)__entry->saddr; \ 9 \ 10 v4->sin_family = AF_INET; \ 11 v4->sin_port = inet->inet_sport; \ 12 v4->sin_addr.s_addr = inet->inet_saddr; \ 13 v4 = (void *)__entry->daddr; \ 14 v4->sin_family = AF_INET; \ 15 v4->sin_port = inet->inet_dport; \ 16 v4->sin_addr.s_addr = inet->inet_daddr; \ 17 } while (0) 18 19 #if IS_ENABLED(CONFIG_IPV6) 20 21 #define TP_STORE_ADDR_PORTS(__entry, inet, sk) \ 22 do { \ 23 if (sk->sk_family == AF_INET6) { \ 24 struct sockaddr_in6 *v6 = (void *)__entry->saddr; \ 25 \ 26 v6->sin6_family = AF_INET6; \ 27 v6->sin6_port = inet->inet_sport; \ 28 v6->sin6_addr = inet6_sk(sk)->saddr; \ 29 v6 = (void *)__entry->daddr; \ 30 v6->sin6_family = AF_INET6; \ 31 v6->sin6_port = inet->inet_dport; \ 32 v6->sin6_addr = sk->sk_v6_daddr; \ 33 } else \ 34 TP_STORE_ADDR_PORTS_V4(__entry, inet, sk); \ 35 } while (0) 36 37 #else 38 39 #define TP_STORE_ADDR_PORTS(__entry, inet, sk) \ 40 TP_STORE_ADDR_PORTS_V4(__entry, inet, sk); 41 42 #endif 43 44 #define TP_STORE_V4MAPPED(__entry, saddr, daddr) \ 45 do { \ 46 struct in6_addr *pin6; \ 47 \ 48 pin6 = (struct in6_addr *)__entry->saddr_v6; \ 49 ipv6_addr_set_v4mapped(saddr, pin6); \ 50 pin6 = (struct in6_addr *)__entry->daddr_v6; \ 51 ipv6_addr_set_v4mapped(daddr, pin6); \ 52 } while (0) 53 54 #if IS_ENABLED(CONFIG_IPV6) 55 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \ 56 do { \ 57 if (sk->sk_family == AF_INET6) { \ 58 struct in6_addr *pin6; \ 59 \ 60 pin6 = (struct in6_addr *)__entry->saddr_v6; \ 61 *pin6 = saddr6; \ 62 pin6 = (struct in6_addr *)__entry->daddr_v6; \ 63 *pin6 = daddr6; \ 64 } else { \ 65 TP_STORE_V4MAPPED(__entry, saddr, daddr); \ 66 } \ 67 } while (0) 68 #else 69 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \ 70 TP_STORE_V4MAPPED(__entry, saddr, daddr) 71 #endif 72 73 #define TP_STORE_ADDR_PORTS_SKB_V4(skb, protoh, entry_saddr, entry_daddr) \ 74 do { \ 75 struct sockaddr_in *v4 = (void *)entry_saddr; \ 76 \ 77 v4->sin_family = AF_INET; \ 78 v4->sin_port = protoh->source; \ 79 v4->sin_addr.s_addr = ip_hdr(skb)->saddr; \ 80 v4 = (void *)entry_daddr; \ 81 v4->sin_family = AF_INET; \ 82 v4->sin_port = protoh->dest; \ 83 v4->sin_addr.s_addr = ip_hdr(skb)->daddr; \ 84 } while (0) 85 86 #if IS_ENABLED(CONFIG_IPV6) 87 88 #define TP_STORE_ADDR_PORTS_SKB(skb, protoh, entry_saddr, entry_daddr) \ 89 do { \ 90 const struct iphdr *iph = ip_hdr(skb); \ 91 \ 92 if (iph->version == 6) { \ 93 struct sockaddr_in6 *v6 = (void *)entry_saddr; \ 94 \ 95 v6->sin6_family = AF_INET6; \ 96 v6->sin6_port = protoh->source; \ 97 v6->sin6_addr = ipv6_hdr(skb)->saddr; \ 98 v6 = (void *)entry_daddr; \ 99 v6->sin6_family = AF_INET6; \ 100 v6->sin6_port = protoh->dest; \ 101 v6->sin6_addr = ipv6_hdr(skb)->daddr; \ 102 } else \ 103 TP_STORE_ADDR_PORTS_SKB_V4(skb, protoh, \ 104 entry_saddr, \ 105 entry_daddr); \ 106 } while (0) 107 108 #else 109 110 #define TP_STORE_ADDR_PORTS_SKB(skb, protoh, entry_saddr, entry_daddr) \ 111 TP_STORE_ADDR_PORTS_SKB_V4(skb, protoh, entry_saddr, entry_daddr) 112 113 #endif 114 115 #endif 116